Package Exports
- craftalert
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (craftalert) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
A beautiful replacement for JavaScript's "alert"
Installation
$ npm install --save craftalertUsage
import cral from 'craftalert'
cral("Hello world!")Upgrading from 1.X
Many improvements and breaking changes have been introduced in the 2.0 release. Make sure you read the upgrade guide to avoid nasty suprises!
Guides
Documentation
Examples
An error message:
cral("Oops!", "Something went wrong!", "error")A warning message, with a function attached to the confirm message:
- Using promises:
cral({
title: "Are you sure?",
text: "Are you sure that you want to leave this page?",
icon: "warning",
dangerMode: true,
})
.then(willDelete => {
if (willDelete) {
cral("Deleted!", "Your imaginary file has been deleted!", "success");
}
});- Using async/await:
const willDelete = await cral({
title: "Are you sure?",
text: "Are you sure that you want to delete this file?",
icon: "warning",
dangerMode: true,
})
if (willDelete) {
cral("Deleted!", "Your imaginary file has been deleted!", "success");
}A prompt modal, where the user's input is logged:
- Using promises:
cral("Type something:", {
content: "input",
})
.then((value) => {
cral(`You typed: ${value}`);
})- Using async/await:
const value = await cral("Type something:", {
content: "input",
})
cral(`You typed: ${value}`);In combination with Fetch:
- Using promises:
cral({
text: 'Wanna log some information about Bulbasaur?',
button: {
text: "Search!",
closeModal: false,
},
})
.then(willSearch => {
if (willSearch) {
return fetch(`http://pokeapi.co/api/v2/pokemon/1`)
}
})
.then(result => result.json())
.then(json => console.log(json))
.catch(err => {
cral("Oops!", "Seems like we couldn't fetch the info", "error")
})- Using async/await:
const willSearch = await cral({
text: 'Wanna log some information about Bulbasaur?',
button: {
text: "Search!",
closeModal: false,
},
})
if (willSearch) {
try {
const result = await fetch(`http://pokeapi.co/api/v2/pokemon/1`)
const json = await result.json()
console.log(json)
} catch (err) {
cral("Oops!", "Seems like we couldn't fetch the info", "error")
}
}Contributing
If you're changing the core library:
- Make changes in the
srcfolder. - Preview changes by running
npm run docs - Submit pull request
If you're changing the documentation:
- Make changes in the
docs-srcfolder. - Preview changes by running
npm run docs - Run
npm run builddocsto compile the changes to thedocsfolder - Submit pull request