Need help with sweetalert?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

t4t5
21.6K Stars 2.9K Forks MIT License 359 Commits 162 Opened issues

Description

A beautiful replacement for JavaScript's "alert"

Services available

!
?

Need anything else?

Contributors list

# 2,064
Elixir
phoenix...
TypeScr...
Firebas...
139 commits
# 20,665
webos
React
sweetal...
TypeScr...
8 commits
# 24,843
CSS
TypeScr...
sw-prec...
sweetal...
5 commits
# 28,530
sweetal...
TypeScr...
CSS
5 commits
# 28,250
imagema...
ctypes
CSS
sweetal...
5 commits
# 32,554
Laravel
profili...
sweetal...
TypeScr...
4 commits
# 2,470
JavaScr...
SQL
schema-...
SQLite
3 commits
# 6,157
wechat-...
mac
alfred
omil
3 commits
# 34,694
CSS
TypeScr...
sw-prec...
sweetal...
3 commits
# 27,962
sweetal...
TypeScr...
CSS
tour
3 commits
# 625
React
Electro...
curry
ESLint
3 commits
# 1,547
Shell
templat...
Gulp
mdl
3 commits
# 26,256
CSS
TypeScr...
webasse...
Angular
2 commits
# 49,344
twilio
sweetal...
TypeScr...
CSS
2 commits
# 45,832
CSS
TypeScr...
arcgis
sweetal...
2 commits
# 869
Shell
CSS
Bootstr...
skype
2 commits
# 49,234
CSS
TypeScr...
node
sketcha...
2 commits
# 45,587
CSS
Webpack
reactjs
sweetal...
2 commits
# 17,582
android...
Java
Android
sweetal...
2 commits
# 46,180
sweetal...
TypeScr...
CSS
Shell
2 commits

SweetAlert

A beautiful replacement for JavaScript's "alert"

npm version Build status

A success modal

Installation

$ npm install --save sweetalert

Usage

import swal from 'sweetalert';

swal("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:

swal("Oops!", "Something went wrong!", "error");

A warning message, with a function attached to the confirm message:

  • Using promises:
    javascript
    swal({
    title: "Are you sure?",
    text: "Are you sure that you want to leave this page?",
    icon: "warning",
    dangerMode: true,
    })
    .then(willDelete => {
    if (willDelete) {
      swal("Deleted!", "Your imaginary file has been deleted!", "success");
    }
    });
    
  • Using async/await: ```javascript const willDelete = await swal({ title: "Are you sure?", text: "Are you sure that you want to delete this file?", icon: "warning", dangerMode: true, });

if (willDelete) { swal("Deleted!", "Your imaginary file has been deleted!", "success"); } ```

A prompt modal, where the user's input is logged:

  • Using promises:
    javascript
    swal("Type something:", {
    content: "input",
    })
    .then((value) => {
    swal(`You typed: ${value}`);
    });
    
  • Using async/await: ```javascript const value = await swal("Type something:", { content: "input", });

swal(

You typed: ${value}
); ```

In combination with Fetch:

  • Using promises:
    javascript
    swal({
    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 => {
    swal("Oops!", "Seems like we couldn't fetch the info", "error");
    });
    
  • Using async/await: ```javascript const willSearch = await swal({ 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) { swal("Oops!", "Seems like we couldn't fetch the info", "error"); } } ```

Using with React

SweetAlert has tools for integrating with your favourite rendering library..

If you're using React, you can install SweetAlert with React in addition to the main library, and easily add React components to your alerts like this:

import React from 'react'
import swal from '@sweetalert/with-react'

swal(

Hello world!

This is now rendered with JSX!

)

Read more about integrating with React

Contributing

If you're changing the core library:

  1. Make changes in the
    src
    folder.
  2. Preview changes by running
    npm run docs
  3. Submit pull request

If you're changing the documentation:

  1. Make changes in the
    docs-src
    folder.
  2. Preview changes by running
    npm run docs
  3. Run
    npm run builddocs
    to compile the changes to the
    docs
    folder
  4. Submit pull request

Contributors

This project exists thanks to all the people who contribute. [Contribute].

Backers

Thank you to all our backers! 🙏 [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.