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.
387 lines
15 KiB
387 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';
|
|
|
|
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);
|
|
|
|
// ── 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 snippets ─────────────────────────────────────────────────────
|
|
const somaSnippet = $derived(
|
|
[
|
|
'<!-- Section is eidos-native — no soma layer. -->',
|
|
'<!-- Equivalent semantic markup (not real soma): -->',
|
|
'',
|
|
'<div',
|
|
' data-box',
|
|
' data-section',
|
|
` data-size="${size}"`,
|
|
` style="inline-size: 100%; padding-block: var(--section-padding-block-${size});"`,
|
|
'>',
|
|
' …',
|
|
'</div>'
|
|
].join('\n')
|
|
);
|
|
|
|
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>.
|
|
Despite the name, Section currently renders as <code><div></code> — there is no
|
|
<code>as</code> prop yet, so when you need a real <code><section></code> landmark,
|
|
wrap or nest one. For centred max-width content use
|
|
<a href="/uix/components/container"><Container></a>; for non-semantic padding use
|
|
<a href="/uix/components/box"><Box></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 === '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><div></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 snippets per layer ─────────────────────────────────── -->
|
|
<div data-uix-code>
|
|
<div data-uix-code-head>
|
|
<span data-uix-layer-badge="soma">soma</span>
|
|
<span>n/a · section 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 · 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><Box></code></a
|
|
>: it sets <code>width: 100%</code>, picks a default
|
|
<code>padding-block</code> from <code>size</code>, and renders as <code><div></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>Limitations</div>
|
|
<p data-uix-section-desc>
|
|
Section currently has no <code>as</code> prop — the rendered element is always
|
|
<code><div></code>. Add a <code><section></code> wrapper outside Section
|
|
(or nest a <code><section></code> as the first child) when landmark semantics
|
|
are needed.
|
|
</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><Section></code></td><td>Radix renders a real <code><section></code> by default and takes <code>size="1..4"</code>; UIX uses named tokens (<code>sm..xl</code>) and renders <code><div></code> pending an <code>as</code> prop.</td></tr>
|
|
<tr><td class="name">chakra-ui</td><td>n/a</td><td>Chakra has no dedicated Section — they recommend <code><Box as="section" py="…"></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"><{part.defaultElement}></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><Box></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 === '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>None implicit. Despite the name, Section renders as <code><div></code> — there is no implicit <code>region</code> role. Wrap Section in a real <code><section aria-labelledby="…"></code> or use a heading inside to provide landmark structure.</td></tr>
|
|
<tr><td class="name">Label</td><td>Not applicable to Section itself. If you wrap a real <code><section></code> around it, label it with <code>aria-labelledby</code> pointing at the heading.</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>
|