# Icon

Flux uses the excellent Heroicons project for its icon collection. Heroicons is a set of beautiful and functional icons crafted by the fine folks at [Tailwind Labs](https://tailwindcss.com)

```tsx
import { BoltIcon } from '@fluxui-dev/react/icons';

<BoltIcon />
```

## Variants

There are four variants for each icon: `outline` (default), `solid`, `mini`, and `micro`.

```tsx
<BoltIcon />                  {/* 24px, outline */}
<BoltIcon variant="solid" />  {/* 24px, filled */}
<BoltIcon variant="mini" />   {/* 20px, filled */}
<BoltIcon variant="micro" />  {/* 16px, filled */}
```

## Sizes

Control the size (height/width) of an icon using the `size-*` Tailwind utility.

```tsx
<BoltIcon className="size-12" />
<BoltIcon className="size-10" />
<BoltIcon className="size-8" />
```

## Color

You can customize the color of an icon using Tailwind's [text color utilities](https://tailwindcss.com/docs/text-color)

```tsx
<BoltIcon variant="solid" className="text-amber-500 dark:text-amber-300" />
```

## Loading spinner

Flux has a special loading spinner icon that isn't part of the Heroicons collection. You can use this special icon anywhere you would normally use a standard icon.

```tsx
import { LoadingIcon } from '@fluxui-dev/react/icons';

<LoadingIcon />
```

## Dynamic icons

If you need to dynamically set an icon, you can use the `Icon` component and pass in the icon component as a prop.

```tsx
import { Icon } from '@fluxui-dev/react';

<Icon icon={BoltIcon} />
```

## Lucide icons

We love Heroicons, but we acknowledge that it's a fairly limited icon set. If you need more icons, we recommend using [Lucide](https://lucide.dev/) instead.

```shell
npm install lucide-react
```

Pass any `lucide-react` icon to a Flux `icon` prop or to `Icon`, and Flux will size it for the variant (24px for `outline`, 20px for `mini`, 16px for `micro`) and adjust its stroke width.

```tsx
import { Crown, Github, GripVertical } from 'lucide-react';

<Icon icon={Crown} />
<Icon icon={GripVertical} />
<Icon icon={Github} />
```

## Custom icons

For full control over your icons, you can create your own icon components. You can simply render SVG code directly, however we recommend using the following template structure to ensure compatibility with other components:

```tsx
import type { ComponentPropsWithRef } from 'react';

export function WinkIcon({ className, ...props }: ComponentPropsWithRef<'svg'>) {
    return (
        <svg
            className={`shrink-0 [:where(&)]:size-6 ${className ?? ''}`}
            data-flux-icon=""
            aria-hidden="true"
            viewBox="0 0 24 24"
            fill="none"
            stroke="currentColor"
            strokeWidth={2}
            {...props}
        >
            {/* Your SVG paths here */}
        </svg>
    );
}
```

```tsx
<WinkIcon />
```

## Reference

### Named icons

All icon components (e.g., `BoltIcon`, `LoadingIcon`) share the same props and behavior.

**Prop:**

- `variant` - Visual style of the icon. Options: `outline` (default), `solid`, `mini`, `micro`.
- `...props` - Any other SVG prop (such as `aria-label` or `style`) and `ref` are forwarded to the `svg` element.

**Class:**

- `size-*` - Control the size of the icon using Tailwind's size utilities (e.g., `size-8`, `size-12`).
- `text-*` - Control the color of the icon using Tailwind's text color utilities (e.g., `text-blue-500`).

**Attribute:**

- `data-flux-icon` - Applied to the root SVG element for styling and identification.

### Icon

**Prop:**

- `icon` - Icon component to render, such as `BoltIcon` from `@fluxui-dev/react/icons` or an icon from `lucide-react`. Required.
- `variant` - Visual style and size of the icon; Flux icons render the matching variant, while other icons receive that variant's size. Options: `outline`, `solid`, `mini`, `micro`. Default: `outline`.
- `className` - Additional classes applied to the `svg` element, such as size or color utilities. `Icon` accepts no other props.

### Icon sizes

**Size:**

- `outline` - 24x24 pixels (default)
- `solid` - 24x24 pixels
- `mini` - 20x20 pixels
- `micro` - 16x16 pixels
