@kumix/ui 0.3.9 → 0.3.11
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 +15 -14
- package/dist/components/motion/adaptive-stepper.d.ts +32 -0
- package/dist/components/motion/adaptive-stepper.d.ts.map +1 -0
- package/dist/components/motion/adaptive-stepper.js +302 -0
- package/dist/components/motion/adaptive-stepper.js.map +1 -0
- package/dist/components/motion/animated-sidebar.d.ts.map +1 -1
- package/dist/components/motion/animated-sidebar.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.map +1 -1
- package/dist/components/motion/availability-scheduler/day-row.js +15 -7
- package/dist/components/motion/availability-scheduler/day-row.js.map +1 -1
- package/dist/components/motion/availability-scheduler/index.js +1 -1
- package/dist/components/motion/button/index.d.ts +2 -1
- package/dist/components/motion/button/index.js +2 -1
- package/dist/components/motion/button/metallic.d.ts +10 -0
- package/dist/components/motion/button/metallic.d.ts.map +1 -0
- package/dist/components/motion/button/metallic.js +71 -0
- package/dist/components/motion/button/metallic.js.map +1 -0
- package/dist/components/motion/combobox/content.js +1 -1
- package/dist/components/motion/combobox/context.js +216 -1
- package/dist/components/motion/combobox/context.js.map +1 -0
- package/dist/components/motion/combobox/list.js +1 -1
- package/dist/components/motion/combobox/trigger.js +1 -1
- package/dist/components/motion/combobox.js +1 -1
- package/dist/components/motion/expandable-control.d.ts +28 -0
- package/dist/components/motion/expandable-control.d.ts.map +1 -0
- package/dist/components/motion/expandable-control.js +149 -0
- package/dist/components/motion/expandable-control.js.map +1 -0
- package/dist/components/motion/expanding-arrow-button.d.ts +12 -0
- package/dist/components/motion/expanding-arrow-button.d.ts.map +1 -0
- package/dist/components/motion/expanding-arrow-button.js +142 -0
- package/dist/components/motion/expanding-arrow-button.js.map +1 -0
- package/dist/components/motion/file-tree.d.ts +42 -0
- package/dist/components/motion/file-tree.d.ts.map +1 -0
- package/dist/components/motion/file-tree.js +272 -0
- package/dist/components/motion/file-tree.js.map +1 -0
- package/dist/components/motion/input.d.ts +2 -0
- package/dist/components/motion/input.d.ts.map +1 -1
- package/dist/components/motion/input.js +28 -25
- package/dist/components/motion/input.js.map +1 -1
- package/dist/components/motion/liquid.d.ts +30 -0
- package/dist/components/motion/liquid.d.ts.map +1 -0
- package/dist/components/motion/liquid.js +248 -0
- package/dist/components/motion/liquid.js.map +1 -0
- package/dist/components/motion/multi-select/content.d.ts +16 -0
- package/dist/components/motion/multi-select/content.d.ts.map +1 -0
- package/dist/components/motion/multi-select/content.js +91 -0
- package/dist/components/motion/multi-select/content.js.map +1 -0
- package/dist/components/motion/multi-select/context.d.ts +64 -0
- package/dist/components/motion/multi-select/context.d.ts.map +1 -0
- package/dist/{context-BizvUNZv.js → components/motion/multi-select/context.js} +44 -114
- package/dist/components/motion/multi-select/context.js.map +1 -0
- package/dist/components/motion/multi-select/index.d.ts +5 -0
- package/dist/components/motion/multi-select/index.js +6 -0
- package/dist/components/motion/multi-select/list.d.ts +40 -0
- package/dist/components/motion/multi-select/list.d.ts.map +1 -0
- package/dist/components/motion/multi-select/list.js +144 -0
- package/dist/components/motion/multi-select/list.js.map +1 -0
- package/dist/components/motion/multi-select/trigger.d.ts +22 -0
- package/dist/components/motion/multi-select/trigger.d.ts.map +1 -0
- package/dist/components/motion/multi-select/trigger.js +185 -0
- package/dist/components/motion/multi-select/trigger.js.map +1 -0
- package/dist/components/motion/signup-form.js +6 -2
- package/dist/components/motion/signup-form.js.map +1 -1
- package/dist/components/motion/table/index.js.map +1 -1
- package/dist/components/reui/alert.d.ts +1 -1
- package/dist/components/reui/badge.d.ts +1 -1
- package/dist/components/reui/cascader/cascader-async.d.ts.map +1 -1
- package/dist/components/reui/cascader/cascader-async.js.map +1 -1
- package/dist/components/reui/cascader/cascader-virtual.d.ts.map +1 -1
- package/dist/components/reui/cascader/cascader-virtual.js.map +1 -1
- package/dist/components/reui/cascader/cascader.d.ts.map +1 -1
- package/dist/components/reui/cascader/cascader.js.map +1 -1
- package/dist/components/reui/code-block/code-block-highlight.d.ts +216 -0
- package/dist/components/reui/code-block/code-block-highlight.d.ts.map +1 -0
- package/dist/components/reui/code-block/code-block-highlight.js +792 -0
- package/dist/components/reui/code-block/code-block-highlight.js.map +1 -0
- package/dist/components/reui/code-block/code-block.d.ts +197 -0
- package/dist/components/reui/code-block/code-block.d.ts.map +1 -0
- package/dist/components/reui/code-block/code-block.js +1150 -0
- package/dist/components/reui/code-block/code-block.js.map +1 -0
- package/dist/components/reui/data-grid/data-grid-cell-selection.d.ts +117 -0
- package/dist/components/reui/data-grid/data-grid-cell-selection.d.ts.map +1 -0
- package/dist/components/reui/data-grid/data-grid-cell-selection.js +1554 -0
- package/dist/components/reui/data-grid/data-grid-cell-selection.js.map +1 -0
- package/dist/components/reui/data-grid/data-grid-column-filter.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-column-filter.js +6 -4
- package/dist/components/reui/data-grid/data-grid-column-filter.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-column-header.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-column-header.js +10 -7
- package/dist/components/reui/data-grid/data-grid-column-header.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-column-visibility.js +3 -2
- package/dist/components/reui/data-grid/data-grid-column-visibility.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-i18n.d.ts +2 -0
- package/dist/components/reui/data-grid/data-grid-i18n.js +53 -0
- package/dist/components/reui/data-grid/data-grid-i18n.js.map +1 -0
- package/dist/components/reui/data-grid/data-grid-pagination.js +14 -8
- package/dist/components/reui/data-grid/data-grid-pagination.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-scroll-area.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-scroll-area.js +3 -3
- package/dist/components/reui/data-grid/data-grid-scroll-area.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table-dnd-rows.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table-dnd-rows.js +6 -4
- package/dist/components/reui/data-grid/data-grid-table-dnd-rows.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table-dnd.js +2 -2
- package/dist/components/reui/data-grid/data-grid-table-dnd.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table-virtual.d.ts +17 -1
- package/dist/components/reui/data-grid/data-grid-table-virtual.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table-virtual.js +146 -50
- package/dist/components/reui/data-grid/data-grid-table-virtual.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table.d.ts +23 -4
- package/dist/components/reui/data-grid/data-grid-table.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table.js +215 -68
- package/dist/components/reui/data-grid/data-grid-table.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid.d.ts +276 -6
- package/dist/components/reui/data-grid/data-grid.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid.js +150 -15
- package/dist/components/reui/data-grid/data-grid.js.map +1 -1
- package/dist/components/reui/filters/filters-advanced.js.map +1 -1
- package/dist/components/reui/filters/filters-chip.js.map +1 -1
- package/dist/components/reui/filters/filters.d.ts.map +1 -1
- package/dist/components/reui/filters/filters.js.map +1 -1
- package/dist/components/reui/frame.d.ts +1 -1
- package/dist/components/reui/gantt/gantt-bar.js +42 -12
- package/dist/components/reui/gantt/gantt-bar.js.map +1 -1
- package/dist/components/reui/gantt/gantt-dnd.d.ts.map +1 -1
- package/dist/components/reui/gantt/gantt-dnd.js +22 -7
- package/dist/components/reui/gantt/gantt-dnd.js.map +1 -1
- package/dist/components/reui/gantt/gantt-i18n.d.ts +8 -0
- package/dist/components/reui/gantt/gantt-i18n.d.ts.map +1 -1
- package/dist/components/reui/gantt/gantt-i18n.js +6 -1
- package/dist/components/reui/gantt/gantt-i18n.js.map +1 -1
- package/dist/components/reui/gantt/gantt-lib.d.ts +59 -2
- package/dist/components/reui/gantt/gantt-lib.d.ts.map +1 -1
- package/dist/components/reui/gantt/gantt-lib.js +67 -2
- package/dist/components/reui/gantt/gantt-lib.js.map +1 -1
- package/dist/components/reui/gantt/gantt-recurrence.js +3 -3
- package/dist/components/reui/gantt/gantt-recurrence.js.map +1 -1
- package/dist/components/reui/gantt/gantt-types.d.ts +32 -1
- package/dist/components/reui/gantt/gantt-types.d.ts.map +1 -1
- package/dist/components/reui/gantt/gantt-view.d.ts.map +1 -1
- package/dist/components/reui/gantt/gantt-view.js +324 -35
- package/dist/components/reui/gantt/gantt-view.js.map +1 -1
- package/dist/components/reui/gantt/gantt.d.ts +71 -2
- package/dist/components/reui/gantt/gantt.d.ts.map +1 -1
- package/dist/components/reui/gantt/gantt.js +8 -0
- package/dist/components/reui/gantt/gantt.js.map +1 -1
- package/dist/components/reui/icon-tile.d.ts +1 -1
- package/dist/components/ui/attachment.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-group.d.ts +1 -1
- package/dist/components/ui/button.d.ts +1 -1
- package/dist/components/ui/field.d.ts +1 -1
- package/dist/components/ui/item.d.ts +1 -1
- package/dist/components/ui/message-scroller.js +1 -1
- package/dist/components/ui/message-scroller.js.map +1 -1
- package/dist/components/ui/sidebar.d.ts +1 -1
- package/dist/components/ui/toggle.d.ts +1 -1
- package/dist/{copy-menu-1FKoMc9o.js → copy-menu-C5GaT4Z-.js} +67 -2
- package/dist/copy-menu-C5GaT4Z-.js.map +1 -0
- package/dist/data-grid-i18n-52UUYPbr.d.ts +66 -0
- package/dist/data-grid-i18n-52UUYPbr.d.ts.map +1 -0
- package/dist/types-smkWN_7x.d.ts.map +1 -1
- package/dist/use-active-option-CmX6Z-4S.js +86 -0
- package/dist/use-active-option-CmX6Z-4S.js.map +1 -0
- package/package.json +7 -13
- package/dist/context-BizvUNZv.js.map +0 -1
- package/dist/copy-menu-1FKoMc9o.js.map +0 -1
|
@@ -1,3 +1,218 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { t as useActiveOption } from "../../../use-active-option-CmX6Z-4S.js";
|
|
3
|
+
import { createContext, useCallback, useContext, useEffect, useId, useMemo, useRef, useState } from "react";
|
|
4
|
+
import { cn } from "@kumix/utils";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
import { useReducedMotion } from "motion/react";
|
|
7
|
+
//#region src/components/motion/combobox/context.tsx
|
|
8
|
+
const defaultFilter = (value, query, keywords) => {
|
|
9
|
+
const needle = query.trim().toLocaleLowerCase();
|
|
10
|
+
if (!needle) return true;
|
|
11
|
+
const haystack = [value, ...keywords].join(" ").toLocaleLowerCase();
|
|
12
|
+
let queryIndex = 0;
|
|
13
|
+
for (const character of haystack) {
|
|
14
|
+
if (character === needle[queryIndex]) queryIndex += 1;
|
|
15
|
+
if (queryIndex === needle.length) return true;
|
|
16
|
+
}
|
|
17
|
+
return false;
|
|
18
|
+
};
|
|
19
|
+
const ComboboxContext = createContext(null);
|
|
20
|
+
const ComboboxGroupContext = createContext(null);
|
|
21
|
+
function useComboboxContext(component) {
|
|
22
|
+
const context = useContext(ComboboxContext);
|
|
23
|
+
if (!context) throw new Error(`${component} must be used within <Combobox>`);
|
|
24
|
+
return context;
|
|
25
|
+
}
|
|
26
|
+
function mergeRefs(...refs) {
|
|
27
|
+
return (node) => {
|
|
28
|
+
for (const ref of refs) if (typeof ref === "function") ref(node);
|
|
29
|
+
else if (ref && typeof ref === "object") ref.current = node;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function Combobox({ children, value: controlledValue, defaultValue, onValueChange, open: controlledOpen, defaultOpen = false, onOpenChange, query: controlledQuery, defaultQuery = "", onQueryChange, filter = defaultFilter, disabled = false, className }) {
|
|
33
|
+
const reduce = useReducedMotion() ?? false;
|
|
34
|
+
const baseId = useId();
|
|
35
|
+
const rootRef = useRef(null);
|
|
36
|
+
const triggerRef = useRef(null);
|
|
37
|
+
const contentRef = useRef(null);
|
|
38
|
+
const inputRef = useRef(null);
|
|
39
|
+
const [internalValue, setInternalValue] = useState(defaultValue);
|
|
40
|
+
const [internalOpen, setInternalOpen] = useState(defaultOpen);
|
|
41
|
+
const [internalQuery, setInternalQuery] = useState(defaultQuery);
|
|
42
|
+
const [items, setItems] = useState(/* @__PURE__ */ new Map());
|
|
43
|
+
const valueControlled = controlledValue !== void 0;
|
|
44
|
+
const openControlled = controlledOpen !== void 0;
|
|
45
|
+
const queryControlled = controlledQuery !== void 0;
|
|
46
|
+
const value = valueControlled ? controlledValue : internalValue;
|
|
47
|
+
const open = openControlled ? controlledOpen : internalOpen;
|
|
48
|
+
const query = queryControlled ? controlledQuery : internalQuery;
|
|
49
|
+
const updateQuery = useCallback((next) => {
|
|
50
|
+
if (!queryControlled) setInternalQuery(next);
|
|
51
|
+
onQueryChange?.(next);
|
|
52
|
+
}, [onQueryChange, queryControlled]);
|
|
53
|
+
const updateOpen = useCallback((next, restoreFocus = false) => {
|
|
54
|
+
if (disabled && next) return;
|
|
55
|
+
if (!openControlled) setInternalOpen(next);
|
|
56
|
+
onOpenChange?.(next);
|
|
57
|
+
if (!next) updateQuery("");
|
|
58
|
+
if (restoreFocus) requestAnimationFrame(() => inputRef.current?.focus({ preventScroll: true }));
|
|
59
|
+
}, [
|
|
60
|
+
disabled,
|
|
61
|
+
onOpenChange,
|
|
62
|
+
openControlled,
|
|
63
|
+
updateQuery
|
|
64
|
+
]);
|
|
65
|
+
const registerItem = useCallback((item) => {
|
|
66
|
+
setItems((current) => {
|
|
67
|
+
const existing = current.get(item.value);
|
|
68
|
+
if (existing?.label === item.label && existing.disabled === item.disabled && existing.id === item.id && existing.ref === item.ref && existing.groupId === item.groupId && existing.keywords.join("\0") === item.keywords.join("\0")) return current;
|
|
69
|
+
const next = new Map(current);
|
|
70
|
+
next.set(item.value, item);
|
|
71
|
+
return next;
|
|
72
|
+
});
|
|
73
|
+
}, []);
|
|
74
|
+
const unregisterItem = useCallback((itemValue) => {
|
|
75
|
+
setItems((current) => {
|
|
76
|
+
if (!current.has(itemValue)) return current;
|
|
77
|
+
const next = new Map(current);
|
|
78
|
+
next.delete(itemValue);
|
|
79
|
+
return next;
|
|
80
|
+
});
|
|
81
|
+
}, []);
|
|
82
|
+
const [openQuery, setOpenQuery] = useState(query);
|
|
83
|
+
if (open && openQuery !== query) setOpenQuery(query);
|
|
84
|
+
const listQuery = open ? query : openQuery;
|
|
85
|
+
const visibleItems = useMemo(() => Array.from(items.values()).filter((item) => filter(item.value, listQuery, [item.label, ...item.keywords])), [
|
|
86
|
+
filter,
|
|
87
|
+
items,
|
|
88
|
+
listQuery
|
|
89
|
+
]);
|
|
90
|
+
const enabledVisibleItems = useMemo(() => visibleItems.filter((item) => !item.disabled), [visibleItems]);
|
|
91
|
+
const visibleValues = useMemo(() => new Set(visibleItems.map((item) => item.value)), [visibleItems]);
|
|
92
|
+
const visibleGroupIds = useMemo(() => new Set(visibleItems.map((item) => item.groupId)), [visibleItems]);
|
|
93
|
+
const { activeValue, setActiveValue, moveActive } = useActiveOption({
|
|
94
|
+
open,
|
|
95
|
+
query: listQuery,
|
|
96
|
+
value,
|
|
97
|
+
enabledItems: enabledVisibleItems
|
|
98
|
+
});
|
|
99
|
+
const select = useCallback((next) => {
|
|
100
|
+
if (items.get(next)?.disabled) return;
|
|
101
|
+
if (!valueControlled) setInternalValue(next);
|
|
102
|
+
onValueChange?.(next);
|
|
103
|
+
updateOpen(false, true);
|
|
104
|
+
}, [
|
|
105
|
+
items,
|
|
106
|
+
onValueChange,
|
|
107
|
+
updateOpen,
|
|
108
|
+
valueControlled
|
|
109
|
+
]);
|
|
110
|
+
const selectActive = useCallback(() => {
|
|
111
|
+
if (activeValue) select(activeValue);
|
|
112
|
+
}, [activeValue, select]);
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
if (!open) return;
|
|
115
|
+
const frame = requestAnimationFrame(() => inputRef.current?.focus({ preventScroll: true }));
|
|
116
|
+
return () => cancelAnimationFrame(frame);
|
|
117
|
+
}, [open]);
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
if (!activeValue || !open) return;
|
|
120
|
+
const item = items.get(activeValue)?.ref.current;
|
|
121
|
+
const list = item?.closest("[role='listbox']");
|
|
122
|
+
if (!item || !list) return;
|
|
123
|
+
const itemRect = item.getBoundingClientRect();
|
|
124
|
+
const listRect = list.getBoundingClientRect();
|
|
125
|
+
if (itemRect.top < listRect.top) list.scrollTop -= listRect.top - itemRect.top;
|
|
126
|
+
else if (itemRect.bottom > listRect.bottom) list.scrollTop += itemRect.bottom - listRect.bottom;
|
|
127
|
+
}, [
|
|
128
|
+
activeValue,
|
|
129
|
+
items,
|
|
130
|
+
open
|
|
131
|
+
]);
|
|
132
|
+
useEffect(() => {
|
|
133
|
+
if (!open) return;
|
|
134
|
+
const isInside = (target) => rootRef.current?.contains(target) || contentRef.current?.contains(target);
|
|
135
|
+
const onPointerDown = (event) => {
|
|
136
|
+
if (!isInside(event.target)) updateOpen(false);
|
|
137
|
+
};
|
|
138
|
+
const onFocusIn = (event) => {
|
|
139
|
+
if (!isInside(event.target)) updateOpen(false);
|
|
140
|
+
};
|
|
141
|
+
const onKeyDown = (event) => {
|
|
142
|
+
if (event.key !== "Escape") return;
|
|
143
|
+
event.preventDefault();
|
|
144
|
+
updateOpen(false, true);
|
|
145
|
+
};
|
|
146
|
+
window.addEventListener("pointerdown", onPointerDown);
|
|
147
|
+
window.addEventListener("focusin", onFocusIn);
|
|
148
|
+
window.addEventListener("keydown", onKeyDown);
|
|
149
|
+
return () => {
|
|
150
|
+
window.removeEventListener("pointerdown", onPointerDown);
|
|
151
|
+
window.removeEventListener("focusin", onFocusIn);
|
|
152
|
+
window.removeEventListener("keydown", onKeyDown);
|
|
153
|
+
};
|
|
154
|
+
}, [open, updateOpen]);
|
|
155
|
+
const activeItem = activeValue ? items.get(activeValue) : void 0;
|
|
156
|
+
const context = useMemo(() => ({
|
|
157
|
+
open,
|
|
158
|
+
setOpen: updateOpen,
|
|
159
|
+
value,
|
|
160
|
+
select,
|
|
161
|
+
query,
|
|
162
|
+
setQuery: updateQuery,
|
|
163
|
+
activeValue,
|
|
164
|
+
setActiveValue,
|
|
165
|
+
moveActive,
|
|
166
|
+
selectActive,
|
|
167
|
+
registerItem,
|
|
168
|
+
unregisterItem,
|
|
169
|
+
labelFor: (itemValue) => itemValue === void 0 ? void 0 : items.get(itemValue)?.label,
|
|
170
|
+
isVisible: (itemValue) => !listQuery.trim() || visibleValues.has(itemValue),
|
|
171
|
+
hasVisibleItems: (groupId) => visibleGroupIds.has(groupId),
|
|
172
|
+
visibleCount: visibleItems.length,
|
|
173
|
+
activeItemId: activeItem?.id,
|
|
174
|
+
triggerId: `${baseId}-trigger`,
|
|
175
|
+
listId: `${baseId}-list`,
|
|
176
|
+
inputId: `${baseId}-input`,
|
|
177
|
+
disabled,
|
|
178
|
+
reduce,
|
|
179
|
+
triggerRef,
|
|
180
|
+
contentRef,
|
|
181
|
+
inputRef,
|
|
182
|
+
activeLayoutId: `${baseId}-active`
|
|
183
|
+
}), [
|
|
184
|
+
activeItem?.id,
|
|
185
|
+
activeValue,
|
|
186
|
+
baseId,
|
|
187
|
+
disabled,
|
|
188
|
+
items,
|
|
189
|
+
listQuery,
|
|
190
|
+
moveActive,
|
|
191
|
+
open,
|
|
192
|
+
query,
|
|
193
|
+
reduce,
|
|
194
|
+
registerItem,
|
|
195
|
+
select,
|
|
196
|
+
selectActive,
|
|
197
|
+
setActiveValue,
|
|
198
|
+
unregisterItem,
|
|
199
|
+
updateOpen,
|
|
200
|
+
updateQuery,
|
|
201
|
+
value,
|
|
202
|
+
visibleItems.length,
|
|
203
|
+
visibleGroupIds,
|
|
204
|
+
visibleValues
|
|
205
|
+
]);
|
|
206
|
+
return /* @__PURE__ */ jsx(ComboboxContext.Provider, {
|
|
207
|
+
value: context,
|
|
208
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
209
|
+
ref: rootRef,
|
|
210
|
+
className: cn("relative w-full", className),
|
|
211
|
+
children
|
|
212
|
+
})
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
//#endregion
|
|
3
216
|
export { Combobox, ComboboxContext, ComboboxGroupContext, mergeRefs, useComboboxContext };
|
|
217
|
+
|
|
218
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","names":[],"sources":["../../../../src/components/motion/combobox/context.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n createContext,\n type MutableRefObject,\n type ReactNode,\n type Ref,\n useCallback,\n useContext,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { useReducedMotion } from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { useActiveOption } from \"./use-active-option\";\n\nexport type RegisteredItem = {\n value: string;\n label: string;\n keywords: string[];\n disabled: boolean;\n groupId: string | null;\n id: string;\n ref: MutableRefObject<HTMLButtonElement | null>;\n};\n\nexport type ComboboxFilter = (value: string, query: string, keywords: string[]) => boolean;\n\nconst defaultFilter: ComboboxFilter = (value, query, keywords) => {\n const needle = query.trim().toLocaleLowerCase();\n if (!needle) return true;\n\n const haystack = [value, ...keywords].join(\" \").toLocaleLowerCase();\n let queryIndex = 0;\n for (const character of haystack) {\n if (character === needle[queryIndex]) queryIndex += 1;\n if (queryIndex === needle.length) return true;\n }\n return false;\n};\n\nexport type ComboboxContextValue = {\n open: boolean;\n setOpen: (open: boolean, restoreFocus?: boolean) => void;\n value: string | undefined;\n select: (value: string) => void;\n query: string;\n setQuery: (query: string) => void;\n /** The option the list is currently pointing at, resolved during render. */\n activeValue: string | null;\n /**\n * Records where the pointer or keyboard moved to. The recorded value is\n * dropped when the query or the result set changes, so it does not always\n * survive to the next `activeValue`.\n */\n setActiveValue: (value: string | null) => void;\n moveActive: (direction: 1 | -1 | \"first\" | \"last\") => void;\n selectActive: () => void;\n registerItem: (item: RegisteredItem) => void;\n unregisterItem: (value: string) => void;\n labelFor: (value: string | undefined) => string | undefined;\n isVisible: (value: string) => boolean;\n hasVisibleItems: (groupId: string) => boolean;\n visibleCount: number;\n activeItemId: string | undefined;\n triggerId: string;\n listId: string;\n inputId: string;\n disabled: boolean;\n reduce: boolean;\n triggerRef: MutableRefObject<HTMLDivElement | null>;\n contentRef: MutableRefObject<HTMLDivElement | null>;\n inputRef: MutableRefObject<HTMLInputElement | null>;\n activeLayoutId: string;\n};\n\nexport const ComboboxContext = createContext<ComboboxContextValue | null>(null);\nexport const ComboboxGroupContext = createContext<string | null>(null);\n\nexport function useComboboxContext(component: string) {\n const context = useContext(ComboboxContext);\n if (!context) throw new Error(`${component} must be used within <Combobox>`);\n return context;\n}\n\nexport function mergeRefs<T>(...refs: Array<Ref<T> | undefined>) {\n return (node: T | null) => {\n for (const ref of refs) {\n if (typeof ref === \"function\") ref(node);\n else if (ref && typeof ref === \"object\") (ref as MutableRefObject<T | null>).current = node;\n }\n };\n}\n\nexport interface ComboboxProps {\n children: ReactNode;\n value?: string;\n defaultValue?: string;\n onValueChange?: (value: string) => void;\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n query?: string;\n defaultQuery?: string;\n onQueryChange?: (query: string) => void;\n filter?: ComboboxFilter;\n disabled?: boolean;\n className?: string;\n}\n\nexport function Combobox({\n children,\n value: controlledValue,\n defaultValue,\n onValueChange,\n open: controlledOpen,\n defaultOpen = false,\n onOpenChange,\n query: controlledQuery,\n defaultQuery = \"\",\n onQueryChange,\n filter = defaultFilter,\n disabled = false,\n className,\n}: ComboboxProps) {\n const reduce = useReducedMotion() ?? false;\n const baseId = useId();\n const rootRef = useRef<HTMLDivElement>(null);\n const triggerRef = useRef<HTMLDivElement>(null);\n const contentRef = useRef<HTMLDivElement>(null);\n const inputRef = useRef<HTMLInputElement>(null);\n const [internalValue, setInternalValue] = useState(defaultValue);\n const [internalOpen, setInternalOpen] = useState(defaultOpen);\n const [internalQuery, setInternalQuery] = useState(defaultQuery);\n const [items, setItems] = useState<Map<string, RegisteredItem>>(new Map());\n\n const valueControlled = controlledValue !== undefined;\n const openControlled = controlledOpen !== undefined;\n const queryControlled = controlledQuery !== undefined;\n const value = valueControlled ? controlledValue : internalValue;\n const open = openControlled ? controlledOpen : internalOpen;\n const query = queryControlled ? controlledQuery : internalQuery;\n\n const updateQuery = useCallback(\n (next: string) => {\n if (!queryControlled) setInternalQuery(next);\n onQueryChange?.(next);\n },\n [onQueryChange, queryControlled],\n );\n\n const updateOpen = useCallback(\n (next: boolean, restoreFocus = false) => {\n if (disabled && next) return;\n if (!openControlled) setInternalOpen(next);\n onOpenChange?.(next);\n if (!next) updateQuery(\"\");\n if (restoreFocus)\n requestAnimationFrame(() => inputRef.current?.focus({ preventScroll: true }));\n },\n [disabled, onOpenChange, openControlled, updateQuery],\n );\n\n const registerItem = useCallback((item: RegisteredItem) => {\n setItems((current) => {\n const existing = current.get(item.value);\n if (\n existing?.label === item.label &&\n existing.disabled === item.disabled &&\n existing.id === item.id &&\n existing.ref === item.ref &&\n existing.groupId === item.groupId &&\n existing.keywords.join(\"\\u0000\") === item.keywords.join(\"\\u0000\")\n ) {\n return current;\n }\n const next = new Map(current);\n next.set(item.value, item);\n return next;\n });\n }, []);\n\n const unregisterItem = useCallback((itemValue: string) => {\n setItems((current) => {\n if (!current.has(itemValue)) return current;\n const next = new Map(current);\n next.delete(itemValue);\n return next;\n });\n }, []);\n\n // The query the list filters by. Closing clears `query`, but the panel is\n // still on screen for its exit, so it keeps filtering by the query it was\n // open with rather than repopulating mid-collapse. The input already reads\n // `query` only while open, so nothing the user can see reads the other one.\n const [openQuery, setOpenQuery] = useState(query);\n if (open && openQuery !== query) setOpenQuery(query);\n const listQuery = open ? query : openQuery;\n\n const visibleItems = useMemo(\n () =>\n Array.from(items.values()).filter((item) =>\n filter(item.value, listQuery, [item.label, ...item.keywords]),\n ),\n [filter, items, listQuery],\n );\n const enabledVisibleItems = useMemo(\n () => visibleItems.filter((item) => !item.disabled),\n [visibleItems],\n );\n const visibleValues = useMemo(\n () => new Set(visibleItems.map((item) => item.value)),\n [visibleItems],\n );\n const visibleGroupIds = useMemo(\n () => new Set(visibleItems.map((item) => item.groupId)),\n [visibleItems],\n );\n\n const { activeValue, setActiveValue, moveActive } = useActiveOption({\n open,\n query: listQuery,\n value,\n enabledItems: enabledVisibleItems,\n });\n\n const select = useCallback(\n (next: string) => {\n if (items.get(next)?.disabled) return;\n if (!valueControlled) setInternalValue(next);\n onValueChange?.(next);\n updateOpen(false, true);\n },\n [items, onValueChange, updateOpen, valueControlled],\n );\n\n const selectActive = useCallback(() => {\n if (activeValue) select(activeValue);\n }, [activeValue, select]);\n\n useEffect(() => {\n if (!open) return;\n const frame = requestAnimationFrame(() => inputRef.current?.focus({ preventScroll: true }));\n return () => cancelAnimationFrame(frame);\n }, [open]);\n\n useEffect(() => {\n if (!activeValue || !open) return;\n const item = items.get(activeValue)?.ref.current;\n const list = item?.closest<HTMLElement>(\"[role='listbox']\");\n if (!item || !list) return;\n const itemRect = item.getBoundingClientRect();\n const listRect = list.getBoundingClientRect();\n if (itemRect.top < listRect.top) list.scrollTop -= listRect.top - itemRect.top;\n else if (itemRect.bottom > listRect.bottom) list.scrollTop += itemRect.bottom - listRect.bottom;\n }, [activeValue, items, open]);\n\n useEffect(() => {\n if (!open) return;\n const isInside = (target: Node) =>\n rootRef.current?.contains(target) || contentRef.current?.contains(target);\n const onPointerDown = (event: PointerEvent) => {\n if (!isInside(event.target as Node)) updateOpen(false);\n };\n const onFocusIn = (event: FocusEvent) => {\n if (!isInside(event.target as Node)) updateOpen(false);\n };\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.key !== \"Escape\") return;\n event.preventDefault();\n updateOpen(false, true);\n };\n window.addEventListener(\"pointerdown\", onPointerDown);\n window.addEventListener(\"focusin\", onFocusIn);\n window.addEventListener(\"keydown\", onKeyDown);\n return () => {\n window.removeEventListener(\"pointerdown\", onPointerDown);\n window.removeEventListener(\"focusin\", onFocusIn);\n window.removeEventListener(\"keydown\", onKeyDown);\n };\n }, [open, updateOpen]);\n\n const activeItem = activeValue ? items.get(activeValue) : undefined;\n const context = useMemo<ComboboxContextValue>(\n () => ({\n open,\n setOpen: updateOpen,\n value,\n select,\n query,\n setQuery: updateQuery,\n activeValue,\n setActiveValue,\n moveActive,\n selectActive,\n registerItem,\n unregisterItem,\n labelFor: (itemValue) => (itemValue === undefined ? undefined : items.get(itemValue)?.label),\n isVisible: (itemValue) => !listQuery.trim() || visibleValues.has(itemValue),\n hasVisibleItems: (groupId) => visibleGroupIds.has(groupId),\n visibleCount: visibleItems.length,\n activeItemId: activeItem?.id,\n triggerId: `${baseId}-trigger`,\n listId: `${baseId}-list`,\n inputId: `${baseId}-input`,\n disabled,\n reduce,\n triggerRef,\n contentRef,\n inputRef,\n activeLayoutId: `${baseId}-active`,\n }),\n [\n activeItem?.id,\n activeValue,\n baseId,\n disabled,\n items,\n listQuery,\n moveActive,\n open,\n query,\n reduce,\n registerItem,\n select,\n selectActive,\n setActiveValue,\n unregisterItem,\n updateOpen,\n updateQuery,\n value,\n visibleItems.length,\n visibleGroupIds,\n visibleValues,\n ],\n );\n\n return (\n <ComboboxContext.Provider value={context}>\n <div ref={rootRef} className={cn(\"relative w-full\", className)}>\n {children}\n </div>\n </ComboboxContext.Provider>\n );\n}\n"],"mappings":";;;;;;;AAgCA,MAAM,iBAAiC,OAAO,OAAO,aAAa;CAChE,MAAM,SAAS,MAAM,KAAK,CAAC,CAAC,kBAAkB;CAC9C,IAAI,CAAC,QAAQ,OAAO;CAEpB,MAAM,WAAW,CAAC,OAAO,GAAG,QAAQ,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,kBAAkB;CAClE,IAAI,aAAa;CACjB,KAAK,MAAM,aAAa,UAAU;EAChC,IAAI,cAAc,OAAO,aAAa,cAAc;EACpD,IAAI,eAAe,OAAO,QAAQ,OAAO;CAC3C;CACA,OAAO;AACT;AAqCA,MAAa,kBAAkB,cAA2C,IAAI;AAC9E,MAAa,uBAAuB,cAA6B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,aAAa;EACb;EACA;CACF,CACF;CAEA,OACE,oBAAC,gBAAgB,UAAjB;EAA0B,OAAO;EAC/B,UAAA,oBAAC,OAAD;GAAK,KAAK;GAAS,WAAW,GAAG,mBAAmB,SAAS;GAC1D;EACE,CAAA;CACmB,CAAA;AAE9B"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { EASE_OUT, SPRING_LAYOUT } from "../../../lib/ease.js";
|
|
3
|
-
import {
|
|
3
|
+
import { ComboboxGroupContext, useComboboxContext } from "./context.js";
|
|
4
4
|
import { useContext, useId, useLayoutEffect, useMemo, useRef } from "react";
|
|
5
5
|
import { cn } from "@kumix/utils";
|
|
6
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { mergeRefs, useComboboxContext } from "./context.js";
|
|
3
3
|
import { cn } from "@kumix/utils";
|
|
4
4
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
5
|
import { ChevronsUpDown, Search } from "lucide-react";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { Combobox } from "./combobox/context.js";
|
|
3
3
|
import { ComboboxContent } from "./combobox/content.js";
|
|
4
4
|
import { ComboboxEmpty, ComboboxGroup, ComboboxItem, ComboboxLabel, ComboboxList, ComboboxSeparator } from "./combobox/list.js";
|
|
5
5
|
import { ComboboxInput, ComboboxTrigger, ComboboxValue } from "./combobox/trigger.js";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
import { HTMLMotionProps } from "motion/react";
|
|
3
|
+
//#region src/components/motion/expandable-control.d.ts
|
|
4
|
+
type ExpandableStateProps = {
|
|
5
|
+
expanded?: boolean;
|
|
6
|
+
defaultExpanded?: boolean;
|
|
7
|
+
onExpandedChange?: (expanded: boolean) => void;
|
|
8
|
+
};
|
|
9
|
+
interface ExpandableButtonProps extends Omit<HTMLMotionProps<"button">, "children">, ExpandableStateProps {
|
|
10
|
+
icon: ReactNode;
|
|
11
|
+
label: ReactNode;
|
|
12
|
+
}
|
|
13
|
+
interface ExpandableChipProps extends ExpandableStateProps {
|
|
14
|
+
label: ReactNode;
|
|
15
|
+
actionIcon: ReactNode;
|
|
16
|
+
actionLabel: string;
|
|
17
|
+
onAction?: () => void;
|
|
18
|
+
collapseOnAction?: boolean;
|
|
19
|
+
disabled?: boolean;
|
|
20
|
+
className?: string;
|
|
21
|
+
labelClassName?: string;
|
|
22
|
+
actionClassName?: string;
|
|
23
|
+
}
|
|
24
|
+
declare function ExpandableButton({ icon, label, expanded, defaultExpanded, onExpandedChange, className, onClick, disabled, type, "aria-label": ariaLabel, ...props }: ExpandableButtonProps): import("react").JSX.Element;
|
|
25
|
+
declare function ExpandableChip({ label, actionIcon, actionLabel, onAction, collapseOnAction, expanded, defaultExpanded, onExpandedChange, disabled, className, labelClassName, actionClassName }: ExpandableChipProps): import("react").JSX.Element;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { ExpandableButton, ExpandableButtonProps, ExpandableChip, ExpandableChipProps };
|
|
28
|
+
//# sourceMappingURL=expandable-control.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expandable-control.d.ts","names":[],"sources":["../../../src/components/motion/expandable-control.tsx"],"mappings":";;;KA6BK;EACH;EACA;EACA,oBAAoB;;UAGL,8BACP,KAAK,wCACX;EACF,MAAM;EACN,OAAO;;UAGQ,4BAA4B;EAC3C,OAAO;EACP,YAAY;EACZ;EACA;EACA;EACA;EACA;EACA;EACA;;iBAyBc,mBACd,MACA,OACA,UACA,iBACA,kBACA,WACA,SACA,UACA,oBACc,cACX,SACF,wCAAqB,IAAA;iBAiER,iBACd,OACA,YACA,aACA,UACA,kBACA,UACA,iBACA,kBACA,UACA,WACA,gBACA,mBACC,sCAAmB,IAAA"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useRef, useState } from "react";
|
|
3
|
+
import { cn } from "@kumix/utils";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { AnimatePresence, motion, useReducedMotion } from "motion/react";
|
|
6
|
+
//#region src/components/motion/expandable-control.tsx
|
|
7
|
+
const CONTINUITY_SPRING = {
|
|
8
|
+
type: "spring",
|
|
9
|
+
stiffness: 220,
|
|
10
|
+
damping: 17,
|
|
11
|
+
mass: .85
|
|
12
|
+
};
|
|
13
|
+
const CONTINUITY_LABEL = {
|
|
14
|
+
hidden: {
|
|
15
|
+
opacity: 0,
|
|
16
|
+
filter: "blur(4px)"
|
|
17
|
+
},
|
|
18
|
+
visible: {
|
|
19
|
+
opacity: 1,
|
|
20
|
+
filter: "blur(0px)"
|
|
21
|
+
},
|
|
22
|
+
exit: {
|
|
23
|
+
opacity: 0,
|
|
24
|
+
filter: "blur(4px)"
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
function useExpandableState({ expanded, defaultExpanded = false, onExpandedChange }) {
|
|
28
|
+
const [internalExpanded, setInternalExpanded] = useState(defaultExpanded);
|
|
29
|
+
const isControlled = expanded !== void 0;
|
|
30
|
+
return [expanded ?? internalExpanded, useCallback((nextExpanded) => {
|
|
31
|
+
if (!isControlled) setInternalExpanded(nextExpanded);
|
|
32
|
+
onExpandedChange?.(nextExpanded);
|
|
33
|
+
}, [isControlled, onExpandedChange])];
|
|
34
|
+
}
|
|
35
|
+
function ExpandableButton({ icon, label, expanded, defaultExpanded, onExpandedChange, className, onClick, disabled, type = "button", "aria-label": ariaLabel, ...props }) {
|
|
36
|
+
const reduce = useReducedMotion();
|
|
37
|
+
const [isExpanded, setExpanded] = useExpandableState({
|
|
38
|
+
expanded,
|
|
39
|
+
defaultExpanded,
|
|
40
|
+
onExpandedChange
|
|
41
|
+
});
|
|
42
|
+
const handleClick = (event) => {
|
|
43
|
+
onClick?.(event);
|
|
44
|
+
if (!event.defaultPrevented) setExpanded(!isExpanded);
|
|
45
|
+
};
|
|
46
|
+
const transition = reduce ? { duration: 0 } : CONTINUITY_SPRING;
|
|
47
|
+
return /* @__PURE__ */ jsx(motion.span, {
|
|
48
|
+
layout: true,
|
|
49
|
+
transition,
|
|
50
|
+
className: "inline-flex",
|
|
51
|
+
children: /* @__PURE__ */ jsxs(motion.button, {
|
|
52
|
+
...props,
|
|
53
|
+
layout: true,
|
|
54
|
+
type,
|
|
55
|
+
"aria-label": ariaLabel ?? (typeof label === "string" ? label : void 0),
|
|
56
|
+
"aria-expanded": isExpanded,
|
|
57
|
+
disabled,
|
|
58
|
+
className: cn("relative inline-flex h-11 min-w-11 items-center overflow-hidden rounded-full border border-border bg-transparent p-1 pr-1 font-medium text-foreground text-sm outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset disabled:pointer-events-none disabled:opacity-50", className),
|
|
59
|
+
style: { borderRadius: 9999 },
|
|
60
|
+
onClick: handleClick,
|
|
61
|
+
whileTap: reduce || disabled ? void 0 : { scale: .97 },
|
|
62
|
+
transition,
|
|
63
|
+
children: [/* @__PURE__ */ jsx(motion.span, {
|
|
64
|
+
layout: "position",
|
|
65
|
+
className: "grid size-9 shrink-0 place-items-center",
|
|
66
|
+
"aria-hidden": "true",
|
|
67
|
+
transition,
|
|
68
|
+
children: icon
|
|
69
|
+
}), /* @__PURE__ */ jsx(AnimatePresence, {
|
|
70
|
+
mode: "popLayout",
|
|
71
|
+
initial: false,
|
|
72
|
+
children: isExpanded ? /* @__PURE__ */ jsx(motion.span, {
|
|
73
|
+
layout: true,
|
|
74
|
+
variants: CONTINUITY_LABEL,
|
|
75
|
+
initial: reduce ? { opacity: 0 } : "hidden",
|
|
76
|
+
animate: reduce ? { opacity: 1 } : "visible",
|
|
77
|
+
exit: reduce ? { opacity: 0 } : "exit",
|
|
78
|
+
transition,
|
|
79
|
+
className: "relative inline-flex w-max items-center whitespace-nowrap pr-3",
|
|
80
|
+
"aria-hidden": "true",
|
|
81
|
+
children: label
|
|
82
|
+
}, "label") : null
|
|
83
|
+
})]
|
|
84
|
+
})
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
function ExpandableChip({ label, actionIcon, actionLabel, onAction, collapseOnAction = true, expanded, defaultExpanded, onExpandedChange, disabled, className, labelClassName, actionClassName }) {
|
|
88
|
+
const reduce = useReducedMotion();
|
|
89
|
+
const triggerRef = useRef(null);
|
|
90
|
+
const [isExpanded, setExpanded] = useExpandableState({
|
|
91
|
+
expanded,
|
|
92
|
+
defaultExpanded,
|
|
93
|
+
onExpandedChange
|
|
94
|
+
});
|
|
95
|
+
const handleAction = () => {
|
|
96
|
+
onAction?.();
|
|
97
|
+
if (collapseOnAction) {
|
|
98
|
+
setExpanded(false);
|
|
99
|
+
triggerRef.current?.focus();
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
const transition = reduce ? { duration: 0 } : CONTINUITY_SPRING;
|
|
103
|
+
return /* @__PURE__ */ jsx(motion.span, {
|
|
104
|
+
layout: true,
|
|
105
|
+
transition,
|
|
106
|
+
className: "inline-flex",
|
|
107
|
+
children: /* @__PURE__ */ jsxs(motion.div, {
|
|
108
|
+
layout: true,
|
|
109
|
+
className: cn("inline-flex h-10 items-center overflow-hidden rounded-full border border-border bg-transparent text-foreground text-sm has-focus-visible:ring-2 has-focus-visible:ring-ring has-focus-visible:ring-inset", className),
|
|
110
|
+
style: { borderRadius: 9999 },
|
|
111
|
+
transition,
|
|
112
|
+
children: [/* @__PURE__ */ jsx(motion.button, {
|
|
113
|
+
layout: "position",
|
|
114
|
+
ref: triggerRef,
|
|
115
|
+
type: "button",
|
|
116
|
+
"aria-expanded": isExpanded,
|
|
117
|
+
disabled,
|
|
118
|
+
className: cn("h-full whitespace-nowrap py-0 pl-3 font-medium outline-none disabled:pointer-events-none disabled:opacity-50", isExpanded ? "pr-1" : "pr-3", labelClassName),
|
|
119
|
+
onClick: () => setExpanded(!isExpanded),
|
|
120
|
+
transition,
|
|
121
|
+
children: label
|
|
122
|
+
}), /* @__PURE__ */ jsx(motion.span, {
|
|
123
|
+
variants: CONTINUITY_LABEL,
|
|
124
|
+
className: cn("relative inline-flex h-10 shrink-0 items-center overflow-hidden", isExpanded ? "w-8" : "w-0"),
|
|
125
|
+
"aria-hidden": !isExpanded,
|
|
126
|
+
initial: false,
|
|
127
|
+
animate: reduce ? { opacity: isExpanded ? 1 : 0 } : isExpanded ? "visible" : "hidden",
|
|
128
|
+
transition,
|
|
129
|
+
children: /* @__PURE__ */ jsx(motion.button, {
|
|
130
|
+
type: "button",
|
|
131
|
+
"aria-label": actionLabel,
|
|
132
|
+
disabled: disabled || !isExpanded,
|
|
133
|
+
className: cn("flex h-10 w-8 shrink-0 items-center justify-center rounded-full text-muted-foreground outline-none transition-colors hover:text-foreground disabled:pointer-events-none", disabled && "opacity-50", actionClassName),
|
|
134
|
+
onClick: handleAction,
|
|
135
|
+
whileTap: reduce || disabled ? void 0 : { scale: .97 },
|
|
136
|
+
transition,
|
|
137
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
138
|
+
"aria-hidden": "true",
|
|
139
|
+
children: actionIcon
|
|
140
|
+
})
|
|
141
|
+
})
|
|
142
|
+
})]
|
|
143
|
+
})
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
//#endregion
|
|
147
|
+
export { ExpandableButton, ExpandableChip };
|
|
148
|
+
|
|
149
|
+
//# sourceMappingURL=expandable-control.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expandable-control.js","names":[],"sources":["../../../src/components/motion/expandable-control.tsx"],"sourcesContent":["\"use client\";\n\nimport { type MouseEvent, type ReactNode, useCallback, useRef, useState } from \"react\";\nimport {\n AnimatePresence,\n type HTMLMotionProps,\n motion,\n type Transition,\n useReducedMotion,\n type Variants,\n} from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\n\n// Matches the Motion Patterns \"Layout continuity\" recipe so the surface\n// keeps its identity while its footprint changes.\nconst CONTINUITY_SPRING: Transition = {\n type: \"spring\",\n stiffness: 220,\n damping: 17,\n mass: 0.85,\n};\n\nconst CONTINUITY_LABEL: Variants = {\n hidden: { opacity: 0, filter: \"blur(4px)\" },\n visible: { opacity: 1, filter: \"blur(0px)\" },\n exit: { opacity: 0, filter: \"blur(4px)\" },\n};\n\ntype ExpandableStateProps = {\n expanded?: boolean;\n defaultExpanded?: boolean;\n onExpandedChange?: (expanded: boolean) => void;\n};\n\nexport interface ExpandableButtonProps\n extends Omit<HTMLMotionProps<\"button\">, \"children\">,\n ExpandableStateProps {\n icon: ReactNode;\n label: ReactNode;\n}\n\nexport interface ExpandableChipProps extends ExpandableStateProps {\n label: ReactNode;\n actionIcon: ReactNode;\n actionLabel: string;\n onAction?: () => void;\n collapseOnAction?: boolean;\n disabled?: boolean;\n className?: string;\n labelClassName?: string;\n actionClassName?: string;\n}\n\nfunction useExpandableState({\n expanded,\n defaultExpanded = false,\n onExpandedChange,\n}: ExpandableStateProps) {\n const [internalExpanded, setInternalExpanded] = useState(defaultExpanded);\n const isControlled = expanded !== undefined;\n const currentExpanded = expanded ?? internalExpanded;\n\n const setExpanded = useCallback(\n (nextExpanded: boolean) => {\n if (!isControlled) {\n setInternalExpanded(nextExpanded);\n }\n onExpandedChange?.(nextExpanded);\n },\n [isControlled, onExpandedChange],\n );\n\n return [currentExpanded, setExpanded] as const;\n}\n\nexport function ExpandableButton({\n icon,\n label,\n expanded,\n defaultExpanded,\n onExpandedChange,\n className,\n onClick,\n disabled,\n type = \"button\",\n \"aria-label\": ariaLabel,\n ...props\n}: ExpandableButtonProps) {\n const reduce = useReducedMotion();\n const [isExpanded, setExpanded] = useExpandableState({\n expanded,\n defaultExpanded,\n onExpandedChange,\n });\n\n const handleClick = (event: MouseEvent<HTMLButtonElement>) => {\n onClick?.(event);\n if (!event.defaultPrevented) {\n setExpanded(!isExpanded);\n }\n };\n\n const transition = reduce ? { duration: 0 } : CONTINUITY_SPRING;\n\n return (\n <motion.span layout transition={transition} className=\"inline-flex\">\n <motion.button\n {...props}\n layout\n type={type}\n aria-label={ariaLabel ?? (typeof label === \"string\" ? label : undefined)}\n aria-expanded={isExpanded}\n disabled={disabled}\n className={cn(\n \"relative inline-flex h-11 min-w-11 items-center overflow-hidden rounded-full border border-border bg-transparent p-1 pr-1 font-medium text-foreground text-sm outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset disabled:pointer-events-none disabled:opacity-50\",\n className,\n )}\n style={{ borderRadius: 9999 }}\n onClick={handleClick}\n whileTap={reduce || disabled ? undefined : { scale: 0.97 }}\n transition={transition}\n >\n <motion.span\n layout=\"position\"\n className=\"grid size-9 shrink-0 place-items-center\"\n aria-hidden=\"true\"\n transition={transition}\n >\n {icon}\n </motion.span>\n <AnimatePresence mode=\"popLayout\" initial={false}>\n {isExpanded ? (\n <motion.span\n key=\"label\"\n layout\n variants={CONTINUITY_LABEL}\n initial={reduce ? { opacity: 0 } : \"hidden\"}\n animate={reduce ? { opacity: 1 } : \"visible\"}\n exit={reduce ? { opacity: 0 } : \"exit\"}\n transition={transition}\n className=\"relative inline-flex w-max items-center whitespace-nowrap pr-3\"\n aria-hidden=\"true\"\n >\n {label}\n </motion.span>\n ) : null}\n </AnimatePresence>\n </motion.button>\n </motion.span>\n );\n}\n\nexport function ExpandableChip({\n label,\n actionIcon,\n actionLabel,\n onAction,\n collapseOnAction = true,\n expanded,\n defaultExpanded,\n onExpandedChange,\n disabled,\n className,\n labelClassName,\n actionClassName,\n}: ExpandableChipProps) {\n const reduce = useReducedMotion();\n const triggerRef = useRef<HTMLButtonElement>(null);\n const [isExpanded, setExpanded] = useExpandableState({\n expanded,\n defaultExpanded,\n onExpandedChange,\n });\n\n const handleAction = () => {\n onAction?.();\n if (collapseOnAction) {\n setExpanded(false);\n triggerRef.current?.focus();\n }\n };\n\n const transition = reduce ? { duration: 0 } : CONTINUITY_SPRING;\n\n return (\n <motion.span layout transition={transition} className=\"inline-flex\">\n <motion.div\n layout\n className={cn(\n \"inline-flex h-10 items-center overflow-hidden rounded-full border border-border bg-transparent text-foreground text-sm has-focus-visible:ring-2 has-focus-visible:ring-ring has-focus-visible:ring-inset\",\n className,\n )}\n style={{ borderRadius: 9999 }}\n transition={transition}\n >\n <motion.button\n layout=\"position\"\n ref={triggerRef}\n type=\"button\"\n aria-expanded={isExpanded}\n disabled={disabled}\n className={cn(\n \"h-full whitespace-nowrap py-0 pl-3 font-medium outline-none disabled:pointer-events-none disabled:opacity-50\",\n isExpanded ? \"pr-1\" : \"pr-3\",\n labelClassName,\n )}\n onClick={() => setExpanded(!isExpanded)}\n transition={transition}\n >\n {label}\n </motion.button>\n <motion.span\n variants={CONTINUITY_LABEL}\n className={cn(\n \"relative inline-flex h-10 shrink-0 items-center overflow-hidden\",\n isExpanded ? \"w-8\" : \"w-0\",\n )}\n aria-hidden={!isExpanded}\n initial={false}\n animate={reduce ? { opacity: isExpanded ? 1 : 0 } : isExpanded ? \"visible\" : \"hidden\"}\n transition={transition}\n >\n <motion.button\n type=\"button\"\n aria-label={actionLabel}\n disabled={disabled || !isExpanded}\n className={cn(\n \"flex h-10 w-8 shrink-0 items-center justify-center rounded-full text-muted-foreground outline-none transition-colors hover:text-foreground disabled:pointer-events-none\",\n disabled && \"opacity-50\",\n actionClassName,\n )}\n onClick={handleAction}\n whileTap={reduce || disabled ? undefined : { scale: 0.97 }}\n transition={transition}\n >\n <span aria-hidden=\"true\">{actionIcon}</span>\n </motion.button>\n </motion.span>\n </motion.div>\n </motion.span>\n );\n}\n"],"mappings":";;;;;;AAgBA,MAAM,oBAAgC;CACpC,MAAM;CACN,WAAW;CACX,SAAS;CACT,MAAM;AACR;AAEA,MAAM,mBAA6B;CACjC,QAAQ;EAAE,SAAS;EAAG,QAAQ;CAAY;CAC1C,SAAS;EAAE,SAAS;EAAG,QAAQ;CAAY;CAC3C,MAAM;EAAE,SAAS;EAAG,QAAQ;CAAY;AAC1C;AA2B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EZ,UAAA,oBAAC,QAAD;MAAM,eAAY;MAAQ,UAAA;KAAiB,CAAA;IAC9B,CAAA;GACJ,CAAA,CACH;;CACD,CAAA;AAEjB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
import { HTMLMotionProps } from "motion/react";
|
|
3
|
+
//#region src/components/motion/expanding-arrow-button.d.ts
|
|
4
|
+
interface ExpandingArrowButtonProps extends Omit<HTMLMotionProps<"button">, "children"> {
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
accentClassName?: string;
|
|
7
|
+
labelClassName?: string;
|
|
8
|
+
}
|
|
9
|
+
declare const ExpandingArrowButton: import("react").ForwardRefExoticComponent<Omit<ExpandingArrowButtonProps, "ref"> & import("react").RefAttributes<HTMLButtonElement>>;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { ExpandingArrowButton, ExpandingArrowButtonProps };
|
|
12
|
+
//# sourceMappingURL=expanding-arrow-button.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expanding-arrow-button.d.ts","names":[],"sources":["../../../src/components/motion/expanding-arrow-button.tsx"],"mappings":";;;UASiB,kCAAkC,KAAK;EACtD,UAAU;EACV;EACA;;cAiBW,sCAAoB,0BAAA,KAAA,oDAAA,cAAA"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useHoverCapable } from "../../hooks/use-hover-capable.js";
|
|
3
|
+
import { EASE_OUT, SPRING_LAYOUT, SPRING_PRESS } from "../../lib/ease.js";
|
|
4
|
+
import { forwardRef, useState } from "react";
|
|
5
|
+
import { cn } from "@kumix/utils";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { motion, useReducedMotion } from "motion/react";
|
|
8
|
+
//#region src/components/motion/expanding-arrow-button.tsx
|
|
9
|
+
const ARROW_OPACITY = [
|
|
10
|
+
1,
|
|
11
|
+
.78,
|
|
12
|
+
.54,
|
|
13
|
+
.32,
|
|
14
|
+
.16
|
|
15
|
+
];
|
|
16
|
+
function DottedChevron({ className }) {
|
|
17
|
+
return /* @__PURE__ */ jsxs("svg", {
|
|
18
|
+
viewBox: "0 0 20 28",
|
|
19
|
+
fill: "none",
|
|
20
|
+
"aria-hidden": "true",
|
|
21
|
+
className,
|
|
22
|
+
children: [
|
|
23
|
+
/* @__PURE__ */ jsx("circle", {
|
|
24
|
+
cx: "4",
|
|
25
|
+
cy: "4",
|
|
26
|
+
r: "2",
|
|
27
|
+
fill: "currentColor"
|
|
28
|
+
}),
|
|
29
|
+
/* @__PURE__ */ jsx("circle", {
|
|
30
|
+
cx: "10",
|
|
31
|
+
cy: "9",
|
|
32
|
+
r: "2",
|
|
33
|
+
fill: "currentColor"
|
|
34
|
+
}),
|
|
35
|
+
/* @__PURE__ */ jsx("circle", {
|
|
36
|
+
cx: "16",
|
|
37
|
+
cy: "14",
|
|
38
|
+
r: "2",
|
|
39
|
+
fill: "currentColor"
|
|
40
|
+
}),
|
|
41
|
+
/* @__PURE__ */ jsx("circle", {
|
|
42
|
+
cx: "10",
|
|
43
|
+
cy: "19",
|
|
44
|
+
r: "2",
|
|
45
|
+
fill: "currentColor"
|
|
46
|
+
}),
|
|
47
|
+
/* @__PURE__ */ jsx("circle", {
|
|
48
|
+
cx: "4",
|
|
49
|
+
cy: "24",
|
|
50
|
+
r: "2",
|
|
51
|
+
fill: "currentColor"
|
|
52
|
+
})
|
|
53
|
+
]
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
const ExpandingArrowButton = forwardRef(function ExpandingArrowButton({ children, className, accentClassName, labelClassName, disabled, onMouseEnter, onMouseLeave, onFocus, onBlur, ...rest }, ref) {
|
|
57
|
+
const reduce = useReducedMotion();
|
|
58
|
+
const canHover = useHoverCapable();
|
|
59
|
+
const [hovered, setHovered] = useState(false);
|
|
60
|
+
const [focused, setFocused] = useState(false);
|
|
61
|
+
const active = !disabled && (canHover && hovered || focused);
|
|
62
|
+
const layoutTransition = reduce ? { duration: 0 } : SPRING_LAYOUT;
|
|
63
|
+
const handleMouseEnter = (event) => {
|
|
64
|
+
setHovered(true);
|
|
65
|
+
onMouseEnter?.(event);
|
|
66
|
+
};
|
|
67
|
+
const handleMouseLeave = (event) => {
|
|
68
|
+
setHovered(false);
|
|
69
|
+
onMouseLeave?.(event);
|
|
70
|
+
};
|
|
71
|
+
const handleFocus = (event) => {
|
|
72
|
+
setFocused(true);
|
|
73
|
+
onFocus?.(event);
|
|
74
|
+
};
|
|
75
|
+
const handleBlur = (event) => {
|
|
76
|
+
setFocused(false);
|
|
77
|
+
onBlur?.(event);
|
|
78
|
+
};
|
|
79
|
+
return /* @__PURE__ */ jsxs(motion.button, {
|
|
80
|
+
ref,
|
|
81
|
+
type: "button",
|
|
82
|
+
disabled,
|
|
83
|
+
onMouseEnter: handleMouseEnter,
|
|
84
|
+
onMouseLeave: handleMouseLeave,
|
|
85
|
+
onFocus: handleFocus,
|
|
86
|
+
onBlur: handleBlur,
|
|
87
|
+
whileTap: reduce || disabled ? void 0 : { scale: .97 },
|
|
88
|
+
transition: SPRING_PRESS,
|
|
89
|
+
className: cn("relative inline-flex h-16 min-w-72 select-none items-center overflow-hidden rounded-[22px] bg-neutral-950 p-1.5 text-white", "outline-none focus-visible:ring-2 focus-visible:ring-lime-300 focus-visible:ring-offset-2 focus-visible:ring-offset-background", "disabled:pointer-events-none disabled:opacity-50", className),
|
|
90
|
+
...rest,
|
|
91
|
+
children: [/* @__PURE__ */ jsxs(motion.span, {
|
|
92
|
+
layout: "size",
|
|
93
|
+
"aria-hidden": "true",
|
|
94
|
+
transition: layoutTransition,
|
|
95
|
+
style: {
|
|
96
|
+
width: active ? "calc(100% - 12px)" : 52,
|
|
97
|
+
borderRadius: 16
|
|
98
|
+
},
|
|
99
|
+
className: cn("absolute inset-y-1.5 left-1.5 z-10 overflow-hidden bg-lime-300 text-neutral-950", accentClassName),
|
|
100
|
+
children: [/* @__PURE__ */ jsx(motion.span, {
|
|
101
|
+
animate: { opacity: active ? 0 : 1 },
|
|
102
|
+
transition: {
|
|
103
|
+
duration: reduce ? 0 : .1,
|
|
104
|
+
ease: EASE_OUT
|
|
105
|
+
},
|
|
106
|
+
className: "absolute inset-0 grid place-items-center",
|
|
107
|
+
children: /* @__PURE__ */ jsx(DottedChevron, { className: "h-7 w-5" })
|
|
108
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
109
|
+
className: "absolute inset-0 flex items-center justify-around px-3",
|
|
110
|
+
children: ARROW_OPACITY.map((opacity, index) => /* @__PURE__ */ jsx(motion.span, {
|
|
111
|
+
animate: {
|
|
112
|
+
opacity: active ? 1 : 0,
|
|
113
|
+
transform: active && !reduce ? "translateX(0px)" : "translateX(-6px)"
|
|
114
|
+
},
|
|
115
|
+
transition: {
|
|
116
|
+
duration: reduce ? 0 : .18,
|
|
117
|
+
delay: active && !reduce ? .04 + index * .025 : 0,
|
|
118
|
+
ease: EASE_OUT
|
|
119
|
+
},
|
|
120
|
+
style: { color: `rgb(10 10 10 / ${opacity})` },
|
|
121
|
+
className: "inline-grid place-items-center",
|
|
122
|
+
children: /* @__PURE__ */ jsx(DottedChevron, { className: "h-7 w-5" })
|
|
123
|
+
}, opacity))
|
|
124
|
+
})]
|
|
125
|
+
}), /* @__PURE__ */ jsx(motion.span, {
|
|
126
|
+
animate: {
|
|
127
|
+
opacity: active ? 0 : 1,
|
|
128
|
+
transform: active && !reduce ? "translateX(6px)" : "translateX(0px)"
|
|
129
|
+
},
|
|
130
|
+
transition: {
|
|
131
|
+
duration: reduce ? 0 : .12,
|
|
132
|
+
ease: EASE_OUT
|
|
133
|
+
},
|
|
134
|
+
className: cn("relative z-0 mr-5 ml-[76px] whitespace-nowrap font-medium text-lg tracking-[-0.02em]", labelClassName),
|
|
135
|
+
children
|
|
136
|
+
})]
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
//#endregion
|
|
140
|
+
export { ExpandingArrowButton };
|
|
141
|
+
|
|
142
|
+
//# sourceMappingURL=expanding-arrow-button.js.map
|