# Icon

Renders an SVG glyph from the kit's icon registry at `1em` in the current text color. The kit ships the glyphs its own components need; register your own with `provideVigdxIcons`.

- Package: [@vigdx/ui](https://www.npmjs.com/package/@vigdx/ui)
- Selectors: `vig-icon`
- Source: [libs/ui/src/lib/atoms/icon/icon.ts](https://github.com/bakyurekk/vigdx/blob/main/libs/ui/src/lib/atoms/icon/icon.ts)

```typescript title="Import"
import { Icon, provideVigdxIcons } from '@vigdx/ui/icon';
```

## Default icons

Every glyph in `VIG_DEFAULT_ICONS`, the built-in set the kit's components use. Pass its key as `name`.

```typescript title="icon-gallery.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Icon, VIG_DEFAULT_ICONS } from '@vigdx/ui/icon';

@Component({
  selector: 'app-icon-gallery',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Icon],
  template: `
    <ul class="grid grid-cols-[repeat(auto-fill,minmax(7.5rem,1fr))] gap-2">
      @for (name of names; track name) {
        <li
          class="flex flex-col items-center gap-2 rounded-card border border-border-subtle px-2 py-3 text-foreground"
        >
          <vig-icon [name]="name" class="text-2xl" />
          <code class="text-xs text-muted-foreground">{{ name }}</code>
        </li>
      }
    </ul>
  `,
})
export class IconGalleryDemo {
  protected readonly names = Object.keys(VIG_DEFAULT_ICONS);
}
```

## Size and color

An icon is `1em` square and stroked with `currentColor`: size it with a font-size class and color it with a text color. `strokeWidth` makes a single glyph bolder or lighter.

```typescript title="icon-sizing.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Icon } from '@vigdx/ui/icon';

@Component({
  selector: 'app-icon-sizing',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Icon],
  template: `
    <div class="flex flex-col gap-5">
      <div class="flex flex-wrap items-end gap-5 text-foreground">
        <vig-icon name="calendar" class="text-sm" />
        <vig-icon name="calendar" class="text-base" />
        <vig-icon name="calendar" class="text-xl" />
        <vig-icon name="calendar" class="text-3xl" />
        <vig-icon name="calendar" class="text-5xl" />
      </div>
      <div class="flex flex-wrap items-center gap-5 text-2xl">
        <vig-icon name="info" class="text-info" />
        <vig-icon name="success" class="text-success" />
        <vig-icon name="warning" class="text-warning" />
        <vig-icon name="error" class="text-error" />
        <vig-icon name="check" class="text-primary" [strokeWidth]="3" />
      </div>
      <p class="text-sm text-foreground">
        <vig-icon name="upload" /> Inline icons sit on the text baseline and follow its size.
      </p>
    </div>
  `,
})
export class IconSizingDemo {}
```

## Meaningful icons

Icons are decorative by default. When an icon carries information that no nearby text gives, pass an `ariaLabel`; next to a text label, leave it decorative.

```typescript title="icon-labelled.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Icon } from '@vigdx/ui/icon';

@Component({
  selector: 'app-icon-labelled',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Icon],
  template: `
    <dl class="grid grid-cols-[auto_1fr] items-center gap-x-4 gap-y-3 text-sm text-foreground">
      <dt>Two-factor login</dt>
      <dd><vig-icon name="success" class="text-lg text-success" ariaLabel="Enabled" /></dd>
      <dt>Recovery email</dt>
      <dd><vig-icon name="warning" class="text-lg text-warning" ariaLabel="Not verified" /></dd>
      <dt>Backup codes</dt>
      <dd class="flex items-center gap-1.5 text-error">
        <vig-icon name="error" class="text-lg" /> Not generated
      </dd>
    </dl>
  `,
})
export class IconLabelledDemo {}
```

## Custom icons

`provideVigdxIcons` merges glyphs into the registry by name, adding new ones or overriding built-ins. An `IconDefinition` is SVG path data on a 24×24 `viewBox`; outline by default, filled with `fill: 'currentColor'`.

```typescript title="icon-custom.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Button, ButtonIcon } from '@vigdx/ui/button';
import { Icon, provideVigdxIcons } from '@vigdx/ui/icon';

@Component({
  selector: 'app-icon-custom',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Button, ButtonIcon, Icon],
  // In an app, register icons once in app.config.ts; here they are scoped to this demo.
  providers: [
    provideVigdxIcons({
      pencil: { paths: ['M17 3a2.8 2.8 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z', 'm15 5 4 4'] },
      trash: {
        paths: [
          'M3 6h18',
          'M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6',
          'M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2',
        ],
      },
      star: {
        fill: 'currentColor',
        strokeWidth: 1,
        paths: ['m12 2 3.1 6.3 6.9 1-5 4.9 1.2 6.8L12 17.8 5.8 21l1.2-6.8-5-4.9 6.9-1Z'],
      },
    }),
  ],
  template: `
    <div class="flex flex-wrap items-center gap-3">
      <vig-icon name="star" class="text-2xl text-warning" ariaLabel="Favorite" />
      <vig-button label="Edit" variant="secondary">
        <vig-icon vigButtonIcon name="pencil" />
      </vig-button>
      <vig-button label="Delete" variant="error" appearance="outlined">
        <vig-icon vigButtonIcon name="trash" />
      </vig-button>
    </div>
  `,
})
export class IconCustomDemo {}
```

## Styling hooks

Internal elements carry a stable `data-part` and the component's `data-scope`; both are public API, so removing one is a breaking change. Select a part by both, e.g. `[data-scope="icon"][data-part="svg"] { … }`: the pair stays within this component when kit components nest, and also reaches parts in overlay panels, which render outside the host. State is exposed through `aria-*` and, where listed, a `data-state`; literal values are checked by the API gate, values computed from the component's state follow its documented types. Other `data-*` attributes listed below (such as `data-opening` while an overlay animates) are API too. See [Customizing](https://vigdx.com/docs/theming.md#customizing).

Scope: `[data-scope="icon"]`

| Part | Element | data-state |
| --- | --- | --- |
| `svg` | The inline `<svg>`. |   |

## Accessibility

- By default the icon is `aria-hidden="true"` and its SVG is not focusable, so screen readers skip it.
- With `ariaLabel` the icon becomes `role="img"` with that name. Use it only when the icon is the sole carrier of the information.
- Icon-only controls get their name from the control, not the icon: pass `ariaLabel` to the button and keep the icon decorative.
- Meaningful icons need a 3:1 contrast against their background (WCAG 1.4.11); never use color alone to tell states apart.
- Glyphs are path data rendered by Angular bindings, not HTML strings, so no `innerHTML` or sanitizer bypass is involved.

## API

### Icon

Selector: `vig-icon` · Kind: component

Renders a registered icon at 1em in the current text color. Decorative by default (hidden from assistive tech); pass `ariaLabel` for a meaningful one. Size it with the font size, e.g. `class="text-[1.25em]"`.

#### Inputs

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `ariaLabel` | `string \| undefined` | `undefined` | Accessible name; when set the icon is exposed as `role="img"`. |
| `name` (required) | `string` | — | Name of a registered icon (see `VIG_DEFAULT_ICONS` and `provideVigdxIcons`). |
| `strokeWidth` | `number \| undefined` | `undefined` | Per-instance stroke width override, e.g. a bolder check inside a small box. |
