🧈 ButterPop.js

A lightweight, highly customizable toast notification library with no dependencies.
Making beautiful, interactive notifications smooth as butter! 🍞âœĻ

ButterPop.js Demo

âœĻ Features

⚡

Zero Dependencies

Pure vanilla JavaScript, no external libraries required.

ðŸŠķ

Lightweight

Under 80KB minified (CSS + JS), won't weigh down your project.

ðŸŽĻ

Multiple Themes

41 beautiful built-in themes to match your design.

ðŸ“ą

Responsive Design

Looks great on all devices, from mobile to desktop.

📍

Multiple Positions

7 positioning options for flexible placement.

⏱ïļ

Progress Indicators

Visual progress bars to show remaining time.

🔄

Queue Management

Smart handling of multiple notifications.

â™ŋ

Accessibility Focus

ARIA attributes and keyboard navigation support.

ðŸ“Ķ Installation

Download the latest release and include it in your project:

HTML
<link rel="stylesheet" href="butterpop.css">
<script src="butterpop.js"></script>

You can include ButterPop.js directly from a CDN:

jsDelivr
<!-- CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterpop@1.0.4/butterpop.min.css">

<!-- JavaScript -->
<script src="https://cdn.jsdelivr.net/npm/butterpop@1.0.4/butterpop.min.js"></script>

NPM installation coming soon!

Bash
npm install butterpop

Import ButterPop.js as an ES Module:

HTML
<script type="module">
  import ButterPop from 'https://cdn.jsdelivr.net/npm/butterpop@1.0.4/butterpop.esm.min.js';
  
  // Your code here
  ButterPop.success('Hello from ES Module!');
</script>

🚀 Quick Start

Basic Usage

Show toast notifications with different styles:

JavaScript
// Success notification
ButterPop.success('Operation completed successfully! 🎉');

// Error notification
ButterPop.error('An error occurred! ❌');

// Warning notification
ButterPop.warning('Warning: This action cannot be undone! ⚠ïļ');

// Info notification
ButterPop.info('Did you know? ButterPop.js is awesome! ðŸ’Ą');

Advanced Usage

Customize your notifications with options:

JavaScript
// Advanced usage with options
ButterPop.show({
  message: "Custom notification with many options",
  type: "info",
  position: "top-right",
  duration: 5000,
  theme: "glassmorphism",
  progress: true,
  pauseOnHover: true,
  onClick: () => console.log("Toast clicked!"),
  actions: [{
    text: "View",
    callback: () => console.log("View clicked!")
  }, {
    text: "Dismiss",
    callback: (toast) => ButterPop.remove(toast.id)
  }]
});

With Action Buttons

Add interactive buttons to your toasts:

JavaScript
ButterPop.show({
  message: "New message from John",
  type: "info",
  actions: [
    {
      text: "Reply",
      callback: () => { console.log("Reply clicked"); }
    },
    {
      text: "Dismiss",
      callback: (toast) => { ButterPop.remove(toast.id); }
    }
  ]
});

📋 API Documentation

Core Methods

ButterPop.js provides several methods to create and manage toast notifications:

Method Description
ButterPop.show(options) Create and display a toast with custom options
ButterPop.success(message, options) Show a success toast (green)
ButterPop.error(message, options) Show an error toast (red)
ButterPop.warning(message, options) Show a warning toast (orange/yellow)
ButterPop.info(message, options) Show an info toast (blue)
ButterPop.remove(id) Remove a specific toast by ID
ButterPop.clearAll() Remove all active toasts
ButterPop.configure(options) Set global default options

Configuration Options

Customize your toasts with these configuration options:

Option Type Default Description
message String '' The notification message
type String '' Toast type (success, error, warning, info)
position String 'top-right' Position on screen (top-left, top-right, top-center, bottom-left, bottom-right, bottom-center, center)
duration Number 5000 Duration in milliseconds (0 for persistent toast)
theme String 'default' Theme name (see Themes section)
progress Boolean false Show progress bar
progressColor String null Custom color for progress bar (CSS color)
closable Boolean true Show close button
closeOnClick Boolean false Close when clicking on the toast
pauseOnHover Boolean true Pause timer when hovering
preventDuplicates Boolean false Prevent duplicate notifications
onClick Function null Callback function when toast is clicked
onClose Function null Callback function when toast is closed
actions Array [] Action buttons with callbacks (see Actions section)
className String '' Additional CSS class to apply to the toast
icon String/HTML/Boolean true Custom icon content or false to disable icon
maxVisible Number 5 Maximum number of visible toasts (global option)

Action Buttons

You can add interactive action buttons to your toasts:

JavaScript
ButterPop.show({
  message: "New message from John",
  type: "info",
  actions: [
    {
      text: "Reply",
      callback: () => { openReplyDialog(); }
    },
    {
      text: "Dismiss",
      callback: (toast) => { ButterPop.remove(toast.id); }
    }
  ]
});

Each action in the array accepts these properties:

Property Type Description
text String Button text
callback Function Function to call when clicked (receives toast object)
className String Additional CSS class for styling

Global Configuration

You can set default options for all toasts:

JavaScript
ButterPop.configure({
  position: "bottom-center",
  duration: 8000,
  theme: "material",
  progress: true,
  pauseOnHover: true,
  maxVisible: 3
});

Custom Callbacks

You can add callback functions for click and close events:

JavaScript
ButterPop.show({
  message: "Click me for more info",
  type: "info",
  onClick: () => {
    window.open('https://example.com', '_blank');
  },
  onClose: () => {
    console.log('Toast was closed');
  }
});

Creating Persistent Toasts

Set duration to 0 to make a toast stay until manually closed:

JavaScript
ButterPop.warning("This won't disappear until you close it", {
  duration: 0,
  closable: true
});

Preventing Duplicates

You can prevent duplicate notifications with the preventDuplicates option:

JavaScript
// This will only show one toast, even if called multiple times
const options = {
  message: "You have a new notification",
  preventDuplicates: true
};

ButterPop.info(options.message, options);
ButterPop.info(options.message, options); // This one won't appear

ðŸŽĻ Themes

ButterPop.js comes with 41 beautiful built-in themes to match your design preferences. Themes affect the visual appearance of your toast notifications, making them blend seamlessly with your application's style.

Built-in Themes

Default & Minimal

Dark & Light

Glassmorphism & Neon

Material & Gradient

Rounded & Neumorphism

Retro & Cyberpunk

Theme Description
default Clean, simple style with colored borders
minimal Subtle, minimalist style with thin borders
dark Dark background with light text, suitable for light websites
light Light background with dark text, suitable for dark websites
glassmorphism Modern frosted glass effect with transparency
neon Glowing borders with colorful text shadows
material Google Material Design inspired with shadows and transitions
gradient Smooth color gradients based on notification type
rounded Pill-shaped toasts with fully rounded corners
neumorphism Soft UI/Neumorphic design with adaptive light/dark mode support
retro Vintage computer/pixel art inspired style
cyberpunk Futuristic neon style with scan lines and glowing effects
pastel Soft, gentle colors with smooth corners and subtle shadows
terminal Command-line inspired theme with monospace font and console aesthetics
elegant Sophisticated typography with subtle bottom borders and serif fonts
bubble Speech bubble style with triangular tail and rounded corners
forest Nature-inspired dark green theme with leaf pattern texture
futuristic High-tech UI with gradients, accents, and modern typography
comic Fun cartoon-style design with speech bubbles and bold outlines
luxury Premium dark theme with gold accents and subtle gradients
neon-brutalism Bold, skewed design with bright contrasting colors and thick outlines
monochrome Minimalist black and white design with geometric accents
candy Sweet, colorful design with dotted patterns and soft gradients
aqua Water-inspired with ocean gradients and wave effects
nordic Clean Scandinavian design with minimal colors
blueprint Technical drawing style with grid backgrounds
paper Paper texture with a folded corner effect
origami Paper-fold inspired design with sharp angles
sunset Warm gradient colors inspired by sunset
holographic Iridescent metallic effect with rainbow highlights
chalk Chalkboard texture with handwritten style text
aurora Aurora borealis-inspired theme with colorful gradients
corporate Professional, corporate style with subtle gradients
zen Calm, serene style with soft colors and subtle shadows
frost Cold, frosty style with icy gradients and subtle shadows
velvet Soft, luxurious style with velvet textures and subtle gradients
quantum Futuristic, high-tech style with vibrant colors and subtle shadows
neon-glow Vibrant glowing text with colorful shadows and pulsing effects
watercolor Soft, artistic style with gradient backgrounds and subtle texture
vintage Retro-inspired design with aged paper texture and classic typography
pixel 8-bit style design with pixelated aesthetics and game-inspired colors
handwritten Casual note-like appearance with handwritten font and paper texture

Using Themes

JavaScript
// Set a theme for a specific toast
ButterPop.success("Operation completed!", { theme: "glassmorphism" });

// Set a default theme for all toasts
ButterPop.configure({ theme: "material" });

Custom Icons

You can customize the icons in your toast notifications using several methods:

JavaScript
// Use an emoji as an icon
ButterPop.show({
  message: "Toast with emoji icon",
  type: "info",
  icon: "🚀"
});

// Use custom SVG
const svgIcon = ``;

ButterPop.show({
  message: "Toast with custom SVG icon",
  type: "info",
  icon: svgIcon
});

// Use Font Awesome or other icon libraries
// Make sure to include the Font Awesome library in your project
ButterPop.show({
  message: "Toast with Font Awesome icon",
  type: "info",
  icon: ''
});

// Use an image
ButterPop.show({
  message: "Toast with image icon",
  type: "info",
  icon: 'Icon'
});

// Remove the icon completely
ButterPop.show({
  message: "Toast with no icon",
  type: "info",
  icon: false
});

📚 Examples

Form Validation

Use ButterPop to provide feedback during form validation:

JavaScript
function validateForm() {
  const email = document.getElementById('email').value;
  if (!email.includes('@')) {
    ButterPop.error("Please enter a valid email address", {
      position: "top-center",
      theme: "material"
    });
    return false;
  }
  
  ButterPop.success("Form submitted successfully!");
  return true;
}

Try it out:

API Request Notification

Provide feedback during API requests:

JavaScript
async function fetchData() {
  try {
    ButterPop.info("Fetching data...", { duration: 0, id: "fetch-toast" });
    
    const response = await fetch('https://api.example.com/data');
    const data = await response.json();
    
    ButterPop.remove("fetch-toast");
    ButterPop.success("Data loaded successfully!");
    
    return data;
  } catch (error) {
    ButterPop.remove("fetch-toast");
    ButterPop.error("Failed to load data: " + error.message, {
      duration: 0,
      actions: [{
        text: "Retry",
        callback: fetchData
      }]
    });
  }
}

Simulate API Request:

Browser Compatibility

ButterPop.js works with all modern browsers:

  • Chrome 49+
  • Firefox 52+
  • Safari 10+
  • Edge 16+
  • Opera 36+
  • iOS Safari 10+
  • Android Browser 4.4+

ðŸŽŪ Live Demo

Create your own custom toast notifications with this interactive demo. Experiment with different options and see the results in real-time.

Live Preview

This is a custom toast notification

Generated Code:

JavaScript
// Generated code will appear here