{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dialog",
  "type": "registry:ui",
  "title": "Dialog",
  "description": "A modal dialog with title, description, scrolling body and pinned footer buttons; alert mode for destructive choices. Built on Radix Dialog.",
  "dependencies": [
    "lucide-react@^1.49.0",
    "radix-ui@^1.6.7"
  ],
  "registryDependencies": [
    "https://ui.klarhimmel.com/r/icon-button.json",
    "https://ui.klarhimmel.com/r/theme.json",
    "https://ui.klarhimmel.com/r/utils.json"
  ],
  "files": [
    {
      "path": "src/ui/dialog.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/ui/dialog.tsx",
      "content": "import type { ReactNode } from 'react';\nimport { Dialog as D } from 'radix-ui';\nimport { X } from 'lucide-react';\nimport { ThemeRootScope, useThemeRoot } from '../lib/theme-root';\nimport { cn } from '../lib/utils';\nimport { IconButton } from './icon-button';\n\nexport interface DialogProps {\n  open?: boolean;\n  defaultOpen?: boolean;\n  onOpenChange?: (open: boolean) => void;\n  /** The element that opens it (a Button). Focus returns to it on close. Omit for a controlled dialog. */\n  trigger?: ReactNode;\n  /** Required: names the dialog. */\n  title: string;\n  /** A line under the title: text, or a small row of parts (a key with its copy button). */\n  description?: ReactNode;\n  children?: ReactNode;\n  /** Buttons, pinned under the body. */\n  footer?: ReactNode;\n  /**\n   * An alert dialog (role=alertdialog) for a decision that cannot be missed, like a delete: clicking outside does not\n   * close it, Escape still does.\n   */\n  alert?: boolean;\n  /** The close button's name for screen readers, in the page's language ('Stäng'). Default 'Close'. */\n  closeLabel?: string;\n  className?: string;\n}\n\nfunction Panel({ title, description, children, footer, alert, closeLabel = 'Close', className }: Omit<DialogProps, 'open' | 'defaultOpen' | 'onOpenChange' | 'trigger'>) {\n  const root = useThemeRoot();\n  return (\n    <D.Portal container={root}>\n      <D.Overlay className=\"fixed inset-0 z-50 bg-(--kh-scrim)\" />\n      <D.Content\n        role={alert ? 'alertdialog' : 'dialog'}\n        tabIndex={-1}\n        // Focus lands on the dialog itself, so a screen reader reads the title first and a keyboard user starts at the top.\n        // An alert dialog puts it on the least destructive control instead (the element marked data-kh-autofocus, its Cancel).\n        onOpenAutoFocus={(e) => {\n          e.preventDefault();\n          const el = e.currentTarget as HTMLElement;\n          ((alert ? el.querySelector<HTMLElement>('[data-kh-autofocus]') : null) ?? el).focus();\n        }}\n        onInteractOutside={alert ? (e) => e.preventDefault() : undefined}\n        // Escape inside an open Select or Combobox closes its list first, not the dialog.\n        onEscapeKeyDown={(e) => { if ((document.activeElement as HTMLElement | null)?.matches?.('[role=combobox][aria-expanded=true]')) e.preventDefault(); }}\n        className={cn(\n          'fixed left-1/2 top-1/2 z-50 flex max-h-[85dvh] w-[min(32rem,calc(100vw-2rem))] -translate-x-1/2 -translate-y-1/2 flex-col gap-4 overflow-hidden',\n          'rounded-kh-xl border border-kh-line bg-kh-surface pt-5 text-kh-ink shadow-kh-3 outline-none',\n          className,\n        )}\n      >\n        <div className=\"flex items-start justify-between gap-4 px-5\">\n          {/* min-w-0 and anywhere-wrapping: a long unbroken title (a hash) wraps instead of pushing the close button out of sight. */}\n          <div className=\"flex min-w-0 flex-1 flex-col gap-1\">\n            <D.Title className=\"text-kh-heading font-semibold [overflow-wrap:anywhere]\">{title}</D.Title>\n            {description ? <D.Description asChild={typeof description !== 'string'} className=\"text-kh-small text-kh-muted\">{typeof description === 'string' ? description : <div>{description}</div>}</D.Description> : <D.Description className=\"sr-only\">{title}</D.Description>}\n          </div>\n          <D.Close asChild>\n            <IconButton label={closeLabel} size=\"sm\" noTooltip className=\"-mr-2 -mt-1\">\n              <X aria-hidden className=\"size-4\" />\n            </IconButton>\n          </D.Close>\n        </div>\n        <div className=\"flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto px-5 pb-5 text-kh-body\">{children}</div>\n        {footer && <div className=\"flex flex-wrap justify-end gap-3 border-t border-kh-line bg-kh-surface px-5 py-4\">{footer}</div>}\n      </D.Content>\n    </D.Portal>\n  );\n}\n\n/** A modal dialog: it traps focus, closes on Escape, and gives focus back to what opened it. */\nexport function Dialog({ open, defaultOpen, onOpenChange, trigger, ...panel }: DialogProps) {\n  return (\n    <ThemeRootScope>\n      <D.Root open={open} defaultOpen={defaultOpen} onOpenChange={onOpenChange}>\n        {trigger && <D.Trigger asChild>{trigger}</D.Trigger>}\n        <Panel {...panel} />\n      </D.Root>\n    </ThemeRootScope>\n  );\n}\n\n/** Closes the dialog it sits in. Wrap a footer Button: `<DialogClose><Button>Cancel</Button></DialogClose>`. */\nexport function DialogClose({ children }: { children: ReactNode }) {\n  return <D.Close asChild>{children}</D.Close>;\n}\n"
    }
  ]
}
