import * as DialogPrimitive from '@radix-ui/react-dialog'; import { motion, AnimatePresence } from 'framer-motion'; import { forwardRef, type ComponentPropsWithoutRef, createContext, useContext, useState, } from 'react'; import { cn } from '@/lib/utils'; import { CloseIcon } from '@/components/icons'; import { backdrop, backdropTransition, scale, scaleTransition } from '../../motion/transitions'; export { Trigger as DialogTrigger, Portal as DialogPortal, Close as DialogClose, } from '@radix-ui/react-dialog'; // Context for AnimatePresence const DialogContext = createContext<{ open: boolean }>({ open: false }); // Root export type DialogProps = ComponentPropsWithoutRef; export const Dialog = ({ children, open, onOpenChange, ...props }: DialogProps) => { const [internalOpen, setInternalOpen] = useState(false); const isOpen = open !== undefined ? open : internalOpen; const handleOpenChange = onOpenChange || setInternalOpen; return ( {children} ); }; // Overlay export type DialogOverlayProps = ComponentPropsWithoutRef; export const DialogOverlay = forwardRef( ({ className, ...props }, ref) => ( ), ); DialogOverlay.displayName = 'DialogOverlay'; // Content export interface DialogContentProps extends ComponentPropsWithoutRef { showCloseButton?: boolean; } export const DialogContent = forwardRef( ({ className, children, showCloseButton = true, ...props }, ref) => { const { open } = useContext(DialogContext); return ( {open && ( <> {children} {showCloseButton && ( Close )} )} ); }, ); DialogContent.displayName = 'DialogContent'; // Header export type DialogHeaderProps = React.HTMLAttributes; export const DialogHeader = ({ className, ...props }: DialogHeaderProps) => (
); DialogHeader.displayName = 'DialogHeader'; // Footer export type DialogFooterProps = React.HTMLAttributes; export const DialogFooter = ({ className, ...props }: DialogFooterProps) => (
); DialogFooter.displayName = 'DialogFooter'; // Title export type DialogTitleProps = ComponentPropsWithoutRef; export const DialogTitle = forwardRef( ({ className, ...props }, ref) => ( ), ); DialogTitle.displayName = 'DialogTitle'; // Description export type DialogDescriptionProps = ComponentPropsWithoutRef; export const DialogDescription = forwardRef( ({ className, ...props }, ref) => ( ), ); DialogDescription.displayName = 'DialogDescription';