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.
461 lines
17 KiB
461 lines
17 KiB
<script lang="ts">
|
|
import { Wrap, type WrapProps } from '$uix/eidos/components/wrap';
|
|
import { Box } from '$uix/eidos/components/box';
|
|
import { compileMorfo } from '$uix/morfo';
|
|
import { wrapMorfo } from '@/uix/morfo/components/wrap';
|
|
|
|
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 — Wrap container props ─────────────────────────────────
|
|
let gap = $state<number>(2);
|
|
let rowGap = $state<number>(0);
|
|
let columnGap = $state<number>(0);
|
|
let align = $state<'stretch' | 'start' | 'center' | 'end' | 'baseline'>('center');
|
|
let justify = $state<
|
|
'start' | 'center' | 'end' | 'space-between' | 'space-around' | 'space-evenly' | 'stretch'
|
|
>('start');
|
|
let padding = $state<number>(4);
|
|
let itemCount = $state<number>(12);
|
|
|
|
const alignOptions = ['stretch', 'start', 'center', 'end', 'baseline'] as const;
|
|
const justifyOptions = [
|
|
'start',
|
|
'center',
|
|
'end',
|
|
'space-between',
|
|
'space-around',
|
|
'space-evenly',
|
|
'stretch'
|
|
] as const;
|
|
|
|
const wrapProps = $derived<Partial<WrapProps>>({
|
|
gap,
|
|
rowGap: rowGap || undefined,
|
|
columnGap: columnGap || undefined,
|
|
align,
|
|
justify,
|
|
padding
|
|
});
|
|
|
|
// ── Compiled morfo ────────────────────────────────────────────────────
|
|
const compiled = compileMorfo(wrapMorfo);
|
|
const partsList = $derived([...compiled.parts.byKebab.values()]);
|
|
const events = $derived([...compiled.actions.byName.values()]);
|
|
|
|
const pillLabels = [
|
|
'svelte',
|
|
'kit',
|
|
'vite',
|
|
'eslint',
|
|
'prettier',
|
|
'typescript',
|
|
'playwright',
|
|
'vitest',
|
|
'lucide',
|
|
'zod',
|
|
'tailwind',
|
|
'turbo',
|
|
'pnpm',
|
|
'storybook',
|
|
'css',
|
|
'html'
|
|
];
|
|
const pills = $derived(pillLabels.slice(0, itemCount));
|
|
|
|
$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(
|
|
[
|
|
'<!-- Wrap is eidos-native — no soma layer. -->',
|
|
'<!-- Equivalent semantic markup (not real soma): -->',
|
|
'',
|
|
'<div',
|
|
' data-box',
|
|
' data-flex',
|
|
' data-wrap',
|
|
' style="display: flex; flex-wrap: wrap; gap: var(--space-2);"',
|
|
'>',
|
|
' …',
|
|
'</div>'
|
|
].join('\n')
|
|
);
|
|
|
|
const eidosSnippet = $derived(
|
|
[
|
|
"<script lang='ts'>",
|
|
" import { Wrap } from '$uix/eidos/components/wrap';",
|
|
'</' + 'script>',
|
|
'',
|
|
'<Wrap',
|
|
gap > 0 && ` gap={${gap}}`,
|
|
rowGap > 0 && ` rowGap={${rowGap}}`,
|
|
columnGap > 0 && ` columnGap={${columnGap}}`,
|
|
align !== 'stretch' && ` align="${align}"`,
|
|
justify !== 'start' && ` justify="${justify}"`,
|
|
padding > 0 && ` padding={${padding}}`,
|
|
'>',
|
|
' {#each tags as tag}<Tag>{tag}</Tag>{/each}',
|
|
'</Wrap>'
|
|
]
|
|
.filter(Boolean)
|
|
.join('\n')
|
|
);
|
|
</script>
|
|
|
|
<div data-uix-canvas-inner>
|
|
<header>
|
|
<div data-uix-eyebrow>Layout · Wrap</div>
|
|
<h1 data-uix-page-title>Wrap</h1>
|
|
<p data-uix-page-lede>
|
|
Flex row that <em>always</em> wraps. Use for tag/chip clusters, filter bars or anything
|
|
that should reflow across multiple lines on narrow viewports. Equivalent to
|
|
<a href="/uix/components/flex"><Flex wrap="wrap"></a> with two extra ergonomic
|
|
gap-axis shorthands (<code>rowGap</code>, <code>columnGap</code>). For nowrap clusters
|
|
use <a href="/uix/components/group"><Group></a>; for arbitrary flex direction use
|
|
<code><Flex></code>.
|
|
</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>extends</span>Flex
|
|
</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}>
|
|
<Wrap
|
|
{...wrapProps}
|
|
style="border: 1px dashed var(--color-border-default); border-radius: var(--radius-md); max-inline-size: 32rem; min-block-size: 8rem;"
|
|
>
|
|
{#each pills as label}
|
|
<Box
|
|
paddingX={3}
|
|
paddingY={1}
|
|
style="border: 1px solid var(--color-border-default); border-radius: 999px; background: var(--color-surface-2); font-size: 0.875rem;"
|
|
>{label}</Box>
|
|
{/each}
|
|
</Wrap>
|
|
</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>items</span>
|
|
<span>{pills.length}</span>
|
|
<span style="margin-inline-start: auto;">
|
|
<span data-uix-stage-trace-key>gap</span> {gap} ·
|
|
<span data-uix-stage-trace-key>justify</span> {justify}
|
|
</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>5</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>
|
|
Wrap is eidos-native — no <span data-uix-layer-badge="soma">soma</span> split. Locks
|
|
<code>flex-wrap: wrap</code> and exposes 5 container props on top of <code><Flex></code>.
|
|
The stage caps width at 32rem to demonstrate reflow.
|
|
</p>
|
|
|
|
<div data-uix-subsection-head>
|
|
<span data-uix-layer-badge="eidos">eidos</span> props · wrap behaviour
|
|
</div>
|
|
<div data-uix-controls>
|
|
<label data-uix-control>
|
|
<span data-uix-control-label>gap <span data-uix-control-hint>both axes</span></span>
|
|
<input type="number" min="0" max="8" step="1" bind:value={gap} style="inline-size: 6rem;" />
|
|
</label>
|
|
<label data-uix-control>
|
|
<span data-uix-control-label>rowGap <span data-uix-control-hint>between wrapped lines</span></span>
|
|
<input
|
|
type="number"
|
|
min="0"
|
|
max="8"
|
|
step="1"
|
|
bind:value={rowGap}
|
|
style="inline-size: 6rem;"
|
|
/>
|
|
</label>
|
|
<label data-uix-control>
|
|
<span data-uix-control-label>columnGap <span data-uix-control-hint>between items in a line</span></span>
|
|
<input
|
|
type="number"
|
|
min="0"
|
|
max="8"
|
|
step="1"
|
|
bind:value={columnGap}
|
|
style="inline-size: 6rem;"
|
|
/>
|
|
</label>
|
|
<label data-uix-control>
|
|
<span data-uix-control-label>align <span data-uix-control-hint>per-line cross-axis</span></span>
|
|
<span data-uix-chips role="radiogroup">
|
|
{#each alignOptions as opt}
|
|
<button data-uix-chip data-active={align === opt} onclick={() => (align = opt)}
|
|
>{opt}</button
|
|
>
|
|
{/each}
|
|
</span>
|
|
</label>
|
|
<label data-uix-control>
|
|
<span data-uix-control-label>justify <span data-uix-control-hint>main-axis</span></span>
|
|
<span data-uix-chips role="radiogroup">
|
|
{#each justifyOptions as opt}
|
|
<button data-uix-chip data-active={justify === opt} onclick={() => (justify = opt)}
|
|
>{opt}</button
|
|
>
|
|
{/each}
|
|
</span>
|
|
</label>
|
|
<label data-uix-control>
|
|
<span data-uix-control-label>padding <span data-uix-control-hint>inherited from Box</span></span>
|
|
<input
|
|
type="number"
|
|
min="0"
|
|
max="8"
|
|
step="1"
|
|
bind:value={padding}
|
|
style="inline-size: 6rem;"
|
|
/>
|
|
</label>
|
|
<label data-uix-control>
|
|
<span data-uix-control-label>items <span data-uix-control-hint>demo content count</span></span>
|
|
<input
|
|
type="number"
|
|
min="1"
|
|
max="16"
|
|
step="1"
|
|
bind:value={itemCount}
|
|
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 · wrap 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 · always wraps · per-axis gap shorthands</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>
|
|
Wrap is a narrow specialization of <a href="/uix/components/flex"
|
|
><code><Flex></code></a
|
|
>: locks <code>wrap</code> to <code>'wrap'</code>, drops <code>direction</code>
|
|
(always row), and elevates <code>rowGap</code> / <code>columnGap</code> as
|
|
first-class props because per-axis gaps are the typical reason to reach for Wrap.
|
|
</p>
|
|
|
|
<div data-uix-subsection-head>Container props</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">gap</td><td class="type">number | string</td><td class="default empty">—</td><td>Shorthand for both axes. Number → <code>var(--space-N)</code>.</td></tr>
|
|
<tr><td class="name">rowGap</td><td class="type">number | string</td><td class="default empty">—</td><td>Gap between wrapped lines.</td></tr>
|
|
<tr><td class="name">columnGap</td><td class="type">number | string</td><td class="default empty">—</td><td>Gap between items within a line.</td></tr>
|
|
<tr><td class="name">align</td><td class="type">stretch | start | center | end | baseline | flex-start | flex-end</td><td class="default empty">—</td><td><code>align-items</code> per line — cross-axis.</td></tr>
|
|
<tr><td class="name">justify</td><td class="type">start | center | end | space-between | space-around | space-evenly | stretch | flex-start | flex-end</td><td class="default empty">—</td><td><code>justify-content</code> — main-axis.</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 through Flex:
|
|
<code>padding*</code>, <code>margin*</code>, <code>width</code>, <code>height</code>,
|
|
<code>position</code>, <code>overflow*</code>, plus item-side props.
|
|
</p>
|
|
|
|
<div data-uix-subsection-head>Not on Wrap (use Flex instead)</div>
|
|
<p data-uix-section-desc>
|
|
<code>direction</code> (Wrap is always row), <code>wrap</code> (locked to wrap),
|
|
<code>inline</code> — Wrap intentionally omits these. Use <a
|
|
href="/uix/components/flex"><code><Flex></code></a
|
|
> when you need them.
|
|
</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><Flex wrap="wrap"></code></td><td>Radix doesn't ship a separate Wrap — they recommend Flex with the <code>wrap</code> prop. UIX names it for the common chip-cluster case.</td></tr>
|
|
<tr><td class="name">chakra-ui</td><td><code><Wrap></code> / <code><WrapItem></code></td><td>Chakra wraps each child in a <code><WrapItem></code> internally. UIX has no item wrapper — gap is owned by the container.</td></tr>
|
|
<tr><td class="name">mantine</td><td><code><Group wrap="wrap"></code></td><td>Mantine collapses both into Group with a prop. UIX splits Group (nowrap) and Wrap (wrap) because their visual intent is different.</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>{wrapMorfo.name}</td></tr>
|
|
<tr><td class="name">kebab</td><td><code>{wrapMorfo.kebab}</code></td></tr>
|
|
<tr><td class="name">scope</td><td>{wrapMorfo.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);">
|
|
Wrap composes through <code><Flex wrap="wrap"></code> which composes through
|
|
<code><Box></code>, so the rendered DOM is a single
|
|
<code>div[data-box][data-flex][data-wrap]</code> shell.
|
|
</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>
|
|
Wrap declares no semantic events. As a passive layout primitive, it does not commit,
|
|
emerge, or react to anything — it just arranges its children. Tags/chips/buttons
|
|
inside the Wrap own their 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/wrap/wrap.css</code>. The
|
|
<code>data-wrap</code> marker is mostly for consumer targeting; the actual
|
|
<code>flex-wrap: wrap</code> behaviour is set by the underlying Flex layer because Wrap
|
|
renders as <code><Flex wrap="wrap"></code>.
|
|
</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-wrap]</code></td>
|
|
<td><span data-uix-tag data-kind="morfo">morfo</span></td>
|
|
<td>Provider marker. Used by consumers for targeting; <code>flex-wrap</code> comes from the Flex layer.</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. Default element is <code><div></code>. When wrapping a list of tags/filters, consider <code>role="list"</code> + <code>role="listitem"</code> on the children for screen-reader semantics.</td></tr>
|
|
<tr><td class="name">Label</td><td>Not applicable — Wrap has no content semantics.</td></tr>
|
|
<tr><td class="name">Keyboard</td><td>Wrap is not focusable. Tab order follows DOM order; wrapped lines do not change the focus sequence. For arrow-key cluster navigation use a tag-group or toolbar soma.</td></tr>
|
|
<tr><td class="name">Reduced motion</td><td>Wrap does not animate. Reflow on resize follows CSS defaults.</td></tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</section>
|
|
{/if}
|
|
</div>
|