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

523 lines
22 KiB

<script lang="ts">
import {
GridList,
type GridListSize,
type GridListVariant,
type GridListColor,
type GridListSelectionMode
} from '$uix/eidos/components/grid-list';
import { compileMorfo } from '$uix/morfo';
import { gridListMorfo } from '@/uix/morfo/components/grid-list';
import { getActiveUix } from '$active-uix';
const uix = getActiveUix();
type Tab = 'live' | 'api' | 'morfo' | 'sema' | 'recipe' | 'a11y';
let tab = $state<Tab>('live');
// ── Live state ────────────────────────────────────────────────────────
let value = $state<string[]>(['r2']);
let selectionMode = $state<GridListSelectionMode>('multiple');
let size = $state<GridListSize>('md');
let variant = $state<GridListVariant>('surface');
let color = $state<GridListColor>('primary');
let loop = $state(false);
let disabled = $state(false);
let invalid = $state(false);
let lastAction = $state<string | null>(null);
function trigger(label: string) {
return () => {
lastAction = label;
};
}
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(gridListMorfo);
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')}`;
}
const rows = [
{ value: 'r1', label: 'Acme Industries', meta: 'Enterprise · 240 users' },
{ value: 'r2', label: 'Globex Corporation', meta: 'Pro · 80 users' },
{ value: 'r3', label: 'Initech Systems', meta: 'Free · 5 users' },
{ value: 'r4', label: 'Soylent Foods', meta: 'Enterprise · 1.2k users' },
{ value: 'r5', label: 'Umbrella Inc.', meta: 'Pro · 42 users', disabled: true },
{ value: 'r6', label: 'Wonka Confections', meta: 'Free · 12 users' }
];
const eidosSnippet = $derived(
[
"<script lang='ts'>",
" import { GridList } from '$uix/eidos/components/grid-list';",
' let value = $state<string[]>([]);',
'</' + 'script>',
'',
'<GridList',
' bind:value',
selectionMode !== 'single' && ` selectionMode="${selectionMode}"`,
size !== 'md' && ` size="${size}"`,
variant !== 'surface' && ` variant="${variant}"`,
color !== 'primary' && ` color="${color}"`,
loop && ' loop',
disabled && ' disabled',
invalid && ' invalid',
'>',
' <GridList.Row value="r1">',
' <GridList.Cell><GridList.SelectionCheckbox /></GridList.Cell>',
' <GridList.Cell>Acme Industries</GridList.Cell>',
' <GridList.Cell><button onclick={…}>Edit</button></GridList.Cell>',
' </GridList.Row>',
'</GridList>'
]
.filter(Boolean)
.join('\n')
);
</script>
<div data-uix-canvas-inner>
<header>
<div data-uix-eyebrow>Forms · GridList</div>
<h1 data-uix-page-title>GridList</h1>
<p data-uix-page-lede>
Selectable list with <code>role="grid"</code> semantics — rows
that can contain interactive children (buttons, links, per-row
checkboxes). 2D keyboard nav (Up/Down between rows + Left/Right
between cells / inner controls) lets assistive tech reach the
row-level actions properly. Use over <code>Listbox</code> when
rows aren't atomic options — ARIA forbids interactive descendants
inside <code>role="listbox"</code>.
</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>5
</span>
<span data-uix-meta-pill>
<span data-uix-meta-key>apg</span>
<a href={gridListMorfo.apg} target="_blank" rel="noreferrer">grid ↗</a>
</span>
<span data-uix-meta-pill>
<span data-uix-meta-key>selected</span> {value.join(', ') || '—'}
</span>
{#if lastAction}
<span data-uix-meta-pill>
<span data-uix-meta-key>last</span> {lastAction}
</span>
{/if}
</div>
</header>
<div data-uix-stage>
<div data-uix-stage-area bind:this={stageRef} style="padding: var(--uix-space-3); display: flex; justify-content: center;">
<div style="inline-size: min(32rem, 100%);">
<GridList
bind:value
{selectionMode}
{size}
{variant}
{color}
{loop}
{disabled}
{invalid}
block
>
{#each rows as row (row.value)}
<GridList.Row value={row.value} disabled={row.disabled}>
<GridList.Cell>
<GridList.SelectionCheckbox />
</GridList.Cell>
<GridList.Cell>
<div style="display: flex; flex-direction: column; gap: 2px; min-inline-size: 0;">
<strong style="line-height: 1.2;">{row.label}</strong>
<span style="color: var(--color-content-secondary); font-size: var(--font-size-xs);">{row.meta}</span>
</div>
</GridList.Cell>
<GridList.Cell>
<button
type="button"
onclick={trigger(`Edit ${row.label}`)}
disabled={row.disabled}
style="padding: 0.125rem 0.5rem; border: 1px solid var(--color-border-default); border-radius: var(--radius-sm); background: var(--color-surface-overlay); cursor: pointer; font-size: var(--font-size-xs);"
>
Edit
</button>
</GridList.Cell>
</GridList.Row>
{/each}
</GridList>
</div>
</div>
<div data-uix-stage-trace>
<span data-uix-stage-trace-key>trace</span>
{#if trace.length === 0}
<span>click row body to select; Tab into row to reach inner button</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>value</span> [{value.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>4</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>
Soma owns selection + 2D nav + Shift/Ctrl range/toggle + Ctrl+A select-all + Escape-clear + typeahead.
Eidos adds variant/size/color chrome.
</p>
<div data-uix-subsection-head>
<span data-uix-layer-badge="soma">soma</span> Provider props
</div>
<div data-uix-controls>
<label data-uix-control>
<span data-uix-control-label>selectionMode</span>
<span data-uix-chips role="radiogroup">
{#each ['none', 'single', 'multiple'] as m (m)}
<button data-uix-chip data-active={selectionMode === m} onclick={() => (selectionMode = m as GridListSelectionMode)}>{m}</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>disabled</span>
<span data-uix-switch>
<input type="checkbox" bind:checked={disabled} />
<span data-uix-switch-label>{disabled ? 'on' : 'off'}</span>
</span>
</label>
<label data-uix-control>
<span data-uix-control-label>invalid</span>
<span data-uix-switch>
<input type="checkbox" bind:checked={invalid} />
<span data-uix-switch-label>{invalid ? 'on' : 'off'}</span>
</span>
</label>
</div>
<div data-uix-subsection-head>
<span data-uix-layer-badge="eidos">eidos</span> visual props
</div>
<div data-uix-controls>
<label data-uix-control>
<span data-uix-control-label>variant</span>
<span data-uix-chips role="radiogroup">
{#each ['surface', 'outline', 'ghost'] as v (v)}
<button data-uix-chip data-active={variant === v} onclick={() => (variant = v as GridListVariant)}>{v}</button>
{/each}
</span>
</label>
<label data-uix-control>
<span data-uix-control-label>size</span>
<span data-uix-chips role="radiogroup">
{#each ['xs', 'sm', 'md', 'lg', 'xl'] as s (s)}
<button data-uix-chip data-active={size === s} onclick={() => (size = s as GridListSize)}>{s}</button>
{/each}
</span>
</label>
<label data-uix-control>
<span data-uix-control-label>color</span>
<span data-uix-chips role="radiogroup">
{#each ['primary', 'secondary', 'neutral', 'affirm', 'fulfill', 'risk', 'threat', 'loss'] as c (c)}
<button data-uix-chip data-active={color === c} onclick={() => (color = c as GridListColor)}>{c}</button>
{/each}
</span>
</label>
</div>
<div data-uix-code>
<div data-uix-code-head>
<span data-uix-layer-badge="eidos">eidos</span>
<span>visual · variant + size + color + defaultValue</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>4 parts: Provider, Row, Cell, SelectionCheckbox.</p>
<div data-uix-subsection-head>Provider (GridList)</div>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Prop</th><th>Type</th><th>Default</th><th>Description</th></tr></thead>
<tbody>
<tr><td class="name">value <span data-uix-tag data-kind="bindable">bindable</span></td><td class="type">string[]</td><td class="default">[]</td><td>Selected row values.</td></tr>
<tr><td class="name">defaultValue <span data-uix-tag data-kind="eidos">eidos</span></td><td class="type">string[]</td><td class="default empty">—</td><td>Uncontrolled initial selection. Ignored when value is bound.</td></tr>
<tr><td class="name">selectionMode</td><td class="type">'none' | 'single' | 'multiple'</td><td class="default">'single'</td><td>—</td></tr>
<tr><td class="name">loop</td><td class="type">boolean</td><td class="default">false</td><td>Wrap arrow nav at edges.</td></tr>
<tr><td class="name">typeahead</td><td class="type">boolean</td><td class="default">true</td><td>Letter typing jumps to matching row.</td></tr>
<tr><td class="name">disabled · readonly · required · invalid</td><td class="type">boolean</td><td class="default">false</td><td>OR-merged with Field.Provider.</td></tr>
<tr><td class="name">name</td><td class="type">string</td><td class="default empty">—</td><td>Form name → hidden input.</td></tr>
<tr><td class="name">variant <span data-uix-tag data-kind="eidos">eidos</span></td><td class="type">ControlVariant: 'surface' | 'outline' | 'ghost'</td><td class="default">'surface'</td><td>Container chrome.</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>Row height + font.</td></tr>
<tr><td class="name">color <span data-uix-tag data-kind="eidos">eidos</span></td><td class="type">ColorRole</td><td class="default">'primary'</td><td>Selected-row + focus accent.</td></tr>
</tbody>
</table>
</div>
<div data-uix-subsection-head>Row</div>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Prop</th><th>Type</th><th>Default</th><th>Description</th></tr></thead>
<tbody>
<tr><td class="name">value</td><td class="type">string</td><td class="default empty">required</td><td>Unique row identifier.</td></tr>
<tr><td class="name">textValue</td><td class="type">string</td><td class="default empty">textContent</td><td>Override for typeahead search.</td></tr>
<tr><td class="name">disabled</td><td class="type">boolean</td><td class="default">false</td><td>Skip from selection + 2D nav.</td></tr>
</tbody>
</table>
</div>
<div data-uix-subsection-head>Cell · SelectionCheckbox</div>
<p data-uix-section-desc style="margin-top: 0.25rem;">
<code>Cell</code> renders <code>role="gridcell"</code> as a content slot — wrap any interactive children inside. <code>SelectionCheckbox</code> is a per-row toggle that participates in <code>selectionMode='multiple'</code>; click toggles the row in <code>value</code>. Visual matches the shared menu-indicator pattern (filled accent + white ✓).
</p>
</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/grid-list.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">"{gridListMorfo.name}"</td></tr>
<tr><td class="name">kebab</td><td class="type">"{gridListMorfo.kebab}"</td></tr>
<tr><td class="name">apg</td><td><a href={gridListMorfo.apg} target="_blank" rel="noreferrer">{gridListMorfo.apg}</a></td></tr>
<tr><td class="name">parts.length</td><td class="default">{gridListMorfo.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>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>
<div data-uix-subsection-head>Events declaration</div>
<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></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 ?? '?'}` : '—'}
<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>
</tr>
{/each}
</tbody>
</table>
</div>
</section>
{/if}
{#if tab === 'sema'}
<section data-uix-section id="sema">
<h2 data-uix-section-title>
<span data-uix-layer-badge="sema">sema</span>
· events
</h2>
<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 (action.name)}
{@const intentDecl = 'intent' in action.semantic ? action.semantic.intent : undefined}
{@const effectiveIntent = typeof intentDecl === 'string' ? intentDecl : undefined}
<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 class="default">{effectiveIntent ?? '—'}</td>
<td>
<button
data-uix-play
onclick={() => {
const target = (stageRef?.querySelector('[data-grid-list-row]') ?? stageRef) as HTMLElement | null;
if (!target) return;
void uix.events?.emit({
name: action.name,
family: action.semantic.family,
target,
...(effectiveIntent ? { intent: effectiveIntent } : {})
});
}}
>▶ 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/grid-list/grid-list.css</code>.</p>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Selector</th><th>Source</th><th>What it paints</th></tr></thead>
<tbody>
<tr><td class="name">[data-grid-list]</td><td><span data-uix-tag data-kind="eidos">eidos</span></td><td>Container — flex column, border, padding, scroll cap.</td></tr>
<tr><td class="name">[data-grid-list][data-size]</td><td><span data-uix-tag data-kind="eidos">eidos</span></td><td>Row height + font-size scale.</td></tr>
<tr><td class="name">[data-grid-list][data-variant]</td><td><span data-uix-tag data-kind="eidos">eidos</span></td><td>Container chrome (surface / outline / ghost).</td></tr>
<tr><td class="name">[data-grid-list][data-color]</td><td><span data-uix-tag data-kind="eidos">eidos</span></td><td>Accent palette for selected rows + focus ring.</td></tr>
<tr><td class="name">[data-grid-list-row]</td><td><span data-uix-tag data-kind="soma">morfo</span></td><td>Row — flex layout, padding, hover/highlight states.</td></tr>
<tr><td class="name">[data-grid-list-row][data-selected]</td><td><span data-uix-tag data-kind="soma">morfo</span></td><td>Selected-row accent-soft fill.</td></tr>
<tr><td class="name">[data-grid-list-cell]</td><td><span data-uix-tag data-kind="soma">morfo</span></td><td>Cell slot — first/last child get special flex treatment.</td></tr>
<tr><td class="name">[data-grid-list-selection-checkbox][data-state]</td><td><span data-uix-tag data-kind="eidos">eidos</span></td><td>0.875rem outlined box → filled accent + white ✓.</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={gridListMorfo.apg} target="_blank" rel="noreferrer">grid pattern</a>.
Container is <code>role="grid"</code>; each Row is
<code>role="row"</code>; each Cell is <code>role="gridcell"</code>.
Roving tabindex on rows; arrow nav handles cell-level focus too
so inner buttons / links are reachable.
</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>ArrowDown</span> / <span data-uix-kbd>ArrowUp</span></td><td>Move row focus ±1.</td></tr>
<tr><td><span data-uix-kbd>ArrowRight</span> / <span data-uix-kbd>ArrowLeft</span></td><td>Move cell focus within the row (lets you reach inner buttons / links).</td></tr>
<tr><td><span data-uix-kbd>Home</span> / <span data-uix-kbd>End</span></td><td>First / last row.</td></tr>
<tr><td><span data-uix-kbd>Enter</span> / <span data-uix-kbd>Space</span></td><td>Toggle row selection.</td></tr>
<tr><td><span data-uix-kbd>Shift+Click</span> / <span data-uix-kbd>Shift+ArrowUp/Down</span></td><td>Extend range (multiple mode).</td></tr>
<tr><td><span data-uix-kbd>Ctrl/Cmd+A</span></td><td>Select all (multiple mode).</td></tr>
<tr><td><span data-uix-kbd>Escape</span></td><td>Clear selection.</td></tr>
<tr><td>Letter / digit</td><td>Typeahead — jump to next row whose textValue starts with that character.</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">grid-list</td><td>role</td><td class="type">"grid"</td></tr>
<tr><td class="name">grid-list</td><td>aria-multiselectable</td><td class="type">"true" (multiple mode)</td></tr>
<tr><td class="name">row</td><td>role</td><td class="type">"row"</td></tr>
<tr><td class="name">row</td><td>aria-selected</td><td class="type">"true" | "false"</td></tr>
<tr><td class="name">row</td><td>aria-disabled</td><td class="type">"true" (disabled)</td></tr>
<tr><td class="name">cell</td><td>role</td><td class="type">"gridcell"</td></tr>
<tr><td class="name">selection-checkbox</td><td>role / aria-checked</td><td class="type">"checkbox" / "true|false"</td></tr>
</tbody>
</table>
</div>
</section>
{/if}
</div>

Powered by TurnKey Linux.