You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte-kit-vice/web/routes/uix/components/kbd/+page.svelte

397 lines
15 KiB

<script lang="ts">
import { Kbd, type KbdVariant, type KbdSize } from '$uix/eidos/components/kbd';
import { compileMorfo } from '$uix/morfo';
import { kbdMorfo } from '@/uix/morfo/components/kbd';
type Tab = 'live' | 'api' | 'morfo' | 'sema' | 'recipe' | 'a11y';
type TraceEntry = { event: string; family: string; intent?: string; at: number };
let tab = $state<Tab>('live');
let trace = $state<TraceEntry[]>([]);
let stageRef = $state<HTMLElement | null>(null);
let variant = $state<KbdVariant>('surface');
let size = $state<KbdSize | ''>('');
let content = $state<string>('Ctrl');
const variants: KbdVariant[] = ['surface', 'outline', 'ghost'];
const sizes: KbdSize[] = ['xxs', 'xs', 'sm', 'md', 'lg', 'xl'];
const compiled = compileMorfo(kbdMorfo);
const partsList = $derived([...compiled.parts.byKebab.values()]);
const events = $derived([...compiled.actions.byName.values()]);
$effect(() => {
const el = stageRef;
if (!el) return;
const obs = new MutationObserver((mutations) => {
for (const m of mutations) {
if (m.attributeName !== 'data-event') continue;
const target = m.target as Element;
const ev = target.getAttribute('data-event');
if (!ev) continue;
trace = [
{
event: ev,
family: target.getAttribute('data-event-family') ?? '—',
intent: target.getAttribute('data-event-intent') ?? undefined,
at: Date.now()
},
...trace
].slice(0, 6);
}
});
obs.observe(el, { attributes: true, subtree: true, attributeFilter: ['data-event'] });
return () => obs.disconnect();
});
const eidosSnippet = $derived(
[
"<script lang='ts'>",
" import { Kbd } from '$uix/eidos/components/kbd';",
'</' + 'script>',
'',
'<Kbd',
variant !== 'surface' && ` variant="${variant}"`,
size && ` size="${size}"`,
'>',
' ' + content,
'</Kbd>'
]
.filter(Boolean)
.join('\n')
);
</script>
<div data-uix-canvas-inner>
<header>
<div data-uix-eyebrow>Typography · Kbd</div>
<h1 data-uix-page-title>Kbd</h1>
<p data-uix-page-lede>
Keyboard shortcut typography primitive. Renders <code>{`<kbd>`}</code> with a small chrome
(border + background + inner padding) so the key looks like a physical cap. Inline within
prose — for shortcut hints, key sequences. Single part. Eidos-native: no soma backing, no
semantic events.
</p>
<div data-uix-page-meta>
<span data-uix-meta-pill>
<span data-uix-meta-key>parts</span>{compiled.parts.order.length}
</span>
<span data-uix-meta-pill>
<span data-uix-meta-key>events</span>0
</span>
<span data-uix-meta-pill>
<span data-uix-meta-key>variants</span>3
</span>
<span data-uix-meta-pill>
<span data-uix-meta-key>sizes</span>6
</span>
<span data-uix-meta-pill>
<span data-uix-meta-key>scope</span>eidos
</span>
</div>
</header>
<div data-uix-stage>
<div data-uix-stage-area bind:this={stageRef}>
<p
style="max-inline-size: 38rem; padding: var(--space-3); border: 1px dashed var(--color-neutral-border); border-radius: var(--radius-md); font: inherit; display: flex; align-items: center; gap: 0.4em; flex-wrap: wrap;"
>
Press
<Kbd {variant} size={size || undefined}>{content}</Kbd>
<span>+</span>
<Kbd {variant} size={size || undefined}>K</Kbd>
<span>to open command palette. Or just</span>
<Kbd {variant} size={size || undefined}>Esc</Kbd>
<span>to dismiss.</span>
</p>
</div>
<div data-uix-stage-trace>
<span data-uix-stage-trace-key>trace</span>
<span>{trace.length === 0 ? 'no semantic events' : `${trace.length} event(s)`}</span>
<span style="color: var(--uix-text-faint)">·</span>
<span data-uix-stage-trace-key>variant</span>
<span>{variant}</span>
<span style="margin-inline-start: auto;">
<span data-uix-stage-trace-key>size</span> {size || 'inherit'}
</span>
</div>
</div>
<div data-uix-tabs role="tablist">
<button data-uix-tab data-active={tab === 'live'} onclick={() => (tab = 'live')}>Live</button>
<button data-uix-tab data-active={tab === 'api'} onclick={() => (tab = 'api')}>
API <span data-uix-tab-count>5</span>
</button>
<button data-uix-tab data-active={tab === 'morfo'} onclick={() => (tab = 'morfo')}>
<span data-uix-layer-badge="morfo">morfo</span>
<span data-uix-tab-count>{partsList.length}p · 0e</span>
</button>
<button data-uix-tab data-active={tab === 'sema'} onclick={() => (tab = 'sema')}>
<span data-uix-layer-badge="sema">sema</span>
<span data-uix-tab-count>{events.length}</span>
</button>
<button data-uix-tab data-active={tab === 'recipe'} onclick={() => (tab = 'recipe')}
>Recipe</button
>
<button data-uix-tab data-active={tab === 'a11y'} onclick={() => (tab = 'a11y')}>A11y</button>
</div>
{#if tab === 'live'}
<section data-uix-section>
<h2 data-uix-section-title>Controls</h2>
<p data-uix-section-desc>
Kbd is eidos-native — no <span data-uix-layer-badge="soma">soma</span> split. The
<code>variant</code>
picks chrome (surface = physical-key feel, outline = thin border, ghost = mono only).
</p>
<div data-uix-subsection-head>
<span data-uix-layer-badge="eidos">eidos</span> props · key cap
</div>
<div data-uix-controls>
<label data-uix-control>
<span data-uix-control-label>variant</span>
<span data-uix-chips role="radiogroup">
{#each variants as opt}
<button data-uix-chip data-active={variant === opt} onclick={() => (variant = opt)}
>{opt}</button
>
{/each}
</span>
</label>
<label data-uix-control>
<span data-uix-control-label>size</span>
<span data-uix-chips role="radiogroup">
<button data-uix-chip data-active={size === ''} onclick={() => (size = '')}
>inherit</button
>
{#each sizes as opt}
<button data-uix-chip data-active={size === opt} onclick={() => (size = opt)}
>{opt}</button
>
{/each}
</span>
</label>
<label data-uix-control>
<span data-uix-control-label>first key content</span>
<input type="text" bind:value={content} style="inline-size: 8rem;" />
</label>
</div>
<div data-uix-subsection-head>
<span data-uix-layer-badge="eidos">eidos</span> variant gallery
</div>
<div
data-uix-controls
style="grid-template-columns: 1fr; gap: var(--uix-space-2);"
>
<div
style="display: flex; gap: 0.5em; align-items: center; flex-wrap: wrap; padding: var(--space-3); border: 1px dashed var(--color-neutral-border); border-radius: var(--radius-md);"
>
<span style="color: var(--color-content-muted); min-inline-size: 6em;">surface</span>
<Kbd variant="surface">Ctrl</Kbd>
<Kbd variant="surface">Shift</Kbd>
<Kbd variant="surface">Esc</Kbd>
<Kbd variant="surface" size="xs">F1</Kbd>
<Kbd variant="surface" size="lg">Enter</Kbd>
</div>
<div
style="display: flex; gap: 0.5em; align-items: center; flex-wrap: wrap; padding: var(--space-3); border: 1px dashed var(--color-neutral-border); border-radius: var(--radius-md);"
>
<span style="color: var(--color-content-muted); min-inline-size: 6em;">outline</span>
<Kbd variant="outline">Ctrl</Kbd>
<Kbd variant="outline">Shift</Kbd>
<Kbd variant="outline">Esc</Kbd>
<Kbd variant="outline" size="xs">F1</Kbd>
<Kbd variant="outline" size="lg">Enter</Kbd>
</div>
<div
style="display: flex; gap: 0.5em; align-items: center; flex-wrap: wrap; padding: var(--space-3); border: 1px dashed var(--color-neutral-border); border-radius: var(--radius-md);"
>
<span style="color: var(--color-content-muted); min-inline-size: 6em;">ghost</span>
<Kbd variant="ghost">Ctrl</Kbd>
<Kbd variant="ghost">Shift</Kbd>
<Kbd variant="ghost">Esc</Kbd>
<Kbd variant="ghost" size="xs">F1</Kbd>
<Kbd variant="ghost" size="lg">Enter</Kbd>
</div>
</div>
<!-- ── Code snippet (eidos-native — no soma layer) ──────────────── -->
<div data-uix-code>
<div data-uix-code-head>
<span data-uix-layer-badge="eidos">eidos</span>
<span>visual · variant + size</span>
<span data-uix-code-lang>svelte</span>
</div>
<pre><code>{eidosSnippet}</code></pre>
</div>
</section>
{/if}
{#if tab === 'api'}
<section data-uix-section>
<h2 data-uix-section-title>API reference</h2>
<p data-uix-section-desc>
Kbd composes inline within prose. Compose multiple Kbds with literal separators for
sequences: <code>{`<Kbd>Ctrl</Kbd> + <Kbd>K</Kbd>`}</code>.
</p>
<div data-uix-subsection-head>Props</div>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Prop</th><th>Type</th><th>Default</th><th>Notes</th></tr></thead>
<tbody>
<tr><td class="name">variant</td><td class="type">'surface' | 'outline' | 'ghost'</td><td class="default">'surface'</td><td>Visual chrome.</td></tr>
<tr><td class="name">size</td><td class="type">'xxs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl'</td><td class="default">inherit</td><td>Maps to <code>{`var(--font-size-{key})`}</code>.</td></tr>
<tr><td class="name">as</td><td class="type">string</td><td class="default">'kbd'</td><td>Override rendered tag.</td></tr>
<tr><td class="name">tagStyle</td><td class="type">string</td><td class="default">—</td><td>Extra inline CSS.</td></tr>
</tbody>
</table>
</div>
<div data-uix-subsection-head>Composability examples</div>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Use case</th><th>Snippet</th></tr></thead>
<tbody>
<tr>
<td class="name">Single key</td>
<td><code>{`<Kbd>Esc</Kbd>`}</code></td>
</tr>
<tr>
<td class="name">Two-key shortcut</td>
<td><code>{`<Kbd>Ctrl</Kbd> + <Kbd>K</Kbd>`}</code></td>
</tr>
<tr>
<td class="name">Sequence</td>
<td><code>{`<Kbd>g</Kbd> then <Kbd>h</Kbd>`}</code></td>
</tr>
<tr>
<td class="name">Inline ghost (Markdown look)</td>
<td><code>{`<Kbd variant="ghost">space</Kbd>`}</code></td>
</tr>
<tr>
<td class="name">Inside a Heading</td>
<td>
<code>{`<Heading level={3}>Press <Kbd size="sm">Tab</Kbd> to switch</Heading>`}</code>
</td>
</tr>
</tbody>
</table>
</div>
<div data-uix-subsection-head>Reference comparison</div>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Library</th><th>Closest equivalent</th><th>Difference</th></tr></thead>
<tbody>
<tr><td class="name">radix-themes</td><td><code>&lt;Kbd&gt;</code></td><td>Radix offers size only; UIX adds variant.</td></tr>
<tr><td class="name">chakra-ui</td><td><code>&lt;Kbd&gt;</code></td><td>Chakra uses <code>colorScheme</code>; UIX has variant.</td></tr>
<tr><td class="name">mantine</td><td><code>&lt;Kbd&gt;</code></td><td>Mantine ships a single visual; UIX has 3 variants.</td></tr>
<tr><td class="name">MDN <code>&lt;kbd&gt;</code></td><td>HTML primitive</td><td>UIX wraps the native element with the foundation tokens.</td></tr>
</tbody>
</table>
</div>
</section>
{/if}
{#if tab === 'morfo'}
<section data-uix-section>
<h2 data-uix-section-title>Morfo contract</h2>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Field</th><th>Value</th></tr></thead>
<tbody>
<tr><td class="name">name</td><td>{kbdMorfo.name}</td></tr>
<tr><td class="name">kebab</td><td><code>{kbdMorfo.kebab}</code></td></tr>
<tr><td class="name">scope</td><td>{kbdMorfo.scope.join(', ')}</td></tr>
<tr><td class="name">parts</td><td>{partsList.length}</td></tr>
<tr><td class="name">events</td><td>0</td></tr>
</tbody>
</table>
</div>
<div data-uix-subsection-head>Parts</div>
<div data-uix-table-wrap>
<table data-uix-table>
<thead
><tr
><th>kebab</th><th>marker</th><th>element</th><th>archetype</th><th>optional</th
></tr
></thead
>
<tbody>
{#each partsList as part}
<tr>
<td class="name">{part.kebab}</td>
<td><code data-uix-part-marker>[{part.marker}]</code></td>
<td class="type">&lt;{part.defaultElement}&gt;</td>
<td class="type">{part.archetype}</td>
<td class="default">{part.optional ? 'yes' : 'no'}</td>
</tr>
{/each}
</tbody>
</table>
</div>
<p data-uix-section-desc style="margin-top: var(--uix-space-4);">
The Provider stamps <code>data-kbd</code> on the rendered <code>{`<kbd>`}</code> tag plus
<code>data-variant</code>.
</p>
</section>
{/if}
{#if tab === 'sema'}
<section data-uix-section>
<h2 data-uix-section-title>
<span data-uix-layer-badge="sema">sema</span> · events
</h2>
<p data-uix-section-desc>
Kbd declares no semantic events. The primitive is a label for a shortcut — the actual
shortcut handler lives on the consumer (a Toolbar button, a global key handler). If
binding the visual to a real shortcut, use a synced state with the handler that owns
the verb.
</p>
</section>
{/if}
{#if tab === 'recipe'}
<section data-uix-section>
<h2 data-uix-section-title>Eidos recipe</h2>
<p data-uix-section-desc>
Recipe lives in <code>src/uix/eidos/components/kbd/kbd.css</code>. Base mono typography
from <code>--style-code-font-family</code>; chrome via <code>data-variant</code>.
</p>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Selector</th><th>Owner</th><th>Purpose</th></tr></thead>
<tbody>
<tr><td class="name"><code>[data-kbd]</code></td><td><span data-uix-tag data-kind="morfo">morfo</span></td><td>Provider marker. Base mono cap.</td></tr>
<tr><td class="name"><code>{`[data-kbd][data-variant='surface']`}</code></td><td><span data-uix-tag data-kind="eidos">eidos</span></td><td>Filled cap with bottom-emphasized border.</td></tr>
<tr><td class="name"><code>{`[data-kbd][data-variant='outline']`}</code></td><td><span data-uix-tag data-kind="eidos">eidos</span></td><td>Outlined cap, transparent fill.</td></tr>
<tr><td class="name"><code>{`[data-kbd][data-variant='ghost']`}</code></td><td><span data-uix-tag data-kind="eidos">eidos</span></td><td>Mono font only, no chrome.</td></tr>
</tbody>
</table>
</div>
</section>
{/if}
{#if tab === 'a11y'}
<section data-uix-section>
<h2 data-uix-section-title>Accessibility</h2>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Concern</th><th>Contract</th></tr></thead>
<tbody>
<tr><td class="name">Role</td><td>Native HTML <code>{`<kbd>`}</code> semantics. AT announce as "keyboard input".</td></tr>
<tr><td class="name">Multi-key sequences</td><td>Compose multiple Kbds with literal separators ("+", " then ", " ↓ "). AT read the sequence in order.</td></tr>
<tr><td class="name">Color contrast</td><td>Surface variant uses neutral palette tokens meeting WCAG AA on foundation surfaces.</td></tr>
<tr><td class="name">Selectable text</td><td><code>user-select: none</code> by default. Toggle via <code>tagStyle</code> if the consumer wants the key text selectable.</td></tr>
</tbody>
</table>
</div>
</section>
{/if}
</div>

Powered by TurnKey Linux.