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

518 lines
17 KiB

<script lang="ts">
import { Meter, type MeterShape, type MeterSize } from '$uix/eidos/components/meter';
import { compileMorfo } from '$uix/morfo';
import { meterMorfo } from '@/uix/morfo/components/meter';
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 value = $state(72);
let min = $state(0);
let max = $state(100);
let low = $state(25);
let high = $state(80);
let optimum = $state(60);
let size = $state<MeterSize>('md');
let shape = $state<MeterShape>('linear');
let labelText = $state('Storage usage');
let valueTextOverride = $state('');
const valueText = $derived(valueTextOverride.trim() || undefined);
const zone = $derived(value < low ? 'below' : value > high ? 'above' : 'optimum');
const compiled = compileMorfo(meterMorfo);
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 somaSnippet = $derived(
[
"<script lang='ts'>",
" import * as Meter from '$soma/components/meter';",
` let value = $state(${value});`,
'</' + 'script>',
'',
'<Meter.Provider',
' {value}',
min !== 0 && ` min={${min}}`,
max !== 100 && ` max={${max}}`,
low !== min && ` low={${low}}`,
high !== max && ` high={${high}}`,
optimum !== (low + high) / 2 && ` optimum={${optimum}}`,
valueText && ` valueText="${valueText}"`,
` aria-label="${labelText}"`,
'>',
' <Meter.Indicator />',
'</Meter.Provider>'
]
.filter(Boolean)
.join('\n')
);
const eidosSnippet = $derived(
[
"<script lang='ts'>",
" import { Meter } from '$uix/eidos/components/meter';",
` let value = $state(${value});`,
'</' + 'script>',
'',
'<Meter',
' {value}',
size !== 'md' && ` size="${size}"`,
shape !== 'linear' && ` shape="${shape}"`,
min !== 0 && ` min={${min}}`,
max !== 100 && ` max={${max}}`,
low !== min && ` low={${low}}`,
high !== max && ` high={${high}}`,
optimum !== (low + high) / 2 && ` optimum={${optimum}}`,
valueText && ` valueText="${valueText}"`,
` aria-label="${labelText}"`,
'>',
' <Meter.Indicator />',
'</Meter>'
]
.filter(Boolean)
.join('\n')
);
</script>
<div data-uix-canvas-inner>
<header>
<div data-uix-eyebrow>Status · Meter</div>
<h1 data-uix-page-title>Meter</h1>
<p data-uix-page-lede>
Known-range measurement primitive for values such as storage, battery or score. Soma owns <code
>role="meter"</code
>, thresholds and zone state; Eidos adds visual size, shape 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>shapes</span>2</span>
<span data-uix-meta-pill><span data-uix-meta-key>zones</span>3</span>
</div>
</header>
<div data-uix-stage>
<div data-uix-stage-area bind:this={stageRef}>
<div style="inline-size: min(30rem, 100%); display: grid; gap: var(--uix-space-3);">
<div
style="display: flex; justify-content: space-between; gap: var(--uix-space-3); color: var(--uix-text-muted); font-size: 0.9rem;"
>
<span>{labelText}</span>
<span>{value} / {max}</span>
</div>
<Meter
{value}
{min}
{max}
{low}
{high}
{optimum}
{size}
{shape}
{valueText}
aria-label={labelText}
>
<Meter.Indicator />
</Meter>
</div>
</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>zone</span>
<span data-uix-stage-trace-event>{zone}</span>
<span style="color: var(--uix-text-faint)">·</span>
<span data-uix-stage-trace-key>value</span>
<span>{value} / {max}</span>
<span style="margin-inline-start: auto;">
<span data-uix-stage-trace-key>size</span>
{size}
<span data-uix-stage-trace-key style="margin-inline-start: var(--uix-space-2);">shape</span>
{shape}
</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>
Controls are grouped by owner. <span data-uix-layer-badge="soma">soma</span>
owns measurement, thresholds and zone; <span data-uix-layer-badge="eidos">eidos</span>
owns visual size and shape.
</p>
<div data-uix-subsection-head>
<span data-uix-layer-badge="soma">soma</span> props · measurement
</div>
<div data-uix-controls>
<label data-uix-control>
<span data-uix-control-label>value <span data-uix-control-hint>{value}</span></span>
<input type="range" bind:value {min} {max} />
</label>
<label data-uix-control>
<span data-uix-control-label>min</span>
<input type="number" bind:value={min} />
</label>
<label data-uix-control>
<span data-uix-control-label>max</span>
<input type="number" bind:value={max} />
</label>
<label data-uix-control>
<span data-uix-control-label>low</span>
<input type="number" bind:value={low} />
</label>
<label data-uix-control>
<span data-uix-control-label>high</span>
<input type="number" bind:value={high} />
</label>
<label data-uix-control>
<span data-uix-control-label>optimum</span>
<input type="number" bind:value={optimum} />
</label>
<label data-uix-control>
<span data-uix-control-label>valueText override</span>
<input type="text" bind:value={valueTextOverride} placeholder="e.g. 72 GB used" />
</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', 'xl'] as s}
<button data-uix-chip data-active={size === s} onclick={() => (size = s as MeterSize)}
>{s}</button
>
{/each}
</span>
</label>
<label data-uix-control>
<span data-uix-control-label>shape</span>
<span data-uix-chips role="radiogroup">
{#each ['linear', 'circular'] as s}
<button
data-uix-chip
data-active={shape === s}
onclick={() => (shape = s as MeterShape)}>{s}</button
>
{/each}
</span>
</label>
<label data-uix-control>
<span data-uix-control-label>label text</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 + zone contract</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 + shape</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>Prop</th><th>Type</th><th>Default</th><th>Description</th></tr></thead>
<tbody>
<tr
><td class="name">value</td><td class="type">number</td><td class="default">0</td><td
>Current measurement.</td
></tr
>
<tr
><td class="name">min / max</td><td class="type">number</td><td class="default"
>0 / 100</td
><td>Meter bounds.</td></tr
>
<tr
><td class="name">low / high / optimum</td><td class="type">number</td><td
class="default">min / max / midpoint</td
><td>Thresholds for `below`, `optimum`, `above` zone state.</td></tr
>
<tr
><td class="name">valueText</td><td class="type">string</td><td class="default empty"
>—</td
><td>Accessible value text override.</td></tr
>
<tr
><td class="name">aria-label / aria-labelledby</td><td class="type">string</td><td
class="default">translated Meter</td
><td>Accessible name.</td></tr
>
<tr
><td class="name">size <span data-uix-tag data-kind="eidos">eidos</span></td><td
class="type">ResponsiveProp&lt;'sm'|'md'|'lg'&gt;</td
><td class="default">'md'</td><td>Track thickness.</td></tr
>
<tr
><td class="name">shape <span data-uix-tag data-kind="eidos">eidos</span></td><td
class="type">ResponsiveProp&lt;'linear'|'circular'&gt;</td
><td class="default">'linear'</td><td>Visual presentation: bar or gauge ring.</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/meter.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">"{meterMorfo.name}"</td></tr>
<tr><td class="name">kebab</td><td class="type">"{meterMorfo.kebab}"</td></tr>
<tr
><td class="name">scope</td><td class="type"
>[{meterMorfo.scope.map((s) => `"${s}"`).join(', ')}]</td
></tr
>
<tr
><td class="name">parts.length</td><td class="default">{meterMorfo.parts.length}</td
></tr
>
<tr><td class="name">events.length</td><td class="default">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>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 meterMorfo.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;
}>;
}}
{@const dataAttrs = compiled.contracts.dataAttrsByPart.get(partAny.kebab) ?? []}
{@const ariaAttrs = partAny.aria ?? []}
{#if dataAttrs.length || ariaAttrs.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}
{/each}
</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>
This morfo declares no semantic events. If the component grows user-triggered perceptual
feedback, the event must be declared in Morfo first and surfaced here.
</p>
<div data-uix-empty-state>No Sema events declared.</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/meter/meter.css</code>. The fill reads Soma's
<code>--_meter-value-pct</code> and zone attrs.
</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-meter][data-state]</td><td
><span data-uix-tag data-kind="soma">morfo</span></td
></tr
>
<tr
><td class="name">[data-meter][data-size]</td><td
><span data-uix-tag data-kind="eidos">eidos</span></td
></tr
>
<tr
><td class="name">[data-meter][data-shape]</td><td
><span data-uix-tag data-kind="eidos">eidos</span></td
></tr
>
<tr
><td class="name">[data-meter-indicator][data-state]</td><td
><span data-uix-tag data-kind="soma">morfo</span></td
></tr
>
<tr
><td class="name">--_meter-value-pct / low / high / optimum</td><td
><span data-uix-tag data-kind="soma">runtime CSS vars</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>
Meter represents a static known-range value. It is not for task completion; use Progress for
ongoing work.
</p>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Attribute</th><th>Value</th></tr></thead>
<tbody>
<tr><td>role</td><td class="type">meter</td></tr>
<tr><td>aria-valuemin / aria-valuemax</td><td class="type">min / max</td></tr>
<tr><td>aria-valuenow</td><td class="type">value</td></tr>
<tr><td>aria-valuetext</td><td class="type">valueText when supplied</td></tr>
<tr><td>aria-label / aria-labelledby</td><td class="type">accessible name</td></tr>
</tbody>
</table>
</div>
</section>
{/if}
</div>

Powered by TurnKey Linux.