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

# mds-spinner - examples

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

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

#### Basic Spinner

A spinner shows and animates while `running` is set.

```html
<mds-spinner running></mds-spinner>
```

Without `running` the component is invisible and its animation paused. Render it into the DOM early and set `running` when a request starts; removing the attribute (or setting the prop to `undefined`) hides it again when done.

```html
<!-- Rendered early, hidden until a request starts -->
<mds-spinner></mds-spinner>
```

#### Inline Loading Indicator

Place the spinner next to a label to signal that a section is loading. The spinner is painted in the accent color (`--magma-accent-fg`) by default; set `color` on the host to match the surrounding text instead.

```html
<div class="loading-row">
  <mds-spinner running></mds-spinner>
  <span>Caricamento dati in corso...</span>
</div>
```

#### Full-Page or Overlay Loading State

Centre the spinner over a region with a wrapper. Drive `running` programmatically - set it when the async operation starts, remove it when done.

```html
<div class="overlay">
  <mds-spinner running></mds-spinner>
</div>
```

```css
.overlay {
  align-items: center;
  display: flex;
  inset: 0;
  justify-content: center;
  position: absolute;
}
```

#### Inside `mds-button` (via `await`)

`mds-button` manages its own internal `<mds-spinner>` automatically through its `await` prop. Do not add a separate `<mds-spinner>` next to a button - use `await` on the button itself.

```html
<!-- While an async operation is in flight -->
<mds-button label="Salvataggio in corso..." await variant="primary" tone="strong"></mds-button>
```

#### Controlling Animation Speed

Use the `--mds-spinner-duration` CSS custom property to tune the rotation speed. Set it on the host element - shorter values spin faster, longer values spin slower. Reduced motion still slows the spinner down to 8s per turn, whatever this property says.

```css
.fast-indicator mds-spinner {
  --mds-spinner-duration: 0.4s;
}

.slow-indicator mds-spinner {
  --mds-spinner-duration: 1.5s;
}
```

#### Accessible Loading Region

`<mds-spinner>` is purely decorative and carries no ARIA role. Announce the loading state to screen readers by adding `aria-busy` and `aria-live` on the surrounding container, not on the spinner itself.

```html
<section aria-busy="true" aria-live="polite" aria-label="Ricerca in corso">
  <mds-spinner running></mds-spinner>
</section>
```

#### Colour Customization via CSS Color

The spinner stroke inherits `color` from the host, so you can recolour it without touching shadow internals. Use a semantic colour role so dark mode and high-contrast modes keep working.

```css
.status-warning-spinner mds-spinner {
  color: rgb(var(--magma-warning-text-default));
}
```

```html
<div class="status-warning-spinner">
  <mds-spinner running></mds-spinner>
</div>
```
