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.
386 lines
15 KiB
386 lines
15 KiB
<script lang="ts">
|
|
import { DropdownMenu } from '$uix/eidos/components/dropdown-menu';
|
|
import { compileMorfo } from '$uix/morfo';
|
|
import { dropdownMenuMorfo } from '@/uix/morfo/components/dropdown-menu';
|
|
|
|
type Tab = 'live' | 'api' | 'morfo' | 'sema' | 'recipe' | 'a11y';
|
|
let tab = $state<Tab>('live');
|
|
|
|
// ── Live state ──────────────────────────────────────────────────
|
|
let open = $state(false);
|
|
const sides = ['top', 'right', 'bottom', 'left'] as const;
|
|
const aligns = ['start', 'center', 'end'] as const;
|
|
let side = $state<(typeof sides)[number]>('bottom');
|
|
let align = $state<(typeof aligns)[number]>('start');
|
|
let modal = $state(true);
|
|
let notifications = $state(true);
|
|
let theme = $state<'light' | 'dark' | 'system'>('system');
|
|
let viewLayers = $state<string[]>(['ruler']);
|
|
let lastSelected = $state<string | null>(null);
|
|
|
|
function pickItem(label: string) {
|
|
return () => {
|
|
lastSelected = label;
|
|
};
|
|
}
|
|
|
|
type TraceEntry = { event: string; family: string; intent?: string; at: number };
|
|
let trace = $state<TraceEntry[]>([]);
|
|
let stageRef = $state<HTMLElement | null>(null);
|
|
|
|
$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 compiled = compileMorfo(dropdownMenuMorfo);
|
|
const partsList = $derived([...compiled.parts.byKebab.values()]);
|
|
const events = $derived([...compiled.actions.byName.values()]);
|
|
|
|
function fmtTime(at: number): string {
|
|
const d = new Date(at);
|
|
return `${String(d.getSeconds()).padStart(2, '0')}.${String(d.getMilliseconds()).padStart(3, '0')}`;
|
|
}
|
|
|
|
const somaSnippet = $derived(
|
|
[
|
|
"<script lang='ts'>",
|
|
" import * as DropdownMenu from '$soma/components/dropdown-menu';",
|
|
' let open = $state(false);',
|
|
'</' + 'script>',
|
|
'',
|
|
'<DropdownMenu.Provider',
|
|
' bind:open',
|
|
!modal && ' modal={false}',
|
|
'>',
|
|
' <DropdownMenu.Trigger>Open menu</DropdownMenu.Trigger>',
|
|
` <DropdownMenu.Content side="${side}" align="${align}">`,
|
|
' <DropdownMenu.Item onSelect={...}>Profile</DropdownMenu.Item>',
|
|
' <DropdownMenu.Separator />',
|
|
' <DropdownMenu.CheckboxItem bind:checked>Notifications</DropdownMenu.CheckboxItem>',
|
|
' <DropdownMenu.RadioGroup bind:value>',
|
|
' <DropdownMenu.RadioItem value="light">Light</DropdownMenu.RadioItem>',
|
|
' <DropdownMenu.RadioItem value="dark">Dark</DropdownMenu.RadioItem>',
|
|
' </DropdownMenu.RadioGroup>',
|
|
' </DropdownMenu.Content>',
|
|
'</DropdownMenu.Provider>'
|
|
]
|
|
.filter(Boolean)
|
|
.join('\n')
|
|
);
|
|
|
|
const eidosSnippet = $derived(
|
|
[
|
|
"<script lang='ts'>",
|
|
" import { DropdownMenu } from '$uix/eidos/components/dropdown-menu';",
|
|
' let open = $state(false);',
|
|
'</' + 'script>',
|
|
'',
|
|
'<DropdownMenu',
|
|
' bind:open',
|
|
!modal && ' modal={false}',
|
|
'>',
|
|
' <DropdownMenu.Trigger>Open menu</DropdownMenu.Trigger>',
|
|
` <DropdownMenu.Content side="${side}" align="${align}">`,
|
|
' <DropdownMenu.Group>',
|
|
' <DropdownMenu.GroupHeading>Account</DropdownMenu.GroupHeading>',
|
|
' <DropdownMenu.Item onSelect={...}>Profile</DropdownMenu.Item>',
|
|
' </DropdownMenu.Group>',
|
|
' <DropdownMenu.Separator />',
|
|
' <DropdownMenu.CheckboxItem bind:checked>Notifications</DropdownMenu.CheckboxItem>',
|
|
' <DropdownMenu.Sub>',
|
|
' <DropdownMenu.SubTrigger>More options</DropdownMenu.SubTrigger>',
|
|
' <DropdownMenu.SubContent>',
|
|
' <DropdownMenu.Item>Nested</DropdownMenu.Item>',
|
|
' </DropdownMenu.SubContent>',
|
|
' </DropdownMenu.Sub>',
|
|
' </DropdownMenu.Content>',
|
|
'</DropdownMenu>'
|
|
]
|
|
.filter(Boolean)
|
|
.join('\n')
|
|
);
|
|
</script>
|
|
|
|
<div data-uix-canvas-inner>
|
|
<header>
|
|
<div data-uix-eyebrow>Overlay · DropdownMenu</div>
|
|
<h1 data-uix-page-title>DropdownMenu</h1>
|
|
<p data-uix-page-lede>
|
|
Anchored menu opened by a button trigger. Compound API parity with
|
|
Radix DropdownMenu / Bits UI: Items, Groups (with GroupHeading),
|
|
Separators, optional Checkbox / Radio items with array-binding
|
|
groups, nested Sub-menus and an optional Arrow pointer.
|
|
<span data-uix-layer-badge="soma">soma</span> owns positioning,
|
|
keyboard navigation, focus trap, and dismissal — eidos paints
|
|
panel chrome and item rows uniformly across levels.
|
|
</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>open</span>{open ? 'true' : 'false'}
|
|
</span>
|
|
{#if lastSelected}
|
|
<span data-uix-meta-pill>
|
|
<span data-uix-meta-key>last</span>{lastSelected}
|
|
</span>
|
|
{/if}
|
|
</div>
|
|
</header>
|
|
|
|
<div data-uix-stage>
|
|
<div data-uix-stage-area bind:this={stageRef}>
|
|
<DropdownMenu bind:open {modal}>
|
|
<DropdownMenu.Trigger>Open menu</DropdownMenu.Trigger>
|
|
<DropdownMenu.Content {side} {align}>
|
|
<DropdownMenu.Group>
|
|
<DropdownMenu.GroupHeading>Account</DropdownMenu.GroupHeading>
|
|
<DropdownMenu.Item onSelect={pickItem('Profile')}>Profile</DropdownMenu.Item>
|
|
<DropdownMenu.Item onSelect={pickItem('Settings')}>Settings</DropdownMenu.Item>
|
|
</DropdownMenu.Group>
|
|
<DropdownMenu.Separator />
|
|
<DropdownMenu.CheckboxItem bind:checked={notifications}>
|
|
Show notifications
|
|
</DropdownMenu.CheckboxItem>
|
|
<DropdownMenu.CheckboxGroup bind:value={viewLayers}>
|
|
<DropdownMenu.GroupHeading>View</DropdownMenu.GroupHeading>
|
|
<DropdownMenu.CheckboxItem value="ruler">Ruler</DropdownMenu.CheckboxItem>
|
|
<DropdownMenu.CheckboxItem value="grid">Grid</DropdownMenu.CheckboxItem>
|
|
<DropdownMenu.CheckboxItem value="guides">Guides</DropdownMenu.CheckboxItem>
|
|
</DropdownMenu.CheckboxGroup>
|
|
<DropdownMenu.Separator />
|
|
<DropdownMenu.RadioGroup bind:value={theme}>
|
|
<DropdownMenu.GroupHeading>Theme</DropdownMenu.GroupHeading>
|
|
<DropdownMenu.RadioItem value="light">Light</DropdownMenu.RadioItem>
|
|
<DropdownMenu.RadioItem value="dark">Dark</DropdownMenu.RadioItem>
|
|
<DropdownMenu.RadioItem value="system">System</DropdownMenu.RadioItem>
|
|
</DropdownMenu.RadioGroup>
|
|
<DropdownMenu.Separator />
|
|
<DropdownMenu.Sub>
|
|
<DropdownMenu.SubTrigger>More options</DropdownMenu.SubTrigger>
|
|
<DropdownMenu.SubContent>
|
|
<DropdownMenu.Item onSelect={pickItem('Export…')}>Export…</DropdownMenu.Item>
|
|
<DropdownMenu.Item onSelect={pickItem('Import…')}>Import…</DropdownMenu.Item>
|
|
<DropdownMenu.Item disabled>Sync (offline)</DropdownMenu.Item>
|
|
</DropdownMenu.SubContent>
|
|
</DropdownMenu.Sub>
|
|
<DropdownMenu.Separator />
|
|
<DropdownMenu.Item onSelect={pickItem('Log out')}>Log out</DropdownMenu.Item>
|
|
</DropdownMenu.Content>
|
|
</DropdownMenu>
|
|
</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>
|
|
{#if trace[0]}
|
|
<span style="color: var(--uix-text-faint)">·</span>
|
|
<span data-uix-stage-trace-key>last</span>
|
|
<span>{trace[0].event} ({trace[0].family}) @{fmtTime(trace[0].at)}</span>
|
|
{/if}
|
|
</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>15</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>
|
|
</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>
|
|
<div data-uix-subsection-head>
|
|
<span data-uix-layer-badge="soma">soma</span> props · positioning + behaviour
|
|
</div>
|
|
<div data-uix-controls>
|
|
<label data-uix-control>
|
|
<span data-uix-control-label>side</span>
|
|
<span data-uix-chips role="radiogroup">
|
|
{#each sides as opt}
|
|
<button data-uix-chip data-active={side === opt} onclick={() => (side = opt)}>{opt}</button>
|
|
{/each}
|
|
</span>
|
|
</label>
|
|
<label data-uix-control>
|
|
<span data-uix-control-label>align</span>
|
|
<span data-uix-chips role="radiogroup">
|
|
{#each aligns as opt}
|
|
<button data-uix-chip data-active={align === opt} onclick={() => (align = opt)}>{opt}</button>
|
|
{/each}
|
|
</span>
|
|
</label>
|
|
<label data-uix-control data-control-kind="switch">
|
|
<input type="checkbox" bind:checked={modal} /> modal (overlay)
|
|
</label>
|
|
</div>
|
|
|
|
<div data-uix-code>
|
|
<div data-uix-code-head>
|
|
<span data-uix-layer-badge="soma">soma</span>
|
|
<span>headless · positioning + keyboard</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 · namespaced compound</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>
|
|
15 pass-through parts over <code>soma/components/dropdown-menu</code>.
|
|
No evaluative props at the eidos layer — visual treatment is
|
|
uniform across menu surfaces.
|
|
</p>
|
|
<div data-uix-table-wrap>
|
|
<table data-uix-table>
|
|
<thead><tr><th>Part</th><th>Notes</th></tr></thead>
|
|
<tbody>
|
|
<tr><td class="name">DropdownMenu (root)</td><td>Provider; bind:open, modal, dir.</td></tr>
|
|
<tr><td class="name">Trigger</td><td>Toggle button — bring your own visual.</td></tr>
|
|
<tr><td class="name">Content</td><td>Floating panel — side/align/collisions in soma.</td></tr>
|
|
<tr><td class="name">Arrow</td><td>Optional anchor pointer.</td></tr>
|
|
<tr><td class="name">Item</td><td><code>role=menuitem</code>, <code>onSelect</code>, <code>closeOnSelect</code>.</td></tr>
|
|
<tr><td class="name">Group / GroupHeading</td><td>Semantic grouping with <code>aria-labelledby</code>.</td></tr>
|
|
<tr><td class="name">Separator</td><td><code>role=separator</code>, 1px divider.</td></tr>
|
|
<tr><td class="name">CheckboxItem</td><td><code>role=menuitemcheckbox</code>; bind:checked.</td></tr>
|
|
<tr><td class="name">CheckboxGroup</td><td>Binds an array; child CheckboxItems use <code>value</code>.</td></tr>
|
|
<tr><td class="name">RadioGroup / RadioItem</td><td><code>role=menuitemradio</code> inside <code>role=group</code>.</td></tr>
|
|
<tr><td class="name">Sub / SubTrigger / SubContent</td><td>Nested fly-out menu (ArrowRight to open).</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>Kebab</th><th>Role</th><th>Marker</th><th>Kind</th></tr></thead>
|
|
<tbody>
|
|
{#each partsList as part}
|
|
{@const partAny = part as unknown as Record<string, unknown>}
|
|
<tr>
|
|
<td class="name">{partAny.kebab}</td>
|
|
<td>{partAny.role ?? '—'}</td>
|
|
<td><code>{partAny.marker ?? '—'}</code></td>
|
|
<td>{partAny.kind ?? '—'}</td>
|
|
</tr>
|
|
{/each}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</section>
|
|
{/if}
|
|
|
|
{#if tab === 'sema'}
|
|
<section data-uix-section>
|
|
<h2 data-uix-section-title>
|
|
<span data-uix-layer-badge="sema">sema</span> · events
|
|
</h2>
|
|
<div data-uix-table-wrap>
|
|
<table data-uix-table>
|
|
<thead><tr><th>Name</th><th>Family</th><th>Verb</th><th>Sequence</th></tr></thead>
|
|
<tbody>
|
|
{#each events as action}
|
|
{@const sem = action.semantic}
|
|
<tr>
|
|
<td class="name">{action.name}</td>
|
|
<td class="type">{sem.family}</td>
|
|
<td>{sem.verb ?? '—'}</td>
|
|
<td>{sem.sequence ?? 'pre'}</td>
|
|
</tr>
|
|
{/each}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</section>
|
|
{/if}
|
|
|
|
{#if tab === 'recipe'}
|
|
<section data-uix-section>
|
|
<h2 data-uix-section-title>Eidos recipe</h2>
|
|
<p data-uix-section-desc>
|
|
<code>dropdown-menu.css</code>. Uniform chrome across Content
|
|
and SubContent; items share one set of tokens so a fly-out
|
|
reads identically to the root menu.
|
|
</p>
|
|
</section>
|
|
{/if}
|
|
|
|
{#if tab === 'a11y'}
|
|
<section data-uix-section>
|
|
<h2 data-uix-section-title>A11y</h2>
|
|
<p data-uix-section-desc>
|
|
WAI-ARIA APG <a
|
|
href="https://www.w3.org/WAI/ARIA/apg/patterns/menu-button/"
|
|
target="_blank"
|
|
rel="noopener">Menu Button</a
|
|
>.
|
|
</p>
|
|
<div data-uix-table-wrap>
|
|
<table data-uix-table>
|
|
<thead><tr><th>Key</th><th>Effect</th></tr></thead>
|
|
<tbody>
|
|
<tr><td><kbd>Enter</kbd> / <kbd>Space</kbd> (on Trigger)</td><td>Open the menu.</td></tr>
|
|
<tr><td><kbd>ArrowDown</kbd> (on Trigger)</td><td>Open + focus first item.</td></tr>
|
|
<tr><td><kbd>ArrowUp</kbd> / <kbd>ArrowDown</kbd></td><td>Move focus prev / next.</td></tr>
|
|
<tr><td><kbd>Home</kbd> / <kbd>End</kbd></td><td>Focus first / last.</td></tr>
|
|
<tr><td>Typeahead</td><td>Focus first item whose text matches.</td></tr>
|
|
<tr><td><kbd>Enter</kbd> / <kbd>Space</kbd></td><td>Activate item; close menu by default.</td></tr>
|
|
<tr><td><kbd>Escape</kbd></td><td>Close menu; return focus to Trigger.</td></tr>
|
|
<tr><td><kbd>ArrowRight</kbd> on SubTrigger</td><td>Open submenu; focus first item.</td></tr>
|
|
<tr><td><kbd>ArrowLeft</kbd> in SubContent</td><td>Close submenu; return focus.</td></tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</section>
|
|
{/if}
|
|
</div>
|