<!--
  GENERATED FILE - do not edit by hand.
  Source of truth: src/components/mds-banner/usage/ in the magma monorepo.
-->

# mds-banner - examples

> The API of this component: [`AGENTS.md`](AGENTS.md).

Correct and idiomatic ways to use the `<mds-banner>` component, ordered from most common to most specialized. The examples assume a working knowledge of the variant / tone ladders documented in [`agents/variants.md`](../../../../agents/variants.md) and the shared component rules in [`agents/conventions.md`](../../../../agents/conventions.md).

#### Informational Banner

The baseline usage. Provide `variant="info"` and place the body copy in the default slot. The component derives `role="status"` and `aria-live="polite"` automatically from the variant.

```html
<mds-banner variant="info">
  <mds-text typography="detail">
    Il sistema e in manutenzione programmata dalle 22:00 alle 23:00.
  </mds-text>
</mds-banner>
```

#### Status Variants

Pick the variant that matches the message's semantic weight. `error` and `warning` set `role="alert"` with assertive live region; the others use `role="status"` with polite announcement.

```html
<!-- Esito positivo -->
<mds-banner variant="success">
  <mds-text typography="detail">Dati salvati correttamente.</mds-text>
</mds-banner>

<!-- Avviso non bloccante -->
<mds-banner variant="warning">
  <mds-text typography="detail">La sessione scadra tra 5 minuti.</mds-text>
</mds-banner>

<!-- Errore bloccante -->
<mds-banner variant="error">
  <mds-text typography="detail">Impossibile completare l'operazione. Riprovare.</mds-text>
</mds-banner>
```

#### Banner with Headline

Use the `headline` prop to add a title above the body text. The headline is also used as the banner's accessible label (`aria-label`).

```html
<mds-banner variant="warning" headline="Licenza in scadenza">
  <mds-text typography="detail">
    La licenza del servizio scadra tra 7 giorni. Rinnova ora per non interrompere il servizio.
  </mds-text>
</mds-banner>
```

#### Banner with Icon

Set `icon` to a Magma icon slug. The icon is decorative (`aria-hidden="true"`). The colored badge wrapping the icon is shown by default; add `hide-cockade` for a flatter look.

```html
<!-- Con cockade (default) -->
<mds-banner variant="info" icon="mi/baseline/info" headline="Aggiornamento disponibile">
  <mds-text typography="detail">E disponibile una nuova versione dell'applicazione.</mds-text>
</mds-banner>

<!-- Senza cockade -->
<mds-banner variant="success" icon="mi/baseline/check-circle" hide-cockade>
  <mds-text typography="detail">Operazione completata.</mds-text>
</mds-banner>
```

#### Dismissible Banner

Set `dismissible` to show a close button. The button emits `mdsBannerClose` when activated. Listen for the event to remove the banner from the DOM or update application state.

```html
<mds-banner variant="info" dismissible id="promo-banner">
  <mds-text typography="detail">
    Scopri le nuove funzioni premium disponibili nel tuo piano.
  </mds-text>
</mds-banner>

<script>
  document.querySelector('#promo-banner').addEventListener('mdsBannerClose', () => {
    document.querySelector('#promo-banner').remove();
  });
</script>
```

#### Banner with Action Buttons

Slot `<mds-button>` elements with `slot="action"` to add inline controls. The action region is shown only while at least one `[slot="action"]` child is present, and it follows the actions added or removed after the first render. Match the button variant to the banner variant for visual consistency.

```html
<mds-banner variant="warning" headline="Abbonamento scaduto">
  <mds-text typography="detail">
    La licenza di questo servizio e scaduta. Il servizio continua a funzionare
    ma non puoi utilizzare le funzioni premium.
  </mds-text>
  <mds-button slot="action" variant="warning" tone="outline">Annulla</mds-button>
  <mds-button slot="action" variant="warning" tone="strong">Rinnova abbonamento</mds-button>
</mds-banner>
```

#### Tone for Visual Emphasis

`tone` controls emphasis without changing the semantic variant. `strong` paints the status tint on the whole banner, `weak` (default) keeps a neutral raised surface and colours only the icon, and `box` adds a solid box shadow for high-contrast placements. `mds-banner` accepts only `weak`, `strong`, and `box` - not `outline` or `text`.

```html
<!-- Bassa enfasi (default) -->
<mds-banner variant="error" tone="weak">
  <mds-text typography="detail">Errore di validazione nei campi del modulo.</mds-text>
</mds-banner>

<!-- Alta enfasi -->
<mds-banner variant="error" tone="strong">
  <mds-text typography="detail">Account bloccato per attivita sospetta. Contatta il supporto.</mds-text>
</mds-banner>
```

#### Dark and Light Decorative Variants

`variant="dark"` and `variant="light"` are neutral, decorative banners without an ARIA live region (`role="presentation"`). Use them for non-critical UI chrome - announcements or promotional content that does not require immediate attention.

```html
<mds-banner variant="dark" tone="strong" headline="Novita del mese">
  <mds-text typography="detail">
    Tre nuovi moduli sono stati aggiunti alla piattaforma.
  </mds-text>
  <mds-button slot="action" variant="light" tone="text">Scopri</mds-button>
</mds-banner>
```

#### AI Variant

Use `variant="ai"` to mark banners that present AI-generated content or AI-powered suggestions. The variant emits a polite `role="status"` live announcement.

```html
<mds-banner variant="ai" icon="mi/baseline/auto-awesome" headline="Suggerimento IA">
  <mds-text typography="detail">
    L'analisi ha rilevato tre anomalie nel documento caricato.
  </mds-text>
  <mds-button slot="action" variant="ai" tone="outline">Visualizza dettagli</mds-button>
</mds-banner>
```

#### The Window of a Dialog

Slotted as the `window` of an `<mds-modal>`, the banner is the dialog: `variant="light"` `tone="box"` `dismissible`, its close button closes the modal with no extra JavaScript, and its headline is the title of the dialog, in `h5`, with no attribute to write. The headline is hidden from screen readers, so `aria-label` on `mds-modal` names the dialog, with the same text.

```html
<mds-modal aria-label="Eliminare Contratto di servizio?">
  <mds-banner slot="window" variant="light" tone="box" dismissible headline="Eliminare Contratto di servizio?">
    <mds-text typography="detail">Il documento non potra' essere recuperato.</mds-text>
    <mds-button slot="action" variant="dark" tone="outline" autofocus>Annulla</mds-button>
    <mds-button slot="action" variant="error" tone="strong">Elimina</mds-button>
  </mds-banner>
</mds-modal>
```

In the page the same banner keeps its headline in `h6`, the title of a part. `typography` writes the style when the place does not say it: `h6` or `h5`, nothing larger.

```html
<mds-banner variant="info" typography="h5" headline="Nuova versione del servizio">
  <mds-text typography="detail">Da oggi puoi firmare i documenti dall'app.</mds-text>
</mds-banner>
```

#### CSS Custom Property Customization

Override appearance only through the public `--mds-banner-*` custom properties. Set them on the host or a parent selector; use semantic color roles via `rgb(var(--magma-<role>))` so dark mode and high-contrast modes keep working.

```css
.featured-notice mds-banner {
  --mds-banner-background: rgb(var(--magma-accent-emphasis));
  --mds-banner-color: rgb(var(--magma-accent-on-emphasis));
  --mds-banner-radius: var(--magma-radius-sm);
  --mds-banner-shadow: 0 4px 16px rgb(var(--magma-shadow-ink) / 0.15);
}
```
