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

# mds-accordion-timer-item - examples

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

Correct and idiomatic ways to use the `<mds-accordion-timer-item>` 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 Timed Accordion

The canonical form. Always place `<mds-accordion-timer-item>` as a direct child of [`<mds-accordion-timer>`](../mds-accordion-timer/AGENTS.md). Provide a `description` for each item - it becomes the header label and the accessible name for the content region. Mark one item `selected`: without it the timer does not start.

```html
<mds-accordion-timer>
  <mds-accordion-timer-item description="Introduzione al progetto" selected>
    <mds-text>Contenuto dell'introduzione al progetto.</mds-text>
  </mds-accordion-timer-item>
  <mds-accordion-timer-item description="Obiettivi principali">
    <mds-text>Elenco degli obiettivi principali del progetto.</mds-text>
  </mds-accordion-timer-item>
  <mds-accordion-timer-item description="Conclusioni">
    <mds-text>Riepilogo e prossimi passi.</mds-text>
  </mds-accordion-timer-item>
</mds-accordion-timer>
```

#### Setting the Initially Open Item

Mark one item `selected` to define which panel is open on load. The parent reads this state at `componentDidLoad` to anchor its timer on that item. Mark at most one item; the parent will enforce exclusive selection after load.

```html
<mds-accordion-timer>
  <mds-accordion-timer-item description="Fase uno" selected>
    <mds-text>Descrizione della fase uno.</mds-text>
  </mds-accordion-timer-item>
  <mds-accordion-timer-item description="Fase due">
    <mds-text>Descrizione della fase due.</mds-text>
  </mds-accordion-timer-item>
</mds-accordion-timer>
```

#### Per-Item Duration Override

Set `duration` (in milliseconds) on a single item to give it a different display time than the global `duration` set on the parent. Omit `duration` on items that should use the parent's default.

```html
<mds-accordion-timer duration="5000">
  <mds-accordion-timer-item description="Panoramica rapida" duration="2000" selected>
    <mds-text>Questa sezione scorre piu velocemente delle altre.</mds-text>
  </mds-accordion-timer-item>
  <mds-accordion-timer-item description="Dettagli tecnici" duration="12000">
    <mds-text>Questa sezione richiede piu tempo per la lettura.</mds-text>
  </mds-accordion-timer-item>
  <mds-accordion-timer-item description="Contatti">
    <mds-text>Usa la durata globale di 5000 ms.</mds-text>
  </mds-accordion-timer-item>
</mds-accordion-timer>
```

#### The Title of an Item Is a Part

An item is a part of the page, whose title is styled as `h6` (`titles/part`): write `typography="h6"`, until the default moves from `h5` with the next major (#1218). `typography` is the style only; `tag` gives the level of the title in the outline, one below the title of the section that holds the accordion (`h3` under an `h2`).

```html
<mds-text typography="section" tag="h2">Come funziona</mds-text>
<mds-accordion-timer>
  <mds-accordion-timer-item description="Argomento principale" typography="h6" tag="h3">
    <mds-text>Contenuto dell'argomento principale.</mds-text>
  </mds-accordion-timer-item>
  <mds-accordion-timer-item description="Sotto-argomento" typography="h6" tag="h3">
    <mds-text>Approfondimento del sotto-argomento.</mds-text>
  </mds-accordion-timer-item>
</mds-accordion-timer>
```

The heading wraps the button that opens the item, as the Accordion pattern of the WAI-ARIA Authoring Practices does. Left out, `tag` leaves the item a button only, out of the outline; never write the level of the style (`tag="h6"` under an `h2`), which skips the levels in between.

#### Rich Slotted Content

The default slot accepts HTML elements and components, not only plain text. Use it to compose images, lists, or nested components inside the disclosure panel.

```html
<mds-accordion-timer>
  <mds-accordion-timer-item description="Caratteristiche del prodotto">
    <mds-img src="/images/prodotto.jpg" alt="Foto del prodotto"></mds-img>
    <mds-text>
      Il prodotto include le seguenti funzionalita: gestione utenti, reportistica avanzata e
      integrazione con i sistemi esistenti.
    </mds-text>
  </mds-accordion-timer-item>
  <mds-accordion-timer-item description="Prezzi e licenze">
    <mds-text>Contatta il nostro team commerciale per un preventivo personalizzato.</mds-text>
    <mds-button label="Richiedi preventivo" variant="primary" tone="strong"></mds-button>
  </mds-accordion-timer-item>
</mds-accordion-timer>
```

#### Reacting to Item Changes

Listen for `mdsAccordionTimerItemClickSelect` to detect user-initiated selection (it fires only when a click opens the item). `mdsAccordionTimerItemSelect` on the item fires on every selection - click, code or timer - and `mdsAccordionTimerChange` on the parent reports the new index.

```html
<mds-accordion-timer id="timer">
  <mds-accordion-timer-item description="Notizie in evidenza" id="item-0" selected>
    <mds-text>Prima notizia in evidenza della giornata.</mds-text>
  </mds-accordion-timer-item>
  <mds-accordion-timer-item description="Aggiornamenti recenti" id="item-1">
    <mds-text>Ultimi aggiornamenti disponibili.</mds-text>
  </mds-accordion-timer-item>
</mds-accordion-timer>

<script>
  document.getElementById('item-0').addEventListener('mdsAccordionTimerItemClickSelect', (e) => {
    console.log('selezione manuale', e.detail);
  });

  document.getElementById('timer').addEventListener('mdsAccordionTimerChange', (e) => {
    console.log('avanzamento automatico, indice:', e.detail.index);
  });
</script>
```

#### Styling Customization

Style the item only through its public `--mds-accordion-timer-item-*` CSS custom properties. Use semantic color roles wrapped in `rgb(var(--magma-<role>))` so dark mode and high-contrast modes keep working. Note that `--mds-accordion-timer-item-color` is also inherited from the parent's `--mds-accordion-timer-color` counterpart - setting it on the parent applies to all items at once.

```css
/* Customise a single item by targeting its host */
.featured-section mds-accordion-timer-item {
  --mds-accordion-timer-item-color: rgb(var(--magma-accent-fg));
}
```
