An icon-only button for toolbars, rows and the composer. label is required and serves as both the screen reader name and the tooltip; actions with text use Button.
Status: stable · Components: IconButton
Import
Section titled “Import”import { IconButton } from 'nacre'import { Text, View, signal } from 'nsh'import { IconButton, TEXT_SIZE } from 'nacre'
export function IconButtonUsage() { const copied = signal(false) return ( <View class="flex-row items-center gap-2"> <IconButton icon="copy" label="Copy" onPress={() => copied.set(true)} /> <Text class={`${TEXT_SIZE.small} text-muted-foreground`}>{copied() ? 'Copied to clipboard' : 'Click the icon to copy the message'}</Text> </View> )}Examples
Section titled “Examples”Variants
Section titled “Variants”ghost has no fill (the default), for toolbars and rows; primary is a solid brand fill, only for primary actions like Send; secondary is a light gray fill; round makes it circular (the composer’s + and Send). Use float for toggles over images.
import { View } from 'nsh'import { IconButton } from 'nacre'
export function IconButtonVariants() { return ( <View class="flex-row flex-wrap items-center gap-2"> <IconButton icon="copy" label="Copy" /> <IconButton icon="more" label="More" /> <IconButton icon="send" label="Send" variant="primary" /> <IconButton icon="plus" label="Add" variant="secondary" round /> </View> )}States
Section titled “States”Toggles use pressed to show they’re on, and also pass expanded when they open or close a panel; disabled and loading both block presses, and loading swaps the icon for a spinner; dot is an indicator in the top-right corner (new results to see), with no number.
import { View, signal } from 'nsh'import { IconButton } from 'nacre'
export function IconButtonStates() { const open = signal(false) return ( <View class="flex-row flex-wrap items-center gap-2"> <IconButton icon="sidebar-right" label="Hide right panel" pressed={open()} expanded={open()} onPress={() => open.update((v) => !v)} /> <IconButton icon="download" label="Download" disabled /> <IconButton icon="refresh" label="Refresh" loading /> <IconButton icon="export" label="Export records" dot /> </View> )}xs 24 / sm 28 (default) / md 32 / lg 36, width equal to height, following the control-h-* structure tokens; clear and copy buttons inside a line of small text use 2xs 16 (with the hit area padded to 24).
import { View } from 'nsh'import { IconButton } from 'nacre'
export function IconButtonSizes() { return ( <View class="flex-row flex-wrap items-center gap-2"> <IconButton size="xs" icon="download" label="Download" /> <IconButton size="sm" icon="download" label="Download" /> <IconButton size="md" icon="download" label="Download" /> <IconButton size="lg" icon="download" label="Download" /> </View> )}Surfaces
Section titled “Surfaces”surface says which layer it sits on (ghost only): inverse goes on a solid primary fill (a reminder bubble), with the icon and focus ring in primary-foreground; media sits over any image (a thumbnail’s remove button), a round translucent dark fill that holds up on any picture, with a 10pt icon at 2xs. Use chrome on the title bar.
import { Text, View } from 'nsh'import { IconButton, TEXT_SIZE } from 'nacre'
export function IconButtonSurfaces() { return ( <View class="flex-row flex-wrap items-center gap-4"> <View class="flex-row items-center gap-1 h-7 pl-2.5 pr-1 rounded-md bg-primary"> <Text class={`${TEXT_SIZE.small} text-primary-foreground`}>Remember to invite a rating</Text> <IconButton surface="inverse" size="xs" icon="close" label="Close" /> </View> <View class="w-16 h-16 rounded-lg bg-secondary overflow-hidden"> <View class="absolute inset-0 bg-primary/40" /> <IconButton surface="media" size="2xs" icon="close" label="Remove image" class="absolute top-1 right-1" /> </View> </View> )}Custom icon
Section titled “Custom icon”icon can also be a render function: the button hands it the size and color to use (following the size, surface and pressed state), for the app’s own icon set (keypad, backspace).
import { Text, View, signal, token } from 'nsh'import { IconButton, TEXT_SIZE } from 'nacre'import type { ColorToken } from 'nacre'
export function IconButtonCustomIcon() { const open = signal(false) const glyph = (state: { size: number; color: ColorToken }) => ( <View class="gap-px" style={{ width: state.size, height: state.size }}> <Each of={[0, 1, 2]}> {() => ( <View class="flex-1 flex-row gap-px"> <Each of={[0, 1, 2]}>{() => <View class="flex-1 rounded-full" style={{ backgroundColor: token(state.color) }} />}</Each> </View> )} </Each> </View> ) return ( <View class="flex-row items-center gap-4"> <IconButton icon={glyph} label="Keypad" pressed={open()} expanded={open()} onPress={() => open.update((v) => !v)} /> <View class="flex-row items-center gap-1 h-7 pl-2.5 pr-1 rounded-md bg-primary"> <Text class={`${TEXT_SIZE.small} text-primary-foreground`}>Keypad</Text> <IconButton surface="inverse" size="xs" icon={glyph} label="Keypad" /> </View> </View> )}Tooltip with a shortcut
Section titled “Tooltip with a shortcut”shortcut sits to the right of the tooltip text, one step lighter; don’t put the shortcut in label. While the menu it opens is showing, pass tooltip={null} to hide the tooltip.
Phone: Phones show no shortcut; label is the screen reader name.
import { View } from 'nsh'import { IconButton } from 'nacre'
export function IconButtonShortcut() { return ( <View class="flex-row items-center gap-2"> <IconButton icon="search" label="Search chats" shortcut="⌘K" /> <IconButton icon="sidebar-left" label="Hide sidebar" shortcut="⌃⌘S" /> </View> )}Keyboard
Section titled “Keyboard”| Key | Action |
|---|---|
| Tab | Focus and show the focus ring (not in the Tab order with focusable={false}) |
| Space / Return | Press |
Accessibility
Section titled “Accessibility”- The role is button and the screen reader name is label; the tooltip also defaults to label.
- pressed is exposed as the pressed state; when expanded is passed, it also reads expanded / collapsed.
- Disabled and loading buttons can’t be pressed.
Do / Don’t
Section titled “Do / Don’t”Do
- Name the action in label (“Hide right panel”, “Copy”)
- Use pressed for toggles to show they’re on
- Use one size for every button in a toolbar
- On a primary fill or over an image, change surface instead of colors in class
Don’t
- Use an icon button for primary actions (use Button)
- Put the shortcut in label
- Use dot to show a count (use Badge)
Property descriptions follow the Chinese source comments.
IconButton
Section titled “IconButton”| Prop | Type | Default | Description |
|---|---|---|---|
icon * |
IconName | IconRender |
— | 库图标名,或自带图标的渲染函数(应用自己的图标集,拿到尺寸与颜色) |
label * |
string |
— | 无障碍名,同时作为悬停提示 |
tooltip |
TooltipContent | null |
— | 悬停提示,默认同 label(需要带快捷键时单独给);null 不显示(它打开的菜单开着时,FINDINGS 49) |
shortcut |
string | null |
— | 快捷键(⌃⌘S),在悬停提示里排在文案右侧、淡一档;不要拼进 label / tooltip |
pressed |
boolean |
— | 按下 / 打开态:底色常亮、图标变 foreground;切换时图标 0.8 → 1 弹一下(MOTION.toggle,确认生效) |
pressedIcon |
IconName |
— | 开态换的图标(收藏 star → star-filled、置顶):开关类图标钮开态用实心,不只靠换色(component-standard §15 D9) |
expanded |
boolean |
— | 控制展开的按钮(侧栏开合、右栏开合)报给读屏的展开态 |
disabled |
boolean |
— | |
loading |
boolean |
— | 进行中:图标换成转圈,不可再点(刷新) |
iconColor |
ColorToken |
— | |
onPress |
(event: PressEvent) => void |
— | 带按下事件(读修饰键:⌥ 点击) |
testID |
string |
— | |
dot |
boolean |
— | 右上角 6pt 的 brand 提示点(有新结果待看,如导出完成);不带数字,数字用 Badge |
size |
'2xs' | 'xs' | 'sm' | 'md' | 'lg' |
'sm' |
2xs / xs / sm(默认)/ md / lg:桌面 16 / 24 / 28 / 32 / 36,手机 20 / 32 / 44 / 48 / 52。手机小图标按钮向外补足 44pt 点击区 |
focusable |
boolean |
— | 不进 Tab 顺序(工具栏里由方向键走的项、悬停才出现的钮) |
viewRef |
(node: ViewRef) => void |
— | |
onFocus |
() => void |
— | |
onBlur |
() => void |
— | |
variant |
'ghost' | 'primary' | 'secondary' | 'float' |
'ghost' |
ghost 无底(默认);primary 主色实底(发送);secondary 浅灰实底;float 浮在内容上(图片两侧切换),不透明底 + 浮层投影 |
round |
boolean |
— | 圆形(输入区的 +、Copilot 发送),默认圆角方形 |
class |
string |
— | 根节点的布局类(外边距、self),不改颜色 |
surface |
'card' | 'chrome' | 'inverse' | 'media' |
— | 放在哪一层(只对 ghost 生效):card 白卡与浮层(hover-tint / selected-tint,默认);chrome 窗口材质上(标题栏,chrome-*); inverse 主色实底上(提醒气泡),图标与焦点环取 primary-foreground; media 叠在任意图片上(缩略图的移除钮),圆形半透明深底压住各种图,深色模式反过来 |
* required