feat: add Separator Kbd and Chip components

This commit is contained in:
maoyingjie
2026-10-21 18:35:24 +08:00
parent 3d05fea7bd
commit 3515a47f5e
51 changed files with 2813 additions and 21 deletions
+26
View File
@@ -0,0 +1,26 @@
<script setup lang="ts">
import { computed, provide, useAttrs } from "vue";
import { kbdVariants, type KbdVariants } from "@heroui-vue/styles";
import { kbdContextKey } from "./context";
defineOptions({ inheritAttrs: false });
const props = withDefaults(
defineProps<{
variant?: KbdVariants["variant"];
}>(),
{ variant: "default" },
);
const attrs = useAttrs();
const slots = computed(() => kbdVariants({ variant: props.variant }));
provide(kbdContextKey, { slots });
</script>
<template>
<kbd v-bind="attrs" :class="slots.base()">
<slot />
</kbd>
</template>
@@ -0,0 +1,25 @@
<script setup lang="ts">
import { inject, useAttrs } from "vue";
import { kbdContextKey } from "./context";
import { kbdKeysLabelMap, kbdKeysMap, type KbdKey } from "./constants";
defineOptions({ inheritAttrs: false });
const props = defineProps<{
/** The keyboard key to display. */
keyValue: KbdKey;
}>();
const attrs = useAttrs();
const ctx = inject(kbdContextKey, undefined);
</script>
<template>
<abbr
v-bind="attrs"
:class="ctx?.slots.value.abbr()"
:title="kbdKeysLabelMap[props.keyValue]"
>
{{ kbdKeysMap[props.keyValue] }}
</abbr>
</template>
@@ -0,0 +1,15 @@
<script setup lang="ts">
import { inject, useAttrs } from "vue";
import { kbdContextKey } from "./context";
defineOptions({ inheritAttrs: false });
const attrs = useAttrs();
const ctx = inject(kbdContextKey, undefined);
</script>
<template>
<span v-bind="attrs" :class="ctx?.slots.value.content()">
<slot />
</span>
</template>
@@ -0,0 +1,76 @@
/** Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
* See third-party/HEROUI-LICENSE. */
export type KbdKey =
| "command"
| "shift"
| "ctrl"
| "option"
| "enter"
| "delete"
| "escape"
| "tab"
| "capslock"
| "up"
| "right"
| "down"
| "left"
| "pageup"
| "pagedown"
| "home"
| "end"
| "help"
| "space"
| "fn"
| "win"
| "alt";
export const kbdKeysMap: Record<KbdKey, string> = {
command: "⌘",
shift: "⇧",
ctrl: "⌃",
option: "⌥",
enter: "↵",
delete: "⌫",
escape: "⎋",
tab: "⇥",
capslock: "⇪",
up: "↑",
right: "→",
down: "↓",
left: "←",
pageup: "⇞",
pagedown: "⇟",
home: "↖",
end: "↘",
help: "?",
space: "␣",
fn: "Fn",
win: "⌘",
alt: "⌥",
};
export const kbdKeysLabelMap: Record<KbdKey, string> = {
command: "Command",
shift: "Shift",
ctrl: "Control",
option: "Option",
enter: "Enter",
delete: "Delete",
escape: "Escape",
tab: "Tab",
capslock: "Caps Lock",
up: "Up",
right: "Right",
down: "Down",
left: "Left",
pageup: "Page Up",
pagedown: "Page Down",
home: "Home",
end: "End",
help: "Help",
space: "Space",
fn: "Fn",
win: "Win",
alt: "Alt",
};
@@ -0,0 +1,11 @@
import type { ComputedRef, InjectionKey } from "vue";
import type { KbdVariants, kbdVariants } from "@heroui-vue/styles";
export type KbdSlots = ReturnType<typeof kbdVariants>;
export interface KbdContextValue {
slots: ComputedRef<KbdSlots>;
}
export const kbdContextKey: InjectionKey<KbdContextValue> =
Symbol("HeroUIVue.Kbd");