@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.
- package/dist/{chunk-45QRQKRC.js → chunk-3L5GLI67.js} +12 -8
- package/dist/chunk-3L5GLI67.js.map +1 -0
- package/dist/{chunk-BNWQ7IAZ.js → chunk-4FEOMQYR.js} +5 -5
- package/dist/{chunk-BNWQ7IAZ.js.map → chunk-4FEOMQYR.js.map} +1 -1
- package/dist/{chunk-POKLPMSB.js → chunk-D3JYDAUZ.js} +3 -3
- package/dist/{chunk-POKLPMSB.js.map → chunk-D3JYDAUZ.js.map} +1 -1
- package/dist/{chunk-KMZENCEP.js → chunk-DHJB4UJD.js} +4 -4
- package/dist/{chunk-KMZENCEP.js.map → chunk-DHJB4UJD.js.map} +1 -1
- package/dist/{chunk-IOYZC7SA.js → chunk-DJAXXLN6.js} +3 -3
- package/dist/{chunk-IOYZC7SA.js.map → chunk-DJAXXLN6.js.map} +1 -1
- package/dist/{chunk-3BXKTWWD.js → chunk-FB2G4LNH.js} +5 -5
- package/dist/{chunk-3BXKTWWD.js.map → chunk-FB2G4LNH.js.map} +1 -1
- package/dist/{chunk-E63VD25L.js → chunk-HQPU73WV.js} +4 -4
- package/dist/{chunk-E63VD25L.js.map → chunk-HQPU73WV.js.map} +1 -1
- package/dist/{chunk-RCF7HTG5.js → chunk-IRNF274I.js} +5 -5
- package/dist/chunk-IRNF274I.js.map +1 -0
- package/dist/{chunk-O5W3QWJ6.js → chunk-J44FJ7PH.js} +3 -3
- package/dist/{chunk-O5W3QWJ6.js.map → chunk-J44FJ7PH.js.map} +1 -1
- package/dist/{chunk-TWLJQE75.js → chunk-MRAJ45IM.js} +4 -4
- package/dist/{chunk-TWLJQE75.js.map → chunk-MRAJ45IM.js.map} +1 -1
- package/dist/{chunk-5HUEBSIS.js → chunk-N66NC6QK.js} +120 -24
- package/dist/chunk-N66NC6QK.js.map +1 -0
- package/dist/{chunk-SXNAUSEB.js → chunk-OZMSXYBX.js} +4 -4
- package/dist/{chunk-SXNAUSEB.js.map → chunk-OZMSXYBX.js.map} +1 -1
- package/dist/{chunk-LBAE6FP6.js → chunk-SZEOTXRZ.js} +4 -4
- package/dist/{chunk-LBAE6FP6.js.map → chunk-SZEOTXRZ.js.map} +1 -1
- package/dist/chunk-V6PY7C6S.js +18 -0
- package/dist/chunk-V6PY7C6S.js.map +1 -0
- package/dist/{chunk-MKKQE3TM.js → chunk-YPFSRZ3T.js} +4 -4
- package/dist/{chunk-MKKQE3TM.js.map → chunk-YPFSRZ3T.js.map} +1 -1
- package/dist/{chunk-NJPHZBLI.js → chunk-YWTOW7PZ.js} +5 -5
- package/dist/{chunk-NJPHZBLI.js.map → chunk-YWTOW7PZ.js.map} +1 -1
- package/dist/{chunk-VTDBWU6H.js → chunk-YZJUPYPO.js} +3 -3
- package/dist/{chunk-VTDBWU6H.js.map → chunk-YZJUPYPO.js.map} +1 -1
- package/dist/components/autocomplete/index.js +4 -3
- package/dist/components/autocomplete/index.js.map +1 -1
- package/dist/components/calendar-heatmap/calendar-heatmap-grid.d.ts +94 -0
- package/dist/components/calendar-heatmap/calendar-heatmap-grid.d.ts.map +1 -0
- package/dist/components/calendar-heatmap/calendar-heatmap.d.ts +76 -0
- package/dist/components/calendar-heatmap/calendar-heatmap.d.ts.map +1 -0
- package/dist/components/calendar-heatmap/index.d.ts +2 -0
- package/dist/components/calendar-heatmap/index.d.ts.map +1 -0
- package/dist/components/calendar-heatmap/index.js +311 -0
- package/dist/components/calendar-heatmap/index.js.map +1 -0
- package/dist/components/camera/index.js +6 -5
- package/dist/components/clipboard/index.js +1 -1
- package/dist/components/code-block/chrome.js +4 -4
- package/dist/components/code-block/index.js +5 -5
- package/dist/components/combobox/index.js +4 -3
- package/dist/components/combobox-list/index.js +6 -5
- package/dist/components/data-table/index.js +16 -16
- package/dist/components/date-picker/index.js +7 -6
- package/dist/components/date-picker/index.js.map +1 -1
- package/dist/components/hover-card/hover-card.d.ts +44 -26
- package/dist/components/hover-card/hover-card.d.ts.map +1 -1
- package/dist/components/hover-card/index.js +35 -53
- package/dist/components/hover-card/index.js.map +1 -1
- package/dist/components/input/index.js +1 -1
- package/dist/components/input/input.d.ts.map +1 -1
- package/dist/components/menu/index.js +3 -3
- package/dist/components/menu/menu.d.ts +7 -5
- package/dist/components/menu/menu.d.ts.map +1 -1
- package/dist/components/multi-combobox-list/index.js +6 -5
- package/dist/components/multi-select/index.js +5 -4
- package/dist/components/multi-select/index.js.map +1 -1
- package/dist/components/navigation-progress/index.d.ts +2 -0
- package/dist/components/navigation-progress/index.d.ts.map +1 -0
- package/dist/components/navigation-progress/index.js +133 -0
- package/dist/components/navigation-progress/index.js.map +1 -0
- package/dist/components/navigation-progress/navigation-progress.d.ts +46 -0
- package/dist/components/navigation-progress/navigation-progress.d.ts.map +1 -0
- package/dist/components/number-input/index.js +4 -3
- package/dist/components/number-input/number-input.d.ts.map +1 -1
- package/dist/components/password-input/index.js +1 -1
- package/dist/components/photo-capture/index.js +6 -5
- package/dist/components/photo-capture/index.js.map +1 -1
- package/dist/components/pills-input/index.js +2 -2
- package/dist/components/pin-input/index.js +1 -1
- package/dist/components/popover/index.d.ts +1 -1
- package/dist/components/popover/index.d.ts.map +1 -1
- package/dist/components/popover/index.js +2 -1
- package/dist/components/popover/popover.d.ts +44 -29
- package/dist/components/popover/popover.d.ts.map +1 -1
- package/dist/components/schedule/index.js +2 -2
- package/dist/components/select/index.js +5 -4
- package/dist/components/spotlight/index.js +5 -4
- package/dist/components/spotlight/index.js.map +1 -1
- package/dist/components/tags-input/index.js +4 -3
- package/dist/components/tags-input/index.js.map +1 -1
- package/dist/components/text-input/index.js +1 -1
- package/dist/components/textarea/index.js +1 -1
- package/dist/components/time-input/index.js +5 -4
- package/dist/components/time-input/index.js.map +1 -1
- package/dist/components/tooltip/index.js +2 -2
- package/dist/components/tree-multi-select/index.js +5 -4
- package/dist/components/tree-multi-select/index.js.map +1 -1
- package/dist/components/tree-select/index.js +4 -3
- package/dist/components/tree-select/index.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/lib/placement.d.ts +42 -1
- package/dist/lib/placement.d.ts.map +1 -1
- package/dist/lib/slide-on-switch.d.ts +69 -0
- package/dist/lib/slide-on-switch.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/as-child.contract.test.tsx +4 -0
- package/src/components/calendar-heatmap/calendar-heatmap-grid.test.ts +186 -0
- package/src/components/calendar-heatmap/calendar-heatmap-grid.ts +192 -0
- package/src/components/calendar-heatmap/calendar-heatmap.test.tsx +180 -0
- package/src/components/calendar-heatmap/calendar-heatmap.tsx +385 -0
- package/src/components/calendar-heatmap/index.ts +11 -0
- package/src/components/hover-card/hover-card.tsx +89 -167
- package/src/components/input/input.test.tsx +23 -0
- package/src/components/input/input.tsx +10 -6
- package/src/components/menu/menu.tsx +16 -9
- package/src/components/navigation-progress/index.ts +14 -0
- package/src/components/navigation-progress/navigation-progress.test.tsx +184 -0
- package/src/components/navigation-progress/navigation-progress.tsx +228 -0
- package/src/components/number-input/number-input.tsx +3 -4
- package/src/components/popover/index.ts +2 -0
- package/src/components/popover/popover.test.tsx +131 -0
- package/src/components/popover/popover.tsx +191 -53
- package/src/lib/placement.test.ts +37 -0
- package/src/lib/placement.ts +60 -1
- package/src/lib/slide-on-switch.ts +99 -0
- package/dist/chunk-45QRQKRC.js.map +0 -1
- package/dist/chunk-5HUEBSIS.js.map +0 -1
- package/dist/chunk-G52U24GR.js +0 -10
- package/dist/chunk-G52U24GR.js.map +0 -1
- package/dist/chunk-RCF7HTG5.js.map +0 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
|
|
3
|
+
import { useLocaleContext } from "@ark-ui/react/locale"
|
|
3
4
|
import { Popover as ArkPopover, usePopoverContext } from "@ark-ui/react/popover"
|
|
4
5
|
import { Portal } from "@ark-ui/react/portal"
|
|
5
6
|
import { cva } from "class-variance-authority"
|
|
@@ -8,6 +9,7 @@ import {
|
|
|
8
9
|
createContext,
|
|
9
10
|
type MouseEvent,
|
|
10
11
|
type PointerEvent,
|
|
12
|
+
type RefObject,
|
|
11
13
|
useContext,
|
|
12
14
|
useEffect,
|
|
13
15
|
useRef,
|
|
@@ -23,7 +25,19 @@ import {
|
|
|
23
25
|
useLayerGuard,
|
|
24
26
|
useNestedLayer,
|
|
25
27
|
} from "../../lib/overlay-layer"
|
|
28
|
+
import {
|
|
29
|
+
type LogicalPosition,
|
|
30
|
+
type Placement,
|
|
31
|
+
type PlacementProps,
|
|
32
|
+
toPositioning,
|
|
33
|
+
} from "../../lib/placement"
|
|
26
34
|
import { props } from "../../lib/props"
|
|
35
|
+
import {
|
|
36
|
+
activeGroupContent,
|
|
37
|
+
slideStyle,
|
|
38
|
+
splitGroupChildren,
|
|
39
|
+
useSlideAfterPlaced,
|
|
40
|
+
} from "../../lib/slide-on-switch"
|
|
27
41
|
import type { WithTestId } from "../../lib/test-id"
|
|
28
42
|
import { TEXT_COLOR_CLASSES } from "../../lib/typography-size"
|
|
29
43
|
import { useUncontrolled } from "../../lib/use-uncontrolled"
|
|
@@ -191,7 +205,9 @@ export const popoverEmpty = cn(
|
|
|
191
205
|
* touch and never takes focus).
|
|
192
206
|
*/
|
|
193
207
|
|
|
194
|
-
|
|
208
|
+
/** `position` accepts Ark's physical placements plus the logical, RTL-aware
|
|
209
|
+
* horizontal sides `start` / `end` (resolved to `left` / `right` by direction). */
|
|
210
|
+
export type PopoverPosition = LogicalPosition<Placement>
|
|
195
211
|
|
|
196
212
|
/** Elements a pinned panel can move focus to — the first one wins, else the
|
|
197
213
|
* panel itself (it carries `tabIndex={-1}`). Mirrors what zag's own
|
|
@@ -215,12 +231,14 @@ type HoverSource = "hover" | "press"
|
|
|
215
231
|
type PopoverHover = {
|
|
216
232
|
/** Open and opened by a press (or upgraded from a preview). */
|
|
217
233
|
pinned: boolean
|
|
218
|
-
/** Pointer entering the trigger or the panel.
|
|
219
|
-
|
|
234
|
+
/** Pointer entering the trigger or the panel. `value` is the entered
|
|
235
|
+
* trigger's, inside `Popover.Group`; the panel passes none. */
|
|
236
|
+
onPointerEnter: (event: PointerEvent, value?: string) => void
|
|
220
237
|
/** Pointer leaving the trigger or the panel. */
|
|
221
238
|
onPointerLeave: (event: PointerEvent) => void
|
|
222
239
|
/** A trigger click about to reach Ark — flags a click on an open preview,
|
|
223
|
-
* so
|
|
240
|
+
* so whatever Ark answers it with (a close, or a switch to another
|
|
241
|
+
* trigger) becomes a pin instead. */
|
|
224
242
|
onTriggerClickCapture: (event: MouseEvent<HTMLElement>) => void
|
|
225
243
|
/** A press or focus inside the panel. */
|
|
226
244
|
pin: () => void
|
|
@@ -234,11 +252,15 @@ type PopoverContextValue = {
|
|
|
234
252
|
layers: OverlayLayers
|
|
235
253
|
/** Set only in `mode="hover"`. */
|
|
236
254
|
hover?: PopoverHover
|
|
255
|
+
/** `Popover.Group`'s shared panel, past its open's first placement —
|
|
256
|
+
* gates the slide between triggers (see `useSlideAfterPlaced`). */
|
|
257
|
+
sliding: boolean
|
|
237
258
|
}
|
|
238
259
|
const PopoverContext = createContext<PopoverContextValue>({
|
|
239
260
|
width: "target",
|
|
240
261
|
withinPortal: true,
|
|
241
262
|
layers: new Set(),
|
|
263
|
+
sliding: false,
|
|
242
264
|
})
|
|
243
265
|
|
|
244
266
|
type PopoverHoverDelays = {
|
|
@@ -260,37 +282,11 @@ type PopoverModeProps =
|
|
|
260
282
|
} & UnavailableProps<PopoverHoverDelays, 'requires mode="hover"'>)
|
|
261
283
|
| ({ mode: "hover" } & PopoverHoverDelays)
|
|
262
284
|
|
|
263
|
-
export type PopoverProps = ArkPopover.RootProps &
|
|
264
|
-
PopoverModeProps &
|
|
285
|
+
export type PopoverProps = Omit<ArkPopover.RootProps, "positioning"> &
|
|
286
|
+
PopoverModeProps &
|
|
287
|
+
PlacementProps & {
|
|
265
288
|
/** Match the trigger's width (`"target"`, default) or size to content (`"auto"`). */
|
|
266
289
|
width?: "target" | "auto"
|
|
267
|
-
/** Panel placement relative to the trigger. Defaults to Ark's `"bottom"`. */
|
|
268
|
-
position?: PopoverPosition
|
|
269
|
-
/** Gap in px between the trigger and the panel. */
|
|
270
|
-
gutter?: number
|
|
271
|
-
/** Fine placement, in px: `mainAxis` is the gap from the trigger (it replaces `gutter` when
|
|
272
|
-
* set), `crossAxis` slides the panel along the trigger's edge. Floating UI's `offset()`. */
|
|
273
|
-
offset?:
|
|
274
|
-
| {
|
|
275
|
-
mainAxis?: number | undefined
|
|
276
|
-
crossAxis?: number | undefined
|
|
277
|
-
}
|
|
278
|
-
| undefined
|
|
279
|
-
/** Hide the panel (`visibility: hidden`, no pointer events) once the
|
|
280
|
-
* trigger is fully clipped by its own scrolling ancestor, and restore it
|
|
281
|
-
* once back in view — Floating UI's `hide()` middleware
|
|
282
|
-
* (`strategy: "referenceHidden"`), already wired into Ark's positioning
|
|
283
|
-
* engine, just not exposed until now. Rides the positioner's existing
|
|
284
|
-
* scroll/resize listeners, so no extra observer is needed. Default `true`
|
|
285
|
-
* — a panel that can't see its own trigger is never in a state worth
|
|
286
|
-
* keeping visible; pass `false` to restore the old "keep following the
|
|
287
|
-
* trigger's last known position" behavior. */
|
|
288
|
-
hideWhenDetached?: boolean
|
|
289
|
-
/** Ark's full positioning options (`flip`, `slide`, `overlap`, `boundary`,
|
|
290
|
-
* `getAnchorElement`, …), for placements the props above can't express.
|
|
291
|
-
* Applied over them, so a key set here wins. */
|
|
292
|
-
positioning?: ArkPopover.RootProps["positioning"]
|
|
293
|
-
|
|
294
290
|
/** Render the panel in a Portal so it escapes clipping ancestors. Default `true`. */
|
|
295
291
|
withinPortal?: boolean
|
|
296
292
|
/** Portal target. Defaults to the enclosing `Modal`/`Drawer` when there is
|
|
@@ -314,7 +310,31 @@ const focusInto = (trigger: HTMLElement, initialFocusEl?: () => HTMLElement | nu
|
|
|
314
310
|
target.focus({ preventScroll: true })
|
|
315
311
|
})
|
|
316
312
|
|
|
313
|
+
/** Ark's live Popover API, for the hover path to send zag events through. */
|
|
314
|
+
type PopoverApi = ReturnType<typeof usePopoverContext>
|
|
315
|
+
|
|
316
|
+
/** `Popover.Group`'s link into the Ark root, rendered inside it: keeps `api`
|
|
317
|
+
* pointing at the machine's current API for the hover hook (which runs
|
|
318
|
+
* above the root), and re-anchors the panel whenever the active trigger
|
|
319
|
+
* changes. zag's trigger switch does reposition, but in the same action,
|
|
320
|
+
* against the render it was sent from — still the old trigger — so on its
|
|
321
|
+
* own the panel would swap content in place. (HoverCard's machine gets
|
|
322
|
+
* away with it because its switch re-enters the open state.) */
|
|
323
|
+
const GroupBridge = ({ api }: { api: RefObject<PopoverApi | null> }) => {
|
|
324
|
+
const live = usePopoverContext()
|
|
325
|
+
useEffect(() => {
|
|
326
|
+
api.current = live
|
|
327
|
+
})
|
|
328
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: keyed on the active trigger only; `live` is a new object every render.
|
|
329
|
+
useEffect(() => {
|
|
330
|
+
if (live.open) live.reposition()
|
|
331
|
+
}, [live.triggerValue])
|
|
332
|
+
return null
|
|
333
|
+
}
|
|
334
|
+
|
|
317
335
|
type UsePopoverHoverOptions = {
|
|
336
|
+
/** The machine's API (see `GroupBridge`); set once the Ark root mounts. */
|
|
337
|
+
api: RefObject<PopoverApi | null>
|
|
318
338
|
open?: boolean
|
|
319
339
|
defaultOpen?: boolean
|
|
320
340
|
openDelay: number
|
|
@@ -336,8 +356,21 @@ type UsePopoverHoverOptions = {
|
|
|
336
356
|
* `source` is deliberately not reset on close: zag reads `restoreFocus` when
|
|
337
357
|
* the close lands, so a preview closing must still read as `"hover"` there,
|
|
338
358
|
* or it would yank focus to a trigger the user never focused.
|
|
359
|
+
*
|
|
360
|
+
* Inside `Popover.Group`, hovering a trigger also makes it the active one,
|
|
361
|
+
* through zag's own `setTriggerValue` — the one path that re-anchors the
|
|
362
|
+
* panel too (zag repositions in the same action, reading the value it just
|
|
363
|
+
* set; a controlled `triggerValue` prop would still hold the old one there).
|
|
364
|
+
* So zag owns the value, and the hook never mirrors it. Over an open preview
|
|
365
|
+
* that switch is immediate (the panel slides, no delay replays); a pinned
|
|
366
|
+
* panel ignores hover and stays on its trigger. A click on an open preview
|
|
367
|
+
* pins it whichever answer zag gives: a close for the active trigger, a
|
|
368
|
+
* switch for another one. Which comes is zag's call, so the hook never
|
|
369
|
+
* predicts it — by the time a click lands, a hover may have moved the
|
|
370
|
+
* trigger already.
|
|
339
371
|
*/
|
|
340
372
|
const usePopoverHover = ({
|
|
373
|
+
api,
|
|
341
374
|
open,
|
|
342
375
|
defaultOpen,
|
|
343
376
|
openDelay,
|
|
@@ -355,7 +388,7 @@ const usePopoverHover = ({
|
|
|
355
388
|
const [source, setSource] = useState<HoverSource>("press")
|
|
356
389
|
const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)
|
|
357
390
|
// The trigger of a click that landed on an open preview, between its
|
|
358
|
-
// capture phase and the close Ark answers it with.
|
|
391
|
+
// capture phase and the close or switch Ark answers it with.
|
|
359
392
|
const upgrading = useRef<HTMLElement | null>(null)
|
|
360
393
|
const clear = () => {
|
|
361
394
|
clearTimeout(timer.current)
|
|
@@ -374,8 +407,10 @@ const usePopoverHover = ({
|
|
|
374
407
|
const pinned = isOpen && source === "press"
|
|
375
408
|
const hover: PopoverHover = {
|
|
376
409
|
pinned,
|
|
377
|
-
onPointerEnter: (event) => {
|
|
410
|
+
onPointerEnter: (event, value) => {
|
|
378
411
|
if (event.pointerType === "touch" || pinned) return
|
|
412
|
+
if (value !== undefined && api.current && api.current.triggerValue !== value)
|
|
413
|
+
api.current.setTriggerValue(value)
|
|
379
414
|
if (isOpen) return clear()
|
|
380
415
|
setSource("hover")
|
|
381
416
|
later(true, openDelay)
|
|
@@ -407,10 +442,27 @@ const usePopoverHover = ({
|
|
|
407
442
|
setOpen(next)
|
|
408
443
|
}
|
|
409
444
|
|
|
410
|
-
return {
|
|
445
|
+
return {
|
|
446
|
+
open: isOpen,
|
|
447
|
+
press: source === "press",
|
|
448
|
+
hover,
|
|
449
|
+
onArkOpenChange,
|
|
450
|
+
/** zag switched triggers — pins it if a click on a preview caused it. */
|
|
451
|
+
onArkTriggerValueChange: () => {
|
|
452
|
+
const trigger = upgrading.current
|
|
453
|
+
upgrading.current = null
|
|
454
|
+
if (!trigger) return
|
|
455
|
+
clear()
|
|
456
|
+
setSource("press")
|
|
457
|
+
if (autoFocus) focusInto(trigger, initialFocusEl)
|
|
458
|
+
},
|
|
459
|
+
}
|
|
411
460
|
}
|
|
412
461
|
|
|
413
|
-
|
|
462
|
+
/** `Root` and `Group` — one machine; `group` swaps plain children for
|
|
463
|
+
* `Trigger`s plus the active trigger's `Content`. */
|
|
464
|
+
const Machine = ({
|
|
465
|
+
group,
|
|
414
466
|
mode = "click",
|
|
415
467
|
openDelay,
|
|
416
468
|
closeDelay,
|
|
@@ -418,13 +470,16 @@ const Root = ({
|
|
|
418
470
|
position,
|
|
419
471
|
gutter,
|
|
420
472
|
offset,
|
|
421
|
-
hideWhenDetached
|
|
473
|
+
hideWhenDetached,
|
|
422
474
|
positioning,
|
|
423
475
|
withinPortal = true,
|
|
424
476
|
container,
|
|
425
477
|
children,
|
|
426
478
|
open,
|
|
427
479
|
defaultOpen,
|
|
480
|
+
triggerValue,
|
|
481
|
+
defaultTriggerValue,
|
|
482
|
+
onTriggerValueChange,
|
|
428
483
|
autoFocus = true,
|
|
429
484
|
restoreFocus = true,
|
|
430
485
|
modal = false,
|
|
@@ -432,13 +487,18 @@ const Root = ({
|
|
|
432
487
|
onClose,
|
|
433
488
|
onPointerDownOutside,
|
|
434
489
|
...rest
|
|
435
|
-
}: PopoverProps) => {
|
|
490
|
+
}: PopoverProps & { group: boolean }) => {
|
|
491
|
+
const { dir } = useLocaleContext()
|
|
436
492
|
const guard = useLayerGuard(onPointerDownOutside)
|
|
493
|
+
const slide = useSlideAfterPlaced()
|
|
494
|
+
const api = useRef<PopoverApi | null>(null)
|
|
437
495
|
const notify = (details: { open: boolean }) => {
|
|
438
496
|
onOpenChange?.(details)
|
|
497
|
+
if (group) slide.onOpenChange(details.open)
|
|
439
498
|
if (!details.open) onClose?.()
|
|
440
499
|
}
|
|
441
500
|
const hovering = usePopoverHover({
|
|
501
|
+
api,
|
|
442
502
|
open,
|
|
443
503
|
defaultOpen,
|
|
444
504
|
openDelay: delay(openDelay, 600),
|
|
@@ -455,32 +515,102 @@ const Root = ({
|
|
|
455
515
|
const state = hover
|
|
456
516
|
? { open: hovering.open, onOpenChange: hovering.onArkOpenChange }
|
|
457
517
|
: { open, defaultOpen, onOpenChange: notify }
|
|
518
|
+
const parts = group ? splitGroupChildren(children, Content) : undefined
|
|
458
519
|
return (
|
|
459
520
|
<PopoverContext.Provider
|
|
460
|
-
value={{
|
|
521
|
+
value={{
|
|
522
|
+
width,
|
|
523
|
+
withinPortal,
|
|
524
|
+
container,
|
|
525
|
+
layers: guard.layers,
|
|
526
|
+
hover,
|
|
527
|
+
sliding: group && slide.sliding,
|
|
528
|
+
}}
|
|
461
529
|
>
|
|
462
530
|
<ArkPopover.Root
|
|
531
|
+
// A group's panel mounts on each open, like HoverCard's, so its first
|
|
532
|
+
// frame never inherits a stale position to slide from.
|
|
533
|
+
lazyMount={group}
|
|
534
|
+
unmountOnExit={group}
|
|
463
535
|
onPointerDownOutside={guard.onPointerDownOutside}
|
|
464
|
-
positioning={
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
536
|
+
positioning={toPositioning(
|
|
537
|
+
{
|
|
538
|
+
position,
|
|
539
|
+
gutter,
|
|
540
|
+
offset,
|
|
541
|
+
hideWhenDetached,
|
|
542
|
+
positioning: group
|
|
543
|
+
? {
|
|
544
|
+
...positioning,
|
|
545
|
+
updatePosition: slide.updatePosition(positioning?.updatePosition),
|
|
546
|
+
}
|
|
547
|
+
: positioning,
|
|
548
|
+
},
|
|
549
|
+
dir,
|
|
550
|
+
width,
|
|
551
|
+
)}
|
|
472
552
|
autoFocus={press && autoFocus}
|
|
473
553
|
restoreFocus={press && restoreFocus}
|
|
474
554
|
modal={press && modal}
|
|
555
|
+
triggerValue={triggerValue}
|
|
556
|
+
defaultTriggerValue={defaultTriggerValue}
|
|
557
|
+
onTriggerValueChange={(details) => {
|
|
558
|
+
onTriggerValueChange?.(details)
|
|
559
|
+
hovering.onArkTriggerValueChange()
|
|
560
|
+
}}
|
|
475
561
|
{...state}
|
|
476
562
|
{...rest}
|
|
477
563
|
>
|
|
478
|
-
{
|
|
564
|
+
{parts ? (
|
|
565
|
+
<>
|
|
566
|
+
<GroupBridge api={api} />
|
|
567
|
+
{parts.triggers}
|
|
568
|
+
<ArkPopover.Context>
|
|
569
|
+
{(api) => activeGroupContent(parts.contents, api.triggerValue)}
|
|
570
|
+
</ArkPopover.Context>
|
|
571
|
+
</>
|
|
572
|
+
) : (
|
|
573
|
+
children
|
|
574
|
+
)}
|
|
479
575
|
</ArkPopover.Root>
|
|
480
576
|
</PopoverContext.Provider>
|
|
481
577
|
)
|
|
482
578
|
}
|
|
483
579
|
|
|
580
|
+
const Root = (props: PopoverProps) => <Machine group={false} {...props} />
|
|
581
|
+
|
|
582
|
+
export type PopoverGroupProps = PopoverProps
|
|
583
|
+
|
|
584
|
+
/**
|
|
585
|
+
* One shared panel across several triggers (e.g. a row of avatars) — the
|
|
586
|
+
* same `Popover.Trigger` / `Popover.Content` parts `Popover.Root` uses, just
|
|
587
|
+
* several of each, matched by a shared `value`. The Popover counterpart of
|
|
588
|
+
* `HoverCard.Group`, with the same contract, for cards people act on:
|
|
589
|
+
*
|
|
590
|
+
* <Popover.Group mode="hover" width="auto">
|
|
591
|
+
* <Popover.Trigger value="ada"><Avatar name="Ada Lovelace" /></Popover.Trigger>
|
|
592
|
+
* <Popover.Trigger value="grace"><Avatar name="Grace Hopper" /></Popover.Trigger>
|
|
593
|
+
*
|
|
594
|
+
* <Popover.Content value="ada">Ada's card</Popover.Content>
|
|
595
|
+
* <Popover.Content value="grace">Grace's card</Popover.Content>
|
|
596
|
+
* </Popover.Group>
|
|
597
|
+
*
|
|
598
|
+
* zag's Popover supports several named triggers on one machine: clicking
|
|
599
|
+
* another trigger while the panel is open moves it there instead of closing
|
|
600
|
+
* it, and only the active trigger gets `aria-expanded`. In `mode="hover"`,
|
|
601
|
+
* hovering another trigger while the preview is open moves it too, with no
|
|
602
|
+
* delay replay; a click, tap or Enter on any trigger, or a press or focus in
|
|
603
|
+
* the panel, pins it exactly like a single `mode="hover"` Popover. Either
|
|
604
|
+
* way the panel slides between triggers (`slideStyle`), never on the first
|
|
605
|
+
* open.
|
|
606
|
+
*
|
|
607
|
+
* `triggerValue` / `defaultTriggerValue` / `onTriggerValueChange` read and
|
|
608
|
+
* drive the active trigger. `Trigger`/`Content` must be `Group`'s own direct
|
|
609
|
+
* children (it scans one level, like `HoverCard.Group`); `Group` renders no
|
|
610
|
+
* DOM node, so wrap it from the outside for row layout (`Avatar.Group`).
|
|
611
|
+
*/
|
|
612
|
+
const Group = (props: PopoverGroupProps) => <Machine group {...props} />
|
|
613
|
+
|
|
484
614
|
export type PopoverTriggerProps = ArkPopover.TriggerProps & WithTestId
|
|
485
615
|
|
|
486
616
|
/** Ark's trigger, plus the hover handlers in `mode="hover"`. Ark merges them
|
|
@@ -497,7 +627,7 @@ const Trigger = ({
|
|
|
497
627
|
<ArkPopover.Trigger
|
|
498
628
|
onPointerEnter={(event) => {
|
|
499
629
|
onPointerEnter?.(event)
|
|
500
|
-
hover?.onPointerEnter(event)
|
|
630
|
+
hover?.onPointerEnter(event, rest.value)
|
|
501
631
|
}}
|
|
502
632
|
onPointerLeave={(event) => {
|
|
503
633
|
onPointerLeave?.(event)
|
|
@@ -513,7 +643,13 @@ const Trigger = ({
|
|
|
513
643
|
)
|
|
514
644
|
}
|
|
515
645
|
|
|
516
|
-
export type PopoverContentProps = NoAsChild<ArkPopover.ContentProps> &
|
|
646
|
+
export type PopoverContentProps = NoAsChild<ArkPopover.ContentProps> &
|
|
647
|
+
WithTestId & {
|
|
648
|
+
/** Which `Popover.Group` trigger this content belongs to — only
|
|
649
|
+
* meaningful inside `Popover.Group`, where `Group` renders the one whose
|
|
650
|
+
* `value` matches the active trigger. Never forwarded to the DOM. */
|
|
651
|
+
value?: string
|
|
652
|
+
}
|
|
517
653
|
|
|
518
654
|
const Content = ({
|
|
519
655
|
className,
|
|
@@ -524,15 +660,16 @@ const Content = ({
|
|
|
524
660
|
onPointerDown,
|
|
525
661
|
onFocus,
|
|
526
662
|
asChild: _asChild,
|
|
663
|
+
value: _value,
|
|
527
664
|
...rest
|
|
528
665
|
}: PopoverContentProps) => {
|
|
529
|
-
const { width, withinPortal, container, layers, hover } = useContext(PopoverContext)
|
|
666
|
+
const { width, withinPortal, container, layers, hover, sliding } = useContext(PopoverContext)
|
|
530
667
|
const portalContainer = useOverlayContainer(container)
|
|
531
668
|
// A child of the enclosing Modal/Drawer/Popover (read above this popover's
|
|
532
669
|
// own provider), and the parent of whatever opens from its body.
|
|
533
670
|
useNestedLayer(usePopoverContext().open)
|
|
534
671
|
const panel = (
|
|
535
|
-
<ArkPopover.Positioner>
|
|
672
|
+
<ArkPopover.Positioner style={sliding ? slideStyle : undefined}>
|
|
536
673
|
<ArkPopover.Content
|
|
537
674
|
tabIndex={-1}
|
|
538
675
|
// target → fill the sameWidth positioner; auto → size to content (max-content).
|
|
@@ -605,6 +742,7 @@ export type PopoverAnchorProps = ArkPopover.AnchorProps
|
|
|
605
742
|
|
|
606
743
|
export const Popover = {
|
|
607
744
|
Root,
|
|
745
|
+
Group,
|
|
608
746
|
Trigger,
|
|
609
747
|
/** Positions the panel without attaching any click/keyboard trigger
|
|
610
748
|
* semantics — for a host that already owns its own click resolution
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest"
|
|
2
|
+
import { toPositioning } from "./placement"
|
|
3
|
+
|
|
4
|
+
describe("toPositioning", () => {
|
|
5
|
+
it("defaults to bottom, hidden when detached, sized to content", () => {
|
|
6
|
+
expect(toPositioning({}, "ltr", "auto")).toEqual({
|
|
7
|
+
sameWidth: false,
|
|
8
|
+
placement: "bottom",
|
|
9
|
+
gutter: undefined,
|
|
10
|
+
offset: undefined,
|
|
11
|
+
hideWhenDetached: true,
|
|
12
|
+
})
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
it("resolves the logical sides for the direction", () => {
|
|
16
|
+
expect(toPositioning({ position: "start" }, "ltr", "auto").placement).toBe("left")
|
|
17
|
+
expect(toPositioning({ position: "start" }, "rtl", "auto").placement).toBe("right")
|
|
18
|
+
expect(toPositioning({ position: "end" }, "ltr", "auto").placement).toBe("right")
|
|
19
|
+
expect(toPositioning({ position: "end" }, "rtl", "auto").placement).toBe("left")
|
|
20
|
+
expect(toPositioning({ position: "top-start" }, "rtl", "auto").placement).toBe("top-start")
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it("matches the trigger's width for width=target", () => {
|
|
24
|
+
expect(toPositioning({}, "ltr", "target").sameWidth).toBe(true)
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it("lets the positioning escape hatch win over the props", () => {
|
|
28
|
+
const built = toPositioning(
|
|
29
|
+
{ position: "top", hideWhenDetached: true, positioning: { placement: "left", flip: false } },
|
|
30
|
+
"ltr",
|
|
31
|
+
"auto",
|
|
32
|
+
)
|
|
33
|
+
expect(built.placement).toBe("left")
|
|
34
|
+
expect(built.flip).toBe(false)
|
|
35
|
+
expect(built.hideWhenDetached).toBe(true)
|
|
36
|
+
})
|
|
37
|
+
})
|
package/src/lib/placement.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import type { Popover as ArkPopover } from "@ark-ui/react/popover"
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
|
-
* Shared by Menu/Tooltip (and any future floating-panel component with the
|
|
4
|
+
* Shared by Menu/Tooltip/HoverCard/Popover (and any future floating-panel component with the
|
|
3
5
|
* same contract): `position` accepts a component's own physical placement
|
|
4
6
|
* union `P` (Ark/Floating UI's vocabulary) plus the logical, RTL-aware
|
|
5
7
|
* horizontal sides `start` / `end`, resolved to `left` / `right` by direction.
|
|
@@ -21,3 +23,60 @@ export function resolveLogicalPlacement<P extends string>(
|
|
|
21
23
|
if (position === "end") return (dir === "rtl" ? "left" : "right") as P
|
|
22
24
|
return position as P
|
|
23
25
|
}
|
|
26
|
+
|
|
27
|
+
/** Ark's positioning options — the same zag `PositioningOptions` for every
|
|
28
|
+
* floating machine (Popover, HoverCard, Menu, Tooltip). */
|
|
29
|
+
export type Positioning = NonNullable<ArkPopover.RootProps["positioning"]>
|
|
30
|
+
|
|
31
|
+
/** Physical placements Ark understands — `bottom`, `top-start`, … */
|
|
32
|
+
export type Placement = NonNullable<Positioning["placement"]>
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The placement props Popover and HoverCard share, so a consumer can swap
|
|
36
|
+
* one for the other (or `HoverCard.Group` for `Popover.Group`) without
|
|
37
|
+
* rewriting where the panel goes. Built into Ark's `positioning` by
|
|
38
|
+
* `toPositioning`.
|
|
39
|
+
*/
|
|
40
|
+
export type PlacementProps = {
|
|
41
|
+
/** Panel placement relative to the trigger — Ark's physical placements,
|
|
42
|
+
* plus the RTL-aware `start` / `end` sides. Defaults to `"bottom"`. */
|
|
43
|
+
position?: LogicalPosition<Placement>
|
|
44
|
+
/** Gap in px between the trigger and the panel. */
|
|
45
|
+
gutter?: number
|
|
46
|
+
/** Fine placement, in px: `mainAxis` is the gap from the trigger (it replaces `gutter` when
|
|
47
|
+
* set), `crossAxis` slides the panel along the trigger's edge. Floating UI's `offset()`. */
|
|
48
|
+
offset?:
|
|
49
|
+
| {
|
|
50
|
+
mainAxis?: number | undefined
|
|
51
|
+
crossAxis?: number | undefined
|
|
52
|
+
}
|
|
53
|
+
| undefined
|
|
54
|
+
/** Hide the panel (`visibility: hidden`, no pointer events) once the
|
|
55
|
+
* trigger is fully clipped by its own scrolling ancestor, and restore it
|
|
56
|
+
* once back in view — Floating UI's `hide()` middleware
|
|
57
|
+
* (`strategy: "referenceHidden"`), already wired into Ark's positioning
|
|
58
|
+
* engine. Rides the positioner's existing scroll/resize listeners, so no
|
|
59
|
+
* extra observer is needed. Default `true` — a panel that can't see its
|
|
60
|
+
* own trigger is never in a state worth keeping visible; pass `false` to
|
|
61
|
+
* keep following the trigger's last known position. */
|
|
62
|
+
hideWhenDetached?: boolean
|
|
63
|
+
/** Ark's full positioning options (`flip`, `slide`, `overlap`, `boundary`,
|
|
64
|
+
* `getAnchorElement`, …), for placements the props above can't express.
|
|
65
|
+
* Applied over them, so a key set here wins. */
|
|
66
|
+
positioning?: Positioning
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Build Ark's `positioning` from `PlacementProps` — `start` / `end`
|
|
70
|
+
* resolved for `dir`, `sameWidth` from the panel's `width`. */
|
|
71
|
+
export const toPositioning = (
|
|
72
|
+
{ position = "bottom", gutter, offset, hideWhenDetached = true, positioning }: PlacementProps,
|
|
73
|
+
dir: "ltr" | "rtl",
|
|
74
|
+
width: "target" | "auto",
|
|
75
|
+
): Positioning => ({
|
|
76
|
+
sameWidth: width === "target",
|
|
77
|
+
placement: resolveLogicalPlacement(position, dir),
|
|
78
|
+
gutter,
|
|
79
|
+
offset,
|
|
80
|
+
hideWhenDetached,
|
|
81
|
+
...positioning,
|
|
82
|
+
})
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Children,
|
|
3
|
+
cloneElement,
|
|
4
|
+
type ElementType,
|
|
5
|
+
isValidElement,
|
|
6
|
+
type ReactElement,
|
|
7
|
+
type ReactNode,
|
|
8
|
+
useRef,
|
|
9
|
+
useState,
|
|
10
|
+
} from "react"
|
|
11
|
+
import type { Positioning } from "./placement"
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Shared by `HoverCard.Group` and `Popover.Group`: several named triggers on
|
|
15
|
+
* one Ark machine, one panel that slides from the active trigger to the next.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** Slide transition for a group's shared positioner. Ark sets the
|
|
19
|
+
* positioner's `transform: translate3d(var(--x), var(--y), 0)` inline
|
|
20
|
+
* (`@zag-js/popper`); animating `transform` itself makes the browser
|
|
21
|
+
* interpolate that translate between two trigger anchors when the group's
|
|
22
|
+
* active trigger changes. Passed as `style` (not a class) so it merges with,
|
|
23
|
+
* rather than replaces, Ark's own inline `transform`/`position` (Ark's
|
|
24
|
+
* `mergeProps` shallow-merges style objects); the same override-the-real-style
|
|
25
|
+
* technique `Tabs.Indicator` / `SegmentGroup` use for their sliding pill.
|
|
26
|
+
*
|
|
27
|
+
* Only applied once `useSlideAfterPlaced` reports `sliding`, never on an
|
|
28
|
+
* open's first placement: before it, the positioner sits at its unplaced
|
|
29
|
+
* origin (far off the trigger), and animating *that* jump reads as the panel
|
|
30
|
+
* flying in across the page instead of just appearing. A standalone `Root`
|
|
31
|
+
* never gets this at all: it also repositions on scroll/resize
|
|
32
|
+
* (`autoUpdate`), where an animated `transform` would look laggy rather than
|
|
33
|
+
* responsive. */
|
|
34
|
+
export const slideStyle = {
|
|
35
|
+
transitionProperty: "transform",
|
|
36
|
+
transitionDuration: "200ms",
|
|
37
|
+
transitionTimingFunction: "cubic-bezier(0.32, 0.72, 0, 1)",
|
|
38
|
+
} as const
|
|
39
|
+
|
|
40
|
+
type UpdatePosition = NonNullable<Positioning["updatePosition"]>
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* `sliding` turns true once an open's first placement has been applied, and
|
|
44
|
+
* false on every close. Waiting for the placement itself, not a frame count:
|
|
45
|
+
* the first one after an open can take several frames (the panel mounts,
|
|
46
|
+
* zag defers to the next frame, floating-ui computes asynchronously), and a
|
|
47
|
+
* transition switched on before it lands slides the panel in from its
|
|
48
|
+
* unplaced origin.
|
|
49
|
+
*
|
|
50
|
+
* Feed every open change to `onOpenChange`, and pass `updatePosition(...)`
|
|
51
|
+
* as the machine's `positioning.updatePosition` — zag calls it for every
|
|
52
|
+
* placement, with its own `updatePosition` to run. A consumer's own
|
|
53
|
+
* `updatePosition`, if any, is wrapped rather than replaced.
|
|
54
|
+
*/
|
|
55
|
+
export const useSlideAfterPlaced = () => {
|
|
56
|
+
const [sliding, setSliding] = useState(false)
|
|
57
|
+
// Read by placements zag finishes asynchronously, after a close may have
|
|
58
|
+
// landed — one of those must not re-arm the slide for the next open.
|
|
59
|
+
const open = useRef(false)
|
|
60
|
+
const onOpenChange = (next: boolean) => {
|
|
61
|
+
open.current = next
|
|
62
|
+
if (!next) setSliding(false)
|
|
63
|
+
}
|
|
64
|
+
const updatePosition =
|
|
65
|
+
(custom?: UpdatePosition): UpdatePosition =>
|
|
66
|
+
async (data) => {
|
|
67
|
+
await (custom ? custom(data) : data.updatePosition())
|
|
68
|
+
if (open.current) setSliding(true)
|
|
69
|
+
}
|
|
70
|
+
return { sliding, onOpenChange, updatePosition }
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Split a group's children into its `Content` parts (matched by `type`)
|
|
74
|
+
* and everything else (the triggers), one level deep. */
|
|
75
|
+
export const splitGroupChildren = <P extends { value?: string }>(
|
|
76
|
+
children: ReactNode,
|
|
77
|
+
content: ElementType<P>,
|
|
78
|
+
) => {
|
|
79
|
+
const items = Children.toArray(children)
|
|
80
|
+
const isContent = (node: ReactNode): node is ReactElement<P> =>
|
|
81
|
+
isValidElement(node) && node.type === content
|
|
82
|
+
return { contents: items.filter(isContent), triggers: items.filter((item) => !isContent(item)) }
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** The `Content` whose `value` matches the active trigger, under one forced,
|
|
86
|
+
* stable `key` — overriding whatever each was authored with (e.g.
|
|
87
|
+
* `key={person.handle}` in a `.map()`). The slot only ever renders one at a
|
|
88
|
+
* time, but a *different* key switching in reads to React as a different
|
|
89
|
+
* component, unmounting the real Positioner/Content DOM tree and mounting a
|
|
90
|
+
* fresh one instead of updating it in place. That fresh mount breaks the
|
|
91
|
+
* "one shared, sliding panel" contract: its position starts unset again, so
|
|
92
|
+
* every switch would look like the panel jumping in from the top. */
|
|
93
|
+
export const activeGroupContent = (
|
|
94
|
+
contents: ReactElement<{ value?: string }>[],
|
|
95
|
+
triggerValue: string | null,
|
|
96
|
+
) => {
|
|
97
|
+
const active = contents.find((content) => content.props.value === triggerValue)
|
|
98
|
+
return active ? cloneElement(active, { key: "group-content" }) : null
|
|
99
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/input/input.tsx"],"names":[],"mappings":";;;;;;;;;AAwCO,IAAM,mBAAA,GAAsB,EAAA;AAAA,EACjC,uEAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,6BAAA;AAAA,EACA,iCAAA;AAAA,EACA,0DAAA;AAAA,EACA;AACF;AAQO,IAAM,WAAA,GAAc;AAAA,EACzB,wDAAA;AAAA,EACA,kBAAA,CAAmB,OAAA;AAAA,EACnB,4CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,mLAAA;AAAA;AAAA;AAAA,EAGA,8KAAA;AAAA;AAAA,EAEA,2DAAA;AAAA,EACA,0BAAA;AAAA,EACA,6BAAA;AAAA,EACA;AACF;AAGO,IAAM,aAAA,GAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ3B,OAAA,EAAS,CAAC,YAAA,EAAc,0CAA0C,CAAA;AAAA;AAAA;AAAA,EAGlE,QAAA,EAAU;AAAA,IACR,mCAAA;AAAA,IACA;AAAA;AAEJ;AAQO,IAAM,QAAA,GAAW;AAAA,EACtB,EAAA,EAAI,SAAA;AAAA,EACJ,EAAA,EAAI,SAAA;AAAA,EACJ,EAAA,EAAI,OAAA;AAAA,EACJ,EAAA,EAAI,SAAA;AAAA,EACJ,EAAA,EAAI;AACN;AAGO,IAAM,aAAa,GAAA,CAAI,CAAC,GAAG,WAAA,EAAa,oCAAoC,CAAA,EAAG;AAAA,EACpF,QAAA,EAAU;AAAA,IACR,OAAA,EAAS,aAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOT,IAAA,EAAM;AAAA,MACJ,EAAA,EAAI;AAAA,QACF,eAAA;AAAA,QACA,mDAAA;AAAA,QACA,CAAA,QAAA,EAAW,SAAS,EAAE,CAAA,uBAAA;AAAA,OACxB;AAAA,MACA,EAAA,EAAI;AAAA,QACF,WAAA;AAAA,QACA,uDAAA;AAAA,QACA,CAAA,QAAA,EAAW,SAAS,EAAE,CAAA,yBAAA;AAAA,OACxB;AAAA,MACA,EAAA,EAAI;AAAA,QACF,WAAA;AAAA,QACA,uDAAA;AAAA,QACA,CAAA,QAAA,EAAW,SAAS,EAAE,CAAA,uBAAA;AAAA,OACxB;AAAA,MACA,EAAA,EAAI;AAAA,QACF,WAAA;AAAA,QACA,uDAAA;AAAA,QACA,CAAA,SAAA,EAAY,SAAS,EAAE,CAAA,uBAAA;AAAA,OACzB;AAAA,MACA,EAAA,EAAI;AAAA,QACF,eAAA;AAAA,QACA,mDAAA;AAAA,QACA,CAAA,SAAA,EAAY,SAAS,EAAE,CAAA,uBAAA;AAAA;AACzB;AACF,GACF;AAAA,EACA,eAAA,EAAiB,EAAE,OAAA,EAAS,SAAA,EAAW,MAAM,IAAA;AAC/C,CAAC;AAMM,IAAM,SAAA,GAAY,EAAA;AAAA,EACvB,kDAAA;AAAA,EACA,kBAAA,CAAmB;AACrB;AAUO,IAAM,mBAAmB,kBAAA,CAAmB;AAkC5C,IAAM,YAAY,CAAC;AAAA,EACxB,OAAA;AAAA,EACA,IAAA;AAAA,EACA,OAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,OAAA;AAAA,EACA,SAAA;AAAA,EACA,OAAA;AAAA,EACA,QAAA;AAAA,EACA,SAAA;AAAA,EACA,UAAA;AAAA,EACA,MAAA;AAAA,EACA,OAAA,EAAS,QAAA;AAAA,EACT,GAAG;AACL,CAAA,qBACE,IAAA;AAAA,EAAC,GAAA,CAAI,GAAA;AAAA,EAAJ;AAAA,IACE,GAAG,KAAA,CAAM;AAAA,MACR,cAAA,EAAgB,OAAA;AAAA,MAChB,eAAA,EAAiB,QAAA;AAAA,MACjB,eAAA,EAAiB,QAAA;AAAA,MACjB,cAAA,EAAgB,OAAA;AAAA;AAAA;AAAA,MAGhB,wBAAwB,SAAA,IAAa,IAAA;AAAA,MACrC,sBAAsB,OAAA,IAAW,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAKjC,aAAA,EAAe;AAAA,KAChB,CAAA;AAAA,IACD,SAAA,EAAW,EAAA,CAAG,SAAA,EAAW,UAAA,EAAY,IAAA,EAAM,WAAW,EAAE,OAAA,EAAS,IAAA,EAAM,CAAC,CAAA;AAAA,IACvE,GAAG,IAAA;AAAA,IAEH,QAAA,EAAA;AAAA,MAAA,SAAA,IAAa,IAAA,oBACZ,GAAA,CAAC,MAAA,EAAA,EAAK,SAAA,EAAW,EAAA,CAAG,SAAA,EAAW,UAAA,EAAY,SAAS,CAAA,EAAG,aAAA,EAAW,IAAA,EAC/D,QAAA,EAAA,SAAA,EACH,CAAA;AAAA,MAED,QAAA;AAAA,MACA,OAAA,IAAW,IAAA,oBACV,GAAA,CAAC,MAAA,EAAA,EAAK,SAAA,EAAW,EAAA,CAAG,SAAA,EAAW,UAAA,EAAY,OAAO,CAAA,EAAG,aAAA,EAAW,IAAA,EAC7D,QAAA,EAAA,OAAA,EACH;AAAA;AAAA;AAEJ;AAiBK,IAAM,QAAQ,CAAC;AAAA,EACpB,OAAA;AAAA,EACA,IAAA;AAAA,EACA,OAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,OAAA;AAAA,EACA,SAAA;AAAA,EACA,OAAA;AAAA,EACA,SAAA;AAAA,EACA,UAAA;AAAA,EACA,MAAA;AAAA,EACA,GAAG;AACL,CAAA,KAAkB;AAIhB,EAAA,MAAM,QAAQ,eAAA,EAAgB;AAC9B,EAAA,MAAM,eAAA,GAAkB,OAAO,aAAA,EAAc;AAE7C,EAAA,uBACE,GAAA;AAAA,IAAC,SAAA;AAAA,IAAA;AAAA,MACC,OAAA;AAAA,MACA,IAAA;AAAA,MACA,OAAA;AAAA,MACA,SAAA;AAAA,MACA,OAAA;AAAA,MACA,SAAA;AAAA,MACA,UAAA,EAAY;AAAA,QACV,MAAM,UAAA,EAAY,IAAA;AAAA,QAClB,WAAW,UAAA,EAAY,SAAA;AAAA,QACvB,SAAS,UAAA,EAAY;AAAA,OACvB;AAAA,MACC,GAAG,KAAA,CAAM;AAAA,QACR,QAAA,EAAU,YAAY,KAAA,EAAO,QAAA;AAAA,QAC7B,OAAA,EAAS,WAAW,KAAA,EAAO,OAAA;AAAA,QAC3B,QAAA,EAAU,YAAY,KAAA,EAAO;AAAA,OAC9B,CAAA;AAAA,MAED,QAAA,kBAAA,GAAA;AAAA,QAAC,GAAA,CAAI,KAAA;AAAA,QAAJ;AAAA,UACE,GAAG,eAAA;AAAA,UACH,GAAG,eAAe,KAAK,CAAA;AAAA,UACvB,GAAG,KAAA,CAAM;AAAA,YACR,QAAA,EAAU,YAAY,KAAA,EAAO,QAAA;AAAA,YAC7B,cAAA,EAAgB,WAAW,KAAA,EAAO,OAAA;AAAA,YAClC,QAAA,EAAU,YAAY,KAAA,EAAO,QAAA;AAAA,YAC7B,aAAA,EAAe;AAAA,WAChB,CAAA;AAAA,UACD,SAAA,EAAW,EAAA,CAAG,mBAAA,EAAqB,UAAA,EAAY,KAAK,CAAA;AAAA,UACnD,GAAG;AAAA;AAAA;AACN;AAAA,GACF;AAEJ","file":"chunk-45QRQKRC.js","sourcesContent":["\"use client\"\n\nimport { ark, type HTMLArkProps } from \"@ark-ui/react\"\nimport { useFieldContext } from \"@ark-ui/react/field\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport type { ReactNode, Ref } from \"react\"\nimport type { NoAsChild } from \"../../lib/as-child\"\nimport { cn } from \"../../lib/cn\"\nimport { props } from \"../../lib/props\"\nimport type { WithTestId } from \"../../lib/test-id\"\nimport { TEXT_COLOR_CLASSES } from \"../../lib/typography-size\"\nimport { fieldA11yProps } from \"../field/field\"\n\n/**\n * Input / InputBase — the styled input *shell* the whole form family renders\n * into (Select trigger, Combobox/Autocomplete search field, PillsInput, and\n * `TextInput`). It is deliberately the lowest layer: label / description /\n * error live in `Field`, not here — reach for `TextInput` when you want them\n * built in, which is the common case, and for `Input` when you're composing\n * the shell yourself or the control needs no accessible name of its own.\n *\n * - `InputBase` is the polymorphic shell. It draws the bordered box, the\n * focus-visible ring, the disabled / invalid states, and lays out\n * an optional `startSlot` / `endSlot` around a single control child. The\n * child can be anything — an `<input>`, a `<button>` (Select trigger), or a\n * `<div>` of pills (PillsInput). Style your control with the exported\n * `inputControlClasses` so it sits flush inside the shell.\n * - `Input` is `InputBase` wrapping a real `<input>`. Native\n * input props (`value`, `onChange`, `placeholder`, `name`, `type`, `ref`, …)\n * are forwarded straight to the element; `className` styles the shell root\n * (matching the kit's other components), and `classNames` overrides parts.\n *\n * The shell is palette-independent, so there is no `color` prop: the focus halo\n * and border are a fixed `brand-500` per the 42 UI Kit Figma (see `shellChrome`),\n * and `de33dee` removed both `color` and the `filled` variant. `invalid` swaps\n * the border / ring to red.\n */\n\n/** Inner-control reset — apply to whatever element you nest inside `InputBase`\n * (input, button, …) so it inherits the shell's font and fills the row. */\nexport const inputControlClasses = cn(\n \"w-full flex-1 min-w-0 appearance-none border-0 bg-transparent p-0 m-0\",\n // `font: inherit` is the canonical form-control reset — without it the UA\n // forces its own font-size and the shell's `size` text scale is ignored.\n // No `text-trim`: a native `<input>`'s text renders inside the UA's own\n // form-control internals, not a normal CSS line box, so `text-box-trim`\n // computes an inconsistent (content-dependent) box height there — Chrome\n // was scrolling the text vertically once its computed box stopped matching\n // the element's actual rendered height.\n \"font-[inherit] text-inherit\",\n \"outline-none focus:outline-none\",\n \"placeholder:text-black/50 dark:placeholder:text-white/50\",\n \"disabled:cursor-not-allowed\",\n)\n\n/**\n * Shared shell chrome — surface, border, focus ring, and state styling. The\n * single-line `Input` shell and the multi-line `PillsInput` shell both build on\n * these; only the layout (row vs wrap) and the sizing differ, so the visual\n * treatment (incl. the invalid red halo) lives in exactly one place.\n */\nexport const shellChrome = [\n \"group/input relative rounded-input border outline-none\",\n TEXT_COLOR_CLASSES.primary,\n \"transition-[color,box-shadow,border-color]\",\n // Fixed brand-500 focus halo + border, per the 42 UI Kit Figma — independent\n // of the instance's own `color`. The combined selector matches either shape\n // in the family: a shell wrapping a real focusable descendant (Input,\n // Select, Combobox, MultiSelect, ComboboxList, MultiComboboxList, PinInput's\n // per-cell shell) or a shell that IS the tabbable element itself (TreeSelect,\n // TreeMultiSelect). `:has()` alone only matches the former.\n \"[&:is(:focus-visible,:has(:focus-visible))]:border-brand-500 [&:is(:focus-visible,:has(:focus-visible))]:ring-[3px] [&:is(:focus-visible,:has(:focus-visible))]:ring-brand-500/15\",\n // Invalid wins over the palette: red border + red halo. Same combined\n // selector as the rule above so the two can't drift out of sync.\n \"data-invalid:border-red-500 data-invalid:[&:is(:focus-visible,:has(:focus-visible))]:border-red-500 data-invalid:[&:is(:focus-visible,:has(:focus-visible))]:ring-red-500/15\",\n // Disabled affordances on the shell.\n \"data-disabled:cursor-not-allowed data-disabled:opacity-60\",\n \"data-disabled:bg-white/8\",\n \"data-pointer:cursor-pointer\",\n \"[&_svg]:pointer-events-none [&_svg]:shrink-0\",\n]\n\n/** Surface treatment per `variant`, shared across the input shells. */\nexport const shellVariants = {\n // Translucent border to go with the translucent fill: at `bg-white/4` the\n // shell has no ground of its own, so a fixed opaque hairline can vanish (on\n // a light-gray card) or over-assert (on a mid-tone host page). Same hue\n // language as Card's `default` (navy-tinted light / white-tinted dark), one\n // alpha step tighter — these render within a shade of the opaque colors\n // they replace, so the hairline keeps its weight and only gains\n // background-adaptivity.\n default: [\"bg-white/4\", \"border-brand-900/20 dark:border-white/15\"],\n // Escape hatch: strip the chrome but keep the layout (height / slots). Same\n // combined selector as `shellChrome`'s \"on\" rule so the cancel can't drift.\n unstyled: [\n \"border-transparent bg-transparent\",\n \"rounded-none [&:is(:focus-visible,:has(:focus-visible))]:ring-0\",\n ],\n}\n\n/**\n * Inline gap between the shell's slots and control, per `size`. The single\n * source for this spacing: `inputShell` applies it to the shell row, and any\n * control that lays out its *own* slots inside a nested flex (e.g. the Select\n * trigger) reuses it so adornments sit identically across the family.\n */\nexport const shellGap = {\n xs: \"gap-1.5\",\n sm: \"gap-1.5\",\n md: \"gap-2\",\n lg: \"gap-2.5\",\n xl: \"gap-3\",\n} as const\n\n/** Single-line input shell. Reused by the family's button / input controls. */\nexport const inputShell = cva([...shellChrome, \"flex w-full items-center gap-y-0.5\"], {\n variants: {\n variant: shellVariants,\n // Padding is slot-aware: the base is the tight, no-adornment inset, and each\n // side gains a step of inline padding only when `InputBase` flags an\n // adornment there (`data-with-start-slot` / `data-with-end-slot`). These are\n // self-referential `data-*` variants — the attributes live on this same\n // shell element, so a `group-*` variant (which targets descendants) wouldn't\n // match.\n size: {\n xs: [\n \"ps-1.5 pe-1.5\",\n \"data-with-start-slot:ps-2 data-with-end-slot:pe-2\",\n `min-h-7 ${shellGap.xs} text-xs [&_svg]:size-3`,\n ],\n sm: [\n \"ps-2 pe-2\",\n \"data-with-start-slot:ps-2.5 data-with-end-slot:pe-2.5\",\n `min-h-8 ${shellGap.sm} text-sm [&_svg]:size-3.5`,\n ],\n md: [\n \"ps-2 pe-2\",\n \"data-with-start-slot:ps-2.5 data-with-end-slot:pe-2.5\",\n `min-h-9 ${shellGap.md} text-md [&_svg]:size-4`,\n ],\n lg: [\n \"ps-3 pe-3\",\n \"data-with-start-slot:ps-3.5 data-with-end-slot:pe-3.5\",\n `min-h-10 ${shellGap.lg} text-lg [&_svg]:size-5`,\n ],\n xl: [\n \"ps-3.5 pe-3.5\",\n \"data-with-start-slot:ps-4 data-with-end-slot:pe-4\",\n `min-h-12 ${shellGap.xl} text-xl [&_svg]:size-6`,\n ],\n },\n },\n defaultVariants: { variant: \"default\", size: \"md\" },\n})\n\n/** Start/end adornment slot — the shared visual contract for the inline-start /\n * inline-end content the whole form family lays out (icon, chevron, clear).\n * Exported so Select / Combobox / the pills controls slot their adornments\n * identically to `InputBase` instead of re-deriving the layout. */\nexport const inputSlot = cn(\n \"inline-flex shrink-0 items-center justify-center\",\n TEXT_COLOR_CLASSES.muted,\n)\n\n/** Muted color for a component's own custom-rendered placeholder / empty-state text — a\n * `<span>` standing in for a native `::placeholder` wherever the value display isn't a real\n * `<input>` (Select's trigger, MultiSelect's non-searchable mode, TreeSelect / TreeMultiSelect's\n * trigger, DatePicker's range-mode trigger). Same color pairing as `inputControlClasses`'s native\n * `::placeholder` rule above. Kept as its own export, not folded into `inputSlot` — `inputSlot`'s\n * `inline-flex items-center justify-center shrink-0` are icon-slot layout rules; forced onto a\n * run of text they'd center it and block it from shrinking, silently breaking truncation on the\n * call sites where this color sits on the same span as `flex-1`/`truncate`. */\nexport const placeholderColor = TEXT_COLOR_CLASSES.muted\n\nexport type InputVariant = NonNullable<VariantProps<typeof inputShell>[\"variant\"]>\nexport type InputSize = NonNullable<VariantProps<typeof inputShell>[\"size\"]>\n\ntype ShellClassNames = {\n /** The shell `<div>` (also targeted by `className`). */\n root?: string\n startSlot?: string\n endSlot?: string\n}\n\n/** Props shared by the shell and the convenience `Input`. */\ntype ShellOwnProps = VariantProps<typeof inputShell> & {\n /** Red border + ring; also wires `aria-invalid` on `Input`. */\n invalid?: boolean\n /** Dims the shell and (on `Input`) disables the element. */\n disabled?: boolean\n /** Keeps full contrast but blocks edits (on `Input`). */\n readOnly?: boolean\n /** `cursor: pointer` — for button-like triggers (Select). */\n pointer?: boolean\n /** Decorative or interactive content at the inline-start of the control. */\n startSlot?: ReactNode\n /** Content at the inline-end — chevron, clear button, spinner. */\n endSlot?: ReactNode\n}\n\nexport type InputBaseProps = NoAsChild<Omit<HTMLArkProps<\"div\">, \"color\">> &\n ShellOwnProps &\n WithTestId & {\n classNames?: ShellClassNames\n }\n\nexport const InputBase = ({\n variant,\n size,\n invalid,\n disabled,\n readOnly,\n pointer,\n startSlot,\n endSlot,\n children,\n className,\n classNames,\n testId,\n asChild: _asChild,\n ...rest\n}: InputBaseProps) => (\n <ark.div\n {...props({\n \"data-invalid\": invalid,\n \"data-disabled\": disabled,\n \"data-readonly\": readOnly,\n \"data-pointer\": pointer,\n // Drive the slot-aware padding in `inputShell`: each side gains a step of\n // inline padding when an adornment sits there (`data-with-*-slot:`).\n \"data-with-start-slot\": startSlot != null,\n \"data-with-end-slot\": endSlot != null,\n // Only meaningful when `InputBase` is used bare (no `Input`-style inner\n // control routing its own `testId`) — a `testId` given to a control that\n // wraps `InputBase` itself (Input, NumberInput, Select, …) always lands\n // on that control's real interactive element instead, never here.\n \"data-testid\": testId,\n })}\n className={cn(className, classNames?.root, inputShell({ variant, size }))}\n {...rest}\n >\n {startSlot != null && (\n <span className={cn(inputSlot, classNames?.startSlot)} aria-hidden>\n {startSlot}\n </span>\n )}\n {children}\n {endSlot != null && (\n <span className={cn(inputSlot, classNames?.endSlot)} aria-hidden>\n {endSlot}\n </span>\n )}\n </ark.div>\n)\n\nexport type InputProps = Omit<HTMLArkProps<\"input\">, \"size\" | \"color\"> &\n ShellOwnProps &\n WithTestId & {\n /** Lands on the underlying `<input>` for focus-on-error. Declared\n * explicitly because `HTMLArkProps` is `ComponentPropsWithoutRef`, so the\n * native prop types alone don't carry it — same as `Textarea`,\n * `PasswordInput`, and `NumberInput`. */\n ref?: Ref<HTMLInputElement>\n classNames?: ShellClassNames & {\n /** The inner `<input>` element. */\n input?: string\n }\n }\n\nexport const Input = ({\n variant,\n size,\n invalid,\n disabled,\n readOnly,\n pointer,\n startSlot,\n endSlot,\n className,\n classNames,\n testId,\n ...rest\n}: InputProps) => {\n // When nested in a `Field`, inherit its id / aria-describedby / state so the\n // label, description, and error wire up — exactly how Ark's own `Field.Input`\n // behaves. `useFieldContext` is null outside a Field, so this is a no-op then.\n const field = useFieldContext()\n const fieldInputProps = field?.getInputProps()\n\n return (\n <InputBase\n variant={variant}\n size={size}\n pointer={pointer}\n startSlot={startSlot}\n endSlot={endSlot}\n className={className}\n classNames={{\n root: classNames?.root,\n startSlot: classNames?.startSlot,\n endSlot: classNames?.endSlot,\n }}\n {...props({\n disabled: disabled || field?.disabled,\n invalid: invalid || field?.invalid,\n readOnly: readOnly || field?.readOnly,\n })}\n >\n <ark.input\n {...fieldInputProps}\n {...fieldA11yProps(field)}\n {...props({\n disabled: disabled || field?.disabled,\n \"aria-invalid\": invalid || field?.invalid,\n readOnly: readOnly || field?.readOnly,\n \"data-testid\": testId,\n })}\n className={cn(inputControlClasses, classNames?.input)}\n {...rest}\n />\n </InputBase>\n )\n}\n"]}
|