nook
Browse the docs

Components

Banner

Native

A strip across the top of a page for one message that concerns everyone.

See the prompt

Version 2.4 is out. Read the release notes

Annual plans are 20% off until Friday. See plans

Scheduled maintenance on Sunday, 02:00 to 03:00 UTC.

Payments are failing for some cards. Follow the status page

Installation

npx nook-ui@latest add banner

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 "Banner" component to this project, exactly as Nook ships it.

A strip across the top of a page for one message that concerns everyone.

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 banner`. It writes `components/ui/banner.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/banner.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 { AlertIcon, InfoIcon } from "@/components/icons";
import { Banner, BannerContent } from "@/components/ui/banner";

export default function BannerDefault() {
  return (
    <div className="grid w-full gap-3">
      <Banner dismissible>
        <InfoIcon />
        <BannerContent>
          Version 2.4 is out. <a href="#notes">Read the release notes</a>
        </BannerContent>
      </Banner>
      <Banner variant="brand" aria-label="Offer" dismissible>
        <BannerContent>
          Annual plans are 20% off until Friday. <a href="#plans">See plans</a>
        </BannerContent>
      </Banner>
      <Banner variant="inverse" aria-label="Maintenance">
        <BannerContent>Scheduled maintenance on Sunday, 02:00 to 03:00 UTC.</BannerContent>
      </Banner>
      <Banner variant="destructive" aria-label="Outage">
        <AlertIcon />
        <BannerContent>
          Payments are failing for some cards. <a href="#status">Follow the status page</a>
        </BannerContent>
      </Banner>
    </div>
  );
}
```

API
- `Banner`: The strip.
  - `variant` (`"default" | "brand" | "inverse" | "destructive"`, default "default"): The tone.
  - `dismissible` (`boolean`): Adds a close button.
  - `onDismiss` (`() => void`): Called when it is closed, to remember the choice.
- `BannerContent`: The message. Links inside it are underlined.
- Variant `variant`: default, brand, inverse, destructive (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: A named region, so it can be found from the landmarks list: set `aria-label` when a page has more than one. The close button is labelled Dismiss.

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

Usage

import { AlertIcon, InfoIcon } from "@/components/icons";
import { Banner, BannerContent } from "@/components/ui/banner";

export default function BannerDefault() {
  return (
    <div className="grid w-full gap-3">
      <Banner dismissible>
        <InfoIcon />
        <BannerContent>
          Version 2.4 is out. <a href="#notes">Read the release notes</a>
        </BannerContent>
      </Banner>
      <Banner variant="brand" aria-label="Offer" dismissible>
        <BannerContent>
          Annual plans are 20% off until Friday. <a href="#plans">See plans</a>
        </BannerContent>
      </Banner>
      <Banner variant="inverse" aria-label="Maintenance">
        <BannerContent>Scheduled maintenance on Sunday, 02:00 to 03:00 UTC.</BannerContent>
      </Banner>
      <Banner variant="destructive" aria-label="Outage">
        <AlertIcon />
        <BannerContent>
          Payments are failing for some cards. <a href="#status">Follow the status page</a>
        </BannerContent>
      </Banner>
    </div>
  );
}

Examples

With an action

Your trial ends in 3 days. Pick a plan to keep your projects.

Cookie notice

We use cookies to remember your sign-in and measure traffic. Privacy policy

Long message

We are moving your files to the new storage region this weekend. Uploads may be slow between Saturday 22:00 and Sunday 06:00 UTC, and nothing will be lost. Details

Variants

Defined in one place with cva, at the top of the component file.

  • variant

    default (default)brandinversedestructive

Props

Banner

The strip.

PropTypeDefaultDescription
variant"default" | "brand" | "inverse" | "destructive""default"The tone.
dismissibleboolean–Adds a close button.
onDismiss() => void–Called when it is closed, to remember the choice.

BannerContent

The message. Links inside it are underlined.

Accessibility

A named region, so it can be found from the landmarks list: set `aria-label` when a page has more than one. The close button is labelled Dismiss.

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