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

# mds-icon

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

The `<mds-icon>` web component is the single glyph primitive of the Magma Design System: it inlines an SVG into the DOM so the artwork inherits color and sizing from CSS, and it is the building block that nearly every other component (button, chip, input, banner, list-item, etc.) composes to render its iconography. It replaces a raw `<img>`/`<svg>` tag and centralizes how icon artwork is resolved.

#### Semantic Behavior

- **Decorative by default**: The icon contributes no accessible name; meaning must come from the surrounding labelled control or text.
- **Source resolution**: `name` is interpreted three ways - a string starting with `data:image/svg+xml;base64,` is decoded inline (as UTF-8; a payload that is not base64 draws nothing and logs a console warning), a markup string starting with the `<svg` element, or with the XML declaration, doctype or comments a saved `.svg` file opens with, is used verbatim, and anything else is treated as an icon filename slug fetched as `<svg directory><slug>.svg` (a name starting with `http` is fetched as it is). Without a `name` (attribute missing or empty, property `undefined` or `null`) the icon renders nothing, sends no request and logs nothing; removing `name` clears the icon.
- **Async load**: When `name` is a slug the icon paints once the SVG arrives; a failed fetch renders empty rather than throwing. Only the latest `name` and SVG path count: a request that finishes after a newer one is discarded.
- **Path configuration**: The SVG directory is set programmatically via the shared `IconsSetService.setSvgPath()` singleton (imported from `@maggioli-design-system/magma`), with the `mdsIconSvgPath` `sessionStorage` key as an optional fallback and the `setSvgPath` instance method as an alternative; icons that mounted before the path was configured reload themselves once it is set. An icon removed from the page stops listening for path changes; once it is put back it picks up a path set in the meantime.

#### Properties & Visual Configurations

- **`name`** is the only configurable input and is overloaded: pass an icon filename slug to pull artwork from the shared library, a base64-encoded SVG `data:` URI for inline/dynamic artwork, or a full raw SVG string when the markup is generated at runtime.

This component does not use the shared `variant` / `tone` / `size` ladders defined in [`agents/variants.md`](../../../../agents/variants.md); the color comes from the inherited CSS `fill` and the size from the host `width` (24px by default, the height follows the square aspect ratio), which is how parent components tint and scale their icons.

## 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/design-icon--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 |
| --- | --- | --- | --- | --- |
| `name` | `name` | `string` | - | **Required**. The name of the icon or a base64 string to render it as an svg |

## Methods

| Method | Signature | Description |
| --- | --- | --- |
| `setSvgPath` | `setSvgPath(svgPath: string) => Promise<void>` | Set the path to the directory of svg files |

## Parts

| Part | Description |
| --- | --- |
| `svg` | The svg container of the icon |

## Dependencies

Used by: `mds-avatar`, `mds-banner`, `mds-button`, `mds-chip`, `mds-file`, `mds-file-preview`, `mds-filter-item`, `mds-help`, `mds-img`, `mds-input`, `mds-input-field`, `mds-input-select`, `mds-input-switch`, `mds-input-upload`, `mds-keyboard-key`, `mds-kpi-item`, `mds-link`, `mds-list-item`, `mds-mention`, `mds-paginator-item`, `mds-policy-ai`, `mds-radial-progress`, `mds-stepper-bar-item`, `mds-tab-bar-item`, `mds-url-view`, `mds-usage`.
