# Notice

A tinted panel in the content about the thing beside it: a bare icon in the tone or the agent as the subject, the title and its line, one action, and a close only when it can go, lit with a still glim at the mark.

Tier: free. Type: component. Category: feedback. Tags: agent, settings, permissions, motion.

## Install

```bash
npx shadcn@latest add https://pixilui.com/r/notice.json
```

One-time setup: add the registry to `components.json`:

```json
{
  "registries": {
    "@pixilui": "https://pixilui.com/r/{name}.json"
  }
}
```

Files: `components/pixilui/notice.tsx`.

## Preview

Live preview: https://pixilui.com/components/notice

Knobs:

- `notice`: `approval rule`, `the agent as the subject`, `a model retiring`, `couldn't load`, `live, closable`

Signature: Retry on a failed load turns the same notice in place: the words leave, the tint goes from red to neutral and the title shimmers until 47 runs loaded arrives.

Styles: `lively` (default), `quiet`, set with `data-style` on <html>. The item reads the style through the foundation; it needs no prop. Standalone files: lively https://pixilui.com/r/standalone/notice.tsx, quiet https://pixilui.com/r/standalone/notice.quiet.tsx.

## Code

`components/pixilui/notice.tsx`

```tsx
"use client";

/*
  Notice (B13, locked 2 Dec 2026 with the banner): a tinted panel in the content, about the thing beside it. A bare icon in the
  tone (18 on one line, 20 on two, centered on the words) or the locked agent avatar when the agent is the subject; the title
  in ink, its line in grey; one action from the locked buttons; a close only when it can go. The panel's detail is precise
  light: a still glim in the tone at the mark, the tint fading to its foot, a 0.5px ring in the tone, a lit top edge.

  A port of the locked notice.js, shared with the banner (NoticeFrame, kind banner or notice): the space folds open first
  (the system's fold), then the content arrives in pieces (the icon by the icon-swap recipe, then the words, then each
  button); a change of what it says turns it in place (the words and buttons leave and arrive, the icon or the agent swaps,
  a line more or less glides, the tint turns); closing, the content leaves quieter and faster, then the space folds shut.
  Every value is a token in foundation.css section 8 (--pixilui-notice-*, --pixilui-banner-*).
*/

import { forwardRef, useEffect, useLayoutEffect, useRef, useState, type ComponentPropsWithoutRef, type ReactNode } from "react";
import { flushSync } from "react-dom";
import { cn } from "./lib/utils";
import { fold } from "./lib/motion/surface";
import { prefersReducedMotion } from "./lib/motion/reduced-motion";
import { AgentAvatar, type AgentAvatarState } from "./agent-avatar";
import { Button } from "./button";

/** The locked status colors: the panel takes the fill, the glyph the hue (neutral's glyph is ink). */
export type NoticeTone = "neutral" | "done" | "warn" | "fail" | "wait" | "run";
/** One action: go is the locked primary, secondary and soft the others. */
export type NoticeAction = { label: string; kind?: "go" | "secondary" | "soft"; onClick?: () => void | Promise<void> };

export type NoticeContent = {
  /** The status color: neutral (default), done, warn, fail, wait or run. The panel takes its fill, the glyph its hue. */
  tone?: NoticeTone;
  /** A bare glyph in the tone's hue. */
  icon?: ReactNode;
  /** Or the agent as the subject: the locked agent avatar in this state (it plays its own change when the state changes). */
  agent?: AgentAvatarState;
  /** The agent's name, for screen readers. */
  agentName?: string;
  /** A notice: the title, 14/20 in ink. A banner: the lead of its line, in ink at medium. */
  title: ReactNode;
  /** A notice: the line under the title. A banner: the rest of its one line, after the lead. */
  sub?: ReactNode;
  /** Working: the title shimmers, aria-busy. */
  working?: boolean;
  /** At most one action, from the locked buttons. */
  actions?: NoticeAction[];
  /** A close, only when it can go. */
  closable?: boolean;
};

export type NoticeFrameProps = Omit<ComponentPropsWithoutRef<"div">, "title" | "children"> &
  NoticeContent & {
    kind: "banner" | "notice";
    /** Shown (default) or not: closing plays the leave, then folds the space shut. */
    open?: boolean;
    /** The close was pressed (set open to false, or remove it). */
    onClose?: () => void;
    /** After it has folded shut. */
    onClosed?: () => void;
    /** Changes when the icon changes, so a new glyph swaps in (default: the tone). */
    iconKey?: string;
    /** The close's accessible name. */
    closeLabel?: string;
    /** The close's glyph (the lock's: the static Hugeicons cancel). */
    closeIcon?: ReactNode;
  };

const CLOSE_GLYPH = (
  <svg className="pixilui-i" viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="1.5" aria-hidden="true">
    <path d="M18 6L6 18m12 0L6 6" />
  </svg>
);
// the agent: the locked avatar, its box --notice-agent-k (1.5) times the mark (18, or 20 on two lines), the toast's own
// family and color (--pixilui-notice-agent-family 2d, --notice-agent-color blue)
// each kind's parts, written out (so a one-file build keeps their rules)
const PARTS = {
  banner: { mark: "pixilui-banner-mark", actions: "pixilui-banner-actions", close: "pixilui-banner-close" },
  notice: { mark: "pixilui-notice-mark", actions: "pixilui-notice-actions", close: "pixilui-notice-close" },
};
const AGENT = { family: "2d" as const, color: "blue" as const, k: 1.5, mark: 18, mark2: 20 };

/** The lock's exit curve, a token read by name (--pixilui-ease-in). */
const EASE_EXIT = "--pixilui-ease-in"; // check-registry-ignore: a token name, not a class
// tokens read where the notice is (a one-file build scopes them to `[data-pixilui]`; the foundation sets them on :root) // brand-allow
let scope: Element | null = null;
const css = (n: string) => getComputedStyle(scope && scope.isConnected ? scope : document.documentElement).getPropertyValue((n.startsWith("--pixilui-") ? n : n.replace(/^--/, "--pixilui-"))).trim();
// a curve token; without the foundation (no tokens at all) the browser's plain ease, so nothing throws
const curve = (n: string) => css(n) || "ease";
const ms = (n: string) => { const v = css(n); return parseFloat(v) * (/\dms$/.test(v) ? 1 : 1000) || 0; };
const reduce = () => prefersReducedMotion();
const can = (el: Element | null | undefined): el is HTMLElement => !!el && typeof (el as HTMLElement).animate === "function";

// the pieces, in order: the words, then each button
const pieces = (el: HTMLElement) => [el.querySelector<HTMLElement>(".pixilui-banner-text, .pixilui-notice-text"), ...el.querySelectorAll<HTMLElement>(".pixilui-banner-actions > .pixilui-btn, .pixilui-notice-actions > .pixilui-btn")].filter(can);
const riseIn = (p: HTMLElement, i: number, wait = 0) => p.animate(
  [{ opacity: 0, translate: `0 ${css("--pixilui-notice-in-rise")}`, filter: `blur(${css("--pixilui-notice-in-blur")})` }, { opacity: 1, translate: "0 0", filter: "blur(0)" }],
  { duration: ms("--pixilui-notice-in"), delay: wait + i * ms("--pixilui-notice-in-step"), easing: curve("--pixilui-notice-ease-enter"), fill: "backwards" });
const iconIn = (g: HTMLElement, wait = 0) => g.animate(
  [{ opacity: 0, scale: css(`--pixilui-notice-icon-from`), filter: `blur(${css("--pixilui-notice-icon-blur")})` }, { opacity: 1, scale: 1, filter: "blur(0)" }],
  { duration: ms("--pixilui-notice-icon-in"), delay: wait, easing: curve("--pixilui-notice-ease-swap"), fill: "backwards" });
const leave = (p: HTMLElement) => p.animate(
  [{ opacity: 1, translate: "0 0", filter: "blur(0)" }, { opacity: 0, translate: `0 calc(${css("--pixilui-notice-out-rise")} * -1)`, filter: `blur(${css("--pixilui-notice-in-blur")})` }],
  { duration: ms("--pixilui-notice-out"), easing: curve(EASE_EXIT), fill: "forwards" }).finished.catch(() => {});
const play = (mark: HTMLElement, wait = 0) => { mark.setAttribute("data-pxi-play", ""); setTimeout(() => mark.removeAttribute("data-pxi-play"), wait + (ms("--pixilui-toast-pic-play") || 900)); };

const contentKey = (c: NoticeContent & { iconKey?: string }) =>
  JSON.stringify([c.tone, typeof c.title === "string" ? c.title : "", typeof c.sub === "string" ? c.sub : "", !!c.working, (c.actions ?? []).map((a) => a.label), !!c.closable, c.agent ?? null, c.iconKey ?? (c.agent ? null : c.tone)]);

/** The banner's and the notice's shared frame: the fold, the pieces, the turn and the leave. */
export const NoticeFrame = forwardRef<HTMLDivElement, NoticeFrameProps>(function NoticeFrame(
  { kind, open = true, onClose, onClosed, iconKey, closeLabel = "Dismiss", closeIcon = CLOSE_GLYPH, tone, icon, agent, agentName, title, sub, working, actions, closable, className, ...rest },
  ref,
) {
  const next: NoticeContent & { iconKey?: string } = { tone, icon, agent, agentName, title, sub, working, actions, closable, iconKey };
  const [shown, setShown] = useState(next);
  const [mark, setMark] = useState(next);
  const host = useRef<HTMLDivElement>(null);
  const el = useRef<HTMLDivElement>(null);
  const key = contentKey(next);
  const shownKey = useRef(key);
  const latest = useRef(next);
  useLayoutEffect(() => { latest.current = next; });

  // arrive: the space opens first, then the content in pieces (the icon, the words, then each button)
  useEffect(() => {
    const h = host.current, e = el.current;
    if (!h || !e || !open) return;
    scope = e;
    let a = 0, b = 0;
    a = requestAnimationFrame(() => { b = requestAnimationFrame(() => {
      fold(h, true);
      if (reduce()) return;
      const m = e.querySelector<HTMLElement>(".pixilui-banner-mark, .pixilui-notice-mark"), wait = ms("--pixilui-notice-in-wait");
      if (can(m)) { iconIn(m, wait); play(m, wait); }
      pieces(e).forEach((p, i) => riseIn(p, i + 1, wait));
    }); });
    return () => { cancelAnimationFrame(a); cancelAnimationFrame(b); };
  }, [open]);

  // a turn: what it says changed while it is shown
  useEffect(() => {
    const e = el.current;
    if (!e || !open || key === shownKey.current) return;
    scope = e;
    shownKey.current = key;
    const to = latest.current;
    let live = true;
    (async () => {
      const prev = shown;
      if (!reduce()) await Promise.all(pieces(e).map(leave));
      if (!live) return;
      // a line more or less, on screen: the height glides (the move curve)
      const from = e.getBoundingClientRect().height;
      flushSync(() => setShown(to));
      const h = e.getBoundingClientRect().height;
      if (!reduce() && can(e) && Math.abs(h - from) >= 0.5) {
        e.style.overflow = "clip";
        e.animate([{ height: `${from}px` }, { height: `${h}px` }], { duration: ms("--pixilui-notice-resize"), easing: curve("--pixilui-ease-move") }).finished.then(() => { e.style.overflow = ""; }, () => {});
      }
      const bothAgent = !!to.agent && !!prev.agent;
      const faceChange = !bothAgent && !!(to.agent || prev.agent), iconChange = !to.agent && !prev.agent && (to.iconKey ?? to.tone) !== (prev.iconKey ?? prev.tone);
      const m = e.querySelector<HTMLElement>(".pixilui-banner-mark, .pixilui-notice-mark");
      if (bothAgent) flushSync(() => setMark(to)); // the avatar keeps its place and plays its own state change
      else if (faceChange || iconChange) {
        // the icon swap: the old one shrinks deep into a blur, the new one sharpens out of it
        const swapIn = () => { if (!live) return; flushSync(() => setMark(to)); if (m) { if (!reduce() && can(m)) iconIn(m); play(m); } };
        if (reduce() || !can(m)) swapIn();
        else m.animate([{ opacity: 1, scale: 1, filter: "blur(0)" }, { opacity: 0, scale: css(`--pixilui-notice-icon-from`), filter: `blur(${css("--pixilui-notice-icon-blur")})` }], { duration: ms("--pixilui-notice-out"), easing: curve(EASE_EXIT) }).finished.then(swapIn, swapIn);
      } else flushSync(() => setMark(to));
      if (!reduce()) pieces(e).forEach((p, i) => riseIn(p, i));
    })();
    return () => { live = false; };
    // runs when what it says changes
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [key, open]);

  // leave: the content goes first (faster, quieter, a nudge up), then the space folds shut
  const wasOpen = useRef(open);
  useEffect(() => {
    const h = host.current, e = el.current;
    if (!h || !e || open || !wasOpen.current) { wasOpen.current = open; return; }
    scope = e;
    wasOpen.current = open;
    let live = true;
    (async () => {
      if (!reduce()) await Promise.all([e.querySelector<HTMLElement>(".pixilui-banner-mark, .pixilui-notice-mark"), ...pieces(e)].filter(can).map(leave));
      if (!live) return;
      fold(h, false);
      setTimeout(() => { if (live) onClosed?.(); }, ms("--pixilui-notice-close") + ms("--pixilui-notice-out") + 60);
    })();
    return () => { live = false; };
    // runs when open turns false
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [open]);

  const two = kind === "notice" && !!mark.sub;
  const markNode = mark.agent ? (
    <AgentAvatar family={AGENT.family} color={AGENT.color} name={mark.agentName || "Agent"} size={Math.round((two ? AGENT.mark2 : AGENT.mark) * AGENT.k)} state={mark.agent} />
  ) : (
    mark.icon
  );
  const acts = (
    <>
      {(shown.actions ?? []).map((a, i) => (
        <Button key={i} variant={a.kind === "go" ? "primary" : a.kind === "soft" ? "soft" : "secondary"} size="sm" onClick={() => void a.onClick?.()}>
          {a.label}
        </Button>
      ))}
      {shown.closable ? <Button variant="secondary" size="xs" icon={closeIcon} aria-label={closeLabel} className={PARTS[kind].close} onClick={onClose} /> : null}
    </>
  );
  const titleNode = <b className={shown.working ? "pixilui-text-shimmer" : undefined}>{shown.title}</b>;
  return (
    <div ref={host} className="pixilui-notice-host font-body">
      <div>
        <div
          ref={(n) => { el.current = n; if (typeof ref === "function") ref(n); else if (ref) ref.current = n; }}
          className={cn(kind === "banner" ? "pixilui-banner" : "pixilui-notice", "font-body", className)}
          data-tone={shown.tone ?? "neutral"}
          role={shown.tone === "fail" && kind === "banner" ? "alert" : "status"}
          aria-busy={shown.working ? true : undefined}
          {...rest}
        >
          <span className={PARTS[kind].mark} aria-hidden={mark.agent ? undefined : true}>
            {markNode}
          </span>
          {kind === "banner" ? (
            <p className="pixilui-banner-text">
              {titleNode}
              {shown.sub}
            </p>
          ) : (
            <span className="pixilui-notice-text">
              {titleNode}
              {shown.sub ? <small>{shown.sub}</small> : null}
            </span>
          )}
          <span className={PARTS[kind].actions}>{acts}</span>
        </div>
      </div>
    </div>
  );
});

export type NoticeProps = Omit<NoticeFrameProps, "kind">;

/** A tinted panel in the content about the thing beside it: an icon or the agent, the title and its line, one action, a close when it can go. */
export const Notice = forwardRef<HTMLDivElement, NoticeProps>(function Notice(props, ref) {
  return <NoticeFrame ref={ref} kind="notice" {...props} />;
});
```

## Usage

When to use:

- Something about one setting or one part of the page: an approval rule next to the refund settings, a model that retires, a list that couldn't load.
- The agent as the subject (agent): the locked agent avatar in its state, such as an agent that sends emails on its own.
- A result that turns in place: Retry, then working (a shimmering title, aria-busy), then done, in the same panel.

When not to use:

- Something that affects the whole app or panel: use a banner across its top.
- News that passes (saved, sent): use a toast.
- A choice that blocks the next step: use a dialog.

```tsx
import { useState } from "react";
import { IconDone } from "@/components/pixilui/icons/done";
import { IconFailed } from "@/components/pixilui/icons/failed";
import { IconModel } from "@/components/pixilui/icons/model";
import { IconPermission } from "@/components/pixilui/icons/permission";
import { Notice, type NoticeProps } from "@/components/pixilui/notice";

// The first option of each knob is the demo's default; the docs preview starts there.
export const knobs = {
  notice: ["approval rule", "the agent as the subject", "a model retiring", "couldn't load", "live, closable"],
} as const;

const wait = (ms: number) => new Promise((r) => setTimeout(r, ms));

/** The locked page's notices, each next to the setting it is about; Retry turns the failed one in place. */
export default function NoticeDemo({ notice = "approval rule" }: KnobValues<typeof knobs>) {
  const [loaded, setLoaded] = useState<"failed" | "working" | "done">("failed");
  const [open, setOpen] = useState(true);
  const [key, setKey] = useState(notice);
  if (key !== notice) { setKey(notice); setLoaded("failed"); setOpen(true); }
  const N: Record<(typeof knobs.notice)[number], NoticeProps> = {
    "approval rule": { tone: "warn", icon: <IconPermission />, title: "Refunds over $500 need approval", sub: "Maya Rao approves them; the agent waits until she does." },
    "the agent as the subject": { tone: "neutral", agent: "idle", agentName: "Support agent", title: "This agent sends emails on its own", sub: "It replies to customers without asking you first.", actions: [{ label: "Change", kind: "secondary" }] },
    "a model retiring": { tone: "warn", icon: <IconModel />, title: "This agent's model retires on Jan 15", sub: "Switch now to keep the same answers.", actions: [{ label: "Switch model", kind: "secondary" }] },
    "couldn't load":
      loaded === "failed" ? { tone: "fail", icon: <IconFailed />, title: "Couldn't load today's runs", sub: "The server didn't answer.", actions: [{ label: "Retry", kind: "go", onClick: async () => { setLoaded("working"); await wait(1400); setLoaded("done"); } }] }
      : loaded === "working" ? { tone: "neutral", icon: <IconFailed />, iconKey: "failed", title: "Loading today's runs", sub: "Asking the server again.", working: true }
      : { tone: "done", icon: <IconDone />, title: "47 runs loaded", sub: "2 are waiting on approval.", closable: true },
    "live, closable": { tone: "done", icon: <IconDone />, title: "Instructions are live", sub: "Every agent uses v13 now.", closable: true },
  };
  return (
    <div className="grid w-full max-w-lg gap-4 rounded-panel bg-surface p-6 elevation-raised">
      <div className="grid gap-1">
        <span className="type-label text-foreground">Refund approvals</span>
        <span className="type-caption text-muted">Who approves a refund before the agent sends it.</span>
      </div>
      <Notice key={notice} {...N[notice]} open={open} onClose={() => setOpen(false)} />
    </div>
  );
}
```

## Examples

None.

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `sub` | `ReactNode` |  | A notice: the line under the title. A banner: the rest of its one line, after the lead. |
| `title` (required) | `ReactNode` |  | A notice: the title, 14/20 in ink. A banner: the lead of its line, in ink at medium. |
| `tone` | `"neutral" \| "done" \| "warn" \| "fail" \| "wait" \| "run"` |  | The status color: neutral (default), done, warn, fail, wait or run. The panel takes its fill, the glyph its hue. |
| `icon` | `ReactNode` |  | A bare glyph in the tone's hue. |
| `agent` | `AgentAvatarState` |  | Or the agent as the subject: the locked agent avatar in this state (it plays its own change when the state changes). |
| `agentName` | `string` |  | The agent's name, for screen readers. |
| `working` | `boolean` |  | Working: the title shimmers, aria-busy. |
| `actions` | `NoticeAction[]` |  | At most one action, from the locked buttons. |
| `closable` | `boolean` |  | A close, only when it can go. |
| `open` | `boolean` |  | Shown (default) or not: closing plays the leave, then folds the space shut. |
| `onClose` | `() => void` |  | The close was pressed (set open to false, or remove it). |
| `onClosed` | `() => void` |  | After it has folded shut. |
| `iconKey` | `string` |  | Changes when the icon changes, so a new glyph swaps in (default: the tone). |
| `closeLabel` | `string` |  | The close's accessible name. |
| `closeIcon` | `ReactNode` |  | The close's glyph (the lock's: the static Hugeicons cancel). |

## Keyboard

- `Tab`: Reaches the action and the close.
- `Enter` + `Space`: Runs the focused action or closes it.

## Accessibility

- role status, so a change is announced politely; aria-busy while it works.
- The glyph is decorative (aria-hidden) and the words carry the meaning; the agent's avatar is named (agentName).
- The close only shows when the notice can go, and has an accessible name (closeLabel).

## Motion

- The space folds open first (260ms on Emil's enter curve), then the icon swaps in (300ms from .3 out of a blur) and the words and each button rise 6px out of a 2px blur, 50ms apart.
- A turn: the words and buttons leave (140ms, up 4px), a line more or less glides (240ms), the icon swaps or the agent plays its own change, the tint turns (200ms), and the pieces arrive again.
- Closing, the content leaves quieter and faster, then the space folds shut (200ms). Reduced motion: it appears, turns and goes at once.

## Responsive

- Fills its container; the title and its line wrap, and the action sits on the right.

## Performance

- CSS transitions for the fold and the tint, and a handful of Web Animations for the pieces: nothing runs while it rests.

## Notes for AI

- <Notice tone="warn" icon={<IconPermission />} title="Refunds over $500 need approval" sub="Maya Rao approves them" /> next to the setting it is about.
- Tones: neutral, done, warn, fail, wait, run (the locked status colors). agent="idle" puts the agent avatar in place of the icon.
- Change its props to turn it in place (Retry, then working, then done); pass iconKey when the glyph changes but the tone does not.
- open={false} plays the leave and folds it shut, then onClosed fires; closable shows the close, which calls onClose.
- NoticeFrame (kind banner or notice) is the shared frame; Banner is built on it.

## Related

- [Banner](https://pixilui.com/components/banner/markdown): One line across the top of the app or a panel for something that affects all of it: a runs limit, a paused agent, news. A bare icon or the agent, the lead in ink and the rest in grey, one action, a close only when it can go.
- [Toast](https://pixilui.com/components/toast/markdown): Brief news at the corner on the locked float: a delete that waits while its red rim runs out, the agent asking one question, a run that stopped, money moved, and the everyday note, done, info, warning, error and save, in a stack that fans out.
- [Agent avatar](https://pixilui.com/components/agent-avatar/markdown): The agent's face in four looks, 3D plush, glass orb, flat shape or pixel, in any color, acting out its work: it searches with a magnifier, reads, scribbles, asks and hops when it's done.
