npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jaymago/simple-display-alert

v1.0.6

Published

A lightweight, customizable alert system for web applications with TypeScript support

Downloads

290

Readme

Simple Display Alert

A lightweight, customizable alert system for web applications.

Interactive Demo

🚀 Live Demo - Try it out now!

Installation

npm install @jaymago/simple-display-alert

Features

  • 📦 Lightweight and dependency-free
  • 🎨 Multiple alert types (success, error, warning, info, loader)
  • 📍 Flexible positioning (top-left, top-right, bottom-left, bottom-right)
  • ⚡ Fade animations (left, right, top, bottom)
  • ⏱️ Configurable timeout
  • 🔄 Multiple alerts support
  • 🎯 TypeScript support

Usage

1. Import the Package and Styles

// Import the package
import { 
    displayAlert,          // Generic alert function
    displayAlertSuccess,   // Success variant
    displayAlertError,     // Error variant
    displayAlertWarning,   // Warning variant
    displayAlertInfo,      // Info variant
    displayAlertLoader     // Loading variant
} from 'simple-display-alert';

// Import the CSS (required)
import '@jaymago/simple-display-alert/dist/index.css';

2. Basic Usage

// Success message (green)
displayAlertSuccess('Operation completed successfully!');

// Error message (red)
displayAlertError('An error occurred!');

// Warning message (yellow)
displayAlertWarning('Please check your input');

// Info message (blue)
displayAlertInfo('This is an informational message');

// Loading message (with spinner)
displayAlertLoader('Loading...');

Examples

// First, import both the functions and CSS
import { displayAlert, displayAlertSuccess } from '@jaymago/simple-display-alert';
import '@jaymago/simple-display-alert/dist/index.css';

// Then use the alert functions
displayAlertSuccess('Operation completed successfully!');

displayAlert('Custom alert', {
  type: 'info',
  position: 'top-right',
  timeout: 3000
});

// Multiple alerts
displayAlert('First alert', { position: 'top-left' });
displayAlert('Second alert', { position: 'top-right' });

Alerts with Options

// Success alert with custom position and animation
displayAlertSuccess('Success with options', { 
    position: 'top-right',     // Position in top-right corner
    fadeDirection: 'left'      // Slide in from right
});

// Error alert that stays visible and allows multiple alerts
displayAlertError('Error with options', { 
    timeout: 0,                // Stays visible indefinitely
    multiple: true            // Can stack with other alerts
});

// Warning alert with custom position and animation
displayAlertWarning('Warning with options', { 
    position: 'bottom-left',   // Position in bottom-left corner
    fadeDirection: 'bottom'    // Slide in from top
});

// Info alert with custom timeout
displayAlertInfo('Info with options', { 
    timeout: 3000,            // Hide after 3 seconds
    multiple: true            // Can stack with other alerts
});

// Loading alert with custom position and timeout
displayAlertLoader('Loading with options', { 
    position: 'top-right',    // Position in top-right corner
    timeout: 2000             // Hide after 2 seconds
});

Generic Alert with Full Options

interface DisplayAlertProps {
    // Alert type
    variant: 'success' | 'error' | 'warning' | 'info' | 'white' | 'loader';
    
    // Content
    message: string;
    icon?: 'success' | 'danger' | 'warning' | 'info' | 'loader';
    
    // Positioning
    position?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
    
    // Animation
    fadeDirection?: 'left' | 'right' | 'top' | 'bottom' | 'none';
    
    // Behavior
    timeout?: number;         // Time in ms (0 for no auto-hide)
    closeBtn?: boolean;       // Show/hide close button
    multiple?: boolean;       // Allow multiple alerts
    backdrop?: boolean;       // Show backdrop behind alert
}

// Example usage with all options
displayAlert({
    variant: 'success',
    message: 'Your message here',
    icon: 'success',
    position: 'bottom-right',
    fadeDirection: 'left',
    timeout: 5000,
    closeBtn: true,
    multiple: false,
    backdrop: false
});

Managing Alerts

Hiding Alerts Programmatically

// Method 1: Store the alert reference
const alert = displayAlert({
    variant: 'info',
    message: 'This alert can be hidden programmatically',
    timeout: 0
});
// Later, hide it using:
alert.remove();

// Method 2: Remove all alerts
import { removeResponseAlert } from 'simple-display-alert';

// Remove all alerts from the page
removeResponseAlert();

Alert Types

  • Success alerts for successful operations
  • Error alerts for error messages
  • Warning alerts for warnings
  • Info alerts for information messages
  • Loader alerts for loading states
  • White/neutral alerts for general messages
  • Backdrop alerts for modal-like messages

Icon Options

Each alert type comes with a default icon, but you can customize it using the icon property:

// Available icon options
type AlertIcon = 'success' | 'danger' | 'warning' | 'info' | 'loader';

// Examples
displayAlert({
    variant: 'white',
    message: 'Custom success icon',
    icon: 'success'
});

displayAlert({
    variant: 'white',
    message: 'Custom warning icon',
    icon: 'warning'
});

// Loader icon with custom message
displayAlert({
    variant: 'white',
    message: 'Processing...',
    icon: 'loader'
});

// No icon
displayAlert({
    variant: 'info',
    message: 'Message without icon',
    icon: undefined
});

Default icon mappings:

  • success - Checkmark icon (✓)
  • danger/error - X icon (×)
  • warning - Exclamation mark (!)
  • info - Information icon (i)
  • loader - Animated spinner

Position Options

  • top-left
  • top-right
  • bottom-left
  • bottom-right

Configuration Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | variant | string | 'primary' | Alert type ('success', 'error', 'warning', 'info', 'white', 'loader') | | message | string | - | Alert message content | | timeout | number | 5000 | Time in ms before alert auto-hides (0 for no auto-hide) | | position | string | 'bottom-right' | Alert position on screen | | fadeDirection | string | 'none' | Direction of fade animation | | icon | string | variant default | Icon type to display ('success', 'danger', 'warning', 'info', 'loader'). Each variant has a default icon, but you can override it or set to undefined for no icon | | closeBtn | boolean | true | Show/hide close button | | multiple | boolean | false | Allow multiple alerts | | backdrop | boolean | false | Show backdrop behind alert |

Browser Support

  • Chrome (latest)
  • Firefox (latest)
  • Safari (latest)
  • Edge (latest)

License

MIT License