iter(g237): 新增 kbd 键盘按键标记,键帽样式支持单键与组合键(74 组件)

This commit is contained in:
HIsheR
2026-10-26 21:30:52 +08:00
parent 55980c5ec1
commit fc8c5ad776
12 changed files with 129 additions and 10 deletions
+1
View File
@@ -73,3 +73,4 @@ export { timePicker } from './timePicker.js';
export { pinInput } from './pinInput.js';
export { copyButton } from './copyButton.js';
export { countdown } from './countdown.js';
export { kbd } from './kbd.js';
+10
View File
@@ -0,0 +1,10 @@
import { h } from '@ui-arch/frame';
import type { KbdProps } from './types.js';
/*** 键盘按键标记:键帽样式展示单个按键或组合键(多键以 + 连接),用于快捷键提示 ***/
export function kbd(props: KbdProps): HTMLElement {
const keys = Array.isArray(props.keys) ? props.keys : [props.keys]; // 统一成数组:单键 / 组合键同一渲染路径
const parts: (Node | null)[] = keys.map((k, i) => (i > 0 ? h('span', { class: 'ua-kbd-sep', 'aria-hidden': 'true' }, '+') : null)); // 分隔符占位
keys.forEach((k, i) => parts[i * 2 + 1] = h('kbd', { class: 'ua-kbd-key' }, k)); // 键帽交错插入:sep, key, sep, key…
return h('span', { class: 'ua-kbd' }, ...parts);
}
+5
View File
@@ -281,6 +281,11 @@ export interface CountdownHandle {
reset: () => void; // 复位到总时长并停表
}
/*** 键盘按键入参 ***/
export interface KbdProps {
keys: string | string[]; // 按键内容:单键字符串或多键组合数组(组合以 + 连接展示)
}
/*** 空状态入参 ***/
export interface EmptyProps {
title?: string; // 主标题;缺省不渲染