@zonsh/ui 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/CHANGELOG.md +37 -3
  2. package/README.md +1 -2
  3. package/dist/components/bottom-nav.js +10 -293
  4. package/dist/components/button.d.ts +2 -1
  5. package/dist/components/button.js +2 -0
  6. package/dist/components/radio-group.d.ts +23 -2
  7. package/dist/components/radio-group.js +62 -4
  8. package/dist/index.d.ts +2 -2
  9. package/dist/index.js +2 -2
  10. package/dist/lib/liquid-mark.d.ts +29 -0
  11. package/dist/lib/liquid-mark.js +327 -0
  12. package/dist/skills/zon-ui/SKILL.md +4 -4
  13. package/dist/skills/zon-ui/references/components/button.md +20 -1
  14. package/dist/skills/zon-ui/references/components/radio-group.md +73 -2
  15. package/dist/skills/zon-ui/references/components/theme.md +2 -2
  16. package/dist/sources/audio-player.css +3 -0
  17. package/dist/sources/bottom-nav.css +1 -0
  18. package/dist/sources/button.css +3 -0
  19. package/dist/sources/carousel.css +3 -0
  20. package/dist/sources/code-block.css +3 -0
  21. package/dist/sources/conversation.css +3 -0
  22. package/dist/sources/copy-button.css +3 -0
  23. package/dist/sources/data-table.css +2 -0
  24. package/dist/sources/file-drop.css +3 -0
  25. package/dist/sources/filter-bar.css +2 -0
  26. package/dist/sources/lightbox.css +2 -0
  27. package/dist/sources/markdown-editor.css +2 -0
  28. package/dist/sources/message.css +3 -0
  29. package/dist/sources/pagination.css +3 -0
  30. package/dist/sources/pdf-viewer.css +2 -0
  31. package/dist/sources/radio-group.css +5 -0
  32. package/dist/sources/response.css +2 -0
  33. package/dist/sources/scheduler.css +3 -0
  34. package/dist/sources/sidebar.css +2 -0
  35. package/dist/sources/site-header.css +3 -0
  36. package/dist/sources/sortable.css +3 -0
  37. package/dist/sources/suggestions.css +3 -0
  38. package/dist/sources/theme.css +3 -0
  39. package/dist/sources/tool-call.css +3 -0
  40. package/dist/sources/tour.css +2 -0
  41. package/dist/sources/video-player.css +2 -0
  42. package/dist/styles/core.css +16 -13
  43. package/dist/styles/parts/controls.css +88 -0
  44. package/dist/vite.d.ts +41 -11
  45. package/dist/vite.js +78 -23
  46. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,17 +1,46 @@
1
1
  # @zonsh/ui
2
2
 
3
+ ## 0.8.0
4
+
5
+ Released 20 November 2026.
6
+
7
+ ### Minor Changes
8
+
9
+ - 887096b: `RadioGroup variant="capsule"`: the options side by side in a capsule, with the chosen one on a raised pill that glides. Pressed, the pill swells; dragged, it follows the finger and chooses the option it is let go over, as a capsule `BottomNav` does. It stays a radio group, with one Tab stop, arrow keys, a form value and `required`, and nothing is chosen until someone picks. `size` sets its height to 30, 38 or 46px. Each `Radio` holds an icon, a word or both; an icon alone needs an `aria-label`. Use it for a few short options chosen often, such as the answer to a check, a view or a period, in place of a `BottomNav` bent into the page.
10
+
11
+ ### Patch Changes
12
+
13
+ - 055c818: Fix `BottomNav` choosing an item nobody tapped. A press let go off the bar (slid away before it became a drag) is now over: the document's pointerup or pointercancel ends it. A mouse or pen moving with no button down no longer counts as a drag. Before, a later move or a scroll under a resting mouse could start a drag that captured the pointer, and the next click anywhere on the page chose the item under the pill.
14
+ - 055c818: Export `usePressFeedback`, so a screen without the phone parts presses its buttons at touch-down too. Call it once while the screen is mounted, and mark what should answer with `data-press`.
15
+ - 21a95e2: Leave the page's own scrollbar to the browser. The thin zon scrollbar now styles scrollers inside the page (tables, overflow panels) and no longer the root's or the body's. Styled, Chrome and Edge on Windows 11 swapped their thin overlay bar for a classic one with a gutter, which showed the page ground as a white strip beside dark full-bleed sections. Firefox likewise keeps its own bar on the page.
16
+ - 225fe36: Fix the flash of a fallback font on first load in Vite apps since 0.6. In a build, `zonThemeScript()` from `@zonsh/ui/vite` now preloads Licht Light, Licht Sans Regular and Medium, and Licht Mono Regular by their built, hashed names, right after the theme script. The browser then fetches them with the page instead of after it has laid out the text. `preloadFonts` names other cuts (`["LichtSans-SemiBold"]`), or `false` turns it off. The dev server adds no preloads.
17
+
18
+ ## 0.7.1
19
+
20
+ Released 19 November 2026.
21
+
22
+ ### Patch Changes
23
+
24
+ - cabdd9e: Docs: the README and the skill no longer mention `zonFonts()` or the `/licht/fonts` rewrite. Both went in 0.6.0, and the fonts come with the stylesheet from `licht`.
25
+
3
26
  ## 0.7.0
4
27
 
28
+ Released 18 November 2026.
29
+
5
30
  ### Minor Changes
6
31
 
7
32
  - a74f94f: Toast: a status toast (`success`, `warning`, `info`, `error`) now carries its colour as light — a 1px edge tinted toward it and a soft glow that fills the start side, top to bottom, and fades out before the text. Every toast now sits on its own ground, a step above the page (near black in dark), with the menu's drop shadow and no inset highlight, in place of `material-menu`. Default and loading toasts get the same light in the foreground ink, at half the strength. New token `--status-glow` sets the glow's strength (11% light, 18% dark).
8
33
 
9
34
  ## 0.6.1
10
35
 
11
- No changes in this release.
36
+ Released 18 November 2026.
37
+
38
+ Nothing in `@zonsh/ui` changed. This version came out with `create-zon` 0.6.1, which shares its version number: the theme script it writes into a new app is regenerated from `@zonsh/ui`'s current source.
12
39
 
13
40
  ## 0.6.0
14
41
 
42
+ Released 18 November 2026.
43
+
15
44
  ### Minor Changes
16
45
 
17
46
  - 856349e: `AudioPlayer` splits its surface from its arrangement: `variant` is the surface, `card`, `region` (new, square) or `plain`, and the new `layout` is the arrangement, `default`, `row` or `note`. A row and a note have no surface unless you give one. The root also writes `data-layout`.
@@ -71,7 +100,7 @@ No changes in this release.
71
100
 
72
101
  The marketing guide (`marketing.md`, in the skill, at `/ui/marketing.md` and in llms.txt) is rewritten for landing pages, marketing sites, waitlists, shops and product pages: compose for the product rather than copy zon.sh's outline; five hero variants (split with a figure, product first, centred statement, editorial, with the form) and where the page's one primary goes; a library of section patterns chosen by content, trust without social proof, alternatives to the FAQ accordion and call-to-action bands; and four footer patterns — night CTA, link columns, compact and big wordmark — with code. In the night footer the legal row now sits under the horizon, at the very bottom of the page, instead of above its rim. The skill's index sends agents building those pages to the guide first, and the `Section` docs say the "01 / …" numbering is optional.
73
102
 
74
- - 46f4ba5: Fonts ship with the CSS via `@zonsh/fonts`; `zonFonts()` is gone. `@zonsh/ui` now depends on `@zonsh/fonts` (`^0.1.1`), and `@import "@zonsh/ui/styles.css"` (or `styles/core.css`) brings the Licht, Licht Sans and Licht Mono `@font-face` rules with it: the app's bundler (Vite, or Next.js with Turbopack or webpack) copies the WOFF2 files into the build and serves them from the app's own origin. No plugin, proxy or rewrite, and the faces are pinned by the lockfile instead of following zon.sh. The family names are the same, and the size-matched fallbacks stay (Licht Sans's re-measured against its new cuts).
103
+ - 46f4ba5: Fonts ship with the CSS via `licht`; `zonFonts()` is gone. `@zonsh/ui` now depends on `licht`, and `@import "@zonsh/ui/styles.css"` (or `styles/core.css`) brings the Licht, Licht Sans and Licht Mono `@font-face` rules with it: the app's bundler (Vite, or Next.js with Turbopack or webpack) copies the WOFF2 files into the build and serves them from the app's own origin. No plugin, proxy or rewrite, and the faces are pinned by the lockfile instead of following zon.sh. The family names are the same, and the size-matched fallbacks stay (Licht Sans's re-measured against its new cuts).
75
104
 
76
105
  Every cut is real now: Licht Sans from 100 to 900 and Licht Mono from 100 to 800, each upright and italic, so Tailwind's `font-thin` … `font-black` and `italic` pick a true face for them; the browser fetches only the cuts a page uses. Licht itself also comes in 100–900, but headlines stay Light by rule: the `h1`–`h4` base rule, the `display` utility, `font-heading` (which now sets `font-weight: 300` too), Prose, Response and the editor's headings set 300 with `font-synthesis: none`, and `<b>`/`<strong>` inside them keep the heading's weight, so nothing renders heavier than before. Don't put a weight utility on Licht text: it would now pick a real heavier cut.
77
106
 
@@ -354,7 +383,6 @@ No changes in this release.
354
383
 
355
384
  - bfe8241: Labels keep their descenders: a button label that slides in or out clips across only, and the truncated mono line under a Graph node and the file name in the Lightbox take a normal line height, so a "g" or a "y" is no longer cut at the bottom.
356
385
  - 6325477: Text no longer jumps when the Licht faces arrive. Each family now falls back first to a system face sized to it — "Licht Fallback" (Times New Roman), "Licht Sans Fallback" (Arial) and "Licht Mono Fallback" (Courier New), or their Liberation twins on Linux — with `size-adjust`, `ascent-override`, `descent-override` and `line-gap-override` matched to Licht's width and vertical metrics, so lines keep their length and height through the swap. `--font-heading`, `--font-body` and `--font-mono` name them after the Licht face; where none of those system faces is installed the stack goes on as before.
357
- - a26fbe0: The Licht fonts now come from `licht` (the same files and `@font-face` rules as `@zonsh/fonts`, which npm marks as moved to `licht`), so installing no longer warns about a deprecated package. Nothing to change in an app: `@import "@zonsh/ui/styles.css"` brings them as before.
358
386
  - a60b250: The MCP server is gone: `@zonsh/ui-mcp` is no longer released with the library. The Claude skill inside the package, llms.txt and each component's page as Markdown carry the same docs. The skill and the README no longer point to the server, and where they named its `theme_from_preset` tool, `themeFromPreset(code).css` from `@zonsh/ui` gives the same CSS.
359
387
  - ea2cebb: The motion guide (`docs/motion.md`, the skill's `references/motion.md`) now describes the motion as the code has it: the duration factors in use, each kind of motion (state changes, popups, drawers and toasts, gliding indicators, heights, drag, springs, streaming text, loading, arrival, decoration) with its rule, the distances, what reduced motion does for each, what holds still on a phone, a checklist for a new part, and Do / Don't pairs. The docs site shows it at `/ui/motion`, beside the brand guide.
360
388
  - 5c3a9b9: Motion follows its own guide (docs/motion.md) everywhere:
@@ -430,6 +458,8 @@ No changes in this release.
430
458
 
431
459
  ## 0.5.0
432
460
 
461
+ Released 10 November 2026.
462
+
433
463
  ### Minor Changes
434
464
 
435
465
  - 25366e2: Motion, reworked after Emil Kowalski's skills for designers and engineers (MIT; the web ones are copied into the repository's `.claude/skills/`). The guide is `docs/motion.md`: in the zon-ui skill as `references/motion.md`, on the site as `/ui/motion.md`, and from the MCP server as the new `get_motion_guide` tool.
@@ -474,6 +504,8 @@ No changes in this release.
474
504
 
475
505
  ## 0.4.1
476
506
 
507
+ Released 10 November 2026.
508
+
477
509
  ### Patch Changes
478
510
 
479
511
  - 1454b85: Switch: hovering no longer stretches the thumb; only a press does (18 to 25px, towards where it will go). The stretch is the start of the toggle, so on hover it suggested a flip that wasn't coming, and a column of switches twitched as the pointer passed.
@@ -633,6 +665,8 @@ Not published to npm: its changes were first released in 0.4.1.
633
665
 
634
666
  ## 0.2.0
635
667
 
668
+ Released 2 November 2026.
669
+
636
670
  ### Minor Changes
637
671
 
638
672
  - ccc9ba8: A Button or Tag label wider than its container ends in "…". Slider thumbs stop at the track's ends (`thumbAlignment="center"` keeps the overhang). On a Mac, the Sidebar, Command, PDF viewer and Whiteboard shortcuts take ⌘ only. A table that scrolls is a tab stop. Right to left, popups follow the page's direction and toasts sit bottom left.
package/README.md CHANGED
@@ -51,8 +51,7 @@ Licht, Licht Sans and Licht Mono come with the stylesheet: `@import "@zonsh/ui/s
51
51
  brings their `@font-face` rules from [`licht`](https://www.npmjs.com/package/licht),
52
52
  a dependency, and your bundler (Vite, Next.js, anything that runs Tailwind) copies the WOFF2 files
53
53
  into the build. They are served from your own origin, never hotlinked, and there is nothing to set
54
- up. An app set up before 0.6.0 removes `zonFonts()` (from `@zonsh/ui/vite`, now gone) and any
55
- `/licht/fonts` rewrite.
54
+ up.
56
55
 
57
56
  The build lists every cut of the three families, 52 WOFF2 files (about 1.4 MB; `LichtSerif-*` is
58
57
  Licht, the headline face). That is disk, not page weight: a browser downloads only the cuts a page
@@ -3,7 +3,8 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
3
3
  import { useRender } from "@base-ui/react/use-render";
4
4
  import * as React from "react";
5
5
  import { cn } from "../lib/cn.js";
6
- import { glideMotion, glideStyle, layoutBox, useGlide, useMergedRef } from "../lib/glide.js";
6
+ import { glideMotion, glideStyle, useGlide, useMergedRef } from "../lib/glide.js";
7
+ import { RULE, useLiquidMark } from "../lib/liquid-mark.js";
7
8
  import { usePressFeedback } from "../lib/press.js";
8
9
  import { Badge, BadgeAnchor } from "./badge.js";
9
10
  import { useMessages } from "./locale.js";
@@ -23,304 +24,15 @@ const hiddenFrom = {
23
24
  md: "md:hidden",
24
25
  lg: "lg:hidden",
25
26
  };
26
- /** The bar's mark: a 2px rule, 32px wide, on the hairline over the current item's tile. */
27
- const RULE = 32;
27
+ /** The bar's rule over the current item's tile (its size: RULE, lib/liquid-mark). */
28
28
  function ruleStyle({ rect }) {
29
29
  return rect
30
30
  ? { translate: `${rect.x + (rect.width - RULE) / 2}px -1px`, width: RULE, height: 2 }
31
31
  : undefined;
32
32
  }
33
- /** How far a press moves sideways before it becomes a drag of the mark (px). */
34
- const DRAG_FROM = 6;
35
- const reducedMotion = () => typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
36
- /** Held: the lens trails the finger a little under-damped, and swells with a small wobble. */
37
- const HOLD = { k: 420, c: 30, sizeK: 520, sizeC: 22 };
38
- /**
39
- * Let go: one spring, a touch under critical damping, carries the lens on from its own speed onto
40
- * the item and shrinks it back with the same stiffness, so it travels, sets down and loses its
41
- * lift as one motion that ends at once, rather than a quick shrink and then a slide.
42
- */
43
- const SETTLE = { k: 320, c: 34 };
44
- /** The lens's swell while held: the lift (its shadow) follows it from 0 at rest to 1 held. */
45
- const SWELL = { capsule: 1.3, bar: 1.6 };
46
- /**
47
- * How far a release carries on at the finger's speed when it chooses the item (s): a flick towards
48
- * the next item lands on it, a finger that has stopped chooses what is under it.
49
- */
50
- const PROJECT = 0.08;
51
- /** The finger's speed over its last 80ms (px/s), or 0 once it has stopped. */
52
- function fingerSpeed(samples, now) {
53
- const recent = samples.filter(([t]) => now - t <= 80);
54
- if (recent.length < 2)
55
- return 0;
56
- const [t0, x0] = recent[0];
57
- const [t1, x1] = recent.at(-1);
58
- return t1 > t0 ? ((x1 - x0) / (t1 - t0)) * 1000 : 0;
59
- }
60
- /**
61
- * The mark as a drop of liquid, as in iOS: pressed, it swells past the capsule and lifts; dragged, it
62
- * trails the finger on a spring, stretching along its path and squashing across it, rubber-banding
63
- * past the ends; let go, it springs onto the item under it and wobbles still. The icon under the
64
- * lens swells with it, and a light tick marks each new item where the device can. Letting go
65
- * clicks that item, so a link navigates and `onValueChange` fires as for a tap. A press that stays
66
- * put is an ordinary tap, and the lens travels to the tapped item the same way, stretching as it
67
- * goes. Under reduced motion the lens moves without springs or swelling.
68
- */
69
- function useLiquidMark(row, mark, capsule) {
70
- const [active, setActive] = React.useState(false);
71
- // Held or dragged: the mark lifts (a deeper shadow). A tap's travel moves it as it rests.
72
- const [lifted, setLifted] = React.useState(false);
73
- const [under, setUnder] = React.useState(null);
74
- const state = React.useRef(null);
75
- const swallowClick = React.useRef(false);
76
- const items = () => Array.from(row.current?.querySelectorAll(`:scope > ${ITEM}`) ?? []);
77
- // Measured exactly as the resting glide measures the current tile (layout boxes, from the row's
78
- // padding box), so the spring lands on the very pixel the glide then holds: no 1px hop, no
79
- // change of width, as the lens hands over from the spring to its resting place.
80
- const measure = () => items().map((el) => {
81
- const t = layoutBox(el.querySelector(TILE) ?? el, row.current);
82
- return { left: t.x, top: t.y, width: t.width, height: t.height, centre: t.x + t.width / 2 };
83
- });
84
- const nearest = (s, x) => {
85
- const all = items();
86
- let best = s.under;
87
- let distance = Infinity;
88
- s.tiles.forEach((t, i) => {
89
- if (all[i]?.getAttribute("aria-disabled") === "true")
90
- return;
91
- const away = Math.abs(t.centre - x);
92
- if (away < distance)
93
- [best, distance] = [i, away];
94
- });
95
- return best;
96
- };
97
- const paint = (s) => {
98
- const el = mark.current;
99
- const tile = s.tiles[s.from] ?? s.tiles[0];
100
- if (!el || !tile)
101
- return;
102
- // Stretched along the path by its speed, squashed across it so it keeps its volume.
103
- const along = 1 + s.stretch;
104
- const across = 1 / Math.sqrt(along);
105
- // The lift (the shadow under the pill, parts/navigation.css) rises and sets down with the swell.
106
- const swell = capsule ? SWELL.capsule : SWELL.bar;
107
- el.style.setProperty("--lens-lift", `${Math.min(1, Math.max(0, (s.size - 1) / (swell - 1)))}`);
108
- if (capsule) {
109
- el.style.width = `${tile.width}px`;
110
- el.style.height = `${tile.height}px`;
111
- el.style.translate = `${s.x - tile.width / 2}px ${tile.top}px`;
112
- el.style.scale = `${s.size * along} ${s.size * across}`;
113
- }
114
- else {
115
- // The bar's rule: it stretches with the speed and thickens while held.
116
- el.style.width = `${RULE}px`;
117
- el.style.height = "2px";
118
- el.style.translate = `${s.x - RULE / 2}px -1px`;
119
- el.style.scale = `${along * (1 + (s.size - 1) * 0.6)} ${s.size}`;
120
- }
121
- };
122
- const finish = () => {
123
- const s = state.current;
124
- if (s)
125
- cancelAnimationFrame(s.frame);
126
- state.current = null;
127
- // The spring ended exactly where the resting glide puts it: React writes that place over these
128
- // values on the next render, so only the scale, which it does not know, is cleared here.
129
- if (mark.current) {
130
- mark.current.style.scale = "";
131
- mark.current.style.removeProperty("--lens-lift");
132
- }
133
- setActive(false);
134
- setLifted(false);
135
- setUnder(null);
136
- };
137
- const step = (now) => {
138
- const s = state.current;
139
- if (!s)
140
- return;
141
- const dt = Math.min(0.034, Math.max(0.001, (now - s.last) / 1000));
142
- s.last = now;
143
- if (reducedMotion()) {
144
- [s.x, s.v, s.size, s.sv, s.stretch] = [s.target, 0, 1, 0, 0];
145
- }
146
- else {
147
- // Held, a little under-damped: it trails the finger, overshoots a touch and settles. Let go,
148
- // position and size share one spring, from where and how fast they are (no restart).
149
- const p = s.releasing ? { k: SETTLE.k, c: SETTLE.c, sizeK: SETTLE.k, sizeC: SETTLE.c } : HOLD;
150
- // In steps of at most 4ms, so a slow or dropped frame moves it as far as the spring says,
151
- // not a long straight step that overshoots, and 60Hz and 120Hz screens draw the same curve.
152
- const steps = Math.ceil(dt / 0.004);
153
- const h = dt / steps;
154
- for (let i = 0; i < steps; i++) {
155
- s.v += (p.k * (s.target - s.x) - p.c * s.v) * h;
156
- s.x += s.v * h;
157
- s.sv += (p.sizeK * (s.grow - s.size) - p.sizeC * s.sv) * h;
158
- s.size += s.sv * h;
159
- const want = Math.min(Math.abs(s.v) / 1400, capsule ? 0.45 : 0.9);
160
- s.stretch += (want - s.stretch) * Math.min(1, h * 18);
161
- }
162
- }
163
- paint(s);
164
- // Still to well under a pixel, so handing the place back to the resting glide shows nothing.
165
- const still = Math.abs(s.target - s.x) < 0.2 &&
166
- Math.abs(s.v) < 3 &&
167
- Math.abs(s.grow - s.size) < 0.001 &&
168
- Math.abs(s.sv) < 0.02 &&
169
- s.stretch < 0.002;
170
- if (s.releasing && still)
171
- return finish();
172
- s.frame = requestAnimationFrame(step);
173
- };
174
- const start = (s, lift) => {
175
- state.current = s;
176
- setActive(true);
177
- setLifted(lift);
178
- paint(s);
179
- s.last = performance.now();
180
- s.frame = requestAnimationFrame(step);
181
- };
182
- React.useEffect(() => () => cancelAnimationFrame(state.current?.frame ?? 0), []);
183
- // The item under the lens takes the full ink and swells, as the current one does.
184
- React.useEffect(() => {
185
- items().forEach((el, i) => el.toggleAttribute("data-under", i === under));
186
- // eslint-disable-next-line react-hooks/exhaustive-deps
187
- }, [under]);
188
- const onPointerDown = (event) => {
189
- const list = row.current;
190
- if (!list || (event.pointerType === "mouse" && event.button !== 0))
191
- return;
192
- const item = event.target.closest(ITEM);
193
- if (!item || item.parentElement !== list || item.getAttribute("aria-disabled") === "true")
194
- return;
195
- if (state.current)
196
- finish();
197
- const tiles = measure();
198
- const all = items();
199
- const from = all.indexOf(item);
200
- const current = all.findIndex((el) => el.getAttribute("aria-current") === "page");
201
- const home = tiles[current >= 0 ? current : from].centre;
202
- const s = {
203
- pointer: event.pointerId,
204
- startX: event.clientX,
205
- moved: false,
206
- tiles,
207
- from,
208
- under: from,
209
- x: home,
210
- v: 0,
211
- target: home,
212
- size: 1,
213
- sv: 0,
214
- grow: 1,
215
- stretch: 0,
216
- samples: [[event.timeStamp, event.clientX]],
217
- releasing: false,
218
- last: 0,
219
- frame: 0,
220
- };
221
- // Pressing the current item lifts the lens at once; another waits to see if it is a drag.
222
- if (from === current) {
223
- s.grow = capsule ? SWELL.capsule : SWELL.bar;
224
- start(s, true);
225
- }
226
- else {
227
- state.current = s;
228
- }
229
- };
230
- const onPointerMove = (event) => {
231
- const s = state.current;
232
- const list = row.current;
233
- if (!s || !list || s.pointer !== event.pointerId || s.releasing)
234
- return;
235
- s.samples.push([event.timeStamp, event.clientX]);
236
- if (s.samples.length > 8)
237
- s.samples.shift();
238
- if (!s.moved) {
239
- if (Math.abs(event.clientX - s.startX) < DRAG_FROM)
240
- return;
241
- s.moved = true;
242
- list.setPointerCapture(event.pointerId);
243
- s.grow = capsule ? SWELL.capsule : SWELL.bar;
244
- if (!active)
245
- start(s, true);
246
- else
247
- setLifted(true);
248
- }
249
- const box = list.getBoundingClientRect();
250
- const ends = [s.tiles[0].centre, s.tiles.at(-1).centre];
251
- const [first, last] = [Math.min(...ends), Math.max(...ends)];
252
- const x = event.clientX - box.left - list.clientLeft;
253
- // Past either end it gives a little, harder the further it goes.
254
- const band = (over) => (over * 18) / (over + 30);
255
- s.target = x < first ? first - band(first - x) : x > last ? last + band(x - last) : x;
256
- const next = nearest(s, s.target);
257
- if (next !== s.under) {
258
- s.under = next;
259
- setUnder(next);
260
- navigator.vibrate?.(5);
261
- }
262
- };
263
- const end = (event, choose) => {
264
- const s = state.current;
265
- if (!s || s.pointer !== event.pointerId || s.releasing)
266
- return;
267
- if (!s.moved) {
268
- // A tap. On the current item the lens, which rose, sinks back. On another it travels there
269
- // as liquid, stretching on the way with a little lift, and the click chooses the item.
270
- if (!active) {
271
- const current = items().findIndex((el) => el.getAttribute("aria-current") === "page");
272
- if (!choose || current < 0 || current === s.from || reducedMotion()) {
273
- state.current = null;
274
- return;
275
- }
276
- s.x = s.tiles[current].centre;
277
- s.target = s.tiles[s.from].centre;
278
- s.sv = capsule ? 2.6 : 4;
279
- s.releasing = true;
280
- start(s, false);
281
- return;
282
- }
283
- s.releasing = true;
284
- s.grow = 1;
285
- // It sets down as it shrinks: the lift eases out from the release, with the spring, rather
286
- // than waiting for the spring to finish and then dropping as a second step.
287
- setLifted(false);
288
- return;
289
- }
290
- // The release is not a tap on whatever it ended over: only the item under the lens is chosen.
291
- swallowClick.current = true;
292
- setTimeout(() => (swallowClick.current = false), 0);
293
- const all = items();
294
- const current = all.findIndex((el) => el.getAttribute("aria-current") === "page");
295
- // Let go while moving, it chooses where the finger was heading: a flick carries on to the
296
- // next item, as the lens itself carries on with its speed.
297
- const heading = nearest(s, s.target + fingerSpeed(s.samples, event.timeStamp) * PROJECT);
298
- const pick = choose ? heading : current >= 0 ? current : s.from;
299
- s.target = s.tiles[pick].centre;
300
- s.grow = 1;
301
- s.releasing = true;
302
- setLifted(false);
303
- setUnder(null);
304
- const target = all[pick];
305
- if (choose && target && target.getAttribute("aria-current") !== "page")
306
- target.click();
307
- };
308
- const handlers = {
309
- onPointerDown,
310
- onPointerMove,
311
- onPointerUp: (event) => end(event, true),
312
- onPointerCancel: (event) => end(event, false),
313
- onClickCapture: (event) => {
314
- if (swallowClick.current && event.nativeEvent.isTrusted) {
315
- event.preventDefault();
316
- event.stopPropagation();
317
- }
318
- },
319
- };
320
- return [active, lifted, handlers];
321
- }
322
33
  const ITEM = '[data-slot="bottom-nav-item"]';
323
34
  const TILE = '[data-slot="bottom-nav-item-tile"]';
35
+ const isCurrentPage = (el) => el.getAttribute("aria-current") === "page";
324
36
  const findCurrent = (row) => row.querySelector(`${ITEM}[aria-current="page"] > ${TILE}`);
325
37
  /** How far the page scrolls down before the bar goes, and up before it comes back (px). */
326
38
  const HIDE_AFTER = 24;
@@ -409,7 +121,12 @@ export function BottomNav({ value: valueProp, defaultValue, onValueChange, varia
409
121
  const [hidden, setHidden] = useHideOnScroll(navRef, hideOnScroll, contained);
410
122
  const glide = useGlide(rowRef, findCurrent, { attributes: ["aria-current"], items: ITEM });
411
123
  const markRef = React.useRef(null);
412
- const [liquid, lifted, dragHandlers] = useLiquidMark(rowRef, markRef, capsule);
124
+ const [liquid, lifted, dragHandlers] = useLiquidMark(rowRef, markRef, {
125
+ capsule,
126
+ item: ITEM,
127
+ tile: TILE,
128
+ isCurrent: isCurrentPage,
129
+ });
413
130
  // While dragged, the mark sits under the finger, centred on it, at the tiles' size and height.
414
131
  const resting = capsule ? glideStyle(glide) : ruleStyle(glide);
415
132
  const context = React.useMemo(() => ({
@@ -1,5 +1,7 @@
1
1
  import { Button as BaseButton } from "@base-ui/react/button";
2
2
  import * as React from "react";
3
+ /** Press feedback at touch-down, as the phone parts give it, for a screen's own buttons and rows. */
4
+ export { usePressFeedback } from "../lib/press.js";
3
5
  declare const variants: {
4
6
  /** The layered primary. One per view — the action that carries the page. */
5
7
  readonly primary: "material-primary";
@@ -67,4 +69,3 @@ export interface ButtonProps extends BaseButton.Props {
67
69
  * Use `render={<a href="…" />}` with `nativeButton={false}` for links styled as buttons.
68
70
  */
69
71
  export declare function Button({ variant, size, collapsible, expandable, loading, loadingLabel, className, children, ref, ...props }: ButtonProps): React.JSX.Element;
70
- export {};
@@ -6,6 +6,8 @@ import { sx } from "../lib/cn.js";
6
6
  import { useCollapsible } from "../lib/collapse-row.js";
7
7
  import { mergeRefs } from "../lib/merge-refs.js";
8
8
  import { Spinner } from "./spinner.js";
9
+ /** Press feedback at touch-down, as the phone parts give it, for a screen's own buttons and rows. */
10
+ export { usePressFeedback } from "../lib/press.js";
9
11
  /* The raised material fills a trigger whose popup is open; a disabled button explaining itself with
10
12
  a tooltip stays at rest instead. */
11
13
  const variants = {
@@ -1,6 +1,24 @@
1
1
  import { Radio as BaseRadio } from "@base-ui/react/radio";
2
2
  import { RadioGroup as BaseRadioGroup } from "@base-ui/react/radio-group";
3
3
  import * as React from "react";
4
+ /**
5
+ * `default`: a column of round radios beside their labels. `capsule`: the options side by side in
6
+ * a capsule, the chosen one on a raised pill that glides, and drags like a lens, as BottomNav's.
7
+ */
8
+ export type RadioGroupVariant = "default" | "capsule";
9
+ /** A capsule's height: 30, 38 or 46px, as every control. */
10
+ export type RadioGroupSize = "sm" | "default" | "lg";
11
+ export interface RadioGroupProps<Value> extends BaseRadioGroup.Props<Value> {
12
+ /**
13
+ * `default`: round radios beside their labels, in a column. `capsule`: the options side by side
14
+ * in a capsule, the chosen one on a raised pill that glides to the next and can be dragged
15
+ * across. For a few short options (an icon or a word or two each) chosen often: an answer to a
16
+ * check, a view, a period.
17
+ */
18
+ variant?: RadioGroupVariant;
19
+ /** A capsule's height: `sm` 30px, `default` 38px, `lg` 46px. Capsule only. */
20
+ size?: RadioGroupSize;
21
+ }
4
22
  /**
5
23
  * RadioGroup — one choice from a short list where every option should stay visible.
6
24
  *
@@ -9,10 +27,13 @@ import * as React from "react";
9
27
  * about seven options use `Select`. The rule people break: a radio group with nothing selected
10
28
  * and no `required` — give it a sensible `defaultValue` or make the choice mandatory.
11
29
  */
12
- export declare function RadioGroup<Value>({ className, ref, ...props }: BaseRadioGroup.Props<Value>): React.JSX.Element;
30
+ export declare function RadioGroup<Value>({ variant, size, className, ref, ...props }: RadioGroupProps<Value>): React.JSX.Element;
13
31
  /**
14
32
  * Radio — an 18px round control in the field material. Selected, it takes the primary fill
15
33
  * with an inner dot. Always place it inside `<RadioGroup>` and next to a visible label
16
34
  * (`<FieldLabel><Radio value="…" />Label</FieldLabel>`).
35
+ *
36
+ * In a capsule (`RadioGroup variant="capsule"`) it is one segment instead: its children, an icon,
37
+ * a word or both, muted until it is checked. An icon alone needs an `aria-label`.
17
38
  */
18
- export declare function Radio<Value>({ className, ...props }: BaseRadio.Root.Props<Value>): React.JSX.Element;
39
+ export declare function Radio<Value>({ className, children, ...props }: BaseRadio.Root.Props<Value>): React.JSX.Element;
@@ -1,11 +1,26 @@
1
1
  "use client";
2
- import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { Radio as BaseRadio } from "@base-ui/react/radio";
4
4
  import { RadioGroup as BaseRadioGroup } from "@base-ui/react/radio-group";
5
5
  import * as React from "react";
6
6
  import { cn, sx } from "../lib/cn.js";
7
7
  import { useFormReset } from "../lib/form-reset.js";
8
+ import { glideMotion, glideStyle, useGlide } from "../lib/glide.js";
9
+ import { useLiquidMark } from "../lib/liquid-mark.js";
8
10
  import { mergeRefs } from "../lib/merge-refs.js";
11
+ import { usePressFeedback } from "../lib/press.js";
12
+ const RadioGroupContext = React.createContext({
13
+ variant: "default",
14
+ size: "default",
15
+ });
16
+ const RADIO = '[data-slot="radio"]';
17
+ const isChecked = (el) => el.getAttribute("aria-checked") === "true";
18
+ const findChecked = (row) => row.querySelector(`:scope > ${RADIO}[aria-checked="true"]`);
19
+ const capsuleHeight = {
20
+ sm: "h-(--control-h-sm) [--capsule-item:calc(var(--control-h-sm)-8px)]",
21
+ default: "h-(--control-h) [--capsule-item:calc(var(--control-h)-8px)]",
22
+ lg: "h-(--control-h-lg) [--capsule-item:calc(var(--control-h-lg)-8px)]",
23
+ };
9
24
  /**
10
25
  * RadioGroup — one choice from a short list where every option should stay visible.
11
26
  *
@@ -14,18 +29,61 @@ import { mergeRefs } from "../lib/merge-refs.js";
14
29
  * about seven options use `Select`. The rule people break: a radio group with nothing selected
15
30
  * and no `required` — give it a sensible `defaultValue` or make the choice mandatory.
16
31
  */
17
- export function RadioGroup({ className, ref, ...props }) {
32
+ export function RadioGroup({ variant = "default", size = "default", className, ref, ...props }) {
18
33
  // A form's reset remounts the group, and its radios, from its defaults (lib/form-reset).
19
34
  const [resetKey, formRef] = useFormReset();
20
35
  const refs = React.useMemo(() => mergeRefs(formRef, ref), [formRef, ref]);
21
- return (_jsx(BaseRadioGroup, { ref: refs, "data-slot": "radio-group", className: sx("flex flex-col items-start gap-3", className), ...props }, resetKey));
36
+ const context = React.useMemo(() => ({ variant, size }), [variant, size]);
37
+ return (_jsx(RadioGroupContext.Provider, { value: context, children: variant === "capsule" ? (_jsx(CapsuleGroup, { groupRef: refs, size: size, className: className, ...props }, resetKey)) : (_jsx(BaseRadioGroup, { ref: refs, "data-slot": "radio-group", className: sx("flex flex-col items-start gap-3", className), ...props }, resetKey)) }));
38
+ }
39
+ /**
40
+ * The capsule: the radios in a row on the field's track, the checked one on a raised pill that
41
+ * glides to the next (lib/glide) and, pressed or dragged, swells and follows the finger as a lens
42
+ * (lib/liquid-mark): let go, it chooses the radio under it. Nothing checked, no pill.
43
+ */
44
+ function CapsuleGroup({ groupRef, size, className, children, disabled, readOnly, ...props }) {
45
+ usePressFeedback();
46
+ const rowRef = React.useRef(null);
47
+ const markRef = React.useRef(null);
48
+ const refs = React.useMemo(() => mergeRefs(groupRef, rowRef), [groupRef]);
49
+ const glide = useGlide(rowRef, findChecked, { attributes: ["aria-checked"], items: RADIO });
50
+ const [liquid, lifted, handlers] = useLiquidMark(rowRef, markRef, {
51
+ capsule: true,
52
+ item: RADIO,
53
+ isCurrent: isChecked,
54
+ });
55
+ const resting = glideStyle(glide);
56
+ return (_jsxs(BaseRadioGroup, { ref: refs, "data-slot": "radio-group", "data-variant": "capsule", "data-size": size, "data-dragging": liquid ? "" : undefined, disabled: disabled, readOnly: readOnly, ...(disabled || readOnly ? {} : handlers), className: sx([
57
+ // Equal shares, each item as wide as the widest needs: a capsule of like choices.
58
+ "relative isolate inline-grid w-fit max-w-full material-field auto-cols-fr grid-flow-col items-center rounded-full p-[3px]",
59
+ capsuleHeight[size],
60
+ "data-disabled:opacity-50",
61
+ ], className), ...props, children: [_jsx("span", { "aria-hidden": true, ref: markRef, "data-slot": "radio-group-indicator", "data-visible": glide.visible ? "" : undefined, "data-instant": glide.instant ? "" : undefined, "data-lifted": lifted ? "" : undefined, className: cn(glideMotion, "-z-1 rounded-full border border-transparent bg-control-surface bg-linear-to-b from-control-inner-edge to-transparent shadow-raised"),
62
+ // While liquid, the spring in useLiquidMark places it frame by frame, with no transition.
63
+ style: liquid
64
+ ? { transition: "opacity var(--duration-fade)" }
65
+ : resting && !glide.instant
66
+ ? { ...resting, transitionProperty: "translate, width, height, opacity, filter" }
67
+ : resting }), children] }));
22
68
  }
23
69
  /**
24
70
  * Radio — an 18px round control in the field material. Selected, it takes the primary fill
25
71
  * with an inner dot. Always place it inside `<RadioGroup>` and next to a visible label
26
72
  * (`<FieldLabel><Radio value="…" />Label</FieldLabel>`).
73
+ *
74
+ * In a capsule (`RadioGroup variant="capsule"`) it is one segment instead: its children, an icon,
75
+ * a word or both, muted until it is checked. An icon alone needs an `aria-label`.
27
76
  */
28
- export function Radio({ className, ...props }) {
77
+ export function Radio({ className, children, ...props }) {
78
+ const { variant } = React.useContext(RadioGroupContext);
79
+ if (variant === "capsule")
80
+ return (_jsx(BaseRadio.Root, { "data-slot": "radio", "data-variant": "capsule", "data-press": "", className: sx([
81
+ "touch-target relative flex h-(--capsule-item) min-w-[calc(var(--capsule-item)*1.5)] cursor-pointer items-center justify-center gap-1.5 rounded-full px-3 outline-none select-none [-webkit-tap-highlight-color:transparent]",
82
+ "font-body text-sm leading-none font-medium whitespace-nowrap",
83
+ "focus-visible:outline-(length:--focus-width) focus-visible:outline-offset-0 focus-visible:outline-control-focus focus-visible:outline-solid",
84
+ "data-disabled:cursor-default data-readonly:cursor-default",
85
+ "[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4.5",
86
+ ], className), ...props, children: _jsx("span", { "data-slot": "radio-label", className: "inline-flex items-center gap-1.5", children: children }) }));
29
87
  return (_jsx(BaseRadio.Root, { "data-slot": "radio", className: sx([
30
88
  "touch-target relative inline-flex size-(--check-size) shrink-0 material-field cursor-pointer items-center justify-center rounded-full p-0",
31
89
  "data-checked:border-transparent data-checked:bg-primary data-checked:bg-none data-checked:text-primary-foreground data-checked:shadow-checked",
package/dist/index.d.ts CHANGED
@@ -15,7 +15,7 @@ export { type BadgeVariant, type BadgeSize, type BadgeProps, Badge, type BadgeAn
15
15
  export { type BottomNavMessages, type BottomNavVariant, type BottomNavBreakpoint, type BottomNavProps, BottomNav, type BottomNavItemProps, BottomNavItem, type BottomNavActionProps, BottomNavAction, } from "./components/bottom-nav.js";
16
16
  export { type BreadcrumbMessages, type BreadcrumbItem, type BreadcrumbProps, Breadcrumb, } from "./components/breadcrumb.js";
17
17
  export { type ButtonGroupProps, ButtonGroup, type ButtonGroupSeparatorProps, ButtonGroupSeparator, } from "./components/button-group.js";
18
- export { type ButtonVariant, type ButtonSize, type ButtonProps, Button } from "./components/button.js";
18
+ export { usePressFeedback, type ButtonVariant, type ButtonSize, type ButtonProps, Button, } from "./components/button.js";
19
19
  export { type CardVariant, type CardProps, Card, CardHeader, CardTitle, CardDescription, CardContent, CardFooter, } from "./components/card.js";
20
20
  export { type CheckboxProps, Checkbox, type CheckboxGroupProps, CheckboxGroup } from "./components/checkbox.js";
21
21
  export { type CodeBlockMessages, type CodeBlockProps, CodeBlock } from "./components/code-block.js";
@@ -61,7 +61,7 @@ export { type ProgressTone, type ProgressProps, Progress } from "./components/pr
61
61
  export { type PromptInputMessages, type PromptInputStatus, type PromptInputLayout, type PromptInputProps, PromptInput, PromptInputHeader, type PromptInputAttachmentProps, PromptInputAttachment, type PromptInputAttachButtonProps, PromptInputAttachButton, type PromptInputTextareaProps, PromptInputTextarea, PromptInputToolbar, type PromptInputToolsProps, PromptInputTools, PromptInputButton, type PromptInputSubmitProps, PromptInputSubmit, } from "./components/prompt-input.js";
62
62
  export { type PullToRefreshMessages, type PullToRefreshProps, PullToRefresh, } from "./components/pull-to-refresh.js";
63
63
  export { type QuoteProps, Quote } from "./components/quote.js";
64
- export { RadioGroup, Radio } from "./components/radio-group.js";
64
+ export { type RadioGroupVariant, type RadioGroupSize, type RadioGroupProps, RadioGroup, Radio, } from "./components/radio-group.js";
65
65
  export { type RatingMessages, type RatingProps, Rating } from "./components/rating.js";
66
66
  export { type ReasoningMessages, type ReasoningProps, Reasoning, type ReasoningTriggerProps, ReasoningTrigger, ReasoningContent, } from "./components/reasoning.js";
67
67
  export { type ResponseMessages, type ResponseProps, Response } from "./components/response.js";
package/dist/index.js CHANGED
@@ -16,7 +16,7 @@ export { Badge, BadgeAnchor, } from "./components/badge.js";
16
16
  export { BottomNav, BottomNavItem, BottomNavAction, } from "./components/bottom-nav.js";
17
17
  export { Breadcrumb, } from "./components/breadcrumb.js";
18
18
  export { ButtonGroup, ButtonGroupSeparator, } from "./components/button-group.js";
19
- export { Button } from "./components/button.js";
19
+ export { usePressFeedback, Button, } from "./components/button.js";
20
20
  export { Card, CardHeader, CardTitle, CardDescription, CardContent, CardFooter, } from "./components/card.js";
21
21
  export { Checkbox, CheckboxGroup } from "./components/checkbox.js";
22
22
  export { CodeBlock } from "./components/code-block.js";
@@ -62,7 +62,7 @@ export { Progress } from "./components/progress.js";
62
62
  export { PromptInput, PromptInputHeader, PromptInputAttachment, PromptInputAttachButton, PromptInputTextarea, PromptInputToolbar, PromptInputTools, PromptInputButton, PromptInputSubmit, } from "./components/prompt-input.js";
63
63
  export { PullToRefresh, } from "./components/pull-to-refresh.js";
64
64
  export { Quote } from "./components/quote.js";
65
- export { RadioGroup, Radio } from "./components/radio-group.js";
65
+ export { RadioGroup, Radio, } from "./components/radio-group.js";
66
66
  export { Rating } from "./components/rating.js";
67
67
  export { Reasoning, ReasoningTrigger, ReasoningContent, } from "./components/reasoning.js";
68
68
  export { Response } from "./components/response.js";