Components

Banner

A strip across the top of a page or a view for one short notice: a release, a beta, a trial ending, an outage.

Usage

import { Banner, BannerClose, BannerLink } from 'nyctoui/banner'

<Banner>
  Workspaces can now share one billing plan.
  <BannerLink href="/changelog">Read the changelog</BannerLink>
  <BannerClose />
</Banner>

Put the banner first in the page, above the header, and let it run the full width. It is at least 40px tall with 14px text, and wraps onto a second line on narrow screens rather than cutting the text off. Keep it to one sentence and one link; a page holds one banner at a time.

It takes the same tone and variant as a Badge, with the same tints and inks, so a Badge inside it, like the New above, matches. For a notice that comes and goes after an action, use a Toast.

Good for

  • An outage or degraded-service notice across the top of a SaaS dashboard.
  • A trial ending soon, with a link to the billing page.
  • A beta notice at the top of a new section of an app.
  • A read-only notice when someone opens a shared document they can’t edit.

Examples

Tones

neutral is for announcements: a release, a beta, a new feature. The hues are for status, as on a badge: blue for information, green for success, yellow and orange for warnings, red for an outage or a failure.

Outline

variant="outline" leaves the page’s own background and draws a hairline underneath, for a banner that should sit back further than a tinted strip.

With an icon

Put a 16px Tabler icon in a BannerIcon before the text. It takes the banner’s color and is hidden from assistive technology; the text carries the meaning.

Above an app

align="start" lines the text up with the view under it, for a notice above an app rather than a landing page.

Dismissing

A BannerClose hides the banner. It sits at the inline end, and the banner keeps the same room on the other side, so centered text stays centered on the page. Pass open and onOpenChange to keep the choice, for example in storage under the announcement’s id, so it stays dismissed on the next visit and the next announcement shows again.

Accessibility

A banner is plain content, not a live region: it is on the page when the page loads, so it is read in order like the rest. For a notice that appears after something happens, use a Toast, which is announced. To make the banner a landmark, pass render={<aside aria-label="Announcement" />}.

BannerClose is labelled “Dismiss”. A status tone is never the only signal: say what happened in the text.

Best practices

Do
  • Pick the tone from the message: blue for news, yellow or orange for a warning, red for a failure, green for a confirmation.
  • Keep it to one short sentence, such as “Payments are delayed”, plus one link to the detail.
  • Let people dismiss a release or beta notice with BannerClose, and keep an outage or a blocked account up until it is fixed.
  • Say the status in the words, not only the color or the icon; the icon is decoration to a screen reader.
Don’t
  • Use a banner for something that just happened, like a saved change. That’s a toast.
  • Stack several banners. Combine related notices into one, or show the most urgent and queue the rest.
  • Use a banner for a note about one part of the page. Put a callout next to that part instead.

API reference

A <div> by default. Other props go to the element.

PropTypeDefault
tone
Color, as on Badge. Use a hue only for status.
'neutral' | 'red' | 'orange' | 'yellow' | 'green' | 'blue''neutral'
variant
A tinted fill, or a hairline under a transparent fill.
'soft' | 'outline''soft'
align
Centered for a page, or lined up with an app view.
'center' | 'start''center'
open
Whether the banner is shown. For controlled use.
boolean—
defaultOpen
Whether it is shown at first. For uncontrolled use.
booleantrue
onOpenChange
Called with false when a BannerClose is pressed.
(open: boolean) => void—
render
Renders another element, such as an <aside>, with the banner’s props.
ReactElement | (props) => ReactElement—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

BannerIcon

A <span> slot for a 16px icon, hidden from assistive technology.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

An underlined <a> in the banner’s color. Other props go to the element.

PropTypeDefault
render
Renders a router link instead, e.g. <Link to="…" />.
ReactElement | (props) => ReactElement—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

BannerClose

A small ghost icon Button that hides the banner. Other props go to the button.

PropTypeDefault
aria-label
The button’s accessible name.
string'Dismiss'
onClick
Runs first; call event.preventDefault() to keep the banner open.
(event) => void—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—