Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

feat(ui): optically balanced Kbd glyphs, unified pills, and canonical macOS order (MUL-9797) (#11148)

Jiayuan Zhang28acda90033e
diff --git a/AGENTS.md b/AGENTS.md
index 59d173724d..32c39a332f 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -120,7 +120,7 @@ Workspace-scoped queries filter by `workspace_id`; membership gates access and `
- For Button and Dialog usage, read `packages/ui/docs/button.md` and `packages/ui/docs/dialog.md`.
- Prefer existing shadcn/Base UI primitives. Add components with `pnpm ui:add <component>`.
- For `pnpm ui:add @reui/<name>`, decline overwrite prompts. Keep `REUI_LICENSE_KEY` in the environment, never in repo files. Adapt vendored primitives into `packages/ui/components/ui/` and compositions into `packages/views/`.
-- Import icons from `@multica/ui/icons`; no icon library is installed. If the icon you need is missing, draw it by following `.agents/skills/multica-icons/SKILL.md`. Do not substitute an inline SVG or an emoji. Rewrite icon imports in `ui:add` output before committing.
+- Import icons from `@multica/ui/icons`; no icon library is installed. If the icon you need is missing, draw it by following `.agents/skills/multica-icons/SKILL.md`. Do not substitute an inline SVG or an emoji. Rewrite icon imports in `ui:add` output before committing. Exception: proportional-width optical keycap glyphs live exclusively in `KBD_GLYPHS` inside `packages/ui/components/ui/kbd.tsx` and are only for `<Kbd>`.
- Use shared semantic tokens in `packages/ui/styles/`. Typography uses the role-named `--text-*` scale in `packages/ui/styles/tokens.css`, not Tailwind's default size ramp.
- Selected states remain identifiable on hover. Handle overflow, long text, and scrolling deliberately; avoid unnecessary local state and dividers.
diff --git a/apps/storybook/.storybook/preview.tsx b/apps/storybook/.storybook/preview.tsx
index bc35ee8ff5..784d8bc0ac 100644
--- a/apps/storybook/.storybook/preview.tsx
+++ b/apps/storybook/.storybook/preview.tsx
@@ -57,7 +57,7 @@ const preview: Preview = {
parameters: {
layout: "centered",
options: {
- storySort: { order: ["Comment box", ["Compare all", "*"], "Voice input", ["Composer (A + C)", "Waveform", ["Compare all", "*"], "Settings", "First use", "Edge cases", "Explored", ["All directions", "*"]]] },
+ storySort: { order: ["Kbd", ["Compare all", "Specimen wall", "Real surfaces", "Glyph anatomy", "*"], "Comment box", ["Compare all", "*"], "Voice input", ["Composer (A + C)", "Waveform", ["Compare all", "*"], "Settings", "First use", "Edge cases", "Explored", ["All directions", "*"]]] },
},
controls: { disable: true },
actions: { disable: true },
diff --git a/apps/storybook/src/kbd/kbd-glyphs.tsx b/apps/storybook/src/kbd/kbd-glyphs.tsx
new file mode 100644
index 0000000000..af8c704bfe
--- /dev/null
+++ b/apps/storybook/src/kbd/kbd-glyphs.tsx
@@ -0,0 +1,5 @@
+export {
+ KBD_GLYPHS as OPTICAL_GLYPHS,
+ KbdGlyph as OpticalKbdGlyph,
+ type KbdGlyphName as OpticalGlyphName,
+} from "@multica/ui/components/ui/kbd";
diff --git a/apps/storybook/src/kbd/kbd.stories.tsx b/apps/storybook/src/kbd/kbd.stories.tsx
new file mode 100644
index 0000000000..decacce0e1
--- /dev/null
+++ b/apps/storybook/src/kbd/kbd.stories.tsx
@@ -0,0 +1,936 @@
+import { useState, type CSSProperties, type ReactNode } from "react";
+import type { Meta, StoryObj } from "@storybook/react-vite";
+import {
+ ArrowBigUp,
+ ArrowDown,
+ ArrowLeft,
+ ArrowRight,
+ ArrowRightToLine,
+ ArrowUp,
+ Command,
+ CornerDownLeft,
+ Delete,
+ MessageSquare,
+ Option,
+ PanelLeft,
+ PanelRight,
+ Plus,
+ Search,
+ Space,
+ type IconComponent,
+} from "@multica/ui/icons";
+import { Button } from "@multica/ui/components/ui/button";
+import { cn } from "@multica/ui/lib/utils";
+import type { Lang } from "../voice-input/copy";
+import { useStoryEnv } from "../voice-input/env";
+import { OpticalKbdGlyph, type OpticalGlyphName } from "./kbd-glyphs";
+import {
+ chord,
+ DemoLiteralKbd,
+ DemoShortcutKeycaps,
+ type DemoChord,
+ type DemoPlatform,
+ type DemoSize,
+ type DemoVariant,
+} from "./variants";
+
+const meta = {
+ title: "Kbd",
+ id: "kbd",
+ parameters: { layout: "fullscreen" },
+} satisfies Meta;
+export default meta;
+type Story = StoryObj<typeof meta>;
+
+type VariantMeta = {
+ id: DemoVariant;
+ badge: string;
+ name: Record<Lang, string>;
+ summary: Record<Lang, string>;
+};
+
+const VARIANTS: VariantMeta[] = [
+ {
+ id: "current",
+ badge: "A",
+ name: { zh: "线上现状", en: "Current" },
+ summary: {
+ zh: "24px 通用图标硬缩 12px · Control 裸 Unicode「⌃」· ⌘ 排首位 · 固定高度不随 --font-scale 缩放",
+ en: "24px UI icons shrunk to 12px · raw Unicode ⌃ · ⌘ first · fixed heights ignore --font-scale",
+ },
+ },
+ {
+ id: "quick-win",
+ badge: "B",
+ name: { zh: "Step 1 · Quick Win", en: "Step 1 · Quick Win" },
+ summary: {
+ zh: "修正 ⌃⌥⇧⌘ 顺序 · 开启 OpenType case · em 相对缩放 · 补 ⌃/⌦ 矢量字形 · Space 用文字",
+ en: "Canonical ⌃⌥⇧⌘ order · OpenType case · em scaling · vector ⌃/⌦ · Space text",
+ },
+ },
+ {
+ id: "optical-pill",
+ badge: "C",
+ name: { zh: "Step 2 · 专用字形 + 单胶囊", en: "Step 2 · Optical glyphs + Pill" },
+ summary: {
+ zh: "16px 比例字宽专用键帽字形(对齐 Inter 500 笔宽与 cap-height)· 组合收进单胶囊",
+ en: "16px proportional-width optical glyphs matched to Inter 500 · unified single pill",
+ },
+ },
+ {
+ id: "optical-split",
+ badge: "C′",
+ name: { zh: "Step 2 · 专用字形 + 拆键", en: "Step 2 · Optical glyphs + Split" },
+ summary: {
+ zh: "同一套光学字形,保留一键一帽(适合 Settings 快捷键录制页,或对比单胶囊 vs 拆键)",
+ en: "Same optical glyphs in individual keycaps (for Settings recording or split comparison)",
+ },
+ },
+];
+
+const COMPARE_GROUPS: {
+ title: Record<Lang, string>;
+ items: { label: Record<Lang, string>; shortcut: DemoChord; note?: Record<Lang, string> }[];
+}[] = [
+ {
+ title: { zh: "修饰键顺序与多键组合", en: "Modifier order & multi-modifier chords" },
+ items: [
+ { label: { zh: "打开搜索", en: "Open search" }, shortcut: chord("K", { primary: true }) },
+ {
+ label: { zh: "新建对话", en: "New chat" },
+ shortcut: chord("J", { primary: true, shift: true }),
+ note: { zh: "⌘⇧J → ⇧⌘J", en: "⌘⇧J → ⇧⌘J" },
+ },
+ {
+ label: { zh: "切换全屏", en: "Full screen" },
+ shortcut: chord("F", { control: true, primary: true }),
+ note: { zh: "裸 Unicode ⌃ → 居中矢量", en: "Raw ⌃ → centered vector" },
+ },
+ {
+ label: { zh: "全修饰键", en: "All modifiers" },
+ shortcut: chord("S", { control: true, alt: true, shift: true, primary: true }),
+ note: { zh: "⌃ ⌥ ⇧ ⌘ S 齐平检验", en: "⌃ ⌥ ⇧ ⌘ S alignment check" },
+ },
+ {
+ label: { zh: "强制退出", en: "Force quit" },
+ shortcut: chord("Escape", { alt: true, primary: true }),
+ },
+ ],
+ },
+ {
+ title: { zh: "标点与符号键(OpenType case)", en: "Punctuation & symbol keys (OpenType case)" },
+ items: [
+ { label: { zh: "后退", en: "Go back" }, shortcut: chord("[", { primary: true }) },
+ { label: { zh: "前进", en: "Go forward" }, shortcut: chord("]", { primary: true }) },
+ { label: { zh: "右侧栏", en: "Right sidebar" }, shortcut: chord("/", { primary: true }) },
+ { label: { zh: "设置", en: "Settings" }, shortcut: chord(",", { primary: true }) },
+ { label: { zh: "放大", en: "Zoom in" }, shortcut: chord("Plus", { primary: true }) },
+ { label: { zh: "缩小", en: "Zoom out" }, shortcut: chord("Minus", { primary: true }) },
+ ],
+ },
+ {
+ title: { zh: "功能键与方向键", en: "Action & navigation keys" },
+ items: [
+ { label: { zh: "发送", en: "Send" }, shortcut: chord("Enter", { primary: true }) },
+ { label: { zh: "换行", en: "Newline" }, shortcut: chord("Enter", { shift: true }) },
+ { label: { zh: "按词退格", en: "Delete word" }, shortcut: chord("Backspace", { alt: true }) },
+ {
+ label: { zh: "前向删除", en: "Forward delete" },
+ shortcut: chord("Delete", { alt: true }),
+ note: { zh: "区分 ⌫ 与 ⌦", en: "Distinguishes ⌫ vs ⌦" },
+ },
+ {
+ label: { zh: "按住说话", en: "Push to talk" },
+ shortcut: chord("Space", { alt: true }),
+ note: { zh: "下沉的 ␣ → Space", en: "Low ␣ → Space" },
+ },
+ { label: { zh: "反向缩进", en: "Outdent" }, shortcut: chord("Tab", { shift: true }) },
+ { label: { zh: "向上移动", en: "Move up" }, shortcut: chord("Up", { alt: true }) },
+ { label: { zh: "跳至行首", en: "Line start" }, shortcut: chord("Left", { primary: true }) },
+ ],
+ },
+];
+
+function Segmented<T extends string | number>({
+ label,
+ value,
+ options,
+ onChange,
+}: {
+ label: string;
+ value: T;
+ options: readonly { value: T; label: string }[];
+ onChange: (value: T) => void;
+}) {
+ return (
+ <div className="inline-flex items-center gap-2">
+ <span className="text-caption text-muted-foreground">{label}</span>
+ <div className="inline-flex rounded-md border border-border bg-card p-0.5">
+ {options.map((opt) => (
+ <button
+ key={String(opt.value)}
+ type="button"
+ onClick={() => onChange(opt.value)}
+ className={cn(
+ "rounded-xs px-2 py-0.5 text-caption font-medium transition-colors",
+ value === opt.value
+ ? "bg-surface-selected text-foreground shadow-2xs"
+ : "text-muted-foreground hover:text-foreground",
+ )}
+ >
+ {opt.label}
+ </button>
+ ))}
+ </div>
+ </div>
+ );
+}
+
+function ComparePage() {
+ const { lang } = useStoryEnv();
+ const zh = lang === "zh";
+ const [fontScale, setFontScale] = useState<number>(1);
+ const [size, setSize] = useState<DemoSize>("sm");
+ const [platform, setPlatform] = useState<DemoPlatform>("macos");
+ const [zoom, setZoom] = useState<number>(1);
+
+ return (
+ <div
+ className="min-h-screen bg-background p-10"
+ style={{ "--font-scale": fontScale } as CSSProperties}
+ >
+ <div className="mx-auto max-w-[1280px]">
+ <header className="flex flex-wrap items-end justify-between gap-4">
+ <div className="max-w-2xl">
+ <h1 className="text-title font-semibold">
+ {zh ? "Kbd 光学平衡对比:现状 vs Step 1 vs Step 2" : "Kbd optical balance: Current vs Step 1 vs Step 2"}
+ </h1>
+ <p className="mt-1.5 text-body text-muted-foreground">
+ {zh
+ ? "试着切换 --font-scale 和 2× 放大镜:注意观察 ⌃ 高度、⇧ 胖瘦、Space 居中、⌘[ 基线,以及字号放大后图文是否脱节。"
+ : "Toggle --font-scale and 2× loupe to inspect ⌃ vertical balance, ⇧ proportion, Space centering, ⌘[ baseline, and icon/text scaling."}
+ </p>
+ </div>
+ <div className="flex flex-wrap items-center gap-3">
+ <Segmented
+ label="--font-scale"
+ value={fontScale}
+ onChange={setFontScale}
+ options={[
+ { value: 0.9, label: "0.9×" },
+ { value: 1, label: "1.0×" },
+ { value: 1.15, label: "1.15×" },
+ { value: 1.3, label: "1.3×" },
+ ]}
+ />
+ <Segmented
+ label={zh ? "尺寸" : "Size"}
+ value={size}
+ onChange={setSize}
+ options={[
+ { value: "sm", label: "sm" },
+ { value: "md", label: "md" },
+ ]}
+ />
+ <Segmented
+ label={zh ? "平台" : "Platform"}
+ value={platform}
+ onChange={setPlatform}
+ options={[
+ { value: "macos", label: "macOS" },
+ { value: "windows", label: "Windows" },
+ ]}
+ />
+ <Segmented
+ label={zh ? "放大" : "Loupe"}
+ value={zoom}
+ onChange={setZoom}
+ options={[
+ { value: 1, label: "1×" },
+ { value: 1.6, label: "1.6×" },
+ ]}
+ />
+ </div>
+ </header>
+
+ <div className="mt-8 overflow-hidden rounded-xl border border-border bg-card shadow-xs">
+ <div className="grid grid-cols-[200px_repeat(4,minmax(0,1fr))] border-b border-border bg-muted/40">
+ <div className="px-4 py-3 text-caption font-medium text-muted-foreground">
+ {zh ? "快捷键" : "Shortcut"}
+ </div>
+ {VARIANTS.map((v) => (
+ <div key={v.id} className="border-l border-border px-4 py-3">
+ <div className="flex items-center gap-1.5">
+ <span className="inline-flex h-4.5 min-w-4.5 items-center justify-center rounded-xs bg-brand/12 px-1 text-micro font-semibold text-brand">
+ {v.badge}
+ </span>
+ <span className="text-label font-semibold">{v.name[lang]}</span>
+ </div>
+ <p className="mt-1 text-micro leading-snug text-muted-foreground">
+ {v.summary[lang]}
+ </p>
+ </div>
+ ))}
+ </div>
+
+ {COMPARE_GROUPS.map((group) => (
+ <div key={group.title.en}>
+ <div className="border-y border-border bg-muted/25 px-4 py-2 text-caption font-medium text-muted-foreground">
+ {group.title[lang]}
+ </div>
+ <div className="divide-y divide-border/70">
+ {group.items.map((item) => (
+ <div
+ key={item.label.en}
+ className="grid grid-cols-[200px_repeat(4,minmax(0,1fr))] items-center"
+ >
+ <div className="px-4 py-3">
+ <div className="text-label font-medium">{item.label[lang]}</div>
+ {item.note && (
+ <div className="mt-0.5 text-micro text-faint-foreground">
+ {item.note[lang]}
+ </div>
+ )}
+ </div>
+ {VARIANTS.map((v) => (
+ <div
+ key={v.id}
+ className="flex items-center border-l border-border/70 px-4 py-3"
+ >
+ <div
+ style={
+ zoom !== 1
+ ? { transform: `scale(${zoom})`, transformOrigin: "left center" }
+ : undefined
+ }
+ >
+ <DemoShortcutKeycaps
+ shortcut={item.shortcut}
+ variant={v.id}
+ platform={platform}
+ size={size}
+ />
+ </div>
+ </div>
+ ))}
+ </div>
+ ))}
+ </div>
+ </div>
+ ))}
+ </div>
+ </div>
+ </div>
+ );
+}
+
+const SPECIMEN_ROWS: DemoChord[][] = [
+ [
+ chord("Left"),
+ chord("D", { alt: true, primary: true }),
+ chord(",", { primary: true }),
+ chord("Fn"),
+ chord("T", { shift: true, primary: true }),
+ chord("J", { primary: true }),
+ chord("Down", { control: true }),
+ ],
+ [
+ chord("4", { shift: true, primary: true }),
+ chord("I", { primary: true }),
+ chord("F12"),
+ chord("Backspace", { alt: true }),
+ chord("/", { primary: true }),
+ chord("Q", { control: true, primary: true }),
+ chord("Right"),
+ ],
+ [
+ chord("L", { primary: true }),
+ chord("Enter", { shift: true }),
+ chord("Z", { primary: true }),
+ chord("PageDown"),
+ chord("Right", { alt: true }),
+ chord("R", { primary: true }),
+ ],
+ [
+ chord("Escape"),
+ chord("Down", { alt: true }),
+ chord("A", { primary: true }),
+ chord("Tab"),
+ chord("Tab", { control: true, shift: true }),
+ chord("[", { primary: true }),
+ ],
+ [
+ chord("P", { shift: true, primary: true }),
+ chord("/"),
+ chord("K", { primary: true }),
+ chord("Escape", { alt: true, primary: true }),
+ chord("Up"),
+ chord("S", { primary: true }),
+ ],
+ [
+ chord("Down"),
+ chord("Enter", { primary: true }),
+ chord("Space"),
+ chord("Tab", { shift: true }),
+ chord("J", { shift: true, primary: true }),
+ chord("Delete", { alt: true }),
+ ],
+ [
+ chord("]", { primary: true }),
+ chord("S", { control: true, alt: true, shift: true, primary: true }),
+ chord("Backspace"),
+ chord("Left", { primary: true }),
+ chord("F", { control: true, primary: true }),
+ chord("H", { primary: true }),
+ ],
+];
+
+function SpecimenWallPage() {
+ const { lang } = useStoryEnv();
+ const zh = lang === "zh";
+ const [variant, setVariant] = useState<DemoVariant>("optical-pill");
+ const [size, setSize] = useState<DemoSize>("md");
+
+ return (
+ <div className="min-h-screen bg-background p-10">
+ <div className="mx-auto max-w-[1040px]">
+ <header className="flex flex-wrap items-end justify-between gap-4">
+ <div>
+ <h1 className="text-title font-semibold">
+ {zh ? "键帽标本墙(参考 @sunniekapar 构图)" : "Keycap specimen wall (inspired by @sunniekapar)"}
+ </h1>
+ <p className="mt-1 text-body text-muted-foreground">
+ {zh
+ ? "在整墙高密度排布里直接切换 A / B / C / C′,可以最直观感受光学均衡度与单胶囊的呼吸感。顶部工具栏可切 Dark 模式。"
+ : "Switch A / B / C / C′ across a full wall of shortcuts to judge optical balance and visual calm. Use the toolbar to toggle Dark mode."}
+ </p>
+ </div>
+ <div className="flex flex-wrap items-center gap-3">
+ <Segmented
+ label={zh ? "方案" : "Variant"}
+ value={variant}
+ onChange={setVariant}
+ options={[
+ { value: "current", label: "A · Current" },
+ { value: "quick-win", label: "B · Step 1" },
+ { value: "optical-pill", label: "C · Optical Pill" },
+ { value: "optical-split", label: "C′ · Optical Split" },
+ ]}
+ />
+ <Segmented
+ label={zh ? "尺寸" : "Size"}
+ value={size}
+ onChange={setSize}
+ options={[
+ { value: "sm", label: "sm" },
+ { value: "md", label: "md" },
+ ]}
+ />
+ </div>
+ </header>
+
+ <div className="mt-8 rounded-2xl border border-border bg-page-canvas px-8 py-10 shadow-xs">
+ <div className="flex flex-col items-center gap-4">
+ {SPECIMEN_ROWS.map((row, rowIdx) => (
+ <div
+ key={rowIdx}
+ className="flex flex-wrap items-center justify-center gap-3.5"
+ >
+ {row.map((item, idx) => (
+ <DemoShortcutKeycaps
+ key={`${rowIdx}-${idx}`}
+ shortcut={item}
+ variant={variant}
+ size={size}
+ />
+ ))}
+ </div>
+ ))}
+ </div>
+ </div>
+ </div>
+ </div>
+ );
+}
+
+function TooltipPreview({
+ label,
+ shortcut,
+}: {
+ label: string;
+ shortcut: ReactNode;
+}) {
+ return (
+ <div className="dark inline-flex items-center gap-1.5 rounded-md bg-(--tooltip) py-1 pr-1.5 pl-2.5 text-caption text-white shadow-(--tooltip-shadow)">
+ <span>{label}</span>
+ {shortcut}
+ </div>
+ );
+}
+
+function SurfaceColumn({
+ title,
+ badge,
+ variant,
+ lang,
+}: {
+ title: string;
+ badge: string;
+ variant: DemoVariant;
+ lang: Lang;
+}) {
+ const zh = lang === "zh";
+ const settingsVariant: DemoVariant =
+ variant === "optical-pill" ? "optical-split" : variant;
+
+ return (
+ <div className="space-y-6">
+ <div className="flex items-center gap-2">
+ <span className="inline-flex h-5 min-w-5 items-center justify-center rounded-xs bg-brand/12 px-1.5 text-caption font-semibold text-brand">
+ {badge}
+ </span>
+ <h2 className="text-body font-semibold">{title}</h2>
+ </div>
+
+ {/* 1. Command Palette */}
+ <section className="overflow-hidden rounded-xl border border-border bg-popover shadow-md">
+ <div className="flex items-center gap-2 border-b border-border px-3 py-2.5">
+ <Search className="size-4 text-muted-foreground" />
+ <span className="flex-1 text-body text-faint-foreground">
+ {zh ? "搜索议题、项目或命令…" : "Search issues, projects, or commands…"}
+ </span>
+ <DemoShortcutKeycaps shortcut={chord("Escape")} variant={variant} />
+ </div>
+ <div className="p-1.5">
+ <div className="px-2 pt-1 pb-1 text-caption font-medium text-muted-foreground">
+ {zh ? "常用命令" : "Commands"}
+ </div>
+ {[
+ {
+ icon: Plus,
+ label: zh ? "新建议题" : "Create issue",
+ sc: chord("C"),
+ selected: true,
+ },
+ {
+ icon: MessageSquare,
+ label: zh ? "开始新对话" : "Start new chat",
+ sc: chord("J", { primary: true, shift: true }),
+ },
+ {
+ icon: PanelLeft,
+ label: zh ? "切换左侧边栏" : "Toggle sidebar",
+ sc: chord("B", { primary: true }),
+ },
+ {
+ icon: PanelRight,
+ label: zh ? "切换右侧详情栏" : "Toggle right sidebar",
+ sc: chord("/", { primary: true }),
+ },
+ {
+ icon: ArrowLeft,
+ label: zh ? "返回上一页" : "Go back",
+ sc: chord("[", { primary: true }),
+ },
+ ].map((row) => (
+ <div
+ key={row.label}
+ className={cn(
+ "flex h-9 items-center gap-2.5 rounded-md px-2 text-body",
+ row.selected && "bg-accent",
+ )}
+ >
+ <row.icon className="size-4 text-muted-foreground" />
+ <span className="flex-1 truncate">{row.label}</span>
+ <DemoShortcutKeycaps shortcut={row.sc} variant={variant} />
+ </div>
+ ))}
+ </div>
+ <div className="flex items-center gap-3 border-t border-border px-3 py-2 text-caption text-muted-foreground">
+ <span className="inline-flex items-center gap-1.5">
+ <span className="inline-flex gap-0.5">
+ <DemoShortcutKeycaps shortcut={chord("Up")} variant={variant} />
+ <DemoShortcutKeycaps shortcut={chord("Down")} variant={variant} />
+ </span>
+ <span>{zh ? "切换" : "Navigate"}</span>
+ </span>
+ <span className="inline-flex items-center gap-1.5">
+ <DemoShortcutKeycaps shortcut={chord("Enter")} variant={variant} />
+ <span>{zh ? "打开" : "Select"}</span>
+ </span>
+ <span className="ml-auto inline-flex items-center gap-2.5">
+ <span className="inline-flex items-center gap-1">
+ <DemoLiteralKbd variant={variant}>&gt;</DemoLiteralKbd>
+ <span>{zh ? "命令" : "Commands"}</span>
+ </span>
+ <span className="inline-flex items-center gap-1">
+ <DemoLiteralKbd variant={variant}>#</DemoLiteralKbd>
+ <span>{zh ? "议题" : "Issues"}</span>
+ </span>
+ </span>
+ </div>
+ </section>
+
+ {/* 2. Tooltips & Primary Buttons */}
+ <section className="rounded-xl border border-border bg-card p-5 shadow-xs">
+ <div className="text-caption font-medium text-muted-foreground">
+ {zh ? "Tooltip 与主按钮反色" : "Tooltips & inverted primary buttons"}
+ </div>
+ <div className="mt-3.5 flex flex-wrap items-center gap-2.5">
+ <TooltipPreview
+ label={zh ? "新对话" : "New chat"}
+ shortcut={
+ <DemoShortcutKeycaps
+ shortcut={chord("J", { primary: true, shift: true })}
+ variant={variant}
+ tone="tooltip"
+ />
+ }
+ />
+ <TooltipPreview
+ label={zh ? "右侧栏" : "Right sidebar"}
+ shortcut={
+ <DemoShortcutKeycaps
+ shortcut={chord("/", { primary: true })}
+ variant={variant}
+ tone="tooltip"
+ />
+ }
+ />
+ <TooltipPreview
+ label={zh ? "按住说话" : "Voice input"}
+ shortcut={
+ <DemoShortcutKeycaps
+ shortcut={chord("Space", { alt: true })}
+ variant={variant}
+ tone="tooltip"
+ />
+ }
+ />
+ <TooltipPreview
+ label={zh ? "新窗口打开" : "Open in new window"}
+ shortcut={
+ <DemoShortcutKeycaps
+ shortcut={chord(zh ? "点击" : "Click", { shift: true })}
+ variant={variant}
+ tone="tooltip"
+ />
+ }
+ />
+ </div>
+ <div className="mt-4 flex flex-wrap items-center gap-3">
+ <Button size="sm">
+ <span>{zh ? "创建议题" : "Create Issue"}</span>
+ <DemoShortcutKeycaps
+ shortcut={chord("Enter", { primary: true })}
+ variant={variant}
+ tone="on-primary"
+ className="ml-1"
+ />
+ </Button>
+ <Button size="sm" variant="outline">
+ <span>{zh ? "搜索" : "Search"}</span>
+ <DemoShortcutKeycaps
+ shortcut={chord("K", { primary: true })}
+ variant={variant}
+ className="ml-1"
+ />
+ </Button>
+ </div>
+ </section>
+
+ {/* 3. Settings · Keyboard shortcuts */}
+ <section className="rounded-xl border border-border bg-card shadow-xs">
+ <div className="flex items-center justify-between border-b border-border px-4 py-2.5">
+ <span className="text-caption font-medium text-muted-foreground">
+ {zh ? "设置 · 固定快捷键(md 尺寸)" : "Settings · Fixed shortcuts (md)"}
+ </span>
+ {variant === "optical-pill" && (
+ <span className="text-micro text-faint-foreground">
+ {zh ? "设置页保留拆键(C′)" : "Split kept in Settings (C′)"}
+ </span>
+ )}
+ </div>
+ <div className="divide-y divide-border/70">
+ {[
+ { label: zh ? "打开设置" : "Open settings", sc: chord(",", { primary: true }) },
+ { label: zh ? "后退 / 前进" : "Back / Forward", sc: chord("[", { primary: true }) },
+ { label: zh ? "放大界面" : "Zoom in", sc: chord("Plus", { primary: true }) },
+ { label: zh ? "缩小界面" : "Zoom out", sc: chord("Minus", { primary: true }) },
+ { label: zh ? "全屏切换" : "Toggle full screen", sc: chord("F", { control: true, primary: true }) },
+ ].map((row) => (
+ <div key={row.label} className="flex items-center justify-between px-4 py-2.5">
+ <span className="text-body">{row.label}</span>
+ <DemoShortcutKeycaps
+ shortcut={row.sc}
+ variant={settingsVariant}
+ size="md"
+ />
+ </div>
+ ))}
+ </div>
+ </section>
+ </div>
+ );
+}
+
+function RealSurfacesPage() {
+ const { lang } = useStoryEnv();
+ const zh = lang === "zh";
+
+ return (
+ <div className="min-h-screen bg-background p-10">
+ <div className="mx-auto max-w-[1200px]">
+ <header className="max-w-3xl">
+ <h1 className="text-title font-semibold">
+ {zh ? "真实产品界面对比:现状 vs Step 2" : "Real product surfaces: Current vs Step 2"}
+ </h1>
+ <p className="mt-1.5 text-body text-muted-foreground">
+ {zh
+ ? "把现状(左)和 Step 2 方案(右:高密度场景用单胶囊 C,设置页保留拆键 C′,反色用正式 tone 变体)放进 Multica 真实容器里直接对比。"
+ : "Side-by-side in real Multica chrome: Current (left) vs Step 2 (right: pill C in dense surfaces, split C′ in Settings, formal inverted tones)."}
+ </p>
+ </header>
+
+ <div className="mt-8 grid grid-cols-1 gap-8 lg:grid-cols-2">
+ <SurfaceColumn
+ badge="A"
+ title={zh ? "线上现状" : "Current"}
+ variant="current"
+ lang={lang}
+ />
+ <SurfaceColumn
+ badge="C"
+ title={zh ? "Step 2 · 光学字形 + 场景分层" : "Step 2 · Optical glyphs + layered grouping"}
+ variant="optical-pill"
+ lang={lang}
+ />
+ </div>
+ </div>
+ </div>
+ );
+}
+
+const ANATOMY_ITEMS: {
+ name: OpticalGlyphName;
+ label: string;
+ legacyIcon?: IconComponent;
+ legacyText?: string;
+ note: Record<Lang, string>;
+}[] = [
+ {
+ name: "command",
+ label: "Command",
+ legacyIcon: Command,
+ note: { zh: "圆角环更舒展,小字号不糊中心孔", en: "More open corner loops stay crisp at 11px" },
+ },
+ {
+ name: "control",
+ label: "Control",
+ legacyText: "⌃",
+ note: { zh: "消除裸 Unicode 上漂,居中在 cap-height 中线", en: "Replaces high floating Unicode ⌃ with centered vector" },
+ },
+ {
+ name: "option",
+ label: "Option",
+ legacyIcon: Option,
+ note: { zh: "比例宽画布(17:16),斜杠与横杠配重均衡", en: "Proportional 17:16 box balances open diagonal weight" },
+ },
+ {
+ name: "shift",
+ label: "Shift",
+ legacyIcon: ArrowBigUp,
+ note: { zh: "由瘦长高箭头改为贴合大写高度的宽比例 ⇧", en: "Shorter, wider keycap ⇧ instead of tall ArrowBigUp" },
+ },
+ {
+ name: "enter",
+ label: "Return",
+ legacyIcon: CornerDownLeft,
+ note: { zh: "箭头重心抬升至中线,不再底部下坠", en: "Visual center lifted to cap midline" },
+ },
+ {
+ name: "backspace",
+ label: "Backspace",
+ legacyIcon: Delete,
+ note: { zh: "18.5:16 比例宽,外框收高抵消封闭体量", en: "18.5:16 box; slightly tighter height offsets closed silhouette" },
+ },
+ {
+ name: "forwardDelete",
+ label: "Forward Delete",
+ legacyIcon: Delete,
+ note: { zh: "现状与 Backspace 混用同一图标,现补齐 ⌦", en: "Previously shared Backspace icon; now distinct ⌦" },
+ },
+ {
+ name: "tab",
+ label: "Tab",
+ legacyIcon: ArrowRightToLine,
+ note: { zh: "竖线对齐 cap-height,箭杆居中", en: "Stop bar aligns with cap-height; centered shaft" },
+ },
+ {
+ name: "arrowUp",
+ label: "Up",
+ legacyIcon: ArrowUp,
+ note: { zh: "收窄水平字宽(13:16),组合里不留多余空白", en: "Narrower 13:16 advance avoids excess side-bearing" },
+ },
+ {
+ name: "arrowDown",
+ label: "Down",
+ legacyIcon: ArrowDown,
+ note: { zh: "与 Up 完全对称,笔宽对齐 Inter 500", en: "Symmetric with Up; stroke matches Inter 500" },
+ },
+ {
+ name: "arrowLeft",
+ label: "Left",
+ legacyIcon: ArrowLeft,
+ note: { zh: "与 ⌘ 并排时中线平齐", en: "Aligns on midline next to ⌘" },
+ },
+ {
+ name: "arrowRight",
+ label: "Right",
+ legacyIcon: ArrowRight,
+ note: { zh: "与 ⌥ 并排时中线平齐", en: "Aligns on midline next to ⌥" },
+ },
+ {
+ name: "space",
+ label: "Space",
+ legacyIcon: Space,
+ note: { zh: "现状贴在底部,现垂直居中(且默认推荐 Space 文字)", en: "Was bottom-sunk; now centered (text Space preferred by default)" },
+ },
+];
+
+function SpecimenCell({
+ showGuides,
+ children,
+}: {
+ showGuides: boolean;
+ children: ReactNode;
+}) {
+ return (
+ <div className="relative inline-flex items-center justify-center rounded-md border border-border/70 bg-page-canvas px-4 py-2.5">
+ {showGuides && (
+ <>
+ <span
+ aria-hidden="true"
+ className="pointer-events-none absolute inset-x-1 top-1/2 -translate-y-[0.365em] border-t border-dashed border-brand/45"
+ style={{ fontSize: "36px" }}
+ />
+ <span
+ aria-hidden="true"
+ className="pointer-events-none absolute inset-x-1 top-1/2 border-t border-dotted border-destructive/45"
+ />
+ <span
+ aria-hidden="true"
+ className="pointer-events-none absolute inset-x-1 top-1/2 translate-y-[0.365em] border-t border-dashed border-brand/45"
+ style={{ fontSize: "36px" }}
+ />
+ </>
+ )}
+ <div
+ className="relative inline-flex items-center gap-2 font-sans leading-none font-medium text-foreground"
+ style={{ fontSize: "36px", fontFeatureSettings: '"case" 1' }}
+ >
+ <span className="text-faint-foreground/60">H</span>
+ {children}
+ <span className="text-faint-foreground/60">K</span>
+ </div>
+ </div>
+ );
+}
+
+function GlyphAnatomyPage() {
+ const { lang } = useStoryEnv();
+ const zh = lang === "zh";
+ const [showGuides, setShowGuides] = useState(true);
+
+ return (
+ <div className="min-h-screen bg-background p-10">
+ <div className="mx-auto max-w-[1160px]">
+ <header className="flex flex-wrap items-end justify-between gap-4">
+ <div className="max-w-2xl">
+ <h1 className="text-title font-semibold">
+ {zh ? "字形解剖(3× 放大 + Cap-height 标线)" : "Glyph anatomy (3× zoom + cap-height guides)"}
+ </h1>
+ <p className="mt-1.5 text-body text-muted-foreground">
+ {zh
+ ? "把每个符号夹在 Inter 500 大写字母 H 与 K 中间放大观察:蓝虚线为大写字高(cap-height),红点线为光学中线。"
+ : "Every symbol flanked by Inter 500 capitals H and K at 3×: dashed blue marks cap-height, dotted red marks optical midline."}
+ </p>
+ </div>
+ <Segmented
+ label={zh ? "参考线" : "Guides"}
+ value={showGuides ? "on" : "off"}
+ onChange={(v) => setShowGuides(v === "on")}
+ options={[
+ { value: "on", label: zh ? "显示" : "On" },
+ { value: "off", label: zh ? "隐藏" : "Off" },
+ ]}
+ />
+ </header>
+
+ <div className="mt-8 grid grid-cols-1 gap-4 md:grid-cols-2">
+ {ANATOMY_ITEMS.map((item) => {
+ const LegacyIcon = item.legacyIcon;
+ return (
+ <div
+ key={item.name}
+ className="rounded-xl border border-border bg-card p-4 shadow-xs"
+ >
+ <div className="flex items-baseline justify-between gap-2">
+ <span className="text-body font-semibold">{item.label}</span>
+ <span className="text-caption text-muted-foreground">
+ {item.note[lang]}
+ </span>
+ </div>
+ <div className="mt-3 grid grid-cols-2 gap-3">
+ <div>
+ <div className="mb-1.5 text-micro text-muted-foreground">
+ {zh ? "A · 现状(24px 图标缩放)" : "A · Current (24px icon scaled)"}
+ </div>
+ <SpecimenCell showGuides={showGuides}>
+ {LegacyIcon ? (
+ <LegacyIcon
+ strokeWidth={1.8}
+ style={{ width: "39px", height: "39px" }}
+ />
+ ) : (
+ <span>{item.legacyText}</span>
+ )}
+ </SpecimenCell>
+ </div>
+ <div>
+ <div className="mb-1.5 text-micro font-medium text-brand">
+ {zh ? "C · 新版(16px 光学字形)" : "C · New (16px optical glyph)"}
+ </div>
+ <SpecimenCell showGuides={showGuides}>
+ <OpticalKbdGlyph name={item.name} />
+ </SpecimenCell>
+ </div>
+ </div>
+ </div>
+ );
+ })}
+ </div>
+ </div>
+ </div>
+ );
+}
+
+export const Compare: Story = {
+ name: "Compare all",
+ render: () => <ComparePage />,
+};
+
+export const SpecimenWall: Story = {
+ name: "Specimen wall",
+ render: () => <SpecimenWallPage />,
+};
+
+export const RealSurfaces: Story = {
+ name: "Real surfaces",
+ render: () => <RealSurfacesPage />,
+};
+
+export const GlyphAnatomy: Story = {
+ name: "Glyph anatomy",
+ render: () => <GlyphAnatomyPage />,
+};
diff --git a/apps/storybook/src/kbd/variants.tsx b/apps/storybook/src/kbd/variants.tsx
new file mode 100644
index 0000000000..cd93e7cd87
--- /dev/null
+++ b/apps/storybook/src/kbd/variants.tsx
@@ -0,0 +1,400 @@
+import type { CSSProperties, ReactNode } from "react";
+import {
+ ArrowBigUp,
+ ArrowDown,
+ ArrowLeft,
+ ArrowRight,
+ ArrowRightToLine,
+ ArrowUp,
+ Command,
+ CornerDownLeft,
+ Delete,
+ Option,
+ Space,
+ type IconComponent,
+} from "@multica/ui/icons";
+import { Kbd } from "@multica/ui/components/ui/kbd";
+import { cn } from "@multica/ui/lib/utils";
+import { OpticalKbdGlyph, type OpticalGlyphName } from "./kbd-glyphs";
+
+export type DemoPlatform = "macos" | "windows";
+export type DemoVariant = "current" | "quick-win" | "optical-pill" | "optical-split";
+export type DemoSize = "sm" | "md";
+export type DemoTone = "default" | "on-primary" | "tooltip" | "subtle";
+
+export interface DemoChord {
+ key: string;
+ modifiers?: {
+ primary?: boolean;
+ control?: boolean;
+ alt?: boolean;
+ shift?: boolean;
+ };
+}
+
+export function chord(
+ key: string,
+ modifiers: DemoChord["modifiers"] = {},
+): DemoChord {
+ return { key, modifiers };
+}
+
+type CurrentToken = {
+ id: string;
+ label: string;
+ text?: string;
+ icon?: IconComponent;
+};
+
+const CURRENT_KEY_TOKENS: Record<string, Omit<CurrentToken, "id">> = {
+ Enter: { label: "Enter", icon: CornerDownLeft },
+ Backspace: { label: "Backspace", icon: Delete },
+ Delete: { label: "Delete", icon: Delete },
+ Up: { label: "Up Arrow", icon: ArrowUp },
+ Down: { label: "Down Arrow", icon: ArrowDown },
+ Left: { label: "Left Arrow", icon: ArrowLeft },
+ Right: { label: "Right Arrow", icon: ArrowRight },
+ Space: { label: "Space", icon: Space },
+ Tab: { label: "Tab", icon: ArrowRightToLine },
+ Escape: { label: "Esc" },
+ Plus: { label: "+" },
+ Minus: { label: "−" },
+ Equals: { label: "=" },
+ Underscore: { label: "_" },
+};
+
+/** Exact token builder mirroring packages/views/common/shortcut-keycaps.tsx. */
+function buildCurrentTokens(shortcut: DemoChord, platform: DemoPlatform): CurrentToken[] {
+ const m = shortcut.modifiers ?? {};
+ const tokens: CurrentToken[] = [];
+ if (platform === "macos") {
+ if (m.primary) tokens.push({ id: "primary", label: "Command", icon: Command });
+ if (m.control) tokens.push({ id: "control", label: "Control", text: "⌃" });
+ if (m.alt) tokens.push({ id: "alt", label: "Option", icon: Option });
+ if (m.shift) tokens.push({ id: "shift", label: "Shift", icon: ArrowBigUp });
+ } else {
+ if (m.primary) tokens.push({ id: "primary", label: "Ctrl" });
+ if (m.control) tokens.push({ id: "control", label: "Control" });
+ if (m.alt) tokens.push({ id: "alt", label: "Alt" });
+ if (m.shift) tokens.push({ id: "shift", label: "Shift", icon: ArrowBigUp });
+ }
+ const keyToken = CURRENT_KEY_TOKENS[shortcut.key] ?? { label: shortcut.key };
+ tokens.push({ id: `key-${shortcut.key}`, ...keyToken });
+ return tokens;
+}
+
+type OpticalToken = {
+ id: string;
+ label: string;
+ kind: "glyph" | "text";
+ glyph?: OpticalGlyphName;
+ text?: string;
+ /** Keep legacy 24px icon in quick-win mode except Control & ForwardDelete. */
+ legacyIcon?: IconComponent;
+};
+
+const QUICK_WIN_KEY_TOKENS: Record<string, Omit<OpticalToken, "id">> = {
+ Enter: { label: "Enter", kind: "glyph", legacyIcon: CornerDownLeft },
+ Backspace: { label: "Backspace", kind: "glyph", legacyIcon: Delete },
+ Delete: { label: "Delete", kind: "glyph", glyph: "forwardDelete" },
+ Up: { label: "Up Arrow", kind: "glyph", legacyIcon: ArrowUp },
+ Down: { label: "Down Arrow", kind: "glyph", legacyIcon: ArrowDown },
+ Left: { label: "Left Arrow", kind: "glyph", legacyIcon: ArrowLeft },
+ Right: { label: "Right Arrow", kind: "glyph", legacyIcon: ArrowRight },
+ Space: { label: "Space", kind: "text", text: "Space" },
+ Tab: { label: "Tab", kind: "glyph", legacyIcon: ArrowRightToLine },
+ Escape: { label: "Esc", kind: "text", text: "Esc" },
+ Plus: { label: "+", kind: "text", text: "+" },
+ Minus: { label: "−", kind: "text", text: "−" },
+ Equals: { label: "=", kind: "text", text: "=" },
+ Underscore: { label: "_", kind: "text", text: "_" },
+};
+
+const OPTICAL_KEY_TOKENS: Record<string, Omit<OpticalToken, "id">> = {
+ Enter: { label: "Enter", kind: "glyph", glyph: "enter" },
+ Backspace: { label: "Backspace", kind: "glyph", glyph: "backspace" },
+ Delete: { label: "Delete", kind: "glyph", glyph: "forwardDelete" },
+ Up: { label: "Up Arrow", kind: "glyph", glyph: "arrowUp" },
+ Down: { label: "Down Arrow", kind: "glyph", glyph: "arrowDown" },
+ Left: { label: "Left Arrow", kind: "glyph", glyph: "arrowLeft" },
+ Right: { label: "Right Arrow", kind: "glyph", glyph: "arrowRight" },
+ Space: { label: "Space", kind: "text", text: "Space" },
+ Tab: { label: "Tab", kind: "glyph", glyph: "tab" },
+ Escape: { label: "Esc", kind: "text", text: "Esc" },
+ Plus: { label: "+", kind: "text", text: "+" },
+ Minus: { label: "−", kind: "text", text: "−" },
+ Equals: { label: "=", kind: "text", text: "=" },
+ Underscore: { label: "_", kind: "text", text: "_" },
+};
+
+/** Canonical Apple HIG modifier order: Control → Option → Shift → Command. */
+function buildQuickWinTokens(shortcut: DemoChord, platform: DemoPlatform): OpticalToken[] {
+ const m = shortcut.modifiers ?? {};
+ const tokens: OpticalToken[] = [];
+ if (platform === "macos") {
+ if (m.control) tokens.push({ id: "control", label: "Control", kind: "glyph", glyph: "control" });
+ if (m.alt) tokens.push({ id: "alt", label: "Option", kind: "glyph", legacyIcon: Option });
+ if (m.shift) tokens.push({ id: "shift", label: "Shift", kind: "glyph", legacyIcon: ArrowBigUp });
+ if (m.primary) tokens.push({ id: "primary", label: "Command", kind: "glyph", legacyIcon: Command });
+ } else {
+ if (m.primary) tokens.push({ id: "primary", label: "Ctrl", kind: "text", text: "Ctrl" });
+ if (m.control) tokens.push({ id: "control", label: "Control", kind: "text", text: "Control" });
+ if (m.alt) tokens.push({ id: "alt", label: "Alt", kind: "text", text: "Alt" });
+ if (m.shift) tokens.push({ id: "shift", label: "Shift", kind: "glyph", legacyIcon: ArrowBigUp });
+ }
+ const keyToken = QUICK_WIN_KEY_TOKENS[shortcut.key] ?? {
+ label: shortcut.key,
+ kind: "text" as const,
+ text: shortcut.key,
+ };
+ tokens.push({ id: `key-${shortcut.key}`, ...keyToken });
+ return tokens;
+}
+
+function buildOpticalTokens(shortcut: DemoChord, platform: DemoPlatform): OpticalToken[] {
+ const m = shortcut.modifiers ?? {};
+ const tokens: OpticalToken[] = [];
+ if (platform === "macos") {
+ if (m.control) tokens.push({ id: "control", label: "Control", kind: "glyph", glyph: "control" });
+ if (m.alt) tokens.push({ id: "alt", label: "Option", kind: "glyph", glyph: "option" });
+ if (m.shift) tokens.push({ id: "shift", label: "Shift", kind: "glyph", glyph: "shift" });
+ if (m.primary) tokens.push({ id: "primary", label: "Command", kind: "glyph", glyph: "command" });
+ } else {
+ if (m.primary) tokens.push({ id: "primary", label: "Ctrl", kind: "text", text: "Ctrl" });
+ if (m.control) tokens.push({ id: "control", label: "Control", kind: "text", text: "Control" });
+ if (m.alt) tokens.push({ id: "alt", label: "Alt", kind: "text", text: "Alt" });
+ if (m.shift) tokens.push({ id: "shift", label: "Shift", kind: "glyph", glyph: "shift" });
+ }
+ const keyToken = OPTICAL_KEY_TOKENS[shortcut.key] ?? {
+ label: shortcut.key,
+ kind: "text" as const,
+ text: shortcut.key,
+ };
+ tokens.push({ id: `key-${shortcut.key}`, ...keyToken });
+ return tokens;
+}
+
+const CASE_STYLE: CSSProperties = {
+ fontFeatureSettings: '"case" 1',
+};
+
+const TONE_CLASSES: Record<DemoTone, string> = {
+ default:
+ "border border-input bg-card text-muted-foreground shadow-[0_1px_0_0_color-mix(in_oklab,var(--input)_85%,transparent)] dark:border-white/12 dark:bg-surface-raised dark:shadow-[0_1px_0_0_rgb(0_0_0/0.5)]",
+ subtle:
+ "border border-input/85 bg-muted/70 text-muted-foreground shadow-[0_1px_0_0_color-mix(in_oklab,var(--input)_75%,transparent)]",
+ "on-primary":
+ "border border-primary-foreground/25 bg-primary-foreground/14 text-primary-foreground shadow-none",
+ tooltip:
+ "border border-white/14 bg-white/10 text-tooltip-foreground/90 shadow-none",
+};
+
+const CURRENT_TONE_CLASSES: Record<DemoTone, string> = {
+ default:
+ "border border-border/70 bg-muted/80 shadow-[0_1px_0_0_color-mix(in_oklab,var(--border)_70%,transparent)]",
+ subtle:
+ "border border-border/70 bg-muted/80 shadow-[0_1px_0_0_color-mix(in_oklab,var(--border)_70%,transparent)]",
+ "on-primary":
+ "border-background/30 bg-background/15 text-primary-foreground shadow-none",
+ tooltip:
+ "border border-border/70 bg-foreground/12 shadow-[0_1px_0_0_color-mix(in_oklab,var(--border)_70%,transparent)]",
+};
+
+/**
+ * Optical vertical centering tweaks for punctuation keys that still sit low
+ * in proportional sans even with OpenType `case`.
+ */
+function renderOpticalText(text: string): ReactNode {
+ if (text === ",") {
+ return <span className="inline-block -translate-y-[0.04em]">{text}</span>;
+ }
+ return <span>{text}</span>;
+}
+
+export function DemoShortcutKeycaps({
+ shortcut,
+ variant,
+ platform = "macos",
+ size = "sm",
+ tone = "default",
+ className,
+}: {
+ shortcut: DemoChord;
+ variant: DemoVariant;
+ platform?: DemoPlatform;
+ size?: DemoSize;
+ tone?: DemoTone;
+ className?: string;
+}) {
+ if (variant === "current") {
+ const tokens = buildCurrentTokens(shortcut, platform);
+ return (
+ <span className={cn("inline-flex items-center gap-1", className)}>
+ {tokens.map(({ id, label, text, icon: Icon }) => (
+ <kbd
+ key={id}
+ title={label}
+ className={cn(
+ "pointer-events-none inline-flex w-fit items-center justify-center gap-1 rounded-sm font-sans font-medium text-muted-foreground select-none",
+ CURRENT_TONE_CLASSES[tone],
+ size === "md"
+ ? "h-7 min-w-7 rounded-md px-1.5 text-caption [&_svg]:size-3.5"
+ : "h-5 min-w-5 px-1 text-micro [&_svg]:size-3",
+ )}
+ >
+ {Icon ? <Icon aria-hidden="true" strokeWidth={1.8} /> : (text ?? label)}
+ </kbd>
+ ))}
+ </span>
+ );
+ }
+
+ if (variant === "quick-win") {
+ const tokens = buildQuickWinTokens(shortcut, platform);
+ return (
+ <span className={cn("inline-flex items-center gap-1", className)}>
+ {tokens.map(({ id, label, glyph, legacyIcon: LegacyIcon, text }) => (
+ <kbd
+ key={id}
+ title={label}
+ style={CASE_STYLE}
+ className={cn(
+ "pointer-events-none inline-flex w-fit items-center justify-center font-sans leading-none font-medium select-none",
+ TONE_CLASSES[tone],
+ size === "md"
+ ? "h-[2.15em] min-w-[2.15em] rounded-md px-[0.5em] text-caption"
+ : "h-[1.82em] min-w-[1.82em] rounded-sm px-[0.42em] text-micro",
+ )}
+ >
+ {glyph ? (
+ <OpticalKbdGlyph name={glyph} />
+ ) : LegacyIcon ? (
+ <LegacyIcon
+ aria-hidden="true"
+ strokeWidth={1.9}
+ style={{ width: "1.1em", height: "1.1em" }}
+ />
+ ) : (
+ text ?? label
+ )}
+ </kbd>
+ ))}
+ </span>
+ );
+ }
+
+ const tokens = buildOpticalTokens(shortcut, platform);
+ const isPill = variant === "optical-pill";
+
+ if (isPill) {
+ const isSingleCharOrGlyph =
+ tokens.length === 1 &&
+ (tokens[0]!.kind === "glyph" || (tokens[0]!.text?.length ?? 0) <= 1);
+ return (
+ <kbd
+ style={CASE_STYLE}
+ className={cn(
+ "pointer-events-none inline-flex w-fit items-center justify-center font-sans leading-none font-medium tracking-[-0.01em] select-none",
+ TONE_CLASSES[tone],
+ size === "md"
+ ? cn(
+ "h-[2.15em] min-w-[2.15em] gap-[0.34em] rounded-md text-caption",
+ isSingleCharOrGlyph ? "px-[0.45em]" : "px-[0.62em]",
+ )
+ : cn(
+ "h-[1.85em] min-w-[1.85em] gap-[0.28em] rounded-[5px] text-micro",
+ isSingleCharOrGlyph ? "px-[0.36em]" : "px-[0.5em]",
+ ),
+ className,
+ )}
+ >
+ {tokens.map(({ id, label, glyph, text }) => (
+ <span
+ key={id}
+ title={label}
+ className="inline-flex items-center justify-center"
+ >
+ {glyph ? (
+ <OpticalKbdGlyph name={glyph} />
+ ) : (
+ renderOpticalText(text ?? label)
+ )}
+ </span>
+ ))}
+ </kbd>
+ );
+ }
+
+ // optical-split: bespoke proportional optical glyphs in individual keycaps
+ return (
+ <span className={cn("inline-flex items-center gap-1", className)}>
+ {tokens.map(({ id, label, glyph, text }) => {
+ const isWideText = !glyph && (text?.length ?? 0) > 1;
+ return (
+ <kbd
+ key={id}
+ title={label}
+ style={CASE_STYLE}
+ className={cn(
+ "pointer-events-none inline-flex w-fit items-center justify-center font-sans leading-none font-medium select-none",
+ TONE_CLASSES[tone],
+ size === "md"
+ ? cn(
+ "h-[2.15em] min-w-[2.15em] rounded-md text-caption",
+ isWideText ? "px-[0.58em]" : "px-[0.4em]",
+ )
+ : cn(
+ "h-[1.85em] min-w-[1.85em] rounded-[5px] text-micro",
+ isWideText ? "px-[0.46em]" : "px-[0.32em]",
+ ),
+ )}
+ >
+ {glyph ? (
+ <OpticalKbdGlyph name={glyph} />
+ ) : (
+ renderOpticalText(text ?? label)
+ )}
+ </kbd>
+ );
+ })}
+ </span>
+ );
+}
+
+/** Standalone literal keycap (e.g., `>`, `#`, `@`, `Fn`, `Click`) for surface consistency. */
+export function DemoLiteralKbd({
+ children,
+ variant,
+ size = "sm",
+ tone = "default",
+}: {
+ children: ReactNode;
+ variant: DemoVariant;
+ size?: DemoSize;
+ tone?: DemoTone;
+}) {
+ if (variant === "current") {
+ return (
+ <kbd
+ className={cn(
+ "pointer-events-none inline-flex w-fit items-center justify-center gap-1 rounded-sm border border-border/70 bg-muted/80 font-sans font-medium text-muted-foreground select-none",
+ size === "md"
+ ? "h-7 min-w-7 rounded-md px-1.5 text-caption"
+ : "h-5 min-w-5 px-1 text-micro",
+ )}
+ >
+ {children}
+ </kbd>
+ );
+ }
+ return (
+ <Kbd
+ size={size}
+ tone={tone === "on-primary" ? "on-primary" : "default"}
+ compact
+ className={tone === "tooltip" ? TONE_CLASSES.tooltip : undefined}
+ >
+ {children}
+ </Kbd>
+ );
+}
diff --git a/apps/web/features/landing/site/desktop-page.tsx b/apps/web/features/landing/site/desktop-page.tsx
index 44ecd93749..15e470e0f0 100644
--- a/apps/web/features/landing/site/desktop-page.tsx
+++ b/apps/web/features/landing/site/desktop-page.tsx
@@ -73,7 +73,7 @@ const HIGHLIGHTS: { title: string; body: string; points: string[]; visual: Compo
title: "A window for every workspace",
body: "Open each workspace in a window of its own, with its own tabs for issues, chats, and projects. Quit and reopen, and every window comes back with its tabs.",
points: [
- "Open a new window from the workspace menu, or with ⌘⇧N / Ctrl+Shift+N",
+ "Open a new window from the workspace menu, or with ⇧⌘N / Ctrl+Shift+N",
"Pin the tabs you keep coming back to",
"Multica links open in a tab instead of the browser",
],
diff --git a/packages/core/shortcuts/definitions.test.ts b/packages/core/shortcuts/definitions.test.ts
index ecb9a2f0fd..24ca595aef 100644
--- a/packages/core/shortcuts/definitions.test.ts
+++ b/packages/core/shortcuts/definitions.test.ts
@@ -174,6 +174,26 @@ describe("keyboard shortcut definitions", () => {
expect(formatShortcut(shortcut, "linux")).toBe("Ctrl+Enter");
});
+ it("formats macOS modifiers in canonical Control-Option-Shift-Command order", () => {
+ expect(
+ formatShortcut(
+ createShortcutChord("S", {
+ primary: true,
+ control: true,
+ alt: true,
+ shift: true,
+ }),
+ "macos",
+ ),
+ ).toBe("⌃⌥⇧⌘S");
+ expect(
+ formatShortcut(
+ createShortcutChord("J", { primary: true, shift: true }),
+ "macos",
+ ),
+ ).toBe("⇧⌘J");
+ });
+
it("detects modern and legacy browser platform signals", () => {
vi.stubGlobal("navigator", {
userAgentData: { platform: "macOS" },
diff --git a/packages/core/shortcuts/definitions.ts b/packages/core/shortcuts/definitions.ts
index 3d1ac7836c..d08a1ed357 100644
--- a/packages/core/shortcuts/definitions.ts
+++ b/packages/core/shortcuts/definitions.ts
@@ -339,10 +339,10 @@ export function formatShortcut(
if (platform === "macos") {
return [
- modifiers.primary ? "⌘" : "",
modifiers.control ? "⌃" : "",
modifiers.alt ? "⌥" : "",
modifiers.shift ? "⇧" : "",
+ modifiers.primary ? "⌘" : "",
modifiers.meta ? "Meta" : "",
key,
].join("");
diff --git a/packages/ui/components/ui/kbd.test.tsx b/packages/ui/components/ui/kbd.test.tsx
new file mode 100644
index 0000000000..679853ee6b
--- /dev/null
+++ b/packages/ui/components/ui/kbd.test.tsx
@@ -0,0 +1,39 @@
+import { describe, expect, it } from "vitest";
+import { render } from "@testing-library/react";
+import { Kbd, KbdGlyph, KBD_GLYPHS, type KbdGlyphName } from "./kbd";
+
+describe("Kbd", () => {
+ it("applies OpenType case feature and em-scaled classes", () => {
+ const { container } = render(<Kbd>[</Kbd>);
+ const kbd = container.querySelector("[data-slot='kbd']") as HTMLElement;
+ expect(kbd).not.toBeNull();
+ expect(kbd.style.fontFeatureSettings).toBe('"case" 1');
+ expect(kbd.className).toContain("h-[1.85em]");
+ expect(kbd.className).toContain("in-data-[slot=tooltip-content]:bg-white/10!");
+ });
+
+ it("supports md size, compact padding, and on-primary tone", () => {
+ const { container } = render(
+ <Kbd size="md" tone="on-primary" compact>
+ K
+ </Kbd>,
+ );
+ const kbd = container.querySelector("[data-slot='kbd']") as HTMLElement;
+ expect(kbd.className).toContain("h-[2.15em]");
+ expect(kbd.className).toContain("px-[0.42em]");
+ expect(kbd.className).toContain("text-primary-foreground");
+ });
+
+ it("renders every optical glyph with proportional em width and shared 16-unit height", () => {
+ for (const name of Object.keys(KBD_GLYPHS) as KbdGlyphName[]) {
+ const { container, unmount } = render(<KbdGlyph name={name} />);
+ const svg = container.querySelector(`[data-kbd-glyph="${name}"]`) as SVGElement;
+ expect(svg).not.toBeNull();
+ expect(svg.getAttribute("viewBox")).toBe(`0 0 ${KBD_GLYPHS[name].width} 16`);
+ expect(svg.getAttribute("aria-hidden")).toBe("true");
+ expect(svg.style.height).toBe("1.18em");
+ expect(svg.style.width).toMatch(/em$/);
+ unmount();
+ }
+ });
+});
diff --git a/packages/ui/components/ui/kbd.tsx b/packages/ui/components/ui/kbd.tsx
index 2884c6d066..1cb309ef9e 100644
--- a/packages/ui/components/ui/kbd.tsx
+++ b/packages/ui/components/ui/kbd.tsx
@@ -1,18 +1,215 @@
-import { cn } from "@multica/ui/lib/utils"
+import type { CSSProperties, SVGProps } from "react";
+import { cn } from "@multica/ui/lib/utils";
-function Kbd({ className, ...props }: React.ComponentProps<"kbd">) {
+export type KbdGlyphName =
+ | "command"
+ | "control"
+ | "option"
+ | "shift"
+ | "enter"
+ | "backspace"
+ | "forwardDelete"
+ | "tab"
+ | "arrowUp"
+ | "arrowDown"
+ | "arrowLeft"
+ | "arrowRight"
+ | "space";
+
+export type KbdSize = "sm" | "md";
+export type KbdTone = "default" | "on-primary";
+
+interface KbdGlyphSpec {
+ /** Proportional advance width on a shared 16-unit vertical em-box. */
+ width: number;
+ /**
+ * Stroke width tuned to Inter Medium (500) stem weight (~0.086em):
+ * 1.18 / 16 * 1.18em ≈ 0.087em. Closed/dense silhouettes step slightly
+ * lighter (1.15–1.16) to match the perceived mass of open strokes.
+ */
+ strokeWidth: number;
+ /** Inner SVG paths; cap-height optical band is y = 3.2..12.8 (center y = 8). */
+ paths: readonly string[];
+}
+
+/**
+ * Optical keycap glyphs on a shared 16-unit vertical grid with proportional
+ * advance widths (like font glyphs, not fixed-square 24px UI icons).
+ */
+export const KBD_GLYPHS: Record<KbdGlyphName, KbdGlyphSpec> = {
+ command: {
+ width: 15.5,
+ strokeWidth: 1.15,
+ paths: [
+ "M9.45 4.75v6.5a1.62 1.62 0 1 0 1.62-1.62H4.43a1.62 1.62 0 1 0 1.62 1.62v-6.5a1.62 1.62 0 1 0-1.62 1.62h6.64a1.62 1.62 0 1 0-1.62-1.62Z",
+ ],
+ },
+ control: {
+ width: 13.5,
+ strokeWidth: 1.22,
+ paths: ["M2.75 10.05 6.75 5.6l4 4.45"],
+ },
+ option: {
+ width: 17,
+ strokeWidth: 1.2,
+ paths: ["M2.25 4.15h3.85l4.2 7.7h4.45", "M10.25 4.15h4.5"],
+ },
+ shift: {
+ width: 15.5,
+ strokeWidth: 1.16,
+ paths: [
+ "M7.75 3.35 2.75 8.55h2.75v3.35c0 .42.34.75.75.75h3c.41 0 .75-.33.75-.75V8.55h2.75L7.75 3.35Z",
+ ],
+ },
+ enter: {
+ width: 16.5,
+ strokeWidth: 1.2,
+ paths: [
+ "M13.6 3.85v3.55c0 1.05-.85 1.9-1.9 1.9H3.45",
+ "M6.35 6.5 3.25 9.3l3.1 2.8",
+ ],
+ },
+ backspace: {
+ width: 18.5,
+ strokeWidth: 1.15,
+ paths: [
+ "M6.05 4.05h8.9c.9 0 1.6.7 1.6 1.6v4.7c0 .9-.7 1.6-1.6 1.6h-8.9c-.48 0-.93-.22-1.24-.59L2.25 8l2.56-3.36c.31-.37.76-.59 1.24-.59Z",
+ "M9.3 6.25 12.8 9.75",
+ "M12.8 6.25 9.3 9.75",
+ ],
+ },
+ forwardDelete: {
+ width: 18.5,
+ strokeWidth: 1.15,
+ paths: [
+ "M12.45 4.05h-8.9c-.9 0-1.6.7-1.6 1.6v4.7c0 .9.7 1.6 1.6 1.6h8.9c.48 0 .93-.22 1.24-.59L16.25 8l-2.56-3.36c-.31-.37-.76-.59-1.24-.59Z",
+ "M5.7 6.25 9.2 9.75",
+ "M9.2 6.25 5.7 9.75",
+ ],
+ },
+ tab: {
+ width: 17,
+ strokeWidth: 1.2,
+ paths: [
+ "M2.25 8h8.9",
+ "M8.1 4.9 11.4 8l-3.3 3.1",
+ "M14.5 4.05v7.9",
+ ],
+ },
+ arrowUp: {
+ width: 13,
+ strokeWidth: 1.22,
+ paths: ["M6.5 12.35V3.8", "M3.25 6.95 6.5 3.65l3.25 3.3"],
+ },
+ arrowDown: {
+ width: 13,
+ strokeWidth: 1.22,
+ paths: ["M6.5 3.65v8.55", "M3.25 9.05 6.5 12.35l3.25-3.3"],
+ },
+ arrowLeft: {
+ width: 15,
+ strokeWidth: 1.22,
+ paths: ["M12.1 8H3.3", "M6.45 4.75 3.15 8l3.3 3.25"],
+ },
+ arrowRight: {
+ width: 15,
+ strokeWidth: 1.22,
+ paths: ["M2.9 8h8.8", "M8.55 4.75 11.85 8l-3.3 3.25"],
+ },
+ space: {
+ width: 16.5,
+ strokeWidth: 1.2,
+ paths: ["M2.6 6.8v2.2c0 .72.58 1.3 1.3 1.3h8.7c.72 0 1.3-.58 1.3-1.3V6.8"],
+ },
+};
+
+const GLYPH_HEIGHT_EM = 1.18;
+
+function KbdGlyph({
+ name,
+ className,
+ strokeWidth,
+ style,
+ ...rest
+}: {
+ name: KbdGlyphName;
+} & Omit<SVGProps<SVGSVGElement>, "viewBox" | "width" | "height">) {
+ const spec = KBD_GLYPHS[name];
+ const widthEm = ((spec.width / 16) * GLYPH_HEIGHT_EM).toFixed(4);
+ return (
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox={`0 0 ${spec.width} 16`}
+ fill="none"
+ stroke="currentColor"
+ strokeWidth={strokeWidth ?? spec.strokeWidth}
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ aria-hidden="true"
+ data-kbd-glyph={name}
+ className={cn("shrink-0", className)}
+ style={{
+ width: `${widthEm}em`,
+ height: `${GLYPH_HEIGHT_EM}em`,
+ ...style,
+ }}
+ {...rest}
+ >
+ {spec.paths.map((d, i) => (
+ <path key={i} d={d} />
+ ))}
+ </svg>
+ );
+}
+
+const KBD_CASE_STYLE: CSSProperties = {
+ fontFeatureSettings: '"case" 1',
+};
+
+interface KbdProps extends React.ComponentProps<"kbd"> {
+ size?: KbdSize;
+ tone?: KbdTone;
+ /** Tighter horizontal padding for single-glyph / single-character keycaps. */
+ compact?: boolean;
+}
+
+function Kbd({
+ className,
+ size = "sm",
+ tone = "default",
+ compact = false,
+ style,
+ ...props
+}: KbdProps) {
return (
<kbd
data-slot="kbd"
+ style={style ? { ...KBD_CASE_STYLE, ...style } : KBD_CASE_STYLE}
className={cn(
- // In a tooltip the keycap is a translucent light fill: the solid muted
- // fill sits below the tooltip surface's lightness in dark mode.
- "pointer-events-none inline-flex h-5 w-fit min-w-5 items-center justify-center gap-1 rounded-sm bg-muted px-1 font-sans text-caption font-medium text-muted-foreground select-none in-data-[slot=tooltip-content]:bg-foreground/12 [&_svg:not([class*='size-'])]:size-3",
- className
+ "pointer-events-none inline-flex w-fit items-center justify-center font-sans leading-none font-medium tracking-[-0.01em] select-none [&_svg:not([data-kbd-glyph]):not([class*='size-'])]:size-[1.1em]",
+ tone === "on-primary"
+ ? "border border-primary-foreground/25 bg-primary-foreground/14 text-primary-foreground shadow-none"
+ : [
+ "border border-input bg-card text-muted-foreground shadow-[0_1px_0_0_color-mix(in_oklab,var(--input)_85%,transparent)]",
+ "dark:border-white/12 dark:bg-surface-raised dark:shadow-[0_1px_0_0_rgb(0_0_0/0.5)]",
+ // Tooltips use a dark surface in both themes; override both light and
+ // dark default styles so keycaps stay crisp without passing a tone.
+ "in-data-[slot=tooltip-content]:border-white/14! in-data-[slot=tooltip-content]:bg-white/10! in-data-[slot=tooltip-content]:text-tooltip-foreground/90! in-data-[slot=tooltip-content]:shadow-none!",
+ ],
+ size === "md"
+ ? cn(
+ "h-[2.15em] min-w-[2.15em] gap-[0.34em] rounded-md text-caption",
+ compact ? "px-[0.42em]" : "px-[0.6em]",
+ )
+ : cn(
+ "h-[1.85em] min-w-[1.85em] gap-[0.28em] rounded-sm text-micro",
+ compact ? "px-[0.34em]" : "px-[0.48em]",
+ ),
+ className,
)}
{...props}
/>
- )
+ );
}
function KbdGroup({ className, ...props }: React.ComponentProps<"div">) {
@@ -22,7 +219,7 @@ function KbdGroup({ className, ...props }: React.ComponentProps<"div">) {
className={cn("inline-flex items-center gap-1", className)}
{...props}
/>
- )
+ );
}
-export { Kbd, KbdGroup }
+export { Kbd, KbdGlyph, KbdGroup, type KbdProps };
diff --git a/packages/views/agents/create/choose-runtime-page.tsx b/packages/views/agents/create/choose-runtime-page.tsx
index 4f9995c351..7cad9458ac 100644
--- a/packages/views/agents/create/choose-runtime-page.tsx
+++ b/packages/views/agents/create/choose-runtime-page.tsx
@@ -13,6 +13,7 @@ import { useWSEvent } from "@multica/core/realtime";
import { memberListOptions } from "@multica/core/workspace/queries";
import { Button } from "@multica/ui/components/ui/button";
import { Input } from "@multica/ui/components/ui/input";
+import { Kbd } from "@multica/ui/components/ui/kbd";
import { useBackOrReplace, useNavigation } from "../../navigation";
import { useT } from "../../i18n";
import { ConnectRemoteDialog } from "../../runtimes/components/connect-remote-dialog";
@@ -226,9 +227,9 @@ export function ChooseRuntimePage({
aria-label={t(($) => $.creation_studio.runtime_step.search_placeholder)}
className="h-8 pl-8 pr-8"
/>
- <kbd className="pointer-events-none absolute right-2 top-1/2 -translate-y-1/2 rounded-xs border bg-muted px-1 text-micro text-muted-foreground">
+ <Kbd aria-hidden="true" compact className="absolute right-2 top-1/2 -translate-y-1/2">
/
- </kbd>
+ </Kbd>
</div>
</div>
diff --git a/packages/views/common/shortcut-keycaps.test.tsx b/packages/views/common/shortcut-keycaps.test.tsx
index 5276bb2bf3..da2ea45d1f 100644
--- a/packages/views/common/shortcut-keycaps.test.tsx
+++ b/packages/views/common/shortcut-keycaps.test.tsx
@@ -4,7 +4,7 @@ import { createShortcutChord } from "@multica/core/shortcuts";
import { ShortcutKeycaps } from "./shortcut-keycaps";
describe("ShortcutKeycaps", () => {
- it("uses icons for macOS Command and Enter", () => {
+ it("renders a unified optical pill by default for macOS Command+Enter", () => {
const { container } = render(
<ShortcutKeycaps
shortcut={createShortcutChord("Enter", { primary: true })}
@@ -13,39 +13,88 @@ describe("ShortcutKeycaps", () => {
);
expect(screen.getByRole("img", { name: "⌘↵" })).toBeInTheDocument();
- expect(container.querySelector(".icon-command")).toBeInTheDocument();
- expect(container.querySelector(".icon-corner-down-left")).toBeInTheDocument();
+ expect(container.querySelectorAll("[data-slot='kbd']")).toHaveLength(1);
+ expect(container.querySelector("[data-kbd-glyph='command']")).toBeInTheDocument();
+ expect(container.querySelector("[data-kbd-glyph='enter']")).toBeInTheDocument();
expect(container.querySelector("[title='Enter']")?.textContent).toBe("");
});
- it("keeps platform-specific modifier labels while iconizing function keys", () => {
+ it("renders separate keycaps when layout is split", () => {
const { container } = render(
<ShortcutKeycaps
- shortcut={createShortcutChord("Enter", { primary: true })}
- platform="windows"
+ shortcut={createShortcutChord("J", { primary: true, shift: true })}
+ platform="macos"
+ layout="split"
/>,
);
- expect(screen.getByRole("img", { name: "Ctrl+Enter" })).toBeInTheDocument();
- expect(container.querySelector("[title='Ctrl']")).toHaveTextContent("Ctrl");
- expect(container.querySelector(".icon-corner-down-left")).toBeInTheDocument();
- expect(container.querySelector(".icon-command")).not.toBeInTheDocument();
+ expect(screen.getByRole("img", { name: "⇧⌘J" })).toBeInTheDocument();
+ const keycaps = container.querySelectorAll("[data-slot='kbd']");
+ expect(keycaps).toHaveLength(3);
+ expect(Array.from(keycaps).map((el) => el.getAttribute("data-shortcut-key"))).toEqual([
+ "shift",
+ "primary",
+ "key-J",
+ ]);
});
- it("uses the canonical macOS Control glyph instead of an unrelated icon", () => {
+ it("orders macOS modifiers in canonical Control-Option-Shift-Command order", () => {
const { container } = render(
<ShortcutKeycaps
- shortcut={createShortcutChord("F", { control: true })}
+ shortcut={createShortcutChord("S", {
+ primary: true,
+ control: true,
+ alt: true,
+ shift: true,
+ })}
platform="macos"
/>,
);
- expect(screen.getByRole("img", { name: "⌃F" })).toBeInTheDocument();
- expect(container.querySelector("[title='Control']")).toHaveTextContent("⌃");
- expect(container.querySelector(".icon-command")).not.toBeInTheDocument();
+ expect(screen.getByRole("img", { name: "⌃⌥⇧⌘S" })).toBeInTheDocument();
+ const keys = Array.from(
+ container.querySelectorAll("[data-shortcut-key]"),
+ ).map((el) => el.getAttribute("data-shortcut-key"));
+ expect(keys).toEqual(["control", "alt", "shift", "primary", "key-S"]);
+ expect(container.querySelector("[data-kbd-glyph='control']")).toBeInTheDocument();
+ expect(container.querySelector("[data-kbd-glyph='option']")).toBeInTheDocument();
+ expect(container.querySelector("[data-kbd-glyph='shift']")).toBeInTheDocument();
+ expect(container.querySelector("[data-kbd-glyph='command']")).toBeInTheDocument();
+ });
+
+ it("keeps platform-specific modifier labels while using optical glyphs for action keys", () => {
+ const { container } = render(
+ <ShortcutKeycaps
+ shortcut={createShortcutChord("Enter", { primary: true })}
+ platform="windows"
+ />,
+ );
+
+ expect(screen.getByRole("img", { name: "Ctrl+Enter" })).toBeInTheDocument();
+ expect(container.querySelector("[title='Ctrl']")).toHaveTextContent("Ctrl");
+ expect(container.querySelector("[data-kbd-glyph='enter']")).toBeInTheDocument();
+ expect(container.querySelector("[data-kbd-glyph='command']")).not.toBeInTheDocument();
+ });
+
+ it("distinguishes Backspace from forward Delete and renders Space as text", () => {
+ const { container: backspaceContainer } = render(
+ <ShortcutKeycaps shortcut={createShortcutChord("Backspace")} platform="macos" />,
+ );
+ expect(backspaceContainer.querySelector("[data-kbd-glyph='backspace']")).toBeInTheDocument();
+
+ const { container: deleteContainer } = render(
+ <ShortcutKeycaps shortcut={createShortcutChord("Delete")} platform="macos" />,
+ );
+ expect(deleteContainer.querySelector("[data-kbd-glyph='forwardDelete']")).toBeInTheDocument();
+
+ const { container: spaceContainer } = render(
+ <ShortcutKeycaps shortcut={createShortcutChord("Space", { alt: true })} platform="macos" />,
+ );
+ expect(spaceContainer.querySelector("[title='Space']")).toHaveTextContent("Space");
+ expect(spaceContainer.querySelector("[data-kbd-glyph='space']")).not.toBeInTheDocument();
});
- it("falls back to compact text when there is no exact semantic icon", () => {
+ it("falls back to compact text when there is no semantic glyph", () => {
const { container } = render(
<ShortcutKeycaps shortcut={createShortcutChord("Escape")} platform="linux" />,
);
diff --git a/packages/views/common/shortcut-keycaps.tsx b/packages/views/common/shortcut-keycaps.tsx
index 9422215791..9cc85be31c 100644
--- a/packages/views/common/shortcut-keycaps.tsx
+++ b/packages/views/common/shortcut-keycaps.tsx
@@ -1,19 +1,5 @@
"use client";
-import {
- ArrowBigUp,
- ArrowDown,
- ArrowLeft,
- ArrowRight,
- ArrowRightToLine,
- ArrowUp,
- Command,
- CornerDownLeft,
- Delete,
- Option,
- Space,
- type IconComponent,
-} from "@multica/ui/icons";
import {
formatShortcut,
getShortcutPlatform,
@@ -22,33 +8,43 @@ import {
type ShortcutChord,
type ShortcutPlatform,
} from "@multica/core/shortcuts";
-import { Kbd } from "@multica/ui/components/ui/kbd";
+import {
+ Kbd,
+ KbdGlyph,
+ type KbdGlyphName,
+ type KbdSize,
+ type KbdTone,
+} from "@multica/ui/components/ui/kbd";
import { cn } from "@multica/ui/lib/utils";
type ShortcutToken = {
id: string;
label: string;
text?: string;
- icon?: IconComponent;
+ glyph?: KbdGlyphName;
};
const KEY_TOKENS: Record<string, Omit<ShortcutToken, "id">> = {
- Enter: { label: "Enter", icon: CornerDownLeft },
- Backspace: { label: "Backspace", icon: Delete },
- Delete: { label: "Delete", icon: Delete },
- Up: { label: "Up Arrow", icon: ArrowUp },
- Down: { label: "Down Arrow", icon: ArrowDown },
- Left: { label: "Left Arrow", icon: ArrowLeft },
- Right: { label: "Right Arrow", icon: ArrowRight },
- Space: { label: "Space", icon: Space },
- Tab: { label: "Tab", icon: ArrowRightToLine },
- Escape: { label: "Esc" },
- Plus: { label: "+" },
- Minus: { label: "−" },
- Equals: { label: "=" },
- Underscore: { label: "_" },
+ Enter: { label: "Enter", glyph: "enter" },
+ Backspace: { label: "Backspace", glyph: "backspace" },
+ Delete: { label: "Delete", glyph: "forwardDelete" },
+ Up: { label: "Up Arrow", glyph: "arrowUp" },
+ Down: { label: "Down Arrow", glyph: "arrowDown" },
+ Left: { label: "Left Arrow", glyph: "arrowLeft" },
+ Right: { label: "Right Arrow", glyph: "arrowRight" },
+ Space: { label: "Space", text: "Space" },
+ Tab: { label: "Tab", glyph: "tab" },
+ Escape: { label: "Esc", text: "Esc" },
+ Plus: { label: "+", text: "+" },
+ Minus: { label: "−", text: "−" },
+ Equals: { label: "=", text: "=" },
+ Underscore: { label: "_", text: "_" },
};
+/**
+ * Resolve display tokens for a chord. macOS follows Apple HIG canonical
+ * modifier order: Control → Option → Shift → Command → Key.
+ */
function shortcutTokens(
shortcut: ShortcutChord,
platform: ShortcutPlatform,
@@ -57,46 +53,103 @@ function shortcutTokens(
const tokens: ShortcutToken[] = [];
if (platform === "macos") {
- if (modifiers.primary) tokens.push({ id: "primary", label: "Command", icon: Command });
- if (modifiers.control) tokens.push({ id: "control", label: "Control", text: "⌃" });
- if (modifiers.alt) tokens.push({ id: "alt", label: "Option", icon: Option });
- if (modifiers.shift) tokens.push({ id: "shift", label: "Shift", icon: ArrowBigUp });
- if (modifiers.meta) tokens.push({ id: "meta", label: "Meta" });
+ if (modifiers.control) tokens.push({ id: "control", label: "Control", glyph: "control" });
+ if (modifiers.alt) tokens.push({ id: "alt", label: "Option", glyph: "option" });
+ if (modifiers.shift) tokens.push({ id: "shift", label: "Shift", glyph: "shift" });
+ if (modifiers.primary) tokens.push({ id: "primary", label: "Command", glyph: "command" });
+ if (modifiers.meta) tokens.push({ id: "meta", label: "Meta", text: "Meta" });
} else {
- if (modifiers.primary) tokens.push({ id: "primary", label: "Ctrl" });
- if (modifiers.control) tokens.push({ id: "control", label: "Control" });
+ if (modifiers.primary) tokens.push({ id: "primary", label: "Ctrl", text: "Ctrl" });
+ if (modifiers.control) tokens.push({ id: "control", label: "Control", text: "Control" });
if (modifiers.meta) {
- tokens.push({
- id: "meta",
- label: platform === "windows" ? "Win" : "Super",
- });
+ const text = platform === "windows" ? "Win" : "Super";
+ tokens.push({ id: "meta", label: text, text });
}
- if (modifiers.alt) tokens.push({ id: "alt", label: "Alt" });
- if (modifiers.shift) tokens.push({ id: "shift", label: "Shift", icon: ArrowBigUp });
+ if (modifiers.alt) tokens.push({ id: "alt", label: "Alt", text: "Alt" });
+ if (modifiers.shift) tokens.push({ id: "shift", label: "Shift", glyph: "shift" });
}
- const keyToken = KEY_TOKENS[shortcut.key] ?? { label: shortcut.key };
+ const keyToken = KEY_TOKENS[shortcut.key] ?? { label: shortcut.key, text: shortcut.key };
tokens.push({ id: `key-${shortcut.key}`, ...keyToken });
return tokens;
}
+function renderTokenContent({ label, text, glyph }: ShortcutToken) {
+ if (glyph) return <KbdGlyph name={glyph} />;
+ const display = text ?? label;
+ if (display === ",") {
+ return <span className="inline-block -translate-y-[0.04em]">{display}</span>;
+ }
+ return display;
+}
+
+function isSingleCompactToken(token: ShortcutToken): boolean {
+ if (token.glyph) return true;
+ return (token.text ?? token.label).length <= 1;
+}
+
+export type ShortcutKeycapsLayout = "pill" | "split";
+
export function ShortcutKeycaps({
shortcut,
platform = getShortcutPlatform(),
size = "sm",
+ layout = "pill",
+ tone = "default",
decorative = false,
className,
keyClassName,
}: {
shortcut: ShortcutChord;
platform?: ShortcutPlatform;
- size?: "sm" | "md";
+ size?: KbdSize;
+ /**
+ * `pill` (default) groups a chord into one quiet keycap for dense chrome
+ * (palettes, tooltips, buttons). `split` separates each key for Settings and
+ * shortcut recording where individual physical keys are the subject.
+ */
+ layout?: ShortcutKeycapsLayout;
+ tone?: KbdTone;
/** Hide a redundant hint when its parent already names the action. */
decorative?: boolean;
className?: string;
keyClassName?: string;
}) {
const accessibleLabel = formatShortcut(shortcut, platform);
+ const tokens = shortcutTokens(shortcut, platform);
+
+ if (layout === "pill") {
+ const compact = tokens.length === 1 && isSingleCompactToken(tokens[0]!);
+ return (
+ <span
+ className={cn("inline-flex items-center", className)}
+ role={decorative ? undefined : "img"}
+ aria-label={decorative ? undefined : accessibleLabel}
+ aria-hidden={decorative || undefined}
+ data-slot="shortcut-keycaps"
+ data-layout="pill"
+ >
+ <Kbd
+ aria-hidden="true"
+ size={size}
+ tone={tone}
+ compact={compact}
+ className={keyClassName}
+ >
+ {tokens.map((token) => (
+ <span
+ key={token.id}
+ title={token.label}
+ data-shortcut-key={token.id}
+ className="inline-flex items-center justify-center"
+ >
+ {renderTokenContent(token)}
+ </span>
+ ))}
+ </Kbd>
+ </span>
+ );
+ }
return (
<span
@@ -105,22 +158,20 @@ export function ShortcutKeycaps({
aria-label={decorative ? undefined : accessibleLabel}
aria-hidden={decorative || undefined}
data-slot="shortcut-keycaps"
+ data-layout="split"
>
- {shortcutTokens(shortcut, platform).map(({ id, label, text, icon: Icon }) => (
+ {tokens.map((token) => (
<Kbd
- key={id}
+ key={token.id}
aria-hidden="true"
- title={label}
- data-shortcut-key={id}
- className={cn(
- "border border-border/70 bg-muted/80 shadow-[0_1px_0_0_color-mix(in_oklab,var(--border)_70%,transparent)]",
- size === "md"
- ? "h-7 min-w-7 rounded-md px-1.5 text-caption [&_svg]:size-3.5"
- : "h-5 min-w-5 px-1 text-micro [&_svg]:size-3",
- keyClassName,
- )}
+ title={token.label}
+ data-shortcut-key={token.id}
+ size={size}
+ tone={tone}
+ compact={isSingleCompactToken(token)}
+ className={keyClassName}
>
- {Icon ? <Icon aria-hidden="true" strokeWidth={1.8} /> : (text ?? label)}
+ {renderTokenContent(token)}
</Kbd>
))}
</span>
diff --git a/packages/views/dev-toolbar/actions-panel.tsx b/packages/views/dev-toolbar/actions-panel.tsx
index 601e781aa9..fc6a4b9dfe 100644
--- a/packages/views/dev-toolbar/actions-panel.tsx
+++ b/packages/views/dev-toolbar/actions-panel.tsx
@@ -5,10 +5,11 @@ import { useQueryClient } from "@tanstack/react-query";
import { toast } from "sonner";
import { useAuthStore } from "@multica/core/auth";
import { useDevActionsStore } from "@multica/core/dev-actions";
-import { createShortcutChord, formatShortcut, shortcutMatchesEvent } from "@multica/core/shortcuts";
+import { createShortcutChord, shortcutMatchesEvent } from "@multica/core/shortcuts";
import { Popover, PopoverContent, PopoverTrigger } from "@multica/ui/components/ui/popover";
import { History, Pin, Play, Search, Zap } from "@multica/ui/icons";
import { cn } from "@multica/ui/lib/utils";
+import { ShortcutKeycaps } from "../common/shortcut-keycaps";
import {
blockedReason,
commandTitle,
@@ -317,7 +318,7 @@ export function ActionsPanel({ wsId, onClose }: { wsId: string | null; onClose:
onKeyDown={onSearchKey}
className="min-w-0 flex-1 bg-transparent text-body text-foreground outline-none placeholder:text-muted-foreground"
/>
- <kbd className="shrink-0 font-mono text-micro text-muted-foreground">{formatShortcut(OPEN_SHORTCUT)}</kbd>
+ <ShortcutKeycaps shortcut={OPEN_SHORTCUT} decorative className="shrink-0" />
</div>
{query.trim() ? (
<SearchResults
diff --git a/packages/views/issues/components/annotation-composer.tsx b/packages/views/issues/components/annotation-composer.tsx
index 17a2a6ad99..45958d44e7 100644
--- a/packages/views/issues/components/annotation-composer.tsx
+++ b/packages/views/issues/components/annotation-composer.tsx
@@ -151,7 +151,7 @@ export function AnnotationComposer({
<Button size="sm" disabled={!annotation.note.trim() || !canSave || busy} onClick={save}
aria-label={t(($) => existing ? $.reply.annotations.save : $.reply.annotations.confirm_add)}>
{t(($) => existing ? $.reply.annotations.save_short : $.reply.annotations.confirm_add_short)}
- <ShortcutKeycaps shortcut={ENTER} decorative />
+ <ShortcutKeycaps shortcut={ENTER} tone="on-primary" decorative />
</Button>
</div>
</div>}
diff --git a/packages/views/issues/components/wakeup-create.tsx b/packages/views/issues/components/wakeup-create.tsx
index 199b170984..ddb8b38d2a 100644
--- a/packages/views/issues/components/wakeup-create.tsx
+++ b/packages/views/issues/components/wakeup-create.tsx
@@ -353,9 +353,9 @@ export function WakeupCreateForm({
{sendShortcut && !create.isPending ? (
<ShortcutKeycaps
shortcut={sendShortcut}
+ tone="on-primary"
decorative
className="ml-1 max-sm:hidden"
- keyClassName="border-background/30 bg-background/15 text-primary-foreground shadow-none"
/>
) : null}
</Button>
diff --git a/packages/views/layout/rail-workspaces.tsx b/packages/views/layout/rail-workspaces.tsx
index bd9a27fa73..0ff2b81e2c 100644
--- a/packages/views/layout/rail-workspaces.tsx
+++ b/packages/views/layout/rail-workspaces.tsx
@@ -2,7 +2,7 @@
import { useMemo, useState, type MouseEvent } from "react";
import { useQuery } from "@tanstack/react-query";
-import { AppWindow, ArrowBigUp, Check, Link2, Mail, Pin, PinOff, Plus, Settings, UserPlus } from "@multica/ui/icons";
+import { AppWindow, Check, Link2, Mail, Pin, PinOff, Plus, Settings, UserPlus } from "@multica/ui/icons";
import { toast } from "sonner";
import { copyText } from "@multica/ui/lib/clipboard";
import type { api } from "@multica/core/api";
@@ -31,7 +31,7 @@ import {
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@multica/ui/components/ui/dropdown-menu";
-import { Kbd, KbdGroup } from "@multica/ui/components/ui/kbd";
+import { Kbd, KbdGlyph } from "@multica/ui/components/ui/kbd";
import { cn } from "@multica/ui/lib/utils";
import { useRowMenu } from "../common/point-menu";
import { useT } from "../i18n";
@@ -67,12 +67,10 @@ function NewWindowButton({ onOpen }: { onOpen: () => void }) {
label={label}
side="right"
shortcut={
- <KbdGroup>
- <Kbd>
- <ArrowBigUp />
- </Kbd>
- <Kbd>{t(($) => $.rail.open_in_new_window_click)}</Kbd>
- </KbdGroup>
+ <Kbd>
+ <KbdGlyph name="shift" />
+ <span>{t(($) => $.rail.open_in_new_window_click)}</span>
+ </Kbd>
}
>
<button
diff --git a/packages/views/modals/create-issue.tsx b/packages/views/modals/create-issue.tsx
index c4260be48e..1fa9fc8fd2 100644
--- a/packages/views/modals/create-issue.tsx
+++ b/packages/views/modals/create-issue.tsx
@@ -983,9 +983,9 @@ export function ManualCreatePanel({
{sendShortcut ? (
<ShortcutKeycaps
shortcut={sendShortcut}
+ tone="on-primary"
decorative
className="ml-1 max-sm:hidden"
- keyClassName="border-background/30 bg-background/15 text-primary-foreground shadow-none"
/>
) : null}
</>
diff --git a/packages/views/modals/feedback.tsx b/packages/views/modals/feedback.tsx
index 55ba00bc76..797a695433 100644
--- a/packages/views/modals/feedback.tsx
+++ b/packages/views/modals/feedback.tsx
@@ -199,9 +199,9 @@ export function FeedbackModal({
{sendShortcut ? (
<ShortcutKeycaps
shortcut={sendShortcut}
+ tone="on-primary"
decorative
className="ml-1"
- keyClassName="border-background/30 bg-background/15 text-primary-foreground shadow-none"
/>
) : null}
</Button>
diff --git a/packages/views/modals/quick-create-issue.tsx b/packages/views/modals/quick-create-issue.tsx
index b561e65ebc..9a0f93a49c 100644
--- a/packages/views/modals/quick-create-issue.tsx
+++ b/packages/views/modals/quick-create-issue.tsx
@@ -679,9 +679,9 @@ export function AgentCreatePanel({
// footer reflows at.
<ShortcutKeycaps
shortcut={sendShortcut}
+ tone="on-primary"
decorative
className="ml-1 max-sm:hidden"
- keyClassName="border-background/30 bg-background/15 text-primary-foreground shadow-none"
/>
) : null}
</>
diff --git a/packages/views/modals/run-confirm.tsx b/packages/views/modals/run-confirm.tsx
index 3a3d372e1d..de53d1a47d 100644
--- a/packages/views/modals/run-confirm.tsx
+++ b/packages/views/modals/run-confirm.tsx
@@ -262,9 +262,9 @@ export function RunConfirmModal({
{sendShortcut ? (
<ShortcutKeycaps
shortcut={sendShortcut}
+ tone="on-primary"
decorative
className="ml-1"
- keyClassName="border-background/30 bg-background/15 text-primary-foreground shadow-none"
/>
) : null}
</>
diff --git a/packages/views/search/footer.tsx b/packages/views/search/footer.tsx
index 054f2690fb..b28cb94f2d 100644
--- a/packages/views/search/footer.tsx
+++ b/packages/views/search/footer.tsx
@@ -25,7 +25,7 @@ function PrefixHint({ prefix, children }: { prefix: string; children: ReactNode
return (
<Hint
keys={
- <Kbd aria-hidden="true" className="h-5 min-w-5 border border-border/70 bg-muted/80 px-1 text-micro">
+ <Kbd aria-hidden="true" compact>
{prefix}
</Kbd>
}
diff --git a/packages/views/settings/components/keyboard-shortcuts-tab.tsx b/packages/views/settings/components/keyboard-shortcuts-tab.tsx
index c0544fa5bb..0ce3bd0f04 100644
--- a/packages/views/settings/components/keyboard-shortcuts-tab.tsx
+++ b/packages/views/settings/components/keyboard-shortcuts-tab.tsx
@@ -327,7 +327,7 @@ function ShortcutRow({
{t(($) => $.shortcuts.recording)}
</span>
) : shortcut ? (
- <ShortcutKeycaps shortcut={shortcut} decorative />
+ <ShortcutKeycaps shortcut={shortcut} layout="split" decorative />
) : (
<span className="font-sans font-normal text-muted-foreground">
{t(($) => $.shortcuts.unassigned)}
@@ -372,7 +372,7 @@ function ShortcutRow({
function FixedShortcutRow({ label, shortcut }: { label: string; shortcut: ShortcutChord }) {
return (
<SettingsRow label={label}>
- <ShortcutKeycaps shortcut={shortcut} size="md" className="justify-end" />
+ <ShortcutKeycaps shortcut={shortcut} size="md" layout="split" className="justify-end" />
</SettingsRow>
);
}
diff --git a/packages/views/settings/components/voice-input-tab.tsx b/packages/views/settings/components/voice-input-tab.tsx
index 3322542ce9..9d76a88400 100644
--- a/packages/views/settings/components/voice-input-tab.tsx
+++ b/packages/views/settings/components/voice-input-tab.tsx
@@ -138,7 +138,7 @@ function ShortcutRow() {
>
<div className="flex items-center gap-3">
{shortcut ? (
- <ShortcutKeycaps shortcut={shortcut} size="md" />
+ <ShortcutKeycaps shortcut={shortcut} size="md" layout="split" />
) : (
<span className="text-caption text-muted-foreground">
{t(($) => $.voice_input.shortcut.unassigned)}