Skip to content

Kbd

键帽。把键名画成符号,组合键用 _ 连起来。

Installation

pnpm dlx @weme-ui/weme-ui add kbd

Usage

K
Vueexamples/usage.vueExpand codeHide code
<script lang="ts" setup>
import Kbd from '../kbd.vue'
</script>

<template>
  <div class="flex gap-3 items-center">
    <Kbd value="meta_k" />
  </div>
</template>

Examples

Variants

↵↵
Vueexamples/variants.vueExpand codeHide code
<script lang="ts" setup>
import Kbd from '../kbd.vue'
</script>

<template>
  <div class="flex gap-3 items-center">
    <Kbd value="enter" />
    <Kbd value="enter" variant="plain" />
  </div>
</template>

Sizes

⇧⇧⇧
Vueexamples/sizes.vueExpand codeHide code
<script lang="ts" setup>
import Kbd from '../kbd.vue'

const sizes = ['sm', 'md', 'lg'] as const
</script>

<template>
  <div class="flex gap-3 items-center">
    <Kbd v-for="size in sizes" :key="size" :size="size" value="shift" />
  </div>
</template>

Props

PropTypeDefault
asAsTag | Component'kbd'
根节点渲染为的元素或组件(Reka UI Primitive)
AsTag | Component
'kbd'
asChildbooleanfalse
合并到子元素上渲染(Reka UI composition)
boolean
false
valueKbdKey | KbdKey[] | string | string[]-
单个键、键数组,或用 _ 分开的组合。不在 kbdKeysMap 里的键会转成大写
KbdKey | KbdKey[] | string | string[]
-
variant'soft' | 'plain''soft'
表面
'soft' | 'plain'
'soft'
size'sm' | 'md' | 'lg''md'
尺寸
'sm' | 'md' | 'lg'
'md'
classany-
额外 class
any
-

kbdKeysMap

键名到符号。meta、ctrl、alt 在表里是空字符串,挂载后按系统填:macOS 分别是 ⌘、⌃、⌥,其它系统是 Ctrl、Ctrl、Alt。

FieldDescription
meta—
—
ctrl—
—
alt—
—
win⊞
⊞
command⌘
⌘
shift⇧
⇧
control⌃
⌃
option⌥
⌥
enter↵
↵
delete⌦
⌦
backspace⌫
⌫
escape⎋
⎋
tab⇥
⇥
capsLock⇪
⇪
arrowUp↑
↑
arrowRight→
→
arrowDown↓
↓
arrowLeft←
←
pageup⇞
⇞
pagedown⇟
⇟
home↖
↖
end↘
↘

Files

  • src/components/kbd/kbd.vue
  • src/components/kbd/kbd.props.ts
  • src/components/kbd/kbd.style.ts