@zyncat/ui 0.17.0 → 0.18.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 (140) hide show
  1. package/README.md +6 -6
  2. package/dist/alert.js +6 -6
  3. package/dist/button.css +20 -10
  4. package/dist/button.js +2 -1
  5. package/dist/{chunk-5W5TKANX.js → chunk-2DNKZ57E.js} +3 -3
  6. package/dist/{chunk-5W5TKANX.js.map → chunk-2DNKZ57E.js.map} +1 -1
  7. package/dist/{chunk-ZHMOH62S.js → chunk-6H3IJ752.js} +22 -7
  8. package/dist/chunk-6H3IJ752.js.map +1 -0
  9. package/dist/{chunk-WC45VSST.js → chunk-AIAPXRCI.js} +19 -18
  10. package/dist/chunk-AIAPXRCI.js.map +1 -0
  11. package/dist/{chunk-3MLUH2QL.js → chunk-BRKGYLEQ.js} +12 -9
  12. package/dist/chunk-BRKGYLEQ.js.map +1 -0
  13. package/dist/{chunk-RY35IU3G.js → chunk-C3D32LE3.js} +6 -5
  14. package/dist/chunk-C3D32LE3.js.map +1 -0
  15. package/dist/{chunk-GZ6UMHCK.js → chunk-F2TB3TT6.js} +4 -4
  16. package/dist/{chunk-GZ6UMHCK.js.map → chunk-F2TB3TT6.js.map} +1 -1
  17. package/dist/{chunk-4PQDVK23.js → chunk-F64Z42PJ.js} +6 -6
  18. package/dist/{chunk-4PQDVK23.js.map → chunk-F64Z42PJ.js.map} +1 -1
  19. package/dist/{chunk-EOWWVFBF.js → chunk-HBWRKEW4.js} +3 -3
  20. package/dist/{chunk-EOWWVFBF.js.map → chunk-HBWRKEW4.js.map} +1 -1
  21. package/dist/{chunk-M2A6PZ7J.js → chunk-JINATP4N.js} +13 -13
  22. package/dist/chunk-JINATP4N.js.map +1 -0
  23. package/dist/{chunk-7VTWJL72.js → chunk-M2KGLH2G.js} +8 -8
  24. package/dist/{chunk-7VTWJL72.js.map → chunk-M2KGLH2G.js.map} +1 -1
  25. package/dist/{chunk-DH7DT6EO.js → chunk-N43NDSME.js} +3 -3
  26. package/dist/{chunk-DH7DT6EO.js.map → chunk-N43NDSME.js.map} +1 -1
  27. package/dist/{chunk-7ZSIUUC3.js → chunk-PXQBJMPJ.js} +4 -4
  28. package/dist/{chunk-7ZSIUUC3.js.map → chunk-PXQBJMPJ.js.map} +1 -1
  29. package/dist/{chunk-FLDIRXFU.js → chunk-RJENXXTI.js} +5 -5
  30. package/dist/{chunk-FLDIRXFU.js.map → chunk-RJENXXTI.js.map} +1 -1
  31. package/dist/chunk-RLNCRDAL.js +89 -0
  32. package/dist/chunk-RLNCRDAL.js.map +1 -0
  33. package/dist/{chunk-WZUTBJC4.js → chunk-TDHLZY6I.js} +23 -5
  34. package/dist/chunk-TDHLZY6I.js.map +1 -0
  35. package/dist/chunk-TP2AC5MQ.js +13 -0
  36. package/dist/chunk-TP2AC5MQ.js.map +1 -0
  37. package/dist/{chunk-WQKWPI6V.js → chunk-TRPAKUIB.js} +6 -6
  38. package/dist/{chunk-WQKWPI6V.js.map → chunk-TRPAKUIB.js.map} +1 -1
  39. package/dist/{chunk-GWCBTD63.js → chunk-V6QAAOA5.js} +3 -3
  40. package/dist/{chunk-GWCBTD63.js.map → chunk-V6QAAOA5.js.map} +1 -1
  41. package/dist/{chunk-6IXLW7QA.js → chunk-VJXP256V.js} +10 -10
  42. package/dist/chunk-VJXP256V.js.map +1 -0
  43. package/dist/{chunk-IUQAUBVM.js → chunk-VQFILXQN.js} +5 -5
  44. package/dist/chunk-VQFILXQN.js.map +1 -0
  45. package/dist/{chunk-HWDIVGME.js → chunk-XKDR22VE.js} +3 -3
  46. package/dist/{chunk-HWDIVGME.js.map → chunk-XKDR22VE.js.map} +1 -1
  47. package/dist/cli.js +3 -2
  48. package/dist/confetti.js +2 -2
  49. package/dist/date-field.js +15 -15
  50. package/dist/date-range-field.js +16 -16
  51. package/dist/datetime-field.js +15 -15
  52. package/dist/dialog.js +10 -10
  53. package/dist/dialog.js.map +1 -1
  54. package/dist/dropdown.js +14 -14
  55. package/dist/dropdown.js.map +1 -1
  56. package/dist/emoji-picker.js +37 -22
  57. package/dist/emoji-picker.js.map +1 -1
  58. package/dist/flow-field.js +2 -2
  59. package/dist/glide.js +3 -3
  60. package/dist/instagram-feed.js +2 -2
  61. package/dist/lens.js +2 -2
  62. package/dist/modal.js +10 -10
  63. package/dist/modal.js.map +1 -1
  64. package/dist/morphing-text.js +2 -2
  65. package/dist/motion-devtools.js +3 -3
  66. package/dist/motion-tokens.js +1 -1
  67. package/dist/multi-select.js +10 -10
  68. package/dist/odometer.js +2 -2
  69. package/dist/pagination.js +3 -3
  70. package/dist/popover.js +10 -10
  71. package/dist/radio-group.js +5 -5
  72. package/dist/select.js +10 -10
  73. package/dist/sheet.js +9 -9
  74. package/dist/status-badge.js +2 -2
  75. package/dist/support-rail.js +9 -9
  76. package/dist/table.js +5 -5
  77. package/dist/tabs.js +17 -11
  78. package/dist/tabs.js.map +1 -1
  79. package/dist/tag.js +6 -6
  80. package/dist/theme-grid.js +6 -6
  81. package/dist/theme-switcher.js +14 -14
  82. package/dist/{theme-transition-LLC644ZR.js → theme-transition-VGLPZDJI.js} +4 -4
  83. package/dist/{theme-transition-LLC644ZR.js.map → theme-transition-VGLPZDJI.js.map} +1 -1
  84. package/dist/theme.js +3 -3
  85. package/dist/theme.js.map +1 -1
  86. package/dist/tiktok.js +2 -2
  87. package/dist/toast.js +8 -8
  88. package/dist/tooltip.js +25 -22
  89. package/dist/tooltip.js.map +1 -1
  90. package/dist/types/components/internal/hooks/use-press-feedback.d.ts +7 -0
  91. package/dist/types/components/internal/overlay/layer.d.ts +7 -1
  92. package/dist/types/components/internal/utils/token-px.d.ts +1 -1
  93. package/dist/types/motion/motion-timing.d.ts +1 -1
  94. package/dist/types/tokens/motion-tokens.d.ts +5 -3
  95. package/dist/types/tokens/theme-tokens.generated.d.ts +6 -8
  96. package/dist/typing-lines.js +2 -2
  97. package/dist/typing-lines.js.map +1 -1
  98. package/dist/youtube.js +2 -2
  99. package/package.json +12 -10
  100. package/skills/zyncat-ui/SKILL.md +1 -1
  101. package/skills/zyncat-ui/references/components.md +1 -1
  102. package/skills/zyncat-ui/references/theming.md +31 -23
  103. package/src/components/composites/dialog/Dialog.tsx +2 -2
  104. package/src/components/composites/dropdown/Dropdown.tsx +5 -5
  105. package/src/components/composites/emoji-picker/react/category-bar.tsx +17 -5
  106. package/src/components/composites/emoji-picker/scaffold.ts +6 -5
  107. package/src/components/composites/modal/Modal.tsx +2 -2
  108. package/src/components/composites/popover/Popover.tsx +5 -5
  109. package/src/components/composites/select/core/menu.tsx +15 -10
  110. package/src/components/composites/sheet/Sheet.tsx +2 -2
  111. package/src/components/composites/tabs/Tabs.tsx +13 -7
  112. package/src/components/composites/tooltip/tooltip-host.tsx +19 -17
  113. package/src/components/expressive/typing-lines/TypingLines.tsx +0 -0
  114. package/src/components/internal/hooks/use-press-feedback.ts +52 -0
  115. package/src/components/internal/overlay/layer.tsx +35 -2
  116. package/src/components/internal/overlay/position.ts +2 -2
  117. package/src/components/internal/utils/token-px.ts +4 -4
  118. package/src/components/primitives/button/Button.tsx +18 -3
  119. package/src/components/primitives/button/button.css +20 -10
  120. package/src/motion/glide.tsx +9 -6
  121. package/src/motion/motion-timing.ts +5 -2
  122. package/src/styles.css +0 -1
  123. package/src/tokens/decisions.css +4 -4
  124. package/src/tokens/motion-tokens.ts +26 -7
  125. package/src/tokens/semantic.css +3 -5
  126. package/src/tokens/theme-tokens.generated.ts +6 -8
  127. package/tailwind.css +1 -1
  128. package/dist/chunk-3MLUH2QL.js.map +0 -1
  129. package/dist/chunk-6IXLW7QA.js.map +0 -1
  130. package/dist/chunk-IUQAUBVM.js.map +0 -1
  131. package/dist/chunk-LH2UIEKN.js +0 -42
  132. package/dist/chunk-LH2UIEKN.js.map +0 -1
  133. package/dist/chunk-M2A6PZ7J.js.map +0 -1
  134. package/dist/chunk-RY35IU3G.js.map +0 -1
  135. package/dist/chunk-UE63OOVG.js +0 -13
  136. package/dist/chunk-UE63OOVG.js.map +0 -1
  137. package/dist/chunk-WC45VSST.js.map +0 -1
  138. package/dist/chunk-WZUTBJC4.js.map +0 -1
  139. package/dist/chunk-ZHMOH62S.js.map +0 -1
  140. package/src/tokens/fonts.css +0 -1
@@ -67,7 +67,7 @@ export function Modal({
67
67
  const autoId = useId();
68
68
  const panelId = id || 'modal-' + autoId;
69
69
  const close = () => setOpen(false);
70
- const timings = resolveMotionTiming(animation, OV_TAKEOVER_TIMING);
70
+ const timings = resolveMotionTiming(animation, OV_TAKEOVER_TIMING, container ?? triggerRef.current);
71
71
 
72
72
  return (
73
73
  <Fragment>
@@ -79,7 +79,7 @@ export function Modal({
79
79
  triggerRef,
80
80
  activateOn,
81
81
  })}
82
- <OverlayPortal container={container}>
82
+ <OverlayPortal container={container} scope={triggerRef.current}>
83
83
  <Presence>
84
84
  {open && (
85
85
  <ModalShell
@@ -10,7 +10,7 @@ import { Presence } from '../../../motion/presence';
10
10
  import { popIn, popOut } from '../../../motion/presets';
11
11
  import type { DisableableAnimation } from '../../../motion/timing';
12
12
  import { useMotion, type MotionSpecs } from '../../../motion/use-motion';
13
- import { UIMotion } from '../../../tokens/motion-tokens';
13
+ import { motionFor } from '../../../tokens/motion-tokens';
14
14
  import { useControllable } from '../../internal/hooks/use-controllable';
15
15
  import { useReturnFocus } from '../../internal/overlay/focus';
16
16
  import { ovCloneTrigger, OverlayPortal, useOutsidePress, useOverlayEntry } from '../../internal/overlay/layer';
@@ -126,7 +126,7 @@ export function Popover({
126
126
  const autoId = useId();
127
127
  const panelId = id || 'popover-' + autoId;
128
128
  const close = () => setOpen(false);
129
- const timings = resolveMotionTiming(animation, POPOVER_TIMING);
129
+ const timings = resolveMotionTiming(animation, POPOVER_TIMING, triggerRef.current);
130
130
 
131
131
  return (
132
132
  <Fragment>
@@ -138,13 +138,13 @@ export function Popover({
138
138
  triggerRef,
139
139
  activateOn,
140
140
  })}
141
- <OverlayPortal>
141
+ <OverlayPortal scope={triggerRef.current}>
142
142
  <Presence>
143
143
  {open && (
144
144
  <PopoverPanel
145
145
  key="panel"
146
- animate={popIn(UIMotion.scale.floating, timings.open)}
147
- exit={popOut(UIMotion.scale.floating, timings.close)}
146
+ animate={popIn(motionFor(triggerRef.current).scale.floating, timings.open)}
147
+ exit={popOut(motionFor(triggerRef.current).scale.floating, timings.close)}
148
148
  panelId={panelId}
149
149
  side={side}
150
150
  align={align}
@@ -7,7 +7,7 @@ import { resolveMotionTiming } from '../../../../motion/motion-timing';
7
7
  import { Presence } from '../../../../motion/presence';
8
8
  import type { DisableableAnimation } from '../../../../motion/timing';
9
9
  import { useMotion, type MotionSpecs } from '../../../../motion/use-motion';
10
- import { UIMotion, type MotionTransition } from '../../../../tokens/motion-tokens';
10
+ import { motionFor, type MotionTransition } from '../../../../tokens/motion-tokens';
11
11
  import { menuHighlightAttrs, type MenuHighlightProps } from '../../../internal/menu/highlight';
12
12
  import { OverlayPortal, useOutsidePress, useOverlayEntry } from '../../../internal/overlay/layer';
13
13
  import { useAnchorPosition } from '../../../internal/overlay/position';
@@ -17,17 +17,22 @@ const SELECT_MENU_TIMING = {
17
17
  close: { duration: 'base', ease: 'exit' },
18
18
  } as const;
19
19
 
20
- function selectMenuLayers(animation: DisableableAnimation | undefined, dir: 'open' | 'close'): Layer[] {
21
- const t = resolveMotionTiming(animation, SELECT_MENU_TIMING)[dir];
22
- const fade = (d: MotionTransition) => ({ duration: d.duration === 0 ? 0 : UIMotion.dur.fast, ease: d.ease });
23
- const drop = -UIMotion.dist.sm;
20
+ function selectMenuLayers(
21
+ animation: DisableableAnimation | undefined,
22
+ dir: 'open' | 'close',
23
+ scope?: Element | null,
24
+ ): Layer[] {
25
+ const motion = motionFor(scope);
26
+ const t = resolveMotionTiming(animation, SELECT_MENU_TIMING, scope)[dir];
27
+ const fade = (d: MotionTransition) => ({ duration: d.duration === 0 ? 0 : motion.dur.fast, ease: d.ease });
28
+ const drop = -motion.dist.sm;
24
29
  return dir === 'open'
25
30
  ? [
26
- { y: [drop, 0], scale: [UIMotion.scale.floating, 1], timing: t },
31
+ { y: [drop, 0], scale: [motion.scale.floating, 1], timing: t },
27
32
  { opacity: [0, 1], timing: fade(t) },
28
33
  ]
29
34
  : [
30
- { y: [drop], scale: [UIMotion.scale.floating], timing: t },
35
+ { y: [drop], scale: [motion.scale.floating], timing: t },
31
36
  { opacity: [0], timing: fade(t) },
32
37
  ];
33
38
  }
@@ -94,13 +99,13 @@ export function SelectMenu({
94
99
  children,
95
100
  }: SelectMenuProps) {
96
101
  return (
97
- <OverlayPortal>
102
+ <OverlayPortal scope={triggerRef.current}>
98
103
  <Presence>
99
104
  {open && (
100
105
  <MenuSurface
101
106
  key="menu"
102
- animate={selectMenuLayers(animation, 'open')}
103
- exit={selectMenuLayers(animation, 'close')}
107
+ animate={selectMenuLayers(animation, 'open', triggerRef.current)}
108
+ exit={selectMenuLayers(animation, 'close', triggerRef.current)}
104
109
  menuId={menuId}
105
110
  requestClose={requestClose}
106
111
  triggerRef={triggerRef}
@@ -116,7 +116,7 @@ export function Sheet({
116
116
  const autoId = useId();
117
117
  const panelId = id || 'sheet-' + autoId;
118
118
  const close = () => setOpen(false);
119
- const timings = resolveMotionTiming(animation, SHEET_TIMING);
119
+ const timings = resolveMotionTiming(animation, SHEET_TIMING, container ?? triggerRef.current);
120
120
  const axis = side === 'bottom' ? 'y' : 'x';
121
121
 
122
122
  return (
@@ -129,7 +129,7 @@ export function Sheet({
129
129
  triggerRef,
130
130
  activateOn,
131
131
  })}
132
- <OverlayPortal container={container}>
132
+ <OverlayPortal container={container} scope={triggerRef.current}>
133
133
  <Presence>
134
134
  {open && (
135
135
  <SheetShell
@@ -18,14 +18,12 @@ import { Motion } from '../../../motion/element';
18
18
  import { GlidePill, useGlide } from '../../../motion/glide';
19
19
  import { resolveMotionTiming } from '../../../motion/motion-timing';
20
20
  import { type DisableableAnimation } from '../../../motion/timing';
21
- import { UIMotion } from '../../../tokens/motion-tokens';
21
+ import { motionFor } from '../../../tokens/motion-tokens';
22
22
  import { useScrollEdges } from '../../internal/hooks/use-scroll-edges';
23
23
  import { IconSlot } from '../../internal/icon/IconSlot';
24
24
  import { activationProps, type ActivateOn } from '../../internal/utils/activation';
25
25
  import { cx } from '../../internal/utils/cx';
26
26
 
27
- const SM = UIMotion;
28
-
29
27
  /** One tab in the row. */
30
28
  export interface TabItem {
31
29
  /** Stable identity - also used in the tab/panel id pair. */
@@ -109,7 +107,9 @@ export function Tabs({
109
107
  const next = { x: el.offsetLeft, w: el.offsetWidth };
110
108
  ink.style.opacity = '1';
111
109
 
112
- if (!animated || !placedRef.current || SM.reduced) {
110
+ const motion = motionFor(list);
111
+
112
+ if (!animated || !placedRef.current || motion.reduced) {
113
113
  set(ink, { x: [next.x], width: [next.w] });
114
114
  } else {
115
115
  const lr = list.getBoundingClientRect();
@@ -122,7 +122,11 @@ export function Tabs({
122
122
  animate(ink, {
123
123
  x: [cur.x, lead, next.x],
124
124
  width: [cur.w, span, next.w],
125
- timing: { duration: SM.dur.slow, times: [0, 0.55, 1], ease: [SM.ease.standard, SM.ease.entrance] },
125
+ timing: {
126
+ duration: motion.dur.slow,
127
+ times: [0, 0.55, 1],
128
+ ease: [motion.ease.standard, motion.ease.entrance],
129
+ },
126
130
  });
127
131
  }
128
132
  }
@@ -138,7 +142,7 @@ export function Tabs({
138
142
  const l = listRef.current,
139
143
  el = value != null ? tabRefs.current[value] : null;
140
144
  if (l && el && l.scrollWidth > l.clientWidth) {
141
- const behavior: ScrollBehavior = SM.reduced ? 'auto' : 'smooth';
145
+ const behavior: ScrollBehavior = motionFor(l).reduced ? 'auto' : 'smooth';
142
146
  if (el.offsetLeft < l.scrollLeft + TABS_EDGE_PAD) {
143
147
  l.scrollTo({ left: el.offsetLeft - TABS_EDGE_PAD, behavior });
144
148
  } else if (el.offsetLeft + el.offsetWidth > l.scrollLeft + l.clientWidth - TABS_EDGE_PAD) {
@@ -263,10 +267,12 @@ const TABPANEL_TIMING = {
263
267
  } as const;
264
268
 
265
269
  export function TabPanel({ tab, name, dir = 0, className = '', style, children, animation, htmlProps }: TabPanelProps) {
266
- const enter = resolveMotionTiming(animation, TABPANEL_TIMING).open;
270
+ const panelRef = useRef<HTMLElement>(null);
271
+ const enter = resolveMotionTiming(animation, TABPANEL_TIMING, panelRef.current).open;
267
272
 
268
273
  return (
269
274
  <Motion
275
+ ref={panelRef}
270
276
  layout
271
277
  layoutTransition={{ size: 'morph', timing: enter }}
272
278
  role="tabpanel"
@@ -6,12 +6,12 @@ import { createPortal } from 'react-dom';
6
6
  import { Motion } from '../../../motion/element';
7
7
  import { Presence } from '../../../motion/presence';
8
8
  import { popIn, popOut } from '../../../motion/presets';
9
- import { UIMotion } from '../../../tokens/motion-tokens';
9
+ import { motionFor } from '../../../tokens/motion-tokens';
10
+ import { inheritedThemeAttrs } from '../../internal/overlay/layer';
10
11
  import { tokenPx } from '../../internal/utils/token-px';
11
12
  import { store, TOOLTIP_DOM_ID, type ActivePayload, type Placement } from './tooltip-store';
12
13
 
13
- const SM = UIMotion;
14
- const TIP_LAYOUT = { size: 'morph' as const, timing: UIMotion.t.layout };
14
+ const tipLayout = (scope?: Element | null) => ({ size: 'morph' as const, timing: motionFor(scope).t.layout });
15
15
 
16
16
  interface Size {
17
17
  w: number;
@@ -26,10 +26,10 @@ interface RenderedBox extends TargetBox {
26
26
  bodyW: number;
27
27
  }
28
28
 
29
- function targetBox(size: Size, t: DOMRect, want: Placement): TargetBox {
29
+ function targetBox(size: Size, t: DOMRect, want: Placement, scope?: Element | null): TargetBox {
30
30
  const vw = window.innerWidth,
31
31
  vh = window.innerHeight,
32
- TIP_GAP = tokenPx('--space-2', 8) || 8,
32
+ TIP_GAP = tokenPx('--space-2', 8, scope) || 8,
33
33
  M = TIP_GAP;
34
34
  let p = want;
35
35
  if (p === 'top' && t.top - size.h - TIP_GAP < M) p = 'bottom';
@@ -61,10 +61,10 @@ function targetBox(size: Size, t: DOMRect, want: Placement): TargetBox {
61
61
 
62
62
  const surface = () => document.getElementById(TOOLTIP_DOM_ID);
63
63
 
64
- const fromEdge = (p: Placement) => ({
65
- x: p === 'left' ? SM.dist.sm : p === 'right' ? -SM.dist.sm : 0,
66
- y: p === 'top' ? SM.dist.sm : p === 'bottom' ? -SM.dist.sm : 0,
67
- });
64
+ const fromEdge = (p: Placement, scope?: Element | null) => {
65
+ const { sm } = motionFor(scope).dist;
66
+ return { x: p === 'left' ? sm : p === 'right' ? -sm : 0, y: p === 'top' ? sm : p === 'bottom' ? -sm : 0 };
67
+ };
68
68
 
69
69
  function Body({ a, width }: { a: ActivePayload; width?: number }) {
70
70
  return (
@@ -82,26 +82,28 @@ function Body({ a, width }: { a: ActivePayload; width?: number }) {
82
82
  }
83
83
 
84
84
  function TipSurface({ a, box }: { a: ActivePayload; box: RenderedBox }) {
85
- const edge = fromEdge(box.placement);
85
+ const motion = motionFor(a.anchor());
86
+ const edge = fromEdge(box.placement, a.anchor());
86
87
  return (
87
88
  <Motion
88
89
  layout
89
- layoutTransition={TIP_LAYOUT}
90
+ layoutTransition={tipLayout(a.anchor())}
90
91
  className="zc-tooltip"
92
+ {...inheritedThemeAttrs(a.anchor())}
91
93
  id={TOOLTIP_DOM_ID}
92
94
  role="tooltip"
93
95
  data-placement={box.placement}
94
96
  style={{ translate: `${box.x}px ${box.y}px`, width: box.w, height: box.h }}
95
97
  animate={[
96
- { x: [edge.x, 0], y: [edge.y, 0], timing: { ...SM.t.layout, fill: 'none' }, composite: 'add' },
97
- popIn(SM.scale.floating, SM.t.enter),
98
+ { x: [edge.x, 0], y: [edge.y, 0], timing: { ...motion.t.layout, fill: 'none' }, composite: 'add' },
99
+ popIn(motion.scale.floating, motion.t.enter),
98
100
  ]}
99
101
  exit={[
100
- { x: [0, edge.x], y: [0, edge.y], timing: SM.t.exit, composite: 'add' },
101
- popOut(SM.scale.floating, SM.t.exit),
102
+ { x: [0, edge.x], y: [0, edge.y], timing: motion.t.exit, composite: 'add' },
103
+ popOut(motion.scale.floating, motion.t.exit),
102
104
  ]}
103
105
  >
104
- <Motion as="span" key={a.id} animate={{ opacity: [0, 1], timing: SM.t.enter }}>
106
+ <Motion as="span" key={a.id} animate={{ opacity: [0, 1], timing: motion.t.enter }}>
105
107
  <Body a={a} width={box.bodyW} />
106
108
  </Motion>
107
109
  </Motion>
@@ -131,7 +133,7 @@ export function TooltipHost() {
131
133
  if (!from.width && !from.height) return;
132
134
  if (!surface()) drift.current = { x: 0, y: 0 };
133
135
  anchored.current = { x: from.left, y: from.top };
134
- const to = targetBox({ w: Math.ceil(bubble.width), h: Math.ceil(bubble.height) }, from, active.placement);
136
+ const to = targetBox({ w: Math.ceil(bubble.width), h: Math.ceil(bubble.height) }, from, active.placement, anchor);
135
137
  setShown({
136
138
  a: active,
137
139
  box: { ...to, x: to.x - drift.current.x, y: to.y - drift.current.y, bodyW: Math.ceil(body.width) },
@@ -0,0 +1,52 @@
1
+ 'use client';
2
+
3
+ import { useCallback, useEffect, useRef, useState, type PointerEvent } from 'react';
4
+
5
+ import { motionFor } from '../../../tokens/motion-tokens';
6
+
7
+ export interface PressFeedback {
8
+ pressed: boolean;
9
+ onPointerDown: (event: PointerEvent<HTMLElement>) => void;
10
+ onPointerLeave: () => void;
11
+ }
12
+
13
+ export function usePressFeedback(inert: boolean): PressFeedback {
14
+ const [pressed, setPressed] = useState(false);
15
+ const holdUntil = useRef(0);
16
+ const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
17
+ const listeners = useRef<AbortController | undefined>(undefined);
18
+
19
+ const release = useCallback(() => {
20
+ listeners.current?.abort();
21
+ listeners.current = undefined;
22
+ clearTimeout(timer.current);
23
+ const remaining = holdUntil.current - Date.now();
24
+ if (remaining > 0) timer.current = setTimeout(() => setPressed(false), remaining);
25
+ else setPressed(false);
26
+ }, []);
27
+
28
+ useEffect(
29
+ () => () => {
30
+ listeners.current?.abort();
31
+ clearTimeout(timer.current);
32
+ },
33
+ [],
34
+ );
35
+
36
+ const onPointerDown = useCallback(
37
+ (event: PointerEvent<HTMLElement>) => {
38
+ if (inert) return;
39
+ listeners.current?.abort();
40
+ clearTimeout(timer.current);
41
+ holdUntil.current = Date.now() + motionFor(event.currentTarget).dur.fast * 1000;
42
+ setPressed(true);
43
+ const controller = new AbortController();
44
+ listeners.current = controller;
45
+ addEventListener('pointerup', release, { signal: controller.signal });
46
+ addEventListener('pointercancel', release, { signal: controller.signal });
47
+ },
48
+ [inert, release],
49
+ );
50
+
51
+ return { pressed, onPointerDown, onPointerLeave: release };
52
+ }
@@ -171,10 +171,43 @@ function useHydrated() {
171
171
  );
172
172
  }
173
173
 
174
- function OverlayPortal({ container, children }: { container?: HTMLElement | null; children: ReactNode }) {
174
+ const ovNearestTheme = (el: Element | null | undefined, attr: string): string | null =>
175
+ el?.closest(`[${attr}]`)?.getAttribute(attr) ?? null;
176
+
177
+ const ovThemeDifferingFromPage = (scope: Element | null | undefined, attr: string): string | undefined => {
178
+ const own = ovNearestTheme(scope, attr);
179
+ return own !== null && own !== ovNearestTheme(document.body, attr) ? own : undefined;
180
+ };
181
+
182
+ export interface InheritedThemeAttrs {
183
+ 'data-theme'?: string;
184
+ 'data-polarity'?: string;
185
+ }
186
+
187
+ export function inheritedThemeAttrs(scope: Element | null | undefined): InheritedThemeAttrs {
188
+ return {
189
+ 'data-theme': ovThemeDifferingFromPage(scope, 'data-theme'),
190
+ 'data-polarity': ovThemeDifferingFromPage(scope, 'data-polarity'),
191
+ };
192
+ }
193
+
194
+ function OverlayPortal({
195
+ container,
196
+ scope,
197
+ children,
198
+ }: {
199
+ container?: HTMLElement | null;
200
+ scope?: Element | null;
201
+ children: ReactNode;
202
+ }) {
175
203
  const hydrated = useHydrated();
176
204
  if (!hydrated) return null;
177
- return createPortal(<div data-overlay-root="">{children}</div>, container ?? document.body);
205
+ return createPortal(
206
+ <div data-overlay-root="" {...inheritedThemeAttrs(scope)}>
207
+ {children}
208
+ </div>,
209
+ container ?? document.body,
210
+ );
178
211
  }
179
212
 
180
213
  export { ovIsTop, ovInOverlayAbove, useOverlayEntry, useOutsidePress, ovCloneTrigger, OverlayPortal };
@@ -30,9 +30,9 @@ export function useAnchorPosition({ side, align, arrow, anchor, triggerRef, pane
30
30
  const pw = p.offsetWidth;
31
31
  const ph = p.offsetHeight;
32
32
 
33
- const edge = tokenPx('--space-2');
33
+ const edge = tokenPx('--space-2', 0, p);
34
34
 
35
- const gap = arrow ? tokenPx('--space-2') + 3 : 0;
35
+ const gap = arrow ? tokenPx('--space-2', 0, p) + 3 : 0;
36
36
 
37
37
  const vw = window.innerWidth;
38
38
  const vh = window.innerHeight;
@@ -1,8 +1,8 @@
1
- export function tokenPx(token: string, fallback = 0): number {
1
+ export function tokenPx(token: string, fallback = 0, scope?: Element | null): number {
2
2
  if (typeof document === 'undefined') return fallback;
3
- const root = document.documentElement;
4
- const v = getComputedStyle(root).getPropertyValue(token).trim();
3
+ const el = scope ?? document.documentElement;
4
+ const v = getComputedStyle(el).getPropertyValue(token).trim();
5
5
  const n = parseFloat(v);
6
6
  if (Number.isNaN(n)) return fallback;
7
- return v.endsWith('rem') ? n * parseFloat(getComputedStyle(root).fontSize) : n;
7
+ return v.endsWith('rem') ? n * parseFloat(getComputedStyle(document.documentElement).fontSize) : n;
8
8
  }
@@ -1,6 +1,9 @@
1
+ 'use client';
2
+
1
3
  import type { ButtonHTMLAttributes, CSSProperties, ReactNode, Ref } from 'react';
2
4
 
3
5
  import type { DataAttributes } from '../../../dom-props';
6
+ import { usePressFeedback } from '../../internal/hooks/use-press-feedback';
4
7
  import { cx } from '../../internal/utils/cx';
5
8
  import { Spinner } from '../spinner/Spinner';
6
9
  import { buttonClass, type ButtonSize, type ButtonVariant } from './button-style';
@@ -34,6 +37,13 @@ interface ButtonOwnProps {
34
37
 
35
38
  type ButtonRestProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, keyof ButtonOwnProps> & DataAttributes;
36
39
 
40
+ const chain =
41
+ <E,>(theirs: ((event: E) => void) | undefined, mine: (event: E) => void) =>
42
+ (event: E) => {
43
+ mine(event);
44
+ theirs?.(event);
45
+ };
46
+
37
47
  export interface ButtonProps extends ButtonOwnProps, ButtonRestProps {
38
48
  /** Standard <button> attributes (onClick, name, form, aria-*, data-*, ...) forwarded verbatim.
39
49
  * Bare `<button>` attributes also pass through directly; `htmlProps` wins on conflict. */
@@ -54,7 +64,10 @@ export function Button({
54
64
  htmlProps,
55
65
  ...rest
56
66
  }: ButtonProps) {
67
+ const inert = disabled || loading;
68
+ const press = usePressFeedback(inert);
57
69
  const cls = cx(buttonClass({ variant, size, fullWidth, className }), loading && 'zc-is-loading');
70
+ const merged = { ...rest, ...htmlProps };
58
71
 
59
72
  return (
60
73
  <button
@@ -62,10 +75,12 @@ export function Button({
62
75
  ref={ref}
63
76
  className={cls}
64
77
  style={style}
65
- disabled={disabled || loading}
78
+ disabled={inert}
66
79
  aria-busy={loading || undefined}
67
- {...rest}
68
- {...htmlProps}
80
+ {...merged}
81
+ data-pressed={press.pressed ? 'true' : undefined}
82
+ onPointerDown={chain(merged.onPointerDown, press.onPointerDown)}
83
+ onPointerLeave={chain(merged.onPointerLeave, press.onPointerLeave)}
69
84
  >
70
85
  <span className="zc-btn__label">{children}</span>
71
86
  {loading ? <Spinner label={null} className="zc-btn__spinner" /> : null}
@@ -17,6 +17,7 @@
17
17
  --btn-ring: var(--ring-accent);
18
18
  --btn-gap: var(--space-2);
19
19
  --btn-press-scale: 0.96;
20
+ --btn-press-timing: var(--duration-base) var(--ease-spring);
20
21
 
21
22
  position: relative;
22
23
  isolation: isolate;
@@ -54,7 +55,7 @@
54
55
  color var(--duration-fast) var(--ease-standard),
55
56
  box-shadow var(--duration-fast) var(--ease-standard),
56
57
  outline-color var(--duration-fast) var(--ease-standard),
57
- transform var(--duration-slow) var(--ease-standard);
58
+ transform var(--btn-press-timing);
58
59
  outline: var(--ring-rest);
59
60
  }
60
61
 
@@ -62,7 +63,9 @@
62
63
  outline: var(--btn-ring);
63
64
  }
64
65
 
65
- .zc-btn:active:not(:disabled):not(.zc-is-loading) {
66
+ .zc-btn:active:not(:disabled):not(.zc-is-loading),
67
+ .zc-btn[data-pressed] {
68
+ --btn-press-timing: var(--duration-fast) var(--ease-standard);
66
69
  transform: scale(var(--btn-press-scale));
67
70
  }
68
71
 
@@ -128,7 +131,8 @@
128
131
  inset 0 1px 0 0 rgb(255 255 255 / calc(0.36 * var(--sheen-strength))),
129
132
  inset 0 -1px 0 0 rgb(var(--shadow-rgb) / 0.18), var(--shadow-md), var(--glow-accent);
130
133
  }
131
- .zc-btn--primary:active:not(:disabled):not(.zc-is-loading) {
134
+ .zc-btn--primary:active:not(:disabled):not(.zc-is-loading),
135
+ .zc-btn--primary[data-pressed]:not(:disabled):not(.zc-is-loading) {
132
136
  --btn-grad-a: color-mix(in oklab, var(--accent-hover) 70%, var(--accent-active));
133
137
  --btn-grad-b: var(--accent-fill);
134
138
  }
@@ -150,7 +154,8 @@
150
154
  --btn-grad-a: color-mix(in oklab, var(--text-secondary) 3%, var(--btn-face-lit));
151
155
  --btn-grad-b: color-mix(in oklab, var(--text-secondary) 3%, var(--btn-face-shade));
152
156
  }
153
- .zc-btn--secondary:active:not(:disabled):not(.zc-is-loading) {
157
+ .zc-btn--secondary:active:not(:disabled):not(.zc-is-loading),
158
+ .zc-btn--secondary[data-pressed]:not(:disabled):not(.zc-is-loading) {
154
159
  --btn-grad-a: color-mix(in oklab, var(--text-secondary) 5%, var(--btn-face-lit));
155
160
  --btn-grad-b: color-mix(in oklab, var(--text-secondary) 5%, var(--btn-face-shade));
156
161
  --btn-shadow: inset 0 1px 2px 0 rgb(var(--shadow-rgb) / 0.06);
@@ -176,11 +181,13 @@
176
181
  .zc-btn--ghost:hover:not(:disabled):not(.zc-is-loading) {
177
182
  color: var(--text-strong);
178
183
  }
179
- .zc-btn--ghost:hover:not(:disabled):not(.zc-is-loading)::before {
184
+ .zc-btn--ghost:hover:not(:disabled):not(.zc-is-loading)::before,
185
+ .zc-btn--ghost[data-pressed]::before {
180
186
  opacity: 1;
181
187
  transform: scale(1);
182
188
  }
183
- .zc-btn--ghost:active:not(:disabled):not(.zc-is-loading)::before {
189
+ .zc-btn--ghost:active:not(:disabled):not(.zc-is-loading)::before,
190
+ .zc-btn--ghost[data-pressed]:not(:disabled):not(.zc-is-loading)::before {
184
191
  background: var(--neutral-wash-press);
185
192
  }
186
193
 
@@ -201,7 +208,8 @@
201
208
  inset 0 1px 0 0 rgb(255 255 255 / calc(0.36 * var(--sheen-strength))),
202
209
  inset 0 -1px 0 0 rgb(var(--shadow-rgb) / 0.18), var(--shadow-md), var(--glow-danger);
203
210
  }
204
- .zc-btn--danger:active:not(:disabled):not(.zc-is-loading) {
211
+ .zc-btn--danger:active:not(:disabled):not(.zc-is-loading),
212
+ .zc-btn--danger[data-pressed]:not(:disabled):not(.zc-is-loading) {
205
213
  --btn-grad-a: color-mix(in oklab, var(--danger) 70%, var(--danger-active));
206
214
  --btn-grad-b: var(--danger-fill);
207
215
  --btn-shadow: inset 0 1px 2px 0 rgb(var(--shadow-rgb) / 0.16), 0 1px 1px 0 rgb(var(--shadow-rgb) / 0.08);
@@ -222,7 +230,8 @@
222
230
  text-decoration: underline;
223
231
  text-underline-offset: var(--space-px);
224
232
  }
225
- .zc-btn--link:active:not(:disabled):not(.zc-is-loading) {
233
+ .zc-btn--link:active:not(:disabled):not(.zc-is-loading),
234
+ .zc-btn--link[data-pressed]:not(:disabled):not(.zc-is-loading) {
226
235
  color: var(--accent-active);
227
236
  }
228
237
  .zc-btn--link:focus-visible {
@@ -234,7 +243,7 @@
234
243
  .zc-btn.zc-is-loading {
235
244
  cursor: default;
236
245
  }
237
- .zc-btn:disabled {
246
+ .zc-btn:disabled:not([data-pressed]) {
238
247
  transform: none;
239
248
  }
240
249
  .zc-btn--primary:disabled {
@@ -277,7 +286,8 @@
277
286
  }
278
287
 
279
288
  @media (prefers-reduced-motion: reduce) {
280
- .zc-btn:active:not(:disabled):not(.zc-is-loading) {
289
+ .zc-btn:active:not(:disabled):not(.zc-is-loading),
290
+ .zc-btn[data-pressed] {
281
291
  transform: none;
282
292
  }
283
293
  }
@@ -3,7 +3,7 @@
3
3
  import { useCallback, useMemo, useRef, type RefObject } from 'react';
4
4
 
5
5
  import { animate, flip, measure, set, type Box } from '../engine';
6
- import { UIMotion as SM } from '../tokens/motion-tokens';
6
+ import { motionFor } from '../tokens/motion-tokens';
7
7
 
8
8
  export type GlideApi = ReturnType<typeof useGlide>;
9
9
 
@@ -36,20 +36,23 @@ export function useGlide<T extends HTMLElement>(containerRef: RefObject<T | null
36
36
  if (!box || !pill || !target) return;
37
37
  const at = layoutBox(target, box);
38
38
  if (!at) return;
39
+ const motion = motionFor(box);
39
40
  const was = measure(pill);
40
41
  set(pill, { x: [at.left], y: [at.top], width: [at.width], height: [at.height] });
41
- animate(pill, { opacity: [1], timing: { duration: SM.dur.fast, ease: SM.ease.standard } });
42
- const glided = visible.current && !SM.reduced && was.width > 0 && was.height > 0;
42
+ animate(pill, { opacity: [1], timing: { duration: motion.dur.fast, ease: motion.ease.standard } });
43
+ const glided = visible.current && !motion.reduced && was.width > 0 && was.height > 0;
43
44
  visible.current = true;
44
- if (glided) flip(pill, was, { size: 'morph', timing: SM.t.glide });
45
+ if (glided) flip(pill, was, { size: 'morph', timing: motion.t.glide });
45
46
  },
46
47
  [containerRef],
47
48
  );
48
49
 
49
50
  const leave = useCallback(() => {
50
51
  visible.current = false;
51
- if (ref.current) animate(ref.current, { opacity: [0], timing: { duration: SM.dur.fast, ease: SM.ease.exit } });
52
- }, []);
52
+ if (!ref.current) return;
53
+ const motion = motionFor(containerRef.current);
54
+ animate(ref.current, { opacity: [0], timing: { duration: motion.dur.fast, ease: motion.ease.exit } });
55
+ }, [containerRef]);
53
56
 
54
57
  return useMemo(() => ({ ref, enter, leave }), [enter, leave]);
55
58
  }
@@ -1,5 +1,5 @@
1
1
  import type { DurationToken, EaseToken } from '../tokens/motion-scale';
2
- import { UIMotion, type MotionTransition } from '../tokens/motion-tokens';
2
+ import { motionFor, type MotionTransition } from '../tokens/motion-tokens';
3
3
  import { resolveDirection, type DisableableAnimation, type TimingDirection } from './timing';
4
4
 
5
5
  export interface DirectionDefault {
@@ -20,13 +20,16 @@ export interface MotionTimings {
20
20
  export function resolveMotionTiming(
21
21
  animation: DisableableAnimation | undefined,
22
22
  defaults: MotionTimingDefaults,
23
+ scope?: Element | null,
23
24
  ): MotionTimings {
24
25
  if (animation === null) return { open: { duration: 0 }, close: { duration: 0 } };
25
26
 
27
+ const motion = motionFor(scope);
28
+
26
29
  const build = (dir: TimingDirection): MotionTransition => {
27
30
  const durToken = (animation && resolveDirection(animation.duration, dir)) || defaults[dir].duration;
28
31
  const easeToken = (animation && resolveDirection(animation.ease, dir)) || defaults[dir].ease;
29
- return { duration: UIMotion.dur[durToken], ease: UIMotion.ease[easeToken] };
32
+ return { duration: motion.dur[durToken], ease: motion.ease[easeToken] };
30
33
  };
31
34
 
32
35
  return { open: build('open'), close: build('close') };
package/src/styles.css CHANGED
@@ -5,7 +5,6 @@
5
5
 
6
6
  @import './tokens/reset.css';
7
7
  @import './tokens/decisions.css';
8
- @import './tokens/fonts.css';
9
8
 
10
9
  @import './tokens/color.css';
11
10
  @import './tokens/typography.css';
@@ -15,9 +15,9 @@
15
15
  --neutral: var(--accent);
16
16
  /* Roundness - every --radius-<step> is a fixed ratio of it, 0 squaring every corner. */
17
17
  --radius: 0.5rem;
18
- /* The body face - every --type-* bundle follows. */
19
- --font-body: 'Geist', system-ui, -apple-system, 'Segoe UI', sans-serif;
20
- /* The code face - --type-code follows. */
21
- --font-code: 'Geist Mono', ui-monospace, 'SF Mono', 'Menlo', monospace;
18
+ /* The body face - every --type-* bundle follows. The package loads no webfont; point this at yours. */
19
+ --font-body: system-ui, -apple-system, 'Segoe UI', sans-serif;
20
+ /* The code face - --type-code follows. The package loads no webfont; point this at yours. */
21
+ --font-code: ui-monospace, 'SF Mono', 'Menlo', monospace;
22
22
  }
23
23
  }