import { styled } from '@stitches/react' import * as DialogPrimitive from '@radix-ui/react-dialog' import { ComponentPropsWithoutRef, ElementRef, forwardRef, ReactNode, useState, } from 'react' import { AnimatePresence, motion } from 'framer-motion' const Overlay = styled(DialogPrimitive.Overlay, { backgroundColor: '$neutralBg', position: 'fixed', inset: 0, zIndex: 5000, }) const AnimatedOverlay = forwardRef< ElementRef, ComponentPropsWithoutRef >(({ ...props }, forwardedRef) => ( )) const Content = styled(DialogPrimitive.Content, { backgroundColor: '$neutralBg', borderRadius: 8, $$shadowColor: '$colors$gray7', boxShadow: '0 4px 8px rgba(0,0,0,0.2), inset 0 2px 2px rgba(255,255,255,0.2)', border: '1px solid $gray7', position: 'fixed', top: '12.5%', left: '50%', transform: 'translateX(-50%)', minWidth: 490, maxWidth: '90vw', maxHeight: '85vh', overflowY: 'auto', '&:focus': { outline: 'none' }, zIndex: 5000, }) const AnimatedContent = forwardRef< ElementRef, ComponentPropsWithoutRef >(({ children, ...props }, forwardedRef) => ( {children} )) type Props = { trigger?: ReactNode portalProps?: DialogPrimitive.PortalProps overlayProps?: DialogPrimitive.DialogOverlayProps open?: ComponentPropsWithoutRef['open'] onOpenChange: ComponentPropsWithoutRef< typeof DialogPrimitive.Root >['onOpenChange'] } const Dialog = forwardRef< ElementRef, ComponentPropsWithoutRef & Props >( ( { children, trigger, portalProps, overlayProps, open, onOpenChange, ...props }, forwardedRef ) => { const [_open, _onOpenChange] = useState(false) return ( {trigger && ( {trigger} )} {open && ( {children} )} ) } ) export { Dialog, Content, AnimatedContent, Overlay, AnimatedOverlay }