Skip to content

Announcement Bar

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.

On this page
Used for
  • Launch notice
  • Model release banner
  • Event countdown
  • Maintenance warning

Examples

Installation

npx knowns-ui@latest add announcement-bar
For Claude Code, Cursor or Codex: installs it and wires the props to your own data.

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
Defaulttrue / 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

  1. 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.
  2. 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.
  3. 03Calls countdown.onEnd when the time runs out and closes the bar when hideWhenDone is set.
  4. 04Remembers a dismissal in localStorage under kn-announcement:<id>, and never throws when storage is blocked.
  5. 05Hides itself before paint when it was dismissed earlier, so a returning visitor sees no flash and no layout jump.
  6. 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

Works with

When to use

When to use

  • A launch, a sale with a deadline or a maintenance notice above the header, dismissed once per visitor.

When not to use

  • Messages about a single action, like Saved: use Toast.
  • Anything the user must act on before going on: use Dialog.

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" }).

Need help?

Stuck on Announcement Bar, or found something off? We read every message.