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.
449 lines
17 KiB
449 lines
17 KiB
<script lang="ts">
|
|
import {
|
|
Link,
|
|
type LinkVariant,
|
|
type LinkUnderline,
|
|
type LinkSize,
|
|
type LinkColor
|
|
} from '$uix/eidos/components/link';
|
|
import { compileMorfo } from '$uix/morfo';
|
|
import { linkMorfo } from '@/uix/morfo/components/link';
|
|
|
|
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 variant = $state<LinkVariant>('default');
|
|
let underline = $state<LinkUnderline>('hover');
|
|
let size = $state<LinkSize | ''>('');
|
|
let color = $state<LinkColor>('primary');
|
|
let external = $state(false);
|
|
let disabled = $state(false);
|
|
let href = $state('/uix/components/link');
|
|
let content = $state('documentation');
|
|
|
|
const variants: LinkVariant[] = ['default', 'subtle', 'plain'];
|
|
const underlines: LinkUnderline[] = ['none', 'hover', 'always'];
|
|
const sizes: LinkSize[] = ['xxs', 'xs', 'sm', 'md', 'lg', 'xl'];
|
|
const colors: LinkColor[] = [
|
|
'primary',
|
|
'secondary',
|
|
'neutral',
|
|
'affirm',
|
|
'fulfill',
|
|
'risk',
|
|
'threat',
|
|
'loss'
|
|
];
|
|
|
|
const compiled = compileMorfo(linkMorfo);
|
|
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(
|
|
[
|
|
'<!-- Link is eidos-native — no soma layer. -->',
|
|
'<!-- Equivalent markup: -->',
|
|
'',
|
|
disabled ? '<span' : '<a',
|
|
!disabled && ` href="${href}"`,
|
|
' data-link',
|
|
` data-variant="${variant}"`,
|
|
` data-underline="${underline}"`,
|
|
` data-color="${color}"`,
|
|
external && !disabled && ' target="_blank"',
|
|
external && !disabled && ' rel="noopener noreferrer"',
|
|
disabled && ' aria-disabled="true"',
|
|
'>',
|
|
' ' + content,
|
|
disabled ? '</span>' : '</a>'
|
|
]
|
|
.filter(Boolean)
|
|
.join('\n')
|
|
);
|
|
|
|
const eidosSnippet = $derived(
|
|
[
|
|
"<script lang='ts'>",
|
|
" import { Link } from '$uix/eidos/components/link';",
|
|
'</' + 'script>',
|
|
'',
|
|
'<Link',
|
|
!disabled && ` href="${href}"`,
|
|
variant !== 'default' && ` variant="${variant}"`,
|
|
underline !== 'hover' && ` underline="${underline}"`,
|
|
size && ` size="${size}"`,
|
|
color !== 'primary' && ` color="${color}"`,
|
|
external && ' external',
|
|
disabled && ' disabled',
|
|
'>',
|
|
' ' + content,
|
|
'</Link>'
|
|
]
|
|
.filter(Boolean)
|
|
.join('\n')
|
|
);
|
|
</script>
|
|
|
|
<div data-uix-canvas-inner>
|
|
<header>
|
|
<div data-uix-eyebrow>Typography · Link</div>
|
|
<h1 data-uix-page-title>Link</h1>
|
|
<p data-uix-page-lede>
|
|
Inline text link primitive. Renders <code>{`<a>`}</code> by default — or
|
|
<code>{`<span aria-disabled>`}</code>
|
|
when disabled — so the link composes mid-paragraph without breaking ambient typography.
|
|
Visual variants drive color + underline; <code>external</code> adds the standard
|
|
<code>target="_blank"</code>
|
|
+ <code>rel="noopener noreferrer"</code> + screen-reader affordance. Single part. Eidos-native:
|
|
no soma backing, no semantic events on the morfo (navigation belongs to the consumer).
|
|
</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>variants</span>3
|
|
</span>
|
|
<span data-uix-meta-pill>
|
|
<span data-uix-meta-key>colors</span>8
|
|
</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}>
|
|
<p
|
|
style="max-inline-size: 38rem; padding: var(--space-3); border: 1px dashed var(--color-neutral-border); border-radius: var(--radius-md); font: inherit;"
|
|
>
|
|
Read the
|
|
<Link
|
|
{href}
|
|
{variant}
|
|
{underline}
|
|
size={size || undefined}
|
|
{color}
|
|
{external}
|
|
{disabled}
|
|
>
|
|
{content}
|
|
</Link>
|
|
for more information.
|
|
</p>
|
|
</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>variant</span>
|
|
<span>{variant}</span>
|
|
<span style="margin-inline-start: auto;">
|
|
<span data-uix-stage-trace-key>color</span> {color} ·
|
|
<span data-uix-stage-trace-key>underline</span> {underline}
|
|
</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>9</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>
|
|
Link is eidos-native — no <span data-uix-layer-badge="soma">soma</span> split. Inherits
|
|
ambient typography; local concerns are color + underline + size.
|
|
</p>
|
|
|
|
<div data-uix-subsection-head>
|
|
<span data-uix-layer-badge="eidos">eidos</span> props · visual treatment
|
|
</div>
|
|
<div data-uix-controls>
|
|
<label data-uix-control>
|
|
<span data-uix-control-label>variant</span>
|
|
<span data-uix-chips role="radiogroup">
|
|
{#each variants as opt}
|
|
<button data-uix-chip data-active={variant === opt} onclick={() => (variant = opt)}
|
|
>{opt}</button
|
|
>
|
|
{/each}
|
|
</span>
|
|
</label>
|
|
<label data-uix-control>
|
|
<span data-uix-control-label>underline</span>
|
|
<span data-uix-chips role="radiogroup">
|
|
{#each underlines as opt}
|
|
<button
|
|
data-uix-chip
|
|
data-active={underline === opt}
|
|
onclick={() => (underline = opt)}>{opt}</button
|
|
>
|
|
{/each}
|
|
</span>
|
|
</label>
|
|
<label data-uix-control>
|
|
<span data-uix-control-label>size</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>color</span>
|
|
<span data-uix-chips role="radiogroup">
|
|
{#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
|
|
>external <span data-uix-control-hint>target=_blank + SR text</span></span
|
|
>
|
|
<span data-uix-switch>
|
|
<input type="checkbox" bind:checked={external} />
|
|
<span data-uix-switch-label>{external ? 'on' : 'off'}</span>
|
|
</span>
|
|
</label>
|
|
<label data-uix-control>
|
|
<span data-uix-control-label>disabled</span>
|
|
<span data-uix-switch>
|
|
<input type="checkbox" bind:checked={disabled} />
|
|
<span data-uix-switch-label>{disabled ? 'on' : 'off'}</span>
|
|
</span>
|
|
</label>
|
|
<label data-uix-control>
|
|
<span data-uix-control-label>href</span>
|
|
<input type="text" bind:value={href} style="inline-size: 18rem;" />
|
|
</label>
|
|
<label data-uix-control>
|
|
<span data-uix-control-label>content</span>
|
|
<input type="text" bind:value={content} style="inline-size: 14rem;" />
|
|
</label>
|
|
</div>
|
|
|
|
<div data-uix-code>
|
|
<div data-uix-code-head>
|
|
<span data-uix-layer-badge="soma">soma</span>
|
|
<span>n/a · link 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 · variant + color + external</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>
|
|
Link inherits ambient typography. Local concerns are color + underline + size. <code
|
|
>external</code
|
|
>
|
|
wires the standard new-tab affordance; <code>disabled</code> swaps the tag to
|
|
<code>{`<span aria-disabled>`}</code>.
|
|
</p>
|
|
|
|
<div data-uix-subsection-head>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">href</td><td class="type">string</td><td class="default">—</td><td>Target URL.</td></tr>
|
|
<tr><td class="name">external</td><td class="type">boolean</td><td class="default">false</td><td>Adds <code>target="_blank"</code> + <code>rel</code> + SR-only "(opens in new tab)".</td></tr>
|
|
<tr><td class="name">variant</td><td class="type">'default' | 'subtle' | 'plain'</td><td class="default">'default'</td><td>Visual variant.</td></tr>
|
|
<tr><td class="name">underline</td><td class="type">'none' | 'hover' | 'always'</td><td class="default">'hover'</td><td>Underline behavior.</td></tr>
|
|
<tr><td class="name">size</td><td class="type">'xxs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl'</td><td class="default">inherit</td><td>Size override.</td></tr>
|
|
<tr><td class="name">color</td><td class="type">'primary' | 'secondary' | 'neutral' | 'affirm' | 'fulfill' | 'risk' | 'threat' | 'loss'</td><td class="default">'primary'</td><td>Intent color.</td></tr>
|
|
<tr><td class="name">disabled</td><td class="type">boolean</td><td class="default">false</td><td>Renders <code>{`<span aria-disabled>`}</code>, drops href.</td></tr>
|
|
<tr><td class="name">tagStyle</td><td class="type">string</td><td class="default">—</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><Link></code></td><td>Radix has size + weight; UIX has intent palette.</td></tr>
|
|
<tr><td class="name">chakra-ui</td><td><code><Link></code></td><td>Chakra uses <code>colorScheme</code>; UIX restricts to intent.</td></tr>
|
|
<tr><td class="name">mantine</td><td><code><Anchor></code></td><td>Mantine uses free colors; UIX intent.</td></tr>
|
|
<tr><td class="name">shadcn/ui</td><td>recipe-only</td><td>shadcn provides Tailwind classes; UIX ships a component with external affordance.</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>{linkMorfo.name}</td></tr>
|
|
<tr><td class="name">kebab</td><td><code>{linkMorfo.kebab}</code></td></tr>
|
|
<tr><td class="name">scope</td><td>{linkMorfo.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);">
|
|
The Provider stamps <code>data-link</code> on the rendered tag (default <code>{`<a>`}</code>,
|
|
or <code>{`<span>`}</code> when disabled) plus <code>data-variant</code>,
|
|
<code>data-underline</code>, <code>data-color</code> and (when set)
|
|
<code>data-external</code> / <code>data-disabled</code>.
|
|
</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>
|
|
Link declares no semantic events. Navigation / click ownership belongs to the consumer
|
|
(SvelteKit router, custom action, sema-driven verb on the surrounding component). If
|
|
Link is used as a button-style affordance (form submit, dialog action), the consumer
|
|
should wrap a <code>{`<Toolbar.Button>`}</code> instead — that surface owns the sema
|
|
commit. Hover and active visual states are CSS-only — they don't qualify as semantic
|
|
transitions.
|
|
</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/link/link.css</code>. The shell selector
|
|
is <code>[data-link]</code>; underline behavior + color are driven by data-attrs.
|
|
</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-link]</code></td><td><span data-uix-tag data-kind="morfo">morfo</span></td><td>Anchor / span shell.</td></tr>
|
|
<tr><td class="name"><code>{`[data-link][data-color='X']`}</code></td><td><span data-uix-tag data-kind="eidos">eidos</span></td><td>Intent palette.</td></tr>
|
|
<tr><td class="name"><code>{`[data-link][data-underline='none'|'hover'|'always']`}</code></td><td><span data-uix-tag data-kind="eidos">eidos</span></td><td>Underline behavior.</td></tr>
|
|
<tr><td class="name"><code>{`[data-link][data-variant='subtle'|'plain']`}</code></td><td><span data-uix-tag data-kind="eidos">eidos</span></td><td>Inherits color (variant override).</td></tr>
|
|
<tr><td class="name"><code>[data-link]:hover</code> / <code>:active</code> / <code>:focus-visible</code></td><td><span data-uix-tag data-kind="eidos">eidos</span></td><td>Interactive states.</td></tr>
|
|
<tr><td class="name"><code>[data-link][data-disabled]</code></td><td><span data-uix-tag data-kind="eidos">eidos</span></td><td>Disabled (no pointer events, dimmed).</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>Native HTML <code>{`<a>`}</code> when enabled. AT announce as "link".</td></tr>
|
|
<tr><td class="name">Disabled</td><td>Renders <code>{`<span aria-disabled="true">`}</code> without href. Out of tab order via <code>pointer-events: none</code> + missing href.</td></tr>
|
|
<tr><td class="name">External links</td><td>SR-only "(opens in new tab)" text + visible icon. <code>target="_blank"</code> always paired with <code>rel="noopener noreferrer"</code>.</td></tr>
|
|
<tr><td class="name">Focus ring</td><td>Always-on <code>:focus-visible</code> outline using <code>--color-primary-solid</code>.</td></tr>
|
|
<tr><td class="name">Color contrast</td><td>Each intent's text-token meets WCAG AA on the foundation surfaces.</td></tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</section>
|
|
{/if}
|
|
</div>
|