import React, { useRef, useState } from 'react'; import { Dialog as HDialog } from '@headlessui/react'; import { Button } from '@/components/elements/button/index'; import { XIcon } from '@heroicons/react/solid'; import { AnimatePresence, motion } from 'framer-motion'; import { DialogContext, IconPosition, RenderDialogProps, styles } from './'; const variants = { open: { scale: 1, opacity: 1, transition: { type: 'spring', damping: 15, stiffness: 300, duration: 0.15, }, }, closed: { scale: 0.75, opacity: 0, transition: { type: 'easeIn', duration: 0.15, }, }, bounce: { scale: 0.95, opacity: 1, transition: { type: 'linear', duration: 0.075 }, }, }; export default ({ open, title, description, onClose, hideCloseIcon, preventExternalClose, children, }: RenderDialogProps) => { const container = useRef(null); const [icon, setIcon] = useState(); const [footer, setFooter] = useState(); const [iconPosition, setIconPosition] = useState('title'); const [down, setDown] = useState(false); const onContainerClick = (down: boolean, e: React.MouseEvent): void => { if (e.target instanceof HTMLElement && container.current?.isSameNode(e.target)) { setDown(down); } }; const onDialogClose = (): void => { if (!preventExternalClose) { return onClose(); } }; return ( {open && (
{iconPosition === 'container' && icon}
{iconPosition !== 'container' && icon}
{title && ( {title} )} {description && ( {description} )}
{children}
{footer} {/* Keep this below the other buttons so that it isn't the default focus if they're present. */} {!hideCloseIcon && (
)}
)} ); };