{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dialog",
  "title": "Dialog",
  "description": "Dialog (header, scrolling body, footer cells) and AlertDialog (an attention cell; focus lands on the safe action): region-framed modals on Base UI. Also installable as @keyline-ui/alert-dialog.",
  "dependencies": [
    "@base-ui/react@1.9.0"
  ],
  "registryDependencies": [
    "@keyline-ui/keyline",
    "utils",
    "@keyline-ui/scroll-area",
    "@keyline-ui/keyline-scope",
    "@keyline-ui/keyline-render"
  ],
  "files": [
    {
      "path": "src/registry/keyline/ui/dialog.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { Dialog as DialogPrimitive } from \"@base-ui/react/dialog\";\nimport { AlertDialog as AlertPrimitive } from \"@base-ui/react/alert-dialog\";\nimport { mergeProps } from \"@base-ui/react/merge-props\";\nimport { useRender } from \"@base-ui/react/use-render\";\n\nimport { cn } from \"@/lib/utils\";\nimport { ScrollArea } from \"./scroll-area\";\nimport { scopeProps, useKeylineScope } from \"../lib/keyline-scope\";\nimport { resolveClassName, resolveStyle, type PartProps } from \"../lib/keyline-render\";\n\n/* Modal surfaces are region frames: 3px, region cut. They are the only overlays that carry a cut,\n   because they are not attached to an owner. Parts are named as Base UI names them; AlertDialog's Title,\n   Description, Close and Backdrop are Dialog's own parts in Base UI, so the Dialog parts serve both. */\n\nconst DialogRoot = DialogPrimitive.Root;\nconst Dialog = DialogRoot;\n\n/** The element that opens the dialog. Rendered as another part (`render={<Button />}`), the element is that part's\n * and carries its data-slot. */\nfunction DialogTrigger(props: DialogPrimitive.Trigger.Props): React.ReactElement {\n  return <DialogPrimitive.Trigger {...props} data-slot=\"dialog-trigger\" />;\n}\n\nfunction DialogClose(props: DialogPrimitive.Close.Props): React.ReactElement {\n  return <DialogPrimitive.Close {...props} data-slot=\"dialog-close\" />;\n}\n\n/** The scrim behind a modal surface. It fades in with the surface and leaves with it, not after it. */\nfunction DialogBackdrop({ className, ...props }: DialogPrimitive.Backdrop.Props): React.ReactElement {\n  return (\n    <DialogPrimitive.Backdrop\n      className={resolveClassName(\n        cn(\n          \"fixed inset-0 z-(--kl-z-overlay) bg-kl-scrim transition-opacity duration-(--kl-t-unfold) ease-linear\",\n          \"data-ending-style:opacity-0 data-ending-style:duration-(--kl-t-fold) data-starting-style:opacity-0\",\n        ),\n        className,\n      )}\n      {...props}\n      data-slot=\"dialog-backdrop\"\n    />\n  );\n}\n\n/*\n * The modal frame: fixed, centred, region weight, lifted to the overlay surface. It unfolds from its top keyline\n * (clip-path) and folds back to it. A closing dialog is inert: a second click 60ms after the first landed on its\n * confirm button and ran it twice.\n */\nconst modal = cn(\n  \"kl-frame fixed inset-x-0 top-[14vh] z-(--kl-z-overlay) mx-auto max-h-[calc(100vh-20vh)] text-kl-ink outline-0\",\n  \"[--kl-cell:var(--kl-raised)]\",\n  \"transition-[clip-path] duration-(--kl-t-unfold) ease-(--kl-ease-out) [clip-path:inset(-8px)]\",\n  \"data-ending-style:[clip-path:inset(0_0_100%_0)] data-starting-style:[clip-path:inset(0_0_100%_0)]\",\n  \"data-ending-style:pointer-events-none data-ending-style:duration-(--kl-t-fold) data-ending-style:ease-(--kl-ease-in)\",\n);\n\ntype PortalProps = {\n  /** Where the portal renders (defaults to <body>). */\n  container?: DialogPrimitive.Portal.Props[\"container\"];\n  /** Props for Base UI's Dialog.Portal. */\n  portalProps?: Omit<DialogPrimitive.Portal.Props, \"container\" | \"children\">;\n};\n\n/** Portal, backdrop and the configuration of the place the surface is written, around a popup. */\nfunction ModalPortal({\n  container,\n  portalProps,\n  children,\n}: PortalProps & { children: React.ReactNode }): React.ReactElement {\n  const [marker, scope, probe] = useKeylineScope(false, container);\n  return (\n    <>\n      {marker}\n      <DialogPrimitive.Portal container={container} {...portalProps}>\n        {probe}\n        <DialogBackdrop {...scopeProps(scope)} />\n        {/* carries the scope to the popup without a box of its own */}\n        <div {...scopeProps(scope, { className: \"contents\" })}>{children}</div>\n      </DialogPrimitive.Portal>\n    </>\n  );\n}\n\ntype DialogPopupProps = DialogPrimitive.Popup.Props & PortalProps;\n\n/**\n * The dialog: Base UI's Portal, Backdrop and Popup in one part. A region frame over a scrim, with a header, a body\n * that scrolls and a footer of cells. It carries the configuration (cut, density, motion, theme, dir) of the place\n * it is written, not of <body>.\n */\nfunction DialogPopup({ className, container, portalProps, ...props }: DialogPopupProps): React.ReactElement {\n  return (\n    <ModalPortal container={container} portalProps={portalProps}>\n      <DialogPrimitive.Popup\n        className={resolveClassName(cn(modal, \"flex w-[min(560px,calc(100vw-32px))] flex-col\"), className)}\n        {...props}\n        data-slot=\"dialog-popup\"\n      />\n    </ModalPortal>\n  );\n}\n\ntype PartState = Record<string, never>;\nconst PART_STATE: PartState = {};\n\n/** Header cell row of a dialog: title, description, optional close. Reserves the cut's room. */\nfunction DialogHeader({ render, className, style, ...props }: PartProps<\"div\", PartState>): React.ReactElement {\n  const own = {\n    \"data-slot\": \"dialog-header\",\n    className: resolveClassName(\n      cn(\n        \"grid flex-none gap-1 border-b-(length:--kl-k3) border-b-kl-line pe-[18px] pt-4 pb-3.5\",\n        \"ps-[calc(18px+var(--kl-c-room,0px))]\",\n      ),\n      className,\n    )(PART_STATE),\n    style: resolveStyle(undefined, style)(PART_STATE),\n  };\n  return useRender({ defaultTagName: \"div\", render, state: PART_STATE, props: mergeProps<\"div\">(props, own) });\n}\n\ntype DialogBodyProps = Omit<React.ComponentProps<typeof ScrollArea>, \"className\" | \"style\"> & {\n  className?: string | ((state: PartState) => string | undefined);\n  style?: React.CSSProperties | ((state: PartState) => React.CSSProperties | undefined);\n};\n\n/** The dialog's scrolling body: a Keyline Scroll Area. `className` and `style` reach the scroll area itself;\n * `contentClassName` lays out the content (a grid with a 16px gap by default). Fields and groups go here, standalone\n * (2px). */\nfunction DialogBody({ className, style, contentClassName, children, ...props }: DialogBodyProps): React.ReactElement {\n  return (\n    <ScrollArea\n      className={resolveClassName(\"min-h-0 flex-[1_1_auto]\", className)(PART_STATE)}\n      style={resolveStyle(undefined, style)(PART_STATE)}\n      viewportClassName=\"overscroll-contain\"\n      contentClassName={cn(\"grid content-start gap-4 p-[18px]\", contentClassName)}\n      {...props}\n      data-slot=\"dialog-body\"\n    >\n      {children}\n    </ScrollArea>\n  );\n}\n\n/** Footer: a row of cells (use Button layout=\"cell\") sharing the dialog's bottom keyline. */\nfunction DialogFooter({ render, className, style, ...props }: PartProps<\"div\", PartState>): React.ReactElement {\n  const own = {\n    \"data-slot\": \"dialog-footer\",\n    className: resolveClassName(\n      \"kl-cells flex-none border-t-(length:--kl-k3) border-t-kl-line *:min-w-0 *:flex-[1_1_0]\",\n      className,\n    )(PART_STATE),\n    style: resolveStyle(undefined, style)(PART_STATE),\n  };\n  return useRender({ defaultTagName: \"div\", render, state: PART_STATE, props: mergeProps<\"div\">(props, own) });\n}\n\nfunction DialogTitle({ className, ...props }: DialogPrimitive.Title.Props): React.ReactElement {\n  return (\n    <DialogPrimitive.Title\n      className={resolveClassName(\"m-0 text-(length:--kl-text-title)/[1.2] font-(--kl-weight-strong)\", className)}\n      {...props}\n      data-slot=\"dialog-title\"\n    />\n  );\n}\n\nfunction DialogDescription({ className, ...props }: DialogPrimitive.Description.Props): React.ReactElement {\n  return (\n    <DialogPrimitive.Description\n      className={resolveClassName(\"m-0 text-kl-ink-2\", className)}\n      {...props}\n      data-slot=\"dialog-description\"\n    />\n  );\n}\n\n/* ---------- confirmation (alert) dialog ---------- */\n\nconst AlertDialogRoot = AlertPrimitive.Root;\nconst AlertDialog = AlertDialogRoot;\n\nfunction AlertDialogTrigger(props: AlertPrimitive.Trigger.Props): React.ReactElement {\n  return <AlertPrimitive.Trigger {...props} data-slot=\"alert-dialog-trigger\" />;\n}\n\ntype Tone = \"destructive\" | \"primary\";\n\ntype AlertDialogPopupProps = DialogPrimitive.Popup.Props &\n  PortalProps & {\n    /** The signal of the question: red attention for a destructive action, cobalt for a commitment. */\n    tone?: Tone;\n  };\n\n/** The confirmation frame: Base UI's Portal, Backdrop and Popup in one part. A narrower region of rows. */\nfunction AlertDialogPopup({\n  tone = \"destructive\",\n  className,\n  container,\n  portalProps,\n  ...props\n}: AlertDialogPopupProps): React.ReactElement {\n  return (\n    <ModalPortal container={container} portalProps={portalProps}>\n      <AlertPrimitive.Popup\n        data-tone={tone}\n        className={resolveClassName(cn(modal, \"kl-rows w-[min(480px,calc(100vw-32px))]\"), className)}\n        {...props}\n        data-slot=\"alert-dialog-popup\"\n      />\n    </ModalPortal>\n  );\n}\n\n/* the two answers: cells of the footer, the confirm cell flooded with the tone */\nconst answer =\n  \"kl-cell kl-key min-h-[52px] flex-1 justify-center text-(length:--kl-text-lead) font-(--kl-weight-strong)\";\nconst confirmTone: Record<Tone, string> = {\n  destructive: cn(\n    \"bg-kl-red text-kl-on-red hover:bg-kl-red-hi focus-visible:outline-current\",\n    \"forced-colors:bg-[Mark] forced-colors:text-[MarkText] forced-colors:forced-color-adjust-none\",\n  ),\n  primary: \"bg-kl-cobalt text-kl-on-cobalt hover:bg-kl-cobalt-hi focus-visible:outline-current\",\n};\n\ntype AlertDialogContentProps = Omit<AlertDialogPopupProps, \"title\"> & {\n  title: React.ReactNode;\n  description?: React.ReactNode;\n  /** The safe action receives initial focus. */\n  cancelLabel: string;\n  confirmLabel: string;\n  onConfirm: () => void;\n};\n\n/**\n * The usual confirmation, built from the parts: an attention cell (! or ?) beside the question, optional detail, and\n * two answers on the bottom keyline. Focus lands on the safe answer.\n */\nfunction AlertDialogContent({\n  title,\n  description,\n  cancelLabel,\n  confirmLabel,\n  onConfirm,\n  tone = \"destructive\",\n  children,\n  ...props\n}: AlertDialogContentProps): React.ReactElement {\n  const safe = React.useRef<HTMLButtonElement>(null);\n  return (\n    <AlertDialogPopup tone={tone} initialFocus={safe} {...props}>\n      <div data-slot=\"alert-dialog-header\" className=\"kl-cells min-h-20\">\n        <span\n          data-slot=\"alert-dialog-signal\"\n          aria-hidden\n          className={cn(\n            // a glyph pinned to its fixed 60px cell, not text: it does not follow the type scale\n            \"grid w-[60px] flex-none place-items-center text-[26px] font-(--kl-weight-display)\",\n            tone === \"destructive\" ? \"bg-kl-red text-kl-on-red\" : \"bg-kl-cobalt text-kl-on-cobalt\",\n            \"forced-colors:bg-[Mark] forced-colors:text-[MarkText] forced-colors:forced-color-adjust-none\",\n          )}\n        >\n          {tone === \"destructive\" ? \"!\" : \"?\"}\n        </span>\n        <div className=\"grid flex-1 content-center gap-1.5 px-[18px] py-3.5\">\n          <DialogTitle>{title}</DialogTitle>\n          {description ? <DialogDescription>{description}</DialogDescription> : null}\n        </div>\n      </div>\n      {children ? (\n        <div data-slot=\"alert-dialog-body\" className=\"grid gap-2.5 px-[18px] py-4\">\n          {children}\n        </div>\n      ) : null}\n      {/* the footer is a row of the frame (kl-rows draws its top keyline) at region weight */}\n      <div data-slot=\"alert-dialog-footer\" className=\"kl-cells border-t-(length:--kl-k3)\">\n        <AlertPrimitive.Close ref={safe} className={answer} data-slot=\"alert-dialog-cancel\">\n          <span>{cancelLabel}</span>\n        </AlertPrimitive.Close>\n        <AlertPrimitive.Close\n          className={cn(answer, confirmTone[tone])}\n          onClick={onConfirm}\n          data-slot=\"alert-dialog-confirm\"\n        >\n          <span>{confirmLabel}</span>\n        </AlertPrimitive.Close>\n      </div>\n    </AlertDialogPopup>\n  );\n}\n\nexport {\n  Dialog,\n  DialogRoot,\n  DialogTrigger,\n  DialogClose,\n  DialogBackdrop,\n  DialogPopup,\n  DialogHeader,\n  DialogBody,\n  DialogFooter,\n  DialogTitle,\n  DialogDescription,\n  AlertDialog,\n  AlertDialogRoot,\n  AlertDialogTrigger,\n  AlertDialogPopup,\n  AlertDialogContent,\n};\n",
      "type": "registry:ui",
      "target": "components/keyline/ui/dialog.tsx"
    }
  ],
  "type": "registry:ui"
}