# Banner (/components/banner)

<ReferenceLinks
  links={[
    { label: "Source", href: meta.links.source, iconName: "code" },
    { label: "Stories", href: meta.links.stories },
  ]}
/>

<Stage code={"<Banner tone=\"brand\" dismissible={{ onDismiss: () => {} }}>\n  <Banner.Title>A new entity editor is available</Banner.Title>\n  <Banner.Description>\n    {\"Turn it on for this workspace from Settings → Labs.\"}\n  </Banner.Description>\n</Banner>\n<Banner tone=\"warning\">\n  <Banner.Title>Workspace permissions are changing</Banner.Title>\n  <Banner.Description>\n    {\"Members inherited from parent teams must be re-added by 1 November.\"}\n  </Banner.Description>\n  <Banner.Actions>\n    <Banner.ActionButton>Review changes</Banner.ActionButton>\n  </Banner.Actions>\n</Banner>\n<Banner tone=\"error\" variant=\"solid\">\n  <Banner.Description>\n    {\"Sync with the graph failed — recent edits aren't saved.\"}\n  </Banner.Description>\n  <Banner.Actions>\n    <Banner.ActionButton>Retry</Banner.ActionButton>\n  </Banner.Actions>\n</Banner>"}>
  <Column>
    <Banner tone="brand" dismissible={{ onDismiss: noop }}>
      <BannerTitle>A new entity editor is available</BannerTitle>
      <BannerDescription>
        {"Turn it on for this workspace from Settings → Labs."}
      </BannerDescription>
    </Banner>
    <Banner tone="warning">
      <BannerTitle>Workspace permissions are changing</BannerTitle>
      <BannerDescription>
        {"Members inherited from parent teams must be re-added by 1 November."}
      </BannerDescription>
      <BannerActions>
        <BannerActionButton>Review changes</BannerActionButton>
      </BannerActions>
    </Banner>
    <Banner tone="error" variant="solid">
      <BannerDescription>
        {"Sync with the graph failed — recent edits aren't saved."}
      </BannerDescription>
      <BannerActions>
        <BannerActionButton>Retry</BannerActionButton>
      </BannerActions>
    </Banner>
  </Column>
</Stage>

## Installation [#installation]

1. Install the package.

```sh
npm install @hashintel/ds-components
```

2. Import the component.

```tsx
import { Banner } from "@hashintel/ds-components";

export const PermissionsChangeBanner = () => (
  <Banner tone="warning">
    <Banner.Title>Workspace permissions are changing</Banner.Title>
    <Banner.Description>
      Members inherited from parent teams must be re-added by 1 November.
    </Banner.Description>
  </Banner>
);
```

### When to use [#when-to-use]

<DoList
  items={[
    "Use Banner for a page or section-level condition the user didn't just cause — a permissions change, a failed sync, an expiring trial.",
    "Place the banner at the top of the page or section it describes, so the status reads before the content it affects.",
    <Fragment key="0">
      Use <code>Banner.Actions</code> when the user can resolve the condition in
      place — review, retry, approve.
    </Fragment>,
    "Show one banner per view — when several conditions apply, keep the most severe and fold the rest into its description.",
  ]}
/>

### When not to use [#when-not-to-use]

<DontList
  items={[
    "Don't confirm an action the user just took — show the result inline, next to the control that triggered it.",
    "Don't use banners for field-level validation — use Form's field errors under the input.",
    "Don't use a banner for a decision that must block the flow — use Dialog.",
  ]}
/>

## Anatomy [#anatomy]

```tsx
<Banner tone="neutral">
  <Banner.Title>Title</Banner.Title>
  <Banner.Description>Description</Banner.Description>
  <Banner.Actions>
    <Banner.ActionButton>Action</Banner.ActionButton>
  </Banner.Actions>
</Banner>
```

## Examples [#examples]

### Basic [#basic]

<Stage code={"<Banner tone=\"neutral\" variant=\"soft\">\n  <Banner.Title>Scheduled maintenance on Saturday</Banner.Title>\n  <Banner.Description>\n    {\n      \"HASH will be read-only from 02:00 to 04:00 UTC while the graph is upgraded.\"\n    }\n  </Banner.Description>\n</Banner>"}>
  <Column>
    <Banner tone="neutral" variant="soft">
      <BannerTitle>Scheduled maintenance on Saturday</BannerTitle>
      <BannerDescription>
        {
          "HASH will be read-only from 02:00 to 04:00 UTC while the graph is upgraded."
        }
      </BannerDescription>
    </Banner>
  </Column>
</Stage>

### Description only [#description-only]

Most banners don't need a title — a lone `Banner.Description` keeps a short
status to a single line.

<Stage code={"<Banner tone=\"brand\">\n  <Banner.Description>\n    {\"This flow is shared with everyone in the workspace.\"}\n  </Banner.Description>\n</Banner>"}>
  <Column>
    <Banner tone="brand">
      <BannerDescription>
        {"This flow is shared with everyone in the workspace."}
      </BannerDescription>
    </Banner>
  </Column>
</Stage>

### Tones [#tones]

`tone` sets the palette and the default icon: `neutral` for routine context,
`brand` for product messages, `success` to confirm, `warning` to forewarn, and
`error` for failures that need attention now.

<Stage code={"<Banner tone=\"neutral\">\n  <Banner.Description>\n    {\"Neutral — routine context that needs no action.\"}\n  </Banner.Description>\n</Banner>\n<Banner tone=\"brand\">\n  <Banner.Description>\n    {\"Brand — product announcements and feature promotion.\"}\n  </Banner.Description>\n</Banner>\n<Banner tone=\"success\">\n  <Banner.Description>\n    {\"Success — a background task completed as expected.\"}\n  </Banner.Description>\n</Banner>\n<Banner tone=\"warning\">\n  <Banner.Description>\n    {\"Warning — something needs attention before it becomes a problem.\"}\n  </Banner.Description>\n</Banner>\n<Banner tone=\"error\">\n  <Banner.Description>\n    {\"Error — something failed and needs fixing now.\"}\n  </Banner.Description>\n</Banner>"}>
  <Column>
    <Banner tone="neutral">
      <BannerDescription>
        {"Neutral — routine context that needs no action."}
      </BannerDescription>
    </Banner>
    <Banner tone="brand">
      <BannerDescription>
        {"Brand — product announcements and feature promotion."}
      </BannerDescription>
    </Banner>
    <Banner tone="success">
      <BannerDescription>
        {"Success — a background task completed as expected."}
      </BannerDescription>
    </Banner>
    <Banner tone="warning">
      <BannerDescription>
        {"Warning — something needs attention before it becomes a problem."}
      </BannerDescription>
    </Banner>
    <Banner tone="error">
      <BannerDescription>
        {"Error — something failed and needs fixing now."}
      </BannerDescription>
    </Banner>
  </Column>
</Stage>

### Variants [#variants]

`soft` (the default) tints the surface for messages in the page flow.
`outline` sits flat on opaque surfaces such as cards and dialogs. `solid` is a
saturated fill — reserve it for the most prominent page-level messages.

<Stage code={"<Banner tone=\"brand\" variant=\"soft\">\n  <Banner.Description>\n    {\"Soft — the tinted default for messages in the page flow.\"}\n  </Banner.Description>\n</Banner>\n<Banner tone=\"brand\" variant=\"outline\">\n  <Banner.Description>\n    {\"Outline — flat on opaque surfaces such as cards and dialogs.\"}\n  </Banner.Description>\n</Banner>\n<Banner tone=\"brand\" variant=\"solid\">\n  <Banner.Description>\n    {\"Solid — a saturated fill for the most prominent messages.\"}\n  </Banner.Description>\n</Banner>"}>
  <Column>
    <Banner tone="brand" variant="soft">
      <BannerDescription>
        {"Soft — the tinted default for messages in the page flow."}
      </BannerDescription>
    </Banner>
    <Banner tone="brand" variant="outline">
      <BannerDescription>
        {"Outline — flat on opaque surfaces such as cards and dialogs."}
      </BannerDescription>
    </Banner>
    <Banner tone="brand" variant="solid">
      <BannerDescription>
        {"Solid — a saturated fill for the most prominent messages."}
      </BannerDescription>
    </Banner>
  </Column>
</Stage>

### With actions [#with-actions]

Wrap `Banner.ActionButton`s in `Banner.Actions` so users can resolve the
condition in place — prefer one or two. Action buttons default to a compact
secondary treatment, and the `solid` variant restyles them to read on the
fill; pass an explicit `variant` to opt out.

<Stage code={"<Banner tone=\"warning\">\n  <Banner.Title>Workspace permissions are changing</Banner.Title>\n  <Banner.Description>\n    {\"Members inherited from parent teams must be re-added by 1 November.\"}\n  </Banner.Description>\n  <Banner.Actions>\n    <Banner.ActionButton>Review changes</Banner.ActionButton>\n    <Banner.ActionButton>Snooze</Banner.ActionButton>\n  </Banner.Actions>\n</Banner>\n<Banner tone=\"error\" variant=\"solid\">\n  <Banner.Description>\n    {\"Sync with the graph failed — recent edits aren't saved.\"}\n  </Banner.Description>\n  <Banner.Actions>\n    <Banner.ActionButton>Retry</Banner.ActionButton>\n  </Banner.Actions>\n</Banner>"}>
  <Column>
    <Banner tone="warning">
      <BannerTitle>Workspace permissions are changing</BannerTitle>
      <BannerDescription>
        {"Members inherited from parent teams must be re-added by 1 November."}
      </BannerDescription>
      <BannerActions>
        <BannerActionButton>Review changes</BannerActionButton>
        <BannerActionButton>Snooze</BannerActionButton>
      </BannerActions>
    </Banner>
    <Banner tone="error" variant="solid">
      <BannerDescription>
        {"Sync with the graph failed — recent edits aren't saved."}
      </BannerDescription>
      <BannerActions>
        <BannerActionButton>Retry</BannerActionButton>
      </BannerActions>
    </Banner>
  </Column>
</Stage>

### Dismissible [#dismissible]

Pass `dismissible` with an `onDismiss` callback to render a trailing dismiss
button. Dismissing doesn't automatically remove the banner — you must handle it via the callback. Make
banners dismissible unless they carry critical information or a required
action.

<Stage code={"<Banner tone=\"brand\" dismissible={{ onDismiss: () => {} }}>\n  <Banner.Description>\n    {\"Tip: drag a property onto the canvas to add it to the entity type.\"}\n  </Banner.Description>\n</Banner>"}>
  <Column>
    <Banner tone="brand" dismissible={{ onDismiss: noop }}>
      <BannerDescription>
        {"Tip: drag a property onto the canvas to add it to the entity type."}
      </BannerDescription>
    </Banner>
  </Column>
</Stage>

```tsx
import { useState } from "react";

import { Banner } from "@hashintel/ds-components";

export const EditorTipBanner = () => {
  const [dismissed, setDismissed] = useState(false);

  if (dismissed) {
    return null;
  }

  return (
    <Banner tone="brand" dismissible={{ onDismiss: () => setDismissed(true) }}>
      <Banner.Description>
        {"Tip: drag a property onto the canvas to add it to the entity type."}
      </Banner.Description>
    </Banner>
  );
};
```

### Leading icon [#leading-icon]

`icon` defaults to `true`, the tone's own icon — keep it unless a more
specific glyph adds meaning. Pass `{ iconName }` for a named design-system
icon, or `false` for none. Pass `icon={{ custom }}` to lead with any node

<Stage code={"<Banner tone=\"brand\" icon>\n  <Banner.Description>\n    {\"A new entity editor is available for this workspace.\"}\n  </Banner.Description>\n</Banner>\n<Banner tone=\"brand\" icon={{ iconName: \"sparkles\" }}>\n  <Banner.Description>\n    {\"HASH AI suggested 3 property mappings for this flow.\"}\n  </Banner.Description>\n</Banner>\n<Banner tone=\"brand\" icon={false}>\n  <Banner.Description>\n    {\"This workspace is on the free plan.\"}\n  </Banner.Description>\n</Banner>"}>
  <Column>
    <Banner tone="brand" icon>
      <BannerDescription>
        {"A new entity editor is available for this workspace."}
      </BannerDescription>
    </Banner>
    <Banner tone="brand" icon={{ iconName: "sparkles" }}>
      <BannerDescription>
        {"HASH AI suggested 3 property mappings for this flow."}
      </BannerDescription>
    </Banner>
    <Banner tone="brand" icon={false}>
      <BannerDescription>
        {"This workspace is on the free plan."}
      </BannerDescription>
    </Banner>
  </Column>
</Stage>

### Custom children [#custom-children]

Children that aren't `Banner.Actions` render in the message column, so custom
markup can replace or sit alongside the built-in parts. Custom content doesn't
pick up the tone's text color — set your own.

<Stage code={"<Banner tone=\"brand\" icon={false}>\n  <div style={{ fontWeight: 500 }}>\n    3 of 5 import steps complete — mapping properties for Person entities.\n  </div>\n  <Banner.Actions>\n    <Banner.ActionButton>View import</Banner.ActionButton>\n  </Banner.Actions>\n</Banner>"}>
  <Column>
    <Banner tone="brand" icon={false}>
      <div style={{ fontWeight: 500 }}>
        3 of 5 import steps complete — mapping properties for Person entities.
      </div>
      <BannerActions>
        <BannerActionButton>View import</BannerActionButton>
      </BannerActions>
    </Banner>
  </Column>
</Stage>

## Behavior [#behavior]

- When the banner runs narrow, the actions wrap beneath the message instead of
  squeezing it into a narrow column.

## Content [#content]

- Lead the title with what happened, as a short sentence: "Workspace
  permissions are changing". Use sentence case and no trailing period.
- Keep descriptions to 1–2 sentences: what happened, then what to do about it.
- For `warning` and `error` banners, always say how to resolve the condition.
- Write action labels verb-first, 1–3 words: "Review changes", "Retry sync".
- Don't write severity into the copy ("Error:", "Warning!") — the tone's icon
  and color already carry it.

## Accessibility [#accessibility]

A banner that announces an urgent problem should implement the
[WAI-ARIA alert pattern](https://www.w3.org/WAI/ARIA/apg/patterns/alert/).

### What Banner provides [#what-banner-provides]

- `Banner.Title` renders a real heading — `h2` by default, but this can be adjusted with `as`.
- No ARIA role is set by default — a banner rendered with the page needs none.

### What you must do [#what-you-must-do]

- Set `role="status"` on banners inserted after load so screen readers
  announce them politely; reserve `role="alert"` for urgent failures — it
  interrupts whatever is being read.
- Choose the `Banner.Title` heading level with `as` so it slots into the
  page's heading outline.

## API reference [#api-reference]

### Banner [#banner]

<PropsTable
  of={Banner}
  defaults={{
    icon: "true",
    variant: '"soft"',
  }}
/>

### Banner.Title [#bannertitle]

<PropsTable of={BannerTitle} defaults={{ as: '"h2"' }} />

### Banner.Description [#bannerdescription]

<PropsTable of={BannerDescription} defaults={{ as: '"p"' }} />

### Banner.Actions [#banneractions]

<PropsTable of={BannerActions} />

### Banner.ActionButton [#banneractionbutton]

<PropsTable
  of={BannerActionButton}
  defaults={{
    variant: '"subtle"',
    size: '"xs"',
    tone: '"neutral"',
    shape: '"default"',
    iconPosition: '"left"',
    type: '"button"',
  }}
/>
