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

# mds-status-bar - examples

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

Correct and idiomatic ways to use the `<mds-status-bar>` 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).

#### The Edit of a Page

The canonical form: when a form is the whole page, its row of actions docks in the bar for the whole edit (`surfaces/edit-actions`), Annulla `dark outline` and Salva `primary strong` last (`actions/order`). Show the bar by setting `visible`; it docks to the bottom-right corner of the viewport by default, and the page keeps its room. Inside the `<form>`, Salva submits it and Annulla resets it.

```html
<main class="page-frame">
  <form class="max-w-form grid gap-between-fields">
    <mds-input-field label="Oggetto"><mds-input value="Rinnovo concessione suolo pubblico"></mds-input></mds-input-field>
    <mds-input-field label="Note per l'ufficio"><mds-input type="textarea"></mds-input></mds-input-field>

    <mds-status-bar visible description="Modifiche non salvate">
      <mds-button type="reset" variant="dark" tone="outline">Annulla</mds-button>
      <mds-button>Salva</mds-button>
    </mds-status-bar>
  </form>
</main>
```

#### Showing a Contextual Description

Use `description` to render an optional caption beside the slotted actions when the context is not obvious from the buttons alone.

```html
<mds-status-bar visible description="Stai modificando 4 elementi">
  <mds-button variant="dark" tone="outline">Annulla</mds-button>
  <mds-button variant="primary" tone="strong">Salva</mds-button>
</mds-status-bar>
```

#### Controlling Position

Use the `position` prop to anchor the bar to the bottom-left or to the bottom-center of the viewport. The default is `'bottom-right'`.

```html
<!-- Bottom-left -->
<mds-status-bar visible position="bottom-left" description="Selezione attiva">
  <mds-button variant="error" tone="outline">Elimina selezionati</mds-button>
</mds-status-bar>

<!-- Centered bottom -->
<mds-status-bar visible position="bottom" description="Azione in corso">
  <mds-button variant="primary" tone="strong">Applica</mds-button>
</mds-status-bar>
```

#### Programmatic Show / Hide

Toggle the bar imperatively: set `visible = true` to show it and call `hide()` to dismiss it (`visible = false` works too: the component normalizes it to `undefined`). In markup remove the attribute, never write `visible="false"`.

```html
<mds-button id="edit-trigger">Modifica elementi</mds-button>

<mds-status-bar id="bar" description="Stai modificando la selezione">
  <mds-button id="cancel" variant="dark" tone="outline">Annulla</mds-button>
  <mds-button id="save" variant="primary" tone="strong">Salva modifiche</mds-button>
</mds-status-bar>

<script>
  const bar = document.getElementById('bar');
  document.getElementById('edit-trigger').addEventListener('click', () => {
    bar.visible = true;
  });
  document.getElementById('cancel').addEventListener('click', () => {
    bar.hide();
  });
</script>
```

#### Async Confirm Flow

Show an in-flight state on the confirm button using `await`, then call `hide()` when the operation completes. The cancel button should be disabled while the request is in progress.

```html
<mds-status-bar id="bar" visible description="Stai modificando 3 elementi">
  <mds-button id="cancel" variant="dark" tone="outline">Annulla</mds-button>
  <mds-button id="confirm" variant="primary" tone="strong">Conferma</mds-button>
</mds-status-bar>

<script>
  const bar = document.getElementById('bar');
  const cancel = document.getElementById('cancel');
  const confirm = document.getElementById('confirm');

  confirm.addEventListener('click', async () => {
    cancel.disabled = true;
    confirm.await = true;
    confirm.label = 'Salvataggio in corso...';
    await saveChanges();
    bar.hide();
  });
</script>
```

#### Locking Body Scroll

Set `overflow="auto"` to prevent the page from scrolling while the status bar is open. The default `'manual'` leaves the body scrollable.

```html
<mds-status-bar visible overflow="auto" description="Salvataggio in corso">
  <mds-button variant="dark" tone="outline">Annulla</mds-button>
  <mds-button variant="primary" tone="strong" await>Salva</mds-button>
</mds-status-bar>
```

#### Styling Customization

Customize the bar only through its public `--mds-status-bar-*` CSS custom properties and the exposed `::part()` names (`status-bar`, `status-bar-area`, `actions`); the backdrop behind the bar is set by the component. Use semantic color roles via `rgb(var(--magma-<role>))` so dark mode keeps working.

```css
mds-status-bar {
  --mds-status-bar-max-width: 700px;
}

mds-status-bar::part(status-bar) {
  border: 1px solid rgb(var(--magma-border-default));
}
```
