# Notice

What a person must read to act safely: a framed sentence with its glyph and one action, or a bar naming the scope a view stands in.

Live variants: https://design.arcadia.is/components/notice

```tsx
import { Notice } from "@arcadia/ui";
```

```tsx
import { useState } from "react";
import {
  Button, IconButton, Notice, Chip, ListRow, PineSweep, StatusDot, ProgressRing,
  Shimmer, Skeleton, Spinner, ListRows, TextRoll,
} from "@arcadia/ui";

function Tones() {
  return (
    <div {...stylex.props(NoticePage.stack)}>
      <Notice id="docs.paste-secrets">Paste a key here only on a machine you trust. Anyone with this Mac can read it.</Notice>
      <Notice id="docs.recovery-unsaved" tone="warning" action={<Button size="sm" variant="secondary">Save it</Button>}>
        This is your only device and your Recovery Key is not saved. Lose it and the saved sign-ins are gone.
      </Notice>
      <Notice id="docs.payment-failed" tone="danger" action={<Button size="sm" variant="primary">Update payment method</Button>}>
        The last payment failed. Update the card before Dec 4 to keep the team's plan.
      </Notice>
    </div>
  );
}

function Bar() {
  const { held, set, bar, pickUp } = useHeld();
  const [opened, setOpened] = useState(false);
  if (!held) return <Button ref={pickUp} variant="secondary" size="sm" onClick={() => set(true)}>Pick up case again</Button>;
  return (
    <div ref={bar} {...stylex.props(NoticePage.stack)}>
      <Notice layout="bar" aria-label="Active case" tag={<Chip variant="outline" size="md">Case in hand</Chip>} title="Billing dispute for Harbour Lab"
        action={<Button variant="secondary" size="sm" onClick={() => setOpened(true)}>Open case</Button>}
        onLeave={() => set(false)} leaveLabel="Leave case">
        {opened ? "Maya Lin, opened" : "Maya Lin"}
      </Notice>
    </div>
  );
}

const NoticeNotes = <>
  <P>
    A `danger` notice is an `alert`, and a `warning` one is a `status`, so a reader hears it when it
    appears. A neutral notice is plain text. A bar is a
    landmark `region` named by `aria-label`, so a reader can jump to the active scope from anywhere in the panel; its
    words keep their reading order and tab order at every width, and under forced colours its hairline turns
    `CanvasText`. When Leave removes its own control, the product moves focus to what replaces it, as the examples do.
  </P>
  <Keys rows={[
    ["Tab", "Move to the notice's action, then to Leave"],
    ["Enter", "Activate the focused action"],
  ]} />
</>;

function Running() {
  return (
    <div {...sx("cmp-rows", cmp.rows)}>
      <ListRow leading={<PineSweep size="md" />} label="acme-web" meta="2m" />
      <ListRow
        leading={<StatusDot status="running" />}
        label="Preferences dialog"
        meta="now"
        active
      />
      <ListRow
        leading={<StatusDot status="running" />}
        label="Fix the flaky upload test"
        meta="1m"
      />
      <ListRow leading={<StatusDot />} label="Colour tokens" meta="2d" />
    </div>
  );
}

const PineSweepNotes = <>
  <P>
    Decorative unless given a `label`, which makes it an `img` named "Running". Omit the label when the row already says
    so. It never flashes: one stroke brightens at a time, slowly. With reduced motion the whole mark holds still at full
    strength.
  </P>
</>;

function ContextProgress() {
  const [used, setUsed] = useState(0.42);
  return (
    <>
      <Button
        size="sm"
        onClick={() => setUsed((u) => (u >= 0.9 ? 0.18 : Math.min(0.96, u + 0.22)))}
      >
        Use more
      </Button>
      <span {...stylex.props(page.context)}>
        <span aria-hidden="true" {...stylex.props(page.contextValue)}>{Math.round(used * 100)}%</span>
        <ProgressRing
          value={used}
          label="Context used"
          valueText={`${Math.round(used * 200)}k of 200k tokens`}
        />
      </span>
    </>
  );
}

const ProgressRingNotes = <>
  <P>
    With a `label` the ring is a `meter` with its value, range and `valueText` (default: the rounded percentage), so
    "Context used, 122k of 200k tokens" is read instead of a bare number. Without a label it is decorative, for use
    inside a labelled button. The levels are colour only, so say "almost full" in the `valueText` or a tooltip when it
    matters.
  </P>
  <P>
    Forced colours leave a stroke in the page&apos;s own ink, so under them the arc takes the system&apos;s highlight
    and the track its grey text: how far the ring is still shows, in every palette, though its levels do not.
  </P>
</>;

function ProgressRingDemo() { return <ComposerFrame footer={<ComposerControls ring={<ContextProgress />} />} />; }

function Stream() {
  return (
    <div {...sx("cmp-stream", cmp.stream)}>
      <span {...sx("cmp-status", cmp.status)}>
        <PineSweep size="md" /> <Shimmer>Working</Shimmer>
      </span>
      <span {...sx("cmp-status", cmp.status)}>
        <Shimmer>Reading</Shimmer> <span {...sx("cmp-detail", cmp.detail)}>src/settings/dialog.tsx</span>
      </span>
      <span {...sx("cmp-status", cmp.status)}>
        <Shimmer tone="tertiary">Summarizing context</Shimmer>
      </span>
    </div>
  );
}

const ShimmerNotes = <>
  <P>
    The sweep is visual only; the words are plain text and read normally. Put the live-region role on the status
    container, not on the shimmer, and announce a change of step ("Reading", then "Editing") rather than every update.
    With reduced motion the sweep stops and the text holds its tone colour.
  </P>
</>;

function Loading() {
  return (
    <div {...sx("cmp-stream", cmp.stream)} aria-busy="true">
      <div {...sx("cmp-prose", cmp.prose)}>
        <Skeleton lines={["64%", "88%", "40%"]} />
      </div>
      <div {...sx("cmp-rows", cmp.rows)}>
        <ListRow
          interactive={false}
          leading={<Skeleton shape="circle" width="var(--space-4)" />}
          label={<Skeleton width="48%" />}
        />
        <ListRow
          interactive={false}
          leading={<Skeleton shape="circle" width="var(--space-4)" />}
          label={<Skeleton width="62%" />}
        />
      </div>
    </div>
  );
}

const SkeletonNotes = <>
  <P>
    Always decorative (`aria-hidden`): announce loading on the container with `aria-busy`, as above, or with text. With
    reduced motion it holds still at its resting tint.
  </P>
</>;

function Busy() {
  return (
    <>
      <Button variant="secondary" icon="upload" loading>Uploading</Button>
      <div {...sx("cmp-rows", cmp.rows, cmp.rowsNarrow)} data-width="narrow">
        <ListRow
          leading={<Spinner size="sm" />}
          label="Indexing files"
          meta="12%"
          interactive={false}
        />
      </div>
    </>
  );
}

const SpinnerNotes = <>
  <P>
    Decorative unless given a `label`, which makes it an `img` with that name; omit it when nearby text already says what
    is happening. A loading Button or IconButton sets `aria-busy` itself. With reduced motion the arc holds still.
  </P>
</>;

const StatusDotPage = stylex.create({
  pane: {
    display: "flex", flexDirection: "column", width: "100%", minWidth: 0, paddingBlock: space["--space-2"], paddingInline: space["--space-1"],
    backgroundColor: palette["--bg-app"], color: palette["--text-1"],
  },
});

function Rows() {
  return (
    <div {...sx("cmp-rows", cmp.rows)}>
      <ListRow
        leading={<StatusDot status="running" />}
        label="Preferences dialog"
        meta="now"
      />
      <ListRow
        leading={<StatusDot status="attention" />}
        label="Plan the onboarding flow"
        meta="4m"
      />
      <ListRow
        leading={<StatusDot status="unread" />}
        label="Quarterly report"
        meta="13h"
      />
      <ListRow
        leading={<StatusDot status="error" />}
        label="Fix the flaky upload test"
        meta="16h"
      />
      <ListRow
        leading={<StatusDot status="idle" />}
        label="Colour tokens"
        meta="2d"
      />
      <ListRow leading={<StatusDot status="draft" />} label="New chat" meta="3d" />
    </div>
  );
}

function Lights({ theme }: { theme: "dark" | "light" }) {
  return (
    <div {...sx("status-lights", StatusDotPage.pane)} data-theme={theme}>
      <ListRows>
        <ListRow label="Migrate now, or after the backup?" leading="file-text" light={<StatusDot status="attention" />} interactive={false} />
        <ListRow label="Launch week" leading="file-text" light={<StatusDot status="unread" label="Unread" />} interactive={false} />
        <ListRow label="Retry uploads that time out" leading="file-text" light={<StatusDot />} interactive={false} />
      </ListRows>
    </div>
  );
}

function TwoLights() {
  return (
    <>
      <Cell caption="At night"><Lights theme="dark" /></Cell>
      <Cell caption="By day"><Lights theme="light" /></Cell>
    </>
  );
}

const StatusDotNotes = <>
  <P>
    A dot is decorative unless given a `label`, which makes it an `img` with that name. Colour alone never carries the
    status: say it in the row&apos;s text, its `aria-label`, or the dot&apos;s `label` (&quot;Unread&quot;).
  </P>
  <P>
    `status=&quot;attention&quot;` is an `img` named &quot;Waits for your answer&quot; wherever it stands without `children`,
    read as part of a row&apos;s name in its `light`; give it `label=&#123;null&#125;` where the words beside it say so
    already, and it is hidden from readers. It is the plain dot in the attention amber, never a glyph, so its name
    and tooltip tell it from the unread dot. Under forced colours both are drawn in the system&apos;s ink.
  </P>
  <P>
    Without `children`, the mark inherits the surrounding text role&apos;s line height (Body 20px on rows, Caption 16px
    beside Caption text). A `StatusDot` with `children` sets Caption and reads as its word. With `why` it is a stop
    of its own, so the keyboard shows the tooltip a pointer does, and the why is its description; `role` announces a
    change of state.
  </P>
</>;

const LINES = ["Reading the plan", "Searching the web", "Running the tests", "Writing the summary"];

function Rolling() {
  const [i, setI] = useState(0);
  return (
    <div {...sx("cmp-bar", cmp.bar)}>
      <span {...sx("cmp-status", cmp.status, cmp.statusUi)} role="status"><TextRoll text={LINES[i]!} /></span>
      <Button variant="secondary" size="sm" onClick={() => setI((i + 1) % LINES.length)}>Next</Button>
    </div>
  );
}

const TextRollNotes = <>
  <P>
    The current text is in the page once, for a screen reader; the copies the motion draws are hidden from it. Put the
    live-region role on the container, as the examples do with `role=&quot;status&quot;`, so each change is read once.
    Reduced motion swaps the text in place with no motion and no mask, whichever arrival the product set.
  </P>
</>;

export const FIXTURES: Record<string, CatalogSpec> = {
  "empty-state": { examples: [{ Preview: Pane, code: SOURCES.Pane, surface: "pane", layout: "stretch", size: "tall" }], accessibility: Notes },
  "limit-notice": { examples: [{ Preview: InviteInline, code: SOURCES.InviteInline, surface: "pane", layout: "start", size: "compact", caption: "Calm day: inviting people reaches the cap, and the notice stands right under the invite control." }], accessibility: LimitNoticeNotes },
  "live-line": { examples: [{ Preview: Trail, code: SOURCES.Trail, surface: "pane", layout: "start" }], accessibility: LiveLineNotes },
  "loading-line": { examples: [{ Preview: AddressBar, code: SOURCES.AddressBar, size: "compact", layout: "stretch" }], accessibility: LoadingLineNotes },
  "meter": { examples: [{ Preview: MeterDemo, cols: 3, size: "compact" }, { Preview: MeterMeterDemo, cols: 3, size: "compact" }, { Preview: Accounts, code: SOURCES.Accounts, layout: "stretch", size: "compact", caption: "Point at a segment to read what remains in that account.", section: "in-parts" }, { Preview: Plans, code: SOURCES.Plans, layout: "stretch", caption: "Plan windows as limit rows: what is left, low from 15%, spent as Limit reached.", section: "as-a-row" }, { Preview: Owner, code: SOURCES.PoolGrid, caption: "Four accounts at 15:25: one open and lit, two closed by their 5-hour though their weeks remain, and one closed by its week.", section: "a-grid" }, { Preview: MeterMeterDemo_, code: SOURCES.Storage, surface: "pane", caption: "A team's storage: what it holds by kind, against its limit, and what is free.", section: "a-capacity" }], accessibility: MeterNotes },
  "not-found-page": { examples: [{ Preview: Default, code: SOURCES.Default, surface: "pane", layout: "fill" }], accessibility: NotFoundPageNotes },
  "notice": { examples: [{ Preview: Tones, code: SOURCES.Tones, surface: "pane", layout: "fill" }, { Preview: Bar, code: SOURCES.Bar, layout: "fill", section: "bar" }], accessibility: NoticeNotes },
  "pine-sweep": { examples: [{ Preview: Running, code: SOURCES.Running, surface: "sidebar" }], accessibility: PineSweepNotes },
  "progress-ring": { examples: [{ Preview: ProgressRingDemo, code: SOURCES.ContextProgress, surface: "pane", layout: "stretch", caption: "The context meter in a composer's footer. Use more steps it through its levels: yellow from 60%, red from 85%." }], accessibility: ProgressRingNotes },
  "shimmer": { examples: [{ Preview: Stream, code: SOURCES.Stream, surface: "pane", layout: "start" }], accessibility: ShimmerNotes },
  "skeleton": { examples: [{ Preview: Loading, code: SOURCES.Loading, surface: "pane", layout: "stretch" }], accessibility: SkeletonNotes },
  "spinner": { examples: [{ Preview: Busy, code: SOURCES.Busy, size: "compact" }], accessibility: SpinnerNotes },
  "status-dot": { examples: [{ Preview: Rows, code: SOURCES.Rows, surface: "sidebar" }, { Preview: TwoLights, code: SOURCES.TwoLights, cols: 2, caption: "The attention dot, the unread dot and a read line with no light, in a list's margin in each theme." }], accessibility: StatusDotNotes },
  "text-roll": { examples: [{ Preview: Rolling, code: SOURCES.Rolling, size: "compact" }], accessibility: TextRollNotes },
};
```

## Bar

```tsx
import { useState } from "react";
import { Button, Notice, Chip } from "@arcadia/ui";

function Bar() {
  const { held, set, bar, pickUp } = useHeld();
  const [opened, setOpened] = useState(false);
  if (!held) return <Button ref={pickUp} variant="secondary" size="sm" onClick={() => set(true)}>Pick up case again</Button>;
  return (
    <div ref={bar} {...stylex.props(NoticePage.stack)}>
      <Notice layout="bar" aria-label="Active case" tag={<Chip variant="outline" size="md">Case in hand</Chip>} title="Billing dispute for Harbour Lab"
        action={<Button variant="secondary" size="sm" onClick={() => setOpened(true)}>Open case</Button>}
        onLeave={() => set(false)} leaveLabel="Leave case">
        {opened ? "Maya Lin, opened" : "Maya Lin"}
      </Notice>
    </div>
  );
}
```

## Accessibility

A `danger` notice is an `alert`, and a `warning` one is a `status`, so a reader hears it when it appears. A neutral notice is plain text. A bar is a landmark `region` named by `aria-label`, so a reader can jump to the active scope from anywhere in the panel; its words keep their reading order and tab order at every width, and under forced colours its hairline turns `CanvasText`. When Leave removes its own control, the product moves focus to what replaces it, as the examples do.

- Tab: Move to the notice's action, then to Leave
- Enter: Activate the focused action

## API reference

### Notice

- `layout` (`"block"`)
- `id` (`string`, required)
- `tone` (`"neutral" | "warning" | "danger"`)
- `action` (`ReactNode`)
- `nesting` (`"contained-object"`): A separately framed object that belongs inside another one, not a layout wrapper.

### Notice layout="bar"

- `layout` (`"bar"`, required)
- `aria-label` (`string`, required)
- `tag` (`ReactNode`)
- `title` (`ReactNode`, required)
- `action` (`ReactNode`)
- `onLeave` (`() => void`)
- `leaveLabel` (`string`)
- `rootStyle` (`RootStyle`): A component's typed override prop: `Layout` and its documented knobs, each the references it takes or another kit knob of its kind; anything else is a type error at the call site (STYLEX.md).
