145a208687
HD-04 scope, against heroui ce90ea3 cn sources: - stale/fictional content: input.md no longer claims TextField is unmigrated; color-field.md no longer claims ColorPicker is private; header.md drops the fictional Header.Root subcomponent and the stale 'menus not migrated' wording (MenuSection label registration is now documented from HeaderRoot source); radio-group.md drops three copied CheckboxGroup wordings (variant override is Radio's, scalar emits, native single-value submit); input-otp.md drops the fictional data-complete state and lists the real missing upstream props - toggle-button disabled row now matches the real CSS hooks (:disabled / [aria-disabled], with data-disabled as a marker only) - part API / CSS classes / interactive states restored per pinned sources: button (full class lists + real variable-based global CSS), accordion (per-part tables + variant/state lists), card (per-part tables + variant list), switch (SwitchGroup snippet + Switch/ SwitchGroup class lists + states), color-field Group (class list + states), input-otp (variant notes, global CSS, class/state lists); input-group gains the two upstream usage chapters - RelatedComponents restored from the pinned componentRelationships (first-3, filtered against componentsMap): 64 pages rewritten, list-box/slider sections added, 7 empty-mapping pages' fabricated entries removed; RelatedShowcases left unmigrated with its real data inventory recorded (2 cases, showcase-site cards) - defaults unified on implementation evidence: granularity (inferred day/minute) and visibleYears (full min-max span, no "or 20" fallback); HD-03 hand-offs resolved (trigger focus-visible noted for HD-06, width guards kept) - new demos: header-collection-grouping (MenuSection/ListBoxSection label wiring), empty-state-collection (collection empty slot); empty-state page deduplicated with a boundary compatibility note - ComponentPreview minHeight/isBgSolid restored per the 30 upstream marks; tabs-overflow max-w-full kept after measuring internal scroll - tests: +3 header registration/demo cases, +1 empty-state collection case; full suite 110 files / 1630 tests, typecheck and build:docs pass
139 lines
4.3 KiB
Markdown
139 lines
4.3 KiB
Markdown
---
|
||
title: Kbd 键盘按键
|
||
description: 展示键盘快捷键与按键组合
|
||
component: kbd
|
||
group: 组件
|
||
---
|
||
|
||
## 用法
|
||
|
||
```vue
|
||
<script setup lang="ts">
|
||
import { Kbd, KbdAbbr, KbdContent } from "@heroui-vue/components";
|
||
</script>
|
||
```
|
||
|
||
<ComponentPreview name="kbd-basic" />
|
||
|
||
## 组件结构
|
||
|
||
```vue
|
||
<script setup lang="ts">
|
||
import { Kbd, KbdAbbr, KbdContent } from "@heroui-vue/components";
|
||
</script>
|
||
|
||
<template>
|
||
<Kbd>
|
||
<KbdAbbr key-value="command" />
|
||
<KbdContent>K</KbdContent>
|
||
</Kbd>
|
||
</template>
|
||
```
|
||
|
||
`KbdAbbr` 根据 `keyValue` 显示按键符号,并自动设置无障碍 `title`。`KbdContent` 包裹按键字母或文本。
|
||
|
||
## 示例
|
||
|
||
### 变体
|
||
|
||
<ComponentPreview name="kbd-variants" />
|
||
|
||
### 导航按键
|
||
|
||
<ComponentPreview name="kbd-navigation-keys" />
|
||
|
||
### 行内用法
|
||
|
||
<ComponentPreview name="kbd-inline-usage" />
|
||
|
||
### 说明文字
|
||
|
||
<ComponentPreview name="kbd-instructional-text" />
|
||
|
||
### 特殊按键
|
||
|
||
<ComponentPreview name="kbd-special-keys" />
|
||
|
||
## 自定义样式
|
||
|
||
### Tailwind CSS
|
||
|
||
<ComponentPreview name="kbd-custom-styles" />
|
||
|
||
### 全局 CSS
|
||
|
||
可使用 `@layer components` 指令自定义 Kbd 组件类。
|
||
|
||
```css
|
||
@layer components {
|
||
.hv-kbd {
|
||
@apply bg-gray-100 dark:bg-gray-800 border-gray-300;
|
||
}
|
||
|
||
.hv-kbd__abbr {
|
||
@apply font-bold;
|
||
}
|
||
|
||
.hv-kbd__content {
|
||
@apply text-sm;
|
||
}
|
||
}
|
||
```
|
||
|
||
## 样式参考
|
||
|
||
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。
|
||
|
||
### CSS 类
|
||
|
||
Kbd 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/kbd.css)):
|
||
|
||
#### 基础类 [!toc]
|
||
|
||
- `.hv-kbd` - 基础按键样式,含背景、边框与间距
|
||
- `.hv-kbd__abbr` - 修饰键的缩写元素
|
||
- `.hv-kbd__content` - 按键文本的内容包裹层
|
||
|
||
## API 参考
|
||
|
||
### Kbd
|
||
|
||
| Prop | 类型 | 默认值 | 描述 |
|
||
| --------- | --------------------------- | ----------- | ----------------------------- |
|
||
| `variant` | `'default' \| 'light'` | `'default'` | 按键视觉变体 |
|
||
| 默认插槽 | `Component` | - | 按键内容 |
|
||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||
|
||
### KbdAbbr
|
||
|
||
| Prop | 类型 | 默认值 | 描述 |
|
||
| ---------- | --------------------------- | ------ | --------------------------------------------------------------------------- |
|
||
| `keyValue` | `KbdKey` | - | 要显示的按键;符号与 `title` 由映射表给出(如 `command` → `⌘` / `Command`) |
|
||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||
|
||
### KbdContent
|
||
|
||
| Prop | 类型 | 默认值 | 描述 |
|
||
| -------- | --------------------------- | ------ | ----------------------------- |
|
||
| 默认插槽 | `Component` | - | 按键文本内容 |
|
||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||
|
||
`class` 遵循 Vue 的 class 绑定,可接收字符串、数组和对象,并与对应 slot 的基础类合并;不要使用 React 的 `className`。
|
||
|
||
### KbdContent Type
|
||
|
||
`keyValue` prop 可用的按键值:
|
||
|
||
| Modifier Keys | Special Keys | Navigation Keys | Function Keys |
|
||
| ------------- | ------------ | --------------- | ------------- |
|
||
| `command` | `enter` | `up` | `fn` |
|
||
| `shift` | `delete` | `down` | |
|
||
| `ctrl` | `escape` | `left` | |
|
||
| `option` | `tab` | `right` | |
|
||
| `alt` | `space` | `pageup` | |
|
||
| `win` | `capslock` | `pagedown` | |
|
||
| | `help` | `home` | |
|
||
| | | `end` | |
|
||
|
||
上游文档表格曾写作 `Kbd.Key` 与 `title`/`children`;实际实现与全部演示使用 `KbdAbbr` 的 `keyValue` 与 `KbdContent`。本库按实现迁移,并同时导出 `kbdKeysMap`、`kbdKeysLabelMap` 与 `KbdKey` 类型。
|