跳转到内容
Nacre
组件配色
EN

键帽 Kbd

stableKbd在画廊运行
Kbd
在浏览器里运行真实组件。

在提示、帮助与空态里显示快捷键:高 20、最小宽 20 的灰底键帽。图标钮与菜单项的快捷键用它们自己的 shortcut,不要手拼。

状态:stable · 组件:Kbd

import { Kbd } from 'nacre'
import { Kbd } from 'nacre'
export function KbdUsage() {
return <Kbd>⌘K</Kbd>
}

一个组合写在一枚键帽里,修饰键按 macOS 顺序 ⌃⌥⇧⌘ 排在前面;单键写名字(Esc、Return)。

import { View } from 'nsh'
import { Kbd } from 'nacre'
export function KbdKeys() {
return (
<View class="flex-row items-center gap-2">
<Kbd>⌘K</Kbd>
<Kbd>⇧⌘E</Kbd>
<Kbd>⌃⌘S</Kbd>
<Kbd>Esc</Kbd>
<Kbd>Return</Kbd>
</View>
)
}

帮助与空态里的说明句,键帽和文字同一行、居中对齐。

import { Text, View } from 'nsh'
import { Kbd, TEXT_SIZE } from 'nacre'
export function KbdInline() {
return (
<View class="gap-2">
<View class="flex-row items-center gap-1.5">
<Text class={`${TEXT_SIZE.small} text-muted-foreground`}>按</Text>
<Kbd>⌘K</Kbd>
<Text class={`${TEXT_SIZE.small} text-muted-foreground`}>搜索会话</Text>
</View>
<View class="flex-row items-center gap-1.5">
<Text class={`${TEXT_SIZE.small} text-muted-foreground`}>按</Text>
<Kbd>Esc</Kbd>
<Text class={`${TEXT_SIZE.small} text-muted-foreground`}>关闭预览</Text>
</View>
</View>
)
}

放在已有半透明填充的控件里(搜索入口)时用 bare,免得不透明的灰底成为最亮的一块。

import { Text, View } from 'nsh'
import { Icon, Kbd, TEXT_SIZE } from 'nacre'
export function KbdBare() {
return (
<View class="w-[240px] max-w-full h-7 flex-row items-center gap-1.5 px-2 rounded-md bg-fill-subtle">
<Icon name="search" size={14} color="muted-foreground" />
<Text class={`flex-1 ${TEXT_SIZE.small} text-muted-foreground`}>搜索会话</Text>
<Kbd bare>⌘K</Kbd>
</View>
)
}
  • 键帽是普通文字,读屏按字符念;说明句要把动作写成文字(「按 ⌘K 搜索会话」)。

该用

  • 用 macOS 符号(⌘ ⇧ ⌥ ⌃)
  • 一个组合一枚键帽
  • 图标钮、菜单项用各自的 shortcut 属性

不该用

  • 把快捷键拼进按钮文字
  • 把每个修饰键拆成单独的键帽
属性 类型 默认 说明
children * string —
testID string —
bare boolean —

* 必填