{"version":3,"file":"Floated-ab8a907a.js","sources":["../src/components/Floated.jsx"],"sourcesContent":["import React, { useId, useRef, useLayoutEffect, useEffect } from 'react';\nimport PropTypes from 'prop-types';\nimport styles from '@styles/Floated.module.css';\nimport { MdOutlineClose } from 'react-icons/md';\n\n//modal: fullscreen modal in small view\n//fuild: min-width: 100%\nfunction Floated({\n active = false,\n setActive = () => {},\n onClose = () => {},\n children,\n style,\n modal = false,\n fluid = false,\n locked = false,\n ...rest\n}) {\n const uniqueID = useId();\n const ref = useRef();\n const prevIsActiveRef = useRef(active);\n\n //NOTE: useLayoutEffect is a version of useEffect that fires before the browser repaints the screen.\n useEffect(() => {\n const handler = (e) => {\n if (ref.current.getAttribute('locked') == 'true') return;\n // if action is on the element or its children, do nothing\n if (!ref.current.contains(e.target)) {\n // console.log('not inside');\n setActive(false);\n }\n };\n //NOTE: mousedown is different to click\n document.addEventListener('mousedown', handler);\n return () => {\n // cleanup\n // console.log('cleanup Floated');\n document.removeEventListener('mousedown', handler);\n };\n }, []);\n\n useEffect(() => {\n // Only run if previous state was true and current is false\n if (prevIsActiveRef.current === true && active === false) {\n // console.log('State changed from true to false!');\n // Your logic here\n onClose();\n }\n prevIsActiveRef.current = active;\n }, [active]);\n\n return (\n