# Banner

A message about the page or the whole app, inline or floating, in an information, warning, danger or success tone.

- Family: feedback
- Import: `import { Banner } from "@senvenli/react/feedback";`
- Page: https://design.senvenli.com/docs/components/banner
- JSON: https://design.senvenli.com/docs/components/banner.json

## Example: A section message

What happened in the title, why and what to do beneath it, and up to two link actions.

```tsx
import { Link } from "@senvenli/react/action";
import { Banner } from "@senvenli/react/feedback";

export default function Example() {
  return (
    <Banner
      title="Your trial ends in 3 days"
      actions={
        <>
          <Link href="#plans">Choose a plan</Link>
          <Link href="#compare">Compare plans</Link>
        </>
      }
    >
      Add a payment method to keep your projects and invoices after March 21.
    </Banner>
  );
}
```

## Examples

### Tones

The icon and the title say the status; a danger banner is announced as an alert.

```tsx
import { Link } from "@senvenli/react/action";
import { Banner } from "@senvenli/react/feedback";
import { Stack } from "@senvenli/react/layout";

export default function Example() {
  return (
    <Stack space="space-150">
      <Banner tone="success" title="Bank account verified">
        Payouts start with your next invoice.
      </Banner>
      <Banner tone="warning" title="Storage is almost full">
        You have used 46 of 50 GB. Remove files or upgrade to keep uploading.
      </Banner>
      <Banner tone="danger" title="Payment failed" actions={<Link href="#billing">Update payment method</Link>}>
        We could not charge the card ending in 4242. Update it to keep your plan.
      </Banner>
    </Stack>
  );
}
```

### Dismissible

`onDismiss` adds the close button. Leave it out for errors that must be resolved.

```tsx
import { Button } from "@senvenli/react/action";
import { Banner } from "@senvenli/react/feedback";
import { useState } from "react";

export default function Example() {
  const [isOpen, setOpen] = useState(true);
  if (!isOpen) return <Button onPress={() => setOpen(true)}>Show the banner again</Button>;
  return (
    <Banner title="Invoices have a new layout" onDismiss={() => setOpen(false)} dismissLabel="Close the layout notice">
      Totals and tax now sit at the top of every invoice.
    </Banner>
  );
}
```

### Floating

Pinned to the bottom of the viewport until the visitor acts on it, like a cookie notice.

```tsx
import { Button } from "@senvenli/react/action";
import { Banner } from "@senvenli/react/feedback";
import { useState } from "react";

export default function Example() {
  const [isOpen, setOpen] = useState(false);
  return (
    <>
      <Button onPress={() => setOpen(true)} isDisabled={isOpen}>Show the cookie notice</Button>
      {isOpen && (
        <Banner
          placement="floating"
          aria-label="Cookie notice"
          icon="cookie"
          title="We use cookies"
          actions={<Button onPress={() => setOpen(false)}>Accept</Button>}
          onDismiss={() => setOpen(false)}
          dismissLabel="Close cookie notice"
        >
          They keep you signed in and show us which pages are used.
        </Banner>
      )}
    </>
  );
}
```

## Guidelines

### When to use it

- Telling people something about this page that they need to read or act on.

### Use something else when

- [badge](https://design.senvenli.com/docs/components/badge.md): Only an item's status needs showing.

### Do and avoid

- Say why and what to do; omit the close button for errors that must be resolved.

## Accessibility

Built in:

- Announced with the right urgency for its tone.
- The close button is named "Close" or your `dismissLabel`.

You provide:

- A specific `dismissLabel` when "Close" alone is vague.

## API reference

### Banner

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| tone | `BannerTone` |  | no |  |
| children | `React.ReactNode` |  | no | Why, and what to do. |
| actions | `React.ReactNode` |  | no | Inline: up to two link actions. Floating: a default (neutral) Button, never the gold primary. |
| onDismiss | `() => void` |  | no | Shows a close button; omit for errors that must be resolved. |
| dismissLabel | `string` |  | no | The close button's name when "Close" alone is too vague ("Close cookie notice"). |
| placement | `"inline" \| "floating"` |  | no |  |
| title | `React.ReactNode` |  | no | What happened, one line. |
| aria-label | `string` |  | no | Names the region ("Cookie notice"). |
| avoid | `string \| RefObject<HTMLElement \| null>` |  | no | A sticky bottom bar to sit above: its element (measured from its top edge) or a CSS length with a unit ("72px"). |
| icon | `IconName \| null` |  | no | Replaces the tone icon ("cookie"); `null` shows none (narrow phone layouts). |

### Tokens it reads

`--ds-background-danger`, `--ds-background-information`, `--ds-background-success`, `--ds-background-warning`, `--ds-border`, `--ds-border-danger`, `--ds-border-information`, `--ds-border-success`, `--ds-border-warning`, `--ds-radius-large`, `--ds-shadow-overlay`, `--ds-space-050`, `--ds-space-100`, `--ds-space-150`, `--ds-space-200`, `--ds-surface-overlay`, `--ds-text`

## Related

- [empty-state](https://design.senvenli.com/docs/components/empty-state.md)
