<!--
  GENERATED FILE - do not edit by hand.
  Source of truth: src/components/mds-pref-mode/ in the magma monorepo (usage/*.md and the
  component's JSDoc). Regenerated on every stencil build (scripts/component-docs.ts).
-->

# mds-pref-mode

> `@maggioli-design-system/magma` 2.15.0. Shadow DOM: style it only through the public CSS custom properties and the parts below.

The `<mds-pref-mode>` web component is the mode preference control of the Magma Design System, usually a direct child of the [`<mds-pref>`](../mds-pref/AGENTS.md) panel. It renders a labelled three-way tab (light / system / dark) that lets the user pick a color-scheme mode and applies it globally to the document.

#### Semantic Behavior

- **Usually inside `<mds-pref>`**: Placed as a direct slot child of `<mds-pref>`, alongside the other `mds-pref-*` controls; it also works on its own, since it applies and stores the mode by itself. What it gives up on its own is in its mistakes.
- **Selection follows `mode`**: The active tab reflects whichever mode is currently applied, driven by the `mode` prop.
- **Global mode application**: Selecting a mode applies it document-wide and persists the choice.
- **Persistence on load**: The applied mode resolves from `mode` -> the stored value -> the `system` default, so a previously chosen mode is restored without an explicit prop.
- **`mdsPrefChange` event**: Emits `mdsPrefChange` with `{ preference: 'mode' }` once per change, after the new mode is applied; a pick of the mode already active and the first application on load do not emit it. It bubbles up to `<mds-pref>`; a mode change needs no reload, so it raises no reload notice.
- **Instances stay in sync**: Instances mounted together (a hidden `<mds-pref controller>` and a visible settings panel) share the applied mode: a pick in one is mirrored by the others, which neither apply it again nor emit `mdsPrefChange`. A `pref-mode-*` class written on `<html>` by other code is mirrored the same way.
- **System mode**: The `system` choice follows the OS `prefers-color-scheme` media query to resolve the effective light/dark scheme.
- **Theme lock**: Under a theme that can be used in one mode only (`pref-theme-scheme-light` or `-dark` on `<html>`, written by `mds-pref-theme` from the mode the theme declares), the control shows that mode selected and disables the other two items: the page is in that mode whatever was picked. The stored choice is left alone and comes back with a theme of both modes.

#### Properties & Visual Configurations

- **`mode`**: Sets and reflects the active mode (`light`, `dark`, `system`). Leave it unset to inherit the persisted/default mode; set it explicitly to force a starting mode.
- **`transition`**: Controls the visual switch between schemes. Use `smooth` (default) for a fading neutral overlay that flips the mode mid-fade, `flash` for an instant switch with a brief overlay pulse, or `none` to apply the new mode with no overlay animation. The overlay timing and z-index are tunable through `--mds-pref-mode-overlay-*` CSS custom properties.
- **`size`**: Sizes the nested tab items (`sm` / `md`). Inside `<mds-pref>`, set it on the parent instead: the parent's `size` reaches every `mds-pref-*` child on load and when it changes, and overwrites the child's own.

## Read next

- [`examples.md`](examples.md) - correct usage, from the most common case
- [`mistakes.md`](mistakes.md) - the wrong forms, each with the right one
- [Storybook](https://magma-design-system.github.io/magma/storybook/?path=/docs/ui-preferences-mode--docs) - the live examples, in the published Storybook of `main`
- [`conventions.md`](../../../../agents/conventions.md), [`variants.md`](../../../../agents/variants.md), [`mistakes.md`](../../../../agents/mistakes.md) - the rules shared by every component

## Props

| Prop | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `lockedScheme` | `locked-scheme` | `"all" \| "dark" \| "light" \| undefined` | - | Locks the mode choice to one mode, `light` or `dark`: the control shows that mode selected and disables the other two items, without touching the stored preference, which comes back when the lock goes. `all` locks nothing. Unset, the control follows the active theme: a theme that can be used in one mode only (`pref-theme-scheme-light` or `-dark` on `<html>`, written by `mds-pref-theme` from the mode the theme declares, #1274) locks it the same way. Not meant to be set directly. |
| `mode` | `mode` | `"dark" \| "light" \| "system" \| undefined` | - | Specifies the preference mode |
| `size` | `size` | `"md" \| "sm" \| undefined` | - | Sets the size of the component items nested inside it |
| `transition` | `transition` | `"flash" \| "none" \| "smooth"` | `'smooth'` | Specifies the transition of switching from a mode to another one |

## Events

| Event | Detail | Description |
| --- | --- | --- |
| `mdsPrefChange` | `MdsPrefChangeEventDetail` | Emits when the component is triggered |

## CSS custom properties

| Property | Description |
| --- | --- |
| `--mds-pref-mode-overlay-z-index` | Sets the z-index of the overlay which hides UI color flash on theme change |

Only these are public. Its other 2 are internal: they may change in any release, do not set them.

## Dependencies

Uses: `mds-text`, `mds-tab`, `mds-tab-item`.
