Kbd
一个显示键盘按键的kbd元素。
用法
使用默认插槽设置Kbd的值。
K
<template>
<UKbd>K</UKbd>
</template>值
使用value prop设置Kbd的值。
K
<template>
<UKbd value="K" />
</template>您可以将特殊密钥传递给value prop,该prop通过useKbd组合。例如,meta密钥在macOS上显示为⌘,在其他平台上显示为Ctrl。
<template>
<UKbd value="meta" />
</template>Color
使用color道具更改Kbd的颜色。
K
<template>
<UKbd color="neutral">K</UKbd>
</template>Variant
使用variant prop更改Kbd的变体。
K
<template>
<UKbd color="neutral" variant="solid">K</UKbd>
</template>Size
使用size属性更改Kbd的大小。
K
<template>
<UKbd size="lg">K</UKbd>
</template>示例
class道具
使用class道具覆盖徽章的基本样式。
K
<template>
<UKbd class="font-bold rounded-full" variant="subtle">K</UKbd>
</template>API
Props
| Prop | Default | Type |
|---|---|---|
as | 'kbd' | anyThe element or component this component should render as. |
value | string | |
color | 'neutral' | "primary" | "secondary" | "success" | "info" | "warning" | "error" | "neutral" |
variant | 'outline' | "outline" | "soft" | "subtle" | "solid" |
size | 'md' | "sm" | "md" | "lg" |
ui | { base?: any; } |
Slots
| Slot | Type |
|---|---|
default | {} |
Theme
app.config.ts
export default defineAppConfig({
ui: {
kbd: {
base: 'inline-flex items-center justify-center px-1 rounded-sm font-medium font-sans uppercase',
variants: {
color: {
primary: '',
secondary: '',
success: '',
info: '',
warning: '',
error: '',
neutral: ''
},
variant: {
solid: '',
outline: '',
soft: '',
subtle: ''
},
size: {
sm: 'h-4 min-w-[16px] text-[10px]',
md: 'h-5 min-w-[20px] text-[11px]',
lg: 'h-6 min-w-[24px] text-[12px]'
}
},
compoundVariants: [
{
color: 'primary',
variant: 'solid',
class: 'text-inverted bg-primary'
},
{
color: 'primary',
variant: 'outline',
class: 'ring ring-inset ring-primary/50 text-primary'
},
{
color: 'primary',
variant: 'soft',
class: 'text-primary bg-primary/10'
},
{
color: 'primary',
variant: 'subtle',
class: 'text-primary ring ring-inset ring-primary/25 bg-primary/10'
},
{
color: 'neutral',
variant: 'solid',
class: 'text-inverted bg-inverted'
},
{
color: 'neutral',
variant: 'outline',
class: 'ring ring-inset ring-accented text-default bg-default'
},
{
color: 'neutral',
variant: 'soft',
class: 'text-default bg-elevated'
},
{
color: 'neutral',
variant: 'subtle',
class: 'ring ring-inset ring-accented text-default bg-elevated'
}
],
defaultVariants: {
variant: 'outline',
color: 'neutral',
size: 'md'
}
}
}
})vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nuxt/ui/vite'
export default defineConfig({
plugins: [
vue(),
ui({
ui: {
kbd: {
base: 'inline-flex items-center justify-center px-1 rounded-sm font-medium font-sans uppercase',
variants: {
color: {
primary: '',
secondary: '',
success: '',
info: '',
warning: '',
error: '',
neutral: ''
},
variant: {
solid: '',
outline: '',
soft: '',
subtle: ''
},
size: {
sm: 'h-4 min-w-[16px] text-[10px]',
md: 'h-5 min-w-[20px] text-[11px]',
lg: 'h-6 min-w-[24px] text-[12px]'
}
},
compoundVariants: [
{
color: 'primary',
variant: 'solid',
class: 'text-inverted bg-primary'
},
{
color: 'primary',
variant: 'outline',
class: 'ring ring-inset ring-primary/50 text-primary'
},
{
color: 'primary',
variant: 'soft',
class: 'text-primary bg-primary/10'
},
{
color: 'primary',
variant: 'subtle',
class: 'text-primary ring ring-inset ring-primary/25 bg-primary/10'
},
{
color: 'neutral',
variant: 'solid',
class: 'text-inverted bg-inverted'
},
{
color: 'neutral',
variant: 'outline',
class: 'ring ring-inset ring-accented text-default bg-default'
},
{
color: 'neutral',
variant: 'soft',
class: 'text-default bg-elevated'
},
{
color: 'neutral',
variant: 'subtle',
class: 'ring ring-inset ring-accented text-default bg-elevated'
}
],
defaultVariants: {
variant: 'outline',
color: 'neutral',
size: 'md'
}
}
}
})
]
})Changelog
No recent changes