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

@bjnstnkvc/alert

v1.0.6

Published

Simple JavaScript Alert library.

Downloads

3

Readme

Alert

Simple JavaScript Alert library.

Installation & setup

NPM

You can install the package via npm:

npm install @bjnstnkvc/alert

Once the package has been installed, you can import it using import declaration:

import Alert from '@bjnstnkvc/alert'

Additionally, you can import default library styles:

import '@bjnstnkvc/alert/src/alert.css'

CDN

You can install the package via jsDelivr CDN:

<script src="https://cdn.jsdelivr.net/npm/@bjnstnkvc/alert/lib/Alert.min.js"></script>

Additionally, you can import default library styles:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@bjnstnkvc/alert/src/alert.css">

Usage

Once imported, you can make an AJAX request using the following methods:

new Alert({ config })

Config

In order to create an Alert, you need to pass config object. The Config object consists of the following properties:

container

A string representing the DOM element to which Alert will be appended (defaults to body):

new Alert({
    container: '.element',
})

type

A string representing the type of Alert. The library comes with 4 predefined types (success, error, warning and info)

new Alert({
    type: 'success',
    ...
})

Depending on the type of choice, an Alert will look as follows:

| success | error | warning | info | |-------------------------------------------|---------------------------------------|-------------------------------------------|-------------------------------------| | Success Alert | Error Alert | Warning Alert | Info Alert |

message

A string representing an Alert message:

new Alert({
    type: 'error',
    message: 'Something went wrong!', 
    ...
})

You can also pass HTML to the property:

new Alert({
    type: 'error',
    message: '<strong>Oops!</strong> Something went wrong.' ,
    ...
})

Example above would generate the following Alert:

Error Alert with HTML message

duration

An integer value that determines for how long an Alert should be displayed (defaults to 5 seconds).

new Alert({
    duration: 10,
    ...
})

expires

A boolean value that determines whether an Alert should expire/auto-close (defaults to true).

new Alert({
    expires: false,
    ...
})

info

If passed as boolean, this property determines whether an Alert should have an info icon (defaults to true):

new Alert({
    type: 'success',
    message: 'Payment completed!',
    info: false,
    ...
})

Example above would generate the following Alert:

Alert without HTML info icon

You can pass an HTML string, which will then be rendered instead of a default icon:

new Alert({
    type: 'success',
    message: 'Payment completed!',
    info: '<i class="far fa-credit-card"></i>',
    ...
})

Example above would generate the following Alert:

Alert with HTML info icon

Note: Example above uses FontAwesome in order to display the icon which needs to be imported.

close

If passed as boolean, this property determines whether an Alert should have a close icon (defaults to true):

new Alert({
    type: 'info',
    message: 'Profile updated!',
    close: false,
    ...
})

Example above would generate the following Alert:

Alert without HTML close icon

You can pass an HTML string, which will then be rendered instead of a default icon:

new Alert({
    type: 'info',
    message: 'Profile updated!',
    icon: '<i class="far fa-times-circle"></i>',
    ...
})

Example above would generate the following Alert:

Alert with HTML close icon

Note: Example above uses FontAwesome in order to display the icon which needs to be imported.

withProgress

A boolean value which determines whether an Alert should have a progress bar (defaults to false):

new Alert({
    type: 'info',
    message: 'Verification email sent!',
    withProgress: true
})

Example above would generate the following Alert:

Alert with Progress Bar

Customization

colors

As mentioned in a type section, the library comes with 4 predefined types (success, error, warning and info).

In case you would like to change the color pallet, you have 2 options:

  1. Change the color by redefining CSS variables:
:root {
    --alert-success : rgba(118, 189, 87, 1);
    --alert-error   : rgba(214, 45, 48, 1);
    --alert-warning : rgba(238, 146, 19, 1);
    --alert-info    : rgba(63, 175, 239, 1);
}
  1. Change the color by setting redefining CSS classes:
.alert-success {
    color : rgba(118, 189, 87, 1);
}

.alert-error {
    color : rgba(214, 45, 48, 1);
}

.alert-warning {
    color : rgba(238, 146, 19, 1);
}

.alert-info {
    color : rgba(63, 175, 239, 1);
}

types

You can set your own Alert types, simply by passing it to the constructor. The library will dynamically create a CSS class when generating an Alert.

new Alert({
    type: 'emergency',
    ...
})

Example above would generate the following HTML class:

<div class="alert alert-emergency alert-is-open" role="alert">
    ...
</div>

styles

Alert is made of following CSS classes:

  1. alert - Alert container.
  2. alert__info - Alert Info icon element.
  3. alert__message - Alert Message element.
  4. alert__close - Alert Close icon element.
  5. alert__progress - Alert Progress Bar element.
  6. alert-is-open - Class that's utilized when the Alert is open.
  7. alert-is-closed - Class that's utilized prior to Alert being closed.

Feel free to redeclare these classes in your own CSS files and overwrite their properties in order to customize the Alert to your liking.