One line above the header for a launch, a sale or a notice: a link or CTA, an optional countdown, tones, and a dismissal remembered per id.
- Launch notice
- Model release banner
- Event countdown
- Maintenance warning
Examples
Installation
npx knowns-ui@latest add announcement-barPaste this into your coding agent (Claude Code, Cursor, Codex). It checks your project, sets up the registry, runs the install and verifies it.
Install Announcement bar from Knowns UI into this project. Work step by step, show me each change, and ask before you edit files outside this project.
Context: Knowns UI (https://ui.knowns.dev) is a shadcn registry. Items land in the project as source files. Docs: https://ui.knowns.dev/docs/announcement-bar
1. Check the project first. Stop and tell me if any of these is missing:
- React 19 and Tailwind CSS v4.
- A components.json at the project root. If there is none, ask me before running `npx knowns-ui@latest init --no-key` (it runs shadcn init when needed, then adds the registries).
2. Run:
```bash
npx knowns-ui@latest add announcement-bar
```
It writes these files:
- lib/knowns/run.ts
- lib/knowns/json.tsx
- lib/knowns/status.ts
- lib/knowns/tone.ts
- lib/knowns/types.ts
- lib/knowns/use-abortable.ts
- lib/knowns/utils.ts
- components/ui/knowns/blocks/site/announcement-bar.tsx
- components/ui/knowns/blocks/site/site-utils.ts
and installs these npm packages: clsx@^2.1.1, tailwind-merge@^3.7.0.
3. While it runs:
- It also adds a few @keyframes (all named kn-*) to the global CSS file (globals.css or the file components.json points at). Let it: they only add animations.
- If it asks to overwrite files under lib/knowns/: these are shared by every Knowns UI item. List them, say whether I changed them (check git), and ask me before you answer.
- If it asks to overwrite any other file, show me the diff and ask me.
4. Verify:
- Every file in the list above exists.
- The project type-checks (for example `npx tsc --noEmit`) and the dev build has no new errors.
5. Use it: follow the examples and props on https://ui.knowns.dev/docs/announcement-bar, and ask me if anything about my data is unclear.
If the Knowns UI MCP server is connected (https://ui.knowns.dev/docs/ai-and-mcp), use get_component({ name: "announcement-bar" }) or search_docs for details.
Finish with a short summary: the files you added or changed, the packages you installed, and anything I still need to do.Props
- id
string- The dismissal is stored as kn-announcement:<id>. Use a new id for a new announcement.
- action
{ label, href?, onClick? }- A link (with an arrow) or a button after the message.
- countdown
{ end, label?, onEnd?, hideWhenDone? }- Ticks every second; screen readers get the time left in minutes. hideWhenDone collapses the bar at zero.
- tone
"inverted"|"neutral"|"accent"|"warning"|"success"- Default
"inverted" - Colours; text keeps 4.5:1 contrast in both themes.
- dismissible / persist / onDismiss
boolean / boolean / () => void- Default
true / true - The close button, and whether the dismissal is remembered in localStorage.
- icon
ReactNode- A 16px mark before the message.
| Prop | Type | Default | Description |
|---|---|---|---|
| id | string | - | The dismissal is stored as kn-announcement:<id>. Use a new id for a new announcement. |
| action | { label, href?, onClick? } | - | A link (with an arrow) or a button after the message. |
| countdown | { end, label?, onEnd?, hideWhenDone? } | - | Ticks every second; screen readers get the time left in minutes. hideWhenDone collapses the bar at zero. |
| tone | "inverted" | "neutral" | "accent" | "warning" | "success" | "inverted" | Colours; text keeps 4.5:1 contrast in both themes. |
| dismissible / persist / onDismiss | boolean / boolean / () => void | true / true | The close button, and whether the dismissal is remembered in localStorage. |
| icon | ReactNode | - | A 16px mark before the message. |
No layout jump: the bar renders open, and a bar dismissed earlier is hidden before the first paint. Dismissing collapses its height smoothly, so the header below slides up rather than snapping (instant with reduced motion). If storage is blocked the bar simply shows again next visit.
What it handles
- 01Sits above the header as one line with a message, an optional icon and an action that is a link with an arrow or a button.
- 02Counts down to an end date: the digits tick from a 1-second timer, while screen readers get a minute-level sentence instead of the seconds.
- 03Calls countdown.onEnd when the time runs out and closes the bar when hideWhenDone is set.
- 04Remembers a dismissal in localStorage under kn-announcement:<id>, and never throws when storage is blocked.
- 05Hides itself before paint when it was dismissed earlier, so a returning visitor sees no flash and no layout jump.
- 06Offers five tones (neutral, inverted, accent, warning, success), a dismiss button that can be turned off, and persist={false} to skip storage.
States
- First render
- Nothing. The bar paints open, or hidden at once if it was dismissed before
- none
- Dismissed now
- The height collapses so a sticky header below slides up
- 280ms, ease out
- Dismissed on an earlier visit
- The bar is closed before the first paint
- none
- Countdown
- The digits change each second
- every 1s, no animation
- Dismiss button hover
- The button background and opacity change
- 120ms, ease out
- Reduced motion
- The bar closes at once
- 0ms
| State | What moves | Timing |
|---|---|---|
| First render | Nothing. The bar paints open, or hidden at once if it was dismissed before | none |
| Dismissed now | The height collapses so a sticky header below slides up | 280ms, ease out |
| Dismissed on an earlier visit | The bar is closed before the first paint | none |
| Countdown | The digits change each second | every 1s, no animation |
| Dismiss button hover | The button background and opacity change | 120ms, ease out |
| Reduced motion | The bar closes at once | 0ms |
Works with
When to use
Using with AI
Use Copy page for AI above to give your assistant this page, Copy prompt under the install command to have it installed and wired to your data, or connect the Knowns UI MCP server and just ask:
- Add the Knowns UI Announcement Bar to my app and wire it to my own data.
- I need a launch, a sale with a deadline or a maintenance notice above the header, dismissed once per visitor. Set that up with the Knowns UI Announcement Bar.
- Which Announcement Bar props do I need for a minimal setup? Show me a short example.
With the server connected, your assistant calls get_component({ name: "announcement-bar" }) and search_docs({ query: "announcement bar" }).