nook
Browse the docs

Components

Alert Dialog

Built on Base UI

A dialog that needs an answer before anything else, for actions that cannot be undone.

See the prompt

Installation

npx nook-ui@latest add alert-dialog

Prompt

Paste this into your AI coding assistant. It adds this exact component, the same way the CLI does, and tells the assistant how to use it.

Short. For assistants that can run commands in your project.

Plain text
Add the Nook "Alert Dialog" component to this project, exactly as Nook ships it.

A dialog that needs an answer before anything else, for actions that cannot be undone.

Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add alert-dialog`. It writes `components/ui/alert-dialog.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/alert-dialog.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:

```tsx
import { AlertDialog, AlertDialogClose, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from "@/components/ui/alert-dialog";
import { Button } from "@/components/ui/button";

export default function AlertDialogDefault() {
  return (
    <AlertDialog>
      <AlertDialogTrigger render={<Button variant="destructive" />}>Delete workspace</AlertDialogTrigger>
      <AlertDialogContent>
        <AlertDialogHeader>
          <AlertDialogTitle>Delete the Nook workspace?</AlertDialogTitle>
          <AlertDialogDescription>All 12 projects and their files are removed for every member. This cannot be undone.</AlertDialogDescription>
        </AlertDialogHeader>
        <AlertDialogFooter>
          <AlertDialogClose render={<Button variant="outline" />}>Keep workspace</AlertDialogClose>
          <AlertDialogClose render={<Button variant="destructive" />}>Delete workspace</AlertDialogClose>
        </AlertDialogFooter>
      </AlertDialogContent>
    </AlertDialog>
  );
}
```

API
- `AlertDialog`: Holds the open state.
  - `open` (`boolean`): Controlled state.
  - `onOpenChange` (`(open: boolean) => void`): Called when it opens or closes.
- `AlertDialogTrigger`: Opens the dialog.
- `AlertDialogContent`: The popup with its backdrop.
- `AlertDialogClose`: Closes the dialog. Use it for the cancel and the confirm button.
- `AlertDialogHeader, AlertDialogFooter, AlertDialogTitle, AlertDialogDescription`: Layout and text parts.

Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: Renders role=alertdialog. It has no corner close button and ignores clicks outside, so the person must choose. Put the safe choice first in focus order.

Done when the component renders like the example in light and dark mode and the project type-checks.

Usage

import { AlertDialog, AlertDialogClose, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from "@/components/ui/alert-dialog";
import { Button } from "@/components/ui/button";

export default function AlertDialogDefault() {
  return (
    <AlertDialog>
      <AlertDialogTrigger render={<Button variant="destructive" />}>Delete workspace</AlertDialogTrigger>
      <AlertDialogContent>
        <AlertDialogHeader>
          <AlertDialogTitle>Delete the Nook workspace?</AlertDialogTitle>
          <AlertDialogDescription>All 12 projects and their files are removed for every member. This cannot be undone.</AlertDialogDescription>
        </AlertDialogHeader>
        <AlertDialogFooter>
          <AlertDialogClose render={<Button variant="outline" />}>Keep workspace</AlertDialogClose>
          <AlertDialogClose render={<Button variant="destructive" />}>Delete workspace</AlertDialogClose>
        </AlertDialogFooter>
      </AlertDialogContent>
    </AlertDialog>
  );
}

Examples

Destructive

Unsaved changes

Controlled

Priya Nair · Design Ops · Editor

Single action

Props

AlertDialog

Holds the open state.

PropTypeDefaultDescription
openboolean–Controlled state.
onOpenChange(open: boolean) => void–Called when it opens or closes.

AlertDialogTrigger

Opens the dialog.

AlertDialogContent

The popup with its backdrop.

AlertDialogClose

Closes the dialog. Use it for the cancel and the confirm button.

AlertDialogHeader, AlertDialogFooter, AlertDialogTitle, AlertDialogDescription

Layout and text parts.

Accessibility

Renders role=alertdialog. It has no corner close button and ignores clicks outside, so the person must choose. Put the safe choice first in focus order.

Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.