1.0.0 • Published 5 years ago

zino-alert v1.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

JavaScript Alert Web Component

Autonomous open source alert component with RTL support built on Custom Elements and Shadow DOM specifications.

How to use

Installation

  • Install with npm
$ npm install zino-alert
  • Install with bower
$ bower install zino-alert

Using zino-alert

  • HTML way
<zino-alert id="alert-1"
    heading="HTML"
    text="Lorem ipsum dolor sit amet."
    type="success"></zino-alert>

<script type="module" src="../zino-alert.js"></script>

Alert customizations are possible via data-* attributes.

  • using the DOM API
<script type="module" src="../zino-alert.js"></script>

<script>
const alert = document.createElement("zino-alert");
alert.heading = "DOM API";
alert.type = "success";
alert.text = "Autonomous WAI-ARIA accessible alert dialog.";
document.body.appendChild(alert);
alert.open();
</script>
  • using the constructor
<script type="module">
import {ZinoAlert} from "../zino-alert.js";

const alert = new ZinoAlert({
    heading: "Constructor",
    type: "success",
    text: "A web component build on Custom Elements and Shadow DOM APIs.",
    showCancelButton: "true",
    allowEscapeKey: "true"
});
document.body.appendChild(alert);
alert.open();
</script>
Styling
:root {
  --background-head: #fff;
  --color-head: #FA4251;
  --color-head-active: #FA4251;
  --background-foot: #fff;
  --color-foot: #222;
  --background-odd: #fff;
  --background-even: #fff;
  --color-odd: #333;
  --color-even: #222;
}
zino-grid {
  margin: 20px auto 0;
  width: 100%;
  max-width: 1024px;
}

Options

OptionRequiredTypeDefaultDescription
allowEscapeKeyNoBooleantrueWhether to close the alert when the Escape key is pressed
animationNoBooleantrueWhether to use an animation when show the alert
backdropNoBooleantrueWhether to use a backdrop
backgroundNoString#fffThe alert's background color
cancelButtonAriaLabelNoStringCancelThe cancel button's aria-label attribute
cancelButtonColorNoString#aaaThe cancel button's background color
cancelButtonTextNoStringCancelThe cancel button's text
closeButtonAriaLabelNoStringCloseThe close button's aria-label attribute
confirmButtonAriaLabelNoStringOKThe confirm button's aria-label attribute
confirmButtonColorNoString#3085d6The confirm button's background color
confirmButtonTextNoStringOKThe confirm button's text
debugNoBooleanfalseIf true will log events into console
focusCancelNoBooleanfalseWhether to focus on cancel button when alert show
focusConfirmNoBooleantrueWhether to focus on confirm button when alert show
footerNoString(empty)If not empty will show it's content at the alert's footer
headerNoString(empty)If not empty will show it's content at the alert's header
headingNoString(empty)The alert's heading text
positionNoStringcenterThe alert's position. Accepts: top, top-start, top-left, top-end, top-right, center, center-start, center-left, center-end, center-right, bottom, bottom-start, bottom-left, bottom-end, bottom-right
showCancelButtonNoBooleanfalseWhether to show the cancel button
showCloseButtonNoBooleanfalseWhether to show the close button
showConfirmButtonNoBooleantrueWhether to show the confirm button
textNoString(empty)The alert's text
typeYesString(empty)The alert's icon. Accepts: success, error

Methods

MethodDescription
cancelManually triggers the cancel.alert event.
closeManually closes an alert and triggers the close.alert event.
confirmManually triggers the confirm.alert event.
openManually opens an alert and triggers the open.alert event.
document.querySelector("zino-alert").open();

Events

EventDescription
cancel.alertThis event is fired immediately when the Cancel button has been clicked.
close.alertThis event is fired immediately when the close instance method has been called.
confirm.alertThis event is fired immediately when the Confirm button has been clicked.
open.alertThis event is fired immediately when the open instance method has been called.
document.querySelector("zino-alert").addEventListener("close.alert", function(event) {
    // do something...    
});

Browser Support

PolyfillEdgeIE11+Chrome 54+Firefox 63+Safari 10.1+Opera 41+
Yes
No

License

zino-alert is licensed under the MIT license.

Copyright (c) 2019-2020 Dimitar Ivanov