This is just a technology testing project based on Create React App and TailwindCSS
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

74 lines
2.5KB

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