Components
Alert
NativeA callout for information the user should notice, with an optional icon.
Heads up
You can change the theme at any time with a single command.
Installation
npx nook-ui@latest add alertPrompt
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.
Add the Nook "Alert" component to this project, exactly as Nook ships it.
A callout for information the user should notice, with an optional icon.
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`. It writes `components/ui/alert.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.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 { InfoIcon } from "@/components/icons";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
export default function AlertDefault() {
return (
<Alert className="max-w-xl">
<InfoIcon />
<AlertTitle>Heads up</AlertTitle>
<AlertDescription>You can change the theme at any time with a single command.</AlertDescription>
</Alert>
);
}
```
API
- `Alert`: The container. Put an icon as the first child.
- `AlertTitle`: A short heading.
- `AlertDescription`: The message.
- Variant `variant`: default, destructive, info, success, warning (default default)
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: Default alerts use role=status (polite). Destructive alerts use role=alert (assertive).
Done when the component renders like the example in light and dark mode and the project type-checks.Usage
import { InfoIcon } from "@/components/icons";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
export default function AlertDefault() {
return (
<Alert className="max-w-xl">
<InfoIcon />
<AlertTitle>Heads up</AlertTitle>
<AlertDescription>You can change the theme at any time with a single command.</AlertDescription>
</Alert>
);
}Examples
Destructive
Payment failed
Your card was declined. Check the details and try again.
Info, success and warning
Import is running
We are adding 1,240 contacts. You can leave this page.
Domain verified
Emails from hello@acme.example now pass SPF and DKIM.
Card expires soon
Your Visa ending 4242 expires on 31 March. Update it to avoid a failed renewal.
With actions
Two teammates are waiting for access
Ana Souza and Kofi Mensah asked to join Design Ops.
Title only
Changes saved
No icon, just a note: invoices are sent on the 1st.
Form errors
We could not create your workspace
Fix these and try again:
- The workspace URL “acme” is already taken.
- Enter a billing email that ends in a real domain.
Variants
Defined in one place with cva, at the top of the component file.
variant
default (default)destructiveinfosuccesswarning
Props
Alert
The container. Put an icon as the first child.
AlertTitle
A short heading.
AlertDescription
The message.
Accessibility
Default alerts use role=status (polite). Destructive alerts use role=alert (assertive).
Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.