Skip to main content

Icon

Sizes and colours any icon so it lines up with the text beside it.

import { Icon } from "@/fragments/ui";Source

Preview

<Icon icon={Heart} />

Installation

npx @usefragments/cli add icon

Writes src/fragments/ui/components/Icon plus what it imports, the globals stylesheet, and .fragments/registry-lock.json, then prints the packages to add. No account, no key.

Your own registry: publish from Fragments Cloud and add --registry org/name. Connect a workspace.

Examples

Sizes

Steps tuned to the type scale, so icons never float off the baseline.

<div style={{ display: 'flex', gap: '12px', alignItems: 'center' }}>
  <Icon icon={Star} size="xs" />
  <Icon icon={Star} size="sm" />
  <Icon icon={Star} size="md" />
  <Icon icon={Star} size="lg" />
  <Icon icon={Star} size="xl" />

Tones

Tone states carry meaning — never use them for decoration.

<div style={{ display: 'flex', gap: '12px', alignItems: 'center' }}>
  <Icon icon={Check} tone="success" />
  <Icon icon={Warning} tone="warning" />
  <Icon icon={Warning} tone="danger" />
  <Icon icon={Info} tone="accent" />
</div>

Hierarchy

The text colour ladder, for glyphs that sit beside secondary or tertiary copy.

<div style={{ display: 'flex', gap: '12px', alignItems: 'center' }}>
  <Icon icon={Heart} color="primary" />
  <Icon icon={Heart} color="secondary" />
  <Icon icon={Heart} color="tertiary" />
</div>

Weights

Match the stroke to the text weight next to it.

<div style={{ display: 'flex', gap: '12px', alignItems: 'center' }}>
  <Icon icon={Heart} weight="thin" />
  <Icon icon={Heart} weight="light" />
  <Icon icon={Heart} weight="regular" />
  <Icon icon={Heart} weight="bold" />
  <Icon icon={Heart} weight="fill" />

Advanced Icon Props

iconProps passes anything the underlying icon package supports.

<Icon icon={Heart} iconProps={{ mirrored: true }} />

API

Component props
Prop
Type
Default
Description
styleobjectNot set
iconRequiredunionNot setIcon component to render
sizeenumxssmmdlgxlmdIcon size
weightstringthinlightregularboldfillduotoneregularOptional icon style/weight hint (forwarded when supported by the icon component)
toneenumaccentinfosuccesswarningdangerNot setSemantic colour. Reserve success, warning and danger for real state; omit to inherit currentColor
colorenumprimarysecondarytertiaryNot setText-hierarchy colour, the same axis as Text color. tone wins when both are set
iconPropsobjectNot setAdditional props forwarded to the underlying icon component (typed from the icon prop in TypeScript)

Accessibility

  • Icons ship aria-hidden — they are decoration until you label them
  • An icon-only button needs VisuallyHidden text
  • Color alone never carries the message

Guidance

Use when

  • A symbol sits beside text, inside a button, or leads a list item
  • State needs a glanceable marker

Avoid when

  • Artwork or illustration (use Image)
  • Multi-color or animated graphics
  • ButtonchildUse inside icon-only buttons with VisuallyHidden label
  • VisuallyHiddensiblingPair with VisuallyHidden for accessible icon-only elements
  • BadgechildCan be used as badge icon prop

Next steps