sweetalert2

✨ A beautiful, responsive, highly customizable and accessible (WAI-ARIA) replacement for JavaScript's popup boxes. Zero dependencies. đŸ‡ēđŸ‡Ļ

MIT License

Downloads
2.6M
Stars
16.8K
Committers
122

Bot releases are hidden (Show)

sweetalert2 -

Published by limonte almost 7 years ago

Community

  • @acupajoe made a logo for SweetAlert2 🎉 (#726)
  • @toverux delivered the new major release with a lot of improvements for Angular developers toverux/ngx-sweetalert2 🚀
  • @zenflow is now the collaborator, welcome to the team! đŸĨ‡

Other improvements and bug-fixes:

sweetalert2 -

Published by limonte almost 7 years ago

đŸĨ‡ This release is delivered because of the awesomeness of these people (ordered a-z): @acupajoe, @limonte, @samturrell, @toverux, @zenflow

🔴 Breaking change # 1 - useRejections

⚠ī¸ useRejections is now false default, set it to true if you want backward compatibility with previous versions (<7.0.0)

Before you were handling dismissals in the rejection handler: [JSFIDDLE ↗]

swal({
  ...
}).then(
  value => {
    // handle confirm
  },
  dismiss => {
    // handle dismiss
  }
).catch(swal.noop)

Now you should handle both confirmations and dismissals in the fulfillment handler: [JSFIDDLE ↗]

swal({
  ...
}).then(result => {
  if (result.value) {
    // handle confirm
    console.log(result.value)
  } else {
    // handle dismiss, result.dismiss can be 'cancel', 'overlay', 'close', and 'timer'
    console.log(result.dismiss)
  }
})

In order to have painless backward compatibility with previous versions, use useRejections: true [JSFIDDLE ↗]

swal({
  useRejections: true           // <<<<<<------- BACKWARD COMPATIBILITY WITH v6.x
}).then(
  value => {
    // handle confirm
  },
  dismiss => {
    // handle dismiss
  }
).catch(swal.noop)

ℹī¸ Since we are not rejecting promise by default, .catch(swal.noop) isn't needed anymore.

⚠ī¸ useRejections is deprecated and will be removed in the next major release.

🔴 Breaking change # 2 - preConfirm

preConfirm shouldn't reject a promise with an error message, instead it should show an error with swal.showValidationError(message) and fulfill a promise:

Before:

preConfirm: (email) => {
  return new Promise((resolve, reject) => {
    if (email === '[email protected]') {
      reject('This email is already taken.')
    }
    resolve()
  })
}

After:

preConfirm: (email) => {
  return new Promise((resolve) => {
    if (email === '[email protected]') {
      swal.showValidationError('This email is already taken.')
    }
    resolve()
  })
}

🔴 Breaking change # 3 - inputValidator

inputValidator shouldn't reject a promise with an error message, instead, it should fulfill a promise with an error string:

Before:

inputValidator: (email) => {
  return new Promise((resolve, reject) => {
    if (email === '[email protected]') {
      reject('This email is already taken.')
    }
    resolve()
  })
}

After:

preConfirm: (email) => {
  return new Promise((resolve) => {
    if (email === '[email protected]') {
      resolve('This email is already taken.')
    }
    resolve()
  })
}

🔴 Breaking change # 4 - default entry point

  • default entry point is now dist/sweetalert2.all.js (#692 #612 #422).
    • before: import swal from 'sweetalert2/dist/sweetalert2.all.js'
    • now: import swal from 'sweetalert2'

⚠ī¸ It's not needed to import CSS styles separately, they are included in dist/sweetalert2.all.js.

🎉 New features

  • Ability to use with async/await (#485 #700)
const {value: name} = await swal({text: 'What is your name?', input: 'text'})
const {value: location} = await swal({text: 'Where are you from?', input: 'text'})

swal(`Hi ${name}, from ${location}!`)
  • Toasts/growl functionality (#663 #670)
swal({
  text: 'Your work has been saved',
  toast: true
})
  • backdrop parameter, default true (#680 #681)
swal({
  text: 'I will not add a backdrop to the document',
  backdrop: false
})

⚠ī¸ Deprecated parameters

These parameter are now deprecated and will be removed in the next major release:

  • useRejections
  • expectRejections
sweetalert2 -

Published by limonte almost 7 years ago

sweetalert2 -

Published by limonte almost 7 years ago

  • fix the centering in IE11 (#687)
sweetalert2 -

Published by limonte almost 7 years ago

Special thanks to @samturrell đŸģ

sweetalert2 -

Published by limonte almost 7 years ago

sweetalert2 -

Published by limonte almost 7 years ago

sweetalert2 -

Published by limonte about 7 years ago

  • add position and grow options #668 - special thanks to @acupajoe
  • add onBeforeOpen option to call function when dialog is built but not shown yet #669 - special thanks to @sedx
sweetalert2 -

Published by limonte about 7 years ago

  • fix cases when inputValue isn't String (#662)
  • add aria-modal="true" for .swal2-modal (#657)
  • stabilize visual tests by blurring the confirm button before taking screenshot (#656)
sweetalert2 -

Published by limonte about 7 years ago

sweetalert2 -

Published by limonte about 7 years ago

sweetalert2 - dist/sweetalert2.all.min.js

Published by limonte about 7 years ago

  • add all-in-one dist file dist/sweetalert2.all.min.js with CSS bundled into JS (#644)
  • throw a warning when Promise is not defined, DX improvement (#645)

This release was delivered by ninja master @samturrell đŸģ

You can now import all-in-one file with JS + CSS:

import swal from 'sweetalert2/dist/sweetalert2.all.min.js'
sweetalert2 -

Published by limonte about 7 years ago

  • remove MSAnimationEnd, fix #626 #627 #615 #635
sweetalert2 -

Published by limonte about 7 years ago

  • add focusConfirm parameter (#620), true by default for backwards compatibility. If set to false, the first element in tab order inside the modal will be focused, see the example: https://limonte.github.io/sweetalert2/#custom-html
  • add closeButtonAriaLabel parameter (#621)
  • demonstrate onOpen and showLoading() in timer example:
  • add aria-busy state for loading state (#622)
  • add labels for input fields in demo page
sweetalert2 -

Published by limonte about 7 years ago

sweetalert2 -

Published by limonte about 7 years ago

  • added aria-label support for buttons: confirmButtonAriaLabel and cancelButtonAriaLabel (#608)
  • added collaborators list to README and docs page (#614)
  • improved readability (increase font contrast) of examples page
  • removed sass mixins, they were excessive
  • fix examples page for IE11
  • remove gemini tests because of their instability, visual test will be implemented with puppeteer in one of upcoming releases
sweetalert2 -

Published by limonte about 7 years ago

  • allow for jQuery objects in html property in TS definitions (#604) thanks to @gronostajo đŸģ
  • improve inpuPlaceholder's visibility
  • use inputPlaceholder to some of examples
  • improve docs about the showLoaderOnConfirm parameter
sweetalert2 -

Published by limonte about 7 years ago

  • throw warning if showLoaderOnConfirm is true, but preConfirm is not defined (conected to #600)
  • add CODE_OF_CONDUCT.md
  • order focusable elements according to their tabindex (#598)
  • Add sweetalert2-polymer link to README
sweetalert2 -

Published by limonte about 7 years ago

  • target could be string or element (#592) many thanks to @orbweaver- đŸģ
  • add swal.isValidParameter() (#595)
sweetalert2 -

Published by limonte about 7 years ago

  • correct type definition of SweetAlertOptions.progressSteps (#575) thanks to @michaelbull đŸģ
  • fix syntax errors in scss (#591) thanks to @simshaun đŸģ