{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "modal",
  "type": "registry:ui",
  "title": "Modal",
  "description": "Dialog over a dimmed page with a header, scrolling body and actions, plus an alert dialog for destructive confirms.",
  "dependencies": [
    "@remixicon/react@^4.9.0",
    "react-aria-components@^1.17.0"
  ],
  "registryDependencies": [
    "button",
    "close-button",
    "cx",
    "direction",
    "scroll-fade",
    "spinner"
  ],
  "files": [
    {
      "path": "components/base/modal/modal.tsx",
      "content": "\"use client\";\n\nimport {\n  Children,\n  createContext,\n  isValidElement,\n  useContext,\n  useId,\n  useLayoutEffect,\n  useState,\n} from \"react\";\nimport type { ComponentType, ReactElement, ReactNode } from \"react\";\nimport {\n  Dialog as AriaDialog,\n  DialogTrigger as AriaDialogTrigger,\n  Heading as AriaHeading,\n  Modal as AriaModal,\n  ModalOverlay as AriaModalOverlay,\n  OverlayTriggerStateContext,\n  Pressable,\n} from \"react-aria-components\";\nimport type { DialogRenderProps, DialogTriggerProps, ModalOverlayProps } from \"react-aria-components\";\nimport { RiErrorWarningLine } from \"@remixicon/react\";\nimport { Button } from \"@/components/base/buttons/button\";\nimport { CloseButton } from \"@/components/base/buttons/close-button\";\nimport { SpinnerGlyph } from \"@/components/base/spinner/spinner\";\nimport { useDirection } from \"@/components/foundations/direction/direction\";\nimport { ScrollFade, useScrollFade } from \"@/components/foundations/scroll-fade/scroll-fade\";\nimport { cx, sortCx } from \"@/utils/cx\";\n\n/**\n * Modal — a centred dialog over a dimmed page, built on React Aria's\n * ModalOverlay / Modal / Dialog: focus is trapped inside and returns to the\n * trigger on close, the page behind stops scrolling, and Escape or a press on\n * the backdrop dismisses it.\n *\n *   <ModalTrigger>\n *     <Button>Invite teammates</Button>\n *     <Modal>\n *       {({ close }) => (\n *         <>\n *           <ModalHeader title=\"Invite teammates\" description=\"…\" />\n *           <ModalBody>…</ModalBody>\n *           <ModalFooter>\n *             <Button variant=\"secondary\" onClick={close}>Cancel</Button>\n *             <Button onClick={close}>Send invites</Button>\n *           </ModalFooter>\n *         </>\n *       )}\n *     </Modal>\n *   </ModalTrigger>\n *\n * Or control it from your own state with `isOpen` / `onOpenChange`, no trigger.\n * `AlertDialog` is the destructive-confirm preset: role=\"alertdialog\", no\n * backdrop dismissal, focus starts on Cancel.\n *\n * Surface and motion follow Settings Modal: black/70 backdrop fading over\n * 300ms; the panel fades and sharpens from scale 0.85 and a 4px blur over\n * 300ms on the iOS sheet curve, and plays the same transition in reverse\n * before it unmounts. Reduced motion keeps the fade and drops the scale and\n * blur.\n */\n\ntype IconComponent = ComponentType<{ className?: string; \"aria-hidden\"?: boolean | \"true\" | \"false\" }>;\n\nexport type ModalSize = \"sm\" | \"md\" | \"lg\" | \"xl\";\n\nconst styles = sortCx({\n  overlay: \"group/modal fixed inset-x-0 top-0 z-100 flex h-(--visual-viewport-height) items-center justify-center p-4 sm:p-6\",\n  backdrop: [\n    \"absolute inset-0 bg-black/70\",\n    \"transition-opacity duration-300 ease-out\",\n    \"group-data-[entering]/modal:opacity-0 group-data-[exiting]/modal:opacity-0\",\n  ].join(\" \"),\n  modal: [\n    \"relative flex max-h-full w-full flex-col outline-none\",\n    \"transform-gpu transition-[opacity,scale,filter] duration-300 ease-[cubic-bezier(0.32,0.72,0,1)]\",\n    \"data-[entering]:opacity-0 data-[exiting]:opacity-0\",\n    \"motion-safe:data-[entering]:scale-[0.85] motion-safe:data-[entering]:blur-[4px]\",\n    \"motion-safe:data-[exiting]:scale-[0.85] motion-safe:data-[exiting]:blur-[4px]\",\n  ].join(\" \"),\n  dialog: [\n    // overflow-CLIP, not hidden: a hidden box is still programmatically\n    // scrollable, so focusing a field clipped by the body's scroller could\n    // scroll the whole panel instead (see Settings Modal).\n    \"flex min-h-0 flex-col gap-4 overflow-clip py-6 outline-none\",\n    // Settings Modal's surface: page white in light mode, and in dark mode a\n    // ground darker than the inputs and menus it holds, so they keep an edge.\n    \"rounded-3xl border border-separator-border bg-background-full shadow-xs\",\n  ].join(\" \"),\n  size: {\n    sm: \"max-w-[400px]\",\n    md: \"max-w-[480px]\",\n    lg: \"max-w-[640px]\",\n    xl: \"max-w-[800px]\",\n  },\n  icon: {\n    default: \"bg-background-tertiary-default text-foreground-icon-secondary\",\n    danger: \"bg-notification-error-background text-notification-error-foreground\",\n  },\n});\n\n/* ------------------------------------------------------------------ context */\n\ninterface ModalContextValue {\n  descriptionId: string;\n  setDescribed: (described: boolean) => void;\n}\n\nconst ModalContext = createContext<ModalContextValue | null>(null);\n\n/** Closes the surrounding Modal, Drawer, or AlertDialog. */\nexport function useModalClose() {\n  const state = useContext(OverlayTriggerStateContext);\n  return () => state?.close();\n}\n\n/* ------------------------------------------------------------------ trigger */\n\nexport interface ModalTriggerProps extends Omit<DialogTriggerProps, \"children\"> {\n  /**\n   * The trigger, then the Modal (or AlertDialog). The trigger can be any\n   * BoardUI button: anything that forwards its ref and spreads its props.\n   * React Aria's own Button already speaks to DialogTrigger; use that\n   * directly instead of wrapping it here.\n   */\n  children: ReactNode;\n}\n\nexport function ModalTrigger({ children, ...props }: ModalTriggerProps) {\n  const [trigger, ...rest] = Children.toArray(children);\n  return (\n    <AriaDialogTrigger {...props}>\n      {isValidElement(trigger) ? <Pressable>{trigger as ReactElement<Record<string, unknown>, string>}</Pressable> : trigger}\n      {rest}\n    </AriaDialogTrigger>\n  );\n}\n\n/* -------------------------------------------------------------------- modal */\n\nexport interface ModalProps extends Omit<ModalOverlayProps, \"children\" | \"className\" | \"style\"> {\n  /** Panel width: 400, 480 (default), 640, or 800px. */\n  size?: ModalSize;\n  /** `alertdialog` for confirmations that interrupt the user; see AlertDialog. */\n  role?: \"dialog\" | \"alertdialog\";\n  /** Accessible name when the content has no ModalHeader title. */\n  \"aria-label\"?: string;\n  /** Classes on the panel surface (the dialog). */\n  className?: string;\n  /** Classes on the full-screen overlay, e.g. to align the panel to the top. */\n  overlayClassName?: string;\n  children: ReactNode | ((renderProps: DialogRenderProps) => ReactNode);\n}\n\nexport function Modal({\n  size = \"md\",\n  role,\n  \"aria-label\": ariaLabel,\n  className,\n  overlayClassName,\n  isDismissable = true,\n  children,\n  ...props\n}: ModalProps) {\n  const direction = useDirection();\n\n  return (\n    <AriaModalOverlay {...props} dir={direction} isDismissable={isDismissable} className={cx(styles.overlay, overlayClassName)}>\n      <div aria-hidden className={styles.backdrop} />\n      <AriaModal className={cx(styles.modal, styles.size[size])}>\n        <ModalDialog role={role} aria-label={ariaLabel} className={className}>\n          {children}\n        </ModalDialog>\n      </AriaModal>\n    </AriaModalOverlay>\n  );\n}\n\nexport interface ModalDialogProps {\n  role?: \"dialog\" | \"alertdialog\";\n  \"aria-label\"?: string;\n  /** Classes merged onto the panel surface. */\n  className?: string;\n  children: ReactNode | ((renderProps: DialogRenderProps) => ReactNode);\n}\n\n/**\n * The panel surface and dialog element shared by Modal and Drawer: the\n * ModalHeader title names it and the description is wired to\n * aria-describedby. Render it inside a React Aria Modal.\n */\nexport function ModalDialog({ role, \"aria-label\": ariaLabel, className, children }: ModalDialogProps) {\n  const descriptionId = useId();\n  const [described, setDescribed] = useState(false);\n\n  return (\n    <AriaDialog\n      role={role}\n      aria-label={ariaLabel}\n      aria-describedby={described ? descriptionId : undefined}\n      className={cx(styles.dialog, className)}\n    >\n      {(renderProps) => (\n        <ModalContext.Provider value={{ descriptionId, setDescribed }}>\n          {typeof children === \"function\" ? children(renderProps) : children}\n        </ModalContext.Provider>\n      )}\n    </AriaDialog>\n  );\n}\n\n/* ------------------------------------------------------------------ content */\n\nexport interface ModalHeaderProps {\n  title: ReactNode;\n  /** Supporting copy under the title; announced as the dialog's description. */\n  description?: ReactNode;\n  /** Remix Icon shown in a 40px circle above the title. */\n  icon?: IconComponent;\n  /** `danger` tints the icon circle for destructive dialogs. */\n  tone?: \"default\" | \"danger\";\n  /** Show the dismiss button in the top corner. Default true. */\n  showCloseButton?: boolean;\n  closeLabel?: string;\n  className?: string;\n  /** Extra content under the description, e.g. tabs or a step indicator. */\n  children?: ReactNode;\n}\n\nexport function ModalHeader({\n  title,\n  description,\n  icon: Icon,\n  tone = \"default\",\n  showCloseButton = true,\n  closeLabel = \"Close\",\n  className,\n  children,\n}: ModalHeaderProps) {\n  const context = useContext(ModalContext);\n  const close = useModalClose();\n  const setDescribed = context?.setDescribed;\n  const hasDescription = description != null && description !== false;\n\n  useLayoutEffect(() => {\n    if (!hasDescription || !setDescribed) return;\n    setDescribed(true);\n    return () => setDescribed(false);\n  }, [hasDescription, setDescribed]);\n\n  return (\n    <div className={cx(\"flex shrink-0 items-start gap-3 px-6\", className)}>\n      <div className=\"flex min-w-0 flex-1 flex-col\">\n        {Icon ? (\n          <span className={cx(\"mb-4 flex size-10 shrink-0 items-center justify-center rounded-full\", styles.icon[tone])}>\n            <Icon className=\"size-5\" aria-hidden />\n          </span>\n        ) : null}\n        <AriaHeading slot=\"title\" className=\"text-title-3-medium text-text-primary\">\n          {title}\n        </AriaHeading>\n        {hasDescription ? (\n          <p id={context?.descriptionId} className=\"mt-1 text-body-regular text-text-secondary\">\n            {description}\n          </p>\n        ) : null}\n        {children}\n      </div>\n      {showCloseButton ? (\n        <CloseButton size=\"sm\" aria-label={closeLabel} onClick={close} className=\"-me-1 shrink-0\" />\n      ) : null}\n    </div>\n  );\n}\n\nexport interface ModalBodyProps {\n  /** Classes on the scrolling region (it carries px-6 by default). */\n  className?: string;\n  children: ReactNode;\n}\n\n/**\n * The content between the header and the footer. It scrolls on its own when\n * the panel reaches the viewport's height, with the header and footer held\n * in place and a progressive blur softening the top edge once scrolled.\n */\nexport function ModalBody({ className, children }: ModalBodyProps) {\n  const fade = useScrollFade();\n  return (\n    // flex-1 fills a full-height panel (Drawer) and is inert in an\n    // auto-height one: a 0% basis against an indefinite height acts as auto.\n    <div className=\"relative flex min-h-0 flex-1 flex-col\">\n      <div\n        onScroll={fade.onScroll}\n        className={cx(\"min-h-0 flex-1 overflow-y-auto overscroll-contain px-6 py-1 text-body-regular text-text-secondary\", className)}\n      >\n        {children}\n      </div>\n      <ScrollFade progress={fade.progress} surfaceClassName=\"from-background-full\" />\n    </div>\n  );\n}\n\nexport function ModalFooter({ className, children }: { className?: string; children: ReactNode }) {\n  return (\n    <div\n      className={cx(\n        // Stacked full-width on phones (primary action on top), a trailing\n        // row from sm up. 8px extra over the dialog's gap-4 sets the actions\n        // apart from the content.\n        \"mt-2 flex shrink-0 flex-col-reverse gap-2 px-6 sm:flex-row sm:items-center sm:justify-end\",\n        className,\n      )}\n    >\n      {children}\n    </div>\n  );\n}\n\n/* ------------------------------------------------------------- alert dialog */\n\nexport interface AlertDialogProps\n  extends Omit<ModalProps, \"children\" | \"role\" | \"aria-label\" | \"isDismissable\"> {\n  title: ReactNode;\n  description?: ReactNode;\n  /** `danger` (default) pairs a tinted warning icon with a danger confirm button. */\n  variant?: \"danger\" | \"default\";\n  /** Leading icon; `false` hides it. Defaults to a warning glyph. */\n  icon?: IconComponent | false;\n  confirmLabel?: ReactNode;\n  cancelLabel?: ReactNode;\n  /**\n   * Runs on confirm. Return a promise to keep the dialog open until it\n   * settles: Cancel is disabled, and the confirm button turns busy with a\n   * spinner and `pendingLabel`. It closes on success and stays open if the\n   * promise rejects.\n   */\n  onConfirm?: () => void | Promise<unknown>;\n  onCancel?: () => void;\n  /** Confirm-button label while an async `onConfirm` runs. */\n  pendingLabel?: ReactNode;\n  /** Disables the confirm action, e.g. until a confirmation phrase is typed. */\n  isConfirmDisabled?: boolean;\n  /** Close on a backdrop press. Off by default: an alert asks for an answer. */\n  isDismissable?: boolean;\n  /** Extra content between the description and the actions. */\n  children?: ReactNode;\n}\n\n/** Spinner sized for Button's icon slot, in the button's own text colour. */\nfunction PendingGlyph({ className }: { className?: string }) {\n  return <SpinnerGlyph size=\"sm\" className={cx(className, \"text-current\")} />;\n}\n\nexport function AlertDialog({\n  title,\n  description,\n  variant = \"danger\",\n  icon = RiErrorWarningLine,\n  confirmLabel = \"Confirm\",\n  cancelLabel = \"Cancel\",\n  onConfirm,\n  onCancel,\n  pendingLabel,\n  isConfirmDisabled = false,\n  isDismissable = false,\n  size = \"sm\",\n  children,\n  ...props\n}: AlertDialogProps) {\n  const [pending, setPending] = useState(false);\n\n  return (\n    <Modal {...props} size={size} role=\"alertdialog\" isDismissable={isDismissable && !pending} isKeyboardDismissDisabled={pending}>\n      {({ close }) => {\n        const confirm = async () => {\n          if (pending) return;\n          const result = onConfirm?.();\n          if (!result || typeof result.then !== \"function\") return close();\n          setPending(true);\n          try {\n            await result;\n            close();\n          } catch {\n            // Stay open: the caller reports the failure.\n          } finally {\n            setPending(false);\n          }\n        };\n\n        return (\n          <>\n            <ModalHeader\n              title={title}\n              description={description}\n              icon={icon || undefined}\n              tone={variant === \"danger\" ? \"danger\" : \"default\"}\n              showCloseButton={false}\n            />\n            {children ? <ModalBody>{children}</ModalBody> : null}\n            <ModalFooter>\n              <Button\n                variant=\"secondary\"\n                autoFocus\n                disabled={pending}\n                onClick={() => {\n                  onCancel?.();\n                  close();\n                }}\n              >\n                {cancelLabel}\n              </Button>\n              <Button\n                variant={variant === \"danger\" ? \"danger\" : \"primary\"}\n                // Busy rather than disabled while pending: the button keeps\n                // its colour, so the spinner on it stays legible.\n                disabled={isConfirmDisabled}\n                aria-busy={pending || undefined}\n                leadingIcon={pending ? PendingGlyph : undefined}\n                onClick={confirm}\n              >\n                {pending && pendingLabel ? pendingLabel : confirmLabel}\n              </Button>\n            </ModalFooter>\n          </>\n        );\n      }}\n    </Modal>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/base/modal/modal.tsx"
    }
  ],
  "meta": {
    "docsUrl": "https://www.boardui.com/components/modal",
    "example": "import { RiMailLine, RiUserAddLine } from \"@remixicon/react\";\nimport { Button } from \"@/components/base/buttons/button\";\nimport { Input } from \"@/components/base/input/input\";\nimport { Modal, ModalBody, ModalFooter, ModalHeader, ModalTrigger } from \"@/components/base/modal/modal\";\nimport { Select, SelectItem } from \"@/components/base/select/select\";\n\nexport function Example() {\n  return (\n    <ModalTrigger>\n      <Button leadingIcon={RiUserAddLine}>Invite teammates</Button>\n      <Modal>\n        {({ close }) => (\n          <>\n            <ModalHeader\n              title=\"Invite teammates\"\n              description=\"They get an email with a link to join the Acme workspace.\"\n            />\n            <ModalBody>\n              <form id=\"invite-form\" className=\"flex flex-col gap-4\" onSubmit={(event) => { event.preventDefault(); close(); }}>\n                <Input label=\"Email address\" type=\"email\" placeholder=\"name@company.com\" leadingIcon={RiMailLine} isRequired />\n                <Select label=\"Role\" defaultSelectedKey=\"member\" className=\"gap-1.5\" triggerClassName=\"w-full\" popoverClassName=\"w-(--trigger-width)\">\n                  <SelectItem id=\"admin\" textValue=\"Admin\">Admin</SelectItem>\n                  <SelectItem id=\"member\" textValue=\"Member\">Member</SelectItem>\n                  <SelectItem id=\"viewer\" textValue=\"Viewer\">Viewer</SelectItem>\n                </Select>\n              </form>\n            </ModalBody>\n            <ModalFooter>\n              <Button variant=\"secondary\" onClick={close}>Cancel</Button>\n              <Button type=\"submit\" form=\"invite-form\">Send invite</Button>\n            </ModalFooter>\n          </>\n        )}\n      </Modal>\n    </ModalTrigger>\n  );\n}",
    "snippets": [
      {
        "label": "alert",
        "code": "import { RiDeleteBinLine } from \"@remixicon/react\";\nimport { Button } from \"@/components/base/buttons/button\";\nimport { AlertDialog, ModalTrigger } from \"@/components/base/modal/modal\";\n\n<ModalTrigger>\n  <Button variant=\"danger\" leadingIcon={RiDeleteBinLine}>Delete project</Button>\n  <AlertDialog\n    title=\"Delete project?\"\n    description=\"Acme Dashboard and its 24 files will be deleted for everyone. You can't undo this.\"\n    confirmLabel=\"Delete project\"\n    pendingLabel=\"Deleting...\"\n    onConfirm={() => deleteProject(projectId)} // return the promise to keep it open until done\n  />\n</ModalTrigger>"
      },
      {
        "label": "typed",
        "code": "const [phrase, setPhrase] = useState(\"\");\n\n<ModalTrigger onOpenChange={(open) => !open && setPhrase(\"\")}>\n  <Button variant=\"secondary\">Transfer ownership</Button>\n  <AlertDialog\n    title=\"Transfer workspace ownership?\"\n    description=\"Maya Chen becomes the owner and you become an admin. Type acme below to confirm.\"\n    confirmLabel=\"Transfer ownership\"\n    isConfirmDisabled={phrase !== \"acme\"}\n  >\n    <Input aria-label=\"Workspace name\" placeholder=\"acme\" value={phrase} onChange={setPhrase} autoComplete=\"off\" />\n  </AlertDialog>\n</ModalTrigger>"
      },
      {
        "label": "scrolling",
        "code": "<ModalTrigger>\n  <Button variant=\"secondary\" leadingIcon={RiFileTextLine}>Review terms</Button>\n  <Modal size=\"lg\">\n    {({ close }) => (\n      <>\n        <ModalHeader title=\"Terms of service\" description=\"Last updated 1 October 2026\" />\n        <ModalBody>{/* any amount of content */}</ModalBody>\n        <ModalFooter>\n          <Button variant=\"secondary\" onClick={close}>Decline</Button>\n          <Button onClick={close}>Accept</Button>\n        </ModalFooter>\n      </>\n    )}\n  </Modal>\n</ModalTrigger>"
      },
      {
        "label": "controlled",
        "code": "const [isOpen, setIsOpen] = useState(false);\n\n<Button variant=\"secondary\" onClick={() => setIsOpen(true)}>Rename project</Button>\n\n<Modal isOpen={isOpen} onOpenChange={setIsOpen} size=\"sm\">\n  <ModalHeader title=\"Rename project\" />\n  <ModalBody>\n    <form id=\"rename-form\" onSubmit={(event) => { event.preventDefault(); save(); setIsOpen(false); }}>\n      <Input aria-label=\"Project name\" value={draft} onChange={setDraft} autoFocus />\n    </form>\n  </ModalBody>\n  <ModalFooter>\n    <Button variant=\"secondary\" onClick={() => setIsOpen(false)}>Cancel</Button>\n    <Button type=\"submit\" form=\"rename-form\">Save</Button>\n  </ModalFooter>\n</Modal>"
      },
      {
        "label": "sizes",
        "code": "<Modal size=\"sm\">…</Modal> // 400px, the AlertDialog default\n<Modal size=\"md\">…</Modal> // 480px, the default\n<Modal size=\"lg\">…</Modal> // 640px\n<Modal size=\"xl\">…</Modal> // 800px\n\n// Without a ModalHeader, name the dialog yourself\n<Modal aria-label=\"Keyboard shortcuts\">…</Modal>"
      },
      {
        "label": "rtl",
        "code": "import { DirectionProvider } from \"@/components/foundations/direction/direction\";\n\n<DirectionProvider locale=\"ar\">\n  <ModalTrigger>\n    <Button variant=\"secondary\">دعوة أعضاء الفريق</Button>\n    <Modal>\n      {({ close }) => (\n        <>\n          <ModalHeader title=\"دعوة أعضاء الفريق\" description=\"سيصلهم بريد إلكتروني برابط للانضمام إلى مساحة العمل.\" closeLabel=\"إغلاق\" />\n          <ModalBody>\n            <Input label=\"البريد الإلكتروني\" type=\"email\" placeholder=\"name@company.com\" />\n          </ModalBody>\n          <ModalFooter>\n            <Button variant=\"secondary\" onClick={close}>إلغاء</Button>\n            <Button onClick={close}>إرسال الدعوة</Button>\n          </ModalFooter>\n        </>\n      )}\n    </Modal>\n  </ModalTrigger>\n</DirectionProvider>"
      }
    ]
  }
}
