A site-wide announcement bar with an optional close button and session-based dismissal. Use it for launch notices, promos, or maintenance messages at the top of a layout.
Install
pnpm dlx shadcn@latest add https://sitex.full.dev/r/banner.jsonUsage
import { Banner, BannerContainer } from "@/components/ui/banner"
export function SiteBanner() {
return (
<Banner variant="floating" storageKey="v0-3-release">
<BannerContainer>
<p>SiteX 0.3 is out — read the release notes.</p>
</BannerContainer>
</Banner>
)
}Key parts:
Bannerrenders anasidewith two variants:default(full-width, inverted colors) andfloating(rounded, bordered, centered).storageKeymakes dismissal persist for the session: closing stores a flag insessionStorageand the banner stays hidden on later renders.BannerContainercenters the content and renders the close button; passshowClose={false}to hide it, oronCloseto intercept the click (callevent.preventDefault()to keep the banner open).bannerVariantsis exported for reusing the variant classes elsewhere.
The dismiss behavior and sessionStorage check are client-side, so hydrate the banner as an island with a Sitex client directive where you use it in a layout or block, e.g. <Banner client:load>.