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

# mds-usage - examples

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

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

#### Default Informational Note

The simplest form. Omit `variant` to get the `info` default - a neutral, blue-tinted container that draws attention to a usage note without implying correctness or incorrectness.

```html
<mds-usage>
  <mds-text>
    Utilizzare sempre il colore primario del tema per le azioni principali.
  </mds-text>
</mds-usage>
```

#### Recommended Pattern (`variant="do"`)

Use `variant="do"` to mark a component usage or design pattern as explicitly recommended. The container adopts success styling and the header reads the variant label.

```html
<mds-usage variant="do">
  <mds-button label="Salva" variant="primary" tone="strong"></mds-button>
</mds-usage>
```

#### Discouraged Pattern (`variant="dont"`)

Use `variant="dont"` to mark a usage as explicitly forbidden or inadvisable. The container adopts error styling.

```html
<mds-usage variant="dont">
  <button style="background: blue; color: white;">Salva</button>
</mds-usage>
```

#### Cautionary Note (`variant="warn"`)

Use `variant="warn"` when a pattern is not forbidden but requires care - for example when a prop combination is valid but has side effects, or when a rare edge case exists. The container adopts warning styling.

```html
<mds-usage variant="warn">
  <mds-text>
    Impostare type="button" su ogni pulsante all'interno di un form
    per evitare invii accidentali.
  </mds-text>
</mds-usage>
```

#### Custom Header Label via `alias`

When the auto-generated, localized header ("Consentito", "Non consentito", etc.) is not specific enough for the context, pass `alias` to replace it with a custom string. The locale dictionary is bypassed entirely.

```html
<mds-usage variant="do" alias="Struttura consigliata">
  <mds-text>Usare mds-card con header, content e footer separati.</mds-text>
</mds-usage>

<mds-usage variant="dont" alias="Struttura da evitare">
  <mds-text>Non annidare mds-card all'interno di un'altra mds-card.</mds-text>
</mds-usage>
```

#### Custom Header Icon via `icon`

Each `variant` has its own header icon. When a custom `alias` names a more specific category, pass `icon` with a slug that illustrates it; the `variant` still drives the colors and the label fallback. Keep the icon coherent with the `variant`.

```html
<mds-usage variant="do" alias="Struttura consigliata" icon="mi/baseline/account-tree">
  <mds-text>Usare mds-card con header, content e footer separati.</mds-text>
</mds-usage>
```

#### Side-by-Side Do / Dont Pair

Pair a `do` block with a `dont` block to illustrate a correct and an incorrect approach in the same documentation section. No extra wrapper is needed - use a CSS grid or flex container.

```html
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 1rem;">
  <mds-usage variant="do">
    <mds-button label="Conferma" variant="primary" tone="strong"></mds-button>
  </mds-usage>

  <mds-usage variant="dont">
    <mds-button label="Conferma" tone="strong" style="--mds-button-background: green;"></mds-button>
  </mds-usage>
</div>
```

#### Rich Slotted Content

The default slot accepts any HTML or Magma components. Use this to annotate a fully composed UI fragment rather than a single element.

```html
<mds-usage variant="do" alias="Composizione corretta di mds-card">
  <mds-card>
    <mds-card-header slot="header">
      <mds-text typography="h5">Titolo scheda</mds-text>
    </mds-card-header>
    <mds-card-content slot="content">
      <mds-text>Contenuto principale della scheda.</mds-text>
    </mds-card-content>
    <mds-card-footer slot="footer">
      <mds-button label="Azione" variant="primary"></mds-button>
    </mds-card-footer>
  </mds-card>
</mds-usage>
```

#### Styling Customization

`mds-usage` has no public CSS custom property: its border and header colours follow the `variant` (`do`, `dont`, `info`, `warn`). When an annotation needs other colours, style the documented `header`, `icon` and `label` parts, and use the semantic color roles via `rgb(var(--magma-<role>))` to keep dark mode working.

```css
.docs-callout mds-usage::part(header) {
  background-color: rgb(var(--magma-accent-ai-emphasis));
}
.docs-callout mds-usage::part(icon) {
  fill: rgb(var(--magma-accent-ai-on-emphasis));
}
.docs-callout mds-usage::part(label) {
  color: rgb(var(--magma-accent-ai-on-emphasis));
}
```
