# Icon

SVG icon from a path on a 24×24 viewBox, for example from `@mdi/js`. It inherits color and size from the surrounding text (`--icon-size` and `--icon-color` change them). Without `title` it is decorative and hidden from screen readers. It is not clickable: for a clickable icon use `Button` with `buttonType="text"`, `icon` and `aria-label`.

```ts
import { Icon } from '@likable-hair/svelte';
```

Category: simple. Source: `src/lib/components/simple/media/Icon.svelte`.

## Examples

### Basic

The icon takes an SVG path (24×24 viewBox), for example from `@mdi/js`. It inherits color and size from the surrounding text; without `title` it is decorative.

```svelte
<script lang="ts">
	import { mdiCalendarOutline, mdiHeart, mdiMagnify } from '@mdi/js';
	import { Icon } from '@likable-hair/svelte';
</script>

<Icon path={mdiMagnify} />
<Icon path={mdiCalendarOutline} --icon-size="32px" />
<Icon path={mdiHeart} title="Favorite" --icon-size="32px" --icon-color="var(--global-color-error)" />
```

### Clickable icon

Icon is only an image. For a clickable icon use `Button` with `buttonType="text"`: focus, keyboard, hover and `disabled` work correctly. Without text it needs an `aria-label`.

```svelte
<script lang="ts">
	import { mdiClose, mdiPencilOutline, mdiTrashCanOutline } from '@mdi/js';
	import { Button } from '@likable-hair/svelte';
</script>

<Button buttonType="text" variant="secondary" icon={mdiClose} aria-label="Close" />
<Button buttonType="text" icon={mdiPencilOutline} aria-label="Edit" />
<Button buttonType="text" variant="danger" icon={mdiTrashCanOutline} aria-label="Delete" />
<Button buttonType="text" variant="secondary" size="sm" icon={mdiClose} aria-label="Close" disabled />
```

## Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `path` (required) | `string` |  | SVG path on a 24×24 viewBox, for example from `@mdi/js` (`import { mdiPlus } from '@mdi/js'`). |
| `title` | `string` |  | Accessible name. Without it the icon is decorative and hidden from screen readers. |
| `class` | `string` | `''` | Extra classes on the `<svg>` element. |

## CSS variables

For a single instance, pass them as style props: `<Icon --icon-color="tomato">`. The `--icon-default-*` defaults apply to the whole app: override them in `:root` or in a theme.

| Per-instance variable | Default |
| --- | --- |
| `--icon-size` | `--icon-default-size`: `1em` |
| `--icon-color` | `--icon-default-color`: `currentColor` |
