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

# mds-pref-animation - examples

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

Correct and idiomatic ways to use the `<mds-pref-animation>` 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 Usage Inside `mds-pref`

The standard form. Place `<mds-pref-animation>` as a direct slot child of [`<mds-pref>`](../mds-pref/AGENTS.md). No `mode` or `size` is required - the component restores the last persisted choice and defaults to `system` on a first visit.

```html
<mds-pref>
  <mds-pref-animation></mds-pref-animation>
</mds-pref>
```

#### Combined Preferences Panel

Place multiple `mds-pref-*` children inside the same `<mds-pref>`. The parent forwards its `size` to every child, on load and when it changes.

```html
<mds-pref>
  <mds-pref-animation></mds-pref-animation>
  <mds-pref-contrast></mds-pref-contrast>
  <mds-pref-mode></mds-pref-mode>
  <mds-pref-consumption></mds-pref-consumption>
</mds-pref>
```

#### Pre-selecting a Mode via `mode`

Pass `mode` to override the persisted value and start from a known state - for example, a first-run onboarding screen that starts with reduced motion.

```html
<mds-pref>
  <mds-pref-animation mode="reduce"></mds-pref-animation>
</mds-pref>
```

#### Listening for Changes

Handle `mdsPrefChange` when the host application needs to react - for example, to announce the new setting or trigger a soft refresh. The event fires once per change, after the new mode is applied, and not on page load: to know the mode a page starts with, read the `mode` property.

```html
<mds-pref id="prefs">
  <mds-pref-animation></mds-pref-animation>
</mds-pref>

<script>
  document.getElementById('prefs').addEventListener('mdsPrefChange', (event) => {
    // event.detail.preference === 'animation'
    console.log('Preferenza animazioni aggiornata', event.detail);
  });
</script>
```

#### Compact Size

Set `size="sm"` on the parent `<mds-pref>` to shrink the tab items of every `mds-pref-*` child consistently: the parent forwards its `size` on load and on every change.

```html
<!-- In the panel: on the parent only -->
<mds-pref size="sm">
  <mds-pref-animation></mds-pref-animation>
  <mds-pref-contrast></mds-pref-contrast>
</mds-pref>

<!-- Acceptable when used standalone -->
<mds-pref-animation size="sm"></mds-pref-animation>
```

#### Silent Controller (Hidden Preference Sync)

When a `<mds-pref controller>` element is placed in the DOM, it applies preferences silently without rendering any UI. `<mds-pref-animation>` inside it restores the persisted animation class on `<html>` on load without showing the tab group.

```html
<!-- Place once, near the root - no UI is rendered -->
<mds-pref controller>
  <mds-pref-animation></mds-pref-animation>
</mds-pref>
```
