This is just a technology testing project based on Create React App and TailwindCSS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 line
2.3KB

  1. import React from 'react'
  2. import PropTypes from 'prop-types'
  3. import { motion, AnimatePresence } from "framer-motion"
  4. import { RemoveScroll } from 'react-remove-scroll'
  5. export const Popup = (props) => {
  6. const { opened, title, close, children } = props
  7. const popupMotionVariants = {
  8. hidden: {
  9. opacity: 0,
  10. scaleY: 0,
  11. transition: {
  12. type: "linear",
  13. duration: .3
  14. }
  15. },
  16. visible: {
  17. opacity: 1,
  18. scaleY: 1,
  19. transition: {
  20. type: "spring",
  21. damping: 50,
  22. stiffness: 50000,
  23. }
  24. },
  25. }
  26. return <>
  27. <AnimatePresence>
  28. {opened &&
  29. <div className="modal z-50 fixed w-full min-h-screen top-0 left-0 flex items-center justify-center">
  30. <div className="modal-overlay absolute top-0 left-0 w-full h-full bg-primary-900 opacity-50 backdrop-blur"></div>
  31. <div className="modal-wrapper relative w-full">
  32. <div className="max-w-full max-h-screen sm:max-w-lg mx-auto">
  33. <motion.div
  34. variants={popupMotionVariants}
  35. initial="hidden"
  36. animate="visible"
  37. exit="hidden"
  38. >
  39. <div tabIndex="0" aria-label={title} aria-modal className="ma-0 bg-gray-200 shadow-lg border-white border-t-2 border-b-2 sm:border-2 sm:mx-4 sm:rounded-lg focus:outline-none" onClick={e => e.stopPropagation()}>
  40. <div className="px-3 h-12 bg-primary-800 text-white border-b sm:rounded-t-lg border-white font-semibold relative flex items-center">
  41. <div className="w-full text-xl truncate pr-6">{title}</div>
  42. <button type="button" aria-label="Close modal" className="absolute top-0 right-0 w-12 h-12 pb-1 text-3xl leading-none cursor-pointer flex items-center justify-center transform origin-center hover:scale-125 active:scale-110 focus:outline-none" onClick={close}>&times;</button>
  43. </div>
  44. <RemoveScroll removeScrollBar={false}>
  45. {children}
  46. </RemoveScroll>
  47. </div>
  48. </motion.div>
  49. </div>
  50. </div>
  51. </div>
  52. }
  53. </AnimatePresence>
  54. </>
  55. }
  56. export default Popup;
  57. Popup.propTypes = {
  58. opened: PropTypes.bool,
  59. title: PropTypes.string,
  60. close: PropTypes.func,
  61. children: PropTypes.element,
  62. }