Multi-cell OTP / verification code input. Two parts (Provider, Cell) with a snippet-driven cell iteration. Architecture: - A transparent absolutely-positioned <input> captures every keystroke, paste and IME event (soma). - Visible bordered cells follow the hidden input's caret via data-active / data-filled emitted by the morfo. - Single-input approach (shadcn / Bits family) — preserves paste distribution, autocomplete='one-time-code' for SMS autofill on iOS/Android, and IME quality. Eidos surface: - size: 'sm' | 'md' | 'lg' | 'xl' (responsive), cascades cell dimension + glyph size tokens to all cells - Recipe paints square bordered cells with focus ring tracking data-active, subtle bg lift on data-filled, threat-toned border when [data-invalid] cascades from the provider Morfo: - scope: ['soma'] → ['soma', 'sema', 'eidos'] - apg URL added (Textbox pattern — OTP has no formal ARIA pattern) - Passive at the morfo layer (no events array; perceptual feedback via the commit family base when onComplete fires) - README documents the passive classification Comparativa: aligned with shadcn / Bits UI (single hidden input). Ark and Chakra use one input per cell which loses paste / IME quality. Sidebar nav: 'Pin input' added under Forms (next to Tags input). === Sprint Tier 1 — DONE === 1. toggle-groupactive-uix61ffbade2. alert-dialogd5630a523. dropdown-menu4e477e634. context-menu21eb8a625. pin-input (this) Checks: svelte-check 0 errors, component:audit 91/91 PASS. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
parent
21eb8a6264
commit
207774714a
@ -0,0 +1,135 @@
|
|||||||
|
# `<PinInput>` — eidos
|
||||||
|
|
||||||
|
Multi-cell OTP / verification code input. A transparent
|
||||||
|
absolutely-positioned `<input>` captures every keystroke and paste;
|
||||||
|
visible bordered cells follow the hidden input's caret. Field-aware
|
||||||
|
(disabled / readonly / required / invalid OR-merge with the enclosing
|
||||||
|
Field.Provider).
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```svelte
|
||||||
|
<script lang="ts">
|
||||||
|
import { PinInput } from '$uix/eidos/components/pin-input';
|
||||||
|
let code = $state('');
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<PinInput
|
||||||
|
bind:value={code}
|
||||||
|
length={6}
|
||||||
|
type="numeric"
|
||||||
|
size="md"
|
||||||
|
onComplete={(value) => console.log('filled:', value)}
|
||||||
|
>
|
||||||
|
{#snippet children({ cells })}
|
||||||
|
{#each cells as cell, i}
|
||||||
|
<PinInput.Cell {cell} index={i} />
|
||||||
|
{/each}
|
||||||
|
{/snippet}
|
||||||
|
</PinInput>
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parts
|
||||||
|
|
||||||
|
| Part | Notes |
|
||||||
|
|---|---|
|
||||||
|
| `PinInput` (root) | Provider; container + hidden capture input. Exposes `{ cells, isFocused, isHovering, value }` via `children` snippet. |
|
||||||
|
| `Cell` | One visible cell per character position. Receives `cell` (`PinInputCellData`) and `index` from the snippet. |
|
||||||
|
|
||||||
|
## Eidos-layer props
|
||||||
|
|
||||||
|
| Prop | Type | Default | Notes |
|
||||||
|
|---|---|---|---|
|
||||||
|
| `size` | `'sm' \| 'md' \| 'lg' \| 'xl'` (responsive) | `'md'` | Cell dimensions + glyph size. |
|
||||||
|
|
||||||
|
## Headless props (forwarded to soma)
|
||||||
|
|
||||||
|
`value`, `onValueChange`, `onComplete`, `length`, `type`, `pattern`,
|
||||||
|
`pasteTransformer`, `mask`, `placeholder`, `disabled`, `readonly`,
|
||||||
|
`required`, `invalid`, `name`, `autocomplete`, `inputmode`,
|
||||||
|
`aria-label`. See `src/uix/soma/components/pin-input/types.ts`.
|
||||||
|
|
||||||
|
## Cell data-* (emitted by morfo)
|
||||||
|
|
||||||
|
| Attr | When |
|
||||||
|
|---|---|
|
||||||
|
| `data-active` | The cell holds the caret (focused + about to be typed in). |
|
||||||
|
| `data-filled` | The cell has a character. |
|
||||||
|
| `data-disabled` | Cascaded from the provider's disabled state. |
|
||||||
|
|
||||||
|
## Passive justification
|
||||||
|
|
||||||
|
Passive **at the morfo level** — pin-input's morfo declares parts
|
||||||
|
(Provider, Cell, Input) but no `events` array. The user-perceived
|
||||||
|
interactions (typing, paste, completion) are mediated by the hidden
|
||||||
|
`<input>`'s native events; sema-side perceptual feedback piggy-backs
|
||||||
|
on the `commit` family base when the consumer hooks `onComplete`.
|
||||||
|
|
||||||
|
The component IS interactive from the user's perspective. "Passive"
|
||||||
|
here is a contract-layer classification, not a UX one — same logic
|
||||||
|
as `<AlertDialog>` (delegates events to the underlying primitive).
|
||||||
|
|
||||||
|
## Baseline
|
||||||
|
|
||||||
|
WAI-ARIA Textbox pattern:
|
||||||
|
<https://www.w3.org/WAI/ARIA/apg/patterns/textbox/>
|
||||||
|
|
||||||
|
The OTP-input UX has no formal ARIA pattern. Soma follows the
|
||||||
|
de-facto behaviour established by Radix-style implementations and
|
||||||
|
the iOS / Android native code-input controls:
|
||||||
|
|
||||||
|
- Single hidden `<input>` (not one input per cell) so paste, IME and
|
||||||
|
autofill (`one-time-code`) work naturally.
|
||||||
|
- Paste distributes across cells via the morfo's
|
||||||
|
`pasteTransformer` hook.
|
||||||
|
- Backspace clears the previous cell when the current one is empty.
|
||||||
|
- Numeric `type` sets `inputmode='numeric'` + `autocomplete='one-time-code'`
|
||||||
|
so iOS / Android offer the SMS-autofill banner.
|
||||||
|
|
||||||
|
## Comparativa
|
||||||
|
|
||||||
|
| Lib | Single hidden input | Mask | Paste distribute | Type presets | Custom `pattern` | Snippet cells |
|
||||||
|
|---|---|---|---|---|---|---|
|
||||||
|
| **Radix Primitives** | n/a (not provided) | — | — | — | — | — |
|
||||||
|
| **Bits UI** | ✓ | ✓ | ✓ | numeric/alphanumeric/alphabetic | ✓ | ✓ |
|
||||||
|
| **Ark UI** | input per cell | ✓ | ✓ | numeric/alphanumeric | — | — |
|
||||||
|
| **Chakra v3** | input per cell | ✓ | ✓ | numeric/alphanumeric | — | — |
|
||||||
|
| **shadcn/ui (`input-otp`)** | ✓ | ✓ | ✓ | numeric (default) | ✓ | ✓ |
|
||||||
|
| **Eidos (this)** | ✓ | ✓ | ✓ | numeric / alphanumeric / alphabetic / custom | ✓ | ✓ |
|
||||||
|
|
||||||
|
Aligned with the shadcn / Bits family (single hidden input). Ark and
|
||||||
|
Chakra use one input per cell which works but loses paste / IME
|
||||||
|
quality.
|
||||||
|
|
||||||
|
## Decisiones
|
||||||
|
|
||||||
|
- **Snippet-driven Cell rendering.** Forces the consumer to iterate
|
||||||
|
`cells` and render `<PinInput.Cell />` per index. Auto-rendering
|
||||||
|
would hide the per-index `index` arg which downstream consumers
|
||||||
|
use for analytics / focus targeting.
|
||||||
|
- **Cell consumes `data-active` for the focus ring**, not a literal
|
||||||
|
`<input:focus>`. Only the hidden input is focused; the visible
|
||||||
|
cells receive a synthetic focus ring via `data-active` to match
|
||||||
|
the caret position.
|
||||||
|
- **No `variant` knob.** Pin inputs are a singular visual pattern
|
||||||
|
(bordered boxes); variants like outline-only / soft / ghost noise
|
||||||
|
the contract. Consumers can recolor cells via `data-color` if
|
||||||
|
needed.
|
||||||
|
- **Size as t-shirt** (`sm` / `md` / `lg` / `xl`). Matches the rest
|
||||||
|
of UIX's input scale.
|
||||||
|
|
||||||
|
## Gaps
|
||||||
|
|
||||||
|
| Gap | Disposición | Detalle |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| Group separator (e.g. `123-456`) | **diferir** | Soma's `pasteTransformer` strips dashes; rendering a visible separator between groups (Bits' `<PinInput.Group>` part) isn't in the morfo. Add when a real consumer needs it. |
|
||||||
|
| Animated caret transition between cells | **diferir** | Soma emits `data-active` instantly; a transitioned bar could be a nice polish. |
|
||||||
|
| `data-color` cascade | **diferir** | Coloured cells (success on complete, danger on invalid) would propagate from the root's `data-color`. Add when the consumer pattern stabilises. |
|
||||||
|
|
||||||
|
## Reference
|
||||||
|
|
||||||
|
- Bits UI: <https://bits-ui.com/docs/components/pin-input>
|
||||||
|
- Ark UI: <https://ark-ui.com/docs/components/pin-input>
|
||||||
|
- Chakra v3: <https://chakra-ui.com/docs/components/pin-input>
|
||||||
|
- shadcn/ui (`input-otp`):
|
||||||
|
<https://ui.shadcn.com/docs/components/input-otp>
|
||||||
@ -0,0 +1,34 @@
|
|||||||
|
// PinInput — eidos compound API.
|
||||||
|
//
|
||||||
|
// import { PinInput } from '$uix/eidos/components/pin-input';
|
||||||
|
//
|
||||||
|
// <PinInput bind:value length={6} type="numeric" size="md">
|
||||||
|
// {#snippet children({ cells })}
|
||||||
|
// {#each cells as cell, i}
|
||||||
|
// <PinInput.Cell {cell} index={i} />
|
||||||
|
// {/each}
|
||||||
|
// {/snippet}
|
||||||
|
// </PinInput>
|
||||||
|
import PinInputComponent from './pin-input.svelte';
|
||||||
|
import Cell from './pin-input-cell.svelte';
|
||||||
|
|
||||||
|
type PinInputNamespace = typeof PinInputComponent & {
|
||||||
|
Cell: typeof Cell;
|
||||||
|
};
|
||||||
|
|
||||||
|
const PinInput = PinInputComponent as PinInputNamespace;
|
||||||
|
PinInput.Cell = Cell;
|
||||||
|
|
||||||
|
export { PinInput };
|
||||||
|
|
||||||
|
export default PinInput;
|
||||||
|
|
||||||
|
export type {
|
||||||
|
PinInputProps,
|
||||||
|
PinInputCellProps as CellProps,
|
||||||
|
PinInputSize,
|
||||||
|
PinInputCellData,
|
||||||
|
PinInputCellSnippetProps,
|
||||||
|
PinInputProviderSnippetProps,
|
||||||
|
PinInputType
|
||||||
|
} from './types';
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
/**
|
||||||
|
* Eidos `<PinInput.Cell>`. Pass-through over soma's Cell. The morfo
|
||||||
|
* already emits `data-active`, `data-filled`, `data-disabled` etc.
|
||||||
|
* — the recipe targets those for the focus ring + filled-cell
|
||||||
|
* affordance.
|
||||||
|
*/
|
||||||
|
import * as PinInput from '$soma/components/pin-input';
|
||||||
|
import type { PinInputCellProps } from './types';
|
||||||
|
|
||||||
|
let { children: bodyContent, ...rest }: PinInputCellProps = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<PinInput.Cell {...rest}>
|
||||||
|
{#snippet children(snippetProps)}
|
||||||
|
{@render bodyContent?.(snippetProps)}
|
||||||
|
{/snippet}
|
||||||
|
</PinInput.Cell>
|
||||||
@ -0,0 +1,95 @@
|
|||||||
|
/*
|
||||||
|
* PinInput recipe.
|
||||||
|
*
|
||||||
|
* [data-pin-input] → flex row container (also hosts the
|
||||||
|
* hidden capture input as a sibling)
|
||||||
|
* [data-pin-input-cell] → visible character cell
|
||||||
|
*
|
||||||
|
* Soma owns the hidden input and emits per-cell data:
|
||||||
|
*
|
||||||
|
* [data-pin-input-cell][data-active] → focused cell receiving input
|
||||||
|
* [data-pin-input-cell][data-filled] → cell has a character
|
||||||
|
* [data-pin-input-cell][data-disabled] → cell disabled
|
||||||
|
*
|
||||||
|
* The recipe paints bordered boxes with a focus ring on the active
|
||||||
|
* cell and a subtle bg lift on filled cells. The hidden input keeps
|
||||||
|
* its inline absolute positioning from soma.
|
||||||
|
*/
|
||||||
|
|
||||||
|
[data-pin-input] {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: var(--pin-input-gap, var(--space-2));
|
||||||
|
font-family: var(--style-label-font-family, var(--font-ui));
|
||||||
|
}
|
||||||
|
|
||||||
|
[data-pin-input][data-disabled] {
|
||||||
|
opacity: var(--pin-input-disabled-opacity, 0.55);
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Cell ─────────────────────────────────────────────────────────── */
|
||||||
|
|
||||||
|
[data-pin-input-cell] {
|
||||||
|
--_pin-cell-size: var(--pin-input-cell-size-md, 2.5rem);
|
||||||
|
--_pin-cell-font-size: var(--pin-input-cell-font-size-md, var(--font-size-lg));
|
||||||
|
--_pin-cell-radius: var(--pin-input-cell-radius, var(--radius-md));
|
||||||
|
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
inline-size: var(--_pin-cell-size);
|
||||||
|
block-size: var(--_pin-cell-size);
|
||||||
|
border: var(--pin-input-cell-border-width, 1px) solid
|
||||||
|
var(--pin-input-cell-border-color, var(--color-border-default));
|
||||||
|
border-radius: var(--_pin-cell-radius);
|
||||||
|
background: var(--pin-input-cell-bg, var(--color-surface-default));
|
||||||
|
color: var(--color-content-primary);
|
||||||
|
font-size: var(--_pin-cell-font-size);
|
||||||
|
font-weight: var(--pin-input-cell-font-weight, 500);
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
line-height: 1; /* literal: cells are single-glyph, line-height collapse */
|
||||||
|
user-select: none;
|
||||||
|
transition:
|
||||||
|
border-color var(--duration-fast) var(--ease-default),
|
||||||
|
background var(--duration-fast) var(--ease-default),
|
||||||
|
box-shadow var(--duration-fast) var(--ease-default);
|
||||||
|
}
|
||||||
|
|
||||||
|
[data-pin-input-cell][data-filled] {
|
||||||
|
background: var(--pin-input-cell-filled-bg, var(--color-primary-element));
|
||||||
|
border-color: var(--pin-input-cell-filled-border, var(--color-primary-border));
|
||||||
|
}
|
||||||
|
|
||||||
|
[data-pin-input-cell][data-active] {
|
||||||
|
border-color: var(--pin-input-cell-active-border, var(--color-primary-solid));
|
||||||
|
box-shadow: var(--focus-ring);
|
||||||
|
}
|
||||||
|
|
||||||
|
[data-pin-input-cell][data-disabled] {
|
||||||
|
opacity: var(--pin-input-disabled-opacity, 0.55);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Invalid (Field-aware). Soma OR-merges `invalid` with the enclosing
|
||||||
|
* Field's state; both surface as `data-invalid` on the container which
|
||||||
|
* we cascade to cells. */
|
||||||
|
[data-pin-input][data-invalid] [data-pin-input-cell] {
|
||||||
|
border-color: var(--pin-input-cell-invalid-border, var(--color-threat-solid));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Size cascade ─────────────────────────────────────────────────── */
|
||||||
|
|
||||||
|
[data-pin-input][data-size='sm'] [data-pin-input-cell] {
|
||||||
|
--_pin-cell-size: var(--pin-input-cell-size-sm, 2rem);
|
||||||
|
--_pin-cell-font-size: var(--pin-input-cell-font-size-sm, var(--font-size-md));
|
||||||
|
}
|
||||||
|
|
||||||
|
[data-pin-input][data-size='lg'] [data-pin-input-cell] {
|
||||||
|
--_pin-cell-size: var(--pin-input-cell-size-lg, 3rem);
|
||||||
|
--_pin-cell-font-size: var(--pin-input-cell-font-size-lg, var(--font-size-xl));
|
||||||
|
}
|
||||||
|
|
||||||
|
[data-pin-input][data-size='xl'] [data-pin-input-cell] {
|
||||||
|
--_pin-cell-size: var(--pin-input-cell-size-xl, 3.5rem);
|
||||||
|
--_pin-cell-font-size: var(--pin-input-cell-font-size-xl, var(--font-size-xxl));
|
||||||
|
}
|
||||||
@ -0,0 +1,27 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
/**
|
||||||
|
* Eidos `<PinInput>` — root. Passes `data-size` to the container so
|
||||||
|
* the cell recipe picks up the right token slice. Snippet args
|
||||||
|
* (`cells`, `isFocused`, `isHovering`, `value`) are forwarded
|
||||||
|
* unchanged from soma.
|
||||||
|
*/
|
||||||
|
import { ActiveEidos } from '$uix/eidos';
|
||||||
|
import * as PinInput from '$soma/components/pin-input';
|
||||||
|
import type { PinInputProps } from './types';
|
||||||
|
|
||||||
|
let {
|
||||||
|
size = 'md',
|
||||||
|
value = $bindable(''),
|
||||||
|
children: bodyContent,
|
||||||
|
...rest
|
||||||
|
}: PinInputProps = $props();
|
||||||
|
|
||||||
|
const eidos = ActiveEidos.require();
|
||||||
|
const resolvedSize = $derived(eidos.resolve(size, 'md'));
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<PinInput.Provider {...rest} bind:value data-size={resolvedSize}>
|
||||||
|
{#snippet children(snippetProps)}
|
||||||
|
{@render bodyContent?.(snippetProps)}
|
||||||
|
{/snippet}
|
||||||
|
</PinInput.Provider>
|
||||||
@ -0,0 +1,44 @@
|
|||||||
|
import type {
|
||||||
|
ProviderProps,
|
||||||
|
CellProps,
|
||||||
|
PinInputCellData,
|
||||||
|
PinInputCellSnippetProps,
|
||||||
|
PinInputProviderSnippetProps,
|
||||||
|
PinInputType
|
||||||
|
} from '$soma/components/pin-input';
|
||||||
|
import type { ResponsiveProp, Size } from '$uix/eidos/lib/types';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Eidos `<PinInput>` — visual wrapper over the multi-cell OTP / code
|
||||||
|
* input headless primitive. Two parts:
|
||||||
|
*
|
||||||
|
* <PinInput bind:value length={6} type="numeric">
|
||||||
|
* {#snippet children({ cells })}
|
||||||
|
* {#each cells as cell, i}
|
||||||
|
* <PinInput.Cell {cell} index={i} />
|
||||||
|
* {/each}
|
||||||
|
* {/snippet}
|
||||||
|
* </PinInput>
|
||||||
|
*
|
||||||
|
* Soma renders a transparent absolutely-positioned `<input>` that
|
||||||
|
* captures every keystroke + paste; consumers iterate the `cells`
|
||||||
|
* snippet arg and render the visible boxes. Eidos paints the cell
|
||||||
|
* chrome (border, focus ring, filled bg, fake caret).
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** Visual sizing — t-shirt scale narrowed to the steps the recipe maps. */
|
||||||
|
export type PinInputSize = Extract<Size, 'sm' | 'md' | 'lg' | 'xl'>;
|
||||||
|
|
||||||
|
export type PinInputProps = ProviderProps & {
|
||||||
|
/** Cell dimensions. @default 'md' */
|
||||||
|
size?: ResponsiveProp<PinInputSize>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type PinInputCellProps = CellProps;
|
||||||
|
|
||||||
|
export type {
|
||||||
|
PinInputCellData,
|
||||||
|
PinInputCellSnippetProps,
|
||||||
|
PinInputProviderSnippetProps,
|
||||||
|
PinInputType
|
||||||
|
};
|
||||||
@ -0,0 +1,427 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { PinInput, type PinInputSize, type PinInputType } from '$uix/eidos/components/pin-input';
|
||||||
|
import { compileMorfo } from '$uix/morfo';
|
||||||
|
import { pinInputMorfo } from '@/uix/morfo/components/pin-input';
|
||||||
|
|
||||||
|
type Tab = 'live' | 'api' | 'morfo' | 'sema' | 'recipe' | 'a11y';
|
||||||
|
let tab = $state<Tab>('live');
|
||||||
|
|
||||||
|
const sizes: PinInputSize[] = ['sm', 'md', 'lg', 'xl'];
|
||||||
|
const types: PinInputType[] = ['numeric', 'alphanumeric', 'alphabetic', 'custom'];
|
||||||
|
|
||||||
|
let value = $state('');
|
||||||
|
let length = $state(6);
|
||||||
|
let type = $state<PinInputType>('numeric');
|
||||||
|
let size = $state<PinInputSize>('md');
|
||||||
|
let mask = $state(false);
|
||||||
|
let disabled = $state(false);
|
||||||
|
let invalid = $state(false);
|
||||||
|
let placeholder = $state('•');
|
||||||
|
let lastComplete = $state<string | null>(null);
|
||||||
|
|
||||||
|
function handleComplete(v: string) {
|
||||||
|
lastComplete = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
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(pinInputMorfo);
|
||||||
|
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 PinInput from '$soma/components/pin-input';",
|
||||||
|
' let value = $state(\'\');',
|
||||||
|
'</' + 'script>',
|
||||||
|
'',
|
||||||
|
'<PinInput.Provider',
|
||||||
|
' bind:value',
|
||||||
|
length !== 6 && ` length={${length}}`,
|
||||||
|
type !== 'numeric' && ` type="${type}"`,
|
||||||
|
mask && ' mask',
|
||||||
|
disabled && ' disabled',
|
||||||
|
invalid && ' invalid',
|
||||||
|
'>',
|
||||||
|
' {#snippet children({ cells })}',
|
||||||
|
' {#each cells as cell, i}',
|
||||||
|
' <PinInput.Cell {cell} index={i} />',
|
||||||
|
' {/each}',
|
||||||
|
' {/snippet}',
|
||||||
|
'</PinInput.Provider>'
|
||||||
|
]
|
||||||
|
.filter(Boolean)
|
||||||
|
.join('\n')
|
||||||
|
);
|
||||||
|
|
||||||
|
const eidosSnippet = $derived(
|
||||||
|
[
|
||||||
|
"<script lang='ts'>",
|
||||||
|
" import { PinInput } from '$uix/eidos/components/pin-input';",
|
||||||
|
' let value = $state(\'\');',
|
||||||
|
'</' + 'script>',
|
||||||
|
'',
|
||||||
|
'<PinInput',
|
||||||
|
' bind:value',
|
||||||
|
length !== 6 && ` length={${length}}`,
|
||||||
|
type !== 'numeric' && ` type="${type}"`,
|
||||||
|
size !== 'md' && ` size="${size}"`,
|
||||||
|
mask && ' mask',
|
||||||
|
disabled && ' disabled',
|
||||||
|
invalid && ' invalid',
|
||||||
|
' onComplete={(v) => console.log(v)}',
|
||||||
|
'>',
|
||||||
|
' {#snippet children({ cells })}',
|
||||||
|
' {#each cells as cell, i}',
|
||||||
|
' <PinInput.Cell {cell} index={i} />',
|
||||||
|
' {/each}',
|
||||||
|
' {/snippet}',
|
||||||
|
'</PinInput>'
|
||||||
|
]
|
||||||
|
.filter(Boolean)
|
||||||
|
.join('\n')
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div data-uix-canvas-inner>
|
||||||
|
<header>
|
||||||
|
<div data-uix-eyebrow>Form · PinInput</div>
|
||||||
|
<h1 data-uix-page-title>PinInput</h1>
|
||||||
|
<p data-uix-page-lede>
|
||||||
|
Multi-cell OTP / verification code input. Single hidden
|
||||||
|
<code><input></code> captures every keystroke + paste so
|
||||||
|
autofill (<code>autocomplete="one-time-code"</code>), IME and
|
||||||
|
distribute-on-paste all work naturally.
|
||||||
|
<span data-uix-layer-badge="soma">soma</span> owns the capture
|
||||||
|
pipeline; eidos paints the bordered cells with the focus ring
|
||||||
|
tracking the caret via <code>data-active</code>.
|
||||||
|
</p>
|
||||||
|
<div data-uix-page-meta>
|
||||||
|
<span data-uix-meta-pill>
|
||||||
|
<span data-uix-meta-key>length</span>{length}
|
||||||
|
</span>
|
||||||
|
<span data-uix-meta-pill>
|
||||||
|
<span data-uix-meta-key>type</span>{type}
|
||||||
|
</span>
|
||||||
|
<span data-uix-meta-pill>
|
||||||
|
<span data-uix-meta-key>value</span>{value || '—'}
|
||||||
|
</span>
|
||||||
|
{#if lastComplete}
|
||||||
|
<span data-uix-meta-pill>
|
||||||
|
<span data-uix-meta-key>completed</span>{lastComplete}
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div data-uix-stage>
|
||||||
|
<div data-uix-stage-area bind:this={stageRef}>
|
||||||
|
<PinInput
|
||||||
|
bind:value
|
||||||
|
{length}
|
||||||
|
{type}
|
||||||
|
{size}
|
||||||
|
{mask}
|
||||||
|
{disabled}
|
||||||
|
{invalid}
|
||||||
|
{placeholder}
|
||||||
|
onComplete={handleComplete}
|
||||||
|
>
|
||||||
|
{#snippet children({ cells })}
|
||||||
|
{#each cells as cell, i (i)}
|
||||||
|
<PinInput.Cell {cell} index={i} />
|
||||||
|
{/each}
|
||||||
|
{/snippet}
|
||||||
|
</PinInput>
|
||||||
|
</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>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 · {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 · shape + alphabet
|
||||||
|
</div>
|
||||||
|
<div data-uix-controls>
|
||||||
|
<label data-uix-control>
|
||||||
|
<span data-uix-control-label>length</span>
|
||||||
|
<input type="range" min="3" max="10" step="1" bind:value={length} />
|
||||||
|
<span data-uix-control-value>{length}</span>
|
||||||
|
</label>
|
||||||
|
<label data-uix-control>
|
||||||
|
<span data-uix-control-label>type</span>
|
||||||
|
<span data-uix-chips role="radiogroup">
|
||||||
|
{#each types as opt}
|
||||||
|
<button data-uix-chip data-active={type === opt} onclick={() => (type = opt)}>{opt}</button>
|
||||||
|
{/each}
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
<label data-uix-control>
|
||||||
|
<span data-uix-control-label>placeholder</span>
|
||||||
|
<input type="text" bind:value={placeholder} maxlength="1" style="inline-size: 4rem;" />
|
||||||
|
</label>
|
||||||
|
<label data-uix-control data-control-kind="switch">
|
||||||
|
<input type="checkbox" bind:checked={mask} /> mask (•)
|
||||||
|
</label>
|
||||||
|
<label data-uix-control data-control-kind="switch">
|
||||||
|
<input type="checkbox" bind:checked={disabled} /> disabled
|
||||||
|
</label>
|
||||||
|
<label data-uix-control data-control-kind="switch">
|
||||||
|
<input type="checkbox" bind:checked={invalid} /> invalid
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div data-uix-subsection-head>
|
||||||
|
<span data-uix-layer-badge="eidos">eidos</span> props · cell shape
|
||||||
|
</div>
|
||||||
|
<div data-uix-controls>
|
||||||
|
<label data-uix-control>
|
||||||
|
<span data-uix-control-label>size</span>
|
||||||
|
<span data-uix-chips role="radiogroup">
|
||||||
|
{#each sizes as opt}
|
||||||
|
<button data-uix-chip data-active={size === opt} onclick={() => (size = opt)}>{opt}</button>
|
||||||
|
{/each}
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div data-uix-code>
|
||||||
|
<div data-uix-code-head>
|
||||||
|
<span data-uix-layer-badge="soma">soma</span>
|
||||||
|
<span>headless · hidden capture input</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 · sized bordered cells</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>
|
||||||
|
<div data-uix-table-wrap>
|
||||||
|
<table data-uix-table>
|
||||||
|
<thead><tr><th>Name</th><th>Type</th><th>Default</th><th>Notes</th></tr></thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td class="name">value <span data-uix-tag data-kind="soma">soma</span></td>
|
||||||
|
<td class="type">string</td>
|
||||||
|
<td class="default">''</td>
|
||||||
|
<td>Bindable code value.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="name">length <span data-uix-tag data-kind="soma">soma</span></td>
|
||||||
|
<td class="type">number</td>
|
||||||
|
<td class="default">6</td>
|
||||||
|
<td>Number of cells.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="name">type <span data-uix-tag data-kind="soma">soma</span></td>
|
||||||
|
<td class="type">'numeric' | 'alphanumeric' | 'alphabetic' | 'custom'</td>
|
||||||
|
<td class="default">'numeric'</td>
|
||||||
|
<td>Alphabet preset → drives pattern + inputmode + autocomplete defaults.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="name">pattern <span data-uix-tag data-kind="soma">soma</span></td>
|
||||||
|
<td class="type">string | RegExp</td>
|
||||||
|
<td class="default empty">—</td>
|
||||||
|
<td>Custom accept regex (overrides <code>type</code>).</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="name">mask <span data-uix-tag data-kind="soma">soma</span></td>
|
||||||
|
<td class="type">boolean</td>
|
||||||
|
<td class="default">false</td>
|
||||||
|
<td>Show <code>•</code> instead of the real char.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="name">placeholder <span data-uix-tag data-kind="soma">soma</span></td>
|
||||||
|
<td class="type">string</td>
|
||||||
|
<td class="default">''</td>
|
||||||
|
<td>Glyph shown in empty cells.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="name">onComplete <span data-uix-tag data-kind="soma">soma</span></td>
|
||||||
|
<td class="type">(value: string) => void</td>
|
||||||
|
<td class="default empty">—</td>
|
||||||
|
<td>Fired once when <code>value.length === length</code>.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="name">size <span data-uix-tag data-kind="eidos">eidos</span></td>
|
||||||
|
<td class="type">'sm' | 'md' | 'lg' | 'xl'</td>
|
||||||
|
<td class="default">'md'</td>
|
||||||
|
<td>Cell dimensions + glyph size.</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></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>
|
||||||
|
</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>
|
||||||
|
<p data-uix-section-desc>
|
||||||
|
PinInput emits {events.length} events. <code>onComplete</code>
|
||||||
|
fires when the value reaches the target length.
|
||||||
|
</p>
|
||||||
|
<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>pin-input.css</code> styles the bordered cell. The
|
||||||
|
focus ring follows the caret via <code>data-active</code> on
|
||||||
|
the cell — the only actually-focused element is the hidden
|
||||||
|
input, but the visible cell receives the synthetic ring.
|
||||||
|
</p>
|
||||||
|
<div data-uix-table-wrap>
|
||||||
|
<table data-uix-table>
|
||||||
|
<thead><tr><th>Selector</th><th>Purpose</th></tr></thead>
|
||||||
|
<tbody>
|
||||||
|
<tr><td class="name"><code>[data-pin-input]</code></td><td>Inline flex row.</td></tr>
|
||||||
|
<tr><td class="name"><code>[data-pin-input-cell]</code></td><td>Square bordered cell.</td></tr>
|
||||||
|
<tr><td class="name"><code>[data-pin-input-cell][data-active]</code></td><td>Focus ring + primary border.</td></tr>
|
||||||
|
<tr><td class="name"><code>[data-pin-input-cell][data-filled]</code></td><td>Subtle bg lift on filled cells.</td></tr>
|
||||||
|
<tr><td class="name"><code>[data-pin-input][data-invalid] [data-pin-input-cell]</code></td><td>Threat-toned border.</td></tr>
|
||||||
|
<tr><td class="name"><code>[data-pin-input][data-size='lg']</code></td><td>Cell + glyph scale token swap.</td></tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if tab === 'a11y'}
|
||||||
|
<section data-uix-section>
|
||||||
|
<h2 data-uix-section-title>A11y</h2>
|
||||||
|
<p data-uix-section-desc>
|
||||||
|
No formal ARIA pattern for OTP inputs. PinInput follows the
|
||||||
|
de-facto convention: a single hidden
|
||||||
|
<code><input></code> with
|
||||||
|
<code>autocomplete="one-time-code"</code> (when
|
||||||
|
<code>type="numeric"</code>) so iOS / Android surface the
|
||||||
|
SMS-autofill banner.
|
||||||
|
</p>
|
||||||
|
<div data-uix-table-wrap>
|
||||||
|
<table data-uix-table>
|
||||||
|
<thead><tr><th>Key</th><th>Effect</th></tr></thead>
|
||||||
|
<tbody>
|
||||||
|
<tr><td>Any character</td><td>Insert at caret; advance to next cell.</td></tr>
|
||||||
|
<tr><td><kbd>Backspace</kbd></td><td>Clear current cell; if empty, clear + focus previous.</td></tr>
|
||||||
|
<tr><td><kbd>Delete</kbd></td><td>Clear current cell; stay.</td></tr>
|
||||||
|
<tr><td><kbd>ArrowLeft</kbd> / <kbd>ArrowRight</kbd></td><td>Move caret one cell.</td></tr>
|
||||||
|
<tr><td><kbd>Home</kbd> / <kbd>End</kbd></td><td>Caret to first / last cell.</td></tr>
|
||||||
|
<tr><td>Paste</td><td>Distribute across cells (via <code>pasteTransformer</code> if set).</td></tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
Loading…
Reference in new issue