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

# mds-emoji - examples

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

Correct and idiomatic ways to use the `<mds-emoji>` 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 Mascot Display

Drop the component anywhere to render the default mascot, Mia. The element is a square and sizes itself to the value applied via CSS `width` / `height` (it has its own default). No props are required for a static illustration.

```html
<mds-emoji></mds-emoji>
```

#### Choosing a Mascot with `name`

The `name` prop selects between the two available mascots. Use `"mia"` (default) for the AI-branded identity and `"simi"` for the human-like character. Changing `name` at runtime swaps the mascot without a page reload.

```html
<!-- Mia - the AI mascot (default) -->
<mds-emoji name="mia"></mds-emoji>

<!-- Simi - the human-like mascot -->
<mds-emoji name="simi"></mds-emoji>
```

#### Sizing via CSS

Control the rendered size with CSS `width` and `height` on the host - the SVG fills 100% of the host's box. The component keeps a 1:1 aspect ratio automatically.

```html
<mds-emoji name="mia" style="width: 128px; height: 128px;"></mds-emoji>
```

```css
.mascot-hero mds-emoji {
  width: 240px;
  height: 240px;
}
```

#### Mouse-Following Interaction

Call `startFollowMouse()` to activate the 3D head-rotation that tracks the pointer. The feature is off by default. Call `stopFollowMouse()` to deactivate it cleanly.

```html
<mds-emoji id="mascot" name="mia"></mds-emoji>

<script>
  const emoji = document.querySelector('#mascot');
  emoji.startFollowMouse();

  // later, e.g. when leaving a focused section:
  emoji.stopFollowMouse();
</script>
```

#### Idle Blinking

Start the automatic random-interval blink loop with `startBlinking()`. The blink is suppressed while another animation owns the eyes and resumes automatically afterwards.

```html
<mds-emoji id="mascot" name="simi"></mds-emoji>

<script>
  const emoji = document.querySelector('#mascot');
  emoji.startBlinking();
</script>
```

#### Expressing Agreement or Confirmation

Call `agree()` after a successful form submission or confirmed action. The emoji nods and briefly smiles. The returned `Promise` resolves when the animation completes.

```html
<mds-emoji id="mascot" name="mia"></mds-emoji>
<mds-button id="save-btn" label="Salva" variant="primary" tone="strong"></mds-button>

<script>
  const emoji = document.querySelector('#mascot');
  document.querySelector('#save-btn').addEventListener('click', async () => {
    await fetch('/api/save');
    emoji.agree();
  });
</script>
```

#### Expressing a Smile

Call `smile()` for lighter positive feedback - a bounce and closed-eyes smile without the full nod. Useful on hover or focus of a featured element.

```html
<mds-emoji id="mascot" name="mia"></mds-emoji>

<script>
  const emoji = document.querySelector('#mascot');
  document.querySelector('.feature-card').addEventListener('mouseenter', () => {
    emoji.smile();
  });
</script>
```

#### Expressing Disagreement or Errors

Call `disagree()` on validation failure or destructive confirmation. An optional `turnHappyDelay` number (in milliseconds) delays the return to the neutral face - useful when you want the serious expression to linger while an error message is visible.

```html
<mds-emoji id="mascot" name="mia"></mds-emoji>

<script>
  const emoji = document.querySelector('#mascot');

  formEl.addEventListener('submit', async (e) => {
    e.preventDefault();
    const ok = await submitForm();
    if (!ok) {
      emoji.disagree(2000); // stay serious for 2 s while the error banner is visible
    }
  });
</script>
```

#### Thinking State During Async Operations

Call `startThinking()` while a request is in flight - the emoji raises a thinking hand and shifts its gaze. Call `stopThinking()` when the operation settles. Both methods accept an optional `duration` (seconds) for the transition animation.

```html
<mds-emoji id="mascot" name="mia"></mds-emoji>

<script>
  const emoji = document.querySelector('#mascot');

  async function caricaDati() {
    await emoji.startThinking();
    const data = await fetch('/api/data').then((r) => r.json());
    await emoji.stopThinking();
    return data;
  }
</script>
```

#### Chaining Expressions

Because every method returns a `Promise<void>`, you can `await` one before triggering the next. Without awaiting they still never overlap, but each call takes the face over and cuts the previous expression short.

```html
<mds-emoji id="mascot" name="simi"></mds-emoji>

<script>
  const emoji = document.querySelector('#mascot');

  async function onSave() {
    await emoji.startThinking(0.4); // mostri caricamento
    await fetch('/api/salva');
    await emoji.stopThinking(0.4);
    await emoji.agree();           // conferma riuscita
  }
</script>
```

#### CSS Customization - Mouse-Follow Rotation

Tune how far the head turns toward the pointer with the public `--mds-emoji-expression-max-rotation` custom property on the host or a parent selector, always with an angle unit. The initial value of `16deg` is reasonable for most placements; reduce it for a subtler movement. The follow-mouse durations are not public.

```css
.mascot-container mds-emoji {
  --mds-emoji-expression-max-rotation: 10deg;
}
```

#### CSS Customization - Mascot Colors

Override Simi's public skin tones to adapt the character to a custom palette: Simi's skin tones are data, so hex values are fine there. Simi's other colors are not public, and neither are Mia's: they follow the AI accent roles of the theme, so dark mode and named themes keep working.

```css
/* Theming Simi: a skin tone is the palette of an illustration, not a role */
mds-emoji[name='simi'] {
  --mds-emoji-simi-skin: #f5c8a0;
  --mds-emoji-simi-skin-dark: #c8895e;
  --mds-emoji-simi-skin-light: #fdebd8;
}
```

#### CSS Customization - Parallax Offsets

The per-layer parallax offsets and the perspective are not public: the component tunes the depth effect of each mascot. To make the movement subtler or more pronounced, set `--mds-emoji-expression-max-rotation` (see above); to flatten the effect entirely, leave mouse following off (the default) or stop it with `stopFollowMouse()`.

```css
/* Subtle movement for compact placements */
.compact mds-emoji {
  --mds-emoji-expression-max-rotation: 6deg;
}

/* Pronounced movement for hero sections */
.hero mds-emoji {
  --mds-emoji-expression-max-rotation: 24deg;
}
```
