{"version":3,"file":"Dialog-BfW1sIvW.cjs","sources":["../src/components/Dialog/Dialog.tsx"],"sourcesContent":["'use client';\n\nimport { forwardRef } from 'react';\nimport type { FC, ReactNode } from 'react';\nimport type { TriggerProps } from '../../utils/primitiveProps';\nimport * as RadixDialog from '@radix-ui/react-dialog';\nimport { X } from 'lucide-react';\nimport { withSx } from '../../utils/withSx';\nimport type { SxProp } from '../Layout/sx';\nimport type { CSSProperties } from 'react';\nimport { useCloseGuard } from '../../utils/useCloseGuard';\nimport { ReturnFocus, focusFirstField } from '../../utils/overlayFocus';\n\nexport type DialogSize = 'sm' | 'md' | 'lg' | 'xl' | 'full';\n\n// Props are declared explicitly (rather than `extends ComponentPropsWithoutRef<\n// typeof RadixDialog.Root>`) so the published .d.ts stays self-contained and does\n// not import `@radix-ui/react-dialog` — consumers don't need it installed.\nexport interface DialogProps {\n  /** Controlled open state. */\n  open?: boolean;\n  /** Uncontrolled initial open state. */\n  defaultOpen?: boolean;\n  /** Fires when the open state changes (Esc, backdrop, or close button). */\n  onOpenChange?: (open: boolean) => void;\n  /** Whether the dialog blocks interaction with the rest of the page. Default: true. */\n  modal?: boolean;\n  /** Title rendered as the visible h2. Required for accessibility. */\n  title: ReactNode;\n  /** Optional descriptive subhead under the title. */\n  description?: ReactNode;\n  /** Body content (forms, copy, lists). */\n  children?: ReactNode;\n  /** Footer node (typically a Button row). */\n  footer?: ReactNode;\n  /** Width preset. Default: `md`. */\n  size?: DialogSize;\n  /** Hide the built-in X close button. */\n  hideClose?: boolean;\n  /** Close when Esc is pressed. Default: true. Set false for dialogs that must be closed by their own buttons. */\n  closeOnEscape?: boolean;\n  /** Close on a click (or focus move) outside the dialog, e.g. on the backdrop. Default: true. */\n  closeOnOutsideClick?: boolean;\n  /** Body without padding or its own scroll — for content that lays itself out (split panes, own scroll areas). */\n  flush?: boolean;\n  /** Unsaved changes. While true, close attempts go through `onBeforeClose` (or are blocked if it is absent). */\n  dirty?: boolean;\n  /** Guard for close attempts (Esc, backdrop, X). Return `false` (or resolve `false`) to keep the dialog open. */\n  onBeforeClose?: () => boolean | Promise<boolean>;\n  /** Fires when focus moves into the dialog on open; call `preventDefault()` to place focus yourself. Default: first form field in the body, else the Close button. */\n  onOpenAutoFocus?: (event: Event) => void;\n  /** Extra className on the dialog content. */\n  className?: string;\n  /** Inline style on the dialog content panel. */\n  style?: CSSProperties;\n  /**\n   * One-off CSS for the dialog content panel, same as `Box`'s `sx`: each value\n   * may be a scalar or a responsive breakpoint map (`{ base, sm, md, lg, xl }`).\n   * Scalar-only sx merges into inline style; responsive sx injects a scoped class.\n   */\n  sx?: SxProp;\n}\n\n/**\n * Modal dialog built on @radix-ui/react-dialog. Includes a backdrop, focus trap,\n * Esc-to-close, scroll lock, and an accessible title/description out of the box.\n *\n * @example\n *   const [open, setOpen] = useState(false);\n *   <Dialog open={open} onOpenChange={setOpen} title=\"Confirm delete\">\n *     This action can't be undone.\n *   </Dialog>\n */\nexport const Dialog = forwardRef<HTMLDivElement, DialogProps>(function Dialog(\n  { title, description, children, footer, size = 'md', hideClose, closeOnEscape = true, closeOnOutsideClick = true, flush = false, className, style, sx, dirty, onBeforeClose, onOpenAutoFocus, open, defaultOpen, onOpenChange, ...rootProps },\n  ref,\n) {\n  const { className: classes, style: mergedStyle, styleTag } = withSx(\n    sx, style, 'cny-dialog-content', `size-${size}`, className,\n  );\n  const guard = useCloseGuard({ open, defaultOpen, onOpenChange, dirty, onBeforeClose });\n  return (\n    <RadixDialog.Root {...rootProps} open={guard.open} onOpenChange={guard.onOpenChange}>\n      <RadixDialog.Portal>\n        <RadixDialog.Overlay className=\"cny-dialog-overlay\" />\n        <RadixDialog.Content\n          ref={ref}\n          className={classes}\n          style={mergedStyle}\n          onOpenAutoFocus={(e) => { onOpenAutoFocus?.(e); focusFirstField(e, '.cny-dialog-body'); }}\n          onEscapeKeyDown={closeOnEscape ? undefined : (e) => e.preventDefault()}\n          onInteractOutside={closeOnOutsideClick ? undefined : (e) => e.preventDefault()}\n        >\n          <ReturnFocus />\n          {styleTag}\n          <header className=\"cny-dialog-header\">\n            <div className=\"cny-dialog-titles\">\n              <RadixDialog.Title className=\"cny-dialog-title\">{title}</RadixDialog.Title>\n              {description && (\n                <RadixDialog.Description className=\"cny-dialog-description\">{description}</RadixDialog.Description>\n              )}\n            </div>\n            {!hideClose && (\n              <RadixDialog.Close className=\"cny-dialog-close\" aria-label=\"Close dialog\">\n                <X size={16} aria-hidden=\"true\" />\n              </RadixDialog.Close>\n            )}\n          </header>\n          {children != null && <div className={flush ? 'cny-dialog-body flush' : 'cny-dialog-body'}>{children}</div>}\n          {footer != null && <footer className=\"cny-dialog-footer\">{footer}</footer>}\n        </RadixDialog.Content>\n      </RadixDialog.Portal>\n    </RadixDialog.Root>\n  );\n});\n\n/** Trigger button to open a Dialog when wired with a controlled root. */\n// Re-exported Radix primitives are annotated with explicit prop types so the\n// emitted .d.ts does not import `@radix-ui/react-dialog`.\nexport type DialogTriggerProps = TriggerProps;\nexport const DialogTrigger = RadixDialog.Trigger as FC<DialogTriggerProps>;\n/** Close button — typically used inside the body or footer. */\nexport type DialogCloseProps = TriggerProps;\nexport const DialogClose = RadixDialog.Close as FC<DialogCloseProps>;\n"],"names":["Dialog","forwardRef","title","description","children","footer","size","hideClose","closeOnEscape","closeOnOutsideClick","flush","className","style","sx","dirty","onBeforeClose","onOpenAutoFocus","open","defaultOpen","onOpenChange","rootProps","ref","classes","mergedStyle","styleTag","withSx","guard","useCloseGuard","jsx","RadixDialog.Root","jsxs","RadixDialog.Portal","RadixDialog.Overlay","RadixDialog.Content","e","focusFirstField","ReturnFocus","RadixDialog.Title","RadixDialog.Description","RadixDialog.Close","X","DialogTrigger","RadixDialog.Trigger","DialogClose"],"mappings":"wQAyEaA,EAASC,EAAAA,WAAwC,SAC5D,CAAE,MAAAC,EAAO,YAAAC,EAAa,SAAAC,EAAU,OAAAC,EAAQ,KAAAC,EAAO,KAAM,UAAAC,EAAW,cAAAC,EAAgB,GAAM,oBAAA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