# Banner

## Usage

Use `Banner` for persistent messages that require attention or action.

```vue
<script setup lang="ts">
import { Banner } from '@astryx-vue/core/Banner'
</script>

<template>
  <Banner
    status="success"
    title="Changes saved"
    description="Your settings are up to date."
    is-dismissable
  />
</template>
```

Import the theme once in the application entry:

```ts
import '@astryx-vue/themes/neutral.css'
```

### Anatomy

- **Banner frame**: Outer frame that groups the status surface and optional content surface. It carries whole-banner elevation and, for elevated card banners, the radius that shapes that silhouette.
- **Status surface**: The primary painted surface. It communicates status and contains the icon, title, description, actions, and controls.
- **Icon**: Automatically set based on the status (info, warning, error, success).
- **Title**: The main message. Always required.
- **Description**: Additional detail below the title.
- **Action button**: A button for the user to act on the message, like "Review" or "Retry".
- **Dismiss button**: Lets the user close the banner. Enabled by setting isDismissable.
- **Content surface**: Secondary surface for extra detail below the status surface, like a list of errors. Sits behind an expand/collapse toggle by default; set collapsible to false to keep it visible.

## Best practices

| Guidance | Practices |
| --- | --- |
| Do | Pick a status that matches the message: info for updates, warning for caution, error for problems, success for confirmations. |
| Do | Use the card container inside page content and the section container for full-width messages that span the entire page. |
| Do | Make info and success banners dismissable. Keep error banners visible until the user fixes the issue. |
| Do | Keep titles short and scannable: "Payment failed" not "There was a problem processing your most recent payment." |
| Don't | Use Banner for short-lived messages that disappear on their own; use Toast instead. |
| Don't | Stack multiple banners with the same status; combine related messages into one banner. |

## Examples

### Collapsible

One banner with an action, a dismiss control, and details that start open. The details go in the default slot.

```vue
<script setup lang="ts">
import { Banner } from '@astryx-vue/core/Banner'
import { Button } from '@astryx-vue/core/Button'
import { VStack } from '@astryx-vue/core/Stack'
import { Text } from '@astryx-vue/core/Text'
</script>

<template>
  <Banner
    status="warning"
    title="Configuration changes detected"
    description="Review the changes before they take effect."
    :default-is-open="true"
    is-dismissable
  >
    <template #end>
      <Button label="Review" variant="secondary" size="sm" />
    </template>
    <VStack :gap="2">
      <Text type="supporting" color="secondary">
        Changed settings:
      </Text>
      <ul class="banner-preview-list">
        <li>Authentication method updated</li>
        <li>Rate limits modified</li>
      </ul>
    </VStack>
  </Banner>
</template>
```

### Dismiss

isDismissable lets the user close the banner after reading it.

```vue
<script setup lang="ts">
import { Banner } from '@astryx-vue/core/Banner'
import { VStack } from '@astryx-vue/core/Stack'
</script>

<template>
  <VStack :gap="3">
    <Banner status="success" title="Deployment complete" description="Version 3.2.0 is now live in production." is-dismissable />
    <Banner status="warning" title="Scheduled maintenance tonight" description="The system will be briefly unavailable from 2:00–3:00 AM." is-dismissable />
    <Banner status="info" title="New feature available" description="Try the new dashboard layout in Settings." is-dismissable />
  </VStack>
</template>
```

### Floating

elevation med lifts the banner off the page, so it reads as a floating notice.

```vue
<script setup lang="ts">
import { Banner } from '@astryx-vue/core/Banner'
</script>

<template>
  <Banner
    status="info"
    title="You have unsaved changes"
    description="A raised banner reads as an overlay floating above the page."
    elevation="med"
  />
</template>
```

### Full width

With container set to section, the banner runs edge to edge without a rounded corner, for a notice at the top of the page.

```vue
<script setup lang="ts">
import { Banner } from '@astryx-vue/core/Banner'
import { Button } from '@astryx-vue/core/Button'
import { VStack } from '@astryx-vue/core/Stack'
</script>

<template>
  <VStack :gap="3">
    <Banner
      status="warning"
      title="Scheduled downtime"
      description="All services will be unavailable on Sunday from 2:00–4:00 AM."
      container="section"
      is-dismissable
    />
    <Banner
      status="info"
      title="Welcome to the new dashboard"
      description="We have redesigned the layout based on your feedback."
      container="section"
    >
      <template #end>
        <Button label="Take a tour" variant="secondary" size="sm" />
      </template>
    </Banner>
  </VStack>
</template>
```

### Statuses

Info, success, warning, and error, for an update, a confirmation, a caution, and a problem.

```vue
<script setup lang="ts">
import { Banner } from '@astryx-vue/core/Banner'
import { VStack } from '@astryx-vue/core/Stack'
</script>

<template>
  <VStack :gap="3">
    <Banner status="info" title="A new software update is available" description="Version 2.4.1 includes performance improvements and bug fixes." />
    <Banner status="success" title="Changes saved" description="Your profile information has been updated successfully." />
    <Banner status="warning" title="Storage almost full" description="You have used 90% of your available storage." />
    <Banner status="error" title="Build failed" description="3 tests did not pass. Check the logs for details." />
  </VStack>
</template>
```

### Action

A button in the end slot lets the user act on the message.

```vue
<script setup lang="ts">
import { Banner } from '@astryx-vue/core/Banner'
import { Button } from '@astryx-vue/core/Button'
import { VStack } from '@astryx-vue/core/Stack'
</script>

<template>
  <VStack :gap="3">
    <Banner status="info" title="Your trial expires in 3 days" description="Upgrade now to keep access to all features.">
      <template #end>
        <Button label="Upgrade" variant="secondary" size="sm" />
      </template>
    </Banner>
    <Banner status="warning" title="API key expires soon" description="Generate a new key before December 1 to avoid service interruption.">
      <template #end>
        <Button label="Renew key" variant="secondary" size="sm" />
      </template>
    </Banner>
    <Banner status="error" title="Payment failed" description="We could not process your last payment.">
      <template #end>
        <Button label="Retry" variant="secondary" size="sm" />
      </template>
    </Banner>
  </VStack>
</template>
```

## Usage guidance

The `status` prop sets the tone of a banner, and picking the wrong one makes readers misjudge how urgent the message is. The list below covers which status fits which kind of message, plus two usages that are easy to overlook.

- Use `info` for general information and updates.
- Use `success` for the result of a successful action.
- Use `warning` for situations that call for caution.
- Use `error` for problems that block progress.
- Set `:collapsible="false"` for details that users must read, so those details stay visible and no click is needed to open them. Keep the default toggle when the detail is long enough to bury the banner's own message.
- Announce an async outcome from the transition that produced it, with `useAnnounce`.

`status` controls color and icon only. It does not create a live region. Add `role="status"` only when the visible banner should stay a persistent semantic mirror, and reserve `role="alert"` for genuinely urgent content that should interrupt current speech. Content already on the page at first render is not guaranteed to be announced again.

For a single field validation message, use [FieldStatus](/en/components/field-status).

## Props

| Property | Type | Default | Description |
| --- | --- | --- | --- |
| `status` | `'info' \| 'success' \| 'warning' \| 'error'` | — | Required. Message status. |
| `title` | `string` | — | Required. Message title. |
| `description` | `string` | — | Supporting text below the title. |
| `icon` | `Component` | — | Custom decorative icon. |
| `isDismissable` | `boolean` | false | Shows the dismiss button. Dismissal hides the component. |
| `dismissLabel` | `string` | Dismiss {title} | Accessible name for the dismiss button. The tooltip stays the short word Dismiss unless this is set. |
| `container` | `'card' \| 'section'` | card | card has rounded corners. section has square corners. |
| `elevation` | `'none' \| 'low' \| 'med' \| 'high'` | none | Shadow depth for the whole banner. |
| `collapsible` | `boolean` | true | Whether detail content can collapse. |
| `defaultIsOpen` | `boolean` | false | Initial expansion when isOpen is not bound. |
| `v-model:isOpen` | `boolean` | — | Controls expansion from the parent. |
| `expandLabel` | `string` | Expand | Accessible name and tooltip for the expand button. Follows the active locale. |
| `collapseLabel` | `string` | Collapse | Accessible name and tooltip for the collapse button. Follows the active locale. |

## Slots

- Default: details below the header.
- `title`: replaces the visible title. The `title` prop remains required.
- `description`: replaces the supporting text.
- `icon`: replaces the decorative status icon.
- `end`: action buttons at the end of the header.

Title, description and detail slots accept block content.

## Expanding and collapsing

- Detail content enables the expand button.
- Details start collapsed by default.
- `defaultIsOpen` sets the initial state only.
- `v-model:isOpen` controls the current state.
- `collapsible` set to `false` keeps details visible.
- Collapsing unmounts the details.
- If a parent closes focused details, focus returns to the expand button.

```vue
<Banner v-model:is-open="open" status="info" title="Configuration changes">
  <p>Review the updated settings before continuing.</p>
</Banner>
```

## Dismissal

- `isDismissable` shows a dismiss button.
- Clicking it hides the component.
- The component emits `dismiss`.
- Dismissal tries to restore focus to the element used before entering the banner.
- Remount the component or change its `key` to show it again.

## Events and template references

- `update:isOpen(value)`: requests an expansion change.
- `dismiss()`: dismisses the banner.
- `element`: the root `HTMLDivElement | null`. It becomes `null` after dismissal.

## Localization

Provide translated control labels:

- `dismissLabel`: dismiss button.
- `expandLabel`: expand button.
- `collapseLabel`: collapse button.

## Theme

```css
.my-banner {
  --astryx-banner-info-background: #ecfdf5;
  --astryx-banner-info-foreground: #065f46;
}
```

- `--astryx-banner-info-background`: information background.
- `--astryx-banner-info-foreground`: information text and icon.
- `--astryx-banner-success-background`: success background.
- `--astryx-banner-success-foreground`: success text and icon.
- `--astryx-banner-warning-background`: warning background.
- `--astryx-banner-warning-foreground`: warning text and icon.
- `--astryx-banner-error-background`: error background.
- `--astryx-banner-error-foreground`: error text and icon.
- `--astryx-banner-content-background`: detail background.
- `--astryx-banner-border`: detail border.
- `--astryx-radius-container`: card corner radius.

Neutral follows the active light or dark mode.
