Voltar ao ranking

t4t5/sweetalert

TypeScriptsweetalert.js.org

A beautiful replacement for JavaScript's "alert"

modalsweetalertjavascriptpopupdialogalertui
Crescimento de estrelas
Estrelas
22.3k
Forks
2.8k
Crescimento semanal
Issues
166
10k20k
jan. de 2023mar. de 2024mai. de 2025jul. de 2026
Artefatosnpmnpm install sweetalert
README

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 surprises!

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:
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:
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:
swal("Type something:", {
  content: "input",
})
.then((value) => {
  swal(`You typed: ${value}`);
});
  • Using async/await:
const value = await swal("Type something:", {
  content: "input",
});

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

In combination with Fetch:

  • Using promises:
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:
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(
  <div>
    <h1>Hello world!</h1>
    <p>
      This is now rendered with JSX!
    </p>
  </div>
)

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]

Repositórios relacionados
sweetalert2/sweetalert2

✨ A beautiful, responsive, highly customizable and accessible (WAI-ARIA) replacement for JavaScript's popup boxes. Zero dependencies. 🇺🇦🇪🇺

JavaScriptnpmMIT Licensesweetalertalert
sweetalert2.github.io
18.1k1.6k
gorhom/react-native-bottom-sheet

A performant interactive bottom sheet with fully configurable options 🚀

TypeScriptnpmMIT Licensebottom-sheetbottomsheet
gorhom.dev/react-native-bottom-sheet/
9k957
x-extends/vxe-table

vxe table 支持 vue2, vue3 的表格解决方案

TypeScriptnpmMIT Licensevxe-tablevue
vxetable.cn
8.6k1.1k
ng-bootstrap/ng-bootstrap

Angular powered Bootstrap

TypeScriptnpmMIT Licenseangularng-bootstrap
ng-bootstrap.github.io
8.2k1.6k
reactjs/react-modal

Accessible modal dialog component for React

JavaScriptnpmMIT Licensereactjavascript
reactcommunity.org/react-modal
7.4k812
fancyapps/fancybox

jQuery lightbox script for displaying images, videos and more. Touch enabled, responsive and fully customizable.

JavaScriptnpmfancyboxlightbox
fancyapps.com
7.2k1.7k
react-native-modal/react-native-modal

An enhanced, animated, customizable Modal for React Native.

TypeScriptnpmMIT Licensereact-nativereact
5.7k656
algolia/autocomplete

🔮 Fast and full-featured autocomplete library

TypeScriptnpmMIT Licenseautocompletedropdown
alg.li/autocomplete
5.3k340
jschr/bootstrap-modal

Extends the default Bootstrap Modal class. Responsive, stackable, ajax and more.

JavaScriptnpmApache License 2.0bootstrapbootstrap-modal
jschr.github.io/bootstrap-modal/
5k1.1k
willmcpo/body-scroll-lock

Body scroll locking that just works with everything 😏

JavaScriptnpmMIT Licensebody-scroll-lockreact-scroll-lock
4.1k326
Orderella/PopupDialog

A simple, customizable popup dialog for iOS written in Swift. Replaces UIAlertController alert style.

SwiftOtherpopup-dialogpopup
mwfire.de
4k518
ramonszo/zuck.js

A javascript library that lets you add stories EVERYWHERE.

TypeScriptnpmMIT Licensestoriesstory
ramon.codes/projects/zuck.js/
3.7k311