1.0.32 • Published 2 years ago

better-alerts v1.0.32

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

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/better-alerts@1.0.31/lib/styles/better-alerts.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/better-alerts@1.0.31/lib/styles/svg-icons-animate.css" rel="stylesheet">

//Script
<script src="https://cdn.jsdelivr.net/npm/better-alerts@1.0.31/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

PropertyTypeDescription
containerHTMLElement | undefinedContainer for modals and toasts
modal(options: ModalOptions | undefined) => ModalFunction for creating modals
toast(options: ToastOptions | undefined) => ToastFunction for creating toasts

Modal

PropertyTypeDescription
optionsModalOptions | undefinedModal options
isVisiblebooleanReturn visible state of modal
fire() => Promise<Result>Fire modal
close() => Promise<void>Close modal
containerHTMLElementHTML element for modal

Modal options

PropertyTypeDescription
iconIconAn icon displayed when modal is fired
titlestringModal title, h2 tag
textstringModal text under title, p tag
positionPositionA position where modal will be fired
showDenyButtonbooleanDecides about showing deny button
denyButtonTextstringText displayed on a deny button
denyButtonColorstringColor of deny button
showConfirmButtonbooleanDecides about showing confirm button
confirmButtonTextstringText displayed on a confirm button
confirmButtonColorstringColor of confirm button
showCancelButtonbooleanDecides about showing cancel button
cancelButtonTextstringText displayed on a cancel button
cancelButtonColorstringColor of cancel button
closeTimenumberModal auto close time
widthnumberModal box width
heightnumberModal box height
imageImageShows an image in modal

Image

PropertyTypeDescription
urlstringUrl of image
widthnumberImage width
heightnumberImage height
altstringAlt text for img tag

Toast

PropertyTypeDescription
fire() => voidFire a toast
containerHTMLElementToast container
optionsToast optionsToast options

Toast options

PropertyTypeDescription
textstringToast text
backgroundstringToast background
textColorstringToast text color
closeTimenumberTime until toast will close
positionSimplePositionToast position
progressBarbooleanDecides about showing progressbar
progressBarColorstringProgres bar color
pauseOnHoverbooleanDecides about posibility to pause toast progress on hover
closeOnClickbooleanIf set to true, you can remove toast by clicking whole container (not only 'X')
iconIconToast icon

Simple position

Name
left
right
center

Result

PropertyTypeDescription
actionActionAction did to modal: close, confirm, deny
modalModalModal that has been closed

Action

PropertyValue
confirmconfirm
cancelcancel
denydeny

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
1.0.2

2 years ago

1.0.32

2 years ago

1.0.31

2 years ago

1.0.3

2 years ago

1.0.133

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago