# Notice (/docs/agent-ui/components/notice)

Use a notice for something worth reading that isn't a message, like a rate limit, a lost connection or a finished setup. Its mark and colors say whether it's information, a success, a warning or an error.

<Example caption="Press Dismiss on Rate limited: focus moves on to Retry, the notice fades out, then it's removed.">
<Basic />

```tsx
"use client";
import { useState } from "react";
import { Notice } from "@/components/ui/notice";

const button = "self-start rounded-md border border-[var(--kind-color-border)] px-2.5 py-1 text-sm";

export default function NoticeExample() {
  const [rateLimited, setRateLimited] = useState(true);

  return (
    <div className="flex w-full max-w-xl flex-col gap-3">
      <Notice label="Indexing your files">Answers may miss files added in the last minute.</Notice>
      <Notice variant="success" label="Connected to GitHub">
        The assistant can read your repositories now.
      </Notice>
      {rateLimited ? (
        <Notice variant="warning" label="Rate limited" onDismiss={() => setRateLimited(false)}>
          Responses are slower for the next few minutes.
        </Notice>
      ) : (
        <button type="button" className={button} onClick={() => setRateLimited(true)}>
          Show the warning again
        </button>
      )}
      <Notice
        variant="error"
        label="Couldn't reach the model"
        actions={
          <button type="button" className={button}>
            Retry
          </button>
        }
      >
        Check your connection and try again.
      </Notice>
    </div>
  );
}
```
</Example>

## Installation [#installation]

```bash tab="React"
npx shadcn@latest add @kind-ui/notice
```

```bash tab="Web Components"
npx shadcn@latest add @kind-ui/notice-web
```

## Composition [#composition]

```text
Notice
├── NoticeIcon
├── NoticeTitle
├── NoticeDescription
├── NoticeActions
└── NoticeDismiss
```

`Notice` renders these parts: a note named by its `label`. `NoticeIcon` is the status mark, named **Info**, **Success**, **Warning** or **Error**, so the variant has words as well as a color. `NoticeTitle` shows the `label`, `NoticeDescription` holds the notice's `children`, `NoticeActions` holds its `actions`, and `NoticeDismiss` is the **Dismiss** button. To arrange the parts yourself, render them inside `NoticeRoot`.

## Usage [#usage]

### Variants [#variants]

Pass `variant` as `"info"` (the default), `"success"`, `"warning"` or `"error"`. Each has its own mark and tint, which stay readable in light and dark, and the mark keeps its glyph in forced colors. Put buttons that act on the notice, like **Retry**, in `actions`.

```tsx
<Notice variant="error" label="Couldn't reach the model" actions={<button type="button">Retry</button>}>
  Check your connection and try again.
</Notice>
```

### Dismiss [#dismiss]

Pass `onDismiss` to show **Dismiss**. Pressing it moves focus out of the notice first, to the element `focusFallback` returns, else to the next element Tab reaches after the notice (the last one before it when nothing follows). Then the notice fades out, and `onDismiss` is called: remove the notice then. Return a promise to keep it until the promise settles; a rejection brings the notice back.

```tsx
const [shown, setShown] = useState(true);

{shown ? (
  <Notice variant="warning" label="Rate limited" onDismiss={() => setShown(false)}>
    Responses are slower for the next few minutes.
  </Notice>
) : null}
```

A notice you remove without **Dismiss** leaves at once, like any other content you stop rendering.

### Announcements [#announcements]

A notice that's on the page as it loads is read with the page and isn't announced. One you add later rises in and its `label` is announced, once, as is a change of `variant`. Editing its text isn't announced.

### Motion [#motion]

A notice added later rises and fades in, and **Dismiss** fades it out. Under `prefers-reduced-motion`, or with `motion="reduced"`, it only fades, and with `motion="none"` nothing animates.

## API Reference [#api-reference]

### NoticeOptions

| Prop             | Type                                                    | Description                                                                                                                                                           |
| ---------------- | ------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `variant?`       | `"error" \| "info" \| "success" \| "warning"`           | How the notice reads: its icon and colors. Default: `"info"`                                                                                                          |
| `label?`         | `string \| undefined`                                   | The notice's title, which names it. Announced when the notice is added after the page loads, or when its variant changes.                                             |
| `onDismiss?`     | `(() => unknown) \| undefined`                          | Called once Dismiss has faded the notice out: remove the notice then. Shows Dismiss while set. Return a promise to wait for it: a rejection brings the notice back.   |
| `focusFallback?` | `(() => HTMLElement \| null \| undefined) \| undefined` | Where focus goes when Dismiss is pressed. Defaults to the next element Tab reaches after the notice, else the last one before it.                                     |
| `motion?`        | `"auto" \| "none" \| "reduced"`                         | How the notice comes in and leaves: at full motion it rises in and fades out; reduced motion only fades. `"auto"` follows `prefers-reduced-motion`. Default: `"auto"` |

### Agent [#agent]

An agent connected with `createAgent` finds the notice by its label. `dismiss()` does what **Dismiss** does, offered while `onDismiss` is set and the notice isn't already leaving. It doesn't ask a person first.

### NoticeAgentActions

| Prop      | Type                        | Description                                                                                                             |
| --------- | --------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| `dismiss` | `(() => void) \| undefined` | Moves focus out of the notice, fades it out, then calls `onDismiss`, as Dismiss does. Offered while `onDismiss` is set. |

<Caption>
Runs in React and Web Components. On `<kind-notice>`, props are kebab-case attributes and `focusFallback` is a property. Write the text inside a `<kind-notice-description>` and buttons inside a `<kind-notice-actions>`; the element adds its mark, title and Dismiss. The `can-dismiss` attribute shows Dismiss, which fires `dismiss` once the notice has faded: remove it then, or call `event.detail.waitUntil(promise)`.
</Caption>