# Icon (/docs/native/components/icon)

<Preview id="icon/the-size-scale" title={null} />

## Installation [#installation]

<ComponentInstall name="icon" />

## Usage [#usage]

```tsx title="app/index.tsx"
import { Icon } from "@/components/ui/icon";
import { IconHeart } from "@/lib/icons/central";
import { View } from "react-native";

export default function Example() {
  return (
    <View className="flex-1 items-center justify-center p-4">
      <Icon icon={IconHeart} />
    </View>
  );
}
```

## Sizes [#sizes]

`xs` 14, `sm` 16, `md` 18, `lg` 20, `xl` 24, `2xl` 32 — the shared icon scale, which `Spinner`
reads too.

<Preview id="icon/the-size-scale" />

```tsx
<Icon icon={IconHeart} size="sm" />
<Icon icon={IconHeart} size={22} />
```

A named step is a class; a number bypasses the class chain entirely. The precedence ladder is in
[Sizing](/docs/native/getting-started/sizing#precedence-weakest-first), and the full guide to the
set is [Icons](/docs/native/getting-started/icons).

## Colour [#colour]

<Preview id="icon/colour-is-a-token" />

```tsx
<Icon icon={IconHeart} color="destructive" />
<Icon icon={IconHeart} color="#EC4899" />
```

## Inherited defaults [#inherited-defaults]

A bare `<Icon>` takes its size and colour from the nearest provider.

<Preview id="icon/inherited-from-a-button" />

```tsx
import { IconDefaultsProvider } from "@delacour/react-native-ui/icon";

<IconDefaultsProvider value={{ className: "size-icon-lg", color: "muted-foreground" }}>
  {children}
</IconDefaultsProvider>;
```

## A subtree of defaults [#a-subtree-of-defaults]

```tsx
<IconDefaultsProvider value={{ className: "size-icon-2xl", color: "primary" }}>
  <Icon icon={IconHeart} />
  <Icon color="destructive" icon={IconBell} />
</IconDefaultsProvider>
```

`Button`, `Badge` and `ListGroup.ItemPrefix` all publish into this, so a bare `<Icon>` inside one
needs nothing at the call site. An explicit `size` or `color` still wins.

## API Reference [#api-reference]

### IconProps [#iconprops]

Extends `SvgProps`, minus `color`, `width` and `height`.

<TypeTable
  type={{
    icon: {
      type: "IconComponent",
      required: true,
      description: "A Central Icons glyph, imported from @delacour/react-native-ui/icons/central.",
    },
    size: {
      type: '"xs" | "sm" | "md" | "lg" | "xl" | "2xl" | number',
      description: "A named step is a class; a number bypasses the class chain entirely.",
    },
    color: {
      type: "string",
      description: "A theme token name (destructive, muted-foreground) or a literal (#EC4899).",
    },
    className: {
      type: "string",
      description: "Use size-*, not w-* with h-*: tailwind-merge conflicts size into w/h but not the reverse.",
    },
  }}
/>

### Exports [#exports]

```tsx
import {
  Icon,
  type IconProps,
  type IconComponent,
  IconDefaultsProvider,
  useIconDefaults,
  ICON_SIZES,
  ICON_FALLBACK_COLOR,
  ICON_FALLBACK_SIZE_CLASS,
  iconVariants,
  isIconSize,
  resolveIconSizeClass,
} from "@delacour/react-native-ui/icon";
```
