@kumix/ui 0.3.8 → 0.3.10
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 +16 -15
- package/dist/components/agents/ai-sidebar.js +3 -5
- package/dist/components/agents/ai-sidebar.js.map +1 -1
- 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.d.ts +6 -0
- package/dist/components/motion/combobox/context.d.ts.map +1 -1
- package/dist/components/motion/combobox/context.js +1 -233
- package/dist/components/motion/combobox/list.js +1 -1
- package/dist/components/motion/combobox/trigger.js +7 -8
- package/dist/components/motion/combobox/trigger.js.map +1 -1
- package/dist/components/motion/combobox.js +1 -1
- package/dist/components/motion/command-palette.d.ts.map +1 -1
- package/dist/components/motion/command-palette.js +21 -26
- package/dist/components/motion/command-palette.js.map +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/morphing-search.d.ts.map +1 -1
- package/dist/components/motion/morphing-search.js +27 -23
- package/dist/components/motion/morphing-search.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/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/filters/filters-builder.js +1 -1
- package/dist/components/reui/filters/filters-chip.js.map +1 -1
- package/dist/components/reui/filters/filters-editors.js +2 -2
- package/dist/components/reui/filters/filters-editors.js.map +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/ui/badge.d.ts +1 -1
- package/dist/components/ui/bubble.d.ts +1 -1
- package/dist/components/ui/button.d.ts +1 -1
- package/dist/components/ui/item.d.ts +1 -1
- package/dist/components/ui/marker.d.ts +1 -1
- package/dist/components/ui/tabs.d.ts +1 -1
- package/dist/context-BizvUNZv.js +298 -0
- package/dist/context-BizvUNZv.js.map +1 -0
- package/dist/{copy-menu-1FKoMc9o.js → copy-menu-C5GaT4Z-.js} +67 -2
- package/dist/copy-menu-C5GaT4Z-.js.map +1 -0
- package/dist/hooks/use-on-open.d.ts +18 -0
- package/dist/hooks/use-on-open.d.ts.map +1 -0
- package/dist/hooks/use-on-open.js +27 -0
- package/dist/hooks/use-on-open.js.map +1 -0
- package/dist/hooks/use-row-cursor.d.ts +39 -0
- package/dist/hooks/use-row-cursor.d.ts.map +1 -0
- package/dist/hooks/use-row-cursor.js +77 -0
- package/dist/hooks/use-row-cursor.js.map +1 -0
- package/dist/types-smkWN_7x.d.ts.map +1 -1
- package/package.json +7 -13
- package/dist/components/motion/combobox/context.js.map +0 -1
- package/dist/copy-menu-1FKoMc9o.js.map +0 -1
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { useOnOpen } from "../../hooks/use-on-open.js";
|
|
3
|
+
import { useRowCursor } from "../../hooks/use-row-cursor.js";
|
|
2
4
|
import { useTouchCapable } from "../../hooks/use-touch-capable.js";
|
|
3
5
|
import { EASE_OUT } from "../../lib/ease.js";
|
|
4
6
|
import { t as PresenceGate } from "../../presence-gate-BekdC4Bo.js";
|
|
@@ -35,16 +37,11 @@ function CommandPalette({ items, shortcut = "k", placeholder = "Type a command o
|
|
|
35
37
|
onOpenChange?.(v);
|
|
36
38
|
}, [controlled, onOpenChange]);
|
|
37
39
|
const [query, setQuery] = useState("");
|
|
38
|
-
const [active, setActive] = useState(0);
|
|
39
40
|
const [mounted, setMounted] = useState(false);
|
|
40
41
|
useEffect(() => setMounted(true), []);
|
|
41
42
|
const uid = useId();
|
|
42
43
|
const reduce = useReducedMotion();
|
|
43
44
|
const canTouch = useTouchCapable();
|
|
44
|
-
const updateQuery = useCallback((value) => {
|
|
45
|
-
setQuery(value);
|
|
46
|
-
setActive(0);
|
|
47
|
-
}, []);
|
|
48
45
|
const inputRef = useRef(null);
|
|
49
46
|
const listRef = useRef(null);
|
|
50
47
|
useEffect(() => {
|
|
@@ -66,13 +63,6 @@ function CommandPalette({ items, shortcut = "k", placeholder = "Type a command o
|
|
|
66
63
|
shortcut,
|
|
67
64
|
setOpen
|
|
68
65
|
]);
|
|
69
|
-
useEffect(() => {
|
|
70
|
-
if (open) {
|
|
71
|
-
updateQuery("");
|
|
72
|
-
setActive(0);
|
|
73
|
-
requestAnimationFrame(() => inputRef.current?.focus());
|
|
74
|
-
}
|
|
75
|
-
}, [open, updateQuery]);
|
|
76
66
|
useEffect(() => {
|
|
77
67
|
if (!open) return;
|
|
78
68
|
const root = document.documentElement;
|
|
@@ -106,16 +96,27 @@ function CommandPalette({ items, shortcut = "k", placeholder = "Type a command o
|
|
|
106
96
|
});
|
|
107
97
|
return Array.from(map.entries());
|
|
108
98
|
}, [filtered]);
|
|
99
|
+
const rows = useMemo(() => grouped.flatMap(([, list]) => list), [grouped]);
|
|
100
|
+
const { activeIndex: active, moveTo, moveActive } = useRowCursor(rows, query);
|
|
101
|
+
useOnOpen(open, () => {
|
|
102
|
+
setQuery("");
|
|
103
|
+
moveTo(null);
|
|
104
|
+
});
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
if (!open) return;
|
|
107
|
+
const frame = requestAnimationFrame(() => inputRef.current?.focus());
|
|
108
|
+
return () => cancelAnimationFrame(frame);
|
|
109
|
+
}, [open]);
|
|
109
110
|
const onKeyDown = (e) => {
|
|
110
111
|
if (e.key === "ArrowDown") {
|
|
111
112
|
e.preventDefault();
|
|
112
|
-
|
|
113
|
+
moveActive(1);
|
|
113
114
|
} else if (e.key === "ArrowUp") {
|
|
114
115
|
e.preventDefault();
|
|
115
|
-
|
|
116
|
+
moveActive(-1);
|
|
116
117
|
} else if (e.key === "Enter") {
|
|
117
118
|
e.preventDefault();
|
|
118
|
-
const it =
|
|
119
|
+
const it = rows[active];
|
|
119
120
|
if (it) {
|
|
120
121
|
it.onSelect();
|
|
121
122
|
setOpen(false);
|
|
@@ -126,12 +127,6 @@ function CommandPalette({ items, shortcut = "k", placeholder = "Type a command o
|
|
|
126
127
|
if (!open) return;
|
|
127
128
|
(listRef.current?.querySelector(`[data-index="${active}"]`))?.scrollIntoView({ block: "nearest" });
|
|
128
129
|
}, [active, open]);
|
|
129
|
-
const indexOfItem = useMemo(() => {
|
|
130
|
-
const indices = /* @__PURE__ */ new Map();
|
|
131
|
-
let next = 0;
|
|
132
|
-
for (const [, list] of grouped) for (const it of list) indices.set(it.id, next++);
|
|
133
|
-
return indices;
|
|
134
|
-
}, [grouped]);
|
|
135
130
|
if (!mounted) return null;
|
|
136
131
|
return createPortal(/* @__PURE__ */ jsxs(AnimatePresence, {
|
|
137
132
|
initial: false,
|
|
@@ -191,12 +186,12 @@ function CommandPalette({ items, shortcut = "k", placeholder = "Type a command o
|
|
|
191
186
|
/* @__PURE__ */ jsx("input", {
|
|
192
187
|
ref: inputRef,
|
|
193
188
|
value: query,
|
|
194
|
-
onChange: (e) =>
|
|
189
|
+
onChange: (e) => setQuery(e.target.value),
|
|
195
190
|
placeholder,
|
|
196
191
|
role: "combobox",
|
|
197
192
|
"aria-expanded": "true",
|
|
198
193
|
"aria-controls": `${uid}-list`,
|
|
199
|
-
"aria-activedescendant":
|
|
194
|
+
"aria-activedescendant": rows.length > 0 ? `${uid}-opt-${active}` : void 0,
|
|
200
195
|
"aria-autocomplete": "list",
|
|
201
196
|
className: cn("h-12 flex-1 bg-transparent text-foreground text-sm outline-none placeholder:text-muted-foreground", canTouch && "text-base")
|
|
202
197
|
}),
|
|
@@ -211,7 +206,7 @@ function CommandPalette({ items, shortcut = "k", placeholder = "Type a command o
|
|
|
211
206
|
role: "listbox",
|
|
212
207
|
"aria-label": "Commands",
|
|
213
208
|
className: "max-h-[60vh] overflow-y-auto overscroll-contain p-2 [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",
|
|
214
|
-
children:
|
|
209
|
+
children: rows.length === 0 ? /* @__PURE__ */ jsx("div", {
|
|
215
210
|
className: "p-8 text-center text-muted-foreground text-sm",
|
|
216
211
|
children: emptyMessage
|
|
217
212
|
}) : grouped.map(([group, list]) => /* @__PURE__ */ jsxs("div", {
|
|
@@ -221,7 +216,7 @@ function CommandPalette({ items, shortcut = "k", placeholder = "Type a command o
|
|
|
221
216
|
className: "px-2 py-1.5 font-semibold text-[10px] text-muted-foreground uppercase tracking-wider",
|
|
222
217
|
children: group
|
|
223
218
|
}), list.map((it) => {
|
|
224
|
-
const idx =
|
|
219
|
+
const idx = rows.indexOf(it);
|
|
225
220
|
const isActive = idx === active;
|
|
226
221
|
const Icon = it.icon;
|
|
227
222
|
return /* @__PURE__ */ jsxs("button", {
|
|
@@ -230,7 +225,7 @@ function CommandPalette({ items, shortcut = "k", placeholder = "Type a command o
|
|
|
230
225
|
role: "option",
|
|
231
226
|
"aria-selected": isActive,
|
|
232
227
|
"data-index": idx,
|
|
233
|
-
onMouseEnter: () =>
|
|
228
|
+
onMouseEnter: () => moveTo(it.id),
|
|
234
229
|
onClick: () => {
|
|
235
230
|
it.onSelect();
|
|
236
231
|
setOpen(false);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-palette.js","names":[],"sources":["../../../src/components/motion/command-palette.tsx"],"sourcesContent":["\"use client\";\n\nimport { type ReactNode, useCallback, useEffect, useId, useMemo, useRef, useState } from \"react\";\nimport { type LucideIcon, Search } from \"lucide-react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { createPortal } from \"react-dom\";\n\nimport { cn } from \"@kumix/utils\";\nimport { useTouchCapable } from \"../../hooks/use-touch-capable\";\nimport { EASE_OUT } from \"../../lib/ease\";\nimport { PresenceGate } from \"../../lib/presence-gate\";\n\nexport type CommandItem = {\n id: string;\n label: string;\n group?: string;\n hint?: string;\n keywords?: string[];\n icon?: LucideIcon;\n badge?: ReactNode;\n onSelect: () => void;\n};\n\nexport interface CommandPaletteProps {\n items: CommandItem[];\n /** Opens with Cmd/Ctrl + this key. Default: \"k\" */\n shortcut?: string;\n placeholder?: string;\n emptyMessage?: string;\n open?: boolean;\n onOpenChange?: (open: boolean) => void;\n}\n\nfunction fuzzyMatch(needle: string, hay: string) {\n if (!needle) return true;\n needle = needle.toLowerCase();\n hay = hay.toLowerCase();\n let i = 0;\n for (const ch of hay) {\n if (ch === needle[i]) i++;\n if (i === needle.length) return true;\n }\n return false;\n}\n\n// Opened via a keyboard shortcut many times a day — entrance must read as\n// instant. Tight spring, even faster exit.\nconst PANEL_SPRING = {\n type: \"spring\",\n stiffness: 560,\n damping: 40,\n mass: 0.5,\n} as const;\n\nexport function CommandPalette({\n items,\n shortcut = \"k\",\n placeholder = \"Type a command or search…\",\n emptyMessage = \"No results found.\",\n open: controlledOpen,\n onOpenChange,\n}: CommandPaletteProps) {\n const [internalOpen, setInternalOpen] = useState(false);\n const controlled = controlledOpen !== undefined;\n const open = controlled ? controlledOpen : internalOpen;\n const setOpen = useCallback(\n (v: boolean) => {\n if (!controlled) setInternalOpen(v);\n onOpenChange?.(v);\n },\n [controlled, onOpenChange],\n );\n\n const [query, setQuery] = useState(\"\");\n const [active, setActive] = useState(0);\n // Portal target only exists client-side; render nothing during SSR/hydration.\n const [mounted, setMounted] = useState(false);\n useEffect(() => setMounted(true), []);\n const uid = useId();\n const reduce = useReducedMotion();\n const canTouch = useTouchCapable();\n const updateQuery = useCallback((value: string) => {\n setQuery(value);\n setActive(0);\n }, []);\n const inputRef = useRef<HTMLInputElement>(null);\n const listRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n const onKey = (e: KeyboardEvent) => {\n if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === shortcut.toLowerCase()) {\n e.preventDefault();\n setOpen(!open);\n return;\n }\n if (e.key === \"Escape\" && open) {\n e.preventDefault();\n setOpen(false);\n }\n };\n window.addEventListener(\"keydown\", onKey);\n return () => window.removeEventListener(\"keydown\", onKey);\n }, [open, shortcut, setOpen]);\n\n useEffect(() => {\n if (open) {\n updateQuery(\"\");\n setActive(0);\n requestAnimationFrame(() => inputRef.current?.focus());\n }\n }, [open, updateQuery]);\n\n useEffect(() => {\n if (!open) return;\n const root = document.documentElement;\n const previousRootOverflow = root.style.overflow;\n const previousBodyOverflow = document.body.style.overflow;\n root.style.overflow = \"hidden\";\n document.body.style.overflow = \"hidden\";\n return () => {\n root.style.overflow = previousRootOverflow;\n document.body.style.overflow = previousBodyOverflow;\n };\n }, [open]);\n\n const filtered = useMemo(() => {\n if (!query) return items;\n return items.filter((it) => {\n const haystacks = [it.label, it.group ?? \"\", ...(it.keywords ?? [])];\n return haystacks.some((h) => fuzzyMatch(query, h));\n });\n }, [items, query]);\n\n // Reserve the icon column only when at least one item brings an icon, so\n // icon-less lists don't render a dead gap before every label.\n const hasIcons = useMemo(() => items.some((it) => it.icon), [items]);\n\n const grouped = useMemo(() => {\n const map = new Map<string, CommandItem[]>();\n filtered.forEach((it) => {\n const g = it.group ?? \"Results\";\n const groupItems = map.get(g) ?? [];\n groupItems.push(it);\n map.set(g, groupItems);\n });\n return Array.from(map.entries());\n }, [filtered]);\n\n const onKeyDown = (e: React.KeyboardEvent) => {\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n setActive((a) => Math.min(filtered.length - 1, a + 1));\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n setActive((a) => Math.max(0, a - 1));\n } else if (e.key === \"Enter\") {\n e.preventDefault();\n const it = filtered[active];\n if (it) {\n it.onSelect();\n setOpen(false);\n }\n }\n };\n\n useEffect(() => {\n if (!open) return;\n const el = listRef.current?.querySelector<HTMLButtonElement>(`[data-index=\"${active}\"]`);\n el?.scrollIntoView({ block: \"nearest\" });\n }, [active, open]);\n\n // A row's index is its position in the flattened group order, derived once\n // per change of `grouped` rather than counted while the rows render. The rows\n // hang off `PresenceGate`'s render prop, which is its own component: a\n // counter declared in this body would be incremented on the gate's render\n // passes, after this body had already run, and would never be reset again —\n // the ids, `aria-selected` and the highlight all drift with it.\n const indexOfItem = useMemo(() => {\n const indices = new Map<string, number>();\n let next = 0;\n for (const [, list] of grouped) {\n for (const it of list) indices.set(it.id, next++);\n }\n return indices;\n }, [grouped]);\n\n if (!mounted) return null;\n\n // Portaled to <body> so ancestors with transforms, filters, or fixed\n // positioning can't trap the overlay in their stacking context, and mounted\n // only while open. The chrome is two fixed siblings rather than one wrapper:\n // the backdrop spans the viewport edges but carries the scrim colour, and the\n // layer positioning the panel is inset off every edge. Both hang off\n // `PresenceGate`, so interaction releases in the same commit that starts the\n // exit rather than when it ends — `open` is already false for those frames.\n return createPortal(\n <AnimatePresence initial={false}>\n {open ? (\n <PresenceGate key=\"backdrop\">\n {({ gate }) => (\n <motion.button\n type=\"button\"\n aria-label=\"Close command palette\"\n initial={{ opacity: 0 }}\n animate={{ opacity: 1 }}\n exit={{\n opacity: 0,\n transition: { duration: 0.12, ease: EASE_OUT },\n }}\n transition={{ duration: 0.18, ease: EASE_OUT }}\n {...gate}\n onClick={() => setOpen(false)}\n className=\"pointer-events-auto fixed inset-0 z-100 bg-background/5 [-webkit-backdrop-filter:blur(12px)_saturate(140%)] [backdrop-filter:blur(12px)_saturate(140%)]\"\n />\n )}\n </PresenceGate>\n ) : null}\n\n {open ? (\n <PresenceGate key=\"panel-layer\">\n {({ isPresent, gate }) => (\n // The layer itself never takes pointer events, so it carries\n // `inert` alone rather than the gate's pointer-events value.\n <div\n inert={!isPresent}\n className=\"pointer-events-none fixed inset-x-4 top-[18vh] bottom-4 z-100 flex items-start justify-center\"\n >\n <motion.div\n role=\"dialog\"\n aria-modal=\"true\"\n aria-label=\"Command palette\"\n initial={{\n opacity: 0,\n y: reduce ? 0 : -8,\n scale: reduce ? 1 : 0.97,\n }}\n animate={{ opacity: 1, y: 0, scale: 1 }}\n exit={{\n opacity: 0,\n y: reduce ? 0 : -8,\n scale: reduce ? 1 : 0.97,\n transition: { duration: 0.12, ease: EASE_OUT },\n }}\n transition={reduce ? { duration: 0.1 } : PANEL_SPRING}\n {...gate}\n onKeyDown={onKeyDown}\n className=\"pointer-events-auto w-full max-w-xl overflow-hidden rounded-2xl border border-border bg-card shadow-2xl will-change-transform\"\n >\n <div className=\"flex items-center gap-3 border-border border-b px-4\">\n <Search className=\"h-4 w-4 text-muted-foreground\" />\n <input\n ref={inputRef}\n value={query}\n onChange={(e) => updateQuery(e.target.value)}\n placeholder={placeholder}\n role=\"combobox\"\n // The field only exists while the palette is open.\n aria-expanded=\"true\"\n aria-controls={`${uid}-list`}\n aria-activedescendant={filtered.length > 0 ? `${uid}-opt-${active}` : undefined}\n aria-autocomplete=\"list\"\n className={cn(\n \"h-12 flex-1 bg-transparent text-foreground text-sm outline-none placeholder:text-muted-foreground\",\n // The palette focuses this field the moment it opens, and iOS\n // zooms the page in on a focused field under 16px: the fixed\n // overlay is magnified off-center — clipped leading edge, half\n // an icon column — and the zoom outlives the palette. 16px on\n // touch keeps the page at scale 1; pointer devices keep 14px.\n canTouch && \"text-base\",\n )}\n />\n <kbd className=\"hidden rounded border border-border bg-background px-1.5 py-0.5 text-[10px] text-muted-foreground sm:inline-block\">\n ESC\n </kbd>\n </div>\n <div\n ref={listRef}\n id={`${uid}-list`}\n role=\"listbox\"\n aria-label=\"Commands\"\n className=\"max-h-[60vh] overflow-y-auto overscroll-contain p-2 [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden\"\n >\n {filtered.length === 0 ? (\n <div className=\"p-8 text-center text-muted-foreground text-sm\">\n {emptyMessage}\n </div>\n ) : (\n grouped.map(([group, list]) => (\n <div key={group} className=\"mb-1 last:mb-0\">\n <div\n aria-hidden\n className=\"px-2 py-1.5 font-semibold text-[10px] text-muted-foreground uppercase tracking-wider\"\n >\n {group}\n </div>\n {list.map((it) => {\n const idx = indexOfItem.get(it.id) ?? 0;\n const isActive = idx === active;\n const Icon = it.icon;\n return (\n <button\n key={it.id}\n type=\"button\"\n id={`${uid}-opt-${idx}`}\n role=\"option\"\n aria-selected={isActive}\n data-index={idx}\n onMouseEnter={() => setActive(idx)}\n onClick={() => {\n it.onSelect();\n setOpen(false);\n }}\n className={cn(\n \"relative isolate flex w-full items-center gap-3 rounded-md px-2 py-2 text-left text-sm transition-colors\",\n isActive ? \"text-foreground\" : \"text-muted-foreground\",\n )}\n >\n {isActive ? (\n <motion.span\n layoutId={`${uid}-active`}\n className=\"absolute inset-0 z-0 rounded-md bg-primary/5\"\n transition={\n reduce\n ? { duration: 0 }\n : // Tracks rapid arrow-key navigation — keep it tighter\n // than SPRING_LAYOUT so it never lags the active row.\n {\n type: \"spring\",\n stiffness: 480,\n damping: 38,\n }\n }\n />\n ) : null}\n {Icon ? (\n <Icon className=\"relative z-10 h-4 w-4\" />\n ) : hasIcons ? (\n <span className=\"relative z-10 h-4 w-4\" />\n ) : null}\n <span className=\"relative z-10 flex-1 truncate\">{it.label}</span>\n {it.badge ? (\n <span className=\"relative z-10 shrink-0\">{it.badge}</span>\n ) : null}\n {it.hint ? (\n <kbd className=\"relative z-10 rounded border border-border bg-background px-1.5 py-0.5 text-[10px] text-muted-foreground\">\n {it.hint}\n </kbd>\n ) : null}\n </button>\n );\n })}\n </div>\n ))\n )}\n </div>\n </motion.div>\n </div>\n )}\n </PresenceGate>\n ) : null}\n </AnimatePresence>,\n document.body,\n );\n}\n"],"mappings":";;;;;;;;;;;AAiCA,SAAS,WAAW,QAAgB,KAAa;CAC/C,IAAI,CAAC,QAAQ,OAAO;CACpB,SAAS,OAAO,YAAY;CAC5B,MAAM,IAAI,YAAY;CACtB,IAAI,IAAI;CACR,KAAK,MAAM,MAAM,KAAK;EACpB,IAAI,OAAO,OAAO,IAAI;EACtB,IAAI,MAAM,OAAO,QAAQ,OAAO;CAClC;CACA,OAAO;AACT;AAIA,MAAM,eAAe;CACnB,MAAM;CACN,WAAW;CACX,SAAS;CACT,MAAM;AACR;AAEA,SAAgB,eAAe,EAC7B,OACA,WAAW,KACX,cAAc,6BACd,eAAe,qBACf,MAAM,gBACN,gBACsB;CACtB,MAAM,CAAC,cAAc,mBAAmB,SAAS,KAAK;CACtD,MAAM,aAAa,mBAAmB,KAAA;CACtC,MAAM,OAAO,aAAa,iBAAiB;CAC3C,MAAM,UAAU,aACb,MAAe;EACd,IAAI,CAAC,YAAY,gBAAgB,CAAC;EAClC,eAAe,CAAC;CAClB,GACA,CAAC,YAAY,YAAY,CAC3B;CAEA,MAAM,CAAC,OAAO,YAAY,SAAS,EAAE;CACrC,MAAM,CAAC,QAAQ,aAAa,SAAS,CAAC;CAEtC,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAC5C,gBAAgB,WAAW,IAAI,GAAG,CAAC,CAAC;CACpC,MAAM,MAAM,MAAM;CAClB,MAAM,SAAS,iBAAiB;CAChC,MAAM,WAAW,gBAAgB;CACjC,MAAM,cAAc,aAAa,UAAkB;EACjD,SAAS,KAAK;EACd,UAAU,CAAC;CACb,GAAG,CAAC,CAAC;CACL,MAAM,WAAW,OAAyB,IAAI;CAC9C,MAAM,UAAU,OAAuB,IAAI;CAE3C,gBAAgB;EACd,MAAM,SAAS,MAAqB;GAClC,KAAK,EAAE,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AAO,UACnB,qBAAC,OAAD;MAAiB,WAAU;MAA3B,UAAA,CACE,oBAAC,OAAD;OACE,eAAA;OACA,WAAU;OAET,UAAA;MACE,CAAA,GACJ,KAAK,KAAK,OAAO;OAChB,MAAM,MAAM,YAAY,IAAI,GAAG,EAAE,KAAK;OACtC,MAAM,WAAW,QAAQ;OACzB,MAAM,OAAO,GAAG;OAChB,OACE,qBAAC,UAAD;QAEE,MAAK;QACL,IAAI,GAAG,IAAI,OAAO;QAClB,MAAK;QACL,iBAAe;QACf,cAAY;QACZ,oBAAoB,UAAU,GAAG;QACjC,eAAe;SACb,GAAG,SAAS;SACZ,QAAQ,KAAK;QACf;QACA,WAAW,GACT,4GACA,WAAW,oBAAoB,uBACjC;QAfF,UAAA;SAiBG,WACC,oBAAC,OAAO,MAAR;UACE,UAAU,GAAG,IAAI;UACjB,WAAU;UACV,YACE,SACI,EAAE,UAAU,EAAE,IAGd;WACE,MAAM;WACN,WAAW;WACX,SAAS;UACX;SAEP,CAAA,IACC;SACH,OACC,oBAAC,MAAD,EAAM,WAAU,wBAAyB,CAAA,IACvC,WACF,oBAAC,QAAD,EAAM,WAAU,wBAAyB,CAAA,IACvC;SACJ,oBAAC,QAAD;UAAM,WAAU;UAAiC,UAAA,GAAG;SAAY,CAAA;SAC/D,GAAG,QACF,oBAAC,QAAD;UAAM,WAAU;UAA0B,UAAA,GAAG;SAAY,CAAA,IACvD;SACH,GAAG,OACF,oBAAC,OAAD;UAAK,WAAU;UACZ,UAAA,GAAG;SACD,CAAA,IACH;QACE;OA/CD,GAAA,GAAG,EA+CF;MAEZ,CAAC,CACE;KA/DK,GAAA,KA+DL,CACN;IAEA,CAAA,CACK;;EACT,CAAA,EAEK,GA3II,aA2IJ,IACZ,IACW;CACjB,CAAA,GAAA,SAAS,IACX;AACF"}
|
|
1
|
+
{"version":3,"file":"command-palette.js","names":[],"sources":["../../../src/components/motion/command-palette.tsx"],"sourcesContent":["\"use client\";\n\nimport { type ReactNode, useCallback, useEffect, useId, useMemo, useRef, useState } from \"react\";\nimport { type LucideIcon, Search } from \"lucide-react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { createPortal } from \"react-dom\";\n\nimport { cn } from \"@kumix/utils\";\nimport { useOnOpen } from \"../../hooks/use-on-open\";\nimport { useRowCursor } from \"../../hooks/use-row-cursor\";\nimport { useTouchCapable } from \"../../hooks/use-touch-capable\";\nimport { EASE_OUT } from \"../../lib/ease\";\nimport { PresenceGate } from \"../../lib/presence-gate\";\n\nexport type CommandItem = {\n id: string;\n label: string;\n group?: string;\n hint?: string;\n keywords?: string[];\n icon?: LucideIcon;\n badge?: ReactNode;\n onSelect: () => void;\n};\n\nexport interface CommandPaletteProps {\n items: CommandItem[];\n /** Opens with Cmd/Ctrl + this key. Default: \"k\" */\n shortcut?: string;\n placeholder?: string;\n emptyMessage?: string;\n open?: boolean;\n onOpenChange?: (open: boolean) => void;\n}\n\nfunction fuzzyMatch(needle: string, hay: string) {\n if (!needle) return true;\n needle = needle.toLowerCase();\n hay = hay.toLowerCase();\n let i = 0;\n for (const ch of hay) {\n if (ch === needle[i]) i++;\n if (i === needle.length) return true;\n }\n return false;\n}\n\n// Opened via a keyboard shortcut many times a day — entrance must read as\n// instant. Tight spring, even faster exit.\nconst PANEL_SPRING = {\n type: \"spring\",\n stiffness: 560,\n damping: 40,\n mass: 0.5,\n} as const;\n\nexport function CommandPalette({\n items,\n shortcut = \"k\",\n placeholder = \"Type a command or search…\",\n emptyMessage = \"No results found.\",\n open: controlledOpen,\n onOpenChange,\n}: CommandPaletteProps) {\n const [internalOpen, setInternalOpen] = useState(false);\n const controlled = controlledOpen !== undefined;\n const open = controlled ? controlledOpen : internalOpen;\n const setOpen = useCallback(\n (v: boolean) => {\n if (!controlled) setInternalOpen(v);\n onOpenChange?.(v);\n },\n [controlled, onOpenChange],\n );\n\n const [query, setQuery] = useState(\"\");\n // Portal target only exists client-side; render nothing during SSR/hydration.\n const [mounted, setMounted] = useState(false);\n useEffect(() => setMounted(true), []);\n const uid = useId();\n const reduce = useReducedMotion();\n const canTouch = useTouchCapable();\n const inputRef = useRef<HTMLInputElement>(null);\n const listRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n const onKey = (e: KeyboardEvent) => {\n if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === shortcut.toLowerCase()) {\n e.preventDefault();\n setOpen(!open);\n return;\n }\n if (e.key === \"Escape\" && open) {\n e.preventDefault();\n setOpen(false);\n }\n };\n window.addEventListener(\"keydown\", onKey);\n return () => window.removeEventListener(\"keydown\", onKey);\n }, [open, shortcut, setOpen]);\n\n useEffect(() => {\n if (!open) return;\n const root = document.documentElement;\n const previousRootOverflow = root.style.overflow;\n const previousBodyOverflow = document.body.style.overflow;\n root.style.overflow = \"hidden\";\n document.body.style.overflow = \"hidden\";\n return () => {\n root.style.overflow = previousRootOverflow;\n document.body.style.overflow = previousBodyOverflow;\n };\n }, [open]);\n\n const filtered = useMemo(() => {\n if (!query) return items;\n return items.filter((it) => {\n const haystacks = [it.label, it.group ?? \"\", ...(it.keywords ?? [])];\n return haystacks.some((h) => fuzzyMatch(query, h));\n });\n }, [items, query]);\n\n // Reserve the icon column only when at least one item brings an icon, so\n // icon-less lists don't render a dead gap before every label.\n const hasIcons = useMemo(() => items.some((it) => it.icon), [items]);\n\n const grouped = useMemo(() => {\n const map = new Map<string, CommandItem[]>();\n filtered.forEach((it) => {\n const g = it.group ?? \"Results\";\n const groupItems = map.get(g) ?? [];\n groupItems.push(it);\n map.set(g, groupItems);\n });\n return Array.from(map.entries());\n }, [filtered]);\n\n // Grouping reorders the list, so the rendered order is not the filtered\n // order whenever two groups interleave. Everything that has to agree on\n // \"which row\" — the highlight, the ids, Enter, the scroll — reads this one\n // array, so they cannot drift apart.\n const rows = useMemo(() => grouped.flatMap(([, list]) => list), [grouped]);\n\n const { activeIndex: active, moveTo, moveActive } = useRowCursor(rows, query);\n\n // Clearing the query would drop the cursor on its own, but only if it had\n // changed; `moveTo(null)` covers reopening on an already-empty query.\n useOnOpen(open, () => {\n setQuery(\"\");\n moveTo(null);\n });\n\n useEffect(() => {\n if (!open) return;\n const frame = requestAnimationFrame(() => inputRef.current?.focus());\n return () => cancelAnimationFrame(frame);\n }, [open]);\n\n const onKeyDown = (e: React.KeyboardEvent) => {\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n moveActive(1);\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n moveActive(-1);\n } else if (e.key === \"Enter\") {\n e.preventDefault();\n const it = rows[active];\n if (it) {\n it.onSelect();\n setOpen(false);\n }\n }\n };\n\n useEffect(() => {\n if (!open) return;\n const el = listRef.current?.querySelector<HTMLButtonElement>(`[data-index=\"${active}\"]`);\n el?.scrollIntoView({ block: \"nearest\" });\n }, [active, open]);\n\n if (!mounted) return null;\n\n // Portaled to <body> so ancestors with transforms, filters, or fixed\n // positioning can't trap the overlay in their stacking context, and mounted\n // only while open. The chrome is two fixed siblings rather than one wrapper:\n // the backdrop spans the viewport edges but carries the scrim colour, and the\n // layer positioning the panel is inset off every edge. Both hang off\n // `PresenceGate`, so interaction releases in the same commit that starts the\n // exit rather than when it ends — `open` is already false for those frames.\n // See tests/fixed-overlay-edge-sampling.test.tsx.\n return createPortal(\n <AnimatePresence initial={false}>\n {open ? (\n <PresenceGate key=\"backdrop\">\n {({ gate }) => (\n <motion.button\n type=\"button\"\n aria-label=\"Close command palette\"\n initial={{ opacity: 0 }}\n animate={{ opacity: 1 }}\n exit={{\n opacity: 0,\n transition: { duration: 0.12, ease: EASE_OUT },\n }}\n transition={{ duration: 0.18, ease: EASE_OUT }}\n {...gate}\n onClick={() => setOpen(false)}\n className=\"pointer-events-auto fixed inset-0 z-100 bg-background/5 [-webkit-backdrop-filter:blur(12px)_saturate(140%)] [backdrop-filter:blur(12px)_saturate(140%)]\"\n />\n )}\n </PresenceGate>\n ) : null}\n\n {open ? (\n <PresenceGate key=\"panel-layer\">\n {({ isPresent, gate }) => (\n // The layer itself never takes pointer events, so it carries\n // `inert` alone rather than the gate's pointer-events value.\n <div\n inert={!isPresent}\n className=\"pointer-events-none fixed inset-x-4 top-[18vh] bottom-4 z-100 flex items-start justify-center\"\n >\n <motion.div\n role=\"dialog\"\n aria-modal=\"true\"\n aria-label=\"Command palette\"\n initial={{\n opacity: 0,\n y: reduce ? 0 : -8,\n scale: reduce ? 1 : 0.97,\n }}\n animate={{ opacity: 1, y: 0, scale: 1 }}\n exit={{\n opacity: 0,\n y: reduce ? 0 : -8,\n scale: reduce ? 1 : 0.97,\n transition: { duration: 0.12, ease: EASE_OUT },\n }}\n transition={reduce ? { duration: 0.1 } : PANEL_SPRING}\n {...gate}\n onKeyDown={onKeyDown}\n className=\"pointer-events-auto w-full max-w-xl overflow-hidden rounded-2xl border border-border bg-card shadow-2xl will-change-transform\"\n >\n <div className=\"flex items-center gap-3 border-border border-b px-4\">\n <Search className=\"h-4 w-4 text-muted-foreground\" />\n <input\n ref={inputRef}\n value={query}\n onChange={(e) => setQuery(e.target.value)}\n placeholder={placeholder}\n role=\"combobox\"\n // The field only exists while the palette is open.\n aria-expanded=\"true\"\n aria-controls={`${uid}-list`}\n aria-activedescendant={rows.length > 0 ? `${uid}-opt-${active}` : undefined}\n aria-autocomplete=\"list\"\n className={cn(\n \"h-12 flex-1 bg-transparent text-foreground text-sm outline-none placeholder:text-muted-foreground\",\n // The palette focuses this field the moment it opens, and iOS\n // zooms the page in on a focused field under 16px: the fixed\n // overlay is magnified off-center — clipped leading edge, half\n // an icon column — and the zoom outlives the palette. 16px on\n // touch keeps the page at scale 1; pointer devices keep 14px.\n canTouch && \"text-base\",\n )}\n />\n <kbd className=\"hidden rounded border border-border bg-background px-1.5 py-0.5 text-[10px] text-muted-foreground sm:inline-block\">\n ESC\n </kbd>\n </div>\n <div\n ref={listRef}\n id={`${uid}-list`}\n role=\"listbox\"\n aria-label=\"Commands\"\n className=\"max-h-[60vh] overflow-y-auto overscroll-contain p-2 [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden\"\n >\n {rows.length === 0 ? (\n <div className=\"p-8 text-center text-muted-foreground text-sm\">\n {emptyMessage}\n </div>\n ) : (\n grouped.map(([group, list]) => (\n <div key={group} className=\"mb-1 last:mb-0\">\n <div\n aria-hidden\n className=\"px-2 py-1.5 font-semibold text-[10px] text-muted-foreground uppercase tracking-wider\"\n >\n {group}\n </div>\n {list.map((it) => {\n // `rows` holds these very objects, in render order.\n const idx = rows.indexOf(it);\n const isActive = idx === active;\n const Icon = it.icon;\n return (\n <button\n key={it.id}\n type=\"button\"\n id={`${uid}-opt-${idx}`}\n role=\"option\"\n aria-selected={isActive}\n data-index={idx}\n onMouseEnter={() => moveTo(it.id)}\n onClick={() => {\n it.onSelect();\n setOpen(false);\n }}\n className={cn(\n \"relative isolate flex w-full items-center gap-3 rounded-md px-2 py-2 text-left text-sm transition-colors\",\n isActive ? \"text-foreground\" : \"text-muted-foreground\",\n )}\n >\n {isActive ? (\n <motion.span\n layoutId={`${uid}-active`}\n className=\"absolute inset-0 z-0 rounded-md bg-primary/5\"\n transition={\n reduce\n ? { duration: 0 }\n : // Tracks rapid arrow-key navigation — keep it tighter\n // than SPRING_LAYOUT so it never lags the active row.\n {\n type: \"spring\",\n stiffness: 480,\n damping: 38,\n }\n }\n />\n ) : null}\n {Icon ? (\n <Icon className=\"relative z-10 h-4 w-4\" />\n ) : hasIcons ? (\n <span className=\"relative z-10 h-4 w-4\" />\n ) : null}\n <span className=\"relative z-10 flex-1 truncate\">{it.label}</span>\n {it.badge ? (\n <span className=\"relative z-10 shrink-0\">{it.badge}</span>\n ) : null}\n {it.hint ? (\n <kbd className=\"relative z-10 rounded border border-border bg-background px-1.5 py-0.5 text-[10px] text-muted-foreground\">\n {it.hint}\n </kbd>\n ) : null}\n </button>\n );\n })}\n </div>\n ))\n )}\n </div>\n </motion.div>\n </div>\n )}\n </PresenceGate>\n ) : null}\n </AnimatePresence>,\n document.body,\n );\n}\n"],"mappings":";;;;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AAG,EAAE;QAChC,eAAe;SACb,GAAG,SAAS;SACZ,QAAQ,KAAK;QACf;QACA,WAAW,GACT,4GACA,WAAW,oBAAoB,uBACjC;QAfF,UAAA;SAiBG,WACC,oBAAC,OAAO,MAAR;UACE,UAAU,GAAG,IAAI;UACjB,WAAU;UACV,YACE,SACI,EAAE,UAAU,EAAE,IAGd;WACE,MAAM;WACN,WAAW;WACX,SAAS;UACX;SAEP,CAAA,IACC;SACH,OACC,oBAAC,MAAD,EAAM,WAAU,wBAAyB,CAAA,IACvC,WACF,oBAAC,QAAD,EAAM,WAAU,wBAAyB,CAAA,IACvC;SACJ,oBAAC,QAAD;UAAM,WAAU;UAAiC,UAAA,GAAG;SAAY,CAAA;SAC/D,GAAG,QACF,oBAAC,QAAD;UAAM,WAAU;UAA0B,UAAA,GAAG;SAAY,CAAA,IACvD;SACH,GAAG,OACF,oBAAC,OAAD;UAAK,WAAU;UACZ,UAAA,GAAG;SACD,CAAA,IACH;QACE;OA/CD,GAAA,GAAG,EA+CF;MAEZ,CAAC,CACE;KAhEK,GAAA,KAgEL,CACN;IAEA,CAAA,CACK;;EACT,CAAA,EAEK,GA5II,aA4IJ,IACZ,IACW;CACjB,CAAA,GAAA,SAAS,IACX;AACF"}
|
|
@@ -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;AA2BA,SAAS,mBAAmB,EAC1B,UACA,kBAAkB,OAClB,oBACuB;CACvB,MAAM,CAAC,kBAAkB,uBAAuB,SAAS,eAAe;CACxE,MAAM,eAAe,aAAa,KAAA;CAalC,OAAO,CAZiB,YAAY,kBAEhB,aACjB,iBAA0B;EACzB,IAAI,CAAC,cACH,oB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iBACA,kBACA,UACA,WACA,gBACA,mBACsB;CACtB,MAAM,SAAS,iBAAiB;CAChC,MAAM,aAAa,OAA0B,IAAI;CACjD,MAAM,CAAC,YAAY,eAAe,mBAAmB;EACnD;EACA;EACA;CACF,CAAC;CAED,MAAM,qBAAqB;EACzB,WAAW;EACX,IAAI,kBAAkB;GACpB,YAAY,KAAK;GACjB,WAAW,SAAS,MAAM;EAC5B;CACF;CAEA,MAAM,aAAa,SAAS,EAAE,UAAU,EAAE,IAAI;CAE9C,OACE,oBAAC,OAAO,MAAR;EAAa,QAAA;EAAmB;EAAY,WAAU;EACpD,UAAA,qBAAC,OAAO,KAAR;GACE,QAAA;GACA,WAAW,GACT,4MACA,SACF;GACA,OAAO,EAAE,cAAc,KAAK;GAChB;GAPd,UAAA,CASE,oBAAC,OAAO,QAAR;IACE,QAAO;IACP,KAAK;IACL,MAAK;IACL,iBAAe;IACL;IACV,WAAW,GACT,gHACA,aAAa,SAAS,QACtB,cACF;IACA,eAAe,YAAY,CAAC,UAAU;IAC1B;IAEX,UAAA;GACY,CAAA,GACf,oBAAC,OAAO,MAAR;IACE,UAAU;IACV,WAAW,GACT,mEACA,aAAa,QAAQ,KACvB;IACA,eAAa,CAAC;IACd,SAAS;IACT,SAAS,SAAS,EAAE,SAAS,aAAa,IAAI,EAAE,IAAI,aAAa,YAAY;IACjE;IAEZ,UAAA,oBAAC,OAAO,QAAR;KACE,MAAK;KACL,cAAY;KACZ,UAAU,YAAY,CAAC;KACvB,WAAW,GACT,2KACA,YAAY,cACZ,eACF;KACA,SAAS;KACT,UAAU,UAAU,WAAW,KAAA,IAAY,EAAE,OAAO,IAAK;KAC7C;KAEZ,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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expanding-arrow-button.js","names":[],"sources":["../../../src/components/motion/expanding-arrow-button.tsx"],"sourcesContent":["\"use client\";\n\nimport { type FocusEvent, forwardRef, type MouseEvent, type ReactNode, useState } from \"react\";\nimport { type HTMLMotionProps, motion, useReducedMotion } from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { useHoverCapable } from \"../../hooks/use-hover-capable\";\nimport { EASE_OUT, SPRING_LAYOUT, SPRING_PRESS } from \"../../lib/ease\";\n\nexport interface ExpandingArrowButtonProps extends Omit<HTMLMotionProps<\"button\">, \"children\"> {\n children: ReactNode;\n accentClassName?: string;\n labelClassName?: string;\n}\n\nconst ARROW_OPACITY = [1, 0.78, 0.54, 0.32, 0.16] as const;\n\nfunction DottedChevron({ className }: { className?: string }) {\n return (\n <svg viewBox=\"0 0 20 28\" fill=\"none\" aria-hidden=\"true\" className={className}>\n <circle cx=\"4\" cy=\"4\" r=\"2\" fill=\"currentColor\" />\n <circle cx=\"10\" cy=\"9\" r=\"2\" fill=\"currentColor\" />\n <circle cx=\"16\" cy=\"14\" r=\"2\" fill=\"currentColor\" />\n <circle cx=\"10\" cy=\"19\" r=\"2\" fill=\"currentColor\" />\n <circle cx=\"4\" cy=\"24\" r=\"2\" fill=\"currentColor\" />\n </svg>\n );\n}\n\nexport const ExpandingArrowButton = forwardRef<HTMLButtonElement, ExpandingArrowButtonProps>(\n function ExpandingArrowButton(\n {\n children,\n className,\n accentClassName,\n labelClassName,\n disabled,\n onMouseEnter,\n onMouseLeave,\n onFocus,\n onBlur,\n ...rest\n },\n ref,\n ) {\n const reduce = useReducedMotion();\n const canHover = useHoverCapable();\n const [hovered, setHovered] = useState(false);\n const [focused, setFocused] = useState(false);\n const active = !disabled && ((canHover && hovered) || focused);\n const layoutTransition = reduce ? { duration: 0 } : SPRING_LAYOUT;\n\n const handleMouseEnter = (event: MouseEvent<HTMLButtonElement>) => {\n setHovered(true);\n onMouseEnter?.(event);\n };\n\n const handleMouseLeave = (event: MouseEvent<HTMLButtonElement>) => {\n setHovered(false);\n onMouseLeave?.(event);\n };\n\n const handleFocus = (event: FocusEvent<HTMLButtonElement>) => {\n setFocused(true);\n onFocus?.(event);\n };\n\n const handleBlur = (event: FocusEvent<HTMLButtonElement>) => {\n setFocused(false);\n onBlur?.(event);\n };\n\n return (\n <motion.button\n ref={ref}\n type=\"button\"\n disabled={disabled}\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n onFocus={handleFocus}\n onBlur={handleBlur}\n whileTap={reduce || disabled ? undefined : { scale: 0.97 }}\n transition={SPRING_PRESS}\n className={cn(\n \"relative inline-flex h-16 min-w-72 select-none items-center overflow-hidden rounded-[22px] bg-neutral-950 p-1.5 text-white\",\n \"outline-none focus-visible:ring-2 focus-visible:ring-lime-300 focus-visible:ring-offset-2 focus-visible:ring-offset-background\",\n \"disabled:pointer-events-none disabled:opacity-50\",\n className,\n )}\n {...rest}\n >\n <motion.span\n layout=\"size\"\n aria-hidden=\"true\"\n transition={layoutTransition}\n style={{\n width: active ? \"calc(100% - 12px)\" : 52,\n borderRadius: 16,\n }}\n className={cn(\n \"absolute inset-y-1.5 left-1.5 z-10 overflow-hidden bg-lime-300 text-neutral-950\",\n accentClassName,\n )}\n >\n <motion.span\n animate={{ opacity: active ? 0 : 1 }}\n transition={{ duration: reduce ? 0 : 0.1, ease: EASE_OUT }}\n className=\"absolute inset-0 grid place-items-center\"\n >\n <DottedChevron className=\"h-7 w-5\" />\n </motion.span>\n\n <span className=\"absolute inset-0 flex items-center justify-around px-3\">\n {ARROW_OPACITY.map((opacity, index) => (\n <motion.span\n key={opacity}\n animate={{\n opacity: active ? 1 : 0,\n transform: active && !reduce ? \"translateX(0px)\" : \"translateX(-6px)\",\n }}\n transition={{\n duration: reduce ? 0 : 0.18,\n delay: active && !reduce ? 0.04 + index * 0.025 : 0,\n ease: EASE_OUT,\n }}\n style={{ color: `rgb(10 10 10 / ${opacity})` }}\n className=\"inline-grid place-items-center\"\n >\n <DottedChevron className=\"h-7 w-5\" />\n </motion.span>\n ))}\n </span>\n </motion.span>\n\n <motion.span\n animate={{\n opacity: active ? 0 : 1,\n transform: active && !reduce ? \"translateX(6px)\" : \"translateX(0px)\",\n }}\n transition={{ duration: reduce ? 0 : 0.12, ease: EASE_OUT }}\n className={cn(\n \"relative z-0 mr-5 ml-[76px] whitespace-nowrap font-medium text-lg tracking-[-0.02em]\",\n labelClassName,\n )}\n >\n {children}\n </motion.span>\n </motion.button>\n );\n },\n);\n"],"mappings":";;;;;;;;AAeA,MAAM,gBAAgB;CAAC;CAAG;CAAM;CAAM;CAAM;AAAI;AAEhD,SAAS,cAAc,EAAE,aAAqC;CAC5D,OACE,qBAAC,OAAD;EAAK,SAAQ;EAAY,MAAK;EAAO,eAAY;EAAkB;EAAnE,UAAA;GACE,oBAAC,UAAD;IAAQ,IAAG;IAAI,IAAG;IAAI,GAAE;IAAI,MAAK;GAAgB,CAAA;GACjD,oBAAC,UAAD;IAAQ,IAAG;IAAK,IAAG;IAAI,GAAE;IAAI,MAAK;GAAgB,CAAA;GAClD,oBAAC,UAAD;IAAQ,IAAG;IAAK,IAAG;IAAK,GAAE;IAAI,MAAK;GAAgB,CAAA;GACnD,oBAAC,UAAD;IAAQ,IAAG;IAAK,IAAG;IAAK,GAAE;IAAI,MAAK;GAAgB,CAAA;GACnD,oBAAC,UAAD;IAAQ,IAAG;IAAI,IAAG;IAAK,GAAE;IAAI,MAAK;GAAgB,CAAA;EAC/C;;AAET;AAEA,MAAa,uBAAuB,WAClC,SAAS,qBACP,EACE,UACA,WACA,iBACA,gBACA,UACA,cACA,cACA,SACA,QACA,GAAG,QAEL,KACA;CACA,MAAM,SAAS,iBAAiB;CAChC,MAAM,WAAW,gBAAgB;CACjC,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAC5C,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAC5C,MAAM,SAAS,CAAC,aAAc,YAAY,WAAY;CACtD,MAAM,mBAAmB,SAAS,EAAE,UAAU,EAAE,IAAI;CAEpD,MAAM,oBAAoB,UAAyC;EACjE,WAAW,IAAI;EACf,eAAe,KAAK;CACtB;CAEA,MAAM,oBAAoB,UAAyC;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;IACtB,WAAW,UAAU,CAAC,SAAS,oBAAoB;GACrD;GACA,YAAY;IAAE,UAAU,SAAS,IAAI;IAAM,MAAM;GAAS;GAC1D,WAAW,GACT,wFACA,cACF;GAEC;EACU,CAAA,CACA;;AAEnB,CACF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
//#region src/components/motion/file-tree.d.ts
|
|
3
|
+
interface FileTreeFolderProps {
|
|
4
|
+
value: string;
|
|
5
|
+
name: string;
|
|
6
|
+
icon?: ReactNode;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
children?: ReactNode;
|
|
9
|
+
className?: string;
|
|
10
|
+
}
|
|
11
|
+
interface FileTreeFileProps {
|
|
12
|
+
value: string;
|
|
13
|
+
name: string;
|
|
14
|
+
icon?: ReactNode;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
className?: string;
|
|
17
|
+
}
|
|
18
|
+
type FileTreeClassNames = {
|
|
19
|
+
tree?: string;
|
|
20
|
+
item?: string;
|
|
21
|
+
icon?: string;
|
|
22
|
+
label?: string;
|
|
23
|
+
};
|
|
24
|
+
interface FileTreeProps {
|
|
25
|
+
children: ReactNode;
|
|
26
|
+
value?: string | null;
|
|
27
|
+
defaultValue?: string | null;
|
|
28
|
+
onValueChange?: (value: string) => void;
|
|
29
|
+
expandedIds?: string[];
|
|
30
|
+
defaultExpandedIds?: string[];
|
|
31
|
+
onExpandedChange?: (expandedIds: string[]) => void;
|
|
32
|
+
ariaLabel?: string;
|
|
33
|
+
indent?: number;
|
|
34
|
+
className?: string;
|
|
35
|
+
classNames?: FileTreeClassNames;
|
|
36
|
+
}
|
|
37
|
+
declare function FileTreeFolder(_props: FileTreeFolderProps): null;
|
|
38
|
+
declare function FileTreeFile(_props: FileTreeFileProps): null;
|
|
39
|
+
declare function FileTree({ children, value, defaultValue, onValueChange, expandedIds, defaultExpandedIds, onExpandedChange, ariaLabel, indent, className, classNames }: FileTreeProps): import("react").JSX.Element;
|
|
40
|
+
//#endregion
|
|
41
|
+
export { FileTree, FileTreeClassNames, FileTreeFile, FileTreeFileProps, FileTreeFolder, FileTreeFolderProps, FileTreeProps };
|
|
42
|
+
//# sourceMappingURL=file-tree.d.ts.map
|