Shared selector capsule + burst-aware toasts (svelte-sonner base) #42

Closed
opened 2026-10-13 18:25:34 +00:00 by kayg · 2 comments
Owner

kayg's brief (2026-10-13): adopt two interactions decoded from MetalForge (https://metalforge.xyz/interactions, segmented + toast) into Calternal's shared UI primitives. These are behavioural observations from live inspection, not copied source (MetalForge's source is Pro-only). Exact spring constants, press scales and blur amounts are unverified, so we tune our own.

1. One selector primitive (shared selection capsule)

Observed: a single persistent capsule behind transparent options. On change, the leading edge stretches toward the new option and the trailing edge catches up (direction-aware). Position and width fit the option, labels stay fixed, and the text never stretches. Selection is tonal (not an accent blob); the selected label goes primary + weight 600, inactive labels secondary (color/weight transition ~0.25 s). Uses tablist/tab with aria-selected and roving tabindex, and the logical state changes immediately.
Build:

  • ONE Svelte selector component, with direction-aware edge lag (two cancellable springs, or x+width).
  • Interruptions retarget from the current visual bounds: no remount, no snap-back, no duplicate capsule. The first render is placed correctly, with no sweep from 0.
  • Inventory every single-choice selector (toolbar pills, Style sheet segments, settings, filters, view switches) and migrate them. Justify exclusions. Multi-select and toggles keep their own semantics. Icon-only groups keep padded, centred capsules, accessible names and tooltips.
  • Calternal tokens and glass rules, focus-visible distinct from selection, touch targets, disabled state.
  • Reduced motion: a short non-spring change.
  • Variable widths, font load, RTL, scrollable groups, resize, rapid reversals.
  • Batched measurement, no per-frame layout reads, no RAF after settle, and observers cleaned up.

2. Toasts: svelte-sonner base + burst-aware custom renderer

Base: svelte-sonner (MIT, 1.2.1, Svelte 5) owns lifecycle, stacking, swipe/dismiss, positioning and timers. Add a shared adapter plus a custom INNER renderer via toast.custom(Component), updated by {id}. No competing queue, timers or outer transforms. Verify the installed version's APIs, including timer pause, instead of assuming React Sonner behaviour.
Observed: a dot seed opens into a rounded message capsule. Repeats roll a count ("Message sent ×12" as one toast, 9→10 width handled). Undo morphs the same toast to "Undone". Per-character spans, but one coherent accessible string in one role=status region.
Behaviour and safety:

  • Stable id per compatible burst, grouped by operation/context identity, never by message text.
    • Different entities, severities, actions or undo contracts stay separate.
    • Grouping window is bounded and cleared on dismiss; a new burst after expiry starts at 1.
    • Lifetime refreshes through Sonner.
  • Honest Undo:
    • group only operations with real undo tokens that can be reversed together, otherwise keep separate toasts or say "Undo last"
    • disable repeat Undo while it's pending
    • morph to "Undone" only after success; failure or partial reversal stays visible with recovery context
  • Loading stays until resolved, then the same toast morphs to success or error. Long errors wrap on mobile.
  • Keyboard, swipe/close, pause, safe areas, bounded announcements, contrast in every theme, reduced motion, and counts 9→10→99→100.
  • Calternal's toast rule still applies (T1): toasts only for something you can act on or an awaited result, never as plain confirmation.

Evidence (both)

Chromium + WebKit, all themes, phone, keyboard and reduced motion. Recordings for:

  • Selector: left/right moves, non-adjacent jumps, rapid alternating clicks, mid-flight reversal, first render.
  • Toast: 12+ events → one exact-count toast; mixed contexts stay separate; expiry reset; events during entrance/exit; pending, failed and partial Undo; promise rejection; long text; resize.

Short motion recordings and perf numbers, not only static screenshots.

Sequencing

Built in the mockup's shared primitives right after round 3 (#13) lands, on top of its tokens, glass and motion helpers. Then promoted into packages/ui for apps/web. No parallel one-off styles.

kayg's brief (2026-10-13): adopt two interactions decoded from MetalForge (https://metalforge.xyz/interactions, segmented + toast) into Calternal's shared UI primitives. These are **behavioural observations** from live inspection, not copied source (MetalForge's source is Pro-only). Exact spring constants, press scales and blur amounts are unverified, so we tune our own. ## 1. One selector primitive (shared selection capsule) **Observed:** a single persistent capsule behind transparent options. On change, the leading edge stretches toward the new option and the trailing edge catches up (direction-aware). Position and width fit the option, labels stay fixed, and the text never stretches. Selection is tonal (not an accent blob); the selected label goes primary + weight 600, inactive labels secondary (color/weight transition ~0.25 s). Uses tablist/tab with aria-selected and roving tabindex, and the logical state changes immediately. **Build:** - ONE Svelte selector component, with direction-aware edge lag (two cancellable springs, or x+width). - Interruptions retarget from the current visual bounds: no remount, no snap-back, no duplicate capsule. The first render is placed correctly, with no sweep from 0. - Inventory every single-choice selector (toolbar pills, Style sheet segments, settings, filters, view switches) and migrate them. Justify exclusions. Multi-select and toggles keep their own semantics. Icon-only groups keep padded, centred capsules, accessible names and tooltips. - Calternal tokens and glass rules, focus-visible distinct from selection, touch targets, disabled state. - Reduced motion: a short non-spring change. - Variable widths, font load, RTL, scrollable groups, resize, rapid reversals. - Batched measurement, no per-frame layout reads, no RAF after settle, and observers cleaned up. ## 2. Toasts: svelte-sonner base + burst-aware custom renderer **Base:** svelte-sonner (MIT, 1.2.1, Svelte 5) owns lifecycle, stacking, swipe/dismiss, positioning and timers. Add a shared adapter plus a custom INNER renderer via toast.custom(Component), updated by {id}. No competing queue, timers or outer transforms. Verify the installed version's APIs, including timer pause, instead of assuming React Sonner behaviour. **Observed:** a dot seed opens into a rounded message capsule. Repeats roll a count ("Message sent ×12" as one toast, 9→10 width handled). Undo morphs the same toast to "Undone". Per-character spans, but one coherent accessible string in one role=status region. **Behaviour and safety:** - Stable id per compatible burst, grouped by operation/context identity, never by message text. - Different entities, severities, actions or undo contracts stay separate. - Grouping window is bounded and cleared on dismiss; a new burst after expiry starts at 1. - Lifetime refreshes through Sonner. - Honest Undo: - group only operations with real undo tokens that can be reversed together, otherwise keep separate toasts or say "Undo last" - disable repeat Undo while it's pending - morph to "Undone" only after success; failure or partial reversal stays visible with recovery context - Loading stays until resolved, then the same toast morphs to success or error. Long errors wrap on mobile. - Keyboard, swipe/close, pause, safe areas, bounded announcements, contrast in every theme, reduced motion, and counts 9→10→99→100. - Calternal's toast rule still applies (T1): toasts only for something you can act on or an awaited result, never as plain confirmation. ## Evidence (both) Chromium + WebKit, all themes, phone, keyboard and reduced motion. Recordings for: - **Selector:** left/right moves, non-adjacent jumps, rapid alternating clicks, mid-flight reversal, first render. - **Toast:** 12+ events → one exact-count toast; mixed contexts stay separate; expiry reset; events during entrance/exit; pending, failed and partial Undo; promise rejection; long text; resize. Short motion recordings and perf numbers, not only static screenshots. ## Sequencing Built in the mockup's shared primitives right after round 3 (#13) lands, on top of its tokens, glass and motion helpers. Then promoted into packages/ui for apps/web. No parallel one-off styles.
Author
Owner

Addition from kayg (2026-10-13): two more shared primitives, same rules as above. These are sveltebits (MIT + Commons Clause), so we reimplement the behaviour and copy no code.

  1. Toggle = squish switch (ref https://sveltebits.xyz/r/squish-switch.json). Every on/off toggle in the app. Behaviour:

    • drag-scrubbable thumb that stretches with its speed
    • flips at the midpoint and squashes against the track end on a flick
    • slight hover grow (~1.035)
    • ~320 ms colour change

    Reference defaults: 76×38 track, stretch 36, speed 50, size adapted to our density. Uses role=switch with aria-checked, keyboard Space/Enter with no motion, and reduced motion = instant.

  2. Checkbox = spring check (ref https://sveltebits.xyz/r/spring-check.json). Every checkbox, including task checkboxes in notes. One spring press:

    • fills the box
    • draws the tick
    • strikes the label with a small lag (~0.12)
    • dims the words (~0.42 opacity)

    Reference values: bounce ~0.2, box ~28 px radius 9, scaled to text size. In the editor the task state still writes [x] to markdown instantly; the motion is presentational only. Uses native checkbox semantics; keyboard works without motion; reduced motion gives a short crossfade.

kayg: "now you start to see what kind of motion I like": springy, physical, playful but precise. This becomes a TASTE.md principle.

**Addition from kayg (2026-10-13): two more shared primitives, same rules as above.** These are sveltebits (MIT + Commons Clause), so we **reimplement the behaviour and copy no code**. 3. **Toggle = squish switch** (ref https://sveltebits.xyz/r/squish-switch.json). Every on/off toggle in the app. Behaviour: - drag-scrubbable thumb that stretches with its speed - flips at the midpoint and squashes against the track end on a flick - slight hover grow (~1.035) - ~320 ms colour change Reference defaults: 76×38 track, stretch 36, speed 50, size adapted to our density. Uses role=switch with aria-checked, keyboard Space/Enter with no motion, and reduced motion = instant. 4. **Checkbox = spring check** (ref https://sveltebits.xyz/r/spring-check.json). Every checkbox, including task checkboxes in notes. One spring press: - fills the box - draws the tick - strikes the label with a small lag (~0.12) - dims the words (~0.42 opacity) Reference values: bounce ~0.2, box ~28 px radius 9, scaled to text size. In the editor the task state still writes `[x]` to markdown instantly; the motion is presentational only. Uses native checkbox semantics; keyboard works without motion; reduced motion gives a short crossfade. kayg: "now you start to see what kind of motion I like": springy, physical, playful but precise. This becomes a TASTE.md principle.
Author
Owner

The four primitives are built: packages/ui/src/primitives/

Each is standalone, with no app state: it takes props and reads Calternal's colour tokens with fallbacks, so apps/web can import it directly as @calternal/ui/primitives/<name>. The mockup now uses all four. Recordings are below; they're Chromium on this Linux host with software rendering, so the frame pacing is the host's, not the motion's.

1. Selector capsule (selector/)

  • One persistent capsule behind plain options.
  • On a change, the leading edge springs fast and the trailing edge catches up. The capsule stretches toward the new option, then gathers.
  • Interruptions retarget from the capsule's current place and speed: no remount, no snap back, one capsule. The first render is already in place.
  • Labels never move: a bold twin reserves the width.
  • Accessibility: tablist and tab with aria-selected. Roving tabindex; arrows (mirrored in right-to-left), Home and End; disabled options skipped.
  • Keyboard moves are instant. Reduced motion gets a 140 ms plain change.
  • Performance: measuring happens only on change, resize or font load, and the frame loop stops once still. Tests check both.

2. Toasts (toast/)

  • svelte-sonner 1.2.1 runs lifetime, stacking, swipe, pause on hover and timers. I checked them in its installed source: an update by id restarts the timer, and expanding or interacting pauses it.
  • Ours is an adapter plus one custom inner renderer, updated in place by id. There's no second queue.
  • The toast opens from a dot into a capsule, with an exact rolling count ("Block deleted ×12"; 9→10 adds a column and the glass springs wider).
  • Bursts group by operation plus what it happened to, plus severity and follow-up. Never by words. The window is bounded, closes on dismiss or Undo, and a new burst starts again at 1.
  • Honest Undo:
    • Tokens run newest first and stop at the first failure.
    • The toast says "Undone" only if every one worked; otherwise "Undid 1 of 4" or "Couldn't undo that", with Try again.
    • A second Undo is disabled while one runs.
  • A wait stays until it settles, then the same toast turns into the result or the error. Long errors wrap on a phone.
  • Screen readers get one sentence in Sonner's polite region, after the toast settles: a burst of 12 is read once.
  • T1 holds: notify wants an Undo, an action, or an awaited result, and warns in development otherwise.

3. Squish switch (switch/)

  • role=switch with aria-checked.
  • Tap: the thumb glides on a spring and squashes against the end of the track as it hits it.
  • Drag: it follows the finger, stretches with speed, and settles on the side it was heading for (midpoint or flick; a pause before release is a placement, not a flick). The colour changes as it crosses the middle (320 ms).
  • Hover grows it 1.035. Space and Enter switch it instantly; reduced motion is instant too.
  • Sizes are 42×25 and 34×20, scaled down from the 76×38 reference.

4. Spring check (check/)

  • A real checkbox.
  • One press: the box squeezes, fills with a bounce of about 0.2, and the tick draws. A beat later (0.12 s) a line sweeps through the words, line by line when they wrap, and the words dim to 0.42.
  • Keyboard: no motion. Reduced motion: a 120 ms crossfade.
  • In notes, the task's [x] is written at once; the motion is presentation only.
  • The words are dimmed through colour, not opacity: an inline element with opacity becomes a layer that WebKit can clip away entirely.

Migrated in the mockup

  • Selector:
    • Style: What to style, Text style, Weight, Block kind (icons, pick again for plain text), Look, Font tiles
    • Settings: Theme, Sidebar
    • The bar's Notes/Settings tabs
  • Switch: Wide page, Photos from Unsplash, Show markdown.
  • Check: every task in notes.
  • Toasts:
    • block delete (bursts per note)
    • tag rename
    • note to Trash
    • the clipboard error
    • Each undo is a precise token: it undoes exactly its own edit, and refuses if something has been edited on top of it.
  • Also: the phone's Places screen now has the Notes/Settings bar (P8).

Exclusions, on purpose

  • Accent colour swatches and backdrop thumbnails: the picture is the choice, and a capsule behind an image doesn't read.
  • Bold/Italic/Strike: multi-select toggles.
  • Focus and Pin: toolbar toggle buttons, not settings.
  • The mockup-only variant switcher.

Tests

  • Unit tests: 23 (springs, edges, switch physics, bursts and undo).
  • Browser tests: 37 per engine in Chromium and WebKit.
    • First render; stretch measured frame by frame in the page; rapid alternation and reversal; keyboard; right-to-left; scrolling group; resize; nothing chosen.
    • Switch: tap, scrub, short drag, keyboard, disabled.
    • Check: lag, wrapped strike, keyboard, reduced motion.
    • Toasts: 12 to one ×12; 9→10 width; separate contexts; window reset; Undo, double Undo, failed and partial Undo; wait; reject and wrap; dark.
  • The mockup gained four #42 checks; its full suite passes in Chromium.

Caveats from this host: WebKit here draws every inline box 0 px tall, so the strike line itself can't be seen in WebKit here. The test checks the style. Timing assertions that need two frames inside 120 ms are Chromium-only.

Timings (Chromium, software rendering):

  • Selector: settles in about 625 ms, worst frame 26 ms.
  • Switch: about 420 ms, worst frame 24 ms.
  • Toast opening: about 717 ms, worst frame 68 ms (Sonner mounting plus the glass blur on software rendering).

Recordings

  • Selector: left and right, non-adjacent jumps, rapid alternating clicks, a reversal mid-flight, variable widths, icons, keyboard (instant): 42-selector.mp4
  • Squish switch: taps, a slow scrub there and back, a flick, keyboard (instant): 42-switch.mp4
  • Spring check: tick, untick, a wrapped task, keyboard (instant): 42-check.mp4
  • Toasts: 12 → one ×12 (9 → 10), Undo → Undone, mixed contexts apart, hover pause, failed Undo, partial Undo (Undid 1 of 4), a wait → saved, a wait → long error: 42-toast.mp4

In the mockup

Style sheet: block and note, all selectors
Settings selectors and switch; tasks and a ×3 toast
Dark: the toast sits over the page, just above the bar

## The four primitives are built: `packages/ui/src/primitives/` Each is standalone, with no app state: it takes props and reads Calternal's colour tokens with fallbacks, so apps/web can import it directly as `@calternal/ui/primitives/<name>`. The mockup now uses all four. Recordings are below; they're Chromium on this Linux host with software rendering, so the frame pacing is the host's, not the motion's. **1. Selector capsule** (`selector/`) - One persistent capsule behind plain options. - On a change, the leading edge springs fast and the trailing edge catches up. The capsule stretches toward the new option, then gathers. - Interruptions retarget from the capsule's current place and speed: no remount, no snap back, one capsule. The first render is already in place. - Labels never move: a bold twin reserves the width. - Accessibility: tablist and tab with `aria-selected`. Roving tabindex; arrows (mirrored in right-to-left), Home and End; disabled options skipped. - Keyboard moves are instant. Reduced motion gets a 140 ms plain change. - Performance: measuring happens only on change, resize or font load, and the frame loop stops once still. Tests check both. **2. Toasts** (`toast/`) - svelte-sonner 1.2.1 runs lifetime, stacking, swipe, pause on hover and timers. I checked them in its installed source: an update by id restarts the timer, and expanding or interacting pauses it. - Ours is an adapter plus one custom inner renderer, updated in place by id. There's no second queue. - The toast opens from a dot into a capsule, with an exact rolling count ("Block deleted ×12"; 9→10 adds a column and the glass springs wider). - Bursts group by operation plus what it happened to, plus severity and follow-up. Never by words. The window is bounded, closes on dismiss or Undo, and a new burst starts again at 1. - Honest Undo: - Tokens run newest first and stop at the first failure. - The toast says "Undone" only if every one worked; otherwise "Undid 1 of 4" or "Couldn't undo that", with Try again. - A second Undo is disabled while one runs. - A wait stays until it settles, then the same toast turns into the result or the error. Long errors wrap on a phone. - Screen readers get one sentence in Sonner's polite region, after the toast settles: a burst of 12 is read once. - T1 holds: `notify` wants an Undo, an action, or an awaited result, and warns in development otherwise. **3. Squish switch** (`switch/`) - `role=switch` with `aria-checked`. - Tap: the thumb glides on a spring and squashes against the end of the track as it hits it. - Drag: it follows the finger, stretches with speed, and settles on the side it was heading for (midpoint or flick; a pause before release is a placement, not a flick). The colour changes as it crosses the middle (320 ms). - Hover grows it 1.035. Space and Enter switch it instantly; reduced motion is instant too. - Sizes are 42×25 and 34×20, scaled down from the 76×38 reference. **4. Spring check** (`check/`) - A real checkbox. - One press: the box squeezes, fills with a bounce of about 0.2, and the tick draws. A beat later (0.12 s) a line sweeps through the words, line by line when they wrap, and the words dim to 0.42. - Keyboard: no motion. Reduced motion: a 120 ms crossfade. - In notes, the task's `[x]` is written at once; the motion is presentation only. - The words are dimmed through colour, not opacity: an inline element with opacity becomes a layer that WebKit can clip away entirely. **Migrated in the mockup** - **Selector:** - Style: What to style, Text style, Weight, Block kind (icons, pick again for plain text), Look, Font tiles - Settings: Theme, Sidebar - The bar's Notes/Settings tabs - **Switch:** Wide page, Photos from Unsplash, Show markdown. - **Check:** every task in notes. - **Toasts:** - block delete (bursts per note) - tag rename - note to Trash - the clipboard error - Each undo is a precise token: it undoes exactly its own edit, and refuses if something has been edited on top of it. - Also: the phone's Places screen now has the Notes/Settings bar (P8). **Exclusions, on purpose** - Accent colour swatches and backdrop thumbnails: the picture is the choice, and a capsule behind an image doesn't read. - Bold/Italic/Strike: multi-select toggles. - Focus and Pin: toolbar toggle buttons, not settings. - The mockup-only variant switcher. **Tests** - Unit tests: 23 (springs, edges, switch physics, bursts and undo). - Browser tests: 37 per engine in Chromium and WebKit. - First render; stretch measured frame by frame in the page; rapid alternation and reversal; keyboard; right-to-left; scrolling group; resize; nothing chosen. - Switch: tap, scrub, short drag, keyboard, disabled. - Check: lag, wrapped strike, keyboard, reduced motion. - Toasts: 12 to one ×12; 9→10 width; separate contexts; window reset; Undo, double Undo, failed and partial Undo; wait; reject and wrap; dark. - The mockup gained four #42 checks; its full suite passes in Chromium. **Caveats from this host:** WebKit here draws every inline box 0 px tall, so the strike line itself can't be seen in WebKit here. The test checks the style. Timing assertions that need two frames inside 120 ms are Chromium-only. **Timings** (Chromium, software rendering): - Selector: settles in about 625 ms, worst frame 26 ms. - Switch: about 420 ms, worst frame 24 ms. - Toast opening: about 717 ms, worst frame 68 ms (Sonner mounting plus the glass blur on software rendering). ### Recordings - **Selector: left and right, non-adjacent jumps, rapid alternating clicks, a reversal mid-flight, variable widths, icons, keyboard (instant)**: [42-selector.mp4](https://git.kayg.org/attachments/7322c60b-cc22-4658-81be-c035c4572da1) - **Squish switch: taps, a slow scrub there and back, a flick, keyboard (instant)**: [42-switch.mp4](https://git.kayg.org/attachments/69666764-1cf6-4097-b271-0a234a855ff2) - **Spring check: tick, untick, a wrapped task, keyboard (instant)**: [42-check.mp4](https://git.kayg.org/attachments/b67d7219-5284-4f56-a227-3523d6852c7d) - **Toasts: 12 → one ×12 (9 → 10), Undo → Undone, mixed contexts apart, hover pause, failed Undo, partial Undo (Undid 1 of 4), a wait → saved, a wait → long error**: [42-toast.mp4](https://git.kayg.org/attachments/17f30c09-2c0d-4efd-be93-38c0014517f3) ### In the mockup ![Style sheet: block and note, all selectors](https://git.kayg.org/attachments/99cbbeb1-1a83-4245-a14a-6660c5d08cac) ![Settings selectors and switch; tasks and a ×3 toast](https://git.kayg.org/attachments/4512fdec-6d70-466c-89c4-b9087f01609a) ![Dark: the toast sits over the page, just above the bar](https://git.kayg.org/attachments/525ca469-f8c9-4376-885c-86fe373b9463)
kayg closed this issue 2026-10-13 19:51:37 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
kayg/calternal#42
No description provided.