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.
796 lines
29 KiB
796 lines
29 KiB
<script lang="ts">
|
|
import { Form, type FormLayout, type FormSize, type FormVariant } from '$uix/eidos/components/form';
|
|
import { Field } from '$uix/eidos/components/field';
|
|
import { compileMorfo } from '$uix/morfo';
|
|
import { formMorfo } from '@/uix/morfo/components/form';
|
|
import { getActiveUix } from '$active-uix';
|
|
import {
|
|
createForm,
|
|
type Form as FormHandle,
|
|
type FormErrors,
|
|
type FormIssue,
|
|
type ValidationBehaviour
|
|
} from '$libs/forms';
|
|
import { object, string, number, boolean, enumOf, pipe, min, max, email, integer, meta } from '$sium/core';
|
|
|
|
const uix = getActiveUix();
|
|
|
|
type Tab = 'live' | 'api' | 'morfo' | 'sema' | 'recipe' | 'a11y';
|
|
type DemoMode = 'manual' | 'auto';
|
|
type ProfileRole = 'designer' | 'developer' | 'researcher';
|
|
type ProfileValues = {
|
|
fullName: string;
|
|
email: string;
|
|
age: number;
|
|
role: ProfileRole;
|
|
newsletter: boolean;
|
|
};
|
|
type TraceEntry = { event: string; family: string; intent?: string; at: number };
|
|
type ProfileFormMap = Record<ValidationBehaviour, FormHandle<ProfileValues>>;
|
|
|
|
const roleOptions: ProfileRole[] = ['designer', 'developer', 'researcher'];
|
|
const validationBehaviours: ValidationBehaviour[] = [
|
|
'onChange',
|
|
'progressive',
|
|
'onBlur',
|
|
'onSubmit'
|
|
];
|
|
const profileSchema = object({
|
|
fullName: pipe(string(), min(2), meta({ label: 'Full name' })),
|
|
email: pipe(string(), email(), meta({ label: 'Email' })),
|
|
age: pipe(number(), integer(), min(18), max(80), meta({ label: 'Age' })),
|
|
role: pipe(enumOf(['designer', 'developer', 'researcher']), meta({ label: 'Role' })),
|
|
newsletter: pipe(boolean(), meta({ label: 'Newsletter' }))
|
|
});
|
|
const manualDefaults: ProfileValues = {
|
|
fullName: 'Ada Lovelace',
|
|
email: 'ada@example.com',
|
|
age: 36,
|
|
role: 'developer',
|
|
newsletter: false
|
|
};
|
|
const autoDefaults: ProfileValues = {
|
|
fullName: 'Ada Lovelace',
|
|
email: 'ada@example.com',
|
|
age: 36,
|
|
role: 'researcher',
|
|
newsletter: true
|
|
};
|
|
|
|
let tab = $state<Tab>('live');
|
|
let mode = $state<DemoMode>('manual');
|
|
let validationBehaviour = $state<ValidationBehaviour>('onChange');
|
|
let size = $state<FormSize>('md');
|
|
let layout = $state<FormLayout>('stack');
|
|
let variant = $state<FormVariant>('panel');
|
|
let trace = $state<TraceEntry[]>([]);
|
|
let stageRef = $state<HTMLElement | null>(null);
|
|
let manualResult = $state('No valid submit yet.');
|
|
let manualInvalid = $state('Edit a field to an invalid value to see SIUM issues.');
|
|
let autoResult = $state('No valid submit yet.');
|
|
let autoInvalid = $state('AutoFields uses the same SIUM schema and form runtime.');
|
|
|
|
function createProfileForm(
|
|
defaults: ProfileValues,
|
|
validation: ValidationBehaviour,
|
|
onValidSubmit: (values: unknown) => void,
|
|
onInvalidSubmit: (errors: FormErrors) => void
|
|
): FormHandle<ProfileValues> {
|
|
return createForm({
|
|
schema: profileSchema,
|
|
defaults,
|
|
validationBehaviour: validation,
|
|
onValidSubmit,
|
|
onInvalidSubmit
|
|
});
|
|
}
|
|
|
|
const manualForms = Object.fromEntries(
|
|
validationBehaviours.map((validation) => [
|
|
validation,
|
|
createProfileForm(
|
|
manualDefaults,
|
|
validation,
|
|
(values) => {
|
|
manualResult = JSON.stringify(values, null, 2);
|
|
manualInvalid = 'No invalid issues.';
|
|
},
|
|
(errors) => {
|
|
manualInvalid = summarizeErrors(errors);
|
|
}
|
|
)
|
|
])
|
|
) as ProfileFormMap;
|
|
const autoForms = Object.fromEntries(
|
|
validationBehaviours.map((validation) => [
|
|
validation,
|
|
createProfileForm(
|
|
autoDefaults,
|
|
validation,
|
|
(values) => {
|
|
autoResult = JSON.stringify(values, null, 2);
|
|
autoInvalid = 'No invalid issues.';
|
|
},
|
|
(errors) => {
|
|
autoInvalid = summarizeErrors(errors);
|
|
}
|
|
)
|
|
])
|
|
) as ProfileFormMap;
|
|
|
|
const compiled = compileMorfo(formMorfo);
|
|
const partsList = $derived([...compiled.parts.byKebab.values()]);
|
|
const events = $derived([...compiled.actions.byName.values()]);
|
|
const manualForm = $derived(manualForms[validationBehaviour]);
|
|
const autoForm = $derived(autoForms[validationBehaviour]);
|
|
const activeForm = $derived(mode === 'manual' ? manualForm : autoForm);
|
|
const activeResult = $derived(mode === 'manual' ? manualResult : autoResult);
|
|
const activeInvalid = $derived(mode === 'manual' ? manualInvalid : autoInvalid);
|
|
|
|
$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();
|
|
});
|
|
|
|
function fmtTime(at: number): string {
|
|
const d = new Date(at);
|
|
return `${String(d.getSeconds()).padStart(2, '0')}.${String(d.getMilliseconds()).padStart(3, '0')}`;
|
|
}
|
|
|
|
function fallbackMessage(raw: string | undefined, params?: Record<string, unknown>): string {
|
|
if (!raw) return '';
|
|
const template = raw.startsWith('#?') && raw.includes('|') ? raw.slice(raw.indexOf('|') + 1) : raw;
|
|
if (!params) return template;
|
|
return Object.entries(params).reduce(
|
|
(acc, [key, value]) => acc.replaceAll(`{{${key}}}`, String(value)),
|
|
template
|
|
);
|
|
}
|
|
|
|
function issueText(form: FormHandle<ProfileValues>, field: string): string {
|
|
const issue = (form.issues[field] as FormIssue[] | undefined)?.[0];
|
|
if (issue) return fallbackMessage(issue.message, issue.params);
|
|
return fallbackMessage(form.errors[field]?.[0]);
|
|
}
|
|
|
|
function summarizeErrors(errors: FormErrors): string {
|
|
const flat = Object.entries(errors).flatMap(([field, messages]) =>
|
|
messages.map((message) => `${field || 'form'}: ${fallbackMessage(message)}`)
|
|
);
|
|
return flat.length ? flat.join('\n') : 'No invalid issues.';
|
|
}
|
|
|
|
function setManualAge(event: Event): void {
|
|
const target = event.currentTarget as HTMLInputElement;
|
|
manualForm.values.age = Number(target.value);
|
|
}
|
|
|
|
function setManualRole(event: Event): void {
|
|
const target = event.currentTarget as HTMLSelectElement;
|
|
if (roleOptions.includes(target.value as ProfileRole)) {
|
|
manualForm.values.role = target.value as ProfileRole;
|
|
}
|
|
}
|
|
|
|
function setManualNewsletter(event: Event): void {
|
|
const target = event.currentTarget as HTMLInputElement;
|
|
manualForm.values.newsletter = target.checked;
|
|
}
|
|
|
|
const somaSnippet = $derived(
|
|
[
|
|
"<script lang='ts'>",
|
|
" import * as Form from '$soma/components/form';",
|
|
" import * as Field from '$soma/components/field';",
|
|
" import { createForm } from '$libs/forms';",
|
|
" import { object, string, number, pipe, min, max, email, integer, meta } from '$sium/core';",
|
|
'',
|
|
' const schema = object({',
|
|
" fullName: pipe(string(), min(2), meta({ label: 'Full name' })),",
|
|
" email: pipe(string(), email(), meta({ label: 'Email' })),",
|
|
" age: pipe(number(), integer(), min(18), max(80), meta({ label: 'Age' }))",
|
|
' });',
|
|
` const form = createForm({ schema, defaults: { fullName: 'Ada Lovelace', email: 'ada@example.com', age: 36 }, validationBehaviour: '${validationBehaviour}' });`,
|
|
'</' + 'script>',
|
|
'',
|
|
'<Form.Provider {form} {schema}>',
|
|
' <Form.ErrorSummary />',
|
|
' <Field.Provider name="fullName" label="Full name" required>',
|
|
' <Field.Label>Full name <Field.RequiredIndicator /></Field.Label>',
|
|
' <Field.Control><Field.Input bind:value={form.values.fullName} /></Field.Control>',
|
|
' <Field.ErrorText>{form.errors.fullName?.[0]}</Field.ErrorText>',
|
|
' </Field.Provider>',
|
|
' <Field.Provider name="age" label="Age" required>',
|
|
' <Field.Label>Age <Field.RequiredIndicator /></Field.Label>',
|
|
' <Field.Control>',
|
|
' <input type="number" bind:value={form.values.age} />',
|
|
' </Field.Control>',
|
|
' <Field.ErrorText>{form.errors.age?.[0]}</Field.ErrorText>',
|
|
' </Field.Provider>',
|
|
' <Form.Submit>Save profile</Form.Submit>',
|
|
'</Form.Provider>'
|
|
].join('\n')
|
|
);
|
|
|
|
const eidosSnippet = $derived(
|
|
[
|
|
"<script lang='ts'>",
|
|
" import { Form } from '$uix/eidos/components/form';",
|
|
" import { Field } from '$uix/eidos/components/field';",
|
|
" import { createForm } from '$libs/forms';",
|
|
" import { object, string, number, pipe, min, max, email, integer, meta } from '$sium/core';",
|
|
'',
|
|
' const schema = object({',
|
|
" fullName: pipe(string(), min(2), meta({ label: 'Full name' })),",
|
|
" email: pipe(string(), email(), meta({ label: 'Email' })),",
|
|
" age: pipe(number(), integer(), min(18), max(80), meta({ label: 'Age' }))",
|
|
' });',
|
|
` const form = createForm({ schema, defaults: { fullName: 'Ada Lovelace', email: 'ada@example.com', age: 36 }, validationBehaviour: '${validationBehaviour}' });`,
|
|
'</' + 'script>',
|
|
'',
|
|
'<Form',
|
|
' {form}',
|
|
' {schema}',
|
|
size !== 'md' && ` size="${size}"`,
|
|
layout !== 'stack' && ` layout="${layout}"`,
|
|
variant !== 'plain' && ` variant="${variant}"`,
|
|
'>',
|
|
' <Form.ErrorSummary />',
|
|
' <Field name="fullName" label="Full name" required>',
|
|
' <Field.Label>Full name <Field.RequiredIndicator /></Field.Label>',
|
|
' <Field.Control><Field.Input bind:value={form.values.fullName} /></Field.Control>',
|
|
' <Field.ErrorText>{form.errors.fullName?.[0]}</Field.ErrorText>',
|
|
' </Field>',
|
|
' <Field name="age" label="Age" required>',
|
|
' <Field.Label>Age <Field.RequiredIndicator /></Field.Label>',
|
|
' <Field.Control>',
|
|
' <input type="number" bind:value={form.values.age} />',
|
|
' </Field.Control>',
|
|
' <Field.ErrorText>{form.errors.age?.[0]}</Field.ErrorText>',
|
|
' </Field>',
|
|
' <Form.Submit color="fulfill">Save profile</Form.Submit>',
|
|
'</Form>'
|
|
]
|
|
.filter(Boolean)
|
|
.join('\n')
|
|
);
|
|
</script>
|
|
|
|
<div data-uix-canvas-inner>
|
|
<header>
|
|
<div data-uix-eyebrow>Forms · Form</div>
|
|
<h1 data-uix-page-title>Form</h1>
|
|
<p data-uix-page-lede>
|
|
Form runtime backed by SIUM / Standard Schema validation. Soma owns submit/reset,
|
|
field registration, touched/dirty/error state and focus on first error; Eidos adds
|
|
layout, panel chrome and action styling. The live preview includes manual Field
|
|
composition and schema-driven AutoFields.
|
|
</p>
|
|
<div data-uix-page-meta>
|
|
<span data-uix-meta-pill><span data-uix-meta-key>parts</span>{partsList.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>schema</span>SIUM</span>
|
|
<span data-uix-meta-pill><span data-uix-meta-key>validation</span>{validationBehaviour}</span>
|
|
</div>
|
|
</header>
|
|
|
|
<div data-uix-stage>
|
|
<div data-uix-stage-area bind:this={stageRef}>
|
|
<div class="form-demo-shell">
|
|
{#if mode === 'manual'}
|
|
<Form form={manualForm} schema={profileSchema} {size} {layout} {variant}>
|
|
<Form.ErrorSummary hideUntilSubmitted={false}>
|
|
{#snippet children(summary)}
|
|
<strong>{summary.count} validation issue{summary.count === 1 ? '' : 's'}</strong>
|
|
<ul>
|
|
{#each summary.fieldErrors as err}
|
|
<li>{err.field}: {fallbackMessage(err.message)}</li>
|
|
{/each}
|
|
</ul>
|
|
{/snippet}
|
|
</Form.ErrorSummary>
|
|
|
|
<Field name="fullName" label="Full name" required>
|
|
<Field.Label>Full name <Field.RequiredIndicator /></Field.Label>
|
|
<Field.Control>
|
|
<Field.Input
|
|
type="text"
|
|
name="fullName"
|
|
bind:value={manualForm.values.fullName}
|
|
placeholder="Ada Lovelace"
|
|
/>
|
|
</Field.Control>
|
|
<Field.HelperText>Minimum 2 characters.</Field.HelperText>
|
|
<Field.ErrorText>{issueText(manualForm, 'fullName')}</Field.ErrorText>
|
|
</Field>
|
|
|
|
<Field name="email" label="Email" required>
|
|
<Field.Label>Email <Field.RequiredIndicator /></Field.Label>
|
|
<Field.Control>
|
|
<Field.Input
|
|
type="email"
|
|
name="email"
|
|
bind:value={manualForm.values.email}
|
|
placeholder="ada@example.com"
|
|
/>
|
|
</Field.Control>
|
|
<Field.HelperText>Validated by SIUM email().</Field.HelperText>
|
|
<Field.ErrorText>{issueText(manualForm, 'email')}</Field.ErrorText>
|
|
</Field>
|
|
|
|
<Field name="age" label="Age" required>
|
|
<Field.Label>Age <Field.RequiredIndicator /></Field.Label>
|
|
<Field.Control>
|
|
<input
|
|
class="form-demo-native-control"
|
|
type="number"
|
|
min="0"
|
|
value={String(manualForm.values.age)}
|
|
oninput={setManualAge}
|
|
/>
|
|
</Field.Control>
|
|
<Field.HelperText>Integer between 18 and 80.</Field.HelperText>
|
|
<Field.ErrorText>{issueText(manualForm, 'age')}</Field.ErrorText>
|
|
</Field>
|
|
|
|
<Field name="role" label="Role" required>
|
|
<Field.Label>Role <Field.RequiredIndicator /></Field.Label>
|
|
<Field.Control>
|
|
<select
|
|
class="form-demo-native-control"
|
|
value={manualForm.values.role}
|
|
onchange={setManualRole}
|
|
>
|
|
{#each roleOptions as option}
|
|
<option value={option}>{option}</option>
|
|
{/each}
|
|
</select>
|
|
</Field.Control>
|
|
<Field.ErrorText>{issueText(manualForm, 'role')}</Field.ErrorText>
|
|
</Field>
|
|
|
|
<label class="form-demo-check">
|
|
<input
|
|
type="checkbox"
|
|
checked={manualForm.values.newsletter}
|
|
onchange={setManualNewsletter}
|
|
/>
|
|
<span>Receive release notes</span>
|
|
</label>
|
|
|
|
<div class="form-demo-actions">
|
|
<Form.Reset>Reset</Form.Reset>
|
|
<Form.Submit color="fulfill">Save profile</Form.Submit>
|
|
</div>
|
|
</Form>
|
|
{:else}
|
|
<Form form={autoForm} schema={profileSchema} {size} {layout} {variant}>
|
|
<Form.ErrorSummary />
|
|
<Form.AutoFields schema={profileSchema} />
|
|
<div class="form-demo-actions">
|
|
<Form.Reset>Reset</Form.Reset>
|
|
<Form.Submit color="fulfill">Submit AutoFields</Form.Submit>
|
|
</div>
|
|
</Form>
|
|
{/if}
|
|
</div>
|
|
</div>
|
|
<div data-uix-stage-trace>
|
|
<span data-uix-stage-trace-key>trace</span>
|
|
{#if trace.length === 0}
|
|
<span>submit or reset the form to see Sema events</span>
|
|
{:else}
|
|
{#each trace.slice(0, 3) as entry}
|
|
<span>
|
|
<span data-uix-stage-trace-event>{entry.event}</span>
|
|
· {entry.family}{entry.intent ? ' · ' + entry.intent : ''}
|
|
</span>
|
|
<span style="color: var(--uix-text-faint)">{fmtTime(entry.at)}</span>
|
|
{/each}
|
|
{/if}
|
|
<span style="margin-inline-start: auto;">
|
|
<span data-uix-stage-trace-key>valid</span>
|
|
{String(activeForm.isValid)}
|
|
· <span data-uix-stage-trace-key>mode</span>
|
|
{validationBehaviour}
|
|
</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>11</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>
|
|
<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>
|
|
The same SIUM schema drives both demos. Manual mode composes Eidos Field parts.
|
|
AutoFields walks the SIUM AST and renders widgets from schema metadata.
|
|
</p>
|
|
|
|
<div data-uix-subsection-head>
|
|
<span data-uix-layer-badge="soma">soma</span> props · validation and form state
|
|
</div>
|
|
<div data-uix-controls>
|
|
<label data-uix-control>
|
|
<span data-uix-control-label>demo mode</span>
|
|
<span data-uix-chips role="radiogroup">
|
|
{#each ['manual', 'auto'] as item}
|
|
<button
|
|
data-uix-chip
|
|
data-active={mode === item}
|
|
onclick={() => (mode = item as DemoMode)}
|
|
>
|
|
{item}
|
|
</button>
|
|
{/each}
|
|
</span>
|
|
</label>
|
|
<label data-uix-control>
|
|
<span data-uix-control-label>
|
|
validationBehaviour <span data-uix-control-hint>real-time = onChange</span>
|
|
</span>
|
|
<span data-uix-chips role="radiogroup">
|
|
{#each validationBehaviours as item}
|
|
<button
|
|
data-uix-chip
|
|
data-active={validationBehaviour === item}
|
|
onclick={() => (validationBehaviour = item)}
|
|
>
|
|
{item}
|
|
</button>
|
|
{/each}
|
|
</span>
|
|
</label>
|
|
<div data-uix-control>
|
|
<span data-uix-control-label>isDirty</span>
|
|
<span>{String(activeForm.isDirty)}</span>
|
|
</div>
|
|
<div data-uix-control>
|
|
<span data-uix-control-label>isTouched</span>
|
|
<span>{String(activeForm.isTouched)}</span>
|
|
</div>
|
|
<div data-uix-control>
|
|
<span data-uix-control-label>submitCount</span>
|
|
<span>{activeForm.submitCount}</span>
|
|
</div>
|
|
</div>
|
|
|
|
<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>size</span>
|
|
<span data-uix-chips role="radiogroup">
|
|
{#each ['xs', 'sm', 'md', 'lg', 'xl'] as item}
|
|
<button
|
|
data-uix-chip
|
|
data-active={size === item}
|
|
onclick={() => (size = item as FormSize)}
|
|
>
|
|
{item}
|
|
</button>
|
|
{/each}
|
|
</span>
|
|
</label>
|
|
<label data-uix-control>
|
|
<span data-uix-control-label>layout</span>
|
|
<span data-uix-chips role="radiogroup">
|
|
{#each ['stack', 'grid'] as item}
|
|
<button
|
|
data-uix-chip
|
|
data-active={layout === item}
|
|
onclick={() => (layout = item as FormLayout)}
|
|
>
|
|
{item}
|
|
</button>
|
|
{/each}
|
|
</span>
|
|
</label>
|
|
<label data-uix-control>
|
|
<span data-uix-control-label>variant</span>
|
|
<span data-uix-chips role="radiogroup">
|
|
{#each ['plain', 'panel'] as item}
|
|
<button
|
|
data-uix-chip
|
|
data-active={variant === item}
|
|
onclick={() => (variant = item as FormVariant)}
|
|
>
|
|
{item}
|
|
</button>
|
|
{/each}
|
|
</span>
|
|
</label>
|
|
</div>
|
|
|
|
<div class="form-demo-result-grid">
|
|
<div data-uix-code>
|
|
<div data-uix-code-head>
|
|
<span data-uix-layer-badge="soma">soma</span>
|
|
<span>latest invalid submit</span>
|
|
<span data-uix-code-lang>text</span>
|
|
</div>
|
|
<pre><code>{activeInvalid}</code></pre>
|
|
</div>
|
|
<div data-uix-code>
|
|
<div data-uix-code-head>
|
|
<span data-uix-layer-badge="soma">soma</span>
|
|
<span>latest valid values</span>
|
|
<span data-uix-code-lang>json</span>
|
|
</div>
|
|
<pre><code>{activeResult}</code></pre>
|
|
</div>
|
|
</div>
|
|
|
|
<div data-uix-code>
|
|
<div data-uix-code-head>
|
|
<span data-uix-layer-badge="soma">soma</span>
|
|
<span>headless · SIUM validation + Field registration</span>
|
|
<span data-uix-code-lang>svelte</span>
|
|
</div>
|
|
<pre><code>{somaSnippet}</code></pre>
|
|
</div>
|
|
<div data-uix-code>
|
|
<div data-uix-code-head>
|
|
<span data-uix-layer-badge="eidos">eidos</span>
|
|
<span>visual · form layout + Field recipe</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 comparison</h2>
|
|
<p data-uix-section-desc>
|
|
UIX Form is closer to Radix/Ark field primitives plus a schema-aware form runtime.
|
|
SIUM gives the form both validation and enough introspection for AutoFields.
|
|
</p>
|
|
<div data-uix-table-wrap>
|
|
<table data-uix-table>
|
|
<thead>
|
|
<tr><th>Feature</th><th>Radix Form</th><th>Ark Field</th><th>React Aria</th><th>UIX</th><th>Decision</th></tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr><td class="name">Field registration</td><td>✅</td><td>✅</td><td>✅</td><td>✅</td><td>Field name registers with Form.Provider.</td></tr>
|
|
<tr><td class="name">Schema validation</td><td>⚠️ native validity</td><td>⚠️ external</td><td>⚠️ external</td><td>✅</td><td>Any Standard Schema, SIUM shown here.</td></tr>
|
|
<tr><td class="name">Dirty/touched state</td><td>⚠️</td><td>✅</td><td>✅</td><td>✅</td><td>Tracked by createForm and exposed to snippets.</td></tr>
|
|
<tr><td class="name">Error summary</td><td>✅</td><td>⚠️</td><td>⚠️</td><td>✅</td><td>Live region with field-level aggregation.</td></tr>
|
|
<tr><td class="name">First error focus</td><td>⚠️</td><td>⚠️</td><td>✅</td><td>✅</td><td>Soma focuses the first invalid registered field.</td></tr>
|
|
<tr><td class="name">Schema-driven fields</td><td>❌</td><td>❌</td><td>❌</td><td>✅</td><td>Form.AutoFields walks SIUM introspection.</td></tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div data-uix-table-wrap>
|
|
<table data-uix-table>
|
|
<thead><tr><th>Prop / part</th><th>Owner</th><th>Default</th><th>Notes</th></tr></thead>
|
|
<tbody>
|
|
<tr><td class="name">form</td><td>soma</td><td class="default">created from defaults</td><td>Bindable or injected form handle from createForm.</td></tr>
|
|
<tr><td class="name">schema</td><td>soma</td><td class="default empty">-</td><td>Standard Schema. SIUM additionally exposes introspection to AutoFields.</td></tr>
|
|
<tr><td class="name">defaults</td><td>soma</td><td class="default empty">required when no form</td><td>Initial values and reset target.</td></tr>
|
|
<tr><td class="name">validationBehaviour</td><td>soma</td><td class="default">progressive</td><td>progressive | onSubmit | onBlur | onChange. The demo starts on onChange to show real-time SIUM validation.</td></tr>
|
|
<tr><td class="name">focusFirstError</td><td>soma</td><td class="default">true</td><td>Focuses first invalid registered field after invalid submit.</td></tr>
|
|
<tr><td class="name">Submit / Reset</td><td>soma + eidos</td><td class="default">button</td><td>Soma owns type/disabled/pending, Eidos owns size/variant/color.</td></tr>
|
|
<tr><td class="name">ErrorSummary</td><td>soma + eidos</td><td class="default">hidden until submitted</td><td>Aggregates form and field errors.</td></tr>
|
|
<tr><td class="name">AutoFields</td><td>soma renderer</td><td class="default empty">-</td><td>Reflective SIUM renderer, intentionally not a stateful provider.</td></tr>
|
|
<tr><td class="name">size</td><td>eidos</td><td class="default">md</td><td>sm | md | lg.</td></tr>
|
|
<tr><td class="name">layout</td><td>eidos</td><td class="default">stack</td><td>stack | grid.</td></tr>
|
|
<tr><td class="name">variant</td><td>eidos</td><td class="default">plain</td><td>plain | panel.</td></tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</section>
|
|
{/if}
|
|
|
|
{#if tab === 'morfo'}
|
|
<section data-uix-section>
|
|
<h2 data-uix-section-title><span data-uix-layer-badge="morfo">morfo</span> · contract</h2>
|
|
<p data-uix-section-desc>
|
|
Source: <code>src/uix/morfo/components/form.ts</code>. Form declares the
|
|
root, action parts, error summary, AutoFields structural parts and three semantic events.
|
|
</p>
|
|
<div data-uix-table-wrap>
|
|
<table data-uix-table>
|
|
<thead><tr><th>Part</th><th>Marker</th><th>Element</th><th>Role</th><th>States</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.role ?? '-'}</td>
|
|
<td class="default">{part.states.length ? part.states.join(' | ') : '-'}</td>
|
|
<td class="default">{part.optional ? 'yes' : 'no'}</td>
|
|
</tr>
|
|
{/each}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div data-uix-subsection-head>Events declaration</div>
|
|
<div data-uix-table-wrap>
|
|
<table data-uix-table>
|
|
<thead><tr><th>name</th><th>family</th><th>verb</th><th>sequence</th><th>intent</th><th>target</th></tr></thead>
|
|
<tbody>
|
|
{#each events as action}
|
|
<tr>
|
|
<td class="name">{action.name}</td>
|
|
<td class="type">{action.semantic.family}</td>
|
|
<td>{action.semantic.verb ?? '-'}</td>
|
|
<td>{action.semantic.sequence ?? 'pre'}</td>
|
|
<td class="default">{action.semantic.intent ?? '-'}</td>
|
|
<td>{action.target}</td>
|
|
</tr>
|
|
{/each}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</section>
|
|
{/if}
|
|
|
|
{#if tab === 'sema'}
|
|
<section data-uix-section id="sema">
|
|
<h2 data-uix-section-title>
|
|
<span data-uix-layer-badge="sema">sema</span> · events + perceptual signature
|
|
</h2>
|
|
<p data-uix-section-desc>
|
|
Valid submit is a fulfill commit, invalid submit is a risk signal, and reset is neutral.
|
|
Play emits onto the live form root.
|
|
</p>
|
|
<div data-uix-table-wrap>
|
|
<table data-uix-table>
|
|
<thead><tr><th>Name</th><th>Family</th><th>Verb</th><th>Sequence</th><th>Intent</th><th>Play</th></tr></thead>
|
|
<tbody>
|
|
{#each events as action}
|
|
{@const intentDecl = 'intent' in action.semantic ? action.semantic.intent : undefined}
|
|
{@const effectiveIntent = typeof intentDecl === 'string' ? intentDecl : undefined}
|
|
<tr>
|
|
<td class="name">{action.name}</td>
|
|
<td class="type">{action.semantic.family}</td>
|
|
<td>{action.semantic.verb ?? '-'}</td>
|
|
<td>{action.semantic.sequence ?? 'pre'}</td>
|
|
<td>{effectiveIntent ?? '-'}</td>
|
|
<td>
|
|
<button
|
|
data-uix-play
|
|
onclick={() => {
|
|
const target = (stageRef?.querySelector('[data-form]') ?? stageRef) as HTMLElement | null;
|
|
if (!target) return;
|
|
void uix.events?.emit({
|
|
name: action.name,
|
|
family: action.semantic.family,
|
|
target,
|
|
...(effectiveIntent ? { intent: effectiveIntent } : {})
|
|
});
|
|
}}
|
|
>
|
|
Play
|
|
</button>
|
|
</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>
|
|
Selectors live in <code>src/uix/eidos/components/form/form.css</code>.
|
|
Morfo-backed selectors describe form state and actions; Eidos attrs select size,
|
|
layout, variant and action color.
|
|
</p>
|
|
<div data-uix-table-wrap>
|
|
<table data-uix-table>
|
|
<thead><tr><th>Selector</th><th>Source</th><th>Purpose</th></tr></thead>
|
|
<tbody>
|
|
<tr><td class="name"><code>[data-form]</code></td><td><span data-uix-tag data-kind="soma">morfo</span></td><td>Root form and state projection.</td></tr>
|
|
<tr><td class="name"><code>[data-form][data-size][data-layout][data-variant]</code></td><td><span data-uix-tag data-kind="eidos">eidos</span></td><td>Visual scale, grid/stack layout and panel treatment.</td></tr>
|
|
<tr><td class="name"><code>[data-form-submit]</code> / <code>[data-form-reset]</code></td><td><span data-uix-tag data-kind="morfo">morfo</span></td><td>Action buttons and pending/dirty state.</td></tr>
|
|
<tr><td class="name"><code>[data-form-error-summary]</code></td><td><span data-uix-tag data-kind="morfo">morfo</span></td><td>Validation live region.</td></tr>
|
|
<tr><td class="name"><code>[data-form-auto-fields-*]</code></td><td><span data-uix-tag data-kind="morfo">morfo</span></td><td>SIUM reflective field renderer structure.</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">Native form</td><td>Root renders a native <code><form></code> with <code>novalidate</code> by default so Soma validation owns timing.</td></tr>
|
|
<tr><td class="name">Errors</td><td>ErrorSummary is a polite alert region; Field.ErrorText is associated through Field's ARIA contract.</td></tr>
|
|
<tr><td class="name">Focus</td><td>Invalid submit focuses the first registered Field root/control when <code>focusFirstError</code> is true.</td></tr>
|
|
<tr><td class="name">Required</td><td>Field.RequiredIndicator is decorative; controls receive required/aria-required through Soma.</td></tr>
|
|
<tr><td class="name">Reset</td><td>Reset clears values, errors, touched state and submit count in the form runtime.</td></tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</section>
|
|
{/if}
|
|
</div>
|
|
|
|
<style>
|
|
.form-demo-shell {
|
|
inline-size: min(34rem, 100%);
|
|
}
|
|
|
|
.form-demo-actions {
|
|
display: flex;
|
|
justify-content: flex-end;
|
|
gap: var(--uix-space-2);
|
|
grid-column: 1 / -1;
|
|
}
|
|
|
|
.form-demo-native-control {
|
|
inline-size: 100%;
|
|
min-block-size: var(--field-control-height-md, 2.375rem);
|
|
padding-inline: var(--space-3);
|
|
border: 0;
|
|
background: transparent;
|
|
color: inherit;
|
|
font: inherit;
|
|
}
|
|
|
|
.form-demo-native-control:focus {
|
|
outline: none;
|
|
}
|
|
|
|
.form-demo-check {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: var(--uix-space-2);
|
|
color: var(--uix-text-muted);
|
|
font-size: var(--uix-text-sm);
|
|
}
|
|
|
|
.form-demo-result-grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
|
|
gap: var(--uix-space-4);
|
|
margin-block-end: var(--uix-space-5);
|
|
}
|
|
</style>
|