A small square-cornered label for status and markers: dot for status, text for category markers, soft for a fully tinted tag, and outline / dashed for small actions in a tag row. It can be pressable, selectable and removable. Use the rounded Pill for people and groups.
Status: stable · Components: Tag
Import
Section titled “Import”import { Tag } from 'nacre'import { View } from 'nsh'import { Tag } from 'nacre'
export function TagUsage() { return ( <View class="flex-row items-center gap-2"> <Tag variant="dot" tone="success" label="Resolved" /> <Tag tone="warning" label="Major" /> <Tag variant="soft" tone="info" label="System notice" /> </View> )}Examples
Section titled “Examples”Variants
Section titled “Variants”dot is a light gray fill with a colored dot; color lands only on the dot, so a status looks the same in lists and details. text is a light gray fill with status-colored text; soft is a faint status-colored fill; outline is “+N / Show less”, and also a static marker on a gray or selected fill (text’s light gray fill disappears on a fill of the same color); dashed is “+ Add tag”, or marks something missing (a language a knowledge-base article lacks). sm 18 (default) goes inline, md 20 in tables and details.
Phone: On phones read-only tags are 20 (sm) / 24 (md) with radius 5; pressable and removable tags are 32 pills with a 44 tap area. dot, text, soft, outline and dashed are used as on desktop.
import { View } from 'nsh'import { Tag } from 'nacre'
export function TagVariants() { return ( <View class="gap-3"> <View class="flex-row flex-wrap items-center gap-2"> <Tag variant="dot" tone="warning" label="In progress" /> <Tag variant="text" label="Not logged in" /> <Tag variant="soft" tone="destructive" label="Timed out" /> <Tag variant="outline" label="+3" /> <Tag variant="dashed" icon="plus" label="Add tag" /> </View> <View class="flex-row flex-wrap items-center gap-2"> <Tag variant="dot" tone="warning" size="md" label="In progress" /> <Tag testID="demo-dot-uncolored" variant="dot-plain" size="md" label="Unspecified" /> <Tag testID="demo-dot-plain" variant="dot-plain" tone="warning" size="md" label="Awaiting authorization" /> <Tag variant="text" size="md" label="Not logged in" /> <Tag variant="soft" tone="destructive" size="md" label="Timed out" /> </View> </View> )}Six tones: neutral / success / warning / destructive / info / brand. quiet is for “default values” (like a regular case) and takes no fill. icon goes before the text.
import { View } from 'nsh'import { Tag } from 'nacre'
export function TagTones() { return ( <View class="gap-3"> <View class="flex-row flex-wrap items-center gap-2"> <Tag variant="dot" tone="neutral" label="Unassigned" /> <Tag variant="dot" tone="success" label="Completed" /> <Tag variant="dot" tone="warning" label="In progress" /> <Tag variant="dot" tone="destructive" label="Timed out" /> <Tag variant="dot" tone="info" label="Transferred" /> <Tag variant="dot" tone="brand" label="AI" /> </View> <View class="flex-row flex-wrap items-center gap-2"> <Tag tone="quiet" label="Regular" /> <Tag tone="warning" label="Major" /> <Tag tone="destructive" label="Severe" /> <Tag tone="info" label="Inquiry" /> </View> <View class="flex-row flex-wrap items-center gap-2"> <Tag variant="soft" tone="success" label="Configured" /> <Tag variant="soft" tone="warning" icon="warning" label="Missing callback URL" /> <Tag variant="soft" tone="info" label="System notice" /> <Tag variant="soft" tone="brand" label="AI suggestion" /> </View> </View> )}Pressable and expandable
Section titled “Pressable and expandable”With onPress the tag is pressable (a QA tag jumps to its entry) and darkens one step on hover; tags that control expansion, like “+N / Show less”, pass expanded.
Phone: With onPress it is tappable (a QA tag jumps to its entry) and darkens on press; tags that expand or collapse (“+N / Less”) pass expanded.
import { Text, View, signal } from 'nsh'import { Tag, TEXT_SIZE } from 'nacre'
export function TagPressable() { const located = signal(0) const more = signal(false) return ( <View class="flex-row flex-wrap items-center gap-2"> <Tag testID="tag-press" tone="destructive" label="AI error · No apology" onPress={() => located.update((n) => n + 1)} /> <Tag variant="soft" tone="warning" label="Live hits 2" onPress={() => located.update((n) => n + 1)} /> <Tag testID="tag-more" variant="outline" label={more() ? 'Show less' : '+3'} expanded={more()} onPress={() => more.update((v) => !v)} /> <Text class={`${TEXT_SIZE.caption} text-muted-foreground tabular-nums`}>{`$Located ${located()}$ times`}</Text> </View> )}Selectable, removable, add
Section titled “Selectable, removable, add”Note tags: selected changes the fill and adds a checkmark at the end; unselected tags get a remove button via onRemove. The checkmark and remove button share one slot, so the width doesn’t change when toggling. A dashed tag at the end adds a tag. After a removal, removeRef hands the focus to a neighboring tag’s remove button, so the keyboard can keep removing.
import { Text, View, signal } from 'nsh'import type { ViewRef } from 'nsh'import { Tag, TEXT_SIZE } from 'nacre'
export function TagSelectable() { const words = signal(['Call back', 'Escalated to tier 2', 'Docs pending', 'VIP', 'Complaint risk']) const picked = signal(['Call back']) const toggle = (word: string) => picked.update((list) => (list.includes(word) ? list.filter((w) => w !== word) : [...list, word])) const removeButtons = new Map<string, ViewRef>() /** 删掉后焦点交给后面(没有就前面)最近一个可删标签的删除钮,键盘连删不丢焦点 */ const remove = (word: string) => { const index = words().indexOf(word) const rest = words().filter((w) => w !== word) const removable = (w: string) => !picked().includes(w) const next = rest.slice(index).find(removable) ?? rest.slice(0, index).reverse().find(removable) removeButtons.delete(word) words.set(rest) if (next !== undefined) removeButtons.get(next)?.focus() } const add = () => { const word = 'New tag' words.update((list) => (list.includes(word) ? list : [...list, word])) } return ( <View class="w-[360px] max-w-full gap-2"> <View class="flex-row flex-wrap items-center gap-1"> <Each of={words()} key={(word) => word}> {(word) => ( <Tag testID={`tag-pick-${word()}`} label={word()} selected={picked().includes(word())} onPress={() => toggle(word())} onRemove={picked().includes(word()) ? undefined : () => remove(word())} removeRef={(node) => removeButtons.set(word(), node)} /> )} </Each> <Tag testID="tag-add" variant="dashed" icon="plus" label="Add tag" onPress={add} /> </View> <Text class={`${TEXT_SIZE.caption} text-muted-foreground`}>{`$Selected: ${picked().join(', ') || 'None'} · $${words().length}$ total`}</Text> </View> )}Keyboard
Section titled “Keyboard”| Key | Action |
|---|---|
| Tab | Focus a pressable tag; on a removable tag, the remove button is a separate stop |
| Space / Return | Press (toggle selection, expand); on a remove button, remove the tag and move the focus where removeRef points |
Accessibility
Section titled “Accessibility”- Use dot-plain for unboxed enum values and authorization states. Without a tone it renders text alone. Agent presence is a different status.
- Only pressable tags are buttons, with label as the accessible name; static tags are just text.
- A selectable / removable tag is not a single button: the text part is a button, and the remove button is a separate button beside it, named “Delete” by default (change it with removeLabel).
- selected announces the selected state and expanded the expanded state; selection adds a checkmark instead of relying on color alone.
Do / Don’t
Section titled “Do / Don’t”Do
- Use dot for status, text for markers, soft for emphasis
- Show a checkmark on selected tags
- Give statuses in one column the same look and size
Don’t
- Use color as the only distinction
- Use Tag for people, skills or groups (use Pill)
- Use Tag as an ordinary button
Property descriptions follow the Chinese source comments.
| Prop | Type | Default | Description |
|---|---|---|---|
label * |
string |
— | |
tone |
TagTone |
'neutral' |
|
variant |
TagVariant |
'text' |
|
size |
'sm' | 'md' |
— | sm 18 高 11pt(行内标记,默认);md 20 高 12pt(表格与详情里的状态) |
icon |
IconName |
— | 文字前的小图标(11pt) |
truncate |
boolean |
— | 放不下时截断,悬停看全文;默认保持原宽 |
tooltip |
string |
— | 悬停提示;truncate 时默认是 label |
onPress |
() => void |
— | 可点(质检标签定位到条目):悬停加深一档 |
selected |
boolean |
— | 可选的标签(备注标签):选中换 selected-tint 底、正文色字,行尾 16 宽的槽里放勾(非颜色指示,不改字重); 和 onRemove 共用这个槽,未选中可删、选中打勾时宽度不变 |
expanded |
boolean |
— | 控制展开的标签(「+N / 收起」)报给读屏的展开态 |
onRemove |
() => void |
— | 给了就在行尾放 16 的删除钮(2xs IconButton);testID 落在标签本体上,删除钮是 ${testID}-remove |
removeLabel |
string |
— | 删除钮的无障碍名与提示,默认「删除」 |
removeRef |
(node: ViewRef) => void |
— | 删除钮的节点:删掉一个后把焦点交给相邻标签的删除钮(或输入框),键盘连删不丢焦点 |
testID |
string |
— | |
class |
string |
— | 根节点的布局类 |
* required