Announcement bar

A top banner that rotates messages, counts down, and collapses smoothly when dismissed.

npx shadcn@latest add @silicon-ui/announcement-bar
feedbacknew
Loading…

Installation

With the shadcn CLI

npx shadcn@latest add @silicon-ui/announcement-bar

Manually

  1. Install the dependencies.

    npm install lucide-react motion
  2. Copy these files into your project. Shared files are skipped if you already have them.

    • components/silicon-ui/announcement-bar/announcement-bar.tsx
    • components/silicon-ui/announcement-bar/announcement-bar.module.css
  3. Install the foundation once per app for the design and motion tokens: npx shadcn@latest add @silicon-ui/silicon-foundation

Usage

Source codetsx
import { AnnouncementBar } from "@/components/silicon-ui/announcement-bar/announcement-bar";

API reference

PropTypeDefault
messages*Announcement[]—
id

Remembers dismissal under this id. Change the id to show a new campaign to everyone again.

string—
open

Whether the bar is shown. Leave it out to let the component manage it.

boolean—
defaultOpenbooleantrue
onOpenChange(open: boolean) => void—
index

Index of the visible message.

number—
defaultIndexnumber0
onIndexChange(index: number) => void—
interval

Milliseconds each message stays before the next one. Defaults to 6000.

number6000
autoPlay

Rotate automatically. Pauses on hover, focus, or a hidden tab, and is turned off when the visitor prefers reduced motion. Defaults to true.

booleantrue
controls

Show previous, next, and pause controls when there are several messages. Defaults to false: only the close button shows.

booleanfalse
dismissiblebooleantrue
tone"neutral" | "inverted""neutral"
onAction(announcement: Announcement) => void—
onCountdownEnd(announcement: Announcement) => void—
label

Accessible name of the region.

string"Announcements"
classNamestring—

Also accepts the props of HTMLAttributes.

Dependencies

npm
lucide-reactmotion
Registry
silicon-motion-tokens