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

better-alerts

v1.0.32

Published

Library for easy, configurable alerts

Downloads

13

Readme

logo

Navigation


Description

Simple library for creating fancy alerts/modals on your websites. Written with Typescript without any JS animation library.

Installation


Webpack
npm install --save better-alerts
yarn add better-alerts
CDN
//Styles
<link href="https://cdn.jsdelivr.net/npm/[email protected]/lib/styles/better-alerts.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/lib/styles/svg-icons-animate.css" rel="stylesheet">

//Script
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/browser.js"></script>

Modal Usage

Single line
import BetterAlerts from "better-alerts";
import "better-alerts/lib/styles/better-alerts.css";
import "better-alerts/lib/styles/svg-icons-animate.css";

BetterAlerts.modal({ title: "Test." }).fire();

example1


Without main function export
import { modal } from "better-alerts";
import "better-alerts/lib/styles/better-alerts.css";
import "better-alerts/lib/styles/svg-icons-animate.css";

modal({ title: "Shortest way" }).fire()

Modal variable and more complex configuration
import BetterAlerts from "better-alerts";
import "better-alerts/lib/styles/better-alerts.css";
import "better-alerts/lib/styles/svg-icons-animate.css";

const { 
    fire, 
    isVisible, 
    close, 
    container, 
    options 
} = BetterAlerts.modal({
    title: "I'M BIG!",
    text: "What does our customer think?",
    icon: "success",
    showDenyButton: true,
    denyButtonText: "NO!",
    confirmButtonText: "YES",
})

const { result, modal } = await fire();

example2


Close time
import BetterAlerts from "better-alerts";
import "better-alerts/lib/styles/better-alerts.css";
import "better-alerts/lib/styles/svg-icons-animate.css";

BetterAlerts.modal({ 
    title: "Test.",
    closeTime: 1500 //1.5s
}).fire();

Image
import BetterAlerts from "better-alerts";
import "better-alerts/lib/styles/better-alerts.css";
import "better-alerts/lib/styles/svg-icons-animate.css";

BetterAlerts.modal({ 
    title: "Image Test.",
    image: {
        url: "https://unsplash.it/400/200",
        width: 400,
        height: 200,
    }
}).fire();

example4


Modal result
import BetterAlerts from "better-alerts";
import "better-alerts/lib/styles/better-alerts.css";
import "better-alerts/lib/styles/svg-icons-animate.css";

const { fire } = BetterAlerts.modal({
    showDenyButton: true,
    showConfirmButton: true,
    denyButtonText: "Abandon mission",
    confirmButtonText: "Follow train",
    icon: "error",
    title: "Ah shit, here we go again.",
    text: "All you had to do is follow the damn train CJ",
});

const { action } = await fire();

if(action === "confirm"){
    BetterAlerts.modal({ 
        title: "Good job bro.",
        showConfirmButton: true,
        confirmButtonText: "OK",
        icon: "success",
        image: {
            width: 300,
            url: "https://i.imgur.com/voWnwpi.png",
            alt: "Respect+"
        }
    }).fire();

    return;
}

BetterAlerts.modal({ 
    title: "Oh man.",
    showConfirmButton: true,
    confirmButtonText: "OK",
    icon: "error",
    image: {
        width: 300,
        url: "https://i.imgur.com/jLaYy5d.png",
        alt: "Failed"
    }
}).fire();

example5


Toast usage

Single line
import BetterAlerts from "better-alerts";
import "better-alerts/styles/better-alerts.css";
import "better-alerts/styles/svg-icons-animate.css";

BetterAlerts.toast({ text: "Test toast" }).fire();

example6


Without main function export
import { toast } from "better-alerts";
import "better-alerts/styles/better-alerts.css";
import "better-alerts/styles/svg-icons-animate.css";

toast({ text: "Test toast" });

More complex configuration
import { toast } from "better-alerts";
import "better-alerts/styles/better-alerts.css";
import "better-alerts/styles/svg-icons-animate.css";

toast({
    text: "It's easy",
    icon: "Success",
    textColor: "white",
    background: "black",
    pauseOnHover: false,
    progressBar: true,
    progressBarColor: "cyan",
    closeOnClick: false,
    position: "left",
    closeTime: 3000
})

example7


Documentation

BetterAlerts

Property | Type | Description --- | --- | --- container | HTMLElement | undefined | Container for modals and toasts modal | (options: ModalOptions | undefined) => Modal | Function for creating modals toast | (options: ToastOptions | undefined) => Toast | Function for creating toasts


Modal

Property | Type | Description --- | --- | --- options | ModalOptions | undefined | Modal options isVisible | boolean | Return visible state of modal | fire | () => Promise<Result> | Fire modal close | () => Promise<void> | Close modal container | HTMLElement | HTML element for modal


Modal options

Property | Type | Description --- | --- | --- icon | Icon | An icon displayed when modal is fired title | string | Modal title, h2 tag text | string | Modal text under title, p tag position | Position | A position where modal will be fired showDenyButton | boolean | Decides about showing deny button denyButtonText | string | Text displayed on a deny button denyButtonColor | string | Color of deny button showConfirmButton | boolean | Decides about showing confirm button confirmButtonText | string | Text displayed on a confirm button confirmButtonColor | string | Color of confirm button showCancelButton | boolean | Decides about showing cancel button cancelButtonText | string | Text displayed on a cancel button cancelButtonColor | string | Color of cancel button closeTime | number | Modal auto close time | width | number | Modal box width | height | number | Modal box height | image | Image | Shows an image in modal


Image

Property | Type | Description --- | --- | --- url | string| Url of image width | number | Image width height | number | Image height alt | string | Alt text for img tag


Toast

Property | Type | Description --- | --- | --- fire | () => void | Fire a toast container | HTMLElement | Toast container options | Toast options | Toast options


Toast options

Property | Type | Description --- | --- | --- text | string | Toast text background | string | Toast background textColor | string | Toast text color closeTime | number | Time until toast will close position | SimplePosition | Toast position progressBar | boolean | Decides about showing progressbar progressBarColor | string | Progres bar color pauseOnHover | boolean | Decides about posibility to pause toast progress on hover closeOnClick | boolean | If set to true, you can remove toast by clicking whole container (not only 'X') icon | Icon | Toast icon


Simple position

Name | --- | left | right | center |

Result

Property | Type | Description --- | --- | --- action | Action | Action did to modal: close, confirm, deny modal | Modal | Modal that has been closed


Action

Property | Value | --- | --- | confirm | confirm cancel | cancel deny | deny


Icon

Name| ---| error | success | info | warning | question | none |


Position

Name | --- | top-left | top-center | top-right | bottom-left | bottom-center | bottom-right | center-left | center-center | center-right |


To do list

  • ~~Add Toasts~~
  • Custom HTML in modals
  • ~~CDN~~
  • Toast promisses