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.

68 lines
2.3KB

  1. import React from 'react'
  2. import PropTypes from 'prop-types'
  3. import { motion, AnimatePresence } from "framer-motion"
  4. export const Popup = (props) => {
  5. const { opened, title, close, children } = props
  6. const popupMotionVariants = {
  7. hidden: {
  8. opacity: 0,
  9. scaleY: 0,
  10. transition: {
  11. type: "linear",
  12. duration: .3
  13. }
  14. },
  15. visible: {
  16. opacity: 1,
  17. scaleY: 1,
  18. transition: {
  19. type: "spring",
  20. damping: 50,
  21. stiffness: 50000,
  22. }
  23. },
  24. }
  25. //document.body.style.overflow='hidden';
  26. // Если надо закрывать по клику за попапом, то в первый див надо добавить onClick={close}
  27. return <>
  28. <AnimatePresence>
  29. {opened &&
  30. <div className="modal z-50 fixed w-full min-h-screen top-0 left-0 flex items-center justify-center">
  31. <div className="modal-overlay absolute top-0 left-0 w-full h-full bg-primary-900 opacity-50 backdrop-blur"></div>
  32. <div className="modal-wrapper relative w-full">
  33. <div className="max-w-full max-h-screen sm:max-w-lg mx-auto">
  34. <motion.div
  35. variants={popupMotionVariants}
  36. initial="hidden"
  37. animate="visible"
  38. exit="hidden"
  39. >
  40. <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 transition-opacity duration-300" onClick={e => e.stopPropagation()}>
  41. <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">
  42. <div className="w-full text-xl">{title}</div>
  43. <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" onClick={close}>&times;</button>
  44. </div>
  45. {children}
  46. </div>
  47. </motion.div>
  48. </div>
  49. </div>
  50. </div>
  51. }
  52. </AnimatePresence>
  53. </>
  54. }
  55. export default Popup;
  56. Popup.propTypes = {
  57. opened: PropTypes.bool,
  58. title: PropTypes.string,
  59. close: PropTypes.func,
  60. children: PropTypes.element,
  61. }