Dialog

A window laid over the page that leaves everything under it inert until it closes: a header with its title and description, what it holds and the footer's buttons.

import { Button } from "@produkto/ui/Button";
import {
  Dialog,
  DialogClose,
  DialogContent,
  DialogDescription,
  DialogFooter,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from "@produkto/ui/Dialog";

const Example = () => (
  <Dialog>
    <DialogTrigger asChild>
      <Button>Button</Button>
    </DialogTrigger>
    <DialogContent>
      <DialogHeader>
        <DialogTitle>Title</DialogTitle>
        <DialogDescription>Description</DialogDescription>
      </DialogHeader>
      <p>Content goes here.</p>
      <DialogFooter>
        <DialogClose asChild>
          <Button>Button</Button>
        </DialogClose>
      </DialogFooter>
    </DialogContent>
  </Dialog>
);

export default Example;

Usage

import {
  Dialog,
  DialogContent,
  DialogDescription,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from "@produkto/ui/Dialog";
<Dialog>
  <DialogTrigger>Title</DialogTrigger>
  <DialogContent>
    <DialogHeader>
      <DialogTitle>Title</DialogTitle>
      <DialogDescription>
        Description
      </DialogDescription>
    </DialogHeader>
  </DialogContent>
</Dialog>

Examples

Sizes

size sets the window: sm 384px wide, base 448px (the default), or lg, a large window most of the screen tall, the size a sidebar takes.

import { Button } from "@produkto/ui/Button";
import {
  Dialog,
  DialogContent,
  DialogDescription,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
  type DialogSize,
} from "@produkto/ui/Dialog";

const sizes: { size: DialogSize; label: string }[] = [
  { size: "sm", label: "Small" },
  { size: "base", label: "Base" },
  { size: "lg", label: "Large" },
];

const Example = () => (
  <div className="flex flex-wrap items-center gap-2">
    {sizes.map((item) => (
      <Dialog key={item.size}>
        <DialogTrigger asChild>
          <Button>{item.label}</Button>
        </DialogTrigger>
        <DialogContent size={item.size}>
          <DialogHeader>
            <DialogTitle>Title</DialogTitle>
            <DialogDescription>Description</DialogDescription>
          </DialogHeader>
        </DialogContent>
      </Dialog>
    ))}
  </div>
);

export default Example;

Border radius

borderRadius sets the window's corners on the kit's one scale: none, xs 4px, sm 6px, base 8px, lg 12px (the default) or xl 16px; each button opens its own dialog.

import { Button } from "@produkto/ui/Button";
import {
  Dialog,
  DialogContent,
  DialogDescription,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
  type DialogBorderRadius,
} from "@produkto/ui/Dialog";

const radii: DialogBorderRadius[] = ["none", "xs", "sm", "base", "lg", "xl"];

const Example = () => (
  <div className="flex flex-wrap items-center gap-2">
    {radii.map((borderRadius) => (
      <Dialog key={borderRadius}>
        <DialogTrigger asChild>
          <Button>{borderRadius}</Button>
        </DialogTrigger>
        <DialogContent borderRadius={borderRadius}>
          <DialogHeader>
            <DialogTitle>Title</DialogTitle>
            <DialogDescription>Description</DialogDescription>
          </DialogHeader>
        </DialogContent>
      </Dialog>
    ))}
  </div>
);

export default Example;

Alert

alert makes the dialog a question that waits for an answer: read as an alertdialog, it stays open on a click outside, which closes a dialog by default.

import { Button } from "@produkto/ui/Button";
import {
  Dialog,
  DialogClose,
  DialogContent,
  DialogDescription,
  DialogFooter,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from "@produkto/ui/Dialog";

const Example = () => (
  <Dialog>
    <DialogTrigger asChild>
      <Button>Button</Button>
    </DialogTrigger>
    <DialogContent alert>
      <DialogHeader>
        <DialogTitle>Title</DialogTitle>
        <DialogDescription>Description</DialogDescription>
      </DialogHeader>
      <DialogFooter>
        <DialogClose asChild>
          <Button>Button</Button>
        </DialogClose>
      </DialogFooter>
    </DialogContent>
  </Dialog>
);

export default Example;

Scrollable

scrollable={false} stops the window scrolling as one, so a bordered DialogHeader and DialogFooter stay in place while the DialogBody between them scrolls; by default everything scrolls together.

import { Button } from "@produkto/ui/Button";
import {
  Dialog,
  DialogBody,
  DialogClose,
  DialogContent,
  DialogFooter,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from "@produkto/ui/Dialog";

const paragraphs: string[] = Array.from({ length: 10 }, () =>
  "Content goes here. ".repeat(6).trim(),
);

const Example = () => (
  <Dialog>
    <DialogTrigger asChild>
      <Button>Button</Button>
    </DialogTrigger>
    <DialogContent aria-describedby={undefined} scrollable={false}>
      <DialogHeader bordered>
        <DialogTitle>Title</DialogTitle>
      </DialogHeader>
      <DialogBody>
        {paragraphs.map((paragraph, index) => (
          <p key={index}>{paragraph}</p>
        ))}
      </DialogBody>
      <DialogFooter bordered>
        <DialogClose asChild>
          <Button size="sm">Button</Button>
        </DialogClose>
      </DialogFooter>
    </DialogContent>
  </Dialog>
);

export default Example;

API Reference

It takes the props of Radix Dialog.Root.

DialogTrigger

DialogTriggerProps · takes the props of Radix Dialog.Trigger

DialogPortal

DialogPortalProps · takes the props of Radix Dialog.Portal

DialogClose

DialogCloseProps · takes the props of Radix Dialog.Close

DialogOverlay

DialogOverlayProps · takes the props of Radix Dialog.Overlay

DialogContent

DialogContentProps<T> · also takes the props of Radix Dialog.Content
PropTypeDefault
sizeDialogSize"sm" | "base" | "lg"sidebar ? "lg" : "base"
borderRadiusDialogBorderRadius"none" | "xs" | "sm" | "base" | "lg" | "xl""lg"
alertbooleanfalse
scrollablebooleantrue
sidebarDialogSidebar<T>-

DialogHeader

DialogHeaderProps · also takes the props of <div>
PropTypeDefault
borderedbooleanfalse

DialogBody

DialogBodyProps · also takes the props of Radix Dialog.Root
PropTypeDefault
orientationScrollAreaOrientation"vertical" | "horizontal" | "both"-
viewportRefRef<HTMLDivElement>-

DialogPanel

DialogPanelProps · also takes the props of Radix Tabs.Content
PropTypeDefault
scrollablebooleantrue

DialogFooter

DialogFooterProps · also takes the props of <div>
PropTypeDefault
borderedbooleanfalse

DialogTitle

DialogTitleProps · takes the props of Radix Dialog.Title

DialogDescription

DialogDescriptionProps · takes the props of Radix Dialog.Description