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

snap-alert-js

v1.1.0

Published

SnapAlert is a lightweight Javascript plugin that provides customizable and user-friendly alert notifications , Easily display alerts, confirmations, and prompts in your applications with simple methods and flexible options.

Downloads

761

Readme

SnapAlert for Javascript

SnapAlert is a lightweight and customizable Javascript plugin designed for adding stylish alert notifications to your app. This plugin allows you to easily display alerts, confirmations, prompts, and even custom HTML notifications in a user-friendly way.

Installation

Here's how to use SnapAlert in your project:

Installation via CSS

Include the stylesheet on your document's </head> tag.

<head>
  <link rel="stylesheet" href="snapAlert.css">
  <!-- Or -->
  <link rel="stylesheet" href="snapAlert.min.css">
</head>

Instead of installing you may use the remote version.

<head>
  <link rel="stylesheet"
  href="https://cdn.jsdelivr.net/npm/snap-alert-js@latest/dist/snapAlert.css">
  <!-- Or -->
  <link rel="stylesheet"
  href="https://unpkg.com/snap-alert-js@latest/dist/snapAlert.min.css">
</head>

Installation via Javscript

Include the Plugin on your document's before </body> tag.

  <script src="/snap-alert.js">
  <!-- Or -->
  <script src="/snap-alert.min.js"></script>

Instead of installing you may use the remote version.

  <script src="https://cdn.jsdelivr.net/npm/snap-alert-js@latest/dist/snap-alert.js">
  <!-- Or -->
  <script src="https://unpkg.com/snap-alert-js@latest/dist/snap-alert.min.js"></script>

Usage

You can now use SnapAlert to display different types of alerts. Here are some examples:

Basic Alert

SnapAlert.alert('Alert Title', 'This is a basic alert.');

Success Alert

SnapAlert.success('Success', 'Your operation was successful!');

Info Alert

SnapAlert.info('Info', 'Be Notice!');

Error Alert

SnapAlert.error('Error', 'Something went wrong.');

Confirmation Alert with Actions

SnapAlert.warning('Are you sure?', 'This action cannot be undone.', {
  enableConfirm: true,
  enableCancel: true,
  onConfirm: () => {
    console.log('Confirmed!');
  },
  onCancel: () => {
    console.log('Cancelled!');
  }
});

Step 3: Customizing Alerts

You can customize the options for each alert. For example:

SnapAlert.info('Information', 'This is an info alert.', {
  position: 'top right',
  duration: 5000,
  icon: 'custom-icon-class', // Replace with a Boxicons class name (https://boxicons.com)
  isDark: true
});

4. Displaying HTML Alerts

You can display various types of alerts using the provided methods. Below is an example of how to show a custom HTML alert:

SnapAlert.html(`<img src="https://placehold.co/600x400" />`, {
        position: 'top right',
        duration: 5000,
    }
);

Step 5: Set Global Options with SnapOptions

You can use the SnapOptions method to set global default options for all alerts. This is particularly useful if you want to maintain consistency across multiple alerts.

SnapAlert.SnapOptions({
  duration: 5000,
  isDark: true,
  position: 'bottom right'
});

Example of Using Global Options

After setting global options, all subsequent alerts will use the specified default settings unless overridden by individual alert options:

// Set global options
SnapAlert.SnapOptions({
  duration: 4000,
  isDark: false,
});

// Now all alerts will have these default settings
SnapAlert.success('Global Success', 'This alert will use global options.');
SnapAlert.error('Global Error', 'This alert will also use global options.');

clearAll

The clearAll method is used to remove all active alerts from the screen. This can be useful in scenarios where you want to clear multiple notifications at once, such as when navigating away from a page, or after performing a certain action where notifications are no longer relevant.

SnapAlert.clearAll();

This will instantly clear all alerts, including success, error, warning, info, and custom HTML alerts, if any are currently visible.

Available Options

  • rtl: false (Enable/disable right-to-left support)
  • type: 'info', 'success', 'error', 'warning'
  • title: The title of the alert
  • message: The message of the alert
  • position: 'top left', 'top right', 'bottom left', 'bottom right', 'top center', 'bottom center'.
  • duration: Time before auto-close (in milliseconds, default is 3000)
  • autoClose: Automatically close the alert (default is true)
  • enableConfirm: Show confirm button (default is false)
  • onConfirm: Function to execute when confirmed
  • enableCancel: Show cancel button (default is false)
  • onCancel: Function to execute when cancelled
  • isDark: Dark mode for the alert (default is false)
  • icon: Custom icon (default icons are provided)

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Zainalabdeen Radwan
Website | Email