<!-- Generated by scripts/gen-docs.mts from the JSDoc in registry/. Do not edit; run `pnpm run docs`. -->

# PreviewBar

A bar for trying a change before keeping it: the app shows a proposal live (a theme, a layout, an edit), and the bar says what it is and offers Keep, Throw away and Compare with the original. Compare is a toggle button (`aria-pressed`): a tap switches it on or off, and holding the button, or the Compare key (`c`), shows the original only while it is held. Screen readers use the toggle. A new proposal, a new `label`, is announced politely once and not again on later updates. An optional countdown (`seconds`) is drawn in view, hidden from screen readers, and throws the change away when it ends; it waits while the person compares. Escape in the bar throws the change away. When Keep or Throw away removes the bar while it has focus, focus moves on to the next control.

## Install

Once per app, with Tailwind CSS v4 and an `@/*` path alias (skip `init` in an existing shadcn app), then the component:

```sh
npx shadcn@latest init --base base --preset nova --yes --no-monorepo
npx shadcn@latest add ourostack/ouro-ui/ouro-base#v1.3.823
npx shadcn@latest add ourostack/ouro-ui/preview-bar#v1.3.823
```

More: [Installing](https://ui.ouroboros.bot/docs/installing.md).

```tsx
import { PreviewBar } from "@/components/ouro/preview-bar/preview-bar";
```

## Example

```tsx
<PreviewBar label="Trying the Ocean theme" seconds={30} onKeep={keep} onDiscard={revert} onCompareChange={showOriginal} />
```

## Usage

The app owns the proposal: it renders the change, the original while `onCompareChange` says so, and removes the bar.

## Use instead when

- Use `Alert` instead for a notice with no choice to make, and `Toast` for a message about something already done.

## Props

Type: `PreviewBarProps`.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `announcement` | `string` | the label, then "Reverts in N seconds unless you keep it" when there is a countdown | What a screen reader hears for each new proposal. |
| `className` | `string` |  | Layout only: margins, width (`mt-6`, `max-w-md`). Appearance classes warn in development. |
| `compareKey` | `string \| false` | `"c"` | The key that shows the original while it is held, from anywhere on the page except a text field. `false` turns the shortcut off. |
| `compareLabel` | `string` | `"Compare"` | The label of the Compare button, a toggle. |
| `discardLabel` | `string` | `"Throw away"` | The label of the button that throws the change away. |
| `keepLabel` | `string` | `"Keep"` | The label of the button that keeps the change. |
| `label` (required) | `string` |  | What the app is showing, in words: "Trying the Ocean theme". It is the bar's name, and what a screen reader hears when a new proposal arrives. A new label is a new proposal. |
| `onCompareChange` (required) | `(comparing: boolean) => void` |  | Called with `true` while the person is comparing, and `false` when they stop: show the original while it is `true`, and the proposal again when it is `false`. |
| `onDiscard` (required) | `() => void` |  | Called when the person throws the change away, presses Escape in the bar, or the countdown ends. The app puts the original back and removes the bar. |
| `onKeep` (required) | `() => void` |  | Called when the person keeps the change. The app makes it permanent and removes the bar. |
| `seconds` | `number` |  | Seconds before the change is thrown away, counted down in view and never read aloud. Counting stops while the person compares. Leave it out for a proposal that waits. |

## Don't use

These are not props. Passing one fails the type check with the fix in the error, and in development a console message names the fix.

- `onAccept`: Not a prop. Ouro UI says `onKeep`: `<PreviewBar onKeep={() => …} />`.
- `timeout`: Not a prop. The countdown is `seconds`: `<PreviewBar seconds={30} />`.

## `className` is for layout only

Pass margins, width and grid placement (`mt-4`, `w-full`, `col-span-2`).

Appearance comes from props, not classes. In development, a class that sets appearance logs one warning per component instance, naming the prop to use instead. A class sets appearance when, after its variants (`hover:`, `sm:`) and any `!` are removed, it starts with `bg-`, `text-`, `border-`, `rounded-`, `shadow-`, `font-`, `ring-`, `from-`, `via-`, `to-`, `fill-` or `stroke-`, or is `border`, `rounded`, `shadow` or `ring`, or has a `dark:` variant. Text wrapping, overflow and table layout classes (`text-wrap`, `text-ellipsis`, `border-collapse`) are layout and do not warn.

Alignment classes (`text-center`) warn too: set alignment on a parent element.
