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/toolbar/+page.svelte

660 lines
21 KiB

<script lang="ts">
import { Toolbar, type ToolbarSize, type ToolbarVariant } from '$uix/eidos/components/toolbar';
import { compileMorfo } from '$uix/morfo';
import { toolbarMorfo } from '@/uix/morfo/components/toolbar';
import { getActiveUix } from '$active-uix';
type Tab = 'live' | 'api' | 'morfo' | 'sema' | 'recipe' | 'a11y';
type Orientation = 'horizontal' | 'vertical';
type Direction = 'ltr' | 'rtl';
type GroupType = 'single' | 'multiple';
type TraceEntry = { event: string; family: string; intent?: string; at: number };
const uix = getActiveUix();
let tab = $state<Tab>('live');
let orientation = $state<Orientation>('horizontal');
let loop = $state(true);
let dir = $state<Direction>('ltr');
let size = $state<ToolbarSize>('md');
let variant = $state<ToolbarVariant>('surface');
let groupType = $state<GroupType>('multiple');
let groupDisabled = $state(false);
let buttonDisabled = $state(false);
let value = $state<string[]>(['bold']);
let labelText = $state('Formatting options');
const compiled = compileMorfo(toolbarMorfo);
const partsList = $derived([...compiled.parts.byKebab.values()]);
const events = $derived([...compiled.actions.byName.values()]);
let stageRef = $state<HTMLElement | null>(null);
let trace = $state<TraceEntry[]>([]);
$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();
});
function fmtTime(at: number): string {
const d = new Date(at);
return `${String(d.getSeconds()).padStart(2, '0')}.${String(d.getMilliseconds()).padStart(3, '0')}`;
}
const somaSnippet = $derived(
[
"<script lang='ts'>",
" import * as Toolbar from '$soma/components/toolbar';",
' let value = $state<string[]>([]);',
'</' + 'script>',
'',
'<Toolbar.Provider',
` aria-label="${labelText}"`,
orientation !== 'horizontal' && ` orientation="${orientation}"`,
!loop && ' loop={false}',
dir !== 'ltr' && ` dir="${dir}"`,
'>',
' <Toolbar.Button>Undo</Toolbar.Button>',
' <Toolbar.Button>Redo</Toolbar.Button>',
' <Toolbar.Separator />',
` <Toolbar.Group type="${groupType}" bind:value>`,
' <Toolbar.GroupItem value="bold">B</Toolbar.GroupItem>',
' <Toolbar.GroupItem value="italic">I</Toolbar.GroupItem>',
' </Toolbar.Group>',
' <Toolbar.Link href="/uix">Docs</Toolbar.Link>',
'</Toolbar.Provider>'
]
.filter(Boolean)
.join('\n')
);
const eidosSnippet = $derived(
[
"<script lang='ts'>",
" import { Toolbar } from '$uix/eidos/components/toolbar';",
' let value = $state<string[]>([]);',
'</' + 'script>',
'',
'<Toolbar',
` aria-label="${labelText}"`,
size !== 'md' && ` size="${size}"`,
variant !== 'surface' && ` variant="${variant}"`,
orientation !== 'horizontal' && ` orientation="${orientation}"`,
!loop && ' loop={false}',
dir !== 'ltr' && ` dir="${dir}"`,
'>',
' <Toolbar.Button>Undo</Toolbar.Button>',
' <Toolbar.Button>Redo</Toolbar.Button>',
' <Toolbar.Separator />',
` <Toolbar.Group type="${groupType}" bind:value>`,
' <Toolbar.GroupItem value="bold">B</Toolbar.GroupItem>',
' <Toolbar.GroupItem value="italic">I</Toolbar.GroupItem>',
' </Toolbar.Group>',
' <Toolbar.Link href="/uix">Docs</Toolbar.Link>',
'</Toolbar>'
]
.filter(Boolean)
.join('\n')
);
</script>
<div data-uix-canvas-inner>
<header>
<div data-uix-eyebrow>Controls · Toolbar</div>
<h1 data-uix-page-title>Toolbar</h1>
<p data-uix-page-lede>
Grouped action surface with WAI-ARIA toolbar semantics and roving tabindex. Soma owns keyboard
navigation, RTL, loop and group selection; Eidos only adds size, container variant and recipe
styling.
</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>{events.length}</span>
<span data-uix-meta-pill><span data-uix-meta-key>sizes</span>3</span>
<span data-uix-meta-pill><span data-uix-meta-key>variants</span>2</span>
<span data-uix-meta-pill>
<span data-uix-meta-key>apg</span>
<a href={toolbarMorfo.apg} target="_blank" rel="noreferrer">toolbar ↗</a>
</span>
</div>
</header>
<div data-uix-stage bind:this={stageRef}>
<div data-uix-stage-area>
<Toolbar {orientation} {loop} {dir} {size} {variant} aria-label={labelText}>
<Toolbar.Button disabled={buttonDisabled}>Undo</Toolbar.Button>
<Toolbar.Button>Redo</Toolbar.Button>
<Toolbar.Separator />
<Toolbar.Group type={groupType} bind:value disabled={groupDisabled}>
<Toolbar.GroupItem value="bold">B</Toolbar.GroupItem>
<Toolbar.GroupItem value="italic">I</Toolbar.GroupItem>
<Toolbar.GroupItem value="underline">U</Toolbar.GroupItem>
</Toolbar.Group>
<Toolbar.Separator />
<Toolbar.Link href="/uix/components">Docs</Toolbar.Link>
</Toolbar>
</div>
<div data-uix-stage-trace>
<span data-uix-stage-trace-key>trace</span>
{#if trace.length === 0}
<span>toggle a toolbar item to see sema events</span>
{:else}
{#each trace.slice(0, 3) as entry}
<span><span data-uix-stage-trace-event>{entry.event}</span> · {entry.family}{entry.intent ? ' · ' + entry.intent : ''}</span>
<span style="color: var(--uix-text-faint)">{fmtTime(entry.at)}</span>
{/each}
{/if}
<span style="margin-inline-start: auto;">
<span data-uix-stage-trace-key>selection</span>
{value.join(', ') || 'none'} · {orientation} · {dir}
</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>11</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 · {events.length}e</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>
Controls are grouped by layer. <span data-uix-layer-badge="soma">soma</span>
owns ARIA, keyboard, roving tab stop and group state;
<span data-uix-layer-badge="eidos">eidos</span> owns size and variant.
</p>
<div data-uix-subsection-head>
<span data-uix-layer-badge="soma">soma</span> props · keyboard + state
</div>
<div data-uix-controls>
<label data-uix-control>
<span data-uix-control-label>orientation</span>
<span data-uix-chips role="radiogroup">
{#each ['horizontal', 'vertical'] as o}
<button
data-uix-chip
data-active={orientation === o}
onclick={() => (orientation = o as Orientation)}>{o}</button
>
{/each}
</span>
</label>
<label data-uix-control>
<span data-uix-control-label>loop</span>
<span data-uix-switch
><input type="checkbox" bind:checked={loop} /><span data-uix-switch-label
>{loop ? 'on' : 'off'}</span
></span
>
</label>
<label data-uix-control>
<span data-uix-control-label>dir</span>
<span data-uix-chips role="radiogroup">
{#each ['ltr', 'rtl'] as d}
<button data-uix-chip data-active={dir === d} onclick={() => (dir = d as Direction)}
>{d}</button
>
{/each}
</span>
</label>
<label data-uix-control>
<span data-uix-control-label>group type</span>
<span data-uix-chips role="radiogroup">
{#each ['single', 'multiple'] as t}
<button
data-uix-chip
data-active={groupType === t}
onclick={() => {
groupType = t as GroupType;
value = t === 'single' ? value.slice(0, 1) : value;
}}>{t}</button
>
{/each}
</span>
</label>
<label data-uix-control>
<span data-uix-control-label>button disabled</span>
<span data-uix-switch
><input type="checkbox" bind:checked={buttonDisabled} /><span data-uix-switch-label
>{buttonDisabled ? 'on' : 'off'}</span
></span
>
</label>
<label data-uix-control>
<span data-uix-control-label>group disabled</span>
<span data-uix-switch
><input type="checkbox" bind:checked={groupDisabled} /><span data-uix-switch-label
>{groupDisabled ? 'on' : 'off'}</span
></span
>
</label>
</div>
<div data-uix-subsection-head>
<span data-uix-layer-badge="eidos">eidos</span> props · visual treatment
</div>
<div data-uix-controls>
<label data-uix-control>
<span data-uix-control-label>size</span>
<span data-uix-chips role="radiogroup">
{#each ['xs', 'sm', 'md', 'lg'] as s}
<button
data-uix-chip
data-active={size === s}
onclick={() => (size = s as ToolbarSize)}>{s}</button
>
{/each}
</span>
</label>
<label data-uix-control>
<span data-uix-control-label>variant</span>
<span data-uix-chips role="radiogroup">
{#each ['surface', 'outline', 'ghost'] as v}
<button
data-uix-chip
data-active={variant === v}
onclick={() => (variant = v as ToolbarVariant)}>{v}</button
>
{/each}
</span>
</label>
<label data-uix-control>
<span data-uix-control-label>aria-label</span>
<input type="text" bind:value={labelText} />
</label>
</div>
<div data-uix-code>
<div data-uix-code-head>
<span data-uix-layer-badge="soma">soma</span>
<span>headless · ARIA + roving behavior</span>
<span data-uix-code-lang>svelte</span>
</div>
<pre><code>{somaSnippet}</code></pre>
</div>
<div data-uix-code style="margin-top: var(--uix-space-3);">
<div data-uix-code-head>
<span data-uix-layer-badge="eidos">eidos</span>
<span>visual · adds size and variant</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>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Part</th><th>Props</th><th>Description</th></tr></thead>
<tbody>
<tr
><td class="name">Toolbar</td><td class="type"
>orientation, loop, dir, aria-label, size, variant</td
><td>Root toolbar. Must have accessible name.</td></tr
>
<tr
><td class="name">Button</td><td class="type">disabled</td><td
>Action item participating in roving tabindex.</td
></tr
>
<tr
><td class="name">Link</td><td class="type">href and anchor attrs</td><td
>Navigation item participating in roving tabindex.</td
></tr
>
<tr
><td class="name">Group</td><td class="type">type, value, disabled</td><td
>Single or multiple toggle group.</td
></tr
>
<tr
><td class="name">GroupItem</td><td class="type">value, disabled</td><td
>Toggle button with `aria-pressed`.</td
></tr
>
<tr
><td class="name">Separator</td><td class="type">div attrs</td><td
>Perpendicular visual/ARIA separator.</td
></tr
>
</tbody>
</table>
</div>
</section>
{/if}
{#if tab === 'morfo'}
<section data-uix-section>
<h2 data-uix-section-title>
<span data-uix-layer-badge="morfo">morfo</span> · declarative contract
</h2>
<p data-uix-section-desc>Source: <code>src/uix/morfo/components/toolbar.ts</code>.</p>
<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 class="type">"{toolbarMorfo.name}"</td></tr>
<tr><td class="name">kebab</td><td class="type">"{toolbarMorfo.kebab}"</td></tr>
<tr
><td class="name">scope</td><td class="type"
>[{toolbarMorfo.scope.map((s) => `"${s}"`).join(', ')}]</td
></tr
>
<tr
><td class="name">apg</td><td
><a href={toolbarMorfo.apg} target="_blank" rel="noreferrer">{toolbarMorfo.apg}</a
></td
></tr
>
<tr
><td class="name">parts.length</td><td class="default">{toolbarMorfo.parts.length}</td
></tr
>
<tr><td class="name">events.length</td><td class="default">{events.length}</td></tr>
</tbody>
</table>
</div>
<div data-uix-subsection-head>Parts</div>
<div data-uix-table-wrap>
<table data-uix-table>
<thead
><tr
><th>Part</th><th>Marker</th><th>Element</th><th>Role</th><th>States</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.role ?? '—'}</td>
<td class="default">{part.states.length ? part.states.join(' | ') : '—'}</td>
<td class="default">{part.optional ? 'yes' : 'no'}</td>
</tr>
{/each}
</tbody>
</table>
</div>
{#each toolbarMorfo.parts as rawPart}
{@const partAny = rawPart as unknown as {
kebab: string;
aria?: ReadonlyArray<{
attr: string;
value: { kind: string };
condition?: { when: string; prop?: string };
severity?: string;
}>;
keyboard?: ReadonlyArray<{ key: string; action: string }>;
}}
{@const dataAttrs = compiled.contracts.dataAttrsByPart.get(partAny.kebab) ?? []}
{@const ariaAttrs = partAny.aria ?? []}
{@const keyboard = partAny.keyboard ?? []}
{#if dataAttrs.length || ariaAttrs.length || keyboard.length}
<div data-uix-subsection-head>{partAny.kebab}</div>
{#if dataAttrs.length}
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>data-attr</th><th>Values</th><th>Source</th></tr></thead>
<tbody>
{#each dataAttrs as attr}
<tr
><td class="name">{attr.attr}</td><td class="type"
>{attr.values ? attr.values.join(' | ') : '—'}</td
><td class="default"
>{'value' in attr && attr.value
? (attr as { value: { kind: string } }).value.kind
: '—'}</td
></tr
>
{/each}
</tbody>
</table>
</div>
{/if}
{#if ariaAttrs.length}
<div data-uix-table-wrap style="margin-top: var(--uix-space-2);">
<table data-uix-table>
<thead
><tr><th>aria-attr</th><th>Source</th><th>Condition</th><th>Severity</th></tr
></thead
>
<tbody>
{#each ariaAttrs as a}
<tr
><td class="name">{a.attr}</td><td class="type">{a.value.kind}</td><td
class="default"
>{a.condition
? `when ${a.condition.when}${a.condition.prop ? ` (${a.condition.prop})` : ''}`
: 'always'}</td
><td class="default">{a.severity ?? 'required'}</td></tr
>
{/each}
</tbody>
</table>
</div>
{/if}
{#if keyboard.length}
<div data-uix-table-wrap style="margin-top: var(--uix-space-2);">
<table data-uix-table>
<thead><tr><th>key</th><th>action</th></tr></thead>
<tbody>
{#each keyboard as kb}
<tr
><td><span data-uix-kbd>{kb.key}</span></td><td class="default"
>{kb.action}</td
></tr
>
{/each}
</tbody>
</table>
</div>
{/if}
{/if}
{/each}
</section>
{/if}
{#if tab === 'sema'}
<section data-uix-section>
<h2 data-uix-section-title>
<span data-uix-layer-badge="sema">sema</span> · events + perceptual signature
</h2>
<p data-uix-section-desc>
Group items emit <code>commit-toggle</code> when their pressed state changes. Toolbar navigation
itself remains structural keyboard behavior, not a perceptual event.
</p>
<div data-uix-table-wrap>
<table data-uix-table>
<thead
><tr
><th>Name</th><th>Family</th><th>Verb</th><th>Sequence</th><th>Target</th><th>Play</th
></tr
></thead
>
<tbody>
{#each events as action}
<tr>
<td class="name">{action.name}</td>
<td class="type">{action.semantic.family}</td>
<td>{action.semantic.verb ?? '—'}</td>
<td>{action.semantic.sequence ?? 'pre'}</td>
<td>{action.target}</td>
<td>
<button
data-uix-play
onclick={() => {
const target = stageRef?.querySelector(
'[data-toolbar]'
) as HTMLElement | null;
if (!target) return;
void uix.events?.emit({
name: action.name,
family: action.semantic.family,
target
});
}}>▶ play</button
>
</td>
</tr>
{/each}
</tbody>
</table>
</div>
</section>
{/if}
{#if tab === 'recipe'}
<section data-uix-section>
<h2 data-uix-section-title>Eidos recipe</h2>
<p data-uix-section-desc>
Selectors at <code>src/uix/eidos/components/toolbar/toolbar.css</code>. The recipe targets
Morfo markers and the Eidos-only root attrs <code>data-size</code> and
<code>data-variant</code>.
</p>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Selector</th><th>Source</th></tr></thead>
<tbody>
<tr
><td class="name">[data-toolbar][data-orientation]</td><td
><span data-uix-tag data-kind="soma">morfo</span></td
></tr
>
<tr
><td class="name">[data-toolbar][data-size / data-variant]</td><td
><span data-uix-tag data-kind="eidos">eidos</span></td
></tr
>
<tr
><td class="name">[data-toolbar-button] / [data-toolbar-link]</td><td
><span data-uix-tag data-kind="soma">morfo</span></td
></tr
>
<tr
><td class="name">[data-toolbar-group-item][data-state='on']</td><td
><span data-uix-tag data-kind="soma">morfo</span></td
></tr
>
<tr
><td class="name">[data-toolbar-separator][data-orientation]</td><td
><span data-uix-tag data-kind="soma">morfo</span></td
></tr
>
</tbody>
</table>
</div>
</section>
{/if}
{#if tab === 'a11y'}
<section data-uix-section>
<h2 data-uix-section-title>Accessibility</h2>
<p data-uix-section-desc>
Follows the APG <a href={toolbarMorfo.apg} target="_blank" rel="noreferrer"
>toolbar pattern</a
>. The root must have an accessible name.
</p>
<div data-uix-subsection-head>Keyboard</div>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Key</th><th>Action</th></tr></thead>
<tbody>
<tr
><td><span data-uix-kbd>Tab</span></td><td
>Enter or exit the toolbar's single tab stop.</td
></tr
>
<tr
><td><span data-uix-kbd>ArrowRight</span> / <span data-uix-kbd>ArrowLeft</span></td
><td>Move next/previous in horizontal orientation. RTL-aware.</td></tr
>
<tr
><td><span data-uix-kbd>ArrowDown</span> / <span data-uix-kbd>ArrowUp</span></td><td
>Move next/previous in vertical orientation.</td
></tr
>
<tr
><td><span data-uix-kbd>Home</span> / <span data-uix-kbd>End</span></td><td
>Jump to first/last item.</td
></tr
>
<tr
><td><span data-uix-kbd>Enter</span> / <span data-uix-kbd>Space</span></td><td
>Activate button or toggle item.</td
></tr
>
</tbody>
</table>
</div>
<div data-uix-subsection-head>ARIA contract</div>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Part</th><th>Attribute</th><th>Value</th></tr></thead>
<tbody>
<tr
><td class="name">root</td><td>role / aria-orientation</td><td class="type"
>toolbar / orientation</td
></tr
>
<tr><td class="name">group</td><td>role</td><td class="type">group</td></tr>
<tr
><td class="name">group-item</td><td>aria-pressed</td><td class="type"
>true / false</td
></tr
>
<tr
><td class="name">separator</td><td>role / aria-orientation</td><td class="type"
>separator / perpendicular orientation</td
></tr
>
</tbody>
</table>
</div>
</section>
{/if}
</div>

Powered by TurnKey Linux.