Skip to content

React Announcement Banner

AnnouncementBanner is a React announcement banner: a dismissible top bar on glass with a tone, an optional link and static copy. It stores nothing and reports the dismissal through onDismiss so you can remember it.

npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/announcement-banner.json

Version 2 is out: new blocks and a faster build. Read the notes

Remember the dismissal yourself

Controlled with open and onOpenChange; onDismiss fires once when the visitor presses the button, which is where you save it (a cookie, localStorage or an account setting) and pass defaultOpen={false} next time.

Version 2 is out: new blocks and a faster build. Read the notes

Files to copy

6 folders · 8 files · 3 packages
From theme/src/
  • blocks/announcement-banner.tsx
  • components/status-icons/
  • hooks/{use-controllable.ts, use-media-query.ts, use-preferences.ts}
  • motion/{presets.ts, tokens.ts}
  • lib/{cn.ts, warn-once.ts}
  • styles/
shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/announcement-banner.jsonRegistry item: announcement-banner. The styles need the Tailwind v4 glass UI setup.
Packages
pnpm add clsx motion tailwind-merge

Tones

The words carry the meaning; the tone only lights the edge and picks the icon. Set dismissible={false} for a notice that must stay.

This is a accent announcement.

This is a info announcement.

This is a success announcement.

This is a warning announcement.

This is a danger announcement.

This is a neutral announcement.

Props

PropTypeDefaultDescription
children (required)ReactNodeNoneThe announcement text (ReactNode). Keep it to a sentence; it is static copy, not a live countdown.
toneAnnouncementTone"accent"The semantic colour and icon ("accent" | "info" | "success" | "warning" | "danger" | "neutral"). The words carry the meaning; the colour only lights the edge.
linkAnnouncementLinkNoneA link after the text (AnnouncementLink).
iconReactNodeNoneReplaces the tone's icon (ReactNode); it is aria-hidden. Pass null for none.
dismissiblebooleantrueShow the dismiss button (boolean).
openbooleanNoneControls whether the banner is shown (boolean). Use with onOpenChange; leave it out to let the block keep the state.
defaultOpenbooleantrueWhether the banner is shown at first when uncontrolled (boolean). Pass false when you have already stored that this visitor dismissed it.
onOpenChange((open: boolean) => void)NoneCalled whenever the banner is shown or hidden ((open: boolean) => void).
onDismiss(() => void)NoneCalled once when the visitor presses dismiss (() => void). The block stores nothing: save the choice here (a cookie, localStorage, your account settings) and pass defaultOpen={false} next time.
restoreFocusToRefObject<HTMLElement | null>NoneWhere focus goes when the banner is dismissed (RefObject<HTMLElement | null>). Without it, focus moves to the next focusable element after the banner, or to the <main> landmark when there is none.
labelsPartial<AnnouncementBannerLabels>defaultAnnouncementBannerLabelsEvery other string, for translation: labels={{ region: "…" }}; omitted keys keep the English of defaultAnnouncementBannerLabels. All 3 keys of AnnouncementBannerLabels are listed in the key table under the props table.
classNamestringNoneAdds extra classes to the banner (string).
AnnouncementBannerLabels keys and English defaults (3)
Pass any key in labels; the rest keep the defaults of defaultAnnouncementBannerLabels.
KeyEnglish default
regionAnnouncement
dismissDismiss announcement
dismissedAnnouncement dismissed

Keyboard

KeysAction
TabThe link, then the dismiss button.
Enter/Spaceon dismissDismiss the banner and call onDismiss.

Accessibility

  • A labelled group (labels.region), not a landmark and deliberately not a live region, so it is not read out on every page load. Dismissing moves focus on and announces it politely.
  • Tone is never the only signal: the text says it and the icon is aria-hidden. Keep the copy static; a live countdown would be a moving target for assistive tech.
  • The dismiss button has an accessible name and a 44 px target. The banner stores nothing, so there is no hidden persistence to explain.
  • It slides up by transform and fades on its own surface, faster on the way out. Reduced motion: a short fade.

All exports on this page

  • AnnouncementBanner — A dismissible announcement bar for the top of a page: one sentence, an optional link and a close button.
  • defaultAnnouncementBannerLabels — The English AnnouncementBannerLabels used when labels is omitted; a partial labels prop is merged over it.

When to use the announcement banner

  • Use AnnouncementBanner above the navbar for a release, a maintenance window or a promotion, with one sentence and a link to the details.
  • Use onDismiss to save the choice in your own storage (a cookie, localStorage or an account setting) and pass defaultOpen={false} on the next visit, so the component itself never touches storage.
  • Use tone to pick the icon and light the edge: accent, info, success, warning, danger or neutral; the wording always says what it means, so colour is never the only signal.
  • Skip live countdowns and rotating text inside it; a moving banner is hard to read with assistive technology, and the component is designed for static copy.
  • Pair it with HeroSection and Navbar below it, and use dismissible={false} for a notice that must stay visible, such as a legal change.

Frequently asked questions

20 blocks pages in all: browse them on All blocks.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .