Data displayIcon
Searchastronomic.dev# Icon
For a small icon next to a label or in a list, at one of three sizes, with the same line weight everywhere.
Static: no JavaScript.
## Usage
```astro
import Icon from "@astronomic-dev/ui/components/Icon.astro";
```
## Examples
### Sizes and a label
One icon at sm, md and lg, with the same line weight at every size, and one with a label. The icons are from Lucide (@lucide/astro); any icon component fits, or an inline <svg> in the slot. A preset sets the weight with --ui-icon-stroke (default 1.75px).
```astro
---
import Icon from "@astronomic-dev/ui/components/Icon.astro";
// Any icon component fits: Lucide's (@lucide/astro), your own SVG component, or another set.
import Check from "@lucide/astro/icons/check";
import Compass from "@lucide/astro/icons/compass";
---
<div class="flex flex-wrap items-center gap-6">
<Icon icon={Compass} size="sm" />
<Icon icon={Compass} />
<Icon icon={Compass} size="lg" class="text-accent" />
<span class="inline-flex items-center gap-2 text-muted">
<Icon icon={Check} label="Included" class="text-accent" />
Monthly updates
</span>
</div>
```
## Props
### Icon
| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `icon` | `IconComponent` | None | An icon component: Lucide's (@lucide/astro), your own SVG component, or another. It gets aria-hidden="true". Wins over the default slot. |
| `size` | `"sm" \| "md" \| "lg"` | `"md"` | 1rem, 1.25rem or 1.5rem. The line weight stays the same. |
| `label` | `string` | None | What the icon means, when nothing next to it says so. Without it, the icon is decoration. |
| `class` | `string` | None | More classes, merged with cn(), so yours win on conflicts: a color such as text-accent, or a size class such as size-8. |
| Slot | Description |
| --- | --- |
| `default` | An inline <svg>, used when there is no icon prop. It fills the icon's box. |
No other attributes: Icon renders one <span> around the svg.
## Accessibility
- Decorative by default: without label the icon is hidden from screen readers (aria-hidden="true"), as it should be when a word next to it says the same thing.
- Give label when the icon is the only thing that says what it means: the icon is then an image (role img) named by label, and its svg is hidden.
- Color comes from the text color (currentColor), so an icon in text-muted or text-accent keeps that text's contrast.
- Every shape is drawn at the one line weight (--ui-icon-stroke): an icon whose shapes set different stroke widths loses that difference.
Icon
FreeFor a small icon next to a label or in a list, at one of three sizes, with the same line weight everywhere.
- File
- Icon.astro
- Group
- Data display
- Kind
- Static: no JavaScript
- Examples
- 1
Examples
Drag the orange handle to set the width. Frames get real breakpoints.
- Static
- Interactive
- Framed
Sizes and a label
One icon at sm, md and lg, with the same line weight at every size, and one with a label. The icons are from Lucide (@lucide/astro); any icon component fits, or an inline <svg> in the slot. A preset sets the weight with --ui-icon-stroke (default 1.75px).
Monthly updates
Force statemain.astro
examples/icon/main.astro
---
import Icon from "@astronomic-dev/ui/components/Icon.astro";
// Any icon component fits: Lucide's (@lucide/astro), your own SVG component, or another set.
import Check from "@lucide/astro/icons/check";
import Compass from "@lucide/astro/icons/compass";
---
<div class="flex flex-wrap items-center gap-6">
<Icon icon={Compass} size="sm" />
<Icon icon={Compass} />
<Icon icon={Compass} size="lg" class="text-accent" />
<span class="inline-flex items-center gap-2 text-muted">
<Icon icon={Check} label="Included" class="text-accent" />
Monthly updates
</span>
</div>Minimal · Light