{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dialog-modal",
  "type": "registry:component",
  "title": "Dialog Modal",
  "description": "An accessible modal with a blurred scrim, scale-and-fade transitions, a focus trap and focus returned to the trigger.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "site",
    "dialog",
    "modal",
    "overlay",
    "confirm",
    "popup",
    "a11y"
  ],
  "docs": "https://hyperblur.dev/effects/dialog-modal",
  "files": [
    {
      "path": "registry/hyperblur/dialog-modal.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/dialog-modal.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { createPortal } from \"react-dom\";\n\nexport interface DialogModalProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"title\" | \"children\"> {\n  open?: boolean;\n  defaultOpen?: boolean;\n  onOpenChange?: (open: boolean) => void;\n  title?: React.ReactNode;\n  description?: React.ReactNode;\n  children?: React.ReactNode;\n  footer?: React.ReactNode | ((close: () => void) => React.ReactNode);\n  trigger?: React.ReactNode;\n  container?: \"viewport\" | \"parent\";\n  variant?: \"default\" | \"destructive\";\n  closeOnEscape?: boolean;\n  closeOnScrim?: boolean;\n  showClose?: boolean;\n  autoFocus?: boolean;\n  maxWidth?: number;\n  accent?: string;\n}\n\nexport interface DialogButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {\n  tone?: \"primary\" | \"ghost\" | \"danger\";\n}\n\nconst css = `\n.hb-dlg-trigger, .hb-dlg-btn {\n  display: inline-flex;\n  align-items: center;\n  justify-content: center;\n  gap: 6px;\n  box-sizing: border-box;\n  height: 34px;\n  margin: 0;\n  padding: 0 14px;\n  border: 1px solid #262626;\n  border-radius: 999px;\n  background: #171717;\n  color: #ededed;\n  font: inherit;\n  font-size: 13px;\n  font-weight: 500;\n  line-height: 1;\n  white-space: nowrap;\n  cursor: pointer;\n  -webkit-tap-highlight-color: transparent;\n  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;\n}\n.hb-dlg-trigger:hover, .hb-dlg-btn:hover { background: #1f1f1f; border-color: #333333; }\n.hb-dlg-trigger:active, .hb-dlg-btn:active { transform: scale(0.97); }\n.hb-dlg-trigger:focus-visible, .hb-dlg-btn:focus-visible, .hb-dlg-x:focus-visible {\n  outline: 2px solid var(--hb-dlg-accent, #2f7bff);\n  outline-offset: 2px;\n}\n.hb-dlg-btn[data-tone=\"primary\"] { background: #ededed; border-color: #ededed; color: #0a0a0a; font-weight: 600; }\n.hb-dlg-btn[data-tone=\"primary\"]:hover { background: #ffffff; border-color: #ffffff; }\n.hb-dlg-btn[data-tone=\"ghost\"] { background: transparent; border-color: transparent; color: #a1a1a1; }\n.hb-dlg-btn[data-tone=\"ghost\"]:hover { background: rgba(255, 255, 255, 0.07); color: #ededed; }\n.hb-dlg-btn[data-tone=\"danger\"] { background: #e5484d; border-color: #e5484d; color: #ffffff; font-weight: 600; }\n.hb-dlg-btn[data-tone=\"danger\"]:hover { background: #f2555a; border-color: #f2555a; }\n.hb-dlg-btn:disabled { opacity: 0.45; cursor: not-allowed; }\n.hb-dlg-scrim {\n  --hb-dlg-accent: #2f7bff;\n  position: fixed;\n  inset: 0;\n  z-index: 1000;\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  box-sizing: border-box;\n  padding: 16px;\n  background: rgba(0, 0, 0, 0.55);\n  -webkit-backdrop-filter: blur(6px);\n  backdrop-filter: blur(6px);\n  color: #ededed;\n  font-family: var(--font-sans, ui-sans-serif, system-ui, sans-serif);\n  animation: hb-dlg-fade 0.2s ease both;\n}\n.hb-dlg-scrim[data-container=\"parent\"] { position: absolute; z-index: 20; padding: 12px; border-radius: inherit; }\n.hb-dlg-scrim[data-state=\"closed\"] { animation: hb-dlg-fade-out 0.18s ease both; pointer-events: none; }\n.hb-dlg-panel {\n  position: relative;\n  display: flex;\n  flex-direction: column;\n  box-sizing: border-box;\n  width: 100%;\n  max-width: var(--hb-dlg-w, 440px);\n  max-height: 100%;\n  overflow: auto;\n  border: 1px solid #262626;\n  border-radius: 16px;\n  background: #111111;\n  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.02) inset;\n  text-align: left;\n  outline: none;\n  animation: hb-dlg-pop 0.26s cubic-bezier(0.2, 0.9, 0.2, 1) both;\n}\n.hb-dlg-scrim[data-state=\"closed\"] .hb-dlg-panel { animation: hb-dlg-pop-out 0.18s ease both; }\n.hb-dlg-panel[data-variant=\"destructive\"] { --hb-dlg-accent: #e5484d; border-color: rgba(229, 72, 77, 0.28); }\n.hb-dlg-head {\n  display: flex;\n  align-items: flex-start;\n  gap: 12px;\n  padding: 18px 18px 0;\n}\n.hb-dlg-badge {\n  display: inline-flex;\n  flex: none;\n  align-items: center;\n  justify-content: center;\n  width: 36px;\n  height: 36px;\n  border-radius: 10px;\n  background: rgba(229, 72, 77, 0.14);\n  color: #ff6369;\n}\n.hb-dlg-badge svg { width: 18px; height: 18px; }\n.hb-dlg-text { flex: 1; min-width: 0; padding-right: 24px; }\n.hb-dlg-title {\n  margin: 0;\n  color: #ededed;\n  font-size: 16px;\n  font-weight: 600;\n  line-height: 1.35;\n  letter-spacing: -0.01em;\n}\n.hb-dlg-desc {\n  margin: 4px 0 0;\n  color: #a1a1a1;\n  font-size: 13.5px;\n  line-height: 1.5;\n}\n.hb-dlg-body { padding: 14px 18px 0; color: #cfcfcf; font-size: 14px; line-height: 1.55; }\n.hb-dlg-body:empty { display: none; }\n.hb-dlg-foot {\n  display: flex;\n  flex-wrap: wrap;\n  justify-content: flex-end;\n  gap: 8px;\n  padding: 18px;\n}\n.hb-dlg-x {\n  position: absolute;\n  top: 12px;\n  right: 12px;\n  display: inline-flex;\n  align-items: center;\n  justify-content: center;\n  width: 28px;\n  height: 28px;\n  margin: 0;\n  padding: 0;\n  border: 0;\n  border-radius: 8px;\n  background: transparent;\n  color: #8f8f8f;\n  cursor: pointer;\n  transition: background-color 0.15s ease, color 0.15s ease;\n}\n.hb-dlg-x:hover { background: rgba(255, 255, 255, 0.08); color: #ededed; }\n.hb-dlg-x svg { width: 14px; height: 14px; }\n@keyframes hb-dlg-fade { from { opacity: 0; } to { opacity: 1; } }\n@keyframes hb-dlg-fade-out { from { opacity: 1; } to { opacity: 0; } }\n@keyframes hb-dlg-pop { from { opacity: 0; transform: translateY(8px) scale(0.95); } to { opacity: 1; transform: none; } }\n@keyframes hb-dlg-pop-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(4px) scale(0.97); } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-dlg-scrim, .hb-dlg-panel, .hb-dlg-scrim[data-state=\"closed\"], .hb-dlg-scrim[data-state=\"closed\"] .hb-dlg-panel { animation: none; }\n  .hb-dlg-trigger, .hb-dlg-btn, .hb-dlg-x { transition: none; }\n}\n`;\n\nconst focusableSelector =\n  'a[href], button:not(:disabled), input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex=\"-1\"])';\n\nconst subscribe = () => () => {};\n\nexport function DialogButton({ tone = \"ghost\", className = \"\", type = \"button\", ...rest }: DialogButtonProps) {\n  return <button type={type} className={`hb-dlg-btn ${className}`} data-tone={tone} {...rest} />;\n}\n\nexport function DialogModal({\n  open,\n  defaultOpen = false,\n  onOpenChange,\n  title,\n  description,\n  children,\n  footer,\n  trigger,\n  container = \"viewport\",\n  variant = \"default\",\n  closeOnEscape = true,\n  closeOnScrim = true,\n  showClose = true,\n  autoFocus = true,\n  maxWidth = 440,\n  accent = \"#2f7bff\",\n  className = \"\",\n  style,\n  ...rest\n}: DialogModalProps) {\n  const [inner, setInner] = React.useState(defaultOpen);\n  const isOpen = open !== undefined ? open : inner;\n  const [present, setPresent] = React.useState(isOpen);\n  const panel = React.useRef<HTMLDivElement>(null);\n  const downOnScrim = React.useRef(false);\n  const id = React.useId();\n  const titleId = `${id}-title`;\n  const descId = `${id}-desc`;\n  const mounted = React.useSyncExternalStore(subscribe, () => true, () => false);\n\n  if (isOpen && !present) setPresent(true);\n\n  const setOpen = React.useCallback(\n    (next: boolean) => {\n      if (open === undefined) setInner(next);\n      onOpenChange?.(next);\n    },\n    [open, onOpenChange],\n  );\n  const close = React.useCallback(() => setOpen(false), [setOpen]);\n\n  React.useEffect(() => {\n    if (!isOpen) return;\n    const previous = document.activeElement as HTMLElement | null;\n    if (autoFocus) {\n      const node = panel.current;\n      const preferred = node?.querySelector<HTMLElement>(\"[data-autofocus]\");\n      const first = preferred ?? node?.querySelector<HTMLElement>(focusableSelector);\n      (first ?? node)?.focus({ preventScroll: true });\n    }\n    return () => {\n      if (previous && previous !== document.body && previous.isConnected) {\n        previous.focus({ preventScroll: true });\n      }\n    };\n  }, [isOpen, autoFocus]);\n\n  React.useEffect(() => {\n    if (isOpen || !present) return;\n    const timer = setTimeout(() => setPresent(false), 200);\n    return () => clearTimeout(timer);\n  }, [isOpen, present]);\n\n  function handleKeyDown(e: React.KeyboardEvent<HTMLDivElement>) {\n    if (e.key === \"Escape\" && closeOnEscape) {\n      e.stopPropagation();\n      close();\n      return;\n    }\n    if (e.key !== \"Tab\") return;\n    const node = panel.current;\n    if (!node) return;\n    const items = Array.from(node.querySelectorAll<HTMLElement>(focusableSelector));\n    if (items.length === 0) {\n      e.preventDefault();\n      node.focus();\n      return;\n    }\n    const first = items[0];\n    const last = items[items.length - 1];\n    const active = document.activeElement;\n    if (e.shiftKey && (active === first || active === node)) {\n      e.preventDefault();\n      last.focus();\n    } else if (!e.shiftKey && active === last) {\n      e.preventDefault();\n      first.focus();\n    } else if (!node.contains(active)) {\n      e.preventDefault();\n      first.focus();\n    }\n  }\n\n  const resolvedFooter = typeof footer === \"function\" ? footer(close) : footer;\n  const vars = {\n    \"--hb-dlg-accent\": accent,\n    \"--hb-dlg-w\": `${maxWidth}px`,\n    ...style,\n  } as React.CSSProperties;\n\n  const layer = present ? (\n    <div\n      className={`hb-dlg-scrim ${className}`}\n      style={vars}\n      data-container={container}\n      data-state={isOpen ? \"open\" : \"closed\"}\n      onKeyDown={handleKeyDown}\n      onMouseDown={(e) => {\n        downOnScrim.current = e.target === e.currentTarget;\n      }}\n      onClick={(e) => {\n        if (closeOnScrim && downOnScrim.current && e.target === e.currentTarget) close();\n        downOnScrim.current = false;\n      }}\n    >\n      <div\n        ref={panel}\n        role=\"dialog\"\n        aria-modal=\"true\"\n        aria-labelledby={title ? titleId : undefined}\n        aria-describedby={description ? descId : undefined}\n        tabIndex={-1}\n        className=\"hb-dlg-panel\"\n        data-variant={variant}\n        {...rest}\n      >\n        {(title || description || variant === \"destructive\") && (\n          <div className=\"hb-dlg-head\">\n            {variant === \"destructive\" && (\n              <span className=\"hb-dlg-badge\" aria-hidden=\"true\">\n                <svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n                  <path d=\"M10.3 3.9 1.8 18a2 2 0 0 0 1.7 3h17a2 2 0 0 0 1.7-3L13.7 3.9a2 2 0 0 0-3.4 0Z\" />\n                  <path d=\"M12 9v4M12 17h.01\" />\n                </svg>\n              </span>\n            )}\n            <div className=\"hb-dlg-text\">\n              {title && (\n                <h2 id={titleId} className=\"hb-dlg-title\">\n                  {title}\n                </h2>\n              )}\n              {description && (\n                <p id={descId} className=\"hb-dlg-desc\">\n                  {description}\n                </p>\n              )}\n            </div>\n          </div>\n        )}\n        {showClose && (\n          <button type=\"button\" className=\"hb-dlg-x\" aria-label=\"Close dialog\" onClick={close}>\n            <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.75\" strokeLinecap=\"round\" aria-hidden=\"true\">\n              <path d=\"m3.5 3.5 9 9m0-9-9 9\" />\n            </svg>\n          </button>\n        )}\n        <div className=\"hb-dlg-body\">{children}</div>\n        {resolvedFooter && <div className=\"hb-dlg-foot\">{resolvedFooter}</div>}\n      </div>\n    </div>\n  ) : null;\n\n  return (\n    <>\n      <style href=\"hb-dialog-modal\" precedence=\"default\">{css}</style>\n      {trigger !== undefined && (\n        <button\n          type=\"button\"\n          className=\"hb-dlg-trigger\"\n          aria-haspopup=\"dialog\"\n          aria-expanded={isOpen}\n          onClick={() => setOpen(true)}\n        >\n          {trigger}\n        </button>\n      )}\n      {container === \"viewport\" ? (mounted && layer ? createPortal(layer, document.body) : null) : layer}\n    </>\n  );\n}\n"
    }
  ]
}