| 1 |
import { Button } from '@wordpress/components'; |
| 2 |
import { useState, useEffect } from '@wordpress/element'; |
| 3 |
import { __ } from '@wordpress/i18n'; |
| 4 |
import { Icon, close } from '@wordpress/icons'; |
| 5 |
import { Dialog, DialogTitle } from '@headlessui/react'; |
| 6 |
import { useGlobalStore } from '@assist/state/globals'; |
| 7 |
|
| 8 |
export const Modal = () => { |
| 9 |
const { modals, popModal } = useGlobalStore(); |
| 10 |
const ModalContent = modals[0]; |
| 11 |
const [title, setTitle] = useState(''); |
| 12 |
|
| 13 |
useEffect(() => { |
| 14 |
if (!modals[0]) setTitle(''); |
| 15 |
}, [modals]); |
| 16 |
|
| 17 |
return ( |
| 18 |
<Dialog |
| 19 |
as="div" |
| 20 |
className="extendify-assist" |
| 21 |
open={modals.length > 0} |
| 22 |
onClose={popModal}> |
| 23 |
<div className="fixed top-0 z-high mx-auto h-full w-full items-center justify-center overflow-hidden p-2 md:flex md:p-6"> |
| 24 |
<div |
| 25 |
className="fixed inset-0 bg-black/40 transition-opacity" |
| 26 |
aria-hidden="true" |
| 27 |
/> |
| 28 |
<div className="relative mx-auto flex flex-col rounded-sm bg-white shadow-2xl sm:flex sm:min-w-md sm:overflow-hidden"> |
| 29 |
<div className="flex items-center justify-between"> |
| 30 |
<DialogTitle className="m-0 px-6 text-base text-gray-900"> |
| 31 |
{title} |
| 32 |
</DialogTitle> |
| 33 |
<Button |
| 34 |
className="m-4 border-0" |
| 35 |
onClick={popModal} |
| 36 |
icon={<Icon icon={close} size={24} />} |
| 37 |
label={__('Close Modal', 'extendify-local')} |
| 38 |
showTooltip={false} |
| 39 |
/> |
| 40 |
</div> |
| 41 |
<div className="relative m-0 p-6 pt-0 text-left"> |
| 42 |
{modals?.length > 0 && ( |
| 43 |
<ModalContent popModal={popModal} setModalTitle={setTitle} /> |
| 44 |
)} |
| 45 |
</div> |
| 46 |
</div> |
| 47 |
</div> |
| 48 |
</Dialog> |
| 49 |
); |
| 50 |
}; |
| 51 |
|