@kumix/ui 0.4.1 → 0.4.2
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/README.md +37 -30
- package/dist/{cascader-types-DVT-znZ-.d.ts → cascader-types-zhnUQ4sP.d.ts} +11 -3
- package/dist/cascader-types-zhnUQ4sP.d.ts.map +1 -0
- package/dist/components/agents/agent-code.js +1 -1
- package/dist/components/charts/candlestick-chart/context.d.ts.map +1 -1
- package/dist/components/charts/donut-chart/context.d.ts.map +1 -1
- package/dist/components/charts/liquidity-heatmap.d.ts.map +1 -1
- package/dist/components/charts/order-book.d.ts.map +1 -1
- package/dist/components/charts/treemap.d.ts.map +1 -1
- package/dist/components/charts/volume-profile.d.ts.map +1 -1
- package/dist/components/motion/action-swap.d.ts +1 -1
- package/dist/components/motion/action-swap.d.ts.map +1 -1
- package/dist/components/motion/action-swap.js +43 -20
- package/dist/components/motion/action-swap.js.map +1 -1
- package/dist/components/motion/animated-badge.d.ts +1 -1
- package/dist/components/motion/animated-badge.d.ts.map +1 -1
- package/dist/components/motion/animated-badge.js +60 -101
- package/dist/components/motion/animated-badge.js.map +1 -1
- package/dist/components/motion/animated-sidebar.js +1 -1
- package/dist/components/motion/animated-toast-stack.js +1 -1
- package/dist/components/motion/attachment-upload.js +1 -1
- package/dist/components/motion/availability-scheduler/copy-menu.js +1 -1
- package/dist/components/motion/availability-scheduler/day-row.js +1 -1
- package/dist/components/motion/availability-scheduler/index.js +1 -1
- package/dist/components/motion/bloom-menu.d.ts.map +1 -1
- package/dist/components/motion/bloom-menu.js +73 -8
- package/dist/components/motion/bloom-menu.js.map +1 -1
- package/dist/components/motion/bottom-sheet.d.ts.map +1 -1
- package/dist/components/motion/bottom-sheet.js +6 -10
- package/dist/components/motion/bottom-sheet.js.map +1 -1
- package/dist/components/motion/bouncy-accordion.d.ts.map +1 -1
- package/dist/components/motion/bouncy-accordion.js +35 -22
- package/dist/components/motion/bouncy-accordion.js.map +1 -1
- package/dist/components/motion/center-morph-modal.js +1 -1
- package/dist/components/motion/color-picker.d.ts.map +1 -1
- package/dist/components/motion/command-palette.js +1 -1
- package/dist/components/motion/context-menu.js +1 -1
- package/dist/components/motion/date-range-picker.d.ts.map +1 -1
- package/dist/components/motion/drawer.d.ts +1 -1
- package/dist/components/motion/drawer.d.ts.map +1 -1
- package/dist/components/motion/drawer.js +10 -10
- package/dist/components/motion/drawer.js.map +1 -1
- package/dist/components/motion/expandable-action-bar.d.ts.map +1 -1
- package/dist/components/motion/feedback-widget.js +4 -1
- package/dist/components/motion/feedback-widget.js.map +1 -1
- package/dist/components/motion/morphing-lightbox.d.ts.map +1 -1
- package/dist/components/motion/morphing-lightbox.js +1 -1
- package/dist/components/motion/morphing-modal.d.ts +6 -1
- package/dist/components/motion/morphing-modal.d.ts.map +1 -1
- package/dist/components/motion/morphing-modal.js +37 -5
- package/dist/components/motion/morphing-modal.js.map +1 -1
- package/dist/components/motion/morphing-search.js +1 -1
- package/dist/components/motion/morphing-tabs.js +1 -1
- package/dist/components/motion/otp-input.js +19 -11
- package/dist/components/motion/otp-input.js.map +1 -1
- package/dist/components/motion/popover-morph.d.ts +4 -3
- package/dist/components/motion/popover-morph.d.ts.map +1 -1
- package/dist/components/motion/popover-morph.js +47 -55
- package/dist/components/motion/popover-morph.js.map +1 -1
- package/dist/components/motion/popover.js +7 -1
- package/dist/components/motion/popover.js.map +1 -1
- package/dist/components/motion/prediction-market-card.js +1 -1
- package/dist/components/motion/prediction-market.js +1 -1
- package/dist/components/motion/project-folder.js +1 -1
- package/dist/components/motion/radio.d.ts +5 -1
- package/dist/components/motion/radio.d.ts.map +1 -1
- package/dist/components/motion/radio.js +53 -5
- package/dist/components/motion/radio.js.map +1 -1
- package/dist/components/motion/select-morph.d.ts +1 -1
- package/dist/components/motion/select-morph.d.ts.map +1 -1
- package/dist/components/motion/select-morph.js +89 -21
- package/dist/components/motion/select-morph.js.map +1 -1
- package/dist/components/motion/select.d.ts.map +1 -1
- package/dist/components/motion/select.js +153 -135
- package/dist/components/motion/select.js.map +1 -1
- package/dist/components/motion/shader-background.d.ts +3 -2
- package/dist/components/motion/shader-background.d.ts.map +1 -1
- package/dist/components/motion/shader-background.js +9 -3
- package/dist/components/motion/shader-background.js.map +1 -1
- package/dist/components/motion/shared-layout-bg.d.ts.map +1 -1
- package/dist/components/motion/shared-layout-bg.js +17 -3
- package/dist/components/motion/shared-layout-bg.js.map +1 -1
- package/dist/components/motion/swipeable-list.d.ts.map +1 -1
- package/dist/components/motion/swipeable-list.js +61 -4
- package/dist/components/motion/swipeable-list.js.map +1 -1
- package/dist/components/motion/table/row-handle.js +1 -1
- package/dist/components/motion/table/table-header.js +1 -1
- package/dist/components/motion/tabs.d.ts +12 -3
- package/dist/components/motion/tabs.d.ts.map +1 -1
- package/dist/components/motion/tabs.js +248 -26
- package/dist/components/motion/tabs.js.map +1 -1
- package/dist/components/motion/theme-toggle.js +1 -1
- package/dist/components/reui/alert.d.ts +1 -1
- package/dist/components/reui/autocomplete.d.ts +1 -1
- package/dist/components/reui/autocomplete.d.ts.map +1 -1
- package/dist/components/reui/autocomplete.js +1 -1
- package/dist/components/reui/autocomplete.js.map +1 -1
- package/dist/components/reui/badge.d.ts +2 -2
- package/dist/components/reui/cascader/cascader-async.d.ts +21 -5
- package/dist/components/reui/cascader/cascader-async.d.ts.map +1 -1
- package/dist/components/reui/cascader/cascader-async.js +61 -34
- package/dist/components/reui/cascader/cascader-async.js.map +1 -1
- package/dist/components/reui/cascader/cascader-columns.d.ts.map +1 -1
- package/dist/components/reui/cascader/cascader-columns.js +5 -2
- package/dist/components/reui/cascader/cascader-columns.js.map +1 -1
- package/dist/components/reui/cascader/cascader-context.d.ts +3 -1
- package/dist/components/reui/cascader/cascader-context.d.ts.map +1 -1
- package/dist/components/reui/cascader/cascader-context.js.map +1 -1
- package/dist/components/reui/cascader/cascader-i18n.d.ts +1 -1
- package/dist/components/reui/cascader/cascader-item.d.ts +1 -1
- package/dist/components/reui/cascader/cascader-lib.d.ts +34 -8
- package/dist/components/reui/cascader/cascader-lib.d.ts.map +1 -1
- package/dist/components/reui/cascader/cascader-lib.js +145 -29
- package/dist/components/reui/cascader/cascader-lib.js.map +1 -1
- package/dist/components/reui/cascader/cascader-nav.d.ts +1 -1
- package/dist/components/reui/cascader/cascader-types.d.ts +1 -1
- package/dist/components/reui/cascader/cascader.d.ts +13 -8
- package/dist/components/reui/cascader/cascader.d.ts.map +1 -1
- package/dist/components/reui/cascader/cascader.js +31 -16
- package/dist/components/reui/cascader/cascader.js.map +1 -1
- package/dist/components/reui/code-block/code-block.d.ts.map +1 -1
- package/dist/components/reui/color-picker.js +1 -1
- package/dist/components/reui/data-grid/data-grid-cell-selection.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-cell-selection.js +1 -0
- package/dist/components/reui/data-grid/data-grid-cell-selection.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-column-filter.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-column-filter.js +1 -0
- package/dist/components/reui/data-grid/data-grid-column-filter.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-column-header.d.ts +6 -8
- package/dist/components/reui/data-grid/data-grid-column-header.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-column-header.js +7 -8
- package/dist/components/reui/data-grid/data-grid-column-header.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-column-visibility.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-column-visibility.js +1 -0
- package/dist/components/reui/data-grid/data-grid-column-visibility.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-pagination.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-pagination.js +1 -0
- package/dist/components/reui/data-grid/data-grid-pagination.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-scroll-area.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-scroll-area.js +1 -0
- package/dist/components/reui/data-grid/data-grid-scroll-area.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table-dnd-rows.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table-dnd-rows.js +3 -2
- package/dist/components/reui/data-grid/data-grid-table-dnd-rows.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table-dnd.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table-dnd.js +2 -1
- package/dist/components/reui/data-grid/data-grid-table-dnd.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table-virtual.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table-virtual.js +2 -1
- package/dist/components/reui/data-grid/data-grid-table-virtual.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table.d.ts +6 -11
- package/dist/components/reui/data-grid/data-grid-table.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table.js +22 -22
- package/dist/components/reui/data-grid/data-grid-table.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid.d.ts +16 -1
- package/dist/components/reui/data-grid/data-grid.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid.js +80 -22
- package/dist/components/reui/data-grid/data-grid.js.map +1 -1
- package/dist/components/reui/date-selector.d.ts.map +1 -1
- package/dist/components/reui/date-selector.js +21 -15
- package/dist/components/reui/date-selector.js.map +1 -1
- package/dist/components/reui/event-calendar/event-calendar-agenda-view.js +3 -5
- package/dist/components/reui/event-calendar/event-calendar-agenda-view.js.map +1 -1
- package/dist/components/reui/event-calendar/event-calendar-nav.d.ts.map +1 -1
- package/dist/components/reui/event-calendar/event-calendar-nav.js +2 -2
- package/dist/components/reui/event-calendar/event-calendar-nav.js.map +1 -1
- package/dist/components/reui/event-calendar/event-calendar.d.ts.map +1 -1
- package/dist/components/reui/event-calendar/event-calendar.js +34 -31
- package/dist/components/reui/event-calendar/event-calendar.js.map +1 -1
- package/dist/components/reui/file-type.d.ts +302 -6
- package/dist/components/reui/file-type.d.ts.map +1 -1
- package/dist/components/reui/file-type.js +416 -13
- package/dist/components/reui/file-type.js.map +1 -1
- package/dist/components/reui/filters/filters-builder.d.ts +1 -1
- package/dist/components/reui/filters/filters-lib.d.ts +1 -1
- package/dist/components/reui/frame.d.ts +1 -1
- package/dist/components/reui/gantt/gantt-nav.d.ts.map +1 -1
- package/dist/components/reui/gantt/gantt-nav.js +2 -2
- package/dist/components/reui/gantt/gantt-nav.js.map +1 -1
- package/dist/components/reui/gantt/gantt.d.ts.map +1 -1
- package/dist/components/reui/gantt/gantt.js +5 -2
- package/dist/components/reui/gantt/gantt.js.map +1 -1
- package/dist/components/reui/icon-tile.d.ts +2 -2
- package/dist/components/reui/number-field.d.ts +3 -3
- package/dist/components/reui/phone-input.js +30 -27
- package/dist/components/reui/phone-input.js.map +1 -1
- package/dist/components/reui/rating.d.ts +1 -1
- package/dist/components/reui/time-picker.js +1 -1
- package/dist/components/ui/attachment.d.ts +2 -2
- package/dist/components/ui/badge.d.ts +1 -1
- package/dist/components/ui/bubble.d.ts +1 -1
- package/dist/components/ui/button.d.ts +2 -2
- package/dist/components/ui/chart.d.ts.map +1 -1
- package/dist/components/ui/code-block.d.ts +29 -0
- package/dist/components/ui/code-block.d.ts.map +1 -0
- package/dist/components/ui/code-block.js +124 -0
- package/dist/components/ui/code-block.js.map +1 -0
- package/dist/components/ui/empty.d.ts +1 -1
- package/dist/components/ui/item.d.ts +2 -2
- package/dist/components/ui/marker.d.ts +1 -1
- package/dist/components/ui/sidebar.d.ts +1 -1
- package/dist/components/ui/toggle.d.ts +1 -1
- package/dist/components/ui/trace.d.ts +21 -0
- package/dist/components/ui/trace.d.ts.map +1 -0
- package/dist/components/ui/trace.js +77 -0
- package/dist/components/ui/trace.js.map +1 -0
- package/dist/context-BYXeJQnz.d.ts.map +1 -1
- package/dist/{copy-menu-BXUh52bu.js → copy-menu-DOg9Jh-U.js} +2 -2
- package/dist/{copy-menu-BXUh52bu.js.map → copy-menu-DOg9Jh-U.js.map} +1 -1
- package/dist/hooks/use-focus-trap.d.ts +22 -0
- package/dist/hooks/use-focus-trap.d.ts.map +1 -0
- package/dist/hooks/use-focus-trap.js +80 -0
- package/dist/hooks/use-focus-trap.js.map +1 -0
- package/dist/hooks/use-highlighted-code.d.ts +5 -0
- package/dist/hooks/use-highlighted-code.d.ts.map +1 -0
- package/dist/hooks/use-highlighted-code.js +128 -0
- package/dist/hooks/use-highlighted-code.js.map +1 -0
- package/dist/hooks/use-listbox.d.ts +29 -0
- package/dist/hooks/use-listbox.d.ts.map +1 -0
- package/dist/hooks/use-listbox.js +75 -0
- package/dist/hooks/use-listbox.js.map +1 -0
- package/dist/tooltip-C01qUgsW.d.ts.map +1 -1
- package/package.json +8 -8
- package/dist/cascader-types-DVT-znZ-.d.ts.map +0 -1
|
@@ -1,37 +1,45 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { useListbox } from "../../hooks/use-listbox.js";
|
|
2
3
|
import { EASE_OUT } from "../../lib/ease.js";
|
|
3
4
|
import { createContext, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
4
5
|
import { cn } from "@kumix/utils";
|
|
5
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
-
import { motion, useReducedMotion } from "motion/react";
|
|
7
|
+
import { animate, motion, useMotionValue, useMotionValueEvent, useReducedMotion, useTransform } from "motion/react";
|
|
7
8
|
import { Check, ChevronDown } from "lucide-react";
|
|
8
9
|
//#region src/components/motion/select.tsx
|
|
9
|
-
const
|
|
10
|
-
const CHEVRON_TRANSITION = {
|
|
10
|
+
const UNFOLD_SPRING = {
|
|
11
11
|
type: "spring",
|
|
12
|
-
|
|
13
|
-
bounce: .
|
|
12
|
+
visualDuration: .2,
|
|
13
|
+
bounce: .12
|
|
14
14
|
};
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
staggerChildren: .035,
|
|
19
|
-
delayChildren: .05
|
|
20
|
-
} }
|
|
15
|
+
const UNFOLD_EXIT = {
|
|
16
|
+
duration: .2,
|
|
17
|
+
ease: EASE_OUT
|
|
21
18
|
};
|
|
19
|
+
const RADIUS = 12;
|
|
20
|
+
const GAP = 8;
|
|
21
|
+
const LIP = 8;
|
|
22
|
+
const lerp = (a, b, t) => a + (b - a) * t;
|
|
22
23
|
const ITEM_VARIANTS = {
|
|
23
24
|
hidden: {
|
|
24
25
|
opacity: 0,
|
|
25
|
-
y: -
|
|
26
|
-
|
|
26
|
+
y: -4,
|
|
27
|
+
transition: {
|
|
28
|
+
duration: .08,
|
|
29
|
+
ease: EASE_OUT
|
|
30
|
+
}
|
|
27
31
|
},
|
|
28
32
|
show: {
|
|
29
33
|
opacity: 1,
|
|
30
34
|
y: 0,
|
|
31
|
-
|
|
35
|
+
transition: {
|
|
36
|
+
duration: .12,
|
|
37
|
+
ease: EASE_OUT
|
|
38
|
+
}
|
|
32
39
|
}
|
|
33
40
|
};
|
|
34
41
|
const SelectContext = createContext(null);
|
|
42
|
+
const ActiveOptionContext = createContext(void 0);
|
|
35
43
|
function useSelectContext(component) {
|
|
36
44
|
const ctx = useContext(SelectContext);
|
|
37
45
|
if (!ctx) throw new Error(`${component} must be used within <Select>`);
|
|
@@ -49,21 +57,34 @@ function Select({ value, defaultValue, onValueChange, open: openProp, defaultOpe
|
|
|
49
57
|
const current = controlled ? value : internal;
|
|
50
58
|
const openControlled = openProp !== void 0;
|
|
51
59
|
const open = openControlled ? openProp : internalOpen;
|
|
60
|
+
const progress = useMotionValue(open ? 1 : 0);
|
|
52
61
|
const setOpen = useCallback((next) => {
|
|
53
62
|
if (!openControlled) setInternalOpen(next);
|
|
54
63
|
onOpenChange?.(next);
|
|
55
64
|
}, [onOpenChange, openControlled]);
|
|
65
|
+
const close = useCallback(() => {
|
|
66
|
+
const trigger = document.getElementById(`${baseId}-trigger`);
|
|
67
|
+
if (rootRef.current?.contains(document.activeElement) && document.activeElement !== trigger) trigger?.focus();
|
|
68
|
+
setOpen(false);
|
|
69
|
+
}, [baseId, setOpen]);
|
|
56
70
|
const select = useCallback((next) => {
|
|
57
71
|
if (!controlled) setInternal(next);
|
|
58
72
|
onValueChange?.(next);
|
|
59
|
-
|
|
73
|
+
close();
|
|
60
74
|
}, [
|
|
61
75
|
controlled,
|
|
62
76
|
onValueChange,
|
|
63
|
-
|
|
77
|
+
close
|
|
64
78
|
]);
|
|
65
|
-
const register = useCallback((v, label) => {
|
|
66
|
-
setLabels((m) =>
|
|
79
|
+
const register = useCallback((v, label, disabled) => {
|
|
80
|
+
setLabels((m) => {
|
|
81
|
+
const entry = m.get(v);
|
|
82
|
+
if (entry?.label === label && entry.disabled === disabled) return m;
|
|
83
|
+
return new Map(m).set(v, {
|
|
84
|
+
label,
|
|
85
|
+
disabled
|
|
86
|
+
});
|
|
87
|
+
});
|
|
67
88
|
}, []);
|
|
68
89
|
const unregister = useCallback((v) => {
|
|
69
90
|
setLabels((m) => {
|
|
@@ -73,9 +94,17 @@ function Select({ value, defaultValue, onValueChange, open: openProp, defaultOpe
|
|
|
73
94
|
return next;
|
|
74
95
|
});
|
|
75
96
|
}, []);
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
const animation = animate(progress, open ? 1 : 0, reduce ? { duration: .12 } : open ? UNFOLD_SPRING : UNFOLD_EXIT);
|
|
99
|
+
return () => animation.stop();
|
|
100
|
+
}, [
|
|
101
|
+
open,
|
|
102
|
+
progress,
|
|
103
|
+
reduce
|
|
104
|
+
]);
|
|
76
105
|
useEffect(() => {
|
|
77
106
|
if (!open) return;
|
|
78
|
-
const onKey = (e) => e.key === "Escape" &&
|
|
107
|
+
const onKey = (e) => e.key === "Escape" && close();
|
|
79
108
|
const onPointer = (e) => {
|
|
80
109
|
if (rootRef.current && !rootRef.current.contains(e.target)) setOpen(false);
|
|
81
110
|
};
|
|
@@ -85,7 +114,16 @@ function Select({ value, defaultValue, onValueChange, open: openProp, defaultOpe
|
|
|
85
114
|
window.removeEventListener("keydown", onKey);
|
|
86
115
|
window.removeEventListener("pointerdown", onPointer);
|
|
87
116
|
};
|
|
88
|
-
}, [
|
|
117
|
+
}, [
|
|
118
|
+
open,
|
|
119
|
+
setOpen,
|
|
120
|
+
close
|
|
121
|
+
]);
|
|
122
|
+
const rows = useMemo(() => Array.from(labels, ([id, entry]) => ({
|
|
123
|
+
id,
|
|
124
|
+
label: entry.label,
|
|
125
|
+
disabled: entry.disabled
|
|
126
|
+
})), [labels]);
|
|
89
127
|
const ctx = useMemo(() => ({
|
|
90
128
|
value: current,
|
|
91
129
|
open,
|
|
@@ -93,8 +131,11 @@ function Select({ value, defaultValue, onValueChange, open: openProp, defaultOpe
|
|
|
93
131
|
select,
|
|
94
132
|
register,
|
|
95
133
|
unregister,
|
|
96
|
-
labelFor: (v) => v === void 0 ? void 0 : labels.get(v),
|
|
134
|
+
labelFor: (v) => v === void 0 ? void 0 : labels.get(v)?.label,
|
|
135
|
+
rows,
|
|
136
|
+
close,
|
|
97
137
|
reduce,
|
|
138
|
+
progress,
|
|
98
139
|
triggerId: `${baseId}-trigger`,
|
|
99
140
|
listId: `${baseId}-list`,
|
|
100
141
|
disabled,
|
|
@@ -108,7 +149,10 @@ function Select({ value, defaultValue, onValueChange, open: openProp, defaultOpe
|
|
|
108
149
|
register,
|
|
109
150
|
unregister,
|
|
110
151
|
labels,
|
|
152
|
+
rows,
|
|
153
|
+
close,
|
|
111
154
|
reduce,
|
|
155
|
+
progress,
|
|
112
156
|
baseId,
|
|
113
157
|
disabled,
|
|
114
158
|
placement
|
|
@@ -125,32 +169,18 @@ function Select({ value, defaultValue, onValueChange, open: openProp, defaultOpe
|
|
|
125
169
|
function SelectTrigger({ className, children }) {
|
|
126
170
|
const ctx = useSelectContext("SelectTrigger");
|
|
127
171
|
const isTop = ctx.placement === "top";
|
|
128
|
-
const
|
|
172
|
+
const nearRadius = useTransform(ctx.progress, [
|
|
129
173
|
0,
|
|
174
|
+
.2,
|
|
175
|
+
.4,
|
|
176
|
+
1
|
|
177
|
+
], [
|
|
178
|
+
RADIUS,
|
|
130
179
|
0,
|
|
131
|
-
12
|
|
132
|
-
] : [
|
|
133
|
-
12,
|
|
134
180
|
0,
|
|
135
|
-
|
|
136
|
-
];
|
|
137
|
-
const
|
|
138
|
-
duration: .6,
|
|
139
|
-
times: [
|
|
140
|
-
0,
|
|
141
|
-
.4,
|
|
142
|
-
1
|
|
143
|
-
],
|
|
144
|
-
ease: EASE_OUT
|
|
145
|
-
} : {
|
|
146
|
-
duration: .42,
|
|
147
|
-
times: [
|
|
148
|
-
0,
|
|
149
|
-
.5,
|
|
150
|
-
1
|
|
151
|
-
],
|
|
152
|
-
ease: EASE_OUT
|
|
153
|
-
};
|
|
181
|
+
RADIUS
|
|
182
|
+
]);
|
|
183
|
+
const rotate = useTransform(ctx.progress, (p) => ctx.reduce ? ctx.open ? 180 : 0 : Math.min(1, Math.max(0, p)) * 180);
|
|
154
184
|
return /* @__PURE__ */ jsxs(motion.button, {
|
|
155
185
|
type: "button",
|
|
156
186
|
id: ctx.triggerId,
|
|
@@ -159,24 +189,22 @@ function SelectTrigger({ className, children }) {
|
|
|
159
189
|
"aria-expanded": ctx.open,
|
|
160
190
|
"aria-controls": ctx.listId,
|
|
161
191
|
onClick: () => ctx.setOpen(!ctx.open),
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
borderBottomRightRadius: isTop ? 12 : kf
|
|
192
|
+
onKeyDown: (event) => {
|
|
193
|
+
if (!ctx.open && (event.key === "ArrowDown" || event.key === "ArrowUp")) {
|
|
194
|
+
event.preventDefault();
|
|
195
|
+
ctx.setOpen(true);
|
|
196
|
+
}
|
|
168
197
|
},
|
|
169
|
-
|
|
170
|
-
borderTopLeftRadius: isTop ?
|
|
171
|
-
borderTopRightRadius: isTop ?
|
|
172
|
-
borderBottomLeftRadius: isTop ?
|
|
173
|
-
borderBottomRightRadius: isTop ?
|
|
198
|
+
style: {
|
|
199
|
+
borderTopLeftRadius: ctx.reduce || !isTop ? RADIUS : nearRadius,
|
|
200
|
+
borderTopRightRadius: ctx.reduce || !isTop ? RADIUS : nearRadius,
|
|
201
|
+
borderBottomLeftRadius: ctx.reduce || isTop ? RADIUS : nearRadius,
|
|
202
|
+
borderBottomRightRadius: ctx.reduce || isTop ? RADIUS : nearRadius
|
|
174
203
|
},
|
|
175
|
-
className: cn("relative z-10 flex w-full items-center justify-between gap-2
|
|
204
|
+
className: cn("relative z-10 flex w-full items-center justify-between gap-2 border border-border bg-background px-3 py-2 text-foreground text-sm outline-none transition-colors", "hover:border-(--color-border-strong) focus-visible:ring-2 focus-visible:ring-foreground/20", "disabled:pointer-events-none disabled:opacity-50", className),
|
|
176
205
|
children: [children, /* @__PURE__ */ jsx(motion.span, {
|
|
177
206
|
"aria-hidden": true,
|
|
178
|
-
|
|
179
|
-
transition: ctx.reduce ? { duration: 0 } : CHEVRON_TRANSITION,
|
|
207
|
+
style: { rotate },
|
|
180
208
|
className: "text-muted-foreground",
|
|
181
209
|
children: /* @__PURE__ */ jsx(ChevronDown, { className: "h-4 w-4" })
|
|
182
210
|
})]
|
|
@@ -192,23 +220,38 @@ function SelectValue({ placeholder, className }) {
|
|
|
192
220
|
}
|
|
193
221
|
function SelectContent({ className, children }) {
|
|
194
222
|
const ctx = useSelectContext("SelectContent");
|
|
195
|
-
const
|
|
223
|
+
const panelRef = useRef(null);
|
|
196
224
|
const [height, setHeight] = useState(0);
|
|
197
|
-
const open = ctx
|
|
198
|
-
const {
|
|
225
|
+
const { open, progress, reduce, setPlacement } = ctx;
|
|
226
|
+
const { activeId, onKeyDown } = useListbox({
|
|
227
|
+
open,
|
|
228
|
+
rows: ctx.rows,
|
|
229
|
+
selected: ctx.value,
|
|
230
|
+
list: panelRef
|
|
231
|
+
});
|
|
232
|
+
const [exiting, setExiting] = useState(false);
|
|
233
|
+
const [wasOpen, setWasOpen] = useState(open);
|
|
234
|
+
if (open !== wasOpen) {
|
|
235
|
+
setWasOpen(open);
|
|
236
|
+
if (!open) setExiting(true);
|
|
237
|
+
}
|
|
238
|
+
const present = open || exiting;
|
|
239
|
+
useMotionValueEvent(progress, "animationComplete", () => {
|
|
240
|
+
if (progress.get() === 0) setExiting(false);
|
|
241
|
+
});
|
|
199
242
|
useLayoutEffect(() => {
|
|
200
|
-
const node =
|
|
201
|
-
if (!node) return;
|
|
243
|
+
const node = panelRef.current;
|
|
244
|
+
if (!node || !present) return;
|
|
202
245
|
const measure = () => setHeight(node.offsetHeight);
|
|
203
246
|
measure();
|
|
204
247
|
const observer = new ResizeObserver(measure);
|
|
205
248
|
observer.observe(node);
|
|
206
249
|
return () => observer.disconnect();
|
|
207
|
-
});
|
|
250
|
+
}, [present]);
|
|
208
251
|
useLayoutEffect(() => {
|
|
209
252
|
if (!open) return;
|
|
210
253
|
const trigger = document.getElementById(ctx.triggerId);
|
|
211
|
-
const node =
|
|
254
|
+
const node = panelRef.current;
|
|
212
255
|
if (!trigger || !node) return;
|
|
213
256
|
const rect = trigger.getBoundingClientRect();
|
|
214
257
|
const h = node.offsetHeight;
|
|
@@ -221,103 +264,78 @@ function SelectContent({ className, children }) {
|
|
|
221
264
|
setPlacement
|
|
222
265
|
]);
|
|
223
266
|
const isTop = ctx.placement === "top";
|
|
224
|
-
const
|
|
225
|
-
const
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
ease: EASE_OUT,
|
|
239
|
-
delay: .14
|
|
240
|
-
} : {
|
|
241
|
-
duration: .16,
|
|
242
|
-
ease: EASE_OUT
|
|
243
|
-
};
|
|
267
|
+
const ready = height > 0 && !reduce;
|
|
268
|
+
const fromY = ready ? isTop ? GAP : -8 : 0;
|
|
269
|
+
const detach = useTransform(progress, [.4, 1], [0, 1]);
|
|
270
|
+
const y = useTransform(detach, (d) => lerp(fromY, 0, d));
|
|
271
|
+
const nearRadius = useTransform(detach, (d) => ready ? RADIUS * d : RADIUS);
|
|
272
|
+
const borderRadius = useTransform(nearRadius, (near) => isTop ? `${RADIUS}px ${RADIUS}px ${near}px ${near}px` : `${near}px ${near}px ${RADIUS}px ${RADIUS}px`);
|
|
273
|
+
const clipPath = useTransform([progress, nearRadius], ([p, near]) => {
|
|
274
|
+
if (!ready) return "none";
|
|
275
|
+
const reveal = Math.min(1, Math.max(0, p));
|
|
276
|
+
if (reveal === 1) return "none";
|
|
277
|
+
const hidden = Math.max(0, (height - LIP) * (1 - reveal));
|
|
278
|
+
return `inset(${isTop ? `${hidden}px 0 0 0` : `0 0 ${hidden}px 0`} round ${isTop ? `${RADIUS}px ${RADIUS}px ${near}px ${near}px` : `${near}px ${near}px ${RADIUS}px ${RADIUS}px`})`;
|
|
279
|
+
});
|
|
280
|
+
const opacity = useTransform(progress, reduce ? [0, 1] : [0, .12], [0, 1]);
|
|
244
281
|
return /* @__PURE__ */ jsx(motion.div, {
|
|
282
|
+
ref: panelRef,
|
|
245
283
|
id: ctx.listId,
|
|
246
284
|
role: "listbox",
|
|
247
285
|
"aria-labelledby": ctx.triggerId,
|
|
248
286
|
"aria-hidden": !open,
|
|
249
287
|
inert: !open,
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
height: open ? height : 0
|
|
254
|
-
} : {
|
|
255
|
-
opacity: open ? 1 : 0,
|
|
256
|
-
height: open ? height : 0,
|
|
257
|
-
marginTop: isTop ? 0 : nearGap,
|
|
258
|
-
marginBottom: isTop ? nearGap : 0,
|
|
259
|
-
borderTopLeftRadius: isTop ? 12 : nearRadius,
|
|
260
|
-
borderTopRightRadius: isTop ? 12 : nearRadius,
|
|
261
|
-
borderBottomLeftRadius: isTop ? nearRadius : 12,
|
|
262
|
-
borderBottomRightRadius: isTop ? nearRadius : 12
|
|
263
|
-
},
|
|
264
|
-
transition: ctx.reduce ? { duration: .12 } : {
|
|
265
|
-
opacity: open ? { duration: .18 } : {
|
|
266
|
-
duration: .16,
|
|
267
|
-
delay: .12
|
|
268
|
-
},
|
|
269
|
-
height: open ? {
|
|
270
|
-
type: "spring",
|
|
271
|
-
duration: .42,
|
|
272
|
-
bounce: .14
|
|
273
|
-
} : {
|
|
274
|
-
duration: .26,
|
|
275
|
-
ease: EASE_OUT,
|
|
276
|
-
delay: .14
|
|
277
|
-
},
|
|
278
|
-
marginTop: isTop ? INSTANT_TRANSITION : gapT,
|
|
279
|
-
marginBottom: isTop ? gapT : INSTANT_TRANSITION,
|
|
280
|
-
borderTopLeftRadius: isTop ? INSTANT_TRANSITION : radiusT,
|
|
281
|
-
borderTopRightRadius: isTop ? INSTANT_TRANSITION : radiusT,
|
|
282
|
-
borderBottomLeftRadius: isTop ? radiusT : INSTANT_TRANSITION,
|
|
283
|
-
borderBottomRightRadius: isTop ? radiusT : INSTANT_TRANSITION
|
|
288
|
+
onKeyDown: (event) => {
|
|
289
|
+
if (event.key === "Tab") ctx.close();
|
|
290
|
+
else onKeyDown(event);
|
|
284
291
|
},
|
|
285
292
|
style: {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
293
|
+
visibility: present ? void 0 : "hidden",
|
|
294
|
+
maxHeight: present ? void 0 : 0,
|
|
295
|
+
borderWidth: present ? void 0 : 0,
|
|
296
|
+
y,
|
|
297
|
+
clipPath,
|
|
298
|
+
borderRadius,
|
|
299
|
+
opacity,
|
|
300
|
+
pointerEvents: open ? "auto" : "none",
|
|
301
|
+
marginTop: isTop ? 0 : GAP,
|
|
302
|
+
marginBottom: isTop ? GAP : 0
|
|
289
303
|
},
|
|
290
|
-
className: cn("absolute right-0 left-0 z-20
|
|
291
|
-
children: /* @__PURE__ */ jsx(
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
304
|
+
className: cn("absolute right-0 left-0 z-20 overflow-hidden border border-border bg-background shadow-lg", isTop ? "bottom-full" : "top-full", className),
|
|
305
|
+
children: /* @__PURE__ */ jsx(ActiveOptionContext.Provider, {
|
|
306
|
+
value: activeId,
|
|
307
|
+
children: /* @__PURE__ */ jsx(motion.div, {
|
|
308
|
+
initial: false,
|
|
309
|
+
animate: open ? "show" : "hidden",
|
|
310
|
+
className: "p-1",
|
|
311
|
+
children
|
|
312
|
+
})
|
|
298
313
|
})
|
|
299
314
|
});
|
|
300
315
|
}
|
|
301
316
|
function SelectItem({ value, disabled = false, className, children }) {
|
|
302
317
|
const ctx = useSelectContext("SelectItem");
|
|
318
|
+
const activeId = useContext(ActiveOptionContext);
|
|
303
319
|
const selected = ctx.value === value;
|
|
304
320
|
const label = typeof children === "string" ? children : value;
|
|
305
321
|
useLayoutEffect(() => {
|
|
306
|
-
ctx.register(value, label);
|
|
307
|
-
return () => ctx.unregister(value);
|
|
322
|
+
ctx.register(value, label, disabled);
|
|
308
323
|
}, [
|
|
309
324
|
ctx.register,
|
|
310
|
-
ctx.unregister,
|
|
311
325
|
value,
|
|
312
|
-
label
|
|
326
|
+
label,
|
|
327
|
+
disabled
|
|
313
328
|
]);
|
|
314
|
-
|
|
329
|
+
useLayoutEffect(() => () => ctx.unregister(value), [ctx.unregister, value]);
|
|
330
|
+
return /* @__PURE__ */ jsx(motion.div, {
|
|
315
331
|
variants: ctx.reduce ? void 0 : ITEM_VARIANTS,
|
|
316
332
|
children: /* @__PURE__ */ jsxs("button", {
|
|
317
333
|
type: "button",
|
|
318
334
|
role: "option",
|
|
319
335
|
"aria-selected": selected,
|
|
320
336
|
disabled,
|
|
337
|
+
tabIndex: activeId === value ? 0 : -1,
|
|
338
|
+
"data-listbox-id": value,
|
|
321
339
|
onClick: () => ctx.select(value),
|
|
322
340
|
className: cn("flex w-full items-center justify-between gap-2 rounded-lg px-2.5 py-1.5 text-left text-sm outline-none transition-colors", selected ? "bg-muted text-foreground" : "text-muted-foreground hover:bg-muted hover:text-foreground focus-visible:bg-muted", "disabled:pointer-events-none disabled:opacity-50", className),
|
|
323
341
|
children: [children, selected ? /* @__PURE__ */ jsx(Check, { className: "h-3.5 w-3.5 shrink-0" }) : null]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select.js","names":[],"sources":["../../../src/components/motion/select.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n createContext,\n type ReactNode,\n useCallback,\n useContext,\n useEffect,\n useId,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { Check, ChevronDown } from \"lucide-react\";\nimport { motion, type Transition, useReducedMotion, type Variants } from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { EASE_OUT } from \"../../lib/ease\";\n\nconst INSTANT_TRANSITION: Transition = { duration: 0 };\n\n// Spring with bounce powers the unfold/separation; per-property timings in the\n// content choreograph it (see SelectContent). Mirrors bouncy-accordion's feel.\nconst CHEVRON_TRANSITION: Transition = { type: \"spring\", duration: 0.4, bounce: 0.3 };\n\nconst LIST_VARIANTS: Variants = {\n hidden: {},\n show: { transition: { staggerChildren: 0.035, delayChildren: 0.05 } },\n};\nconst ITEM_VARIANTS: Variants = {\n hidden: { opacity: 0, y: -6, filter: \"blur(3px)\" },\n show: { opacity: 1, y: 0, filter: \"blur(0px)\" },\n};\n\ntype Placement = \"bottom\" | \"top\";\n\ninterface SelectContextValue {\n value: string | undefined;\n open: boolean;\n setOpen: (open: boolean) => void;\n select: (value: string) => void;\n register: (value: string, label: string) => void;\n unregister: (value: string) => void;\n labelFor: (value: string | undefined) => string | undefined;\n reduce: boolean;\n triggerId: string;\n listId: string;\n disabled: boolean;\n placement: Placement;\n setPlacement: (p: Placement) => void;\n}\n\nconst SelectContext = createContext<SelectContextValue | null>(null);\n\nfunction useSelectContext(component: string) {\n const ctx = useContext(SelectContext);\n if (!ctx) throw new Error(`${component} must be used within <Select>`);\n return ctx;\n}\n\nexport interface SelectProps {\n value?: string;\n defaultValue?: string;\n onValueChange?: (value: string) => void;\n /**\n * Controlled open state of the panel. A layout that stacks selects can hold\n * this to keep exactly one panel open — the panel is absolutely positioned\n * inside its field, so two open at once paint over each other's options.\n */\n open?: boolean;\n /** Uncontrolled initial open state. Default false. */\n defaultOpen?: boolean;\n /**\n * Fires whenever the panel opens or closes. The panel is absolutely\n * positioned inside the field, so a layout that stacks selects has to know\n * which one is open to paint it above its neighbours.\n */\n onOpenChange?: (open: boolean) => void;\n disabled?: boolean;\n className?: string;\n children: ReactNode;\n}\n\nexport function Select({\n value,\n defaultValue,\n onValueChange,\n open: openProp,\n defaultOpen = false,\n onOpenChange,\n disabled = false,\n className,\n children,\n}: SelectProps) {\n const reduce = useReducedMotion() ?? false;\n const baseId = useId();\n const rootRef = useRef<HTMLDivElement>(null);\n const [internalOpen, setInternalOpen] = useState(defaultOpen);\n const [internal, setInternal] = useState(defaultValue);\n const [labels, setLabels] = useState<Map<string, string>>(new Map());\n const [placement, setPlacement] = useState<Placement>(\"bottom\");\n\n const controlled = value !== undefined;\n const current = controlled ? value : internal;\n const openControlled = openProp !== undefined;\n const open = openControlled ? openProp : internalOpen;\n\n const setOpen = useCallback(\n (next: boolean) => {\n if (!openControlled) setInternalOpen(next);\n onOpenChange?.(next);\n },\n [onOpenChange, openControlled],\n );\n\n const select = useCallback(\n (next: string) => {\n if (!controlled) setInternal(next);\n onValueChange?.(next);\n setOpen(false);\n },\n [controlled, onValueChange, setOpen],\n );\n\n const register = useCallback((v: string, label: string) => {\n setLabels((m) => (m.get(v) === label ? m : new Map(m).set(v, label)));\n }, []);\n const unregister = useCallback((v: string) => {\n setLabels((m) => {\n if (!m.has(v)) return m;\n const next = new Map(m);\n next.delete(v);\n return next;\n });\n }, []);\n\n // close on outside pointer / escape\n useEffect(() => {\n if (!open) return;\n const onKey = (e: KeyboardEvent) => e.key === \"Escape\" && setOpen(false);\n const onPointer = (e: PointerEvent) => {\n if (rootRef.current && !rootRef.current.contains(e.target as Node)) setOpen(false);\n };\n window.addEventListener(\"keydown\", onKey);\n window.addEventListener(\"pointerdown\", onPointer);\n return () => {\n window.removeEventListener(\"keydown\", onKey);\n window.removeEventListener(\"pointerdown\", onPointer);\n };\n }, [open, setOpen]);\n\n const ctx = useMemo<SelectContextValue>(\n () => ({\n value: current,\n open,\n setOpen,\n select,\n register,\n unregister,\n labelFor: (v) => (v === undefined ? undefined : labels.get(v)),\n reduce,\n triggerId: `${baseId}-trigger`,\n listId: `${baseId}-list`,\n disabled,\n placement,\n setPlacement,\n }),\n [\n current,\n open,\n setOpen,\n select,\n register,\n unregister,\n labels,\n reduce,\n baseId,\n disabled,\n placement,\n ],\n );\n\n return (\n <SelectContext.Provider value={ctx}>\n <div ref={rootRef} className={cn(\"relative\", className)}>\n {children}\n </div>\n </SelectContext.Provider>\n );\n}\n\nexport interface SelectTriggerProps {\n className?: string;\n children: ReactNode;\n}\n\nexport function SelectTrigger({ className, children }: SelectTriggerProps) {\n const ctx = useSelectContext(\"SelectTrigger\");\n const isTop = ctx.placement === \"top\";\n // edge facing the panel flattens then rounds; the far edge stays rounded.\n // All four corners are specified so none gets stranded when placement flips.\n const kf = ctx.open ? [0, 0, 12] : [12, 0, 12];\n const kfT: Transition = ctx.reduce\n ? { duration: 0 }\n : ctx.open\n ? { duration: 0.6, times: [0, 0.4, 1], ease: EASE_OUT }\n : { duration: 0.42, times: [0, 0.5, 1], ease: EASE_OUT };\n return (\n <motion.button\n type=\"button\"\n id={ctx.triggerId}\n disabled={ctx.disabled}\n aria-haspopup=\"listbox\"\n aria-expanded={ctx.open}\n aria-controls={ctx.listId}\n onClick={() => ctx.setOpen(!ctx.open)}\n // Gooey: the edge facing the panel snaps flat (panel attached) then rounds\n // back once the panel pulls away — the two pinch apart.\n initial={false}\n animate={{\n borderTopLeftRadius: isTop ? kf : 12,\n borderTopRightRadius: isTop ? kf : 12,\n borderBottomLeftRadius: isTop ? 12 : kf,\n borderBottomRightRadius: isTop ? 12 : kf,\n }}\n transition={{\n borderTopLeftRadius: isTop ? kfT : INSTANT_TRANSITION,\n borderTopRightRadius: isTop ? kfT : INSTANT_TRANSITION,\n borderBottomLeftRadius: isTop ? INSTANT_TRANSITION : kfT,\n borderBottomRightRadius: isTop ? INSTANT_TRANSITION : kfT,\n }}\n className={cn(\n \"relative z-10 flex w-full items-center justify-between gap-2 rounded-xl border border-border bg-background px-3 py-2 text-foreground text-sm outline-none transition-colors\",\n \"hover:border-(--color-border-strong) focus-visible:ring-2 focus-visible:ring-foreground/20\",\n \"disabled:pointer-events-none disabled:opacity-50\",\n className,\n )}\n >\n {children}\n <motion.span\n aria-hidden\n animate={{ rotate: ctx.open ? 180 : 0 }}\n transition={ctx.reduce ? { duration: 0 } : CHEVRON_TRANSITION}\n className=\"text-muted-foreground\"\n >\n <ChevronDown className=\"h-4 w-4\" />\n </motion.span>\n </motion.button>\n );\n}\n\nexport interface SelectValueProps {\n placeholder?: string;\n className?: string;\n}\n\nexport function SelectValue({ placeholder, className }: SelectValueProps) {\n const ctx = useSelectContext(\"SelectValue\");\n const label = ctx.labelFor(ctx.value);\n return (\n <span className={cn(label ? \"text-foreground\" : \"text-muted-foreground\", className)}>\n {label ?? placeholder ?? \"Select\"}\n </span>\n );\n}\n\nexport interface SelectContentProps {\n className?: string;\n children: ReactNode;\n}\n\nexport function SelectContent({ className, children }: SelectContentProps) {\n const ctx = useSelectContext(\"SelectContent\");\n const innerRef = useRef<HTMLDivElement>(null);\n const [height, setHeight] = useState(0);\n const open = ctx.open;\n const { setPlacement } = ctx;\n\n useLayoutEffect(() => {\n const node = innerRef.current;\n if (!node) return;\n const measure = () => setHeight(node.offsetHeight);\n measure();\n const observer = new ResizeObserver(measure);\n observer.observe(node);\n return () => observer.disconnect();\n });\n\n // On open, flip upward when there isn't room below and there's more above.\n useLayoutEffect(() => {\n if (!open) return;\n const trigger = document.getElementById(ctx.triggerId);\n const node = innerRef.current;\n if (!trigger || !node) return;\n const rect = trigger.getBoundingClientRect();\n const h = node.offsetHeight;\n const below = window.innerHeight - rect.bottom;\n const above = rect.top;\n setPlacement(below < h + 16 && above > below ? \"top\" : \"bottom\");\n }, [open, ctx.triggerId, setPlacement]);\n\n // Specify EVERY corner + both margins each render. The near edge (facing the\n // trigger) animates flat->round and the gap opens on that side; the far edge\n // stays rounded and its margin pinned to 0. Setting all of them avoids a\n // stranded square corner when the placement flips between opens.\n const isTop = ctx.placement === \"top\";\n const nearGap = open ? 8 : 0;\n const nearRadius = open ? 12 : 0;\n\n const gapT: Transition = open\n ? { type: \"spring\", duration: 0.6, bounce: 0.5, delay: 0.12 }\n : { type: \"spring\", duration: 0.3, bounce: 0.1 };\n const radiusT: Transition = open\n ? { duration: 0.3, ease: EASE_OUT, delay: 0.14 }\n : { duration: 0.16, ease: EASE_OUT };\n\n // Items stay mounted (open just animates the panel) so each item's label\n // registration persists — otherwise the trigger would fall back to the\n // placeholder the moment the panel closes.\n return (\n <motion.div\n id={ctx.listId}\n role=\"listbox\"\n aria-labelledby={ctx.triggerId}\n aria-hidden={!open}\n inert={!open}\n initial={false}\n animate={\n ctx.reduce\n ? { opacity: open ? 1 : 0, height: open ? height : 0 }\n : {\n opacity: open ? 1 : 0,\n height: open ? height : 0,\n // gap opens on the side facing the trigger\n marginTop: isTop ? 0 : nearGap,\n marginBottom: isTop ? nearGap : 0,\n // near corners go flat->round; far corners stay rounded\n borderTopLeftRadius: isTop ? 12 : nearRadius,\n borderTopRightRadius: isTop ? 12 : nearRadius,\n borderBottomLeftRadius: isTop ? nearRadius : 12,\n borderBottomRightRadius: isTop ? nearRadius : 12,\n }\n }\n transition={\n ctx.reduce\n ? { duration: 0.12 }\n : {\n opacity: open ? { duration: 0.18 } : { duration: 0.16, delay: 0.12 },\n height: open\n ? { type: \"spring\", duration: 0.42, bounce: 0.14 }\n : { duration: 0.26, ease: EASE_OUT, delay: 0.14 },\n marginTop: isTop ? INSTANT_TRANSITION : gapT,\n marginBottom: isTop ? gapT : INSTANT_TRANSITION,\n borderTopLeftRadius: isTop ? INSTANT_TRANSITION : radiusT,\n borderTopRightRadius: isTop ? INSTANT_TRANSITION : radiusT,\n borderBottomLeftRadius: isTop ? radiusT : INSTANT_TRANSITION,\n borderBottomRightRadius: isTop ? radiusT : INSTANT_TRANSITION,\n }\n }\n style={{\n transformOrigin: isTop ? \"bottom\" : \"top\",\n overflow: \"hidden\",\n pointerEvents: open ? \"auto\" : \"none\",\n }}\n // flush against the trigger, then separates into its own rounded pill;\n // sits above or below depending on available space\n className={cn(\n \"absolute right-0 left-0 z-20 rounded-xl border border-border bg-background shadow-lg\",\n isTop ? \"bottom-full\" : \"top-full\",\n className,\n )}\n >\n <motion.div\n ref={innerRef}\n variants={ctx.reduce ? undefined : LIST_VARIANTS}\n initial={false}\n animate={open ? \"show\" : \"hidden\"}\n className=\"p-1\"\n >\n {children}\n </motion.div>\n </motion.div>\n );\n}\n\nexport interface SelectItemProps {\n value: string;\n disabled?: boolean;\n className?: string;\n children: ReactNode;\n}\n\nexport function SelectItem({ value, disabled = false, className, children }: SelectItemProps) {\n const ctx = useSelectContext(\"SelectItem\");\n const selected = ctx.value === value;\n const label = typeof children === \"string\" ? children : value;\n\n useLayoutEffect(() => {\n ctx.register(value, label);\n return () => ctx.unregister(value);\n }, [ctx.register, ctx.unregister, value, label]);\n\n return (\n <motion.li variants={ctx.reduce ? undefined : ITEM_VARIANTS}>\n <button\n type=\"button\"\n role=\"option\"\n aria-selected={selected}\n disabled={disabled}\n onClick={() => ctx.select(value)}\n className={cn(\n \"flex w-full items-center justify-between gap-2 rounded-lg px-2.5 py-1.5 text-left text-sm outline-none transition-colors\",\n selected\n ? \"bg-muted text-foreground\"\n : \"text-muted-foreground hover:bg-muted hover:text-foreground focus-visible:bg-muted\",\n \"disabled:pointer-events-none disabled:opacity-50\",\n className,\n )}\n >\n {children}\n {selected ? <Check className=\"h-3.5 w-3.5 shrink-0\" /> : null}\n </button>\n </motion.li>\n );\n}\n"],"mappings":";;;;;;;;AAoBA,MAAM,qBAAiC,EAAE,UAAU,EAAE;AAIrD,MAAM,qBAAiC;CAAE,MAAM;CAAU,UAAU;CAAK,QAAQ;AAAI;AAEpF,MAAM,gBAA0B;CAC9B,QAAQ,CAAC;CACT,MAAM,EAAE,YAA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AK,CAAC;CAE/C,OACE,oBAAC,OAAO,IAAR;EAAW,UAAU,IAAI,SAAS,KAAA,IAAY;EAC5C,UAAA,qBAAC,UAAD;GACE,MAAK;GACL,MAAK;GACL,iBAAe;GACL;GACV,eAAe,IAAI,OAAO,KAAK;GAC/B,WAAW,GACT,4HACA,WACI,6BACA,qFACJ,oDACA,SACF;GAbF,UAAA,CAeG,UACA,WAAW,oBAAC,OAAD,EAAO,WAAU,uBAAwB,CAAA,IAAI,IACnD;;CACC,CAAA;AAEf"}
|
|
1
|
+
{"version":3,"file":"select.js","names":[],"sources":["../../../src/components/motion/select.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n createContext,\n type ReactNode,\n useCallback,\n useContext,\n useEffect,\n useId,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { Check, ChevronDown } from \"lucide-react\";\nimport {\n animate,\n type MotionValue,\n motion,\n useMotionValue,\n useMotionValueEvent,\n useReducedMotion,\n useTransform,\n type Variants,\n} from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { type ListboxRow, useListbox } from \"../../hooks/use-listbox\";\nimport { EASE_OUT } from \"../../lib/ease\";\n\n// One progress value drives the surface, gap, corners and chevron. This short\n// spring suits the full reveal distance; each reader clamps its small internal\n// overshoot, so all visible endpoints settle together. Rows share a short\n// reveal so long lists have no late entries.\nconst UNFOLD_SPRING = {\n type: \"spring\",\n visualDuration: 0.2,\n bounce: 0.12,\n} as const;\n// Exits are faster than entrances: the panel folds back on a short ease.\nconst UNFOLD_EXIT = { duration: 0.2, ease: EASE_OUT } as const;\nconst RADIUS = 12;\n// How far the open panel sits from the trigger once it has pulled away.\nconst GAP = 8;\n// The surface starts as a thin lip flush against the trigger's edge.\nconst LIP = 8;\nconst lerp = (a: number, b: number, t: number) => a + (b - a) * t;\n\nconst ITEM_VARIANTS: Variants = {\n // A shared short reveal keeps late rows in long, scrolled lists ready with\n // the surface. Per-index staggering can delay visible rows by over a second.\n hidden: { opacity: 0, y: -4, transition: { duration: 0.08, ease: EASE_OUT } },\n show: { opacity: 1, y: 0, transition: { duration: 0.12, ease: EASE_OUT } },\n};\n\ntype Placement = \"bottom\" | \"top\";\n\ninterface SelectContextValue {\n value: string | undefined;\n open: boolean;\n setOpen: (open: boolean) => void;\n select: (value: string) => void;\n register: (value: string, label: string, disabled: boolean) => void;\n unregister: (value: string) => void;\n labelFor: (value: string | undefined) => string | undefined;\n rows: ListboxRow[];\n /** Closes the panel; focus inside it returns to the trigger. */\n close: () => void;\n reduce: boolean;\n progress: MotionValue<number>;\n triggerId: string;\n listId: string;\n disabled: boolean;\n placement: Placement;\n setPlacement: (p: Placement) => void;\n}\n\nconst SelectContext = createContext<SelectContextValue | null>(null);\n// The option keyboard focus is on, resolved during render by the content.\nconst ActiveOptionContext = createContext<string | undefined>(undefined);\n\nfunction useSelectContext(component: string) {\n const ctx = useContext(SelectContext);\n if (!ctx) throw new Error(`${component} must be used within <Select>`);\n return ctx;\n}\n\nexport interface SelectProps {\n value?: string;\n defaultValue?: string;\n onValueChange?: (value: string) => void;\n /**\n * Controlled open state of the panel. A layout that stacks selects can hold\n * this to keep exactly one panel open — the panel is absolutely positioned\n * inside its field, so two open at once paint over each other's options.\n */\n open?: boolean;\n /** Uncontrolled initial open state. Default false. */\n defaultOpen?: boolean;\n /**\n * Fires whenever the panel opens or closes. The panel is absolutely\n * positioned inside the field, so a layout that stacks selects has to know\n * which one is open to paint it above its neighbours.\n */\n onOpenChange?: (open: boolean) => void;\n disabled?: boolean;\n className?: string;\n children: ReactNode;\n}\n\nexport function Select({\n value,\n defaultValue,\n onValueChange,\n open: openProp,\n defaultOpen = false,\n onOpenChange,\n disabled = false,\n className,\n children,\n}: SelectProps) {\n const reduce = useReducedMotion() ?? false;\n const baseId = useId();\n const rootRef = useRef<HTMLDivElement>(null);\n const [internalOpen, setInternalOpen] = useState(defaultOpen);\n const [internal, setInternal] = useState(defaultValue);\n const [labels, setLabels] = useState<Map<string, { label: string; disabled: boolean }>>(\n new Map(),\n );\n const [placement, setPlacement] = useState<Placement>(\"bottom\");\n\n const controlled = value !== undefined;\n const current = controlled ? value : internal;\n const openControlled = openProp !== undefined;\n const open = openControlled ? openProp : internalOpen;\n const progress = useMotionValue(open ? 1 : 0);\n\n const setOpen = useCallback(\n (next: boolean) => {\n if (!openControlled) setInternalOpen(next);\n onOpenChange?.(next);\n },\n [onOpenChange, openControlled],\n );\n\n // The panel turns inert as it closes, which would drop focus held inside it\n // on the page body. Hand it back to the trigger before that happens.\n const close = useCallback(() => {\n const trigger = document.getElementById(`${baseId}-trigger`);\n if (rootRef.current?.contains(document.activeElement) && document.activeElement !== trigger)\n trigger?.focus();\n setOpen(false);\n }, [baseId, setOpen]);\n\n const select = useCallback(\n (next: string) => {\n if (!controlled) setInternal(next);\n onValueChange?.(next);\n close();\n },\n [controlled, onValueChange, close],\n );\n\n const register = useCallback((v: string, label: string, disabled: boolean) => {\n setLabels((m) => {\n const entry = m.get(v);\n if (entry?.label === label && entry.disabled === disabled) return m;\n return new Map(m).set(v, { label, disabled });\n });\n }, []);\n const unregister = useCallback((v: string) => {\n setLabels((m) => {\n if (!m.has(v)) return m;\n const next = new Map(m);\n next.delete(v);\n return next;\n });\n }, []);\n\n // Reduced motion has no travel, so the progress only carries a short fade.\n useEffect(() => {\n const animation = animate(\n progress,\n open ? 1 : 0,\n reduce ? { duration: 0.12 } : open ? UNFOLD_SPRING : UNFOLD_EXIT,\n );\n return () => animation.stop();\n }, [open, progress, reduce]);\n\n // close on outside pointer / escape\n useEffect(() => {\n if (!open) return;\n const onKey = (e: KeyboardEvent) => e.key === \"Escape\" && close();\n const onPointer = (e: PointerEvent) => {\n if (rootRef.current && !rootRef.current.contains(e.target as Node)) setOpen(false);\n };\n window.addEventListener(\"keydown\", onKey);\n window.addEventListener(\"pointerdown\", onPointer);\n return () => {\n window.removeEventListener(\"keydown\", onKey);\n window.removeEventListener(\"pointerdown\", onPointer);\n };\n }, [open, setOpen, close]);\n\n const rows = useMemo(\n () =>\n Array.from(labels, ([id, entry]) => ({\n id,\n label: entry.label,\n disabled: entry.disabled,\n })),\n [labels],\n );\n\n const ctx = useMemo<SelectContextValue>(\n () => ({\n value: current,\n open,\n setOpen,\n select,\n register,\n unregister,\n labelFor: (v) => (v === undefined ? undefined : labels.get(v)?.label),\n rows,\n close,\n reduce,\n progress,\n triggerId: `${baseId}-trigger`,\n listId: `${baseId}-list`,\n disabled,\n placement,\n setPlacement,\n }),\n [\n current,\n open,\n setOpen,\n select,\n register,\n unregister,\n labels,\n rows,\n close,\n reduce,\n progress,\n baseId,\n disabled,\n placement,\n ],\n );\n\n return (\n <SelectContext.Provider value={ctx}>\n <div ref={rootRef} className={cn(\"relative\", className)}>\n {children}\n </div>\n </SelectContext.Provider>\n );\n}\n\nexport interface SelectTriggerProps {\n className?: string;\n children: ReactNode;\n}\n\nexport function SelectTrigger({ className, children }: SelectTriggerProps) {\n const ctx = useSelectContext(\"SelectTrigger\");\n const isTop = ctx.placement === \"top\";\n // The edge facing the panel flattens while the panel is attached to it and\n // rounds back as the panel pulls away — the two pinch apart — on the same\n // curve the panel moves on. The far edge stays rounded.\n const nearRadius = useTransform(ctx.progress, [0, 0.2, 0.4, 1], [RADIUS, 0, 0, RADIUS]);\n const rotate = useTransform(ctx.progress, (p) =>\n ctx.reduce ? (ctx.open ? 180 : 0) : Math.min(1, Math.max(0, p)) * 180,\n );\n return (\n <motion.button\n type=\"button\"\n id={ctx.triggerId}\n disabled={ctx.disabled}\n aria-haspopup=\"listbox\"\n aria-expanded={ctx.open}\n aria-controls={ctx.listId}\n onClick={() => ctx.setOpen(!ctx.open)}\n onKeyDown={(event) => {\n if (!ctx.open && (event.key === \"ArrowDown\" || event.key === \"ArrowUp\")) {\n event.preventDefault();\n ctx.setOpen(true);\n }\n }}\n style={{\n borderTopLeftRadius: ctx.reduce || !isTop ? RADIUS : nearRadius,\n borderTopRightRadius: ctx.reduce || !isTop ? RADIUS : nearRadius,\n borderBottomLeftRadius: ctx.reduce || isTop ? RADIUS : nearRadius,\n borderBottomRightRadius: ctx.reduce || isTop ? RADIUS : nearRadius,\n }}\n className={cn(\n \"relative z-10 flex w-full items-center justify-between gap-2 border border-border bg-background px-3 py-2 text-foreground text-sm outline-none transition-colors\",\n \"hover:border-(--color-border-strong) focus-visible:ring-2 focus-visible:ring-foreground/20\",\n \"disabled:pointer-events-none disabled:opacity-50\",\n className,\n )}\n >\n {children}\n <motion.span aria-hidden style={{ rotate }} className=\"text-muted-foreground\">\n <ChevronDown className=\"h-4 w-4\" />\n </motion.span>\n </motion.button>\n );\n}\n\nexport interface SelectValueProps {\n placeholder?: string;\n className?: string;\n}\n\nexport function SelectValue({ placeholder, className }: SelectValueProps) {\n const ctx = useSelectContext(\"SelectValue\");\n const label = ctx.labelFor(ctx.value);\n return (\n <span className={cn(label ? \"text-foreground\" : \"text-muted-foreground\", className)}>\n {label ?? placeholder ?? \"Select\"}\n </span>\n );\n}\n\nexport interface SelectContentProps {\n className?: string;\n children: ReactNode;\n}\n\nexport function SelectContent({ className, children }: SelectContentProps) {\n const ctx = useSelectContext(\"SelectContent\");\n const panelRef = useRef<HTMLDivElement>(null);\n const [height, setHeight] = useState(0);\n const { open, progress, reduce, setPlacement } = ctx;\n const { activeId, onKeyDown } = useListbox({\n open,\n rows: ctx.rows,\n selected: ctx.value,\n list: panelRef,\n });\n\n // Keep descendants laid out while hidden: display:none resets nested\n // scrollers in Chromium. Collapse only the hidden outer footprint after\n // exit so it cannot extend page scrolling. Opening restores the full box\n // before measurement or focus; neither layout change is animated.\n const [exiting, setExiting] = useState(false);\n const [wasOpen, setWasOpen] = useState(open);\n if (open !== wasOpen) {\n setWasOpen(open);\n if (!open) setExiting(true);\n }\n const present = open || exiting;\n useMotionValueEvent(progress, \"animationComplete\", () => {\n if (progress.get() === 0) setExiting(false);\n });\n\n useLayoutEffect(() => {\n const node = panelRef.current;\n if (!node || !present) return;\n const measure = () => setHeight(node.offsetHeight);\n measure();\n const observer = new ResizeObserver(measure);\n observer.observe(node);\n return () => observer.disconnect();\n }, [present]);\n\n // On open, flip upward when there isn't room below and there's more above.\n useLayoutEffect(() => {\n if (!open) return;\n const trigger = document.getElementById(ctx.triggerId);\n const node = panelRef.current;\n if (!trigger || !node) return;\n const rect = trigger.getBoundingClientRect();\n const h = node.offsetHeight;\n const below = window.innerHeight - rect.bottom;\n const above = rect.top;\n setPlacement(below < h + 16 && above > below ? \"top\" : \"bottom\");\n }, [open, ctx.triggerId, setPlacement]);\n\n const isTop = ctx.placement === \"top\";\n\n // Reveal a full-size panel from its near edge. No ancestor scales the list,\n // so rows, borders and shadow keep their natural thickness. The clip and\n // corner writes can paint; only the gap uses a transform. All read one\n // progress value, with no animated layout properties.\n const ready = height > 0 && !reduce;\n const fromY = ready ? (isTop ? GAP : -GAP) : 0;\n const detach = useTransform(progress, [0.4, 1], [0, 1]);\n const y = useTransform(detach, (d) => lerp(fromY, 0, d));\n const nearRadius = useTransform(detach, (d) => (ready ? RADIUS * d : RADIUS));\n const borderRadius = useTransform(nearRadius, (near) =>\n isTop\n ? `${RADIUS}px ${RADIUS}px ${near}px ${near}px`\n : `${near}px ${near}px ${RADIUS}px ${RADIUS}px`,\n );\n const clipPath = useTransform([progress, nearRadius], ([p, near]: number[]) => {\n if (!ready) return \"none\";\n // Clamp overshoot so the clip never extends into the trigger or exposes\n // overflowing children. At rest remove it so the native shadow is whole.\n const reveal = Math.min(1, Math.max(0, p));\n if (reveal === 1) return \"none\";\n const hidden = Math.max(0, (height - LIP) * (1 - reveal));\n const inset = isTop ? `${hidden}px 0 0 0` : `0 0 ${hidden}px 0`;\n const corners = isTop\n ? `${RADIUS}px ${RADIUS}px ${near}px ${near}px`\n : `${near}px ${near}px ${RADIUS}px ${RADIUS}px`;\n return `inset(${inset} round ${corners})`;\n });\n // The surface materialises over its first frames rather than popping in as\n // a lip; with reduced motion the fade is the whole entrance.\n const opacity = useTransform(progress, reduce ? [0, 1] : [0, 0.12], [0, 1]);\n\n return (\n <motion.div\n ref={panelRef}\n id={ctx.listId}\n role=\"listbox\"\n aria-labelledby={ctx.triggerId}\n aria-hidden={!open}\n inert={!open}\n onKeyDown={(event) => {\n // Tab leaves the list from the trigger, so focus moves on to the\n // control after the select rather than into the closing panel.\n if (event.key === \"Tab\") ctx.close();\n else onKeyDown(event);\n }}\n style={{\n visibility: present ? undefined : \"hidden\",\n maxHeight: present ? undefined : 0,\n borderWidth: present ? undefined : 0,\n y,\n clipPath,\n borderRadius,\n opacity,\n pointerEvents: open ? \"auto\" : \"none\",\n marginTop: isTop ? 0 : GAP,\n marginBottom: isTop ? GAP : 0,\n }}\n // flush against the trigger, then separates into its own rounded pill;\n // sits above or below depending on available space\n className={cn(\n \"absolute right-0 left-0 z-20 overflow-hidden border border-border bg-background shadow-lg\",\n isTop ? \"bottom-full\" : \"top-full\",\n className,\n )}\n >\n <ActiveOptionContext.Provider value={activeId}>\n <motion.div initial={false} animate={open ? \"show\" : \"hidden\"} className=\"p-1\">\n {children}\n </motion.div>\n </ActiveOptionContext.Provider>\n </motion.div>\n );\n}\n\nexport interface SelectItemProps {\n value: string;\n disabled?: boolean;\n className?: string;\n children: ReactNode;\n}\n\nexport function SelectItem({ value, disabled = false, className, children }: SelectItemProps) {\n const ctx = useSelectContext(\"SelectItem\");\n const activeId = useContext(ActiveOptionContext);\n const selected = ctx.value === value;\n const label = typeof children === \"string\" ? children : value;\n\n useLayoutEffect(() => {\n ctx.register(value, label, disabled);\n }, [ctx.register, value, label, disabled]);\n useLayoutEffect(() => () => ctx.unregister(value), [ctx.unregister, value]);\n\n return (\n <motion.div variants={ctx.reduce ? undefined : ITEM_VARIANTS}>\n <button\n type=\"button\"\n role=\"option\"\n aria-selected={selected}\n disabled={disabled}\n // One tab stop: the active option, which focus follows while open.\n tabIndex={activeId === value ? 0 : -1}\n data-listbox-id={value}\n onClick={() => ctx.select(value)}\n className={cn(\n \"flex w-full items-center justify-between gap-2 rounded-lg px-2.5 py-1.5 text-left text-sm outline-none transition-colors\",\n selected\n ? \"bg-muted text-foreground\"\n : \"text-muted-foreground hover:bg-muted hover:text-foreground focus-visible:bg-muted\",\n \"disabled:pointer-events-none disabled:opacity-50\",\n className,\n )}\n >\n {children}\n {selected ? <Check className=\"h-3.5 w-3.5 shrink-0\" /> : null}\n </button>\n </motion.div>\n );\n}\n"],"mappings":";;;;;;;;;AAkCA,MAAM,gBAAgB;CACpB,MAAM;CACN,gBAAgB;CAChB,QAAQ;AACV;AAEA,MAAM,cAAc;CAAE,UAAU;CAAK,MAAM;AAAS;AACpD,MAAM,SAAS;AAEf,MAAM,MAAM;AAEZ,MAAM,MAAM;AACZ,MAAM,QAAQ,GAAW,GAAW,MAAc,KAAK,IAAI,KAAK;AAEhE,MAAM,gBAA0B;CAG9B,QAAQ;EAAE,SAAS;EAAG,GAAG;EAAI,YAAY;GAAE,UAAU;GAAM,MAAM;EAAS;CAAE;CAC5E,MAAM;EAAE,SAAS;EAAG,GAAG;EAAG,YAAY;GAAE,UAAU;GAAM,MAAM;EAAS;CAAE;AAC3E;AAwBA,MAAM,gBAAgB,cAAyC,IAAI;AAEnE,MAAM,sBAAsB,cAAkC,KAAA,CAAS;AAEvE,SAAS,iBAAiB,WAAmB;CAC3C,MAAM,MAAM,WAAW,aAAa;CACpC,IAAI,CAAC,KAAK,MAAM,IAAI,MAAM,GAAG,UAAU,8BAA8B;CACrE,OAAO;AACT;AAyBA,SAAgB,OAAO,EACrB,OACA,cACA,eACA,MAAM,UACN,cAAc,OACd,cACA,WAAW,OACX,WACA,YACc;CACd,MAAM,SAAS,iBAAiB,KAAK;CACrC,MAAM,SAAS,MAAM;CACrB,MAAM,UAAU,OAAuB,IAAI;CAC3C,MAAM,CAAC,cAAc,mBAAmB,SAAS,WAAW;CAC5D,MAAM,CAAC,UAAU,eAAe,SAAS,YAAY;CACrD,MAAM,CAAC,QAAQ,aAAa,yBAC1B,IAAI,IAAI,CACV;CACA,MAAM,CAAC,WAAW,gBAAgB,SAAoB,QAAQ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,IAAI;GACvB,cAAc,QAAQ,MAAM;EAC9B;EAGA,WAAW,GACT,6FACA,QAAQ,gBAAgB,YACxB,SACF;EAEA,UAAA,oBAAC,oBAAoB,UAArB;GAA8B,OAAO;GACnC,UAAA,oBAAC,OAAO,KAAR;IAAY,SAAS;IAAO,SAAS,OAAO,SAAS;IAAU,WAAU;IACtE;GACS,CAAA;EACgB,CAAA;CACpB,CAAA;AAEhB;AASA,SAAgB,WAAW,EAAE,OAAO,WAAW,OAAO,WAAW,YAA6B;CAC5F,MAAM,MAAM,iBAAiB,YAAY;CACzC,MAAM,WAAW,WAAW,mBAAmB;CAC/C,MAAM,WAAW,IAAI,UAAU;CAC/B,MAAM,QAAQ,OAAO,aAAa,WAAW,WAAW;CAExD,sBAAsB;EACpB,IAAI,SAAS,OAAO,OAAO,QAAQ;CACrC,GAAG;EAAC,IAAI;EAAU;EAAO;EAAO;CAAQ,CAAC;CACzC,4BAA4B,IAAI,WAAW,KAAK,GAAG,CAAC,IAAI,YAAY,KAAK,CAAC;CAE1E,OACE,oBAAC,OAAO,KAAR;EAAY,UAAU,IAAI,SAAS,KAAA,IAAY;EAC7C,UAAA,qBAAC,UAAD;GACE,MAAK;GACL,MAAK;GACL,iBAAe;GACL;GAEV,UAAU,aAAa,QAAQ,IAAI;GACnC,mBAAiB;GACjB,eAAe,IAAI,OAAO,KAAK;GAC/B,WAAW,GACT,4HACA,WACI,6BACA,qFACJ,oDACA,SACF;GAhBF,UAAA,CAkBG,UACA,WAAW,oBAAC,OAAD,EAAO,WAAU,uBAAwB,CAAA,IAAI,IACnD;;CACE,CAAA;AAEhB"}
|
|
@@ -29,8 +29,9 @@ export type ShaderBackgroundProps = { [K in ShaderBackgroundVariant]: {
|
|
|
29
29
|
} & ShaderVariantProps[K]; }[ShaderBackgroundVariant];
|
|
30
30
|
export declare const SHADER_BACKGROUND_VARIANTS: ShaderBackgroundVariant[];
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
32
|
+
* Reduced motion freezes every animating variant at speed 0, whether or not
|
|
33
|
+
* the caller passed `speed`: the shaders animate by default when it is left
|
|
34
|
+
* out.
|
|
34
35
|
*/
|
|
35
36
|
export declare function ShaderBackground({ variant, className, ...rest }: ShaderBackgroundProps): import("react").JSX.Element;
|
|
36
37
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shader-background.d.ts","names":[],"sources":["../../../src/components/motion/shader-background.tsx"],"mappings":";;KAmDK;EACH,iBAAiB;EACjB,kBAAkB;EAClB,YAAY;EACZ,aAAa;EACb,MAAM;EACN,OAAO;EACP,OAAO;EACP,SAAS;EACT,OAAO;EACP,cAAc;EACd,0BAA0B;EAC1B,eAAe;EACf,WAAW;EACX,YAAY;EACZ,QAAQ;EACR,WAAW;EACX,kBAAkB;EAClB,gBAAgB;EAChB,wBAAwB;EACxB,iBAAiB;EACjB,gBAAgB;;YAGN,gCAAgC;YAEhC,2BACT,KAAK;EAA4B,SAAS;IAAM,mBAAmB,MACpE;qBA4BW,4BAER
|
|
1
|
+
{"version":3,"file":"shader-background.d.ts","names":[],"sources":["../../../src/components/motion/shader-background.tsx"],"mappings":";;KAmDK;EACH,iBAAiB;EACjB,kBAAkB;EAClB,YAAY;EACZ,aAAa;EACb,MAAM;EACN,OAAO;EACP,OAAO;EACP,SAAS;EACT,OAAO;EACP,cAAc;EACd,0BAA0B;EAC1B,eAAe;EACf,WAAW;EACX,YAAY;EACZ,QAAQ;EACR,WAAW;EACX,kBAAkB;EAClB,gBAAgB;EAChB,wBAAwB;EACxB,iBAAiB;EACjB,gBAAgB;;YAGN,gCAAgC;YAEhC,2BACT,KAAK;EAA4B,SAAS;IAAM,mBAAmB,MACpE;qBA4BW,4BAER;;;;;;wBAaW,mBAAmB,SAAS,cAAc,QAAQ,wCAAqB,IAAA"}
|
|
@@ -29,14 +29,20 @@ const VARIANT_COMPONENTS = {
|
|
|
29
29
|
};
|
|
30
30
|
const SHADER_BACKGROUND_VARIANTS = Object.keys(VARIANT_COMPONENTS);
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
32
|
+
* Variants with no `speed` param: static patterns that never animate, and that
|
|
33
|
+
* would pass an unknown `speed` through to their DOM node.
|
|
34
|
+
*/
|
|
35
|
+
const STATIC_VARIANTS = /* @__PURE__ */ new Set(["dot-grid", "waves"]);
|
|
36
|
+
/**
|
|
37
|
+
* Reduced motion freezes every animating variant at speed 0, whether or not
|
|
38
|
+
* the caller passed `speed`: the shaders animate by default when it is left
|
|
39
|
+
* out.
|
|
34
40
|
*/
|
|
35
41
|
function ShaderBackground({ variant, className, ...rest }) {
|
|
36
42
|
const reducedMotion = useReducedMotion();
|
|
37
43
|
const Shader = VARIANT_COMPONENTS[variant];
|
|
38
44
|
const props = rest;
|
|
39
|
-
const speedProps = reducedMotion &&
|
|
45
|
+
const speedProps = reducedMotion && !STATIC_VARIANTS.has(variant) ? { speed: 0 } : {};
|
|
40
46
|
return /* @__PURE__ */ jsx(Shader, {
|
|
41
47
|
...props,
|
|
42
48
|
...speedProps,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shader-background.js","names":[],"sources":["../../../src/components/motion/shader-background.tsx"],"sourcesContent":["\"use client\";\n\nimport type { ComponentType } from \"react\";\nimport {\n ColorPanels,\n type ColorPanelsProps,\n Dithering,\n type DitheringProps,\n DotGrid,\n type DotGridProps,\n DotOrbit,\n type DotOrbitProps,\n GodRays,\n type GodRaysProps,\n GrainGradient,\n type GrainGradientProps,\n MeshGradient,\n type MeshGradientProps,\n Metaballs,\n type MetaballsProps,\n NeuroNoise,\n type NeuroNoiseProps,\n PerlinNoise,\n type PerlinNoiseProps,\n PulsingBorder,\n type PulsingBorderProps,\n SimplexNoise,\n type SimplexNoiseProps,\n SmokeRing,\n type SmokeRingProps,\n Spiral,\n type SpiralProps,\n StaticMeshGradient,\n type StaticMeshGradientProps,\n StaticRadialGradient,\n type StaticRadialGradientProps,\n Swirl,\n type SwirlProps,\n Voronoi,\n type VoronoiProps,\n Warp,\n type WarpProps,\n Water,\n type WaterProps,\n Waves,\n type WavesProps,\n} from \"@paper-design/shaders-react\";\nimport { useReducedMotion } from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\n\ntype ShaderVariantProps = {\n \"mesh-gradient\": MeshGradientProps;\n \"grain-gradient\": GrainGradientProps;\n \"dot-grid\": DotGridProps;\n \"dot-orbit\": DotOrbitProps;\n warp: WarpProps;\n waves: WavesProps;\n water: WaterProps;\n voronoi: VoronoiProps;\n swirl: SwirlProps;\n \"smoke-ring\": SmokeRingProps;\n \"static-radial-gradient\": StaticRadialGradientProps;\n \"neuro-noise\": NeuroNoiseProps;\n metaballs: MetaballsProps;\n \"god-rays\": GodRaysProps;\n spiral: SpiralProps;\n dithering: DitheringProps;\n \"pulsing-border\": PulsingBorderProps;\n \"color-panels\": ColorPanelsProps;\n \"static-mesh-gradient\": StaticMeshGradientProps;\n \"simplex-noise\": SimplexNoiseProps;\n \"perlin-noise\": PerlinNoiseProps;\n};\n\nexport type ShaderBackgroundVariant = keyof ShaderVariantProps;\n\nexport type ShaderBackgroundProps = {\n [K in ShaderBackgroundVariant]: { variant: K } & ShaderVariantProps[K];\n}[ShaderBackgroundVariant];\n\nconst VARIANT_COMPONENTS: {\n [K in ShaderBackgroundVariant]: ComponentType<ShaderVariantProps[K]>;\n} = {\n \"mesh-gradient\": MeshGradient,\n \"grain-gradient\": GrainGradient,\n \"dot-grid\": DotGrid,\n \"dot-orbit\": DotOrbit,\n warp: Warp,\n waves: Waves,\n water: Water,\n voronoi: Voronoi,\n swirl: Swirl,\n \"smoke-ring\": SmokeRing,\n \"static-radial-gradient\": StaticRadialGradient,\n \"neuro-noise\": NeuroNoise,\n metaballs: Metaballs,\n \"god-rays\": GodRays,\n spiral: Spiral,\n dithering: Dithering,\n \"pulsing-border\": PulsingBorder,\n \"color-panels\": ColorPanels,\n \"static-mesh-gradient\": StaticMeshGradient,\n \"simplex-noise\": SimplexNoise,\n \"perlin-noise\": PerlinNoise,\n};\n\nexport const SHADER_BACKGROUND_VARIANTS = Object.keys(\n VARIANT_COMPONENTS,\n) as ShaderBackgroundVariant[];\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"shader-background.js","names":[],"sources":["../../../src/components/motion/shader-background.tsx"],"sourcesContent":["\"use client\";\n\nimport type { ComponentType } from \"react\";\nimport {\n ColorPanels,\n type ColorPanelsProps,\n Dithering,\n type DitheringProps,\n DotGrid,\n type DotGridProps,\n DotOrbit,\n type DotOrbitProps,\n GodRays,\n type GodRaysProps,\n GrainGradient,\n type GrainGradientProps,\n MeshGradient,\n type MeshGradientProps,\n Metaballs,\n type MetaballsProps,\n NeuroNoise,\n type NeuroNoiseProps,\n PerlinNoise,\n type PerlinNoiseProps,\n PulsingBorder,\n type PulsingBorderProps,\n SimplexNoise,\n type SimplexNoiseProps,\n SmokeRing,\n type SmokeRingProps,\n Spiral,\n type SpiralProps,\n StaticMeshGradient,\n type StaticMeshGradientProps,\n StaticRadialGradient,\n type StaticRadialGradientProps,\n Swirl,\n type SwirlProps,\n Voronoi,\n type VoronoiProps,\n Warp,\n type WarpProps,\n Water,\n type WaterProps,\n Waves,\n type WavesProps,\n} from \"@paper-design/shaders-react\";\nimport { useReducedMotion } from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\n\ntype ShaderVariantProps = {\n \"mesh-gradient\": MeshGradientProps;\n \"grain-gradient\": GrainGradientProps;\n \"dot-grid\": DotGridProps;\n \"dot-orbit\": DotOrbitProps;\n warp: WarpProps;\n waves: WavesProps;\n water: WaterProps;\n voronoi: VoronoiProps;\n swirl: SwirlProps;\n \"smoke-ring\": SmokeRingProps;\n \"static-radial-gradient\": StaticRadialGradientProps;\n \"neuro-noise\": NeuroNoiseProps;\n metaballs: MetaballsProps;\n \"god-rays\": GodRaysProps;\n spiral: SpiralProps;\n dithering: DitheringProps;\n \"pulsing-border\": PulsingBorderProps;\n \"color-panels\": ColorPanelsProps;\n \"static-mesh-gradient\": StaticMeshGradientProps;\n \"simplex-noise\": SimplexNoiseProps;\n \"perlin-noise\": PerlinNoiseProps;\n};\n\nexport type ShaderBackgroundVariant = keyof ShaderVariantProps;\n\nexport type ShaderBackgroundProps = {\n [K in ShaderBackgroundVariant]: { variant: K } & ShaderVariantProps[K];\n}[ShaderBackgroundVariant];\n\nconst VARIANT_COMPONENTS: {\n [K in ShaderBackgroundVariant]: ComponentType<ShaderVariantProps[K]>;\n} = {\n \"mesh-gradient\": MeshGradient,\n \"grain-gradient\": GrainGradient,\n \"dot-grid\": DotGrid,\n \"dot-orbit\": DotOrbit,\n warp: Warp,\n waves: Waves,\n water: Water,\n voronoi: Voronoi,\n swirl: Swirl,\n \"smoke-ring\": SmokeRing,\n \"static-radial-gradient\": StaticRadialGradient,\n \"neuro-noise\": NeuroNoise,\n metaballs: Metaballs,\n \"god-rays\": GodRays,\n spiral: Spiral,\n dithering: Dithering,\n \"pulsing-border\": PulsingBorder,\n \"color-panels\": ColorPanels,\n \"static-mesh-gradient\": StaticMeshGradient,\n \"simplex-noise\": SimplexNoise,\n \"perlin-noise\": PerlinNoise,\n};\n\nexport const SHADER_BACKGROUND_VARIANTS = Object.keys(\n VARIANT_COMPONENTS,\n) as ShaderBackgroundVariant[];\n\n/**\n * Variants with no `speed` param: static patterns that never animate, and that\n * would pass an unknown `speed` through to their DOM node.\n */\nconst STATIC_VARIANTS = new Set<ShaderBackgroundVariant>([\"dot-grid\", \"waves\"]);\n\n/**\n * Reduced motion freezes every animating variant at speed 0, whether or not\n * the caller passed `speed`: the shaders animate by default when it is left\n * out.\n */\nexport function ShaderBackground({ variant, className, ...rest }: ShaderBackgroundProps) {\n const reducedMotion = useReducedMotion();\n const Shader = VARIANT_COMPONENTS[variant] as ComponentType<Record<string, unknown>>;\n const props = rest as Record<string, unknown>;\n const speedProps = reducedMotion && !STATIC_VARIANTS.has(variant) ? { speed: 0 } : {};\n\n return <Shader {...props} {...speedProps} className={cn(\"h-full w-full\", className)} />;\n}\n"],"mappings":";;;;;;AAiFA,MAAM,qBAEF;CACF,iBAAiB;CACjB,kBAAkB;CAClB,YAAY;CACZ,aAAa;CACb,MAAM;CACN,OAAO;CACP,OAAO;CACP,SAAS;CACT,OAAO;CACP,cAAc;CACd,0BAA0B;CAC1B,eAAe;CACf,WAAW;CACX,YAAY;CACZ,QAAQ;CACR,WAAW;CACX,kBAAkB;CAClB,gBAAgB;CAChB,wBAAwB;CACxB,iBAAiB;CACjB,gBAAgB;AAClB;AAEA,MAAa,6BAA6B,OAAO,KAC/C,kBACF;;;;;AAMA,MAAM,kCAAkB,IAAI,IAA6B,CAAC,YAAY,OAAO,CAAC;;;;;;AAO9E,SAAgB,iBAAiB,EAAE,SAAS,WAAW,GAAG,QAA+B;CACvF,MAAM,gBAAgB,iBAAiB;CACvC,MAAM,SAAS,mBAAmB;CAClC,MAAM,QAAQ;CACd,MAAM,aAAa,iBAAiB,CAAC,gBAAgB,IAAI,OAAO,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC;CAEpF,OAAO,oBAAC,QAAD;EAAQ,GAAI;EAAO,GAAI;EAAY,WAAW,GAAG,iBAAiB,SAAS;CAAI,CAAA;AACxF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared-layout-bg.d.ts","names":[],"sources":["../../../src/components/motion/shared-layout-bg.tsx"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"shared-layout-bg.d.ts","names":[],"sources":["../../../src/components/motion/shared-layout-bg.tsx"],"mappings":";;iBA4BiB,4BAA4B,KAAK,eAAe;EAC/D,UAAU;;EAEV;;EAEA;;EAEA;;EAEA;;qBAeW,gCAAc,0BAAA,sCAAA,cAAA"}
|