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

547 lines
19 KiB

<script lang="ts">
import {
Display,
type DisplaySize,
type DisplayFamily,
type DisplayWeight,
type DisplayColor,
type DisplayAlign,
type DisplayTracking
} from '$uix/eidos/components/display';
import { compileMorfo } from '$uix/morfo';
import { displayMorfo } from '@/uix/morfo/components/display';
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 size = $state<DisplaySize | ''>('');
let family = $state<DisplayFamily | ''>('');
let weight = $state<DisplayWeight | ''>('');
let color = $state<DisplayColor | ''>('');
let align = $state<DisplayAlign | ''>('');
let tracking = $state<DisplayTracking | ''>('');
let italic = $state(false);
let underline = $state(false);
let truncate = $state(false);
let clamp = $state<number>(0);
let content = $state('Welcome to UIX.');
let asTag = $state<string>('h1');
const sizes: DisplaySize[] = ['xxs', 'xs', 'sm', 'md', 'lg', 'xl', 'xxl', 'xxxl'];
const families: DisplayFamily[] = ['primary', 'secondary', 'mono', 'display'];
const weights: DisplayWeight[] = ['regular', 'medium', 'semibold', 'bold'];
const colors: DisplayColor[] = ['primary', 'secondary', 'muted', 'disabled', 'on-solid'];
const alignOptions = ['', 'start', 'center', 'end', 'justify'] as const;
const trackingOptions = ['', 'tight', 'normal', 'wide'] as const;
const tagOptions = ['h1', 'h2', 'div', 'p', 'span'] as const;
const compiled = compileMorfo(displayMorfo);
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(
[
'<!-- Display is eidos-native — no soma layer. -->',
'<!-- Equivalent semantic markup: -->',
'',
`<${asTag}`,
' data-display',
tracking && ` data-tracking="${tracking}"`,
' style="font-family: var(--style-hero-font-family); …"',
'>',
` ${content}`,
`</${asTag}>`
]
.filter(Boolean)
.join('\n')
);
const eidosSnippet = $derived(
[
"<script lang='ts'>",
" import { Display } from '$uix/eidos/components/display';",
'</' + 'script>',
'',
'<Display',
asTag !== 'h1' && ` as="${asTag}"`,
size && ` size="${size}"`,
family && ` family="${family}"`,
weight && ` weight="${weight}"`,
color && ` color="${color}"`,
align && ` align="${align}"`,
tracking && ` tracking="${tracking}"`,
italic && ' italic',
underline && ' underline',
truncate && ' truncate',
clamp > 0 && ` clamp={${clamp}}`,
'>',
' ' + content,
'</Display>'
]
.filter(Boolean)
.join('\n')
);
</script>
<div data-uix-canvas-inner>
<header>
<div data-uix-eyebrow>Typography · Display</div>
<h1 data-uix-page-title>Display</h1>
<p data-uix-page-lede>
Hero / oversize typography primitive. Always uses the foundation's
<code>--style-hero-*</code>
tokens, which scale up at the <code>md</code> breakpoint. Default tag is
<code>{`<h1>`}</code>
(use <code>as</code> when the hero look is needed outside heading semantics). The
<code>tracking</code>
prop is the deliberate letter-spacing knob — at hero sizes the value is a design decision.
Single part. Eidos-native: no soma backing, no semantic events.
</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>0
</span>
<span data-uix-meta-pill>
<span data-uix-meta-key>responsive</span>md
</span>
<span data-uix-meta-pill>
<span data-uix-meta-key>tracking</span>3
</span>
<span data-uix-meta-pill>
<span data-uix-meta-key>scope</span>eidos
</span>
</div>
</header>
<div data-uix-stage>
<div data-uix-stage-area bind:this={stageRef}>
<div
style="max-inline-size: 42rem; padding: var(--space-3); border: 1px dashed var(--color-neutral-border); border-radius: var(--radius-md);"
>
<Display
as={asTag}
size={size || undefined}
family={family || undefined}
weight={weight || undefined}
color={color || undefined}
align={align || undefined}
tracking={tracking || undefined}
{italic}
{underline}
{truncate}
clamp={clamp > 0 ? clamp : undefined}
>
{content}
</Display>
</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>style</span>
<span>hero</span>
<span style="margin-inline-start: auto;">
<span data-uix-stage-trace-key>tag</span> &lt;{asTag}&gt; ·
<span data-uix-stage-trace-key>tracking</span> {tracking || 'default'}
</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 · 0e</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>
Display is eidos-native — no <span data-uix-layer-badge="soma">soma</span> split. Always
consumes <code>--style-hero-*</code>; per-axis overrides write inline
<code>--_display-*</code>
CSS variables.
</p>
<div data-uix-subsection-head>
<span data-uix-layer-badge="eidos">eidos</span> props · hero treatment
</div>
<div data-uix-controls>
<label data-uix-control>
<span data-uix-control-label>as <span data-uix-control-hint>rendered tag</span></span>
<span data-uix-chips role="radiogroup">
{#each tagOptions as opt}
<button data-uix-chip data-active={asTag === opt} onclick={() => (asTag = opt)}>
&lt;{opt}&gt;
</button>
{/each}
</span>
</label>
<label data-uix-control>
<span data-uix-control-label>size override</span>
<span data-uix-chips role="radiogroup">
<button data-uix-chip data-active={size === ''} onclick={() => (size = '')}
>inherit</button
>
{#each sizes as opt}
<button data-uix-chip data-active={size === opt} onclick={() => (size = opt)}
>{opt}</button
>
{/each}
</span>
</label>
<label data-uix-control>
<span data-uix-control-label>family override</span>
<span data-uix-chips role="radiogroup">
<button data-uix-chip data-active={family === ''} onclick={() => (family = '')}
>inherit</button
>
{#each families as opt}
<button data-uix-chip data-active={family === opt} onclick={() => (family = opt)}
>{opt}</button
>
{/each}
</span>
</label>
<label data-uix-control>
<span data-uix-control-label>weight override</span>
<span data-uix-chips role="radiogroup">
<button data-uix-chip data-active={weight === ''} onclick={() => (weight = '')}
>inherit</button
>
{#each weights as opt}
<button data-uix-chip data-active={weight === opt} onclick={() => (weight = opt)}
>{opt}</button
>
{/each}
</span>
</label>
<label data-uix-control>
<span data-uix-control-label>color override</span>
<span data-uix-chips role="radiogroup">
<button data-uix-chip data-active={color === ''} onclick={() => (color = '')}
>inherit</button
>
{#each colors as opt}
<button data-uix-chip data-active={color === opt} onclick={() => (color = opt)}
>{opt}</button
>
{/each}
</span>
</label>
<label data-uix-control>
<span data-uix-control-label>align</span>
<span data-uix-chips role="radiogroup">
{#each alignOptions as opt}
<button data-uix-chip data-active={align === opt} onclick={() => (align = opt)}
>{opt || 'inherit'}</button
>
{/each}
</span>
</label>
<label data-uix-control>
<span data-uix-control-label
>tracking <span data-uix-control-hint>letter-spacing</span></span
>
<span data-uix-chips role="radiogroup">
{#each trackingOptions as opt}
<button
data-uix-chip
data-active={tracking === opt}
onclick={() => (tracking = opt)}>{opt || 'default'}</button
>
{/each}
</span>
</label>
<label data-uix-control>
<span data-uix-control-label>italic</span>
<span data-uix-switch>
<input type="checkbox" bind:checked={italic} />
<span data-uix-switch-label>{italic ? 'on' : 'off'}</span>
</span>
</label>
<label data-uix-control>
<span data-uix-control-label>underline</span>
<span data-uix-switch>
<input type="checkbox" bind:checked={underline} />
<span data-uix-switch-label>{underline ? 'on' : 'off'}</span>
</span>
</label>
<label data-uix-control>
<span data-uix-control-label>truncate</span>
<span data-uix-switch>
<input type="checkbox" bind:checked={truncate} />
<span data-uix-switch-label>{truncate ? 'on' : 'off'}</span>
</span>
</label>
<label data-uix-control>
<span data-uix-control-label
>clamp <span data-uix-control-hint>multi-line cap (0 = off)</span></span
>
<input
type="number"
min="0"
max="10"
step="1"
bind:value={clamp}
style="inline-size: 6rem;"
/>
</label>
<label data-uix-control style="grid-column: span 2;">
<span data-uix-control-label>content</span>
<input type="text" bind:value={content} style="inline-size: 100%; font: inherit;" />
</label>
</div>
<div data-uix-code>
<div data-uix-code-head>
<span data-uix-layer-badge="soma">soma</span>
<span>n/a · display is eidos-native — equivalent markup shown</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 · hero style + per-axis overrides</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>
Display always uses the foundation's <code>--style-hero-*</code> tokens. Per-axis props
override individual fields without breaking the hero cascade. <code>tracking</code> maps
to fixed em values because foundation letter-spacing tokens are mostly 0 at hero scale.
</p>
<div data-uix-subsection-head>Per-axis overrides</div>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Prop</th><th>Type</th><th>Notes</th></tr></thead>
<tbody>
<tr
><td class="name">size</td><td class="type"
>'xxs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl' | 'xxxl'</td
><td>Override the hero size step.</td></tr
>
<tr
><td class="name">family</td><td class="type"
>'primary' | 'secondary' | 'mono' | 'display'</td
><td>Override the hero family.</td></tr
>
<tr
><td class="name">weight</td><td class="type"
>'regular' | 'medium' | 'semibold' | 'bold'</td
><td>Override the hero weight.</td></tr
>
<tr
><td class="name">color</td><td class="type"
>'primary' | 'secondary' | 'muted' | 'disabled' | 'on-solid'</td
><td>Content-role color slot.</td></tr
>
<tr
><td class="name">align</td><td class="type"
>'start' | 'center' | 'end' | 'justify'</td
><td>Maps to <code>text-align</code>.</td></tr
>
<tr
><td class="name">tracking</td><td class="type"
>'tight' | 'normal' | 'wide'</td
><td>Letter-spacing: -0.02em / 0 / 0.02em.</td></tr
>
</tbody>
</table>
</div>
<div data-uix-subsection-head>Shorthand booleans + truncation</div>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Prop</th><th>Type</th><th>Notes</th></tr></thead>
<tbody>
<tr><td class="name">italic</td><td class="type">boolean</td><td><code>font-style: italic</code>.</td></tr>
<tr><td class="name">underline</td><td class="type">boolean</td><td><code>text-decoration: underline</code>.</td></tr>
<tr><td class="name">truncate</td><td class="type">boolean</td><td>Single-line ellipsis.</td></tr>
<tr><td class="name">clamp</td><td class="type">number</td><td>Multi-line cap via <code>-webkit-line-clamp</code>.</td></tr>
</tbody>
</table>
</div>
<div data-uix-subsection-head>Element + escape hatch</div>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Prop</th><th>Type</th><th>Notes</th></tr></thead>
<tbody>
<tr><td class="name">as</td><td class="type">string</td><td>HTML tag. Default <code>'h1'</code>.</td></tr>
<tr><td class="name">tagStyle</td><td class="type">string</td><td>Extra inline CSS.</td></tr>
</tbody>
</table>
</div>
<div data-uix-subsection-head>Reference comparison</div>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Library</th><th>Closest equivalent</th><th>Difference</th></tr></thead>
<tbody>
<tr><td class="name">radix-themes</td><td><code>&lt;Heading size="9"&gt;</code></td><td>Radix uses a large heading size; UIX has a dedicated Display surface.</td></tr>
<tr><td class="name">chakra-ui</td><td><code>&lt;Heading as="h1"&gt;</code></td><td>Chakra reuses Heading; UIX splits.</td></tr>
<tr><td class="name">mantine</td><td><code>&lt;Title order={`{1}`}&gt;</code></td><td>Mantine's Title is the only heading primitive; UIX has Heading + Display.</td></tr>
<tr><td class="name">mui Typography</td><td><code>variant="h1"</code></td><td>MUI's h1 ≈ UIX Display when consumer overrides <code>fontSize</code>.</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>Field</th><th>Value</th></tr></thead>
<tbody>
<tr><td class="name">name</td><td>{displayMorfo.name}</td></tr>
<tr><td class="name">kebab</td><td><code>{displayMorfo.kebab}</code></td></tr>
<tr><td class="name">scope</td><td>{displayMorfo.scope.join(', ')}</td></tr>
<tr><td class="name">parts</td><td>{partsList.length}</td></tr>
<tr><td class="name">events</td><td>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>kebab</th><th>marker</th><th>element</th><th>archetype</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.archetype}</td>
<td class="default">{part.optional ? 'yes' : 'no'}</td>
</tr>
{/each}
</tbody>
</table>
</div>
<p data-uix-section-desc style="margin-top: var(--uix-space-4);">
The Provider stamps <code>data-display</code> on the rendered tag (default
<code>{`<h1>`}</code>). The hero cascade is always-on; per-axis overrides come from
<code>--_display-*</code>
inline. <code>data-tracking</code> reflects the active tracking key for downstream
styling.
</p>
</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>
Display declares no semantic events. As a passive primitive, it simply renders hero
typography. Components that animate hero titles (landing-page entrance, dialog hero)
compose Display inside an interactive surface that owns the relevant sema verb.
</p>
</section>
{/if}
{#if tab === 'recipe'}
<section data-uix-section>
<h2 data-uix-section-title>Eidos recipe</h2>
<p data-uix-section-desc>
Recipe lives in <code>src/uix/eidos/components/display/display.css</code>. The selector
<code>[data-display]</code>
applies the hero cascade. Per-axis overrides come from inline <code>--_display-*</code>
CSS variables; tracking maps to fixed em values via the same channel.
</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-display]</code></td><td><span data-uix-tag data-kind="morfo">morfo</span></td><td>Provider marker. Default hero-style applied.</td></tr>
<tr><td class="name"><code>{`[data-display][data-italic|data-underline|data-truncate|data-clamp]`}</code></td><td><span data-uix-tag data-kind="eidos">eidos</span></td><td>Visual modifier flags.</td></tr>
</tbody>
</table>
</div>
</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>Default tag <code>{`<h1>`}</code> — page-level heading. Use <code>as</code> when display typography is needed outside heading semantics (e.g. marketing pull-quote → <code>as="p"</code>).</td></tr>
<tr><td class="name">Single h1 per page</td><td>Convention: only one <code>{`<h1>`}</code> per document. Display defaults to that; switch to <code>as</code> if a second hero appears.</td></tr>
<tr><td class="name">Truncation + AT</td><td>CSS-only — full text remains in DOM. AT read the full hero.</td></tr>
<tr><td class="name">Color contrast</td><td>Content-role colors meet WCAG AA. Free colors via <code>tagStyle</code> bypass that guarantee.</td></tr>
</tbody>
</table>
</div>
</section>
{/if}
</div>

Powered by TurnKey Linux.