Dialog

A modal window that overlays the page.

Installation

pnpm dlx cubix@latest add dialog --base aria

Usage

Import
import {
  Dialog,
  DialogContent,
  DialogDescription,
  DialogFooter,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from "@/components/cubix/dialog"
Example
<Dialog>
  <DialogTrigger render={<Button variant="outline" />}>
Open
</DialogTrigger>
  <DialogContent>
    <DialogHeader>
      <DialogTitle>Are you absolutely sure?</DialogTitle>
      <DialogDescription>
        This action cannot be undone. This will permanently delete your
        account and remove your data from our servers.
      </DialogDescription>
    </DialogHeader>
    <DialogFooter>
      <DialogClose render={<Button variant="outline" />}>
Cancel
</DialogClose>
      <Button variant="destructive">Delete</Button>
    </DialogFooter>
  </DialogContent>
</Dialog>

Examples

With form

Dialogs work well with form fields when you need a confirmation:

Without built-in close

Set showCloseButton= on DialogContent to hide the built-in X button and provide your own:

API Reference

Note: The dialog is built on the native <dialog> element - Escape closes it, focus is trapped, and clicking the backdrop dismisses it. State is uncontrolled by default.

Dialog

The container that wraps the trigger and the content and manages open state.

PropTypeDefaultDescription
childrenReact.ReactNode-The trigger and content elements. State is managed internally (uncontrolled).

DialogTrigger / DialogClose

The elements that open and close the dialog. Use render to merge the behavior onto a Button.

PropTypeDefaultDescription
renderReact.ReactElement-Render the trigger or close control as another element (e.g. a Button).
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

DialogContent

The content panel rendered as a native modal dialog with backdrop.

PropTypeDefaultDescription
showCloseButtonbooleantrueShow the built-in close (X) button in the top-right corner.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).
...propsReact.ComponentProps<'dialog'>-All native dialog attributes are forwarded to the rendered element.

DialogHeader / DialogFooter

Layout regions of the dialog content.

PropTypeDefaultDescription
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

DialogTitle / DialogDescription

The title and description text of the dialog.

PropTypeDefaultDescription
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).