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

816 lines
32 KiB

<script lang="ts">
import {
ToggleGroup,
type ToggleGroupSize,
type ToggleGroupVariant,
type ToggleGroupColor,
type ToggleGroupSelectionMode
} from '$uix/eidos/components/toggle-group';
import type { Orientation } from '$soma/types';
import { compileMorfo } from '$uix/morfo';
import { toggleGroupMorfo } from '@/uix/morfo/components/toggle-group';
import { getActiveUix } from '$active-uix';
import { page } from '$app/state';
import { colorValue, PALETTE_SCALES } from '../../lib/harness.svelte';
import TokensPanel from '../../lib/TokensPanel.svelte';
const uix = getActiveUix();
const params = page.url.searchParams;
type Tab = 'live' | 'api' | 'morfo' | 'sema' | 'recipe' | 'tokens'
| 'a11y';
let tab = $state<Tab>('live');
// ── Live state ──────────────────────────────────────────────────
const selectionModes: ToggleGroupSelectionMode[] = ['single', 'multiple'];
const variants: ToggleGroupVariant[] = ['solid', 'outline', 'ghost'];
// Roles/sentinels + the 33 palette scales — `color` accepts any (ComponentColor, THM-2 §25.5).
const colors: ToggleGroupColor[] = [
'primary',
'neutral',
'affirm',
'risk',
'threat',
'absent',
'unknown',
...PALETTE_SCALES
];
const sizes: ToggleGroupSize[] = ['xs', 'sm', 'md', 'lg', 'xl'];
const orientations: Orientation[] = ['horizontal', 'vertical'];
let selectionMode = $state<ToggleGroupSelectionMode>('single');
let value = $state<string[]>(['bold']);
let variant = $state<ToggleGroupVariant>('outline');
let color = $state<ToggleGroupColor>('neutral');
let customColor = $state('#8e4ec6');
let size = $state<ToggleGroupSize>('md');
let orientation = $state<Orientation>('horizontal');
let attached = $state(true);
let block = $state(false);
let disabled = $state(params.get('perm.disabled') === 'true');
let loop = $state(true);
let iconOnly = $state(false);
let italicDisabled = $state(false);
let ariaLabel = $state('Text format');
const items = $derived([
{ value: 'bold', label: 'Bold', glyph: 'B' },
{ value: 'italic', label: 'Italic', glyph: 'I', disabled: italicDisabled },
{ value: 'underline', label: 'Underline', glyph: 'U' },
{ value: 'strike', label: 'Strikethrough', glyph: 'S' }
]);
type TraceEntry = { event: string; family: string; intent?: string; at: number };
let trace = $state<TraceEntry[]>([]);
let stageRef = $state<HTMLElement | null>(null);
$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 compiled = compileMorfo(toggleGroupMorfo);
const partsList = $derived([...compiled.parts.byKebab.values()]);
const events = $derived([...compiled.actions.byName.values()]);
function fmtTime(at: number): string {
const d = new Date(at);
return `${String(d.getSeconds()).padStart(2, '0')}.${String(d.getMilliseconds()).padStart(3, '0')}`;
}
// ── Snippets ────────────────────────────────────────────────────
const somaSnippet = $derived(
[
"<script lang='ts'>",
" import * as ToggleGroup from '$soma/components/toggle-group';",
' let value = $state<string[]>([\'bold\']);',
'</' + 'script>',
'',
'<ToggleGroup.Provider',
selectionMode !== 'single' && ` selectionMode="${selectionMode}"`,
' bind:value',
disabled && ' disabled',
!loop && ' loop={false}',
orientation !== 'horizontal' && ` orientation="${orientation}"`,
` aria-label="${ariaLabel}"`,
'>',
...items.map(
(it) =>
` <ToggleGroup.Item value="${it.value}"${it.disabled ? ' disabled' : ''}>${it.glyph}</ToggleGroup.Item>`
),
'</ToggleGroup.Provider>'
]
.filter(Boolean)
.join('\n')
);
const eidosSnippet = $derived(
[
"<script lang='ts'>",
" import { ToggleGroup } from '$uix/eidos/components/toggle-group';",
' let value = $state<string[]>([\'bold\']);',
'</' + 'script>',
'',
'<ToggleGroup',
selectionMode !== 'single' && ` selectionMode="${selectionMode}"`,
' bind:value',
variant !== 'solid' && ` variant="${variant}"`,
color !== 'neutral' && ` color="${color}"`,
size !== 'md' && ` size="${size}"`,
orientation !== 'horizontal' && ` orientation="${orientation}"`,
attached && ' attached',
block && ' block',
disabled && ' disabled',
!loop && ' loop={false}',
` aria-label="${ariaLabel}"`,
'>',
...items.map(
(it) =>
` <ToggleGroup.Item value="${it.value}"${it.disabled ? ' disabled' : ''}${iconOnly ? ' iconOnly' : ''}>${it.glyph}</ToggleGroup.Item>`
),
'</ToggleGroup>'
]
.filter(Boolean)
.join('\n')
);
</script>
<div data-uix-canvas-inner>
<header>
<div data-uix-eyebrow>Form · ToggleGroup</div>
<h1 data-uix-page-title>ToggleGroup</h1>
<p data-uix-page-lede>
Multiple toggle buttons sharing one selection model.
<code>selectionMode="single"</code> behaves radio-like (deselectable);
<code>selectionMode="multiple"</code> behaves checkbox-like. Headless
<span data-uix-layer-badge="soma">soma</span>
owns selection state, keyboard navigation, and the
<code>commit-toggle</code> perceptual event; Eidos paints chrome —
<code>variant</code>, <code>color</code>, <code>size</code>,
<code>attached</code> (segmented control affordance) and
<code>block</code> (stretch to fill).
</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>selectionMode</span>{selectionMode}
</span>
<span data-uix-meta-pill>
<span data-uix-meta-key>selected</span>{value.length}
</span>
</div>
</header>
<div data-uix-stage>
<div data-uix-stage-area bind:this={stageRef}>
<ToggleGroup
{selectionMode}
bind:value
{variant}
{color}
{size}
{orientation}
{attached}
{block}
{disabled}
{loop}
aria-label={ariaLabel}
>
{#each items as item (item.value)}
<ToggleGroup.Item value={item.value} disabled={item.disabled} {iconOnly}>
{item.glyph}
</ToggleGroup.Item>
{/each}
</ToggleGroup>
</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>
{#if trace[0]}
<span style="color: var(--uix-text-faint)">·</span>
<span data-uix-stage-trace-key>last</span>
<span>{trace[0].event} ({trace[0].family}) @{fmtTime(trace[0].at)}</span>
{/if}
<span style="margin-inline-start: auto;">
<span data-uix-stage-trace-key>value</span>
[{value.map((v) => `"${v}"`).join(', ')}]
</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>2</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 === 'tokens'} onclick={() => (tab = 'tokens')}>
Tokens <span data-uix-tab-count>1</span>
</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>
Knobs split by layer — <span data-uix-layer-badge="soma">soma</span> owns
selection/keyboard/disabled, <span data-uix-layer-badge="eidos">eidos</span> owns chrome
(variant/color/size/attached/block/iconOnly).
</p>
<div data-uix-subsection-head>
<span data-uix-layer-badge="soma">soma</span> props · selection + a11y
</div>
<div data-uix-controls>
<label data-uix-control>
<span data-uix-control-label>selectionMode</span>
<span data-uix-chips role="radiogroup">
{#each selectionModes as opt}
<button data-uix-chip data-active={selectionMode === opt} onclick={() => (selectionMode = opt)}>{opt}</button>
{/each}
</span>
</label>
<label data-uix-control>
<span data-uix-control-label>orientation</span>
<span data-uix-chips role="radiogroup">
{#each orientations as opt}
<button data-uix-chip data-active={orientation === opt} onclick={() => (orientation = opt)}>{opt}</button>
{/each}
</span>
</label>
<label data-uix-control data-control-kind="switch">
<input type="checkbox" bind:checked={disabled} /> disabled
</label>
<label data-uix-control data-control-kind="switch">
<input type="checkbox" bind:checked={loop} /> loop arrow keys
</label>
<label data-uix-control data-control-kind="switch">
<input type="checkbox" bind:checked={italicDisabled} /> disable "Italic" item
</label>
<label data-uix-control>
<span data-uix-control-label>aria-label</span>
<input type="text" bind:value={ariaLabel} />
</label>
</div>
<div data-uix-subsection-head>
<span data-uix-layer-badge="eidos">eidos</span> props · chrome
</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>color</span>
<span data-uix-chips role="radiogroup">
{#each colors as opt}
<button data-uix-chip data-active={color === opt} onclick={() => (color = opt)}>{opt}</button>
{/each}
<input
type="color"
use:colorValue={customColor}
oninput={(e) => {
customColor = e.currentTarget.value;
color = e.currentTarget.value;
}}
data-active={color === customColor}
aria-label="custom colour value"
style="inline-size: 2rem; block-size: 1.5rem; padding: 0; border: none; background: none; cursor: pointer;"
/>
</span>
</label>
<label data-uix-control>
<span data-uix-control-label>size</span>
<span data-uix-chips role="radiogroup">
{#each sizes as opt}
<button data-uix-chip data-active={size === opt} onclick={() => (size = opt)}>{opt}</button>
{/each}
</span>
</label>
<label data-uix-control data-control-kind="switch">
<input type="checkbox" bind:checked={attached} /> attached (segmented)
</label>
<label data-uix-control data-control-kind="switch">
<input type="checkbox" bind:checked={block} /> block (stretch)
</label>
<label data-uix-control data-control-kind="switch">
<input type="checkbox" bind:checked={iconOnly} /> iconOnly (square)
</label>
</div>
<div data-uix-code>
<div data-uix-code-head>
<span data-uix-layer-badge="soma">soma</span>
<span>headless · selection + keyboard</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 · variant + size + attached + block</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>
Two parts — <code>ToggleGroup</code> (provider/container) and
<code>ToggleGroup.Item</code> (button). Soma drives selection,
eidos drives visual treatment.
</p>
<div data-uix-subsection-head>ToggleGroup (root)</div>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Name</th><th>Type</th><th>Default</th><th>Notes</th></tr></thead>
<tbody>
<tr>
<td class="name">selectionMode <span data-uix-tag data-kind="soma">soma</span></td>
<td class="type">'single' | 'multiple'</td>
<td class="default">'single'</td>
<td>Selection mode.</td>
</tr>
<tr>
<td class="name">value <span data-uix-tag data-kind="soma">soma</span></td>
<td class="type">string[]</td>
<td class="default">[]</td>
<td>Bindable array of selected item values.</td>
</tr>
<tr>
<td class="name">disabled <span data-uix-tag data-kind="soma">soma</span></td>
<td class="type">boolean</td>
<td class="default">false</td>
<td>Disables all items.</td>
</tr>
<tr>
<td class="name">orientation <span data-uix-tag data-kind="soma">soma</span></td>
<td class="type">'horizontal' | 'vertical'</td>
<td class="default">'horizontal'</td>
<td>Arrow-key direction.</td>
</tr>
<tr>
<td class="name">loop <span data-uix-tag data-kind="soma">soma</span></td>
<td class="type">boolean</td>
<td class="default">true</td>
<td>Wrap arrow-key navigation at boundaries.</td>
</tr>
<tr>
<td class="name">aria-label <span data-uix-tag data-kind="soma">soma</span></td>
<td class="type">string</td>
<td class="default empty">—</td>
<td>
<strong>Required</strong> unless <code>aria-labelledby</code> is set.
</td>
</tr>
<tr>
<td class="name">variant <span data-uix-tag data-kind="eidos">eidos</span></td>
<td class="type">'solid' | 'outline' | 'ghost'</td>
<td class="default">'solid'</td>
<td>Visual treatment. Mirrors Toggle.</td>
</tr>
<tr>
<td class="name">color <span data-uix-tag data-kind="eidos">eidos</span></td>
<td class="type">primary | neutral | affirm | risk | threat | absent | unknown</td>
<td class="default">'neutral'</td>
<td>Propagates to items via <code>data-color</code>.</td>
</tr>
<tr>
<td class="name">size <span data-uix-tag data-kind="eidos">eidos</span></td>
<td class="type">'xs' | 'sm' | 'md' | 'lg' | 'xl'</td>
<td class="default">'md'</td>
<td>T-shirt scale, responsive.</td>
</tr>
<tr>
<td class="name">attached <span data-uix-tag data-kind="eidos">eidos</span></td>
<td class="type">boolean</td>
<td class="default">false</td>
<td>Segmented control — shared borders.</td>
</tr>
<tr>
<td class="name">block <span data-uix-tag data-kind="eidos">eidos</span></td>
<td class="type">boolean</td>
<td class="default">false</td>
<td>Stretch items to fill the container.</td>
</tr>
</tbody>
</table>
</div>
<div data-uix-subsection-head>ToggleGroup.Item</div>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Name</th><th>Type</th><th>Default</th><th>Notes</th></tr></thead>
<tbody>
<tr>
<td class="name">value <span data-uix-tag data-kind="soma">soma</span></td>
<td class="type">string</td>
<td class="default empty">—</td>
<td><strong>Required</strong>. Item identifier — appears in the parent's <code>value</code> array when pressed.</td>
</tr>
<tr>
<td class="name">disabled <span data-uix-tag data-kind="soma">soma</span></td>
<td class="type">boolean</td>
<td class="default">false</td>
<td>Disables this item only.</td>
</tr>
<tr>
<td class="name">aria-label <span data-uix-tag data-kind="soma">soma</span></td>
<td class="type">string</td>
<td class="default empty">—</td>
<td>Accessible name override (recommended when <code>iconOnly</code>).</td>
</tr>
<tr>
<td class="name">iconOnly <span data-uix-tag data-kind="eidos">eidos</span></td>
<td class="type">boolean</td>
<td class="default">false</td>
<td>Square aspect — visible label collapsed (assumes <code>aria-label</code> is set).</td>
</tr>
<tr>
<td class="name">…native button attrs</td>
<td class="type">PrimitiveButtonAttributes</td>
<td class="default empty">—</td>
<td>onclick, type, form, etc.</td>
</tr>
</tbody>
</table>
</div>
<div data-uix-subsection-head>Reference parity</div>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Feature</th><th>Radix</th><th>bits-ui</th><th>ark-ui</th><th>Eidos (this)</th></tr></thead>
<tbody>
<tr><td>selectionMode='single' (radio-like)</td><td>✓</td><td>✓</td><td>✓</td><td>✓</td></tr>
<tr><td>selectionMode='multiple' (checkbox-like)</td><td>✓</td><td>✓</td><td>✓</td><td>✓</td></tr>
<tr><td>Roving tabindex</td><td>✓</td><td>✓</td><td>✓</td><td>✓</td></tr>
<tr><td>Arrow-key navigation + Home/End</td><td>✓</td><td>✓</td><td>✓</td><td>✓</td></tr>
<tr><td>orientation='vertical'</td><td>✓</td><td>✓</td><td>✓</td><td>✓</td></tr>
<tr><td>loop control</td><td>—</td><td>✓</td><td>✓</td><td>✓</td></tr>
<tr><td>variant / color cascade to items</td><td>—</td><td>—</td><td>—</td><td>✓</td></tr>
<tr><td>attached (segmented control)</td><td>—</td><td>—</td><td>partial</td><td>✓</td></tr>
<tr><td>block (stretch)</td><td>—</td><td>—</td><td>—</td><td>✓</td></tr>
<tr><td>iconOnly square aspect</td><td>—</td><td>—</td><td>—</td><td>✓</td></tr>
<tr><td>commit-toggle semantic event (per item)</td><td>—</td><td>—</td><td>—</td><td>✓</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>
Two parts (Provider + Item), three events — all targeting the
item: <code>contact-press</code>, <code>commit-toggle</code> and
<code>commit-block</code>. Source:
<code>src/uix/morfo/components/toggle-group.ts</code>.
</p>
<!-- ── Component header ───────────────────────────────────────── -->
<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">"{toggleGroupMorfo.name}"</td></tr>
<tr><td class="name">kebab</td><td class="type">"{toggleGroupMorfo.kebab}"</td></tr>
<tr><td class="name">scope</td><td class="type">[{toggleGroupMorfo.scope.map((s) => `"${s}"`).join(', ')}]</td></tr>
<tr><td class="name">apg</td><td><a href={toggleGroupMorfo.apg} target="_blank" rel="noreferrer">{toggleGroupMorfo.apg}</a></td></tr>
<tr><td class="name">parts.length</td><td class="default">{toggleGroupMorfo.parts.length}</td></tr>
<tr><td class="name">events.length</td><td class="default">{toggleGroupMorfo.events?.length ?? 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>Part</th><th>Marker</th><th>Element</th><th>Role</th><th>Archetype</th><th>States</th><th>Optional</th></tr></thead>
<tbody>
{#each partsList as part (part.kebab)}
<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.archetype ?? '—'}</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 toggleGroupMorfo.parts as rawPart (rawPart.kebab)}
{@const partAny = rawPart as unknown as { kebab: string; aria?: ReadonlyArray<{ attr: string; value: { kind: string }; condition?: { when: string; prop?: string; part?: 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 kind</th></tr></thead>
<tbody>
{#each dataAttrs as attr (attr.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 kind</th><th>Condition</th><th>Severity</th></tr></thead>
<tbody>
{#each ariaAttrs as a (a.attr)}
<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})` : ''}${a.condition.part ? ` (${a.condition.part})` : ''}` : '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 (kb.key)}
<tr>
<td><span data-uix-kbd>{kb.key === ' ' ? 'Space' : kb.key}</span></td>
<td class="default">{kb.action}</td>
</tr>
{/each}
</tbody>
</table>
</div>
{/if}
{/if}
{/each}
<div data-uix-subsection-head>Events declaration</div>
<p data-uix-section-desc style="margin-top: 0.25rem;">
<code>contact-press</code> fires <em>pre</em> — the audible click
that acknowledges the gesture. <code>commit-toggle</code> fires
<em>post</em> the state flip (so sema's perceptual signal lands
once the new pressed state is visible); <code>regime: 'queue'</code>
makes it wait for the contact instead of erasing it, since both
stamp the same item. Its intent is bound to the consumer's
<code>intent</code> prop with a default of <code>neutral</code>;
supported intents narrowed to commit-friendly values.
<code>commit-block</code> fires <em>post</em> with a static
<code>risk</code> when the selection cardinality rejects the pick.
Play them from the <a href="#sema" onclick={(e) => { e.preventDefault(); tab = 'sema'; }}>Sema</a> tab.
</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>intent</th><th>target</th><th>prewrite</th><th>commit</th></tr></thead>
<tbody>
{#each events as action (action.name)}
{@const sem = action.semantic}
{@const intentDecl = 'intent' in sem ? sem.intent : undefined}
{@const intentStr = typeof intentDecl === 'string' ? intentDecl : intentDecl ? `fromProp:${(intentDecl as { fromProp?: string }).fromProp ?? '?'} (default ${(intentDecl as { default?: string }).default ?? '?'})` : '—'}
<tr>
<td class="name">{action.name}</td>
<td class="type">{sem.family}</td>
<td>{sem.verb ?? '—'}</td>
<td>{sem.sequence ?? 'pre'}</td>
<td class="default">{intentStr}</td>
<td>{action.target}</td>
<td class="default">{action.prewrite.length ? action.prewrite.map((p) => `${p.attr}=${p.value}`).join(', ') : '—'}</td>
<td class="default">{action.commit ? `${action.commit.attr}=${action.commit.value}` : '—'}</td>
</tr>
{/each}
</tbody>
</table>
</div>
</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>
Three events, all stamped on the pressed item.
<code>contact-press</code> (<code>contact</code> family,
<em>pre</em>) carries the click; <code>commit-toggle</code>
(<code>commit</code>, <em>post</em>) lands after the state has
flipped, with intent per-item via <code>fromProp:intent</code>;
<code>commit-block</code> (<code>commit</code>, <em>post</em>,
static <code>risk</code>) sounds a pick the cardinality limit
rejected.
</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>Intent</th><th>Play</th></tr></thead>
<tbody>
{#each events as action}
{@const sem = action.semantic}
{@const intentDecl = 'intent' in sem ? sem.intent : undefined}
{@const effectiveIntent =
typeof intentDecl === 'string'
? intentDecl
: intentDecl && typeof intentDecl === 'object' && 'default' in intentDecl
? (intentDecl as { default: string }).default
: undefined}
<tr>
<td class="name">{action.name}</td>
<td class="type">{sem.family}</td>
<td>{sem.verb ?? '—'}</td>
<td>{sem.sequence ?? 'pre'}</td>
<td class="default">{effectiveIntent ?? '—'}</td>
<td>
<button
data-uix-play
onclick={() => {
const target = stageRef?.querySelector(
'[data-toggle-group-item]'
) as HTMLElement | null;
if (!target) return;
void uix.events?.emit({
name: action.name,
family: sem.family,
target,
...(effectiveIntent
? { intent: effectiveIntent as 'neutral' | 'affirm' | 'risk' | 'threat' }
: {})
});
}}>▶ play</button
>
</td>
</tr>
{/each}
</tbody>
</table>
</div>
</section>
{/if}
{#if tab === 'tokens'}
<TokensPanel component="toggle-group" stage={stageRef ?? undefined} />
{/if}
{#if tab === 'recipe'}
<section data-uix-section>
<h2 data-uix-section-title>Eidos recipe</h2>
<p data-uix-section-desc>
Recipe at <code>src/uix/eidos/components/toggle-group/toggle-group.css</code>.
Items consume the Toggle palette tokens so visuals stay
coherent across <code>&lt;Toggle&gt;</code> and
<code>&lt;ToggleGroup.Item&gt;</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-toggle-group]</code></td>
<td><span data-uix-tag data-kind="morfo">morfo</span></td>
<td>Flex container, orientation-aware direction.</td>
</tr>
<tr>
<td class="name"><code>[data-toggle-group][data-attached]</code></td>
<td><span data-uix-tag data-kind="eidos">eidos</span></td>
<td>Collapsed gap + shared borders (segmented control).</td>
</tr>
<tr>
<td class="name"><code>[data-toggle-group][data-block]</code></td>
<td><span data-uix-tag data-kind="eidos">eidos</span></td>
<td>Items <code>flex: 1</code>; group <code>inline-size: 100%</code>.</td>
</tr>
<tr>
<td class="name"><code>[data-toggle-group-item]</code></td>
<td><span data-uix-tag data-kind="morfo">morfo</span></td>
<td>Button — inherits Toggle's height/padding/radius/font tokens.</td>
</tr>
<tr>
<td class="name"><code>[data-toggle-group-item][data-state='on']</code></td>
<td><span data-uix-tag data-kind="morfo">morfo</span></td>
<td>Pressed visual — switches to <code>--_toggle-on-*</code> palette slice.</td>
</tr>
<tr>
<td class="name"
><code>[data-toggle-group][data-variant='outline'] [data-toggle-group-item]</code></td
>
<td><span data-uix-tag data-kind="eidos">eidos</span></td>
<td>Cascades the variant slice from root to items.</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>
Provider exposes <code>role='group'</code> with a required
accessible name (warns in dev when missing). Items are native
<code>&lt;button&gt;</code> with <code>aria-pressed</code> and
roving-tabindex arrow-key navigation. Pattern:
WAI-ARIA <a href={toggleGroupMorfo.apg} target="_blank" rel="noopener">Button</a>
— ToggleGroup is the canonical group-of-toggle-buttons surface
since no APG-formal "toggle group" pattern exists.
</p>
<div data-uix-subsection-head>Keyboard</div>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Key</th><th>Effect</th></tr></thead>
<tbody>
<tr><td><span data-uix-kbd>ArrowRight</span> / <span data-uix-kbd>ArrowDown</span></td><td>Move focus to next item (horizontal / vertical).</td></tr>
<tr><td><span data-uix-kbd>ArrowLeft</span> / <span data-uix-kbd>ArrowUp</span></td><td>Move focus to previous item.</td></tr>
<tr><td><span data-uix-kbd>Home</span></td><td>Move focus to first item.</td></tr>
<tr><td><span data-uix-kbd>End</span></td><td>Move focus to last item.</td></tr>
<tr><td><span data-uix-kbd>Space</span> / <span data-uix-kbd>Enter</span></td><td>Toggle the focused item; fires <code>commit-toggle</code>.</td></tr>
<tr><td><span data-uix-kbd>Tab</span> / <span data-uix-kbd>Shift+Tab</span></td><td>Move focus out of the group (roving tabindex keeps only one item tabbable).</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">provider</td><td>role</td><td class="type">"group"</td></tr>
<tr><td class="name">provider</td><td>aria-orientation</td><td class="type">{`{orientation}`}</td></tr>
<tr><td class="name">provider</td><td>aria-label / aria-labelledby</td><td class="type">required <span style="color: var(--uix-text-faint)">(dev warning if missing)</span></td></tr>
<tr><td class="name">item</td><td>role / type</td><td class="type">"button" / "button"</td></tr>
<tr><td class="name">item</td><td>aria-pressed</td><td class="type">{`{on}`}</td></tr>
<tr><td class="name">item</td><td>aria-disabled</td><td class="type">"true" when <code>disabled</code></td></tr>
<tr><td class="name">item</td><td>tabindex</td><td class="type">0 on focused item · -1 on the rest (roving)</td></tr>
</tbody>
</table>
</div>
</section>
{/if}
</div>

Powered by TurnKey Linux.