'use client'; import * as React from 'react'; import { Dialog as DialogPrimitive } from 'radix-ui'; import { X } from 'lucide-react'; import { AnimatePresence, motion, type HTMLMotionProps, type Transition, } from 'motion/react'; import { cn } from '@workspace/ui/lib/utils'; type DialogContextType = { isOpen: boolean; }; const DialogContext = React.createContext( undefined, ); const useDialog = (): DialogContextType => { const context = React.useContext(DialogContext); if (!context) { throw new Error('useDialog must be used within a Dialog'); } return context; }; type DialogProps = React.ComponentProps; function Dialog({ children, ...props }: DialogProps) { const [isOpen, setIsOpen] = React.useState( props?.open ?? props?.defaultOpen ?? false, ); React.useEffect(() => { if (props?.open !== undefined) setIsOpen(props.open); }, [props?.open]); const handleOpenChange = React.useCallback( (open: boolean) => { setIsOpen(open); props.onOpenChange?.(open); }, [props], ); return ( {children} ); } type DialogTriggerProps = React.ComponentProps; function DialogTrigger(props: DialogTriggerProps) { return ; } type DialogPortalProps = React.ComponentProps; function DialogPortal(props: DialogPortalProps) { return ; } type DialogCloseProps = React.ComponentProps; function DialogClose(props: DialogCloseProps) { return ; } type DialogOverlayProps = React.ComponentProps; function DialogOverlay({ className, ...props }: DialogOverlayProps) { return ( ); } type FlipDirection = 'top' | 'bottom' | 'left' | 'right'; type DialogContentProps = React.ComponentProps & HTMLMotionProps<'div'> & { from?: FlipDirection; transition?: Transition; }; function DialogContent({ className, children, from = 'top', transition = { type: 'spring', stiffness: 150, damping: 25 }, ...props }: DialogContentProps) { const { isOpen } = useDialog(); const initialRotation = from === 'top' || from === 'left' ? '20deg' : '-20deg'; const isVertical = from === 'top' || from === 'bottom'; const rotateAxis = isVertical ? 'rotateX' : 'rotateY'; return ( {isOpen && ( {children} Close )} ); } type DialogHeaderProps = React.ComponentProps<'div'>; function DialogHeader({ className, ...props }: DialogHeaderProps) { return (
); } type DialogFooterProps = React.ComponentProps<'div'>; function DialogFooter({ className, ...props }: DialogFooterProps) { return (
); } type DialogTitleProps = React.ComponentProps; function DialogTitle({ className, ...props }: DialogTitleProps) { return ( ); } type DialogDescriptionProps = React.ComponentProps< typeof DialogPrimitive.Description >; function DialogDescription({ className, ...props }: DialogDescriptionProps) { return ( ); } export { Dialog, DialogPortal, DialogOverlay, DialogClose, DialogTrigger, DialogContent, DialogHeader, DialogFooter, DialogTitle, DialogDescription, useDialog, type DialogContextType, type DialogProps, type DialogTriggerProps, type DialogPortalProps, type DialogCloseProps, type DialogOverlayProps, type DialogContentProps, type DialogHeaderProps, type DialogFooterProps, type DialogTitleProps, type DialogDescriptionProps, };