@kumix/ui 0.3.6 → 0.3.8
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 +25 -24
- package/dist/cascader-types-BnH6wYD-.d.ts +183 -0
- package/dist/cascader-types-BnH6wYD-.d.ts.map +1 -0
- package/dist/components/agents/ai-sidebar.d.ts +17 -1
- package/dist/components/agents/ai-sidebar.d.ts.map +1 -1
- package/dist/components/agents/ai-sidebar.js +90 -14
- package/dist/components/agents/ai-sidebar.js.map +1 -1
- package/dist/components/agents/chat-app.d.ts +10 -5
- package/dist/components/agents/chat-app.d.ts.map +1 -1
- package/dist/components/agents/chat-app.js +54 -5
- package/dist/components/agents/chat-app.js.map +1 -1
- package/dist/components/agents/citations.d.ts.map +1 -1
- package/dist/components/agents/citations.js +5 -6
- package/dist/components/agents/citations.js.map +1 -1
- package/dist/components/agents/tool-approval.d.ts.map +1 -1
- package/dist/components/agents/tool-approval.js +1 -1
- package/dist/components/agents/tool-approval.js.map +1 -1
- package/dist/components/motion/action-swap.d.ts.map +1 -1
- package/dist/components/motion/action-swap.js +2 -2
- package/dist/components/motion/action-swap.js.map +1 -1
- package/dist/components/motion/animated-sidebar.d.ts.map +1 -1
- package/dist/components/motion/animated-sidebar.js +13 -3
- package/dist/components/motion/animated-sidebar.js.map +1 -1
- package/dist/components/motion/attachment-upload.d.ts.map +1 -1
- package/dist/components/motion/attachment-upload.js +9 -5
- package/dist/components/motion/attachment-upload.js.map +1 -1
- package/dist/components/motion/availability-scheduler/copy-menu.js +1 -1
- package/dist/components/motion/availability-scheduler/day-row.d.ts +5 -2
- package/dist/components/motion/availability-scheduler/day-row.d.ts.map +1 -1
- package/dist/components/motion/availability-scheduler/day-row.js +18 -8
- package/dist/components/motion/availability-scheduler/day-row.js.map +1 -1
- package/dist/components/motion/availability-scheduler/index.d.ts.map +1 -1
- package/dist/components/motion/availability-scheduler/index.js +27 -5
- package/dist/components/motion/availability-scheduler/index.js.map +1 -1
- package/dist/components/motion/availability-scheduler/time-select.d.ts +3 -1
- package/dist/components/motion/availability-scheduler/time-select.d.ts.map +1 -1
- package/dist/components/motion/availability-scheduler/time-select.js +3 -1
- package/dist/components/motion/availability-scheduler/time-select.js.map +1 -1
- package/dist/components/motion/bottom-sheet.d.ts.map +1 -1
- package/dist/components/motion/bottom-sheet.js +78 -74
- package/dist/components/motion/bottom-sheet.js.map +1 -1
- package/dist/components/motion/center-morph-modal.d.ts.map +1 -1
- package/dist/components/motion/center-morph-modal.js +82 -88
- package/dist/components/motion/center-morph-modal.js.map +1 -1
- package/dist/components/motion/command-palette.d.ts.map +1 -1
- package/dist/components/motion/command-palette.js +51 -27
- package/dist/components/motion/command-palette.js.map +1 -1
- package/dist/components/motion/context-menu.d.ts.map +1 -1
- package/dist/components/motion/context-menu.js +16 -6
- package/dist/components/motion/context-menu.js.map +1 -1
- package/dist/components/motion/cylinder-carousel.d.ts.map +1 -1
- package/dist/components/motion/cylinder-carousel.js +4 -3
- package/dist/components/motion/cylinder-carousel.js.map +1 -1
- package/dist/components/motion/drawer.d.ts.map +1 -1
- package/dist/components/motion/drawer.js +30 -30
- package/dist/components/motion/drawer.js.map +1 -1
- package/dist/components/motion/expandable-action-bar.d.ts +6 -0
- package/dist/components/motion/expandable-action-bar.d.ts.map +1 -1
- package/dist/components/motion/expandable-action-bar.js +38 -9
- package/dist/components/motion/expandable-action-bar.js.map +1 -1
- package/dist/components/motion/hold-action-button.d.ts +1 -1
- package/dist/components/motion/hold-action-button.d.ts.map +1 -1
- package/dist/components/motion/hold-action-button.js +64 -50
- package/dist/components/motion/hold-action-button.js.map +1 -1
- package/dist/components/motion/loader.js +20 -22
- package/dist/components/motion/loader.js.map +1 -1
- package/dist/components/motion/morphing-modal.d.ts.map +1 -1
- package/dist/components/motion/morphing-modal.js +83 -83
- package/dist/components/motion/morphing-modal.js.map +1 -1
- package/dist/components/motion/morphing-search.d.ts +28 -0
- package/dist/components/motion/morphing-search.d.ts.map +1 -0
- package/dist/components/motion/morphing-search.js +418 -0
- package/dist/components/motion/morphing-search.js.map +1 -0
- package/dist/components/motion/morphing-tabs.d.ts.map +1 -1
- package/dist/components/motion/morphing-tabs.js +59 -18
- package/dist/components/motion/morphing-tabs.js.map +1 -1
- package/dist/components/motion/notification-stack.d.ts.map +1 -1
- package/dist/components/motion/notification-stack.js +28 -11
- package/dist/components/motion/notification-stack.js.map +1 -1
- package/dist/components/motion/popover-morph.d.ts.map +1 -1
- package/dist/components/motion/popover-morph.js +26 -11
- package/dist/components/motion/popover-morph.js.map +1 -1
- package/dist/components/motion/popover.d.ts.map +1 -1
- package/dist/components/motion/popover.js +39 -28
- package/dist/components/motion/popover.js.map +1 -1
- package/dist/components/motion/preview-rail.d.ts.map +1 -1
- package/dist/components/motion/preview-rail.js +42 -13
- package/dist/components/motion/preview-rail.js.map +1 -1
- package/dist/components/motion/project-folder.js +20 -20
- package/dist/components/motion/project-folder.js.map +1 -1
- package/dist/components/motion/pull-to-refresh.d.ts.map +1 -1
- package/dist/components/motion/pull-to-refresh.js +8 -7
- package/dist/components/motion/pull-to-refresh.js.map +1 -1
- package/dist/components/motion/range-slider-bubble.d.ts.map +1 -1
- package/dist/components/motion/range-slider-bubble.js +2 -1
- package/dist/components/motion/range-slider-bubble.js.map +1 -1
- package/dist/components/motion/range-slider-fluid.d.ts.map +1 -1
- package/dist/components/motion/range-slider-fluid.js +2 -1
- package/dist/components/motion/range-slider-fluid.js.map +1 -1
- package/dist/components/motion/range-slider-ruler.d.ts.map +1 -1
- package/dist/components/motion/range-slider-ruler.js +2 -1
- package/dist/components/motion/range-slider-ruler.js.map +1 -1
- package/dist/components/motion/range-slider-wave.d.ts.map +1 -1
- package/dist/components/motion/range-slider-wave.js +2 -1
- package/dist/components/motion/range-slider-wave.js.map +1 -1
- package/dist/components/motion/range-slider.d.ts.map +1 -1
- package/dist/components/motion/range-slider.js +2 -1
- package/dist/components/motion/range-slider.js.map +1 -1
- package/dist/components/motion/select.d.ts +15 -1
- package/dist/components/motion/select.d.ts.map +1 -1
- package/dist/components/motion/select.js +15 -4
- package/dist/components/motion/select.js.map +1 -1
- package/dist/components/motion/slide-action-button.d.ts.map +1 -1
- package/dist/components/motion/slide-action-button.js +3 -2
- package/dist/components/motion/slide-action-button.js.map +1 -1
- package/dist/components/motion/swipeable-list.d.ts.map +1 -1
- package/dist/components/motion/swipeable-list.js +2 -1
- package/dist/components/motion/swipeable-list.js.map +1 -1
- package/dist/components/motion/table/index.d.ts.map +1 -1
- package/dist/components/motion/table/index.js +64 -6
- package/dist/components/motion/table/index.js.map +1 -1
- package/dist/components/motion/table/table-header.d.ts.map +1 -1
- package/dist/components/motion/table/table-header.js +3 -2
- package/dist/components/motion/table/table-header.js.map +1 -1
- package/dist/components/motion/text-reveal.d.ts.map +1 -1
- package/dist/components/motion/text-reveal.js +72 -48
- package/dist/components/motion/text-reveal.js.map +1 -1
- package/dist/components/motion/tooltip.d.ts.map +1 -1
- package/dist/components/motion/tooltip.js +35 -15
- package/dist/components/motion/tooltip.js.map +1 -1
- package/dist/components/motion/wheel-picker.d.ts.map +1 -1
- package/dist/components/motion/wheel-picker.js +4 -3
- package/dist/components/motion/wheel-picker.js.map +1 -1
- package/dist/components/reui/badge.d.ts +1 -1
- package/dist/components/reui/cascader/cascader-async.d.ts +90 -0
- package/dist/components/reui/cascader/cascader-async.d.ts.map +1 -0
- package/dist/components/reui/cascader/cascader-async.js +549 -0
- package/dist/components/reui/cascader/cascader-async.js.map +1 -0
- package/dist/components/reui/cascader/cascader-columns.d.ts +29 -0
- package/dist/components/reui/cascader/cascader-columns.d.ts.map +1 -0
- package/dist/components/reui/cascader/cascader-columns.js +135 -0
- package/dist/components/reui/cascader/cascader-columns.js.map +1 -0
- package/dist/components/reui/cascader/cascader-context.d.ts +193 -0
- package/dist/components/reui/cascader/cascader-context.d.ts.map +1 -0
- package/dist/components/reui/cascader/cascader-context.js +59 -0
- package/dist/components/reui/cascader/cascader-context.js.map +1 -0
- package/dist/components/reui/cascader/cascader-footer.d.ts +85 -0
- package/dist/components/reui/cascader/cascader-footer.d.ts.map +1 -0
- package/dist/components/reui/cascader/cascader-footer.js +456 -0
- package/dist/components/reui/cascader/cascader-footer.js.map +1 -0
- package/dist/components/reui/cascader/cascader-i18n.d.ts +17 -0
- package/dist/components/reui/cascader/cascader-i18n.d.ts.map +1 -0
- package/dist/components/reui/cascader/cascader-i18n.js +68 -0
- package/dist/components/reui/cascader/cascader-i18n.js.map +1 -0
- package/dist/components/reui/cascader/cascader-item.d.ts +115 -0
- package/dist/components/reui/cascader/cascader-item.d.ts.map +1 -0
- package/dist/components/reui/cascader/cascader-item.js +530 -0
- package/dist/components/reui/cascader/cascader-item.js.map +1 -0
- package/dist/components/reui/cascader/cascader-lib.d.ts +141 -0
- package/dist/components/reui/cascader/cascader-lib.d.ts.map +1 -0
- package/dist/components/reui/cascader/cascader-lib.js +576 -0
- package/dist/components/reui/cascader/cascader-lib.js.map +1 -0
- package/dist/components/reui/cascader/cascader-nav.d.ts +59 -0
- package/dist/components/reui/cascader/cascader-nav.d.ts.map +1 -0
- package/dist/components/reui/cascader/cascader-nav.js +312 -0
- package/dist/components/reui/cascader/cascader-nav.js.map +1 -0
- package/dist/components/reui/cascader/cascader-types.d.ts +2 -0
- package/dist/components/reui/cascader/cascader-types.js +2 -0
- package/dist/components/reui/cascader/cascader-virtual.d.ts +65 -0
- package/dist/components/reui/cascader/cascader-virtual.d.ts.map +1 -0
- package/dist/components/reui/cascader/cascader-virtual.js +240 -0
- package/dist/components/reui/cascader/cascader-virtual.js.map +1 -0
- package/dist/components/reui/cascader/cascader.d.ts +322 -0
- package/dist/components/reui/cascader/cascader.d.ts.map +1 -0
- package/dist/components/reui/cascader/cascader.js +1459 -0
- package/dist/components/reui/cascader/cascader.js.map +1 -0
- package/dist/components/reui/event-calendar/event-calendar-event.d.ts +28 -47
- package/dist/components/reui/event-calendar/event-calendar-event.d.ts.map +1 -1
- package/dist/components/reui/event-calendar/event-calendar-event.js +26 -44
- package/dist/components/reui/event-calendar/event-calendar-event.js.map +1 -1
- package/dist/components/reui/event-calendar/event-calendar-nav.js +1 -1
- package/dist/components/reui/event-calendar/event-calendar-types.d.ts +19 -57
- package/dist/components/reui/event-calendar/event-calendar-types.d.ts.map +1 -1
- package/dist/components/reui/filters/filters-advanced.d.ts +52 -0
- package/dist/components/reui/filters/filters-advanced.d.ts.map +1 -0
- package/dist/components/reui/filters/filters-advanced.js +1191 -0
- package/dist/components/reui/filters/filters-advanced.js.map +1 -0
- package/dist/components/reui/filters/filters-builder.d.ts +43 -0
- package/dist/components/reui/filters/filters-builder.d.ts.map +1 -0
- package/dist/components/reui/filters/filters-builder.js +152 -0
- package/dist/components/reui/filters/filters-builder.js.map +1 -0
- package/dist/components/reui/filters/filters-chip.d.ts +79 -0
- package/dist/components/reui/filters/filters-chip.d.ts.map +1 -0
- package/dist/components/reui/filters/filters-chip.js +553 -0
- package/dist/components/reui/filters/filters-chip.js.map +1 -0
- package/dist/components/reui/filters/filters-context.d.ts +290 -0
- package/dist/components/reui/filters/filters-context.d.ts.map +1 -0
- package/dist/components/reui/filters/filters-context.js +277 -0
- package/dist/components/reui/filters/filters-context.js.map +1 -0
- package/dist/components/reui/filters/filters-date.d.ts +43 -0
- package/dist/components/reui/filters/filters-date.d.ts.map +1 -0
- package/dist/components/reui/filters/filters-date.js +143 -0
- package/dist/components/reui/filters/filters-date.js.map +1 -0
- package/dist/components/reui/filters/filters-dnd.d.ts +101 -0
- package/dist/components/reui/filters/filters-dnd.d.ts.map +1 -0
- package/dist/components/reui/filters/filters-dnd.js +454 -0
- package/dist/components/reui/filters/filters-dnd.js.map +1 -0
- package/dist/components/reui/filters/filters-draft.d.ts +2 -0
- package/dist/components/reui/filters/filters-draft.js +128 -0
- package/dist/components/reui/filters/filters-draft.js.map +1 -0
- package/dist/components/reui/filters/filters-editors.d.ts +91 -0
- package/dist/components/reui/filters/filters-editors.d.ts.map +1 -0
- package/dist/components/reui/filters/filters-editors.js +773 -0
- package/dist/components/reui/filters/filters-editors.js.map +1 -0
- package/dist/components/reui/filters/filters-i18n.d.ts +24 -0
- package/dist/components/reui/filters/filters-i18n.d.ts.map +1 -0
- package/dist/components/reui/filters/filters-i18n.js +127 -0
- package/dist/components/reui/filters/filters-i18n.js.map +1 -0
- package/dist/components/reui/filters/filters-lib.d.ts +171 -0
- package/dist/components/reui/filters/filters-lib.d.ts.map +1 -0
- package/dist/components/reui/filters/filters-lib.js +336 -0
- package/dist/components/reui/filters/filters-lib.js.map +1 -0
- package/dist/components/reui/filters/filters-operators.d.ts +49 -0
- package/dist/components/reui/filters/filters-operators.d.ts.map +1 -0
- package/dist/components/reui/filters/filters-operators.js +300 -0
- package/dist/components/reui/filters/filters-operators.js.map +1 -0
- package/dist/components/reui/filters/filters-query.d.ts +132 -0
- package/dist/components/reui/filters/filters-query.d.ts.map +1 -0
- package/dist/components/reui/filters/filters-query.js +476 -0
- package/dist/components/reui/filters/filters-query.js.map +1 -0
- package/dist/components/reui/filters/filters-types.d.ts +452 -0
- package/dist/components/reui/filters/filters-types.d.ts.map +1 -0
- package/dist/components/reui/filters/filters-types.js +2 -0
- package/dist/components/reui/filters/filters.d.ts +114 -0
- package/dist/components/reui/filters/filters.d.ts.map +1 -0
- package/dist/components/reui/filters/filters.js +638 -0
- package/dist/components/reui/filters/filters.js.map +1 -0
- package/dist/components/reui/frame.d.ts +1 -1
- package/dist/components/reui/gantt/gantt-bar.js +1 -1
- package/dist/components/reui/gantt/gantt-nav.js +1 -1
- package/dist/components/reui/gantt/gantt-types.d.ts +25 -71
- package/dist/components/reui/gantt/gantt-types.d.ts.map +1 -1
- package/dist/components/reui/gantt/gantt-view.js +1 -1
- package/dist/components/reui/icon-tile.d.ts +1 -1
- 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/checkbox.js +1 -1
- package/dist/components/ui/checkbox.js.map +1 -1
- package/dist/components/ui/field.js +2 -2
- package/dist/components/ui/field.js.map +1 -1
- package/dist/components/ui/item.d.ts +2 -2
- package/dist/components/ui/marker.d.ts +1 -1
- package/dist/components/ui/radio-group.js +1 -1
- package/dist/components/ui/radio-group.js.map +1 -1
- package/dist/components/ui/sidebar.d.ts +1 -1
- package/dist/components/ui/sidebar.js +1 -1
- package/dist/components/ui/switch.js +1 -1
- package/dist/components/ui/switch.js.map +1 -1
- package/dist/components/ui/tabs.d.ts +1 -1
- package/dist/components/ui/toggle.d.ts +1 -1
- package/dist/{copy-menu-Bk5GP9Gp.js → copy-menu-1FKoMc9o.js} +9 -2
- package/dist/copy-menu-1FKoMc9o.js.map +1 -0
- package/dist/filters-draft-DEAl3TO-.d.ts +70 -0
- package/dist/filters-draft-DEAl3TO-.d.ts.map +1 -0
- package/dist/hooks/use-dismiss.d.ts +34 -0
- package/dist/hooks/use-dismiss.d.ts.map +1 -0
- package/dist/hooks/use-dismiss.js +78 -0
- package/dist/hooks/use-dismiss.js.map +1 -0
- package/dist/hooks/use-favicon.d.ts +17 -0
- package/dist/hooks/use-favicon.d.ts.map +1 -0
- package/dist/hooks/use-favicon.js +35 -0
- package/dist/hooks/use-favicon.js.map +1 -0
- package/dist/hooks/use-hover-gesture.d.ts +38 -0
- package/dist/hooks/use-hover-gesture.d.ts.map +1 -0
- package/dist/hooks/use-hover-gesture.js +46 -0
- package/dist/hooks/use-hover-gesture.js.map +1 -0
- package/dist/hooks/use-slider.d.ts.map +1 -1
- package/dist/hooks/use-slider.js +3 -2
- package/dist/hooks/use-slider.js.map +1 -1
- package/dist/hooks/use-tap-gesture.d.ts +47 -0
- package/dist/hooks/use-tap-gesture.d.ts.map +1 -0
- package/dist/hooks/use-tap-gesture.js +51 -0
- package/dist/hooks/use-tap-gesture.js.map +1 -0
- package/dist/hooks/use-touch-capable.d.ts +15 -0
- package/dist/hooks/use-touch-capable.d.ts.map +1 -0
- package/dist/hooks/use-touch-capable.js +29 -0
- package/dist/hooks/use-touch-capable.js.map +1 -0
- package/dist/lib/text-shimmer.d.ts +2 -2
- package/dist/lib/text-shimmer.d.ts.map +1 -1
- package/dist/lib/text-shimmer.js +2 -2
- package/dist/lib/text-shimmer.js.map +1 -1
- package/dist/lib/touch.d.ts +66 -0
- package/dist/lib/touch.d.ts.map +1 -0
- package/dist/lib/touch.js +79 -0
- package/dist/lib/touch.js.map +1 -0
- package/dist/presence-gate-BekdC4Bo.js +24 -0
- package/dist/presence-gate-BekdC4Bo.js.map +1 -0
- package/dist/types-smkWN_7x.d.ts.map +1 -1
- package/package.json +9 -9
- package/dist/components/reui/filters.d.ts +0 -176
- package/dist/components/reui/filters.d.ts.map +0 -1
- package/dist/components/reui/filters.js +0 -1223
- package/dist/components/reui/filters.js.map +0 -1
- package/dist/copy-menu-Bk5GP9Gp.js.map +0 -1
|
@@ -37,21 +37,31 @@ function useSelectContext(component) {
|
|
|
37
37
|
if (!ctx) throw new Error(`${component} must be used within <Select>`);
|
|
38
38
|
return ctx;
|
|
39
39
|
}
|
|
40
|
-
function Select({ value, defaultValue, onValueChange, disabled = false, className, children }) {
|
|
40
|
+
function Select({ value, defaultValue, onValueChange, open: openProp, defaultOpen = false, onOpenChange, disabled = false, className, children }) {
|
|
41
41
|
const reduce = useReducedMotion() ?? false;
|
|
42
42
|
const baseId = useId();
|
|
43
43
|
const rootRef = useRef(null);
|
|
44
|
-
const [
|
|
44
|
+
const [internalOpen, setInternalOpen] = useState(defaultOpen);
|
|
45
45
|
const [internal, setInternal] = useState(defaultValue);
|
|
46
46
|
const [labels, setLabels] = useState(/* @__PURE__ */ new Map());
|
|
47
47
|
const [placement, setPlacement] = useState("bottom");
|
|
48
48
|
const controlled = value !== void 0;
|
|
49
49
|
const current = controlled ? value : internal;
|
|
50
|
+
const openControlled = openProp !== void 0;
|
|
51
|
+
const open = openControlled ? openProp : internalOpen;
|
|
52
|
+
const setOpen = useCallback((next) => {
|
|
53
|
+
if (!openControlled) setInternalOpen(next);
|
|
54
|
+
onOpenChange?.(next);
|
|
55
|
+
}, [onOpenChange, openControlled]);
|
|
50
56
|
const select = useCallback((next) => {
|
|
51
57
|
if (!controlled) setInternal(next);
|
|
52
58
|
onValueChange?.(next);
|
|
53
59
|
setOpen(false);
|
|
54
|
-
}, [
|
|
60
|
+
}, [
|
|
61
|
+
controlled,
|
|
62
|
+
onValueChange,
|
|
63
|
+
setOpen
|
|
64
|
+
]);
|
|
55
65
|
const register = useCallback((v, label) => {
|
|
56
66
|
setLabels((m) => m.get(v) === label ? m : new Map(m).set(v, label));
|
|
57
67
|
}, []);
|
|
@@ -75,7 +85,7 @@ function Select({ value, defaultValue, onValueChange, disabled = false, classNam
|
|
|
75
85
|
window.removeEventListener("keydown", onKey);
|
|
76
86
|
window.removeEventListener("pointerdown", onPointer);
|
|
77
87
|
};
|
|
78
|
-
}, [open]);
|
|
88
|
+
}, [open, setOpen]);
|
|
79
89
|
const ctx = useMemo(() => ({
|
|
80
90
|
value: current,
|
|
81
91
|
open,
|
|
@@ -93,6 +103,7 @@ function Select({ value, defaultValue, onValueChange, disabled = false, classNam
|
|
|
93
103
|
}), [
|
|
94
104
|
current,
|
|
95
105
|
open,
|
|
106
|
+
setOpen,
|
|
96
107
|
select,
|
|
97
108
|
register,
|
|
98
109
|
unregister,
|
|
@@ -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 disabled?: boolean;\n className?: string;\n children: ReactNode;\n}\n\nexport function Select({\n value,\n defaultValue,\n onValueChange,\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 [open, setOpen] = useState(false);\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\n const select = useCallback(\n (next: string) => {\n if (!controlled) setInternal(next);\n onValueChange?.(next);\n setOpen(false);\n },\n [controlled, onValueChange],\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]);\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 [current, open, select, register, unregister, labels, reduce, baseId, disabled, placement],\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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,IAAI,WAAW,KAAK;CACnC,GAAG;EAAC,IAAI;EAAU,IAAI;EAAY;EAAO;CAAK,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 { 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,YAAY;EAAE,iBAAiB;EAAO,eAAe;CAAK,EAAE;AACtE;AACA,MAAM,gBAA0B;CAC9B,QAAQ;EAAE,SAAS;EAAG,GAAG;EAAI,QAAQ;CAAY;CACjD,MAAM;EAAE,SAAS;EAAG,GAAG;EAAG,QAAQ;CAAY;AAChD;AAoBA,MAAM,gBAAgB,cAAyC,IAAI;AAEnE,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,yBAA8B,IAAI,IAAI,CAAC;CACnE,MAAM,CAAC,WAAW,gBAAgB,SAAoB,QAAQ;CAE9D,MAAM,aAAa,UAAU,KAAA;CAC7B,MAAM,UAAU,aAAa,QAAQ;CACrC,MAAM,iBAAiB,aAAa,KAAA;CACpC,MAAM,OAAO,iBAAiB,WAAW;CAE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Y;GACnC,SAAS;GACT,SAAS,OAAO,SAAS;GACzB,WAAU;GAET;EACS,CAAA;CACF,CAAA;AAEhB;AASA,SAAgB,WAAW,EAAE,OAAO,WAAW,OAAO,WAAW,YAA6B;CAC5F,MAAM,MAAM,iBAAiB,YAAY;CACzC,MAAM,WAAW,IAAI,UAAU;CAC/B,MAAM,QAAQ,OAAO,aAAa,WAAW,WAAW;CAExD,sBAAsB;EACpB,IAAI,SAAS,OAAO,KAAK;EACzB,aAAa,IAAI,WAAW,KAAK;CACnC,GAAG;EAAC,IAAI;EAAU,IAAI;EAAY;EAAO;CAAK,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slide-action-button.d.ts","names":[],"sources":["../../../src/components/motion/slide-action-button.tsx"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"slide-action-button.d.ts","names":[],"sources":["../../../src/components/motion/slide-action-button.tsx"],"mappings":";;UAiBiB,+BAA+B,KAAK,eAAe;EAClE,UAAU;EACV,gBAAgB;EAChB;EACA;EACA;EACA;EACA;;iBAGc,oBACd,UACA,eACA,WACA,YACA,YACA,gBACA,eACA,cACG,QACF,yCAAsB,IAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { TOUCH_GESTURE_CLASS, TOUCH_GESTURE_CONTENT_CLASS } from "../../lib/touch.js";
|
|
2
3
|
import { EASE_OUT, SPRING_LAYOUT, SPRING_PRESS } from "../../lib/ease.js";
|
|
3
4
|
import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
4
5
|
import { cn } from "@kumix/utils";
|
|
@@ -79,7 +80,7 @@ function SlideActionButton({ children, completeLabel = "Complete", threshold = .
|
|
|
79
80
|
};
|
|
80
81
|
return /* @__PURE__ */ jsxs("div", {
|
|
81
82
|
ref: trackRef,
|
|
82
|
-
className: cn("relative h-16 w-72 overflow-hidden rounded-[22px] bg-primary/10 p-1", "ring-1 ring-primary/10", className),
|
|
83
|
+
className: cn("relative h-16 w-72 overflow-hidden rounded-[22px] bg-primary/10 p-1", "ring-1 ring-primary/10", TOUCH_GESTURE_CONTENT_CLASS, className),
|
|
83
84
|
...rest,
|
|
84
85
|
children: [
|
|
85
86
|
/* @__PURE__ */ jsx(motion.span, {
|
|
@@ -122,7 +123,7 @@ function SlideActionButton({ children, completeLabel = "Complete", threshold = .
|
|
|
122
123
|
onKeyDown: handleKeyDown,
|
|
123
124
|
whileTap: reduce || completed ? void 0 : { scale: .94 },
|
|
124
125
|
transition: SPRING_PRESS,
|
|
125
|
-
className: cn("relative z-10 grid size-14 cursor-grab touch-none place-items-center rounded-[18px] bg-primary text-primary-foreground shadow-sm", "outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 focus-visible:ring-offset-background active:cursor-grabbing", completed && "cursor-default bg-background text-foreground", thumbClassName),
|
|
126
|
+
className: cn("relative z-10 grid size-14 cursor-grab touch-none place-items-center rounded-[18px] bg-primary text-primary-foreground shadow-sm", TOUCH_GESTURE_CLASS, "outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 focus-visible:ring-offset-background active:cursor-grabbing", completed && "cursor-default bg-background text-foreground", thumbClassName),
|
|
126
127
|
children: /* @__PURE__ */ jsx(motion.svg, {
|
|
127
128
|
viewBox: "0 0 24 24",
|
|
128
129
|
"aria-hidden": "true",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slide-action-button.js","names":[],"sources":["../../../src/components/motion/slide-action-button.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type HTMLAttributes,\n type KeyboardEvent,\n type ReactNode,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\nimport { animate, motion, useMotionValue, useReducedMotion, useTransform } from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { EASE_OUT, SPRING_LAYOUT, SPRING_PRESS } from \"../../lib/ease\";\n\nexport interface SlideActionButtonProps extends Omit<HTMLAttributes<HTMLDivElement>, \"children\"> {\n children: ReactNode;\n completeLabel?: ReactNode;\n threshold?: number;\n resetDelay?: number;\n onComplete?: () => void;\n thumbClassName?: string;\n fillClassName?: string;\n}\n\nexport function SlideActionButton({\n children,\n completeLabel = \"Complete\",\n threshold = 0.82,\n resetDelay = 1200,\n onComplete,\n thumbClassName,\n fillClassName,\n className,\n ...rest\n}: SlideActionButtonProps) {\n const reduce = useReducedMotion();\n const trackRef = useRef<HTMLDivElement>(null);\n const thumbRef = useRef<HTMLButtonElement>(null);\n const resetTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const completedRef = useRef(false);\n const x = useMotionValue(0);\n const [maxDistance, setMaxDistance] = useState(0);\n const [completed, setCompleted] = useState(false);\n const safeDistance = Math.max(maxDistance, 1);\n const dragProgress = useTransform(x, [0, safeDistance], [0, 1]);\n const fillProgress = useTransform(x, [0, safeDistance], [0, 1]);\n const labelOpacity = useTransform(x, [0, safeDistance * 0.35, safeDistance * 0.65], [1, 0.75, 0]);\n const iconPath = useTransform(\n dragProgress,\n [0, 0.5, 1],\n [\"M 8 5 L 15 12 L 8 19\", \"M 7 8 L 12 14 L 17 10\", \"M 5 12 L 10 17 L 19 7\"],\n );\n\n useLayoutEffect(() => {\n const track = trackRef.current;\n const thumb = thumbRef.current;\n if (!track || !thumb) return;\n\n const measure = () => {\n setMaxDistance(Math.max(track.clientWidth - thumb.clientWidth - 8, 0));\n };\n\n measure();\n const observer = new ResizeObserver(measure);\n observer.observe(track);\n observer.observe(thumb);\n return () => observer.disconnect();\n }, []);\n\n useEffect(\n () => () => {\n if (resetTimerRef.current) clearTimeout(resetTimerRef.current);\n },\n [],\n );\n\n const moveTo = (target: number) => {\n if (reduce) {\n x.set(target);\n return;\n }\n animate(x, target, SPRING_LAYOUT);\n };\n\n const reset = () => {\n completedRef.current = false;\n setCompleted(false);\n moveTo(0);\n };\n\n const complete = () => {\n if (completedRef.current || maxDistance === 0) return;\n completedRef.current = true;\n setCompleted(true);\n moveTo(maxDistance);\n onComplete?.();\n\n if (resetTimerRef.current) clearTimeout(resetTimerRef.current);\n resetTimerRef.current = setTimeout(reset, resetDelay);\n };\n\n const handleKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {\n if (event.key !== \"Enter\" && event.key !== \" \") return;\n event.preventDefault();\n complete();\n };\n\n return (\n <div\n ref={trackRef}\n className={cn(\n \"relative h-16 w-72 overflow-hidden rounded-[22px] bg-primary/10 p-1\",\n \"ring-1 ring-primary/10\",\n className,\n )}\n {...rest}\n >\n <motion.span\n aria-hidden=\"true\"\n style={{ scaleX: fillProgress }}\n className={cn(\n \"absolute inset-0 origin-left bg-primary will-change-transform\",\n fillClassName,\n )}\n />\n\n <motion.span\n aria-hidden=\"true\"\n style={{ opacity: labelOpacity }}\n className=\"pointer-events-none absolute inset-0 grid place-items-center pl-10 font-medium text-foreground text-sm\"\n >\n {children}\n </motion.span>\n\n <motion.span\n aria-live=\"polite\"\n animate={{ opacity: completed ? 1 : 0 }}\n transition={{ duration: reduce ? 0 : 0.15, ease: EASE_OUT }}\n className=\"pointer-events-none absolute inset-0 grid place-items-center font-medium text-primary-foreground text-sm\"\n >\n {completed ? completeLabel : null}\n </motion.span>\n\n <motion.button\n ref={thumbRef}\n type=\"button\"\n aria-label={typeof children === \"string\" ? children : \"Slide action\"}\n drag={completed ? false : \"x\"}\n dragConstraints={{ left: 0, right: maxDistance }}\n dragElastic={0}\n dragMomentum={false}\n style={{ x }}\n onDragEnd={() => {\n if (x.get() >= maxDistance * threshold) complete();\n else moveTo(0);\n }}\n onKeyDown={handleKeyDown}\n whileTap={reduce || completed ? undefined : { scale: 0.94 }}\n transition={SPRING_PRESS}\n className={cn(\n \"relative z-10 grid size-14 cursor-grab touch-none place-items-center rounded-[18px] bg-primary text-primary-foreground shadow-sm\",\n \"outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 focus-visible:ring-offset-background active:cursor-grabbing\",\n completed && \"cursor-default bg-background text-foreground\",\n thumbClassName,\n )}\n >\n <motion.svg viewBox=\"0 0 24 24\" aria-hidden=\"true\" className=\"size-5\">\n <motion.path\n d={iconPath}\n fill=\"none\"\n stroke=\"currentColor\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n strokeWidth=\"2\"\n />\n </motion.svg>\n </motion.button>\n </div>\n );\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"slide-action-button.js","names":[],"sources":["../../../src/components/motion/slide-action-button.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type HTMLAttributes,\n type KeyboardEvent,\n type ReactNode,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\nimport { animate, motion, useMotionValue, useReducedMotion, useTransform } from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { EASE_OUT, SPRING_LAYOUT, SPRING_PRESS } from \"../../lib/ease\";\nimport { TOUCH_GESTURE_CLASS, TOUCH_GESTURE_CONTENT_CLASS } from \"../../lib/touch\";\n\nexport interface SlideActionButtonProps extends Omit<HTMLAttributes<HTMLDivElement>, \"children\"> {\n children: ReactNode;\n completeLabel?: ReactNode;\n threshold?: number;\n resetDelay?: number;\n onComplete?: () => void;\n thumbClassName?: string;\n fillClassName?: string;\n}\n\nexport function SlideActionButton({\n children,\n completeLabel = \"Complete\",\n threshold = 0.82,\n resetDelay = 1200,\n onComplete,\n thumbClassName,\n fillClassName,\n className,\n ...rest\n}: SlideActionButtonProps) {\n const reduce = useReducedMotion();\n const trackRef = useRef<HTMLDivElement>(null);\n const thumbRef = useRef<HTMLButtonElement>(null);\n const resetTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const completedRef = useRef(false);\n const x = useMotionValue(0);\n const [maxDistance, setMaxDistance] = useState(0);\n const [completed, setCompleted] = useState(false);\n const safeDistance = Math.max(maxDistance, 1);\n const dragProgress = useTransform(x, [0, safeDistance], [0, 1]);\n const fillProgress = useTransform(x, [0, safeDistance], [0, 1]);\n const labelOpacity = useTransform(x, [0, safeDistance * 0.35, safeDistance * 0.65], [1, 0.75, 0]);\n const iconPath = useTransform(\n dragProgress,\n [0, 0.5, 1],\n [\"M 8 5 L 15 12 L 8 19\", \"M 7 8 L 12 14 L 17 10\", \"M 5 12 L 10 17 L 19 7\"],\n );\n\n useLayoutEffect(() => {\n const track = trackRef.current;\n const thumb = thumbRef.current;\n if (!track || !thumb) return;\n\n const measure = () => {\n setMaxDistance(Math.max(track.clientWidth - thumb.clientWidth - 8, 0));\n };\n\n measure();\n const observer = new ResizeObserver(measure);\n observer.observe(track);\n observer.observe(thumb);\n return () => observer.disconnect();\n }, []);\n\n useEffect(\n () => () => {\n if (resetTimerRef.current) clearTimeout(resetTimerRef.current);\n },\n [],\n );\n\n const moveTo = (target: number) => {\n if (reduce) {\n x.set(target);\n return;\n }\n animate(x, target, SPRING_LAYOUT);\n };\n\n const reset = () => {\n completedRef.current = false;\n setCompleted(false);\n moveTo(0);\n };\n\n const complete = () => {\n if (completedRef.current || maxDistance === 0) return;\n completedRef.current = true;\n setCompleted(true);\n moveTo(maxDistance);\n onComplete?.();\n\n if (resetTimerRef.current) clearTimeout(resetTimerRef.current);\n resetTimerRef.current = setTimeout(reset, resetDelay);\n };\n\n const handleKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {\n if (event.key !== \"Enter\" && event.key !== \" \") return;\n event.preventDefault();\n complete();\n };\n\n return (\n <div\n ref={trackRef}\n className={cn(\n \"relative h-16 w-72 overflow-hidden rounded-[22px] bg-primary/10 p-1\",\n \"ring-1 ring-primary/10\",\n // The track only carries the label — the slide starts on the thumb,\n // which suppresses selection for the whole gesture on its own.\n TOUCH_GESTURE_CONTENT_CLASS,\n className,\n )}\n {...rest}\n >\n <motion.span\n aria-hidden=\"true\"\n style={{ scaleX: fillProgress }}\n className={cn(\n \"absolute inset-0 origin-left bg-primary will-change-transform\",\n fillClassName,\n )}\n />\n\n <motion.span\n aria-hidden=\"true\"\n style={{ opacity: labelOpacity }}\n className=\"pointer-events-none absolute inset-0 grid place-items-center pl-10 font-medium text-foreground text-sm\"\n >\n {children}\n </motion.span>\n\n <motion.span\n aria-live=\"polite\"\n animate={{ opacity: completed ? 1 : 0 }}\n transition={{ duration: reduce ? 0 : 0.15, ease: EASE_OUT }}\n className=\"pointer-events-none absolute inset-0 grid place-items-center font-medium text-primary-foreground text-sm\"\n >\n {completed ? completeLabel : null}\n </motion.span>\n\n <motion.button\n ref={thumbRef}\n type=\"button\"\n aria-label={typeof children === \"string\" ? children : \"Slide action\"}\n drag={completed ? false : \"x\"}\n dragConstraints={{ left: 0, right: maxDistance }}\n dragElastic={0}\n dragMomentum={false}\n style={{ x }}\n onDragEnd={() => {\n if (x.get() >= maxDistance * threshold) complete();\n else moveTo(0);\n }}\n onKeyDown={handleKeyDown}\n whileTap={reduce || completed ? undefined : { scale: 0.94 }}\n transition={SPRING_PRESS}\n className={cn(\n \"relative z-10 grid size-14 cursor-grab touch-none place-items-center rounded-[18px] bg-primary text-primary-foreground shadow-sm\",\n TOUCH_GESTURE_CLASS,\n \"outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 focus-visible:ring-offset-background active:cursor-grabbing\",\n completed && \"cursor-default bg-background text-foreground\",\n thumbClassName,\n )}\n >\n <motion.svg viewBox=\"0 0 24 24\" aria-hidden=\"true\" className=\"size-5\">\n <motion.path\n d={iconPath}\n fill=\"none\"\n stroke=\"currentColor\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n strokeWidth=\"2\"\n />\n </motion.sv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E,IAAI,KAAK,cAAc,WAAW,SAAS;UAC5C,OAAO,CAAC;IACf;IACA,WAAW;IACX,UAAU,UAAU,YAAY,KAAA,IAAY,EAAE,OAAO,IAAK;IAC1D,YAAY;IACZ,WAAW,GACT,oIACA,qBACA,wJACA,aAAa,gDACb,cACF;IAEA,UAAA,oBAAC,OAAO,KAAR;KAAY,SAAQ;KAAY,eAAY;KAAO,WAAU;KAC3D,UAAA,oBAAC,OAAO,MAAR;MACE,GAAG;MACH,MAAK;MACL,QAAO;MACP,eAAc;MACd,gBAAe;MACf,aAAY;KACb,CAAA;IACS,CAAA;GACC,CAAA;EACZ;;AAET"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"swipeable-list.d.ts","names":[],"sources":["../../../src/components/motion/swipeable-list.tsx"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"swipeable-list.d.ts","names":[],"sources":["../../../src/components/motion/swipeable-list.tsx"],"mappings":";;KAQY;KAEA;EACV;EACA,MAAM;;KAGI;KAEA;EACV;EACA,OAAO;EACP,MAAM;EACN,OAAO;EACP;EACA,WAAW,MAAM;;KAGP;EACV;EACA,QAAQ;EACR,cAAc;EACd,OAAO;EACP,UAAU;EACV,UAAU;EACV,cAAc;EACd,eAAe;EACf;;KAGU;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf,OAAO;EACP,QAAQ;EACR,eAAe;EACf,iBAAiB,OAAO;EACxB,YAAY;IAAW,MAAM;IAAmB,QAAQ;IAAa,MAAM;;EAC3E;EACA;EACA;EACA;EACA,aAAa;EACb,cAAc,MAAM,sBAAsB;;iBAuV5B,gBACd,OACA,OACA,cACA,eACA,UACA,aACA,iBACA,eACA,WACA,YACA,cACC,qCAAkB,IAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { TOUCH_GESTURE_CONTENT_CLASS } from "../../lib/touch.js";
|
|
2
3
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
4
|
import { cn } from "@kumix/utils";
|
|
4
5
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -222,7 +223,7 @@ function SwipeableListRow({ item, actionWidth, revealThreshold, openValue, setOp
|
|
|
222
223
|
onDragStart,
|
|
223
224
|
onDragEnd,
|
|
224
225
|
style: { x },
|
|
225
|
-
className: cn("relative z-10 min-h-[72px] cursor-grab touch-pan-y
|
|
226
|
+
className: cn("relative z-10 min-h-[72px] cursor-grab touch-pan-y rounded-2xl border border-border bg-card px-4 py-3 shadow-sm active:cursor-grabbing", TOUCH_GESTURE_CONTENT_CLASS, classNames?.surface),
|
|
226
227
|
children: renderItem ? renderItem(item) : item.content ?? defaultContent
|
|
227
228
|
})]
|
|
228
229
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"swipeable-list.js","names":[],"sources":["../../../src/components/motion/swipeable-list.tsx"],"sourcesContent":["\"use client\";\n\nimport { type ReactNode, useCallback, useEffect, useRef, useState } from \"react\";\nimport { animate, motion, type PanInfo, useMotionValue, useReducedMotion } from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\n\nexport type SwipeSide = \"left\" | \"right\";\n\nexport type SwipeableListValue = {\n id: string;\n side: SwipeSide;\n};\n\nexport type SwipeActionTone = \"neutral\" | \"primary\" | \"success\" | \"warning\" | \"danger\";\n\nexport type SwipeAction = {\n id: string;\n label: ReactNode;\n icon: ReactNode;\n tone?: SwipeActionTone;\n disabled?: boolean;\n onClick?: (item: SwipeableListItem) => void;\n};\n\nexport type SwipeableListItem = {\n id: string;\n title?: ReactNode;\n description?: ReactNode;\n meta?: ReactNode;\n leading?: ReactNode;\n content?: ReactNode;\n leftActions?: SwipeAction[];\n rightActions?: SwipeAction[];\n disabled?: boolean;\n};\n\nexport type SwipeableListClassNames = {\n root?: string;\n item?: string;\n rail?: string;\n action?: string;\n surface?: string;\n leading?: string;\n content?: string;\n title?: string;\n description?: string;\n meta?: string;\n};\n\nexport interface SwipeableListProps {\n items: SwipeableListItem[];\n value?: SwipeableListValue | null;\n defaultValue?: SwipeableListValue | null;\n onValueChange?: (value: SwipeableListValue | null) => void;\n onAction?: (payload: { item: SwipeableListItem; action: SwipeAction; side: SwipeSide }) => void;\n actionWidth?: number;\n revealThreshold?: number;\n closeOnAction?: boolean;\n className?: string;\n classNames?: SwipeableListClassNames;\n renderItem?: (item: SwipeableListItem) => ReactNode;\n}\n\n// Distance-based release spring keeps short rebounds and full reveals feeling\n// equally direct, closer to native mobile list interactions.\nconst ROW_SETTLE = {\n type: \"spring\",\n stiffness: 560,\n damping: 48,\n mass: 0.82,\n restDelta: 0.5,\n restSpeed: 8,\n} as const;\nconst OPEN_DISTANCE_RATIO = 0.46;\nconst CLOSE_DISTANCE_RATIO = 0.72;\nconst OPEN_VELOCITY = 720;\nconst CLOSE_VELOCITY = 320;\nconst FLING_DISTANCE = 14;\nconst RELEASE_VELOCITY_LIMIT = 1500;\n\nconst ACTION_TONE_CLASS: Record<SwipeActionTone, string> = {\n neutral: \"text-muted-foreground group-hover:text-foreground\",\n primary: \"text-foreground\",\n success: \"text-emerald-600 dark:text-emerald-400\",\n warning: \"text-amber-600 dark:text-amber-400\",\n danger: \"text-destructive\",\n};\n\nfunction useControllableSwipeValue({\n value,\n defaultValue,\n onValueChange,\n}: {\n value?: SwipeableListValue | null;\n defaultValue?: SwipeableListValue | null;\n onValueChange?: (value: SwipeableListValue | null) => void;\n}) {\n const [internalValue, setInternalValue] = useState(defaultValue ?? null);\n const isControlled = value !== undefined;\n const currentValue = value ?? internalValue;\n\n const setValue = useCallback(\n (next: SwipeableListValue | null) => {\n if (!isControlled) {\n setInternalValue(next);\n }\n\n onValueChange?.(next);\n },\n [isControlled, onValueChange],\n );\n\n return [currentValue, setValue] as const;\n}\n\nfunction isActionableSide(value: number, sideWidth: number) {\n return sideWidth > 0 && Math.abs(value) > 0;\n}\n\nfunction clampReleaseVelocity(velocity: number) {\n return Math.max(-RELEASE_VELOCITY_LIMIT, Math.min(RELEASE_VELOCITY_LIMIT, velocity));\n}\n\nfunction SwipeActionButton({\n action,\n actionWidth,\n side,\n focusable,\n onAction,\n className,\n}: {\n action: SwipeAction;\n actionWidth: number;\n side: SwipeSide;\n focusable: boolean;\n onAction: (action: SwipeAction, side: SwipeSide) => void;\n className?: string;\n}) {\n return (\n <button\n type=\"button\"\n disabled={action.disabled}\n tabIndex={focusable ? 0 : -1}\n aria-label={typeof action.label === \"string\" ? action.label : undefined}\n onClick={() => onAction(action, side)}\n className={cn(\n \"group flex h-full shrink-0 items-center justify-center outline-none\",\n \"focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background\",\n \"disabled:pointer-events-none disabled:opacity-50\",\n className,\n )}\n style={{ width: actionWidth }}\n >\n <span\n className={cn(\n \"grid h-9 w-9 place-items-center rounded-full transition-[background-color,color,transform] duration-150 group-hover:bg-background group-active:scale-95\",\n ACTION_TONE_CLASS[action.tone ?? \"neutral\"],\n )}\n >\n {action.icon}\n </span>\n <span className=\"sr-only\">{action.label}</span>\n </button>\n );\n}\n\nfunction SwipeableListRow({\n item,\n actionWidth,\n revealThreshold,\n openValue,\n setOpenValue,\n closeOnAction,\n onAction,\n classNames,\n renderItem,\n}: {\n item: SwipeableListItem;\n actionWidth: number;\n revealThreshold: number;\n openValue: SwipeableListValue | null;\n setOpenValue: (value: SwipeableListValue | null) => void;\n closeOnAction: boolean;\n onAction?: SwipeableListProps[\"onAction\"];\n classNames?: SwipeableListClassNames;\n renderItem?: (item: SwipeableListItem) => ReactNode;\n}) {\n const reduce = useReducedMotion();\n const x = useMotionValue(0);\n const animationRef = useRef<{ stop: () => void } | null>(null);\n const commandedTargetRef = useRef(0);\n const leftActions = item.leftActions ?? [];\n const rightActions = item.rightActions ?? [];\n const leftWidth = leftActions.length * actionWidth;\n const rightWidth = rightActions.length * actionWidth;\n const openSide = openValue?.id === item.id ? openValue.side : null;\n const targetX = openSide === \"left\" ? leftWidth : openSide === \"right\" ? -rightWidth : 0;\n\n const settleX = useCallback(\n (nextX: number, velocity = 0) => {\n commandedTargetRef.current = nextX;\n animationRef.current?.stop();\n\n if (reduce) {\n x.set(nextX);\n return;\n }\n\n animationRef.current = animate(x, nextX, {\n ...ROW_SETTLE,\n velocity: clampReleaseVelocity(velocity),\n onComplete: () => x.set(nextX),\n });\n },\n [reduce, x],\n );\n\n useEffect(() => {\n return () => animationRef.current?.stop();\n }, []);\n\n useEffect(() => {\n if (commandedTargetRef.current === targetX) {\n return;\n }\n\n settleX(targetX);\n }, [settleX, targetX]);\n\n const getTargetX = useCallback(\n (side: SwipeSide | null) => (side === \"left\" ? leftWidth : side === \"right\" ? -rightWidth : 0),\n [leftWidth, rightWidth],\n );\n\n const snapTo = useCallback(\n (side: SwipeSide | null, velocity = 0) => {\n setOpenValue(side ? { id: item.id, side } : null);\n settleX(getTargetX(side), velocity);\n },\n [getTargetX, item.id, setOpenValue, settleX],\n );\n\n const onDragStart = useCallback(() => {\n animationRef.current?.stop();\n\n if (openValue && openValue.id !== item.id) {\n setOpenValue(null);\n }\n }, [item.id, openValue, setOpenValue]);\n\n const onDragEnd = useCallback(\n (_: PointerEvent, info: PanInfo) => {\n const velocity = info.velocity.x;\n const latest = x.get();\n const leftOpenThreshold = Math.max(revealThreshold, leftWidth * OPEN_DISTANCE_RATIO);\n const rightOpenThreshold = Math.max(revealThreshold, rightWidth * OPEN_DISTANCE_RATIO);\n\n if (openSide === \"left\") {\n if (latest < leftWidth * CLOSE_DISTANCE_RATIO || velocity < -CLOSE_VELOCITY) {\n snapTo(null, velocity);\n return;\n }\n\n snapTo(\"left\", velocity);\n return;\n }\n\n if (openSide === \"right\") {\n if (Math.abs(latest) < rightWidth * CLOSE_DISTANCE_RATIO || velocity > CLOSE_VELOCITY) {\n snapTo(null, velocity);\n return;\n }\n\n snapTo(\"right\", velocity);\n return;\n }\n\n if (\n isActionableSide(latest, leftWidth) &&\n (latest > leftOpenThreshold || (velocity > OPEN_VELOCITY && latest > FLING_DISTANCE))\n ) {\n snapTo(\"left\", velocity);\n return;\n }\n\n if (\n isActionableSide(latest, rightWidth) &&\n (latest < -rightOpenThreshold || (velocity < -OPEN_VELOCITY && latest < -FLING_DISTANCE))\n ) {\n snapTo(\"right\", velocity);\n return;\n }\n\n snapTo(null, velocity);\n },\n [leftWidth, openSide, revealThreshold, rightWidth, snapTo, x],\n );\n\n const handleAction = useCallback(\n (action: SwipeAction, side: SwipeSide) => {\n action.onClick?.(item);\n onAction?.({ item, action, side });\n\n if (closeOnAction) {\n snapTo(null);\n }\n },\n [closeOnAction, item, onAction, snapTo],\n );\n\n const defaultContent = (\n <div className=\"flex min-w-0 items-center gap-3\">\n {item.leading ? (\n <div className={cn(\"shrink-0\", classNames?.leading)}>{item.leading}</div>\n ) : null}\n <div className={cn(\"min-w-0 flex-1\", classNames?.content)}>\n {item.title ? (\n <div className={cn(\"truncate font-medium text-foreground text-sm\", classNames?.title)}>\n {item.title}\n </div>\n ) : null}\n {item.description ? (\n <div\n className={cn(\"mt-0.5 truncate text-muted-foreground text-xs\", classNames?.description)}\n >\n {item.description}\n </div>\n ) : null}\n </div>\n {item.meta ? (\n <div className={cn(\"shrink-0 font-medium text-muted-foreground text-xs\", classNames?.meta)}>\n {item.meta}\n </div>\n ) : null}\n </div>\n );\n\n return (\n <div\n className={cn(\n \"relative isolate overflow-hidden rounded-2xl bg-muted\",\n item.disabled && \"opacity-60\",\n classNames?.item,\n )}\n >\n <div\n aria-hidden={!openSide}\n inert={!openSide}\n className={cn(\"absolute inset-0 z-0 flex overflow-hidden rounded-2xl\", classNames?.rail)}\n >\n <div className=\"flex h-full overflow-hidden rounded-l-2xl\">\n {leftActions.map((action) => (\n <SwipeActionButton\n key={action.id}\n action={action}\n actionWidth={actionWidth}\n className={classNames?.action}\n focusable={openSide === \"left\"}\n onAction={handleAction}\n side=\"left\"\n />\n ))}\n </div>\n <div className=\"ml-auto flex h-full overflow-hidden rounded-r-2xl\">\n {rightActions.map((action) => (\n <SwipeActionButton\n key={action.id}\n action={action}\n actionWidth={actionWidth}\n className={classNames?.action}\n focusable={openSide === \"right\"}\n onAction={handleAction}\n side=\"right\"\n />\n ))}\n </div>\n </div>\n\n <motion.div\n drag={item.disabled ? false : \"x\"}\n dragConstraints={{ left: -rightWidth, right: leftWidth }}\n dragElastic={0.04}\n dragMomentum={false}\n onDragStart={onDragStart}\n onDragEnd={onDragEnd}\n style={{ x }}\n className={cn(\n \"relative z-10 min-h-[72px] cursor-grab touch-pan-y select-none rounded-2xl border border-border bg-card px-4 py-3 shadow-sm active:cursor-grabbing\",\n classNames?.surface,\n )}\n >\n {renderItem ? renderItem(item) : (item.content ?? defaultContent)}\n </motion.div>\n </div>\n );\n}\n\nexport function SwipeableList({\n items,\n value,\n defaultValue = null,\n onValueChange,\n onAction,\n actionWidth = 56,\n revealThreshold = 34,\n closeOnAction = true,\n className,\n classNames,\n renderItem,\n}: SwipeableListProps) {\n const [openValue, setOpenValue] = useControllableSwipeValue({\n value,\n defaultValue,\n onValueChange,\n });\n\n return (\n <div className={cn(\"flex w-full flex-col gap-2\", className, classNames?.root)}>\n {items.map((item) => (\n <SwipeableListRow\n key={item.id}\n item={item}\n actionWidth={actionWidth}\n revealThreshold={revealThreshold}\n openValue={openValue}\n setOpenValue={setOpenValue}\n closeOnAction={closeOnAction}\n onAction={onAction}\n classNames={classNames}\n renderItem={renderItem}\n />\n ))}\n </div>\n );\n}\n"],"mappings":";;;;;;AAkEA,MAAM,aAAa;CACjB,MAAM;CACN,WAAW;CACX,SAAS;CACT,MAAM;CACN,WAAW;CACX,WAAW;AACb;AACA,MAAM,sBAAsB;AAC5B,MAAM,uBAAuB;AAC7B,MAAM,gBAAgB;AACtB,MAAM,iBAAiB;AACvB,MAAM,iBAAiB;AACvB,MAAM,yBAAyB;AAE/B,MAAM,oBAAqD;CACzD,SAAS;CACT,SAAS;CACT,SAAS;CACT,SAAS;CACT,QAAQ;AACV;AAEA,SAAS,0BAA0B,EACjC,OAC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,IAAI;EACzE,UAAA,MAAM,KAAK,SACV,oBAAC,kBAAD;GAEQ;GACO;GACI;GACN;GACG;GACC;GACL;GACE;GACA;EACb,GAVM,KAAK,EAUX,CACF;CACE,CAAA;AAET"}
|
|
1
|
+
{"version":3,"file":"swipeable-list.js","names":[],"sources":["../../../src/components/motion/swipeable-list.tsx"],"sourcesContent":["\"use client\";\n\nimport { type ReactNode, useCallback, useEffect, useRef, useState } from \"react\";\nimport { animate, motion, type PanInfo, useMotionValue, useReducedMotion } from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { TOUCH_GESTURE_CONTENT_CLASS } from \"../../lib/touch\";\n\nexport type SwipeSide = \"left\" | \"right\";\n\nexport type SwipeableListValue = {\n id: string;\n side: SwipeSide;\n};\n\nexport type SwipeActionTone = \"neutral\" | \"primary\" | \"success\" | \"warning\" | \"danger\";\n\nexport type SwipeAction = {\n id: string;\n label: ReactNode;\n icon: ReactNode;\n tone?: SwipeActionTone;\n disabled?: boolean;\n onClick?: (item: SwipeableListItem) => void;\n};\n\nexport type SwipeableListItem = {\n id: string;\n title?: ReactNode;\n description?: ReactNode;\n meta?: ReactNode;\n leading?: ReactNode;\n content?: ReactNode;\n leftActions?: SwipeAction[];\n rightActions?: SwipeAction[];\n disabled?: boolean;\n};\n\nexport type SwipeableListClassNames = {\n root?: string;\n item?: string;\n rail?: string;\n action?: string;\n surface?: string;\n leading?: string;\n content?: string;\n title?: string;\n description?: string;\n meta?: string;\n};\n\nexport interface SwipeableListProps {\n items: SwipeableListItem[];\n value?: SwipeableListValue | null;\n defaultValue?: SwipeableListValue | null;\n onValueChange?: (value: SwipeableListValue | null) => void;\n onAction?: (payload: { item: SwipeableListItem; action: SwipeAction; side: SwipeSide }) => void;\n actionWidth?: number;\n revealThreshold?: number;\n closeOnAction?: boolean;\n className?: string;\n classNames?: SwipeableListClassNames;\n renderItem?: (item: SwipeableListItem) => ReactNode;\n}\n\n// Distance-based release spring keeps short rebounds and full reveals feeling\n// equally direct, closer to native mobile list interactions.\nconst ROW_SETTLE = {\n type: \"spring\",\n stiffness: 560,\n damping: 48,\n mass: 0.82,\n restDelta: 0.5,\n restSpeed: 8,\n} as const;\nconst OPEN_DISTANCE_RATIO = 0.46;\nconst CLOSE_DISTANCE_RATIO = 0.72;\nconst OPEN_VELOCITY = 720;\nconst CLOSE_VELOCITY = 320;\nconst FLING_DISTANCE = 14;\nconst RELEASE_VELOCITY_LIMIT = 1500;\n\nconst ACTION_TONE_CLASS: Record<SwipeActionTone, string> = {\n neutral: \"text-muted-foreground group-hover:text-foreground\",\n primary: \"text-foreground\",\n success: \"text-emerald-600 dark:text-emerald-400\",\n warning: \"text-amber-600 dark:text-amber-400\",\n danger: \"text-destructive\",\n};\n\nfunction useControllableSwipeValue({\n value,\n defaultValue,\n onValueChange,\n}: {\n value?: SwipeableListValue | null;\n defaultValue?: SwipeableListValue | null;\n onValueChange?: (value: SwipeableListValue | null) => void;\n}) {\n const [internalValue, setInternalValue] = useState(defaultValue ?? null);\n const isControlled = value !== undefined;\n const currentValue = value ?? internalValue;\n\n const setValue = useCallback(\n (next: SwipeableListValue | null) => {\n if (!isControlled) {\n setInternalValue(next);\n }\n\n onValueChange?.(next);\n },\n [isControlled, onValueChange],\n );\n\n return [currentValue, setValue] as const;\n}\n\nfunction isActionableSide(value: number, sideWidth: number) {\n return sideWidth > 0 && Math.abs(value) > 0;\n}\n\nfunction clampReleaseVelocity(velocity: number) {\n return Math.max(-RELEASE_VELOCITY_LIMIT, Math.min(RELEASE_VELOCITY_LIMIT, velocity));\n}\n\nfunction SwipeActionButton({\n action,\n actionWidth,\n side,\n focusable,\n onAction,\n className,\n}: {\n action: SwipeAction;\n actionWidth: number;\n side: SwipeSide;\n focusable: boolean;\n onAction: (action: SwipeAction, side: SwipeSide) => void;\n className?: string;\n}) {\n return (\n <button\n type=\"button\"\n disabled={action.disabled}\n tabIndex={focusable ? 0 : -1}\n aria-label={typeof action.label === \"string\" ? action.label : undefined}\n onClick={() => onAction(action, side)}\n className={cn(\n \"group flex h-full shrink-0 items-center justify-center outline-none\",\n \"focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background\",\n \"disabled:pointer-events-none disabled:opacity-50\",\n className,\n )}\n style={{ width: actionWidth }}\n >\n <span\n className={cn(\n \"grid h-9 w-9 place-items-center rounded-full transition-[background-color,color,transform] duration-150 group-hover:bg-background group-active:scale-95\",\n ACTION_TONE_CLASS[action.tone ?? \"neutral\"],\n )}\n >\n {action.icon}\n </span>\n <span className=\"sr-only\">{action.label}</span>\n </button>\n );\n}\n\nfunction SwipeableListRow({\n item,\n actionWidth,\n revealThreshold,\n openValue,\n setOpenValue,\n closeOnAction,\n onAction,\n classNames,\n renderItem,\n}: {\n item: SwipeableListItem;\n actionWidth: number;\n revealThreshold: number;\n openValue: SwipeableListValue | null;\n setOpenValue: (value: SwipeableListValue | null) => void;\n closeOnAction: boolean;\n onAction?: SwipeableListProps[\"onAction\"];\n classNames?: SwipeableListClassNames;\n renderItem?: (item: SwipeableListItem) => ReactNode;\n}) {\n const reduce = useReducedMotion();\n const x = useMotionValue(0);\n const animationRef = useRef<{ stop: () => void } | null>(null);\n const commandedTargetRef = useRef(0);\n const leftActions = item.leftActions ?? [];\n const rightActions = item.rightActions ?? [];\n const leftWidth = leftActions.length * actionWidth;\n const rightWidth = rightActions.length * actionWidth;\n const openSide = openValue?.id === item.id ? openValue.side : null;\n const targetX = openSide === \"left\" ? leftWidth : openSide === \"right\" ? -rightWidth : 0;\n\n const settleX = useCallback(\n (nextX: number, velocity = 0) => {\n commandedTargetRef.current = nextX;\n animationRef.current?.stop();\n\n if (reduce) {\n x.set(nextX);\n return;\n }\n\n animationRef.current = animate(x, nextX, {\n ...ROW_SETTLE,\n velocity: clampReleaseVelocity(velocity),\n onComplete: () => x.set(nextX),\n });\n },\n [reduce, x],\n );\n\n useEffect(() => {\n return () => animationRef.current?.stop();\n }, []);\n\n useEffect(() => {\n if (commandedTargetRef.current === targetX) {\n return;\n }\n\n settleX(targetX);\n }, [settleX, targetX]);\n\n const getTargetX = useCallback(\n (side: SwipeSide | null) => (side === \"left\" ? leftWidth : side === \"right\" ? -rightWidth : 0),\n [leftWidth, rightWidth],\n );\n\n const snapTo = useCallback(\n (side: SwipeSide | null, velocity = 0) => {\n setOpenValue(side ? { id: item.id, side } : null);\n settleX(getTargetX(side), velocity);\n },\n [getTargetX, item.id, setOpenValue, settleX],\n );\n\n const onDragStart = useCallback(() => {\n animationRef.current?.stop();\n\n if (openValue && openValue.id !== item.id) {\n setOpenValue(null);\n }\n }, [item.id, openValue, setOpenValue]);\n\n const onDragEnd = useCallback(\n (_: PointerEvent, info: PanInfo) => {\n const velocity = info.velocity.x;\n const latest = x.get();\n const leftOpenThreshold = Math.max(revealThreshold, leftWidth * OPEN_DISTANCE_RATIO);\n const rightOpenThreshold = Math.max(revealThreshold, rightWidth * OPEN_DISTANCE_RATIO);\n\n if (openSide === \"left\") {\n if (latest < leftWidth * CLOSE_DISTANCE_RATIO || velocity < -CLOSE_VELOCITY) {\n snapTo(null, velocity);\n return;\n }\n\n snapTo(\"left\", velocity);\n return;\n }\n\n if (openSide === \"right\") {\n if (Math.abs(latest) < rightWidth * CLOSE_DISTANCE_RATIO || velocity > CLOSE_VELOCITY) {\n snapTo(null, velocity);\n return;\n }\n\n snapTo(\"right\", velocity);\n return;\n }\n\n if (\n isActionableSide(latest, leftWidth) &&\n (latest > leftOpenThreshold || (velocity > OPEN_VELOCITY && latest > FLING_DISTANCE))\n ) {\n snapTo(\"left\", velocity);\n return;\n }\n\n if (\n isActionableSide(latest, rightWidth) &&\n (latest < -rightOpenThreshold || (velocity < -OPEN_VELOCITY && latest < -FLING_DISTANCE))\n ) {\n snapTo(\"right\", velocity);\n return;\n }\n\n snapTo(null, velocity);\n },\n [leftWidth, openSide, revealThreshold, rightWidth, snapTo, x],\n );\n\n const handleAction = useCallback(\n (action: SwipeAction, side: SwipeSide) => {\n action.onClick?.(item);\n onAction?.({ item, action, side });\n\n if (closeOnAction) {\n snapTo(null);\n }\n },\n [closeOnAction, item, onAction, snapTo],\n );\n\n const defaultContent = (\n <div className=\"flex min-w-0 items-center gap-3\">\n {item.leading ? (\n <div className={cn(\"shrink-0\", classNames?.leading)}>{item.leading}</div>\n ) : null}\n <div className={cn(\"min-w-0 flex-1\", classNames?.content)}>\n {item.title ? (\n <div className={cn(\"truncate font-medium text-foreground text-sm\", classNames?.title)}>\n {item.title}\n </div>\n ) : null}\n {item.description ? (\n <div\n className={cn(\"mt-0.5 truncate text-muted-foreground text-xs\", classNames?.description)}\n >\n {item.description}\n </div>\n ) : null}\n </div>\n {item.meta ? (\n <div className={cn(\"shrink-0 font-medium text-muted-foreground text-xs\", classNames?.meta)}>\n {item.meta}\n </div>\n ) : null}\n </div>\n );\n\n return (\n <div\n className={cn(\n \"relative isolate overflow-hidden rounded-2xl bg-muted\",\n item.disabled && \"opacity-60\",\n classNames?.item,\n )}\n >\n <div\n aria-hidden={!openSide}\n inert={!openSide}\n className={cn(\"absolute inset-0 z-0 flex overflow-hidden rounded-2xl\", classNames?.rail)}\n >\n <div className=\"flex h-full overflow-hidden rounded-l-2xl\">\n {leftActions.map((action) => (\n <SwipeActionButton\n key={action.id}\n action={action}\n actionWidth={actionWidth}\n className={classNames?.action}\n focusable={openSide === \"left\"}\n onAction={handleAction}\n side=\"left\"\n />\n ))}\n </div>\n <div className=\"ml-auto flex h-full overflow-hidden rounded-r-2xl\">\n {rightActions.map((action) => (\n <SwipeActionButton\n key={action.id}\n action={action}\n actionWidth={actionWidth}\n className={classNames?.action}\n focusable={openSide === \"right\"}\n onAction={handleAction}\n side=\"right\"\n />\n ))}\n </div>\n </div>\n\n <motion.div\n drag={item.disabled ? false : \"x\"}\n dragConstraints={{ left: -rightWidth, right: leftWidth }}\n dragElastic={0.04}\n dragMomentum={false}\n onDragStart={onDragStart}\n onDragEnd={onDragEnd}\n style={{ x }}\n className={cn(\n // `touch-pan-y`, not `touch-none`: the row owns the horizontal\n // swipe, the page keeps the vertical scroll through it.\n \"relative z-10 min-h-[72px] cursor-grab touch-pan-y rounded-2xl border border-border bg-card px-4 py-3 shadow-sm active:cursor-grabbing\",\n // The swipe is the row's, but what it carries is the consumer's:\n // selection is only suppressed where the platform runs its own press\n // gestures, so a mouse can still select and copy the row's text.\n TOUCH_GESTURE_CONTENT_CLASS,\n classNames?.surface,\n )}\n >\n {renderItem ? renderItem(item) : (item.content ?? defaultContent)}\n </motion.div>\n </div>\n );\n}\n\nexport function SwipeableList({\n items,\n value,\n defaultValue = null,\n onValueChange,\n onAction,\n actionWidth = 56,\n revealThreshold = 34,\n closeOnAction = true,\n className,\n classNames,\n renderItem,\n}: SwipeableListProps) {\n const [openValue, setOpenValue] = useControllableSwipeValue({\n value,\n defaultValue,\n onValueChange,\n });\n\n return (\n <div className={cn(\"flex w-full flex-col gap-2\", className, classNames?.root)}>\n {items.map((item) => (\n <SwipeableListRow\n key={item.id}\n item={item}\n actionWidth={actionWidth}\n revealThreshold={revealThreshold}\n openValue={openValue}\n setOpenValue={setOpenValue}\n closeOnAction={closeOnAction}\n onAction={onAction}\n classNames={classNames}\n renderItem={renderItem}\n />\n ))}\n </div>\n );\n}\n"],"mappings":";;;;;;;AAmEA,MAAM,aAAa;CACjB,MAAM;CACN,WAAW;CACX,SAAS;CACT,MAAM;CACN,WAAW;CACX,WAAW;AACb;AACA,MAAM,sBAAsB;AAC5B,MAAM,uBAAuB;AAC7B,MAAM,gBAAgB;AACtB,MAAM,iBAAiB;AACvB,MAAM,iBAAiB;AACvB,MAAM,yBAAyB;AAE/B,MAAM,oBAAqD;CACzD,SAAS;CACT,SAAS;CACT,SAAS;CACT,SAAS;CACT,QAAQ;AACV;AAEA,SAAS,0BAA0B,EACjC,OACA,cACA,iBAKC;CACD,MAAM,CAAC,eAAe,oBAAoB,SAAS,gBAAgB,IAAI;CACvE,MAAM,eAAe,UAAU,KAAA;CAc/B,OAAO,CAbc,SAAS,eAEb,aACd,SA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E,CAAA;AAET"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/components/motion/table/index.tsx"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/components/motion/table/index.tsx"],"mappings":";;iBAkEgB,MAAM,KACpB,MACA,SACA,UACA,YACA,gBACA,uBACA,mBACA,MAAM,UACN,aACA,cACA,WACA,gBACA,gBACA,aACA,qBACA,YACA,gBACA,aACA,aACA,gBACA,gBACA,WACA,QACA,UACA,cACA,SACA,cACA,YACA,aACC,WAAW,qBAAE,IAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { capturePointer, releasePointer } from "../../../lib/touch.js";
|
|
2
3
|
import { Checkbox } from "../checkbox.js";
|
|
3
4
|
import { EditableCell } from "./editable-cell.js";
|
|
4
5
|
import { RowHandle } from "./row-handle.js";
|
|
@@ -47,14 +48,14 @@ function useColumnReorder({ columns, thRefs, onColumnOrderChange }) {
|
|
|
47
48
|
e.preventDefault();
|
|
48
49
|
e.stopPropagation();
|
|
49
50
|
setDragKey(key);
|
|
50
|
-
e.currentTarget
|
|
51
|
+
capturePointer(e.currentTarget, e.pointerId);
|
|
51
52
|
}, []),
|
|
52
53
|
moveReorder: useCallback((e) => {
|
|
53
54
|
if (!dragKey) return;
|
|
54
55
|
setDropIndex(dropIndexFor(e.clientX));
|
|
55
56
|
}, [dragKey, dropIndexFor]),
|
|
56
57
|
endReorder: useCallback((e) => {
|
|
57
|
-
|
|
58
|
+
releasePointer(e.currentTarget, e.pointerId);
|
|
58
59
|
if (dragKey && dropIndex !== null) {
|
|
59
60
|
const keys = orderedColumns.map((c) => c.key);
|
|
60
61
|
const from = keys.indexOf(dragKey);
|
|
@@ -98,7 +99,7 @@ function useColumnResize({ orderedColumns, thRefs, minColumnWidth, onColumnResiz
|
|
|
98
99
|
startWidth: snapshot[key]
|
|
99
100
|
};
|
|
100
101
|
setWidths(snapshot);
|
|
101
|
-
e.currentTarget
|
|
102
|
+
capturePointer(e.currentTarget, e.pointerId);
|
|
102
103
|
}, [
|
|
103
104
|
minColumnWidth,
|
|
104
105
|
orderedColumns,
|
|
@@ -117,7 +118,7 @@ function useColumnResize({ orderedColumns, thRefs, minColumnWidth, onColumnResiz
|
|
|
117
118
|
endResize: useCallback((e) => {
|
|
118
119
|
const state = resizeRef.current;
|
|
119
120
|
resizeRef.current = null;
|
|
120
|
-
|
|
121
|
+
releasePointer(e.currentTarget, e.pointerId);
|
|
121
122
|
if (state) onColumnResize?.(state.key, widths[state.key] ?? state.startWidth);
|
|
122
123
|
}, [onColumnResize, widths])
|
|
123
124
|
};
|
|
@@ -201,6 +202,41 @@ function useRowSelection({ sortedRows, selectedRowIds, defaultSelectedRowIds, on
|
|
|
201
202
|
}
|
|
202
203
|
//#endregion
|
|
203
204
|
//#region src/components/motion/table/index.tsx
|
|
205
|
+
/**
|
|
206
|
+
* Narrowest a column of bare inputs may be floored to and still show a value:
|
|
207
|
+
* the cell's own `px-4` eats 32 of it.
|
|
208
|
+
*/
|
|
209
|
+
const INPUT_COLUMN_WIDTH = 120;
|
|
210
|
+
/** The root font size Tailwind's rem scale assumes, and the pre-measure guess. */
|
|
211
|
+
const DEFAULT_ROOT_FONT_SIZE = 16;
|
|
212
|
+
/**
|
|
213
|
+
* What one `rem` is worth here, in px. The default until the first client
|
|
214
|
+
* layout, so the server and the hydrating client emit the same floor; measured
|
|
215
|
+
* once after that, because a document that sets its own `html { font-size }`
|
|
216
|
+
* lays a rem column out against that size and a floor computed from 16 would
|
|
217
|
+
* fall short by the same factor.
|
|
218
|
+
*/
|
|
219
|
+
function useRootFontSize() {
|
|
220
|
+
const [size, setSize] = useState(DEFAULT_ROOT_FONT_SIZE);
|
|
221
|
+
useEffect(() => {
|
|
222
|
+
const measured = Number.parseFloat(getComputedStyle(document.documentElement).fontSize);
|
|
223
|
+
if (measured > 0) setSize(measured);
|
|
224
|
+
}, []);
|
|
225
|
+
return size;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* The absolute width a column declared, in px, or null when it declared a share
|
|
229
|
+
* of the remainder instead (`fr`, `%`, `auto`, `calc()`, nothing at all) — those
|
|
230
|
+
* are worth whatever is left over, which is not a width this can add up.
|
|
231
|
+
*/
|
|
232
|
+
function resolveColumnWidth(width, rootFontSize) {
|
|
233
|
+
if (!width) return null;
|
|
234
|
+
const value = Number.parseFloat(width);
|
|
235
|
+
if (!Number.isFinite(value)) return null;
|
|
236
|
+
if (width.endsWith("px")) return value;
|
|
237
|
+
if (width.endsWith("rem")) return value * rootFontSize;
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
204
240
|
function Table({ data, columns, getRowId, selectable = false, selectedRowIds, defaultSelectedRowIds, onSelectionChange, sort: sortProp, defaultSort = null, onSortChange, resizable = false, minColumnWidth = 64, onColumnResize, reorderable = false, onColumnOrderChange, onCellEdit, onColumnRename, onInsertRow, onDeleteRow, onInsertColumn, onDeleteColumn, rowHeight = 48, height = 440, overscan = 10, onEndReached, loading = false, skeletonRows = 3, emptyState = "No data", className }) {
|
|
205
241
|
const reduce = useReducedMotion();
|
|
206
242
|
const scrollRef = useRef(null);
|
|
@@ -246,6 +282,25 @@ function Table({ data, columns, getRowId, selectable = false, selectedRowIds, de
|
|
|
246
282
|
const hasRowMenu = !!(onInsertRow || onDeleteRow);
|
|
247
283
|
const hasColumnMenu = !!(onInsertColumn || onDeleteColumn);
|
|
248
284
|
const sized = orderedColumns.length > 0 && orderedColumns.every((c) => widths[c.key] != null);
|
|
285
|
+
const rootFontSize = useRootFontSize();
|
|
286
|
+
const minTableWidth = useMemo(() => {
|
|
287
|
+
const inputOnly = (column) => Boolean(onColumnRename) || !column.cell && Boolean(column.editable);
|
|
288
|
+
const total = orderedColumns.reduce((sum, column) => {
|
|
289
|
+
const resized = widths[column.key];
|
|
290
|
+
if (resized != null) return sum + resized;
|
|
291
|
+
const declared = resolveColumnWidth(column.width, rootFontSize);
|
|
292
|
+
if (declared != null) return sum + declared;
|
|
293
|
+
return sum + (inputOnly(column) ? Math.max(minColumnWidth, INPUT_COLUMN_WIDTH) : minColumnWidth);
|
|
294
|
+
}, selectable ? 48 : 0);
|
|
295
|
+
return Math.round(total);
|
|
296
|
+
}, [
|
|
297
|
+
minColumnWidth,
|
|
298
|
+
onColumnRename,
|
|
299
|
+
orderedColumns,
|
|
300
|
+
rootFontSize,
|
|
301
|
+
selectable,
|
|
302
|
+
widths
|
|
303
|
+
]);
|
|
249
304
|
const endReachedRef = useRef(false);
|
|
250
305
|
useEffect(() => {
|
|
251
306
|
if (!loading) endReachedRef.current = false;
|
|
@@ -298,8 +353,11 @@ function Table({ data, columns, getRowId, selectable = false, selectedRowIds, de
|
|
|
298
353
|
className: "overflow-auto",
|
|
299
354
|
style: { height },
|
|
300
355
|
children: /* @__PURE__ */ jsxs("table", {
|
|
301
|
-
className: cn("border-collapse", sized ? "w-max
|
|
302
|
-
style: {
|
|
356
|
+
className: cn("border-collapse", sized ? "w-max" : void 0),
|
|
357
|
+
style: {
|
|
358
|
+
tableLayout: "fixed",
|
|
359
|
+
minWidth: `max(100%, ${minTableWidth}px)`
|
|
360
|
+
},
|
|
303
361
|
children: [
|
|
304
362
|
/* @__PURE__ */ jsxs("colgroup", { children: [
|
|
305
363
|
selectable ? /* @__PURE__ */ jsx("col", { style: { width: CHECKBOX_WIDTH } }) : null,
|