Line icons in five sizes (12 / 14 / 16 / 18 / 20, 16 by default); pass a token name for the color. Valid names are the keys of ICONS (IconName). Use IconBadge for leading type indicators. For icon buttons use IconButton, which requires a name.
Status: stable · Components: Icon, IconBadge
Import
Section titled “Import”import { Icon, IconBadge } from 'nacre'An icon next to text is decorative: give it no accessibilityLabel, and screen readers read only the text.
import { Text, View } from 'nsh'import { Icon, TEXT_SIZE } from 'nacre'
export function IconUsage() { return ( <View class="flex-row items-center gap-1.5"> <Icon name="bell" size={14} color="muted-foreground" /> <Text class={`${TEXT_SIZE.small} text-foreground`}>New message alerts</Text> </View> )}Examples
Section titled “Examples”Type badges
Section titled “Type badges”Use 32pt badges for notifications, 24pt for transfer targets, and 36pt for qualifications. The small round version also accepts a custom icon renderer. Supply a label when the badge conveys meaning on its own.
import { View } from 'nsh'import { Icon, IconBadge } from 'nacre'
export function IconBadges() { return ( <View class="flex-row items-center gap-2"> <IconBadge testID="icon-badge-alert" tone="warning" icon="warning" label="Alert" /> <IconBadge testID="icon-badge-target" round size="sm" icon={(state) => <Icon name="user" size={state.size} color={state.color} />} /> <IconBadge testID="icon-badge-certificate" size="lg" icon="building" /> </View> )}Use only 12 / 14 / 16 / 18 / 20. Use 14 inline with small text and 16 with body text.
import { Text, View } from 'nsh'import { Icon, TEXT_SIZE } from 'nacre'
export function IconSizes() { return ( <View class="flex-row items-end gap-4"> {[12, 14, 16, 18, 20].map((size) => ( <View class="items-center gap-1.5"> <Icon name="bell" size={size} color="foreground" /> <Text class={`${TEXT_SIZE.caption} text-muted-foreground tabular-nums`}>{String(size)}</Text> </View> ))} </View> )}Colors
Section titled “Colors”color takes a color token name from theme.json (SVGs are colored with tintColor, which text-* classes don’t reach); status icons use status colors, with text next to them that says it plainly.
import { Text, View } from 'nsh'import { Icon, TEXT_SIZE } from 'nacre'
export function IconColors() { return ( <View class="gap-2"> <View class="flex-row items-center gap-1.5"> <Icon name="warning" size={16} color="warning" /> <Text class={`${TEXT_SIZE.small} text-foreground`}>Queued for over 5 minutes</Text> </View> <View class="flex-row items-center gap-1.5"> <Icon name="circle-x" size={16} color="destructive-text" /> <Text class={`${TEXT_SIZE.small} text-foreground`}>Failed to send</Text> </View> <View class="flex-row items-center gap-1.5"> <Icon name="check" size={16} color="success-text" /> <Text class={`${TEXT_SIZE.small} text-foreground`}>Resolved</Text> </View> <View class="flex-row items-center gap-1.5"> <Icon name="info" size={16} color="muted-foreground" /> <Text class={`${TEXT_SIZE.small} text-muted-foreground`}>The customer left the chat</Text> </View> </View> )}All icons
Section titled “All icons”Every name available in ICONS; hover to see the full name.
Phone: Every name available in ICONS, written under each icon.
import { Text, View } from 'nsh'import { ICONS, Icon, textTooltip, TEXT_SIZE } from 'nacre'import type { IconName } from 'nacre'
export function IconCatalog() { const names = Object.keys(ICONS) as IconName[] return ( <View class="gap-3"> <Text class={`${TEXT_SIZE.small} text-muted-foreground`}>{`$All icons (${names.length}$)`}</Text> <View class="flex-row flex-wrap gap-2"> <Each of={names}> {(name) => ( <View class="w-[104px] h-16 items-center justify-center gap-1.5 rounded-lg bg-plane" tooltip={textTooltip(name())}> <Icon name={name()} size={18} color="foreground" /> <Text class={`max-w-[96px] truncate ${TEXT_SIZE.caption} text-muted-foreground`}>{name()}</Text> </View> )} </Each> </View> </View> )}Accessibility
Section titled “Accessibility”- Not in the accessibility tree by default (decorative); pass accessibilityLabel only when the icon carries meaning on its own, and then it is read.
- Don’t wrap Icon in a button to make it clickable; use IconButton (label required, also used as the tooltip).
Do / Don’t
Section titled “Do / Don’t”Do
- Use only 12 / 14 / 16 / 18 / 20
- Pair status icons with status color tokens
- Write colors as token names (muted-foreground, warning…)
Don’t
- Rely on an icon alone to carry a meaning instead of text
- Tint icons with the brand color as decoration
- Color icons with text-* classes (it has no effect)
Property descriptions follow the Chinese source comments.
| Prop | Type | Default | Description |
|---|---|---|---|
name * |
IconName |
— | |
size |
number |
16 |
|
color |
ColorToken |
'foreground' |
SVG 用 tintColor 着色,text-* 类管不到图片,所以颜色走 token 名 |
class |
string |
— | |
accessibilityLabel |
string |
— |
* required
IconBadge
Section titled “IconBadge”| Prop | Type | Default | Description |
|---|---|---|---|
icon * |
IconName | IconRender |
— | |
tone |
IconBadgeTone |
'neutral' |
|
size |
'sm' | 'md' | 'lg' |
'md' |
sm 是 24pt 底座和 14pt 图标,md / lg 分别是 32 / 36pt 底座与 16pt 图标 |
round |
boolean |
— | |
label |
string |
— | 与文字并排时作装饰;独立表达含义时给读屏名 |
class |
string |
— | |
testID |
string |
— |
* required