@zyncat/ui 0.20.0 → 0.21.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 (281) hide show
  1. package/dist/alert.js +6 -6
  2. package/dist/badge.css +20 -11
  3. package/dist/badge.js +100 -2
  4. package/dist/badge.js.map +1 -1
  5. package/dist/{bloom-HV23M4AW.js → bloom-5MZXLNKG.js} +23 -5
  6. package/dist/bloom-5MZXLNKG.js.map +1 -0
  7. package/dist/button.js +2 -2
  8. package/dist/{chunk-JINATP4N.js → chunk-2W7FOMWE.js} +7 -8
  9. package/dist/chunk-2W7FOMWE.js.map +1 -0
  10. package/dist/{chunk-LNAV5E7S.js → chunk-3HE7N3UK.js} +7 -3
  11. package/dist/chunk-3HE7N3UK.js.map +1 -0
  12. package/dist/{chunk-UKPX3RIP.js → chunk-47OMFFIB.js} +3 -3
  13. package/dist/{chunk-UKPX3RIP.js.map → chunk-47OMFFIB.js.map} +1 -1
  14. package/dist/chunk-4M5FMCFJ.js +16 -0
  15. package/dist/chunk-4M5FMCFJ.js.map +1 -0
  16. package/dist/chunk-6BY5G7BI.js +122 -0
  17. package/dist/chunk-6BY5G7BI.js.map +1 -0
  18. package/dist/{chunk-RLNCRDAL.js → chunk-AOEO2LCZ.js} +4 -4
  19. package/dist/{chunk-RLNCRDAL.js.map → chunk-AOEO2LCZ.js.map} +1 -1
  20. package/dist/{chunk-BRKGYLEQ.js → chunk-AQMR7ZYO.js} +8 -3
  21. package/dist/chunk-AQMR7ZYO.js.map +1 -0
  22. package/dist/{chunk-N43NDSME.js → chunk-AXZBD7LY.js} +6 -3
  23. package/dist/chunk-AXZBD7LY.js.map +1 -0
  24. package/dist/{chunk-V6QAAOA5.js → chunk-BWGK3OD6.js} +9 -6
  25. package/dist/chunk-BWGK3OD6.js.map +1 -0
  26. package/dist/{chunk-VQFILXQN.js → chunk-CYZKPUCG.js} +70 -8
  27. package/dist/chunk-CYZKPUCG.js.map +1 -0
  28. package/dist/{chunk-AIAPXRCI.js → chunk-DEZIQTBW.js} +176 -103
  29. package/dist/chunk-DEZIQTBW.js.map +1 -0
  30. package/dist/{tide-DJZMDAFT.js → chunk-DVLKB3CZ.js} +15 -12
  31. package/dist/chunk-DVLKB3CZ.js.map +1 -0
  32. package/dist/{chunk-F64Z42PJ.js → chunk-GM7IPTTT.js} +5 -6
  33. package/dist/chunk-GM7IPTTT.js.map +1 -0
  34. package/dist/chunk-ITW5UCVU.js +24 -0
  35. package/dist/chunk-ITW5UCVU.js.map +1 -0
  36. package/dist/{chunk-TDHLZY6I.js → chunk-JQZ3FTHP.js} +77 -18
  37. package/dist/chunk-JQZ3FTHP.js.map +1 -0
  38. package/dist/{chunk-PXQBJMPJ.js → chunk-LC6NQQER.js} +3 -3
  39. package/dist/{chunk-PXQBJMPJ.js.map → chunk-LC6NQQER.js.map} +1 -1
  40. package/dist/{chunk-M2KGLH2G.js → chunk-LV442ZOR.js} +10 -10
  41. package/dist/{chunk-M2KGLH2G.js.map → chunk-LV442ZOR.js.map} +1 -1
  42. package/dist/{chunk-F2TB3TT6.js → chunk-PNFFK5HY.js} +4 -4
  43. package/dist/{chunk-F2TB3TT6.js.map → chunk-PNFFK5HY.js.map} +1 -1
  44. package/dist/{chunk-2YGHPQ66.js → chunk-Q5N24VII.js} +2 -2
  45. package/dist/{chunk-2YGHPQ66.js.map → chunk-Q5N24VII.js.map} +1 -1
  46. package/dist/{chunk-XKDR22VE.js → chunk-SPFHWHJ6.js} +8 -4
  47. package/dist/chunk-SPFHWHJ6.js.map +1 -0
  48. package/dist/{chunk-TRPAKUIB.js → chunk-TBIY5YR5.js} +8 -8
  49. package/dist/{chunk-TRPAKUIB.js.map → chunk-TBIY5YR5.js.map} +1 -1
  50. package/dist/chunk-TXJQUN7C.js +108 -0
  51. package/dist/chunk-TXJQUN7C.js.map +1 -0
  52. package/dist/{chunk-VZXML7EH.js → chunk-V4ZN5RD4.js} +12 -3
  53. package/dist/chunk-V4ZN5RD4.js.map +1 -0
  54. package/dist/{chunk-VJXP256V.js → chunk-ZSP4ZTII.js} +7 -7
  55. package/dist/{chunk-VJXP256V.js.map → chunk-ZSP4ZTII.js.map} +1 -1
  56. package/dist/confetti.js +1 -1
  57. package/dist/crossfade-XFZLFLT7.js +91 -0
  58. package/dist/crossfade-XFZLFLT7.js.map +1 -0
  59. package/dist/date-field.js +20 -18
  60. package/dist/date-field.js.map +1 -1
  61. package/dist/date-picker.css +0 -1
  62. package/dist/date-range-field.js +22 -20
  63. package/dist/date-range-field.js.map +1 -1
  64. package/dist/datetime-field.js +21 -19
  65. package/dist/datetime-field.js.map +1 -1
  66. package/dist/dialog.js +9 -9
  67. package/dist/dropdown.css +12 -9
  68. package/dist/dropdown.js +37 -20
  69. package/dist/dropdown.js.map +1 -1
  70. package/dist/emoji-picker.js +14 -14
  71. package/dist/flow-field.js +1 -1
  72. package/dist/glide.js +2 -2
  73. package/dist/instagram-feed.js +2 -2
  74. package/dist/lens.js +1 -1
  75. package/dist/menu-surface.css +81 -7
  76. package/dist/modal.js +8 -8
  77. package/dist/morphing-text.js +1 -1
  78. package/dist/motion-devtools.js +3 -3
  79. package/dist/motion.js +9 -0
  80. package/dist/motion.js.map +1 -0
  81. package/dist/multi-select.js +34 -16
  82. package/dist/multi-select.js.map +1 -1
  83. package/dist/number-field.js +2 -2
  84. package/dist/odometer.css +16 -10
  85. package/dist/odometer.js +105 -72
  86. package/dist/odometer.js.map +1 -1
  87. package/dist/otp-field.js +17 -9
  88. package/dist/otp-field.js.map +1 -1
  89. package/dist/pagination.js +4 -4
  90. package/dist/{paint-CJQCM6ZO.js → paint-NLTI6TEF.js} +5 -3
  91. package/dist/paint-NLTI6TEF.js.map +1 -0
  92. package/dist/popover.js +9 -9
  93. package/dist/radio-group.css +8 -4
  94. package/dist/radio-group.js +5 -5
  95. package/dist/select.css +33 -6
  96. package/dist/select.js +25 -12
  97. package/dist/select.js.map +1 -1
  98. package/dist/sheet.js +9 -9
  99. package/dist/support-rail.js +11 -11
  100. package/dist/table.css +8 -3
  101. package/dist/table.js +7 -7
  102. package/dist/tabs.css +19 -5
  103. package/dist/tabs.js +7 -5
  104. package/dist/tabs.js.map +1 -1
  105. package/dist/tag.js +4 -4
  106. package/dist/textarea.css +13 -1
  107. package/dist/textarea.js +36 -23
  108. package/dist/textarea.js.map +1 -1
  109. package/dist/theme-grid.js +5 -5
  110. package/dist/theme-switcher.js +14 -14
  111. package/dist/{theme-transition-VGLPZDJI.js → theme-transition-FDF2REFD.js} +27 -7
  112. package/dist/theme-transition-FDF2REFD.js.map +1 -0
  113. package/dist/theme-transition.css +49 -0
  114. package/dist/theme.js +2 -2
  115. package/dist/theme.js.map +1 -1
  116. package/dist/tide-AGGMQEJV.js +4 -0
  117. package/dist/tide-AGGMQEJV.js.map +1 -0
  118. package/dist/tiktok.js +2 -2
  119. package/dist/time-field.js +5 -3
  120. package/dist/time-field.js.map +1 -1
  121. package/dist/toast.js +7 -7
  122. package/dist/toggle-tag.js +2 -2
  123. package/dist/toggle.js +4 -15
  124. package/dist/toggle.js.map +1 -1
  125. package/dist/tooltip.js +6 -7
  126. package/dist/tooltip.js.map +1 -1
  127. package/dist/trigger.css +0 -1
  128. package/dist/types/components/composites/date-picker/DateField.d.ts +1 -1
  129. package/dist/types/components/composites/date-picker/DateRangeField.d.ts +1 -1
  130. package/dist/types/components/composites/date-picker/DateTimeField.d.ts +1 -1
  131. package/dist/types/components/composites/date-picker/TimeField.d.ts +1 -1
  132. package/dist/types/components/composites/date-picker/field-shell.d.ts +5 -1
  133. package/dist/types/components/composites/dropdown/Dropdown.d.ts +13 -2
  134. package/dist/types/components/composites/dropdown/types.d.ts +5 -2
  135. package/dist/types/components/composites/select/MultiSelect.d.ts +23 -3
  136. package/dist/types/components/composites/select/Select.d.ts +20 -4
  137. package/dist/types/components/composites/select/core/index.d.ts +2 -1
  138. package/dist/types/components/composites/select/core/menu.d.ts +8 -5
  139. package/dist/types/components/composites/select/core/panel.d.ts +6 -4
  140. package/dist/types/components/composites/select/core/trigger.d.ts +7 -2
  141. package/dist/types/components/composites/select/core/types.d.ts +9 -0
  142. package/dist/types/components/composites/select/core/use-listbox.d.ts +5 -3
  143. package/dist/types/components/composites/tabs/Tabs.d.ts +4 -1
  144. package/dist/types/components/expressive/odometer/Odometer.d.ts +1 -1
  145. package/dist/types/components/expressive/odometer/roll.d.ts +20 -0
  146. package/dist/types/components/expressive/theme-transition/scene.d.ts +3 -0
  147. package/dist/types/components/internal/menu/highlight.d.ts +9 -1
  148. package/dist/types/components/internal/menu/menu-row.d.ts +4 -0
  149. package/dist/types/components/internal/menu/use-anchor-width.d.ts +2 -0
  150. package/dist/types/components/internal/overlay/layer.d.ts +5 -8
  151. package/dist/types/components/internal/overlay/track-anchor.d.ts +5 -0
  152. package/dist/types/components/internal/utils/activation.d.ts +1 -0
  153. package/dist/types/components/primitives/badge/Badge.d.ts +17 -8
  154. package/dist/types/components/primitives/badge/morph-label.d.ts +3 -0
  155. package/dist/types/components/primitives/badge/use-glint-on-change.d.ts +2 -0
  156. package/dist/types/components/primitives/input/OtpField.d.ts +2 -2
  157. package/dist/types/components/primitives/textarea/Textarea.d.ts +2 -2
  158. package/dist/types/components/primitives/textarea/char-meter.d.ts +6 -0
  159. package/dist/types/components/primitives/toggle/switch-glyph.d.ts +6 -0
  160. package/dist/types/motion/crossfade.d.ts +3 -0
  161. package/dist/types/motion/element.d.ts +6 -3
  162. package/dist/types/motion/flip.d.ts +8 -2
  163. package/dist/types/motion/motion.d.ts +7 -0
  164. package/dist/types/theme-scope.d.ts +5 -0
  165. package/dist/types/tokens/component-styles.generated.d.ts +0 -2
  166. package/dist/types/tokens/theme-tokens.generated.d.ts +37 -31
  167. package/dist/typing-lines.js +1 -1
  168. package/dist/youtube.js +2 -2
  169. package/package.json +6 -11
  170. package/skills/zyncat-ui/SKILL.md +2 -2
  171. package/skills/zyncat-ui/references/components.md +3 -4
  172. package/skills/zyncat-ui/references/theming.md +3 -3
  173. package/src/components/composites/date-picker/DateField.tsx +2 -0
  174. package/src/components/composites/date-picker/DateRangeField.tsx +2 -0
  175. package/src/components/composites/date-picker/DateTimeField.tsx +2 -0
  176. package/src/components/composites/date-picker/TimeField.tsx +2 -0
  177. package/src/components/composites/date-picker/date-picker.css +0 -1
  178. package/src/components/composites/date-picker/field-shell.tsx +14 -1
  179. package/src/components/composites/dropdown/Dropdown.tsx +20 -3
  180. package/src/components/composites/dropdown/Dropdown.usage.md +2 -0
  181. package/src/components/composites/dropdown/dropdown.css +12 -9
  182. package/src/components/composites/dropdown/menu-panel.tsx +28 -13
  183. package/src/components/composites/dropdown/types.ts +5 -2
  184. package/src/components/composites/select/MultiSelect.tsx +56 -5
  185. package/src/components/composites/select/MultiSelect.usage.md +10 -0
  186. package/src/components/composites/select/Select.tsx +32 -2
  187. package/src/components/composites/select/Select.usage.md +13 -1
  188. package/src/components/composites/select/core/index.ts +2 -1
  189. package/src/components/composites/select/core/menu.tsx +28 -15
  190. package/src/components/composites/select/core/panel.tsx +57 -52
  191. package/src/components/composites/select/core/trigger.tsx +44 -11
  192. package/src/components/composites/select/core/types.ts +10 -0
  193. package/src/components/composites/select/core/use-listbox.ts +77 -31
  194. package/src/components/composites/select/select.css +33 -6
  195. package/src/components/composites/table/table.css +8 -3
  196. package/src/components/composites/tabs/Tabs.tsx +5 -0
  197. package/src/components/composites/tabs/tabs.css +19 -5
  198. package/src/components/composites/tooltip/tooltip-host.tsx +1 -1
  199. package/src/components/expressive/odometer/Odometer.tsx +45 -92
  200. package/src/components/expressive/odometer/Odometer.usage.md +2 -2
  201. package/src/components/expressive/odometer/odometer.css +16 -10
  202. package/src/components/expressive/odometer/roll.ts +94 -0
  203. package/src/components/expressive/theme-transition/bloom.ts +22 -2
  204. package/src/components/expressive/theme-transition/paint.ts +2 -0
  205. package/src/components/expressive/theme-transition/scene.ts +3 -0
  206. package/src/components/expressive/theme-transition/theme-transition.css +49 -0
  207. package/src/components/expressive/theme-transition/theme-transition.ts +21 -1
  208. package/src/components/expressive/theme-transition/tide.ts +15 -10
  209. package/src/components/internal/menu/highlight.ts +20 -2
  210. package/src/components/internal/menu/menu-row.tsx +36 -8
  211. package/src/components/internal/menu/menu-surface.css +81 -7
  212. package/src/components/internal/menu/use-anchor-width.ts +26 -0
  213. package/src/components/internal/overlay/layer.tsx +11 -23
  214. package/src/components/internal/overlay/position.ts +17 -6
  215. package/src/components/internal/overlay/track-anchor.ts +69 -0
  216. package/src/components/internal/overlay/trigger.css +0 -1
  217. package/src/components/internal/utils/activation.ts +5 -0
  218. package/src/components/primitives/badge/Badge.tsx +38 -15
  219. package/src/components/primitives/badge/Badge.usage.md +12 -5
  220. package/src/components/primitives/badge/badge.css +20 -11
  221. package/src/components/primitives/badge/morph-label.tsx +71 -0
  222. package/src/components/primitives/badge/use-glint-on-change.ts +16 -0
  223. package/src/components/primitives/input/OtpField.tsx +17 -9
  224. package/src/components/primitives/radio-group/radio-group.css +8 -4
  225. package/src/components/primitives/textarea/Textarea.tsx +20 -24
  226. package/src/components/primitives/textarea/char-meter.tsx +34 -0
  227. package/src/components/primitives/textarea/textarea.css +13 -1
  228. package/src/components/primitives/toggle/Toggle.tsx +3 -12
  229. package/src/components/primitives/toggle/switch-glyph.tsx +25 -0
  230. package/src/engine/flip.ts +5 -1
  231. package/src/motion/crossfade.ts +97 -0
  232. package/src/motion/element.tsx +10 -7
  233. package/src/motion/flip.ts +62 -23
  234. package/src/motion/glide.tsx +5 -0
  235. package/src/motion/motion.ts +7 -0
  236. package/src/motion/motion.usage.md +34 -0
  237. package/src/motion/presence.tsx +4 -0
  238. package/src/motion/use-motion.ts +8 -3
  239. package/src/theme-scope.ts +19 -0
  240. package/src/tokens/base.css +7 -0
  241. package/src/tokens/color.css +17 -15
  242. package/src/tokens/component-styles.generated.ts +0 -2
  243. package/src/tokens/dark.css +3 -0
  244. package/src/tokens/decisions.css +5 -3
  245. package/src/tokens/semantic.css +12 -6
  246. package/src/tokens/spacing.css +3 -3
  247. package/src/tokens/theme-tokens.generated.ts +37 -31
  248. package/tailwind.css +2 -0
  249. package/dist/bloom-HV23M4AW.js.map +0 -1
  250. package/dist/chunk-2DNKZ57E.js +0 -72
  251. package/dist/chunk-2DNKZ57E.js.map +0 -1
  252. package/dist/chunk-AIAPXRCI.js.map +0 -1
  253. package/dist/chunk-BRKGYLEQ.js.map +0 -1
  254. package/dist/chunk-F64Z42PJ.js.map +0 -1
  255. package/dist/chunk-JINATP4N.js.map +0 -1
  256. package/dist/chunk-LNAV5E7S.js.map +0 -1
  257. package/dist/chunk-N43NDSME.js.map +0 -1
  258. package/dist/chunk-RJENXXTI.js +0 -93
  259. package/dist/chunk-RJENXXTI.js.map +0 -1
  260. package/dist/chunk-RW2A4M2Q.js +0 -57
  261. package/dist/chunk-RW2A4M2Q.js.map +0 -1
  262. package/dist/chunk-TDHLZY6I.js.map +0 -1
  263. package/dist/chunk-V6QAAOA5.js.map +0 -1
  264. package/dist/chunk-VDOBLABP.js +0 -38
  265. package/dist/chunk-VDOBLABP.js.map +0 -1
  266. package/dist/chunk-VQFILXQN.js.map +0 -1
  267. package/dist/chunk-VZXML7EH.js.map +0 -1
  268. package/dist/chunk-XKDR22VE.js.map +0 -1
  269. package/dist/count-badge.js +0 -13
  270. package/dist/count-badge.js.map +0 -1
  271. package/dist/paint-CJQCM6ZO.js.map +0 -1
  272. package/dist/status-badge.js +0 -72
  273. package/dist/status-badge.js.map +0 -1
  274. package/dist/theme-transition-VGLPZDJI.js.map +0 -1
  275. package/dist/tide-DJZMDAFT.js.map +0 -1
  276. package/dist/types/components/primitives/badge/CountBadge.d.ts +0 -8
  277. package/dist/types/components/primitives/badge/StatusBadge.d.ts +0 -15
  278. package/src/components/primitives/badge/CountBadge.tsx +0 -20
  279. package/src/components/primitives/badge/CountBadge.usage.md +0 -13
  280. package/src/components/primitives/badge/StatusBadge.tsx +0 -113
  281. package/src/components/primitives/badge/StatusBadge.usage.md +0 -14
@@ -0,0 +1,71 @@
1
+ 'use client';
2
+
3
+ import { useEffect, useLayoutEffect, useRef, useState } from 'react';
4
+
5
+ import { UIMotion } from '../../../tokens/motion-tokens';
6
+ import { cx } from '../../internal/utils/cx';
7
+
8
+ const DROP_GRACE_MS = 80;
9
+
10
+ interface Word {
11
+ key: number;
12
+ label: string;
13
+ cls: string;
14
+ }
15
+
16
+ export function MorphLabel({ label }: { label: string }) {
17
+ const prev = useRef(label);
18
+ const keyRef = useRef(1);
19
+ const ghostRef = useRef<HTMLSpanElement>(null);
20
+ const [words, setWords] = useState<Word[]>([{ key: 0, label, cls: '' }]);
21
+ const [boxW, setBoxW] = useState<number>();
22
+
23
+ useLayoutEffect(() => {
24
+ let live = true;
25
+ const measure = () => {
26
+ if (live && ghostRef.current) setBoxW(ghostRef.current.offsetWidth);
27
+ };
28
+ measure();
29
+ document.fonts?.ready.then(measure);
30
+ return () => {
31
+ live = false;
32
+ };
33
+ }, []);
34
+
35
+ useEffect(() => {
36
+ if (prev.current === label) return;
37
+ prev.current = label;
38
+ const nk = keyRef.current++;
39
+ const nextW = ghostRef.current?.offsetWidth;
40
+
41
+ setWords((ws) => ws.concat({ key: nk, label, cls: 'zc-badge__word--in' }));
42
+ const raf = requestAnimationFrame(() =>
43
+ requestAnimationFrame(() => {
44
+ setWords((ws) => ws.map((w) => (w.key === nk ? { ...w, cls: '' } : { ...w, cls: 'zc-badge__word--out' })));
45
+ if (nextW) setBoxW(nextW);
46
+ }),
47
+ );
48
+ const drop = setTimeout(
49
+ () => setWords((ws) => ws.filter((w) => !w.cls.includes('--out'))),
50
+ UIMotion.dur.base * 1000 + DROP_GRACE_MS,
51
+ );
52
+
53
+ return () => {
54
+ cancelAnimationFrame(raf);
55
+ clearTimeout(drop);
56
+ };
57
+ }, [label]);
58
+
59
+ return (
60
+ <span className="zc-badge__morph" style={boxW ? { width: boxW } : undefined}>
61
+ <span className="zc-badge__ghost" ref={ghostRef} aria-hidden="true">
62
+ {label}
63
+ </span>
64
+ {words.map((w) => (
65
+ <span key={w.key} className={cx('zc-badge__word', w.cls)}>
66
+ {w.label}
67
+ </span>
68
+ ))}
69
+ </span>
70
+ );
71
+ }
@@ -0,0 +1,16 @@
1
+ 'use client';
2
+
3
+ import { useEffect, useRef, type RefObject } from 'react';
4
+
5
+ import { fireGlint } from '../../internal/glass/glint';
6
+
7
+ export function useGlintOnChange(ref: RefObject<HTMLElement | null>, value: string, enabled: boolean) {
8
+ const prev = useRef(value);
9
+
10
+ useEffect(() => {
11
+ if (prev.current === value) return;
12
+ prev.current = value;
13
+ if (!enabled || !ref.current) return;
14
+ return fireGlint(ref.current);
15
+ }, [ref, value, enabled]);
16
+ }
@@ -30,8 +30,8 @@ interface OtpFieldOwnProps {
30
30
  error?: boolean;
31
31
  /** Disable every slot. */
32
32
  disabled?: boolean;
33
- /** Compact slot sizing. Only `sm`; omit for default. */
34
- size?: 'sm';
33
+ /** Slot width, height and digit type. @default 'md' */
34
+ size?: 'sm' | 'md';
35
35
  /** Extra class(es) appended to the root wrapper. */
36
36
  className?: string;
37
37
  /** Inline styles merged onto the root wrapper. */
@@ -50,7 +50,7 @@ export function OtpField({
50
50
  group,
51
51
  error,
52
52
  disabled,
53
- size,
53
+ size = 'md',
54
54
  className = '',
55
55
  style,
56
56
  htmlProps,
@@ -77,6 +77,14 @@ export function OtpField({
77
77
  caretEnd(el);
78
78
  }
79
79
  };
80
+ const fill = (i: number, digits: string) => {
81
+ if (!digits) return;
82
+ const start = Math.max(0, Math.min(i, length - digits.length));
83
+ const a = chars.slice();
84
+ for (let k = 0; k < digits.length && start + k < length; k++) a[start + k] = digits[k];
85
+ emit(a.join(''));
86
+ go(Math.min(start + digits.length, length - 1));
87
+ };
80
88
 
81
89
  const cls = cx('zc-otp', size === 'sm' && 'zc-otp--sm', error && 'zc-is-error', className);
82
90
 
@@ -102,9 +110,11 @@ export function OtpField({
102
110
  go(i);
103
111
  }}
104
112
  onChange={(e: ChangeEvent<HTMLInputElement>) => {
105
- const ch = e.target.value.replace(/[^\d]/g, '').slice(-1);
106
- setAt(i, ch);
107
- if (ch && i < length - 1) go(i + 1);
113
+ const digits = e.target.value.replace(/[^\d]/g, '');
114
+ if (!digits) return setAt(i, '');
115
+ const prev = chars[i].trim();
116
+ const added = prev && digits.startsWith(prev) ? digits.slice(prev.length) : digits;
117
+ fill(i, added || prev);
108
118
  }}
109
119
  onKeyDown={(e: KeyboardEvent<HTMLInputElement>) => {
110
120
  if (e.key === 'Backspace' && !chars[i].trim() && i > 0) {
@@ -121,9 +131,7 @@ export function OtpField({
121
131
  }}
122
132
  onPaste={(e: ClipboardEvent<HTMLInputElement>) => {
123
133
  e.preventDefault();
124
- const d = (e.clipboardData.getData('text') || '').replace(/[^\d]/g, '');
125
- emit(chars.slice(0, i).join('') + d);
126
- refs.current[Math.min(i + d.length, length - 1)]?.focus();
134
+ fill(i, (e.clipboardData.getData('text') || '').replace(/[^\d]/g, ''));
127
135
  }}
128
136
  />,
129
137
  );
@@ -7,6 +7,7 @@
7
7
  --radio-group-dot: 18px;
8
8
  --radio-group-dot-gap: 4px;
9
9
  --radio-group-dot-inner: calc(var(--radio-group-dot) - 2 * (var(--border-hairline) + var(--radio-group-dot-gap)));
10
+ --radio-group-hover-wash: color-mix(in oklab, var(--neutral-wash) 60%, transparent);
10
11
 
11
12
  display: grid;
12
13
  border: 0;
@@ -89,7 +90,7 @@
89
90
  left: 0;
90
91
  z-index: 0;
91
92
  border-radius: var(--radius-md);
92
- background: var(--neutral-wash);
93
+ background: var(--radio-group-hover-wash);
93
94
  pointer-events: none;
94
95
  }
95
96
  .zc-rg-opt__control,
@@ -211,6 +212,9 @@
211
212
  transform var(--duration-fast) var(--ease-standard);
212
213
  outline: var(--ring-rest);
213
214
  }
215
+ .zc-rg--cards .zc-rg-opt.zc-is-selected {
216
+ z-index: 1;
217
+ }
214
218
  .zc-rg--cards .zc-rg-opt:active:not(.zc-is-disabled) {
215
219
  transform: translateY(var(--space-px));
216
220
  box-shadow: var(--shadow-xs);
@@ -235,15 +239,15 @@
235
239
 
236
240
  inset: calc(-1 * var(--border-hairline));
237
241
  z-index: 1;
238
- border: var(--border-hairline) solid var(--accent);
242
+ border: var(--border-hairline) solid var(--accent-border);
239
243
  border-radius: var(--radius-lg);
240
- background: var(--accent-subtle);
244
+ background: var(--accent-wash);
241
245
  pointer-events: none;
242
246
  }
243
247
 
244
248
  .zc-rg--cards .zc-rg-opt:hover:not(.zc-is-disabled):not(.zc-is-selected) {
245
249
  border-color: var(--border-strong);
246
- background: var(--neutral-wash);
250
+ background: var(--radio-group-hover-wash);
247
251
  }
248
252
  .zc-rg--cards .zc-rg-opt > .zc-rg-opt__icon,
249
253
  .zc-rg--cards .zc-rg-opt > .zc-rg-opt__control,
@@ -16,6 +16,7 @@ import {
16
16
 
17
17
  import type { DataAttributes } from '../../../dom-props';
18
18
  import { cx } from '../../internal/utils/cx';
19
+ import { Collapse } from '../collapse/Collapse';
19
20
  import {
20
21
  FieldLabel,
21
22
  FieldMessage,
@@ -24,8 +25,7 @@ import {
24
25
  resolveFieldMessage,
25
26
  type FieldMessagingProps,
26
27
  } from '../input/field-chrome';
27
-
28
- const RING_C = (2 * Math.PI * 7).toFixed(2);
28
+ import { CharMeter } from './char-meter';
29
29
 
30
30
  type TextareaNative = Pick<
31
31
  TextareaHTMLAttributes<HTMLTextAreaElement>,
@@ -49,8 +49,8 @@ interface TextareaOwnProps extends FieldMessagingProps, TextareaNative {
49
49
  warnAt?: number;
50
50
  /** Footer hint, left of the meter - e.g. a ⌘↵ affordance. */
51
51
  hint?: ReactNode;
52
- /** md (default) - lg (prominent composer). */
53
- size?: 'md' | 'lg';
52
+ /** Field type and padding: `sm` for a dense form row, `lg` for a prominent composer. @default 'md' */
53
+ size?: 'sm' | 'md' | 'lg';
54
54
  /** Extra class(es) merged onto the field root. */
55
55
  className?: string;
56
56
  /** Inline styles merged onto the field root. */
@@ -81,7 +81,7 @@ export function Textarea({
81
81
  maxRows = 10,
82
82
  warnAt = 20,
83
83
  hint,
84
- size,
84
+ size = 'md',
85
85
  disabled,
86
86
  readOnly,
87
87
  className = '',
@@ -94,8 +94,9 @@ export function Textarea({
94
94
  const text = value ?? '';
95
95
  const count = text.length;
96
96
  const over = max ? Math.max(count - max, 0) : 0;
97
- const remaining = max ? max - count : 0;
98
- const meterState = over ? 'zc-is-over' : max && remaining <= warnAt ? 'zc-is-near' : '';
97
+ const lastMax = useRef(max);
98
+ if (max) lastMax.current = max;
99
+ const meterMax = max ?? lastMax.current;
99
100
 
100
101
  const { state, msg, msgIcon } = resolveFieldMessage(error, warning, success, helper);
101
102
  const autoId = useId();
@@ -140,7 +141,13 @@ export function Textarea({
140
141
  onKeyDown?.(e);
141
142
  };
142
143
 
143
- const cls = cx('zc-fld', 'zc-fld--txa', size === 'lg' && 'zc-fld--lg', state, className);
144
+ const cls = cx(
145
+ 'zc-fld',
146
+ 'zc-fld--txa',
147
+ size === 'sm' ? 'zc-fld--sm' : size === 'lg' ? 'zc-fld--lg' : '',
148
+ state,
149
+ className,
150
+ );
144
151
  const boxCls = cx('zc-txa', disabled && 'zc-is-disabled', readOnly && 'zc-is-readonly');
145
152
 
146
153
  return (
@@ -173,25 +180,14 @@ export function Textarea({
173
180
  aria-describedby={joinIds(msgId, htmlProps?.['aria-describedby'])}
174
181
  />
175
182
  </div>
176
- {(max || hint) && (
183
+ <Collapse open={!!(max || hint)}>
177
184
  <div className="zc-txa__bar">
178
185
  {hint && <span className="zc-txa__hint">{hint}</span>}
179
- {max && (
180
- <span className={cx('zc-txa__meter', meterState)}>
181
- <span className="zc-txa__count">{over || remaining <= warnAt ? remaining : `${count} / ${max}`}</span>
182
- <svg
183
- className="zc-txa__ring"
184
- viewBox="0 0 16 16"
185
- aria-hidden="true"
186
- style={{ '--txa-ring-c': RING_C, '--txa-ring-p': Math.min(count / max, 1) } as CSSProperties}
187
- >
188
- <circle className="zc-txa__ring-trk" cx="8" cy="8" r="7" />
189
- <circle className="zc-txa__ring-prg" cx="8" cy="8" r="7" />
190
- </svg>
191
- </span>
192
- )}
186
+ <Collapse open={!!max} axis="width" fade className="zc-txa__meter-slot">
187
+ {meterMax ? <CharMeter count={count} max={meterMax} warnAt={warnAt} /> : null}
188
+ </Collapse>
193
189
  </div>
194
- )}
190
+ </Collapse>
195
191
  </div>
196
192
  <FieldMessage id={msgId} message={msg} icon={msgIcon} />
197
193
  </div>
@@ -0,0 +1,34 @@
1
+ 'use client';
2
+
3
+ import type { CSSProperties } from 'react';
4
+
5
+ import { cx } from '../../internal/utils/cx';
6
+
7
+ const RING_C = (2 * Math.PI * 7).toFixed(2);
8
+
9
+ export interface CharMeterProps {
10
+ count: number;
11
+ max: number;
12
+ warnAt: number;
13
+ }
14
+
15
+ export function CharMeter({ count, max, warnAt }: CharMeterProps) {
16
+ const over = Math.max(count - max, 0);
17
+ const remaining = max - count;
18
+ const state = over ? 'zc-is-over' : remaining <= warnAt ? 'zc-is-near' : '';
19
+
20
+ return (
21
+ <span className={cx('zc-txa__meter', state)}>
22
+ <span className="zc-txa__count">{over || remaining <= warnAt ? remaining : `${count} / ${max}`}</span>
23
+ <svg
24
+ className="zc-txa__ring"
25
+ viewBox="0 0 16 16"
26
+ aria-hidden="true"
27
+ style={{ '--txa-ring-c': RING_C, '--txa-ring-p': Math.min(count / max, 1) } as CSSProperties}
28
+ >
29
+ <circle className="zc-txa__ring-trk" cx="8" cy="8" r="7" />
30
+ <circle className="zc-txa__ring-prg" cx="8" cy="8" r="7" />
31
+ </svg>
32
+ </span>
33
+ );
34
+ }
@@ -119,9 +119,11 @@
119
119
  white-space: nowrap;
120
120
  }
121
121
 
122
- .zc-txa__meter {
122
+ .zc-txa__meter-slot {
123
123
  margin-left: auto;
124
124
  flex: none;
125
+ }
126
+ .zc-txa__meter {
125
127
  display: inline-flex;
126
128
  align-items: center;
127
129
  gap: var(--space-2);
@@ -199,6 +201,16 @@
199
201
  outline: var(--ring-success);
200
202
  }
201
203
 
204
+ .zc-fld--txa.zc-fld--sm .zc-txa {
205
+ --txa-pad-y: var(--space-2);
206
+ --txa-pad-x: var(--space-3);
207
+ --txa-lh: var(--leading-caption);
208
+ }
209
+ .zc-fld--txa.zc-fld--sm .zc-txa__input,
210
+ .zc-fld--txa.zc-fld--sm .zc-txa__mirror {
211
+ font: var(--type-caption);
212
+ }
213
+
202
214
  .zc-fld--txa.zc-fld--lg .zc-txa {
203
215
  --txa-pad-y: var(--space-4);
204
216
  --txa-lh: var(--leading-body-lg);
@@ -14,6 +14,7 @@ import {
14
14
  import type { DataAttributes } from '../../../dom-props';
15
15
  import { useControllable } from '../../internal/hooks/use-controllable';
16
16
  import { cx } from '../../internal/utils/cx';
17
+ import { SwitchGlyph } from './switch-glyph';
17
18
 
18
19
  interface ToggleOwnProps {
19
20
  /** Controlled checked state. Omit for uncontrolled (use `defaultChecked`). */
@@ -78,24 +79,14 @@ export function Toggle({
78
79
  onPointerLeave={press(false)}
79
80
  onPointerCancel={press(false)}
80
81
  >
81
- <input
82
- type="checkbox"
83
- role="switch"
84
- className="zc-sw__input"
82
+ <SwitchGlyph
83
+ pressed={pressed}
85
84
  disabled={disabled}
86
85
  checked={isOn}
87
86
  onChange={handleChange}
88
87
  {...htmlProps}
89
88
  defaultChecked={undefined}
90
89
  />
91
- <span
92
- className="zc-sw__track"
93
- data-on={isOn ? 'true' : undefined}
94
- data-pressed={pressed ? 'true' : undefined}
95
- aria-hidden="true"
96
- >
97
- <span className="zc-sw__thumb"></span>
98
- </span>
99
90
  {label || description ? (
100
91
  <span className="zc-sw__text">
101
92
  {label ? <span className="zc-sw__label">{label}</span> : null}
@@ -0,0 +1,25 @@
1
+ 'use client';
2
+
3
+ import './toggle.css';
4
+
5
+ import { Fragment, type InputHTMLAttributes } from 'react';
6
+
7
+ export interface SwitchGlyphProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'type'> {
8
+ pressed?: boolean;
9
+ }
10
+
11
+ export function SwitchGlyph({ pressed = false, ...inputProps }: SwitchGlyphProps) {
12
+ return (
13
+ <Fragment>
14
+ <input type="checkbox" role="switch" className="zc-sw__input" {...inputProps} />
15
+ <span
16
+ className="zc-sw__track"
17
+ data-on={inputProps.checked ? 'true' : undefined}
18
+ data-pressed={pressed ? 'true' : undefined}
19
+ aria-hidden="true"
20
+ >
21
+ <span className="zc-sw__thumb"></span>
22
+ </span>
23
+ </Fragment>
24
+ );
25
+ }
@@ -60,7 +60,11 @@ export function flip(el: HTMLElement, from: Box, options: FlipOptions = {}): Pla
60
60
  const dx = from.left - to.left + pivot.x * (sx - 1);
61
61
  const dy = from.top - to.top + pivot.y * (sy - 1);
62
62
 
63
- const timing = { ...options.timing, fill: 'none' as const };
63
+ const holdsStartThroughDelay = (options.timing?.delay ?? 0) > 0;
64
+ const timing: Timing = {
65
+ ...options.timing,
66
+ fill: options.timing?.fill ?? (holdsStartThroughDelay ? 'backwards' : 'none'),
67
+ };
64
68
  const layers: Layer[] = [{ x: [dx, 0], y: [dy, 0], timing, composite: 'add' }];
65
69
  if (scaling)
66
70
  layers.push({
@@ -0,0 +1,97 @@
1
+ import { animate, measure, type Box, type FlipOptions, type Playback } from '../engine';
2
+ import { claim } from '../engine/animate';
3
+ import { sharedSlot } from '../shared-slot';
4
+ import { inheritedThemeAttrs } from '../theme-scope';
5
+
6
+ const SHOWN_BY = 0.45;
7
+ const GONE_BY = 0.5;
8
+
9
+ interface Copy {
10
+ el: HTMLElement;
11
+ box: Box;
12
+ of: HTMLElement;
13
+ play?: Playback;
14
+ }
15
+
16
+ const kept = sharedSlot('motion.crossfade@2', () => new Map<string, Copy>());
17
+ const riding = new WeakMap<HTMLElement, Copy>();
18
+
19
+ function onto(el: HTMLElement, box: Box, target: Box): { x: number; y: number; scale: number } {
20
+ const [px, py] = getComputedStyle(el).transformOrigin.split(' ').map(parseFloat);
21
+ const scale = target.width / box.width;
22
+ return {
23
+ x: target.left - box.left + (target.width - box.width) / 2 + (box.width / 2 - px) * (1 - scale),
24
+ y: target.top - box.top + (target.height - box.height) / 2 + (box.height / 2 - py) * (1 - scale),
25
+ scale,
26
+ };
27
+ }
28
+
29
+ export function keep(id: string, el: HTMLElement, box: Box, { timing }: FlipOptions): void {
30
+ const copy = el.cloneNode(true) as HTMLElement;
31
+ for (const node of [copy, ...copy.querySelectorAll('[id]')]) node.removeAttribute('id');
32
+ for (const [name, value] of Object.entries(inheritedThemeAttrs(el))) if (value) copy.setAttribute(name, value);
33
+ const { font, color, opacity } = getComputedStyle(el);
34
+ Object.assign(copy.style, {
35
+ position: 'fixed',
36
+ left: `${box.left - window.scrollX}px`,
37
+ top: `${box.top - window.scrollY}px`,
38
+ width: `${box.width}px`,
39
+ height: `${box.height}px`,
40
+ boxSizing: 'border-box',
41
+ margin: '0',
42
+ pointerEvents: 'none',
43
+ translate: 'none',
44
+ scale: 'none',
45
+ transform: 'none',
46
+ font,
47
+ color,
48
+ opacity,
49
+ });
50
+ copy.inert = true;
51
+ copy.setAttribute('aria-hidden', 'true');
52
+ document.body.append(copy);
53
+ const entry: Copy = { el: copy, box, of: el };
54
+ kept.set(id, entry);
55
+ queueMicrotask(() => {
56
+ if (kept.get(id) !== entry) return;
57
+ kept.delete(id);
58
+ if (el.isConnected) copy.remove();
59
+ else animate(copy, { opacity: [0], timing }).finished.then(() => copy.remove());
60
+ });
61
+ }
62
+
63
+ export function play(id: string, el: HTMLElement, from: Box, { timing }: FlipOptions): Playback | undefined {
64
+ const next = kept.get(id);
65
+ if (!next) return undefined;
66
+ const replay = next.of === el;
67
+ const copy = replay ? riding.get(el) : next;
68
+ if (!copy) return undefined;
69
+ claim(el, ['translate', 'scale', 'opacity'], null);
70
+ const to = measure(el);
71
+ if (!to.width || !to.height) return undefined;
72
+ kept.delete(id);
73
+ if (replay) next.el.remove();
74
+ copy.play?.stop();
75
+ const rest = Number(getComputedStyle(el).opacity);
76
+ const out = onto(copy.el, copy.box, to);
77
+ const back = onto(el, to, from);
78
+ const run = animate(copy.el, {
79
+ x: [0, out.x],
80
+ y: [0, out.y],
81
+ scale: [1, out.scale],
82
+ opacity: [Number(copy.el.style.opacity), 0, 0],
83
+ timing: { fill: 'backwards', ...timing, times: [0, GONE_BY, 1] },
84
+ });
85
+ copy.play = run;
86
+ riding.set(el, copy);
87
+ run.finished.then(() => {
88
+ if (copy.play === run) copy.el.remove();
89
+ });
90
+ return animate(el, {
91
+ x: [back.x, 0],
92
+ y: [back.y, 0],
93
+ scale: [back.scale, 1],
94
+ opacity: [0, rest, rest],
95
+ timing: { fill: 'backwards', ...timing, times: [0, SHOWN_BY, 1] },
96
+ });
97
+ }
@@ -1,16 +1,17 @@
1
1
  'use client';
2
2
 
3
- import { createElement, useCallback, useRef, type ReactNode, type Ref } from 'react';
3
+ import { createElement, useCallback, useLayoutEffect, useRef, type ReactNode, type Ref } from 'react';
4
4
 
5
5
  import { useFlip, type FlipTuning } from './flip';
6
+ import { usePresence } from './presence-context';
6
7
  import { useMotion, type MotionSpecs } from './use-motion';
7
8
 
8
9
  export interface MotionProps extends MotionSpecs {
9
10
  /** Tag for the element this renders. @default 'div' */
10
11
  as?: string;
11
- /** FLIP this element from its previous box on every render. Implied by `layoutId`. */
12
+ /** FLIP this element from its previous box whenever a render moves it. */
12
13
  layout?: boolean;
13
- /** FLIP from whatever element last held this id, so the box travels between nodes. */
14
+ /** FLIP from whatever element last held this id, so the box travels between nodes. Add `layout` to FLIP its own moves too. */
14
15
  layoutId?: string;
15
16
  /** Tunes whichever layout animation is active; ignored without `layout` or `layoutId`. */
16
17
  layoutTransition?: FlipTuning;
@@ -32,23 +33,25 @@ export function Motion({
32
33
  children,
33
34
  ...rest
34
35
  }: MotionProps) {
35
- const flipRef = useFlip<HTMLElement>(layoutId ?? null, layoutTransition, !!layoutId || !!layout);
36
+ const { isPresent } = usePresence();
37
+ const flip = useFlip<HTMLElement>(layoutId ?? null, layoutTransition, !!layout);
36
38
  const host = useRef<HTMLElement | null>(null);
37
39
  const forwarded = useRef(ref);
38
40
  forwarded.current = ref;
39
41
 
40
42
  useMotion(host, { animate, exit, initial, deps });
43
+ useLayoutEffect(flip.play);
41
44
 
42
45
  const attach = useCallback(
43
46
  (el: HTMLElement | null) => {
44
47
  host.current = el;
45
- flipRef.current = el;
48
+ flip.ref.current = el;
46
49
  const outer = forwarded.current;
47
50
  if (typeof outer === 'function') outer(el);
48
51
  else if (outer) outer.current = el;
49
52
  },
50
- [flipRef],
53
+ [flip.ref],
51
54
  );
52
55
 
53
- return createElement(as, { ...rest, ref: attach }, children);
56
+ return createElement(as, { ...rest, 'data-exiting': isPresent ? undefined : 'true', ref: attach }, children);
54
57
  }