@42-central/ui-react 0.20.1 → 0.22.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 (129) hide show
  1. package/dist/{chunk-45QRQKRC.js → chunk-3L5GLI67.js} +12 -8
  2. package/dist/chunk-3L5GLI67.js.map +1 -0
  3. package/dist/{chunk-BNWQ7IAZ.js → chunk-4FEOMQYR.js} +5 -5
  4. package/dist/{chunk-BNWQ7IAZ.js.map → chunk-4FEOMQYR.js.map} +1 -1
  5. package/dist/{chunk-POKLPMSB.js → chunk-D3JYDAUZ.js} +3 -3
  6. package/dist/{chunk-POKLPMSB.js.map → chunk-D3JYDAUZ.js.map} +1 -1
  7. package/dist/{chunk-KMZENCEP.js → chunk-DHJB4UJD.js} +4 -4
  8. package/dist/{chunk-KMZENCEP.js.map → chunk-DHJB4UJD.js.map} +1 -1
  9. package/dist/{chunk-IOYZC7SA.js → chunk-DJAXXLN6.js} +3 -3
  10. package/dist/{chunk-IOYZC7SA.js.map → chunk-DJAXXLN6.js.map} +1 -1
  11. package/dist/{chunk-3BXKTWWD.js → chunk-FB2G4LNH.js} +5 -5
  12. package/dist/{chunk-3BXKTWWD.js.map → chunk-FB2G4LNH.js.map} +1 -1
  13. package/dist/{chunk-E63VD25L.js → chunk-HQPU73WV.js} +4 -4
  14. package/dist/{chunk-E63VD25L.js.map → chunk-HQPU73WV.js.map} +1 -1
  15. package/dist/{chunk-RCF7HTG5.js → chunk-IRNF274I.js} +5 -5
  16. package/dist/chunk-IRNF274I.js.map +1 -0
  17. package/dist/{chunk-O5W3QWJ6.js → chunk-J44FJ7PH.js} +3 -3
  18. package/dist/{chunk-O5W3QWJ6.js.map → chunk-J44FJ7PH.js.map} +1 -1
  19. package/dist/{chunk-TWLJQE75.js → chunk-MRAJ45IM.js} +4 -4
  20. package/dist/{chunk-TWLJQE75.js.map → chunk-MRAJ45IM.js.map} +1 -1
  21. package/dist/{chunk-5HUEBSIS.js → chunk-N66NC6QK.js} +120 -24
  22. package/dist/chunk-N66NC6QK.js.map +1 -0
  23. package/dist/{chunk-SXNAUSEB.js → chunk-OZMSXYBX.js} +4 -4
  24. package/dist/{chunk-SXNAUSEB.js.map → chunk-OZMSXYBX.js.map} +1 -1
  25. package/dist/{chunk-LBAE6FP6.js → chunk-SZEOTXRZ.js} +4 -4
  26. package/dist/{chunk-LBAE6FP6.js.map → chunk-SZEOTXRZ.js.map} +1 -1
  27. package/dist/chunk-V6PY7C6S.js +18 -0
  28. package/dist/chunk-V6PY7C6S.js.map +1 -0
  29. package/dist/{chunk-MKKQE3TM.js → chunk-YPFSRZ3T.js} +4 -4
  30. package/dist/{chunk-MKKQE3TM.js.map → chunk-YPFSRZ3T.js.map} +1 -1
  31. package/dist/{chunk-NJPHZBLI.js → chunk-YWTOW7PZ.js} +5 -5
  32. package/dist/{chunk-NJPHZBLI.js.map → chunk-YWTOW7PZ.js.map} +1 -1
  33. package/dist/{chunk-VTDBWU6H.js → chunk-YZJUPYPO.js} +3 -3
  34. package/dist/{chunk-VTDBWU6H.js.map → chunk-YZJUPYPO.js.map} +1 -1
  35. package/dist/components/autocomplete/index.js +4 -3
  36. package/dist/components/autocomplete/index.js.map +1 -1
  37. package/dist/components/calendar-heatmap/calendar-heatmap-grid.d.ts +94 -0
  38. package/dist/components/calendar-heatmap/calendar-heatmap-grid.d.ts.map +1 -0
  39. package/dist/components/calendar-heatmap/calendar-heatmap.d.ts +76 -0
  40. package/dist/components/calendar-heatmap/calendar-heatmap.d.ts.map +1 -0
  41. package/dist/components/calendar-heatmap/index.d.ts +2 -0
  42. package/dist/components/calendar-heatmap/index.d.ts.map +1 -0
  43. package/dist/components/calendar-heatmap/index.js +311 -0
  44. package/dist/components/calendar-heatmap/index.js.map +1 -0
  45. package/dist/components/camera/index.js +6 -5
  46. package/dist/components/clipboard/index.js +1 -1
  47. package/dist/components/code-block/chrome.js +4 -4
  48. package/dist/components/code-block/index.js +5 -5
  49. package/dist/components/combobox/index.js +4 -3
  50. package/dist/components/combobox-list/index.js +6 -5
  51. package/dist/components/data-table/index.js +16 -16
  52. package/dist/components/date-picker/index.js +7 -6
  53. package/dist/components/date-picker/index.js.map +1 -1
  54. package/dist/components/hover-card/hover-card.d.ts +44 -26
  55. package/dist/components/hover-card/hover-card.d.ts.map +1 -1
  56. package/dist/components/hover-card/index.js +35 -53
  57. package/dist/components/hover-card/index.js.map +1 -1
  58. package/dist/components/input/index.js +1 -1
  59. package/dist/components/input/input.d.ts.map +1 -1
  60. package/dist/components/menu/index.js +3 -3
  61. package/dist/components/menu/menu.d.ts +7 -5
  62. package/dist/components/menu/menu.d.ts.map +1 -1
  63. package/dist/components/multi-combobox-list/index.js +6 -5
  64. package/dist/components/multi-select/index.js +5 -4
  65. package/dist/components/multi-select/index.js.map +1 -1
  66. package/dist/components/navigation-progress/index.d.ts +2 -0
  67. package/dist/components/navigation-progress/index.d.ts.map +1 -0
  68. package/dist/components/navigation-progress/index.js +133 -0
  69. package/dist/components/navigation-progress/index.js.map +1 -0
  70. package/dist/components/navigation-progress/navigation-progress.d.ts +46 -0
  71. package/dist/components/navigation-progress/navigation-progress.d.ts.map +1 -0
  72. package/dist/components/number-input/index.js +4 -3
  73. package/dist/components/number-input/number-input.d.ts.map +1 -1
  74. package/dist/components/password-input/index.js +1 -1
  75. package/dist/components/photo-capture/index.js +6 -5
  76. package/dist/components/photo-capture/index.js.map +1 -1
  77. package/dist/components/pills-input/index.js +2 -2
  78. package/dist/components/pin-input/index.js +1 -1
  79. package/dist/components/popover/index.d.ts +1 -1
  80. package/dist/components/popover/index.d.ts.map +1 -1
  81. package/dist/components/popover/index.js +2 -1
  82. package/dist/components/popover/popover.d.ts +44 -29
  83. package/dist/components/popover/popover.d.ts.map +1 -1
  84. package/dist/components/schedule/index.js +2 -2
  85. package/dist/components/select/index.js +5 -4
  86. package/dist/components/spotlight/index.js +5 -4
  87. package/dist/components/spotlight/index.js.map +1 -1
  88. package/dist/components/tags-input/index.js +4 -3
  89. package/dist/components/tags-input/index.js.map +1 -1
  90. package/dist/components/text-input/index.js +1 -1
  91. package/dist/components/textarea/index.js +1 -1
  92. package/dist/components/time-input/index.js +5 -4
  93. package/dist/components/time-input/index.js.map +1 -1
  94. package/dist/components/tooltip/index.js +2 -2
  95. package/dist/components/tree-multi-select/index.js +5 -4
  96. package/dist/components/tree-multi-select/index.js.map +1 -1
  97. package/dist/components/tree-select/index.js +4 -3
  98. package/dist/components/tree-select/index.js.map +1 -1
  99. package/dist/index.js +2 -2
  100. package/dist/lib/placement.d.ts +42 -1
  101. package/dist/lib/placement.d.ts.map +1 -1
  102. package/dist/lib/slide-on-switch.d.ts +69 -0
  103. package/dist/lib/slide-on-switch.d.ts.map +1 -0
  104. package/package.json +1 -1
  105. package/src/as-child.contract.test.tsx +4 -0
  106. package/src/components/calendar-heatmap/calendar-heatmap-grid.test.ts +186 -0
  107. package/src/components/calendar-heatmap/calendar-heatmap-grid.ts +192 -0
  108. package/src/components/calendar-heatmap/calendar-heatmap.test.tsx +180 -0
  109. package/src/components/calendar-heatmap/calendar-heatmap.tsx +385 -0
  110. package/src/components/calendar-heatmap/index.ts +11 -0
  111. package/src/components/hover-card/hover-card.tsx +89 -167
  112. package/src/components/input/input.test.tsx +23 -0
  113. package/src/components/input/input.tsx +10 -6
  114. package/src/components/menu/menu.tsx +16 -9
  115. package/src/components/navigation-progress/index.ts +14 -0
  116. package/src/components/navigation-progress/navigation-progress.test.tsx +184 -0
  117. package/src/components/navigation-progress/navigation-progress.tsx +228 -0
  118. package/src/components/number-input/number-input.tsx +3 -4
  119. package/src/components/popover/index.ts +2 -0
  120. package/src/components/popover/popover.test.tsx +131 -0
  121. package/src/components/popover/popover.tsx +191 -53
  122. package/src/lib/placement.test.ts +37 -0
  123. package/src/lib/placement.ts +60 -1
  124. package/src/lib/slide-on-switch.ts +99 -0
  125. package/dist/chunk-45QRQKRC.js.map +0 -1
  126. package/dist/chunk-5HUEBSIS.js.map +0 -1
  127. package/dist/chunk-G52U24GR.js +0 -10
  128. package/dist/chunk-G52U24GR.js.map +0 -1
  129. package/dist/chunk-RCF7HTG5.js.map +0 -1
@@ -0,0 +1,184 @@
1
+ import { act, render } from "@testing-library/react"
2
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"
3
+ import {
4
+ COMPLETE_HOLD,
5
+ FADE_DURATION,
6
+ NavigationProgress,
7
+ type NavigationProgressProps,
8
+ TRICKLE_CAP,
9
+ TRICKLE_INTERVAL,
10
+ } from "./navigation-progress"
11
+
12
+ /**
13
+ * The bar is timer-driven, so every test runs on fake timers and advances
14
+ * them inside `act`. The fill is the root's only child; its `clip-path` reveal
15
+ * is the progress and its opacity class is the visibility.
16
+ */
17
+ type Extra = Omit<NavigationProgressProps, "loading" | "testId">
18
+
19
+ /** The progress, read back from the fill's `clip-path: inset(0 <100 - value>% 0 0)`. */
20
+ const revealed = (el: HTMLElement) => {
21
+ const right = /inset\(0(?:px)? ([\d.]+)%/.exec(el.style.clipPath)?.[1]
22
+ return 100 - Number.parseFloat(right ?? "100")
23
+ }
24
+
25
+ const setup = (loading: boolean, extra: Extra = {}) => {
26
+ const view = render(<NavigationProgress loading={loading} testId="np" {...extra} />)
27
+ const root = view.getByTestId("np")
28
+ const fill = () => root.firstElementChild as HTMLElement
29
+ return {
30
+ root,
31
+ fill,
32
+ width: () => revealed(fill()),
33
+ visible: () => fill().className.includes("opacity-100"),
34
+ rerender: (next: boolean) =>
35
+ view.rerender(<NavigationProgress loading={next} testId="np" {...extra} />),
36
+ }
37
+ }
38
+
39
+ const advance = (ms: number) => act(() => vi.advanceTimersByTime(ms))
40
+
41
+ const mockReducedMotion = (matches: boolean) => {
42
+ vi.spyOn(window, "matchMedia").mockImplementation(
43
+ (query: string) =>
44
+ ({
45
+ matches: matches && query.includes("prefers-reduced-motion"),
46
+ media: query,
47
+ onchange: null,
48
+ addEventListener: () => {},
49
+ removeEventListener: () => {},
50
+ addListener: () => {},
51
+ removeListener: () => {},
52
+ dispatchEvent: () => false,
53
+ }) as MediaQueryList,
54
+ )
55
+ }
56
+
57
+ describe("NavigationProgress", () => {
58
+ beforeEach(() => vi.useFakeTimers())
59
+ afterEach(() => {
60
+ vi.useRealTimers()
61
+ vi.restoreAllMocks()
62
+ })
63
+
64
+ it("is hidden and decorative at rest", () => {
65
+ const bar = setup(false)
66
+ expect(bar.visible()).toBe(false)
67
+ expect(bar.root.getAttribute("aria-hidden")).toBe("true")
68
+ expect(bar.root.getAttribute("data-state")).toBe("idle")
69
+ })
70
+
71
+ it("shows nothing for a load shorter than the delay", () => {
72
+ const bar = setup(true, { delay: 150 })
73
+ advance(100)
74
+ bar.rerender(false)
75
+ advance(2000)
76
+ expect(bar.visible()).toBe(false)
77
+ expect(bar.width()).toBe(0)
78
+ })
79
+
80
+ it("appears after the delay and trickles toward the cap without reaching it", () => {
81
+ const bar = setup(true, { delay: 150 })
82
+ advance(150)
83
+ expect(bar.visible()).toBe(true)
84
+ const first = bar.width()
85
+
86
+ advance(TRICKLE_INTERVAL * 5)
87
+ const later = bar.width()
88
+ expect(later).toBeGreaterThan(first)
89
+
90
+ advance(60_000)
91
+ expect(bar.width()).toBeLessThan(TRICKLE_CAP)
92
+ expect(bar.width()).toBeGreaterThan(TRICKLE_CAP - 1)
93
+ })
94
+
95
+ it("slows down as it fills", () => {
96
+ const bar = setup(true, { delay: 0 })
97
+ advance(0)
98
+ const a = bar.width()
99
+ advance(TRICKLE_INTERVAL)
100
+ const b = bar.width()
101
+ advance(TRICKLE_INTERVAL * 20)
102
+ const c = bar.width()
103
+ advance(TRICKLE_INTERVAL)
104
+ const d = bar.width()
105
+ expect(d - c).toBeLessThan(b - a)
106
+ })
107
+
108
+ it("completes to 100%, fades, then resets to 0", () => {
109
+ const bar = setup(true, { delay: 0 })
110
+ advance(TRICKLE_INTERVAL * 3)
111
+ bar.rerender(false)
112
+ expect(bar.width()).toBe(100)
113
+ expect(bar.visible()).toBe(true)
114
+ expect(bar.root.getAttribute("data-state")).toBe("complete")
115
+
116
+ advance(COMPLETE_HOLD)
117
+ expect(bar.visible()).toBe(false)
118
+ expect(bar.width()).toBe(100)
119
+
120
+ advance(FADE_DURATION)
121
+ expect(bar.width()).toBe(0)
122
+ expect(bar.root.getAttribute("data-state")).toBe("idle")
123
+ })
124
+
125
+ it("keeps going from where it is when loading resumes mid-run", () => {
126
+ const bar = setup(true, { delay: 0 })
127
+ advance(TRICKLE_INTERVAL * 5)
128
+ const before = bar.width()
129
+ bar.rerender(false)
130
+ bar.rerender(true)
131
+ // Caught at 100%: restarts from the sliver, without waiting for the delay.
132
+ expect(bar.visible()).toBe(true)
133
+ expect(bar.width()).toBeLessThan(before)
134
+ advance(TRICKLE_INTERVAL)
135
+ expect(bar.width()).toBeGreaterThan(0)
136
+ expect(bar.width()).toBeLessThan(100)
137
+ })
138
+
139
+ it("under reduced motion, sits full width without trickling and hides when done", () => {
140
+ mockReducedMotion(true)
141
+ const bar = setup(true, { delay: 0 })
142
+ advance(0)
143
+ expect(bar.width()).toBe(100)
144
+ advance(TRICKLE_INTERVAL * 5)
145
+ expect(bar.width()).toBe(100)
146
+
147
+ bar.rerender(false)
148
+ advance(0)
149
+ expect(bar.visible()).toBe(false)
150
+ advance(FADE_DURATION)
151
+ expect(bar.width()).toBe(0)
152
+ })
153
+ it("paints the palette through data-color by default", () => {
154
+ const bar = setup(false, { color: "green" })
155
+ expect(bar.root.getAttribute("data-color")).toBe("green")
156
+ expect(bar.fill().className).toContain("bg-(--c-solid)")
157
+ })
158
+
159
+ it("paints a full-width gradient from the gradient prop, ignoring color", () => {
160
+ const bar = setup(true, {
161
+ delay: 0,
162
+ variant: "gradient",
163
+ color: "green",
164
+ gradient: { from: "red", via: "gold", to: "blue", dir: "to-l" },
165
+ })
166
+ advance(TRICKLE_INTERVAL * 3)
167
+ const fill = bar.fill()
168
+ expect(bar.root.hasAttribute("data-color")).toBe(false)
169
+ expect(fill.className).toContain("bg-linear-to-l")
170
+ expect(fill.className).toContain("w-full")
171
+ expect(fill.style.getPropertyValue("--tw-gradient-from")).toBe("red")
172
+ expect(fill.style.getPropertyValue("--tw-gradient-via")).toBe("gold")
173
+ expect(fill.style.getPropertyValue("--tw-gradient-to")).toBe("blue")
174
+ // Progress is a reveal, not a resize, so the gradient never re-stretches.
175
+ expect(fill.style.width).toBe("")
176
+ expect(bar.width()).toBeGreaterThan(0)
177
+ })
178
+
179
+ it("falls back to the default stops and direction for a bare gradient", () => {
180
+ const bar = setup(false, { variant: "gradient" })
181
+ expect(bar.fill().className).toContain("from-purple-300")
182
+ expect(bar.fill().className).toContain("bg-linear-to-r")
183
+ })
184
+ })
@@ -0,0 +1,228 @@
1
+ "use client"
2
+
3
+ import { type CSSProperties, type Ref, useEffect, useRef, useState } from "react"
4
+ import { cn } from "../../lib/cn"
5
+ import type { Color } from "../../lib/colors"
6
+ import {
7
+ buildGradientVars,
8
+ GRADIENT_DIR_CLASS,
9
+ type GradientDir,
10
+ type GradientProps,
11
+ } from "../../lib/gradient"
12
+ import { useReducedMotion } from "../../lib/motion/reduced-motion"
13
+ import { props } from "../../lib/props"
14
+ import type { Size } from "../../lib/sizes"
15
+ import type { WithTestId } from "../../lib/test-id"
16
+
17
+ /**
18
+ * NavigationProgress — the thin bar pinned to the top of the viewport while a
19
+ * page loads, in the manner of nprogress / Mantine's `NavigationProgress`.
20
+ *
21
+ * It is driven by one boolean, `loading`, so it stays router-agnostic: wire it
22
+ * to whatever knows a navigation is in flight (TanStack Router's
23
+ * `useRouterState({ select: (s) => s.isLoading })`, Next's transitions, a
24
+ * fetch). The bar invents the progress itself, because no router knows how far
25
+ * along a loader is:
26
+ *
27
+ * - **delay**: nothing shows until `loading` has held for `delay` ms, so an
28
+ * instant navigation does not flash a bar.
29
+ * - **trickle**: the bar starts at a sliver and closes a fixed share of the
30
+ * remaining distance to `TRICKLE_CAP` on every tick. It moves quickly at
31
+ * first, then slows, and never reaches the end on its own.
32
+ * - **complete**: when `loading` drops, the bar runs to 100%, holds a beat,
33
+ * fades out, and only then snaps back to 0. The snap has its transition
34
+ * turned off, so the bar never visibly slides backwards.
35
+ * - **re-entry**: if `loading` comes back while the bar is still on screen,
36
+ * it keeps going from where it is. When it had already reached 100%, it
37
+ * restarts from the sliver.
38
+ *
39
+ * Under `prefers-reduced-motion` there is no trickle and no reveal transition.
40
+ * The bar sits at full width while loading and fades away when done.
41
+ *
42
+ * The fill is always full width and the progress is a `clip-path` revealing
43
+ * its left part. That is what makes `variant="gradient"` read right: the
44
+ * gradient spans the whole bar and stays put while the reveal grows, as in
45
+ * `Progress`, instead of being squeezed into, and re-stretched with, every
46
+ * trickle step.
47
+ *
48
+ * The bar is decorative (`aria-hidden`). It duplicates the page change itself,
49
+ * which is what assistive tech should announce, so it is not a
50
+ * `role="progressbar"` and does not wrap `Progress`. It reuses Progress's
51
+ * palette wiring instead: `data-color` plus the `--c-solid` slot var for
52
+ * `filled`, and the `--tw-gradient-*` vars for `gradient`.
53
+ */
54
+
55
+ /** Where a freshly shown bar starts, in percent. */
56
+ const START = 8
57
+ /** The trickle closes in on this value and never passes it. */
58
+ export const TRICKLE_CAP = 90
59
+ /** Share of the remaining distance to the cap closed on each tick. */
60
+ const TRICKLE_RATE = 0.1
61
+ /** ms between trickle ticks. The reveal transition runs this long too, so the
62
+ * steps read as one continuous motion. */
63
+ export const TRICKLE_INTERVAL = 200
64
+ /** ms the full bar stays visible before fading: the reveal run plus a beat. */
65
+ export const COMPLETE_HOLD = 400
66
+ /** ms of the fade-out. The reset to 0 waits for it. */
67
+ export const FADE_DURATION = 300
68
+
69
+ const HEIGHT: Record<Size, string> = {
70
+ xs: "h-0.5",
71
+ sm: "h-1",
72
+ md: "h-1.5",
73
+ lg: "h-2",
74
+ xl: "h-3",
75
+ }
76
+
77
+ export type NavigationProgressSize = Size
78
+ export type NavigationProgressVariant = "filled" | "gradient"
79
+
80
+ export type { GradientDir, GradientProps }
81
+
82
+ const FILL: Record<NavigationProgressVariant, string> = {
83
+ filled: "bg-(--c-solid)",
84
+ // from-*/to-* are the defaults; a `gradient` prop overrides the individual
85
+ // vars it sets. Same stops as Progress's gradient variant.
86
+ gradient: "from-purple-300 to-pink-400",
87
+ }
88
+
89
+ type BarState = {
90
+ value: number
91
+ visible: boolean
92
+ /** Whether the reveal animates. Off for the reset to 0 and the first
93
+ * paint of a new run. */
94
+ animate: boolean
95
+ }
96
+
97
+ const HIDDEN: BarState = { value: 0, visible: false, animate: false }
98
+
99
+ export type NavigationProgressProps = WithTestId & {
100
+ /** Whether a navigation is in flight. */
101
+ loading: boolean
102
+ /** ms `loading` must hold before the bar appears. @default 150 */
103
+ delay?: number
104
+ /** `filled` paints the `color` palette; `gradient` paints `gradient`'s
105
+ * stops across the whole bar. @default "filled" */
106
+ variant?: NavigationProgressVariant
107
+ /** Accent palette. Unset, the bar takes the kit's default solid. Ignored
108
+ * when `variant="gradient"`. */
109
+ color?: Color
110
+ /** Gradient stops and direction; only applied when `variant="gradient"`.
111
+ * Same shape as Badge's and Progress's. Unset fields fall back to
112
+ * purple-300 → pink-400, `to-r`. */
113
+ gradient?: GradientProps
114
+ /** Bar thickness. @default "xs" */
115
+ size?: NavigationProgressSize
116
+ ref?: Ref<HTMLDivElement>
117
+ /** On the fixed root. Override the positioning here to embed the bar
118
+ * somewhere other than the top of the viewport (`absolute`, …). */
119
+ className?: string
120
+ classNames?: { root?: string; bar?: string }
121
+ style?: CSSProperties
122
+ }
123
+
124
+ export const NavigationProgress = ({
125
+ loading,
126
+ delay = 150,
127
+ variant = "filled",
128
+ color,
129
+ gradient,
130
+ size = "xs",
131
+ ref,
132
+ className,
133
+ classNames,
134
+ style,
135
+ testId,
136
+ }: NavigationProgressProps) => {
137
+ const isGradient = variant === "gradient"
138
+ const reduced = useReducedMotion()
139
+ const [bar, setBar] = useState<BarState>(HIDDEN)
140
+ // Read inside the effect without re-running it on every trickle tick.
141
+ const barRef = useRef(bar)
142
+ barRef.current = bar
143
+
144
+ useEffect(() => {
145
+ const timers: ReturnType<typeof setTimeout>[] = []
146
+ const later = (fn: () => void, ms: number) => timers.push(setTimeout(fn, ms))
147
+ let interval: ReturnType<typeof setInterval> | undefined
148
+
149
+ if (loading) {
150
+ const run = () => {
151
+ if (reduced) {
152
+ setBar({ value: 100, visible: true, animate: false })
153
+ return
154
+ }
155
+ interval = setInterval(() => {
156
+ setBar((b) => ({
157
+ ...b,
158
+ value: b.value + (TRICKLE_CAP - b.value) * TRICKLE_RATE,
159
+ animate: true,
160
+ }))
161
+ }, TRICKLE_INTERVAL)
162
+ }
163
+
164
+ const current = barRef.current
165
+ if (current.visible && current.value < 100) {
166
+ // Still trickling (or a re-render mid-run): keep going from here.
167
+ run()
168
+ } else if (current.visible) {
169
+ // Caught mid-completion: restart from the sliver.
170
+ setBar({ value: START, visible: true, animate: false })
171
+ run()
172
+ } else {
173
+ later(() => {
174
+ setBar({ value: START, visible: true, animate: false })
175
+ run()
176
+ }, delay)
177
+ }
178
+ } else if (barRef.current.visible) {
179
+ setBar({ value: 100, visible: true, animate: !reduced })
180
+ later(
181
+ () => {
182
+ setBar((b) => ({ ...b, visible: false }))
183
+ later(() => setBar(HIDDEN), FADE_DURATION)
184
+ },
185
+ reduced ? 0 : COMPLETE_HOLD,
186
+ )
187
+ }
188
+
189
+ return () => {
190
+ for (const t of timers) clearTimeout(t)
191
+ clearInterval(interval)
192
+ }
193
+ }, [loading, delay, reduced])
194
+
195
+ return (
196
+ <div
197
+ ref={ref}
198
+ aria-hidden
199
+ data-color={isGradient ? undefined : color}
200
+ data-variant={variant}
201
+ data-state={bar.visible ? (loading ? "loading" : "complete") : "idle"}
202
+ className={cn(
203
+ "pointer-events-none fixed inset-x-0 top-0 z-(--navigation-progress-z,1000) overflow-hidden",
204
+ HEIGHT[size],
205
+ className,
206
+ classNames?.root,
207
+ )}
208
+ style={style}
209
+ {...props({ "data-testid": testId })}
210
+ >
211
+ <div
212
+ className={cn(
213
+ "h-full w-full transition-opacity ease-out",
214
+ FILL[variant],
215
+ isGradient && GRADIENT_DIR_CLASS[gradient?.dir ?? "to-r"],
216
+ bar.animate && "transition-[clip-path,opacity] motion-reduce:transition-opacity",
217
+ bar.visible ? "opacity-100" : "opacity-0",
218
+ classNames?.bar,
219
+ )}
220
+ style={{
221
+ ...(isGradient && gradient ? buildGradientVars(gradient) : null),
222
+ clipPath: `inset(0 ${100 - bar.value}% 0 0)`,
223
+ transitionDuration: `${bar.visible ? TRICKLE_INTERVAL : FADE_DURATION}ms`,
224
+ }}
225
+ />
226
+ </div>
227
+ )
228
+ }
@@ -379,10 +379,9 @@ export const NumberInput = ({
379
379
  readOnly={readOnly}
380
380
  startSlot={startSlot}
381
381
  // The steppers (and the clear button) are interactive — they must
382
- // not sit inside the `aria-hidden`, `[&_svg]:pointer-events-none`
383
- // end-slot span. Render them as direct children instead, and flag
384
- // the shell's end padding manually so the layout matches an
385
- // `endSlot`.
382
+ // not sit inside the `aria-hidden` end-slot span. Render them as
383
+ // direct children instead, and flag the shell's end padding
384
+ // manually so the layout matches an `endSlot`.
386
385
  classNames={{ root: classNames?.root }}
387
386
  className="pe-0! overflow-clip"
388
387
  {...props({ "data-with-end-slot": !hideControls || canClear || suffix != null })}
@@ -3,6 +3,8 @@
3
3
  export {
4
4
  Popover,
5
5
  type PopoverContentProps,
6
+ type PopoverGroupProps,
7
+ type PopoverPosition,
6
8
  type PopoverProps,
7
9
  type PopoverTriggerProps,
8
10
  } from "./popover"
@@ -213,6 +213,137 @@ describe('Popover mode="hover"', () => {
213
213
  })
214
214
  })
215
215
 
216
+ /**
217
+ * `Popover.Group` — several triggers, one shared panel. A switch has to keep
218
+ * the *same* content node (a remount would restart the slide from the
219
+ * viewport's corner), so it's compared by reference, like `HoverCard.Group`.
220
+ */
221
+ describe("Popover.Group", () => {
222
+ const person = (name: string) => screen.getByRole("button", { name })
223
+ const contents = () => document.querySelectorAll('[data-scope="popover"][data-part="content"]')
224
+
225
+ const Row = (props: Partial<PopoverProps>) => (
226
+ <Popover.Group
227
+ mode="hover"
228
+ openDelay={100}
229
+ closeDelay={100}
230
+ withinPortal={false}
231
+ {...(props as object)}
232
+ >
233
+ <Popover.Trigger value="ada" asChild>
234
+ <button type="button">Ada</button>
235
+ </Popover.Trigger>
236
+ <Popover.Trigger value="grace" asChild>
237
+ <button type="button">Grace</button>
238
+ </Popover.Trigger>
239
+ <Popover.Content value="ada">
240
+ <span>Ada's card</span>
241
+ <a href="/ada">Ada's profile</a>
242
+ </Popover.Content>
243
+ <Popover.Content value="grace">
244
+ <span>Grace's card</span>
245
+ <a href="/grace">Grace's profile</a>
246
+ </Popover.Content>
247
+ </Popover.Group>
248
+ )
249
+
250
+ it("moves an open preview to the next trigger, without closing or replaying the delay", async () => {
251
+ const onOpenChange = vi.fn()
252
+ const onTriggerValueChange = vi.fn()
253
+ render(<Row onOpenChange={onOpenChange} onTriggerValueChange={onTriggerValueChange} />)
254
+ hover(person("Ada"))
255
+ await tick(100)
256
+ expect(screen.queryByText("Ada's card")).not.toBeNull()
257
+ const node = panel()
258
+
259
+ unhover(person("Ada"))
260
+ hover(person("Grace"))
261
+ await tick(0)
262
+ expect(screen.queryByText("Grace's card")).not.toBeNull()
263
+ expect(screen.queryByText("Ada's card")).toBeNull()
264
+ expect(contents()).toHaveLength(1)
265
+ expect(panel()).toBe(node)
266
+ expect(onOpenChange).toHaveBeenCalledTimes(1)
267
+ expect(onTriggerValueChange).toHaveBeenLastCalledWith({
268
+ value: "grace",
269
+ triggerElement: person("Grace"),
270
+ })
271
+
272
+ // The pending close from leaving Ada was cancelled by reaching Grace.
273
+ await tick(1000)
274
+ expect(state()).toBe("open")
275
+ expect(person("Grace").getAttribute("aria-expanded")).toBe("true")
276
+ expect(person("Ada").getAttribute("aria-expanded")).toBe("false")
277
+ })
278
+
279
+ it("pins the clicked trigger's card when another one is previewing", async () => {
280
+ render(<Row />)
281
+ hover(person("Ada"))
282
+ await tick(100)
283
+ await tick(16)
284
+
285
+ fireEvent.click(person("Grace"))
286
+ await tick(16)
287
+ expect(state()).toBe("open")
288
+ expect(screen.queryByText("Grace's card")).not.toBeNull()
289
+ expect(document.activeElement).toBe(screen.getByRole("link", { name: "Grace's profile" }))
290
+
291
+ // Pinned: hover and pointer-leave no longer move or close it.
292
+ unhover(person("Grace"))
293
+ hover(person("Ada"))
294
+ await tick(1000)
295
+ expect(state()).toBe("open")
296
+ expect(screen.queryByText("Grace's card")).not.toBeNull()
297
+ })
298
+
299
+ it("pins when the click lands on a face the preview already moved to", async () => {
300
+ // A real pointer hovers a face before clicking it, so by click time the
301
+ // preview has switched there and zag answers with a close, not a switch.
302
+ const onOpenChange = vi.fn()
303
+ render(<Row onOpenChange={onOpenChange} />)
304
+ hover(person("Ada"))
305
+ await tick(100)
306
+ await tick(16)
307
+ unhover(person("Ada"))
308
+ hover(person("Grace"))
309
+ await tick(0)
310
+ fireEvent.click(person("Grace"))
311
+ await tick(16)
312
+ expect(state()).toBe("open")
313
+ expect(onOpenChange).toHaveBeenCalledTimes(1)
314
+ expect(document.activeElement).toBe(screen.getByRole("link", { name: "Grace's profile" }))
315
+ })
316
+
317
+ it("closes once the pointer leaves the whole group", async () => {
318
+ const onOpenChange = vi.fn()
319
+ render(<Row onOpenChange={onOpenChange} />)
320
+ hover(person("Ada"))
321
+ await tick(100)
322
+ unhover(person("Ada"))
323
+ await tick(100)
324
+ expect(state()).toBe("closed")
325
+ expect(onOpenChange).toHaveBeenLastCalledWith({ open: false })
326
+ })
327
+
328
+ it('switches triggers on click in mode="click"', async () => {
329
+ const onOpenChange = vi.fn()
330
+ render(
331
+ <Row mode="click" openDelay={undefined} closeDelay={undefined} onOpenChange={onOpenChange} />,
332
+ )
333
+ fireEvent.click(person("Ada"))
334
+ await tick(16)
335
+ expect(screen.queryByText("Ada's card")).not.toBeNull()
336
+ const node = panel()
337
+
338
+ fireEvent.click(person("Grace"))
339
+ await tick(16)
340
+ expect(screen.queryByText("Grace's card")).not.toBeNull()
341
+ expect(panel()).toBe(node)
342
+ expect(state()).toBe("open")
343
+ expect(onOpenChange).toHaveBeenCalledTimes(1)
344
+ })
345
+ })
346
+
216
347
  describe("Popover testId", () => {
217
348
  it("lands on the trigger", () => {
218
349
  render(