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.
378 lines
12 KiB
378 lines
12 KiB
|
5 months ago
|
<script lang="ts">
|
||
|
|
import { SearchField, type SearchFieldSize } from '$uix/eidos/components/search-field';
|
||
|
|
import { compileMorfo } from '$uix/morfo';
|
||
|
|
import { searchFieldMorfo } from '@/uix/morfo/components/search-field';
|
||
|
|
import { getActiveUix } from '$active-uix';
|
||
|
|
|
||
|
|
type Tab = 'live' | 'api' | 'morfo' | 'sema' | 'recipe' | 'a11y';
|
||
|
|
|
||
|
|
const uix = getActiveUix();
|
||
|
|
|
||
|
|
let tab = $state<Tab>('live');
|
||
|
|
let value = $state('drawer');
|
||
|
|
let placeholder = $state('Search components');
|
||
|
|
let clearOnEscape = $state(true);
|
||
|
|
let disabled = $state(false);
|
||
|
|
let readonly = $state(false);
|
||
|
|
let required = $state(false);
|
||
|
|
let invalid = $state(false);
|
||
|
|
let size = $state<SearchFieldSize>('md');
|
||
|
|
let lastSubmit = $state('none');
|
||
|
|
|
||
|
|
const compiled = compileMorfo(searchFieldMorfo);
|
||
|
|
const partsList = $derived([...compiled.parts.byKebab.values()]);
|
||
|
|
const events = $derived([...compiled.actions.byName.values()]);
|
||
|
|
const isEmpty = $derived(value.length === 0);
|
||
|
|
let stageRef = $state<HTMLElement | null>(null);
|
||
|
|
|
||
|
|
const somaSnippet = $derived(
|
||
|
|
[
|
||
|
|
"<script lang='ts'>",
|
||
|
|
" import * as SearchField from '$soma/components/search-field';",
|
||
|
|
` let value = $state('${value}');`,
|
||
|
|
'</' + 'script>',
|
||
|
|
'',
|
||
|
|
'<SearchField.Provider bind:value placeholder="Search components">',
|
||
|
|
' <SearchField.Input />',
|
||
|
|
' <SearchField.ClearTrigger>Clear</SearchField.ClearTrigger>',
|
||
|
|
'</SearchField.Provider>'
|
||
|
|
].join('\n')
|
||
|
|
);
|
||
|
|
|
||
|
|
const eidosSnippet = $derived(
|
||
|
|
[
|
||
|
|
"<script lang='ts'>",
|
||
|
|
" import { SearchField } from '$uix/eidos/components/search-field';",
|
||
|
|
` let value = $state('${value}');`,
|
||
|
|
'</' + 'script>',
|
||
|
|
'',
|
||
|
|
`<SearchField bind:value placeholder="Search components" size="${size}">`,
|
||
|
|
' <SearchField.Input />',
|
||
|
|
' <SearchField.ClearTrigger>Clear</SearchField.ClearTrigger>',
|
||
|
|
'</SearchField>'
|
||
|
|
].join('\n')
|
||
|
|
);
|
||
|
|
</script>
|
||
|
|
|
||
|
|
<div data-uix-canvas-inner>
|
||
|
|
<header>
|
||
|
|
<div data-uix-eyebrow>Forms · Search field</div>
|
||
|
|
<h1 data-uix-page-title>SearchField</h1>
|
||
|
|
<p data-uix-page-lede>
|
||
|
|
Searchbox primitive with clear and submit behavior. Soma owns value, focus, clear, keyboard
|
||
|
|
and ARIA; Eidos adds visual size.
|
||
|
|
</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>keyboard</span>2</span>
|
||
|
|
<span data-uix-meta-pill><span data-uix-meta-key>sizes</span>3</span>
|
||
|
|
</div>
|
||
|
|
</header>
|
||
|
|
|
||
|
|
<div data-uix-stage bind:this={stageRef}>
|
||
|
|
<div data-uix-stage-area>
|
||
|
|
<div style="inline-size: min(26rem, 100%);">
|
||
|
|
<SearchField
|
||
|
|
bind:value
|
||
|
|
{placeholder}
|
||
|
|
{clearOnEscape}
|
||
|
|
{disabled}
|
||
|
|
{readonly}
|
||
|
|
{required}
|
||
|
|
{invalid}
|
||
|
|
{size}
|
||
|
|
onSubmit={(next) => (lastSubmit = next || 'empty')}
|
||
|
|
onClear={() => (lastSubmit = 'cleared')}
|
||
|
|
>
|
||
|
|
<SearchField.Input />
|
||
|
|
<SearchField.ClearTrigger>Clear</SearchField.ClearTrigger>
|
||
|
|
</SearchField>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div data-uix-stage-trace>
|
||
|
|
<span data-uix-stage-trace-key>value</span>
|
||
|
|
<span data-uix-stage-trace-event>{isEmpty ? 'empty' : value}</span>
|
||
|
|
<span style="color: var(--uix-text-faint)">·</span>
|
||
|
|
<span data-uix-stage-trace-key>last submit</span>
|
||
|
|
<span>{lastSubmit}</span>
|
||
|
|
<span style="margin-inline-start: auto;">
|
||
|
|
<span data-uix-stage-trace-key>size</span>
|
||
|
|
{size}
|
||
|
|
</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>10</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>
|
||
|
|
<span data-uix-layer-badge="soma">soma</span> owns value, clear and submit.
|
||
|
|
<span data-uix-layer-badge="eidos">eidos</span> owns size.
|
||
|
|
</p>
|
||
|
|
<div data-uix-subsection-head>
|
||
|
|
<span data-uix-layer-badge="soma">soma</span> props · search behavior
|
||
|
|
</div>
|
||
|
|
<div data-uix-controls>
|
||
|
|
<label data-uix-control>
|
||
|
|
<span data-uix-control-label>value</span>
|
||
|
|
<input type="search" bind:value />
|
||
|
|
</label>
|
||
|
|
<label data-uix-control>
|
||
|
|
<span data-uix-control-label>placeholder</span>
|
||
|
|
<input type="text" bind:value={placeholder} />
|
||
|
|
</label>
|
||
|
|
{#each ['clearOnEscape', 'disabled', 'readonly', 'required', 'invalid'] as flag}
|
||
|
|
<label data-uix-control>
|
||
|
|
<span data-uix-control-label>{flag}</span>
|
||
|
|
<span data-uix-switch>
|
||
|
|
{#if flag === 'clearOnEscape'}
|
||
|
|
<input type="checkbox" bind:checked={clearOnEscape} />
|
||
|
|
<span data-uix-switch-label>{clearOnEscape ? 'on' : 'off'}</span>
|
||
|
|
{:else if flag === 'disabled'}
|
||
|
|
<input type="checkbox" bind:checked={disabled} />
|
||
|
|
<span data-uix-switch-label>{disabled ? 'on' : 'off'}</span>
|
||
|
|
{:else if flag === 'readonly'}
|
||
|
|
<input type="checkbox" bind:checked={readonly} />
|
||
|
|
<span data-uix-switch-label>{readonly ? 'on' : 'off'}</span>
|
||
|
|
{:else if flag === 'required'}
|
||
|
|
<input type="checkbox" bind:checked={required} />
|
||
|
|
<span data-uix-switch-label>{required ? 'on' : 'off'}</span>
|
||
|
|
{:else}
|
||
|
|
<input type="checkbox" bind:checked={invalid} />
|
||
|
|
<span data-uix-switch-label>{invalid ? 'on' : 'off'}</span>
|
||
|
|
{/if}
|
||
|
|
</span>
|
||
|
|
</label>
|
||
|
|
{/each}
|
||
|
|
</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 ['sm', 'md', 'lg'] as s}
|
||
|
|
<button
|
||
|
|
data-uix-chip
|
||
|
|
data-active={size === s}
|
||
|
|
onclick={() => (size = s as SearchFieldSize)}>{s}</button
|
||
|
|
>
|
||
|
|
{/each}
|
||
|
|
</span>
|
||
|
|
</label>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div data-uix-code>
|
||
|
|
<div data-uix-code-head>
|
||
|
|
<span data-uix-layer-badge="soma">soma</span>
|
||
|
|
<span>headless · search 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</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 surface</h2>
|
||
|
|
<div data-uix-table-wrap>
|
||
|
|
<table data-uix-table>
|
||
|
|
<thead><tr><th>Prop</th><th>Owner</th><th>Default</th><th>Notes</th></tr></thead>
|
||
|
|
<tbody>
|
||
|
|
<tr
|
||
|
|
><td class="name">value</td><td>soma</td><td class="default">''</td><td
|
||
|
|
>Bindable search text</td
|
||
|
|
></tr
|
||
|
|
>
|
||
|
|
<tr
|
||
|
|
><td class="name">onValueChange</td><td>soma</td><td class="default">noop</td><td
|
||
|
|
>Live filtering path</td
|
||
|
|
></tr
|
||
|
|
>
|
||
|
|
<tr
|
||
|
|
><td class="name">onSubmit</td><td>soma</td><td class="default">noop</td><td
|
||
|
|
>Enter key path</td
|
||
|
|
></tr
|
||
|
|
>
|
||
|
|
<tr
|
||
|
|
><td class="name">onClear</td><td>soma</td><td class="default">noop</td><td
|
||
|
|
>Clear trigger / Escape path</td
|
||
|
|
></tr
|
||
|
|
>
|
||
|
|
<tr
|
||
|
|
><td class="name">clearOnEscape</td><td>soma</td><td class="default">true</td><td
|
||
|
|
>Escape clears the input</td
|
||
|
|
></tr
|
||
|
|
>
|
||
|
|
<tr
|
||
|
|
><td class="name">disabled / readonly / invalid</td><td>soma</td><td class="default"
|
||
|
|
>false</td
|
||
|
|
><td>Field integration flags</td></tr
|
||
|
|
>
|
||
|
|
<tr
|
||
|
|
><td class="name">size</td><td>eidos</td><td class="default">md</td><td
|
||
|
|
>sm | md | lg</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>Part</th><th>Marker</th><th>Element</th><th>Role</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"><{part.defaultElement}></td>
|
||
|
|
<td class="type">{part.role ?? '—'}</td>
|
||
|
|
<td class="default">{part.optional ? 'yes' : 'no'}</td>
|
||
|
|
</tr>
|
||
|
|
{/each}
|
||
|
|
</tbody>
|
||
|
|
</table>
|
||
|
|
</div>
|
||
|
|
<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>
|
||
|
|
{#each searchFieldMorfo.parts[1].keyboard ?? [] as key}
|
||
|
|
<tr><td class="name">{key.key}</td><td>{key.action}</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>
|
||
|
|
SearchField splits submit and reset so Enter and Clear/Escape can carry different perceptual
|
||
|
|
hooks while the value mutation remains owned by Soma.
|
||
|
|
</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-search-field]'
|
||
|
|
) 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 live in <code>src/uix/eidos/components/search-field/search-field.css</code>
|
||
|
|
and consume Soma empty/focus state plus Eidos <code>data-size</code>.
|
||
|
|
</p>
|
||
|
|
</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
|
||
|
|
>Input uses <code>role="searchbox"</code> and <code>type="search"</code>.</td
|
||
|
|
></tr
|
||
|
|
>
|
||
|
|
<tr
|
||
|
|
><td class="name">Label</td><td
|
||
|
|
>Input receives translated label unless a Field label wins.</td
|
||
|
|
></tr
|
||
|
|
>
|
||
|
|
<tr
|
||
|
|
><td class="name">Keyboard</td><td>Enter submits; Escape clears when enabled.</td></tr
|
||
|
|
>
|
||
|
|
<tr><td class="name">Clear</td><td>Clear trigger restores focus to the input.</td></tr>
|
||
|
|
</tbody>
|
||
|
|
</table>
|
||
|
|
</div>
|
||
|
|
</section>
|
||
|
|
{/if}
|
||
|
|
</div>
|