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

378 lines
15 KiB

<script lang="ts">
import { Section, type SectionProps, type SectionSize } from '$uix/eidos/components/section';
import { Box } from '$uix/eidos/components/box';
import { compileMorfo } from '$uix/morfo';
import { sectionMorfo } from '@/uix/morfo/components/section';
import TokensPanel from '../../lib/TokensPanel.svelte';
type Tab = 'live' | 'api' | 'morfo' | 'sema' | 'recipe' | 'tokens'
| '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);
// ── Live state — Section props ────────────────────────────────────────
let size = $state<SectionSize>('md');
let paddingY = $state<string>('');
let paddingX = $state<number>(4);
const sizeOptions: readonly SectionSize[] = ['sm', 'md', 'lg', 'xl'];
const sectionProps = $derived<Partial<SectionProps>>({
size,
paddingY: paddingY || undefined,
paddingX
});
// ── Compiled morfo ────────────────────────────────────────────────────
const compiled = compileMorfo(sectionMorfo);
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();
});
// ── Code snippet ──────────────────────────────────────────────────────
const eidosSnippet = $derived(
[
"<script lang='ts'>",
" import { Section } from '$uix/eidos/components/section';",
'</' + 'script>',
'',
'<Section',
size !== 'lg' && ` size="${size}"`,
paddingY && ` paddingY="${paddingY}"`,
paddingX > 0 && ` paddingX={${paddingX}}`,
'>',
' …',
'</Section>'
]
.filter(Boolean)
.join('\n')
);
</script>
<div data-uix-canvas-inner>
<header>
<div data-uix-eyebrow>Layout · Section</div>
<h1 data-uix-page-title>Section</h1>
<p data-uix-page-lede>
Top-level page section with consistent block-axis padding. Four size tokens
(<code>sm · md · lg · xl</code>) map to <code>--section-padding-block-{`{size}`}</code>.
It renders a real <code>&lt;section&gt;</code>, and it is a page section entire:
<code>containerSize</code> caps the measure and <code>decor</code> paints the
decorative band, both optional, plus the <code>Section.Header</code> that names it.
An unnamed <code>&lt;section&gt;</code> is not a landmark — pass
<code>aria-label</code> (or <code>aria-labelledby</code>) and it becomes a
<code>region</code>. For centred max-width content on its own use
<a href="/uix/components/container">&lt;Container&gt;</a>; for non-semantic padding use
<a href="/uix/components/box">&lt;Box&gt;</a>.
</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>sizes</span>{sizeOptions.length}
</span>
<span data-uix-meta-pill>
<span data-uix-meta-key>scope</span>eidos
</span>
</div>
</header>
<!-- Live preview always rendered -->
<div data-uix-stage>
<div
data-uix-stage-area
bind:this={stageRef}
style="background: repeating-linear-gradient(0deg, transparent 0 8px, var(--color-surface-2) 8px 9px); inline-size: 100%;"
>
<Section
{...sectionProps}
style="border: 1px dashed var(--color-border-default); border-radius: var(--radius-md); background: var(--color-surface-1);"
>
<Box
padding={3}
style="border: 1px solid var(--color-affirm-border); border-radius: var(--radius-sm); background: var(--color-affirm-track); color: var(--color-affirm-text); text-align: center;"
>
Content (padding-block: var(--section-padding-block-{size}))
</Box>
</Section>
</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>size</span>
<span>{size}</span>
<span style="margin-inline-start: auto;">
<span data-uix-stage-trace-key>paddingY</span> {paddingY || `var(--section-padding-block-${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>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 · 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 === 'tokens'} onclick={() => (tab = 'tokens')}>
Tokens <span data-uix-tab-count>4</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>
Section is eidos-native — no <span data-uix-layer-badge="soma">soma</span> split. The
horizontal hatched background shows how the block padding shifts content vertically
as <code>size</code> changes. Note the rendered element is a <code>&lt;div&gt;</code>
— see the A11y tab for guidance on adding a real landmark.
</p>
<div data-uix-subsection-head>
<span data-uix-layer-badge="eidos">eidos</span> props · padding
</div>
<div data-uix-controls>
<label data-uix-control>
<span data-uix-control-label>size <span data-uix-control-hint>→ var(--section-padding-block-N)</span></span>
<span data-uix-chips role="radiogroup">
{#each sizeOptions 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>paddingY <span data-uix-control-hint>override size-keyed default</span></span>
<input
type="text"
placeholder="(size default)"
bind:value={paddingY}
style="inline-size: 12rem;"
/>
</label>
<label data-uix-control>
<span data-uix-control-label>paddingX <span data-uix-control-hint>inherited from Box</span></span>
<input
type="number"
min="0"
max="8"
step="1"
bind:value={paddingX}
style="inline-size: 6rem;"
/>
</label>
</div>
<!-- ── Code snippet (eidos-native — no soma layer) ──────────────── -->
<div data-uix-code>
<div data-uix-code-head>
<span data-uix-layer-badge="eidos">eidos</span>
<span>visual · size-keyed block padding on top of Box</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>
Section is a one-prop specialization of <a href="/uix/components/box"
><code>&lt;Box&gt;</code></a
>: it sets <code>width: 100%</code>, picks a default
<code>padding-block</code> from <code>size</code>, and renders as
<code>&lt;section&gt;</code> (Box's own <code>as</code>). If you pass
<code>paddingY</code> directly, your value wins over the size-keyed default.
</p>
<div data-uix-subsection-head>Padding</div>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Prop</th><th>Type</th><th>Default</th><th>Notes</th></tr></thead>
<tbody>
<tr><td class="name">size</td><td class="type">sm | md | lg | xl</td><td class="default">'lg'</td><td>Maps to <code>--section-padding-block-{`{size}`}</code>: sm→8 / md→12 / lg→16 / xl→24 space steps.</td></tr>
<tr><td class="name">paddingY</td><td class="type">number | string</td><td class="default">SIZE_TO_PADDING[size]</td><td>Override the size-keyed default per-instance.</td></tr>
</tbody>
</table>
</div>
<div data-uix-subsection-head>Inherited from Box</div>
<p data-uix-section-desc>
Every <a href="/uix/components/box">BoxProps</a> field is forwarded:
<code>padding*</code>, <code>margin*</code>, <code>width</code> (locked to 100% by
Section), <code>height</code>, <code>position</code>, <code>overflow*</code>. Pass
<code>paddingX</code> for horizontal padding (no default).
</p>
<div data-uix-subsection-head>Measure, decoration and header</div>
<p data-uix-section-desc>
<code>containerSize</code> composes a <code>&lt;Container&gt;</code> INSIDE the
section; omit it and the children render directly, exactly as before the prop
existed. <code>decor</code> paints a <code>Background.Pattern</code> as a CHILD, so
the band bleeds the full width behind the measure and no extra box is gained. And
<code>Section.Header</code> is the section's name — a <code>Heading level=2</code>
and usually a <code>Text</code>, capped to a measure and revealed on scroll. The
three landed on 2026-08-19: sixteen blocks of the tier were re-wiring the same
chassis by hand, and eight had copied the same header (one had already drifted).
</p>
<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;Section&gt;</code></td><td>Radix renders a real <code>&lt;section&gt;</code> by default and takes <code>size="1..4"</code>; UIX uses named tokens (<code>sm..xl</code>) and also renders <code>&lt;section&gt;</code>, plus the measure, the decoration and the header.</td></tr>
<tr><td class="name">chakra-ui</td><td>n/a</td><td>Chakra has no dedicated Section — they recommend <code>&lt;Box as="section" py="…"&gt;</code>. UIX names the pattern as a primitive for consistency.</td></tr>
<tr><td class="name">mantine</td><td>n/a</td><td>Mantine has no Section either. Sections are usually authored ad-hoc with Stack + AppShell.</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>{sectionMorfo.name}</td></tr>
<tr><td class="name">kebab</td><td><code>{sectionMorfo.kebab}</code></td></tr>
<tr><td class="name">scope</td><td>{sectionMorfo.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);">
Section composes through <code>&lt;Box&gt;</code>, so the rendered DOM is a single
<code>div[data-box][data-section]</code> shell with a <code>data-size</code>
attribute. Recipe lives at
<code>src/uix/eidos/components/section/section.css</code> and declares the
<code>--section-padding-block-*</code> tokens locally.
</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>
Section declares no semantic events. As a passive layout primitive, it does not
commit, emerge, or react to anything — it just pads its children. Content inside the
section owns its own sema.
</p>
</section>
{/if}
{#if tab === 'tokens'}
<TokensPanel component="section" 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 lives in <code>src/uix/eidos/components/section/section.css</code>. The
<code>--section-padding-block-*</code> tokens are defined locally on the
<code>[data-section]</code> selector (intentionally not in the foundation — Section
is the sole consumer).
</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-section]</code></td>
<td><span data-uix-tag data-kind="morfo">morfo</span></td>
<td>Provider marker. Declares the per-size padding tokens and locks <code>inline-size: 100%</code>.</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>Section renders a real <code>&lt;section&gt;</code>. That is NOT a landmark on its own: a <code>&lt;section&gt;</code> is exposed as <code>region</code> only once it carries an accessible name, so an unnamed one is plain structure — which is the right default for a page that stacks many.</td></tr>
<tr><td class="name">Label</td><td>Pass <code>aria-label</code>, or <code>aria-labelledby</code> pointing at the heading inside <code>Section.Header</code>. Naming it is what turns it into a findable <code>region</code>.</td></tr>
<tr><td class="name">Keyboard</td><td>Section is not focusable. Tab order follows DOM order.</td></tr>
<tr><td class="name">Reduced motion</td><td>Section does not animate.</td></tr>
</tbody>
</table>
</div>
</section>
{/if}
</div>

Powered by TurnKey Linux.