Swal.js 806 B

123456789101112131415161718192021222324252627282930313233343536
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. // Sweet Alert
  4. import swal from 'sweetalert';
  5. /**
  6. * Wrapper component for sweetalert plugin
  7. */
  8. const Swal = props => {
  9. const handleClick = e => {
  10. e.preventDefault();
  11. // pass swal reference so is possible to chain popups
  12. swal(props.options).then(p => props.callback(p, swal));
  13. }
  14. const { callback, ...rest } = props;
  15. return (
  16. <div {...rest} onClick={handleClick}>
  17. {props.children}
  18. </div>
  19. )
  20. }
  21. Swal.propType = {
  22. /** swal options object */
  23. options: PropTypes.object.isRequired,
  24. /** callback function for swal response */
  25. callback: PropTypes.func
  26. }
  27. Swal.defaultProps = {
  28. callback: () => {}
  29. }
  30. export default Swal;