import * as React from 'react' import { motion } from 'framer-motion' import * as DialogPrimitive from '@radix-ui/react-dialog' import { cva, type VariantProps } from 'class-variance-authority' import { cn } from '@/lib/utils' import { MOTION_FADE, MOTION_SLIDE_UP } from '@/lib/motion' import { CloseLine } from './icons-inline' import { getThemeFromDocument } from './theme-from-document' const Dialog = DialogPrimitive.Root const DialogTrigger = DialogPrimitive.Trigger const DialogPortal = DialogPrimitive.Portal const DialogClose = DialogPrimitive.Close const DialogOverlay = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( )) DialogOverlay.displayName = DialogPrimitive.Overlay.displayName const contentVariants = cva( 'font-sans fixed left-1/2 top-1/2 z-50 w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 rounded-xl border border-border bg-bg-base text-text shadow-lg p-6 outline-none', { variants: { size: { sm: 'max-w-sm', default: 'max-w-lg', lg: 'max-w-2xl', xl: 'max-w-4xl', }, }, defaultVariants: { size: 'default' }, }, ) export interface DialogContentProps extends React.ComponentPropsWithoutRef, VariantProps { size?: 'sm' | 'default' | 'lg' | 'xl' /** Hide the built-in top-right close button. */ hideCloseButton?: boolean /** When provided (e.g. from ThemeStyleProvider), used for portal wrapper */ dataStyle?: string dataTheme?: string } const DialogContent = React.forwardRef< React.ElementRef, DialogContentProps >( ( { className, children, size = 'default', hideCloseButton = false, dataStyle, dataTheme, ...props }, ref, ) => { const fromDoc = getThemeFromDocument() const dataProps = dataStyle !== undefined ? { 'data-style': dataStyle, 'data-theme': dataTheme ?? fromDoc['data-theme'] ?? '' } : fromDoc return (
{children} {!hideCloseButton && ( Close )}
) }, ) DialogContent.displayName = DialogPrimitive.Content.displayName const DialogHeader = React.forwardRef>( ({ className, ...props }, ref) => (
), ) DialogHeader.displayName = 'DialogHeader' const DialogFooter = React.forwardRef>( ({ className, ...props }, ref) => (
), ) DialogFooter.displayName = 'DialogFooter' const DialogTitle = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( )) DialogTitle.displayName = DialogPrimitive.Title.displayName const DialogDescription = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( )) DialogDescription.displayName = DialogPrimitive.Description.displayName export type DialogHeaderProps = React.HTMLAttributes export type DialogFooterProps = React.HTMLAttributes export { Dialog, DialogTrigger, DialogPortal, DialogOverlay, DialogClose, DialogContent, DialogHeader, DialogFooter, DialogTitle, DialogDescription, contentVariants as dialogContentVariants, }