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

# mds-paginator - examples

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

Correct and idiomatic ways to use the `<mds-paginator>` 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 Paginator

Provide `pages` with the total number of pages. The component renders all items and the previous/next arrows automatically. The `pages` prop is all that is required for a working paginator.

```html
<mds-paginator pages="20"></mds-paginator>
```

#### Starting on a Specific Page

Set `current-page` to pre-select an initial page. On load the component emits `mdsPaginatorChange` and scrolls the strip to center the active item.

```html
<mds-paginator pages="32" current-page="16"></mds-paginator>
```

#### Listening to Page Changes

Listen for `mdsPaginatorChange` to react to navigation. The event detail carries `{ page, caller }` where `page` is the newly selected page number and `caller` is the `mds-paginator-item` that triggered the change.

```html
<mds-paginator id="pager" pages="10"></mds-paginator>

<script>
  document.getElementById('pager').addEventListener('mdsPaginatorChange', (e) => {
    const nuovaPagina = e.detail.page;
    // Aggiorna la tabella o la lista con i dati della nuova pagina
    caricaDati(nuovaPagina);
  });
</script>
```

#### Controlled Navigation from Outside

Write `current-page` programmatically to drive the paginator from application state - for example when a search resets pagination to page 1.

```html
<mds-paginator id="pager" pages="15" current-page="1"></mds-paginator>

<script>
  function resettaPaginazione() {
    document.getElementById('pager').currentPage = 1;
  }
</script>
```

#### Single-Page and Two-Page Edge Cases

When `pages` is `1` only the first/last item and the arrows appear (the scrollable strip is omitted). When `pages` is `2` both the first and last items render without the strip. Both are valid states - pass the real page count without special-casing.

```html
<!-- Una sola pagina: solo gli arrow e la pagina 1 -->
<mds-paginator pages="1"></mds-paginator>

<!-- Due pagine: pagina 1 e pagina 2, nessuna strip -->
<mds-paginator pages="2"></mds-paginator>
```

#### Styling the Page Strip Background

Override `--mds-paginator-background` on the host to change the background of the scrollable pages area. Use a Magma color token wrapped in `rgb(var(...))` so dark mode keeps working.

```css
.mia-tabella mds-paginator {
  --mds-paginator-background: rgb(var(--magma-wash-strong));
}
```

#### Disabling Scroll Animation

Set `--mds-paginator-scroll-behavior` to `auto` to remove the animated scroll when jumping between pages - useful for contexts that already honour `prefers-reduced-motion` at application level.

```css
.stampa mds-paginator {
  --mds-paginator-scroll-behavior: auto;
}
```

#### Styling Individual Items

The items the paginator renders live in its shadow DOM and expose no shadow parts, but they inherit their public `--mds-paginator-item-*` CSS custom properties, documented on [`mds-paginator-item`](../mds-paginator-item/AGENTS.md): set them on the `mds-paginator` host (or a parent selector) to restyle every page item at once. Use the semantic color roles so dark mode keeps working.

```css
.archivio mds-paginator {
  --mds-paginator-item-radius: var(--magma-radius-md);
}
```
