{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "destructive-action-modal",
  "title": "DestructiveActionModal",
  "description": "For actions that cannot be undone. The red button stays off until the name is typed.",
  "dependencies": [
    "@radix-ui/react-dialog@^1.2.0"
  ],
  "registryDependencies": [
    "https://creance.pages.dev/r/button.json",
    "https://creance.pages.dev/r/creance-base.json",
    "https://creance.pages.dev/r/dialog.json",
    "https://creance.pages.dev/r/input.json"
  ],
  "files": [
    {
      "path": "destructive-action-modal/DestructiveActionModal.css",
      "content": ".cr-destructive__confirm {\n  display: grid;\n  gap: var(--cr-space-2);\n  margin-top: var(--cr-space-1);\n}\n\n.cr-destructive__label {\n  font-size: var(--cr-font-size-sm);\n  font-weight: var(--cr-font-weight-semibold);\n}\n\n.cr-destructive__label code {\n  font-family: var(--cr-font-family-mono);\n}\n\n/* Solid red: the one place the kit fills a button with red. */\n.cr-destructive__action {\n  border-color: transparent;\n  background: var(--cr-color-danger-bg);\n  color: var(--cr-color-danger-fg);\n}\n\n.cr-destructive__action:hover:not(:disabled) {\n  background: var(--cr-color-danger-bg-hover);\n}\n",
      "type": "registry:file",
      "target": "@components/creance/destructive-action-modal/DestructiveActionModal.css"
    },
    {
      "path": "destructive-action-modal/DestructiveActionModal.tsx",
      "content": "'use client';\n\nimport * as RadixDialog from '@radix-ui/react-dialog';\nimport { useId, useRef, useState, type ReactElement, type ReactNode } from 'react';\nimport { Button } from '@/components/creance/button/Button';\nimport { Input } from '@/components/creance/input/Input';\nimport { cx } from '@/lib/creance/cx';\nimport '@/components/creance/dialog/Dialog.css';\nimport './DestructiveActionModal.css';\n\nexport interface DestructiveActionModalProps {\n  open?: boolean;\n  onOpenChange?: (open: boolean) => void;\n  /** The button that opens it. */\n  trigger?: ReactElement;\n  /** A question: \"Delete Deploy Fixer?\" */\n  title: ReactNode;\n  /** Exactly what is lost, and that it can't be undone. */\n  description: ReactNode;\n  /** Names the action: \"Delete agent\". */\n  confirmLabel: string;\n  /** Default \"Cancel\". */\n  cancelLabel?: string;\n  /** When set, the action stays off until this exact text is typed. Use it for things that can't be recovered. */\n  confirmText?: string;\n  onConfirm: () => void;\n  className?: string;\n}\n\n/**\n * An alert dialog for an action that can't be undone. Focus starts on Cancel, and the red action can\n * require typing a name first.\n */\nexport function DestructiveActionModal({\n  open,\n  onOpenChange,\n  trigger,\n  title,\n  description,\n  confirmLabel,\n  cancelLabel = 'Cancel',\n  confirmText,\n  onConfirm,\n  className,\n}: DestructiveActionModalProps) {\n  const id = useId();\n  const [typed, setTyped] = useState('');\n  const cancel = useRef<HTMLButtonElement>(null);\n  const ready = confirmText === undefined || typed === confirmText;\n\n  return (\n    <RadixDialog.Root\n      open={open}\n      onOpenChange={(o) => {\n        if (!o) setTyped('');\n        onOpenChange?.(o);\n      }}\n    >\n      {trigger && <RadixDialog.Trigger asChild>{trigger}</RadixDialog.Trigger>}\n      <RadixDialog.Portal>\n        <RadixDialog.Overlay className=\"cr-dialog-overlay\" />\n        <RadixDialog.Content\n          role=\"alertdialog\"\n          className={cx('cr-dialog cr-glass cr-destructive', className)}\n          onOpenAutoFocus={(e) => {\n            // The safe choice gets focus, unless there is a name to type.\n            if (confirmText === undefined) {\n              e.preventDefault();\n              cancel.current?.focus();\n            }\n          }}\n        >\n          <RadixDialog.Title className=\"cr-dialog__title\">{title}</RadixDialog.Title>\n          <RadixDialog.Description className=\"cr-dialog__description\">{description}</RadixDialog.Description>\n          {confirmText !== undefined && (\n            <div className=\"cr-destructive__confirm\">\n              <label htmlFor={`${id}-confirm`} className=\"cr-destructive__label\">\n                Type <code>{confirmText}</code> to confirm\n              </label>\n              <Input id={`${id}-confirm`} value={typed} autoComplete=\"off\" spellCheck={false} onChange={(e) => setTyped(e.currentTarget.value)} />\n            </div>\n          )}\n          <div className=\"cr-dialog__actions\">\n            <RadixDialog.Close asChild>\n              <Button ref={cancel}>{cancelLabel}</Button>\n            </RadixDialog.Close>\n            <Button\n              className=\"cr-destructive__action\"\n              disabled={!ready}\n              onClick={() => {\n                onConfirm();\n                setTyped('');\n                onOpenChange?.(false);\n              }}\n            >\n              {confirmLabel}\n            </Button>\n          </div>\n        </RadixDialog.Content>\n      </RadixDialog.Portal>\n    </RadixDialog.Root>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/creance/destructive-action-modal/DestructiveActionModal.tsx"
    }
  ],
  "categories": [
    "molecule",
    "overlays"
  ],
  "type": "registry:ui"
}