@kumix/ui 0.3.6 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/agents/ai-sidebar.d.ts +17 -1
- package/dist/components/agents/ai-sidebar.d.ts.map +1 -1
- package/dist/components/agents/ai-sidebar.js +90 -14
- package/dist/components/agents/ai-sidebar.js.map +1 -1
- package/dist/components/agents/chat-app.d.ts +10 -5
- package/dist/components/agents/chat-app.d.ts.map +1 -1
- package/dist/components/agents/chat-app.js +54 -5
- package/dist/components/agents/chat-app.js.map +1 -1
- package/dist/components/agents/citations.d.ts.map +1 -1
- package/dist/components/agents/citations.js +5 -6
- package/dist/components/agents/citations.js.map +1 -1
- package/dist/components/agents/tool-approval.d.ts.map +1 -1
- package/dist/components/agents/tool-approval.js +1 -1
- package/dist/components/agents/tool-approval.js.map +1 -1
- package/dist/components/motion/action-swap.d.ts.map +1 -1
- package/dist/components/motion/action-swap.js +2 -2
- package/dist/components/motion/action-swap.js.map +1 -1
- package/dist/components/motion/animated-sidebar.js +1 -0
- 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 +5 -2
- package/dist/components/motion/availability-scheduler/day-row.d.ts.map +1 -1
- package/dist/components/motion/availability-scheduler/day-row.js +18 -8
- package/dist/components/motion/availability-scheduler/day-row.js.map +1 -1
- package/dist/components/motion/availability-scheduler/index.d.ts.map +1 -1
- package/dist/components/motion/availability-scheduler/index.js +27 -5
- package/dist/components/motion/availability-scheduler/index.js.map +1 -1
- package/dist/components/motion/availability-scheduler/time-select.d.ts +3 -1
- package/dist/components/motion/availability-scheduler/time-select.d.ts.map +1 -1
- package/dist/components/motion/availability-scheduler/time-select.js +3 -1
- package/dist/components/motion/availability-scheduler/time-select.js.map +1 -1
- package/dist/components/motion/bottom-sheet.d.ts.map +1 -1
- package/dist/components/motion/bottom-sheet.js +2 -1
- package/dist/components/motion/bottom-sheet.js.map +1 -1
- package/dist/components/motion/command-palette.d.ts.map +1 -1
- package/dist/components/motion/command-palette.js +3 -1
- package/dist/components/motion/command-palette.js.map +1 -1
- package/dist/components/motion/context-menu.d.ts.map +1 -1
- package/dist/components/motion/context-menu.js +16 -6
- package/dist/components/motion/context-menu.js.map +1 -1
- package/dist/components/motion/cylinder-carousel.d.ts.map +1 -1
- package/dist/components/motion/cylinder-carousel.js +4 -3
- package/dist/components/motion/cylinder-carousel.js.map +1 -1
- package/dist/components/motion/expandable-action-bar.d.ts +6 -0
- package/dist/components/motion/expandable-action-bar.d.ts.map +1 -1
- package/dist/components/motion/expandable-action-bar.js +38 -9
- package/dist/components/motion/expandable-action-bar.js.map +1 -1
- package/dist/components/motion/hold-action-button.d.ts +1 -1
- package/dist/components/motion/hold-action-button.d.ts.map +1 -1
- package/dist/components/motion/hold-action-button.js +64 -50
- package/dist/components/motion/hold-action-button.js.map +1 -1
- package/dist/components/motion/morphing-tabs.d.ts.map +1 -1
- package/dist/components/motion/morphing-tabs.js +59 -18
- package/dist/components/motion/morphing-tabs.js.map +1 -1
- package/dist/components/motion/notification-stack.d.ts.map +1 -1
- package/dist/components/motion/notification-stack.js +28 -11
- package/dist/components/motion/notification-stack.js.map +1 -1
- package/dist/components/motion/popover-morph.d.ts.map +1 -1
- package/dist/components/motion/popover-morph.js +26 -11
- package/dist/components/motion/popover-morph.js.map +1 -1
- package/dist/components/motion/popover.d.ts.map +1 -1
- package/dist/components/motion/popover.js +39 -28
- package/dist/components/motion/popover.js.map +1 -1
- package/dist/components/motion/preview-rail.d.ts.map +1 -1
- package/dist/components/motion/preview-rail.js +42 -13
- package/dist/components/motion/preview-rail.js.map +1 -1
- package/dist/components/motion/pull-to-refresh.d.ts.map +1 -1
- package/dist/components/motion/pull-to-refresh.js +8 -7
- package/dist/components/motion/pull-to-refresh.js.map +1 -1
- package/dist/components/motion/range-slider-bubble.d.ts.map +1 -1
- package/dist/components/motion/range-slider-bubble.js +2 -1
- package/dist/components/motion/range-slider-bubble.js.map +1 -1
- package/dist/components/motion/range-slider-fluid.d.ts.map +1 -1
- package/dist/components/motion/range-slider-fluid.js +2 -1
- package/dist/components/motion/range-slider-fluid.js.map +1 -1
- package/dist/components/motion/range-slider-ruler.d.ts.map +1 -1
- package/dist/components/motion/range-slider-ruler.js +2 -1
- package/dist/components/motion/range-slider-ruler.js.map +1 -1
- package/dist/components/motion/range-slider-wave.d.ts.map +1 -1
- package/dist/components/motion/range-slider-wave.js +2 -1
- package/dist/components/motion/range-slider-wave.js.map +1 -1
- package/dist/components/motion/range-slider.d.ts.map +1 -1
- package/dist/components/motion/range-slider.js +2 -1
- package/dist/components/motion/range-slider.js.map +1 -1
- package/dist/components/motion/select.d.ts +15 -1
- package/dist/components/motion/select.d.ts.map +1 -1
- package/dist/components/motion/select.js +15 -4
- package/dist/components/motion/select.js.map +1 -1
- package/dist/components/motion/slide-action-button.d.ts.map +1 -1
- package/dist/components/motion/slide-action-button.js +3 -2
- package/dist/components/motion/slide-action-button.js.map +1 -1
- package/dist/components/motion/swipeable-list.d.ts.map +1 -1
- package/dist/components/motion/swipeable-list.js +2 -1
- package/dist/components/motion/swipeable-list.js.map +1 -1
- package/dist/components/motion/table/index.d.ts.map +1 -1
- package/dist/components/motion/table/index.js +64 -6
- package/dist/components/motion/table/index.js.map +1 -1
- package/dist/components/motion/table/table-header.d.ts.map +1 -1
- package/dist/components/motion/table/table-header.js +3 -2
- package/dist/components/motion/table/table-header.js.map +1 -1
- package/dist/components/motion/text-reveal.d.ts.map +1 -1
- package/dist/components/motion/text-reveal.js +72 -48
- package/dist/components/motion/text-reveal.js.map +1 -1
- package/dist/components/motion/tooltip.d.ts.map +1 -1
- package/dist/components/motion/tooltip.js +35 -15
- package/dist/components/motion/tooltip.js.map +1 -1
- package/dist/components/motion/wheel-picker.d.ts.map +1 -1
- package/dist/components/motion/wheel-picker.js +4 -3
- package/dist/components/motion/wheel-picker.js.map +1 -1
- package/dist/components/reui/badge.d.ts +1 -1
- package/dist/components/reui/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 +2 -2
- package/dist/components/ui/field.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/{copy-menu-Bk5GP9Gp.js → copy-menu-1FKoMc9o.js} +9 -2
- package/dist/copy-menu-1FKoMc9o.js.map +1 -0
- package/dist/hooks/use-dismiss.d.ts +34 -0
- package/dist/hooks/use-dismiss.d.ts.map +1 -0
- package/dist/hooks/use-dismiss.js +78 -0
- package/dist/hooks/use-dismiss.js.map +1 -0
- package/dist/hooks/use-favicon.d.ts +17 -0
- package/dist/hooks/use-favicon.d.ts.map +1 -0
- package/dist/hooks/use-favicon.js +35 -0
- package/dist/hooks/use-favicon.js.map +1 -0
- package/dist/hooks/use-hover-gesture.d.ts +38 -0
- package/dist/hooks/use-hover-gesture.d.ts.map +1 -0
- package/dist/hooks/use-hover-gesture.js +46 -0
- package/dist/hooks/use-hover-gesture.js.map +1 -0
- package/dist/hooks/use-slider.d.ts.map +1 -1
- package/dist/hooks/use-slider.js +3 -2
- package/dist/hooks/use-slider.js.map +1 -1
- package/dist/hooks/use-tap-gesture.d.ts +47 -0
- package/dist/hooks/use-tap-gesture.d.ts.map +1 -0
- package/dist/hooks/use-tap-gesture.js +51 -0
- package/dist/hooks/use-tap-gesture.js.map +1 -0
- package/dist/hooks/use-touch-capable.d.ts +15 -0
- package/dist/hooks/use-touch-capable.d.ts.map +1 -0
- package/dist/hooks/use-touch-capable.js +29 -0
- package/dist/hooks/use-touch-capable.js.map +1 -0
- package/dist/lib/touch.d.ts +66 -0
- package/dist/lib/touch.d.ts.map +1 -0
- package/dist/lib/touch.js +79 -0
- package/dist/lib/touch.js.map +1 -0
- package/dist/types-smkWN_7x.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/copy-menu-Bk5GP9Gp.js.map +0 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { TOUCH_GESTURE_CLASS, capturePointer } from "../../lib/touch.js";
|
|
2
3
|
import { EASE_OUT, SPRING_GLIDE, SPRING_PRESS } from "../../lib/ease.js";
|
|
3
4
|
import { useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
4
5
|
import { cn } from "@kumix/utils";
|
|
@@ -8,7 +9,8 @@ import { X } from "lucide-react";
|
|
|
8
9
|
import { createPortal } from "react-dom";
|
|
9
10
|
//#region src/components/motion/morphing-tabs.tsx
|
|
10
11
|
const DRAG_THRESHOLD = 5;
|
|
11
|
-
const
|
|
12
|
+
const MAX_TAB_WIDTH = 176;
|
|
13
|
+
const MIN_TAB_WIDTH = 96;
|
|
12
14
|
const TAB_HEIGHT = 56;
|
|
13
15
|
const TAB_TOP = 24;
|
|
14
16
|
const TAB_RADIUS = 24;
|
|
@@ -29,11 +31,11 @@ function moveItem(order, from, to) {
|
|
|
29
31
|
next.splice(to, 0, item);
|
|
30
32
|
return next;
|
|
31
33
|
}
|
|
32
|
-
function liquidTabPath(tabLeft, surfaceWidth) {
|
|
34
|
+
function liquidTabPath(tabLeft, surfaceWidth, tabWidth) {
|
|
33
35
|
const panelLeft = SURFACE_INSET;
|
|
34
36
|
const panelRight = surfaceWidth - SURFACE_INSET;
|
|
35
|
-
const left = Math.max(panelLeft, Math.min(panelRight -
|
|
36
|
-
const right = left +
|
|
37
|
+
const left = Math.max(panelLeft, Math.min(panelRight - tabWidth, tabLeft));
|
|
38
|
+
const right = left + tabWidth;
|
|
37
39
|
const top = 24;
|
|
38
40
|
const bottom = RAIL_HEIGHT;
|
|
39
41
|
const leftJoin = Math.max(panelLeft, left - LIQUID_JOIN);
|
|
@@ -62,7 +64,7 @@ function liquidTabPath(tabLeft, surfaceWidth) {
|
|
|
62
64
|
"Z"
|
|
63
65
|
].join(" ");
|
|
64
66
|
}
|
|
65
|
-
function SpringTab({ id, targetLeft, dragging, dragLeft, surfaceLeft, reduce, active, anyDragging, surfaceHost, surfaceWidth, surfaceClassName, zIndex, className, children, registerPosition, onPointerDown, onPointerMove, onPointerUp, onPointerCancel, onLostPointerCapture }) {
|
|
67
|
+
function SpringTab({ id, targetLeft, dragging, dragLeft, surfaceLeft, reduce, active, anyDragging, surfaceHost, surfaceWidth, tabWidth, surfaceClassName, zIndex, className, children, registerPosition, onPointerDown, onPointerMove, onPointerUp, onPointerCancel, onLostPointerCapture }) {
|
|
66
68
|
const target = useMotionValue(targetLeft);
|
|
67
69
|
const position = useSpring(target, SPRING_GLIDE);
|
|
68
70
|
const settledTransform = useTransform(reduce ? target : position, (left) => `translate3d(${left}px, 0, 0)`);
|
|
@@ -93,7 +95,8 @@ function SpringTab({ id, targetLeft, dragging, dragLeft, surfaceLeft, reduce, ac
|
|
|
93
95
|
className: cn("pointer-events-none absolute inset-x-0 top-0 h-[108px] w-full text-[#fafaf8]", dragging ? "z-20" : "z-0", surfaceClassName),
|
|
94
96
|
children: /* @__PURE__ */ jsx(LiquidSurfacePath, {
|
|
95
97
|
left: liquidDriver,
|
|
96
|
-
surfaceWidth
|
|
98
|
+
surfaceWidth,
|
|
99
|
+
tabWidth
|
|
97
100
|
}, anyDragging ? dragging ? "dragged" : "displaced" : "idle")
|
|
98
101
|
}), surfaceHost) : null, /* @__PURE__ */ jsx(motion.div, {
|
|
99
102
|
style: {
|
|
@@ -109,8 +112,8 @@ function SpringTab({ id, targetLeft, dragging, dragLeft, surfaceLeft, reduce, ac
|
|
|
109
112
|
children
|
|
110
113
|
})] });
|
|
111
114
|
}
|
|
112
|
-
function LiquidSurfacePath({ left, surfaceWidth }) {
|
|
113
|
-
const path = useTransform(left, (value) => liquidTabPath(value, surfaceWidth));
|
|
115
|
+
function LiquidSurfacePath({ left, surfaceWidth, tabWidth }) {
|
|
116
|
+
const path = useTransform(left, (value) => liquidTabPath(value, surfaceWidth, tabWidth));
|
|
114
117
|
return /* @__PURE__ */ jsx(motion.path, {
|
|
115
118
|
d: path,
|
|
116
119
|
fill: "currentColor"
|
|
@@ -157,7 +160,39 @@ function MorphingTabs({ items, value, defaultValue, onValueChange, onOrderChange
|
|
|
157
160
|
const firstEnabledItem = orderedItems.find((item) => !item.disabled) ?? orderedItems[0] ?? null;
|
|
158
161
|
const activeItem = currentValue && itemMap.has(currentValue) ? itemMap.get(currentValue) ?? null : firstEnabledItem;
|
|
159
162
|
const activeId = activeItem?.id ?? null;
|
|
160
|
-
const
|
|
163
|
+
const { tabWidth, slotGap } = useMemo(() => {
|
|
164
|
+
const count = order.length;
|
|
165
|
+
if (!surfaceWidth || count === 0) return {
|
|
166
|
+
tabWidth: MAX_TAB_WIDTH,
|
|
167
|
+
slotGap: tabGap
|
|
168
|
+
};
|
|
169
|
+
const inner = surfaceWidth - 32;
|
|
170
|
+
const widthAt = (gap) => Math.floor((inner - gap * (count - 1)) / count);
|
|
171
|
+
if (widthAt(tabGap) >= MIN_TAB_WIDTH) return {
|
|
172
|
+
tabWidth: Math.min(MAX_TAB_WIDTH, widthAt(tabGap)),
|
|
173
|
+
slotGap: tabGap
|
|
174
|
+
};
|
|
175
|
+
if (count > 1 && widthAt(0) >= MIN_TAB_WIDTH) {
|
|
176
|
+
const gap = Math.floor((inner - MIN_TAB_WIDTH * count) / (count - 1));
|
|
177
|
+
return {
|
|
178
|
+
tabWidth: MIN_TAB_WIDTH,
|
|
179
|
+
slotGap: Math.max(0, gap)
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
tabWidth: Math.max(0, widthAt(0)),
|
|
184
|
+
slotGap: 0
|
|
185
|
+
};
|
|
186
|
+
}, [
|
|
187
|
+
order.length,
|
|
188
|
+
surfaceWidth,
|
|
189
|
+
tabGap
|
|
190
|
+
]);
|
|
191
|
+
const slotLefts = useMemo(() => order.map((_, index) => SURFACE_INSET + index * (tabWidth + slotGap)), [
|
|
192
|
+
order,
|
|
193
|
+
slotGap,
|
|
194
|
+
tabWidth
|
|
195
|
+
]);
|
|
161
196
|
const dragStartIndex = draggingId ? order.indexOf(draggingId) : -1;
|
|
162
197
|
const visualIndexFor = useCallback((index) => {
|
|
163
198
|
if (dragStartIndex < 0 || dragTargetIndex < 0) return index;
|
|
@@ -225,7 +260,7 @@ function MorphingTabs({ items, value, defaultValue, onValueChange, onOrderChange
|
|
|
225
260
|
if (event.button !== 0 || itemMap.get(id)?.disabled || dragRef.current) return;
|
|
226
261
|
const startIndex = orderRef.current.indexOf(id);
|
|
227
262
|
if (startIndex < 0) return;
|
|
228
|
-
const capturedSlots = orderRef.current.map((_, index) => SURFACE_INSET + index * (
|
|
263
|
+
const capturedSlots = orderRef.current.map((_, index) => SURFACE_INSET + index * (tabWidth + slotGap));
|
|
229
264
|
const startLeft = capturedSlots[startIndex];
|
|
230
265
|
dragAnimationRef.current?.stop();
|
|
231
266
|
dragAnimationRef.current = null;
|
|
@@ -245,7 +280,8 @@ function MorphingTabs({ items, value, defaultValue, onValueChange, onOrderChange
|
|
|
245
280
|
}, [
|
|
246
281
|
dragLeft,
|
|
247
282
|
itemMap,
|
|
248
|
-
|
|
283
|
+
slotGap,
|
|
284
|
+
tabWidth
|
|
249
285
|
]);
|
|
250
286
|
const moveDrag = useCallback((event) => {
|
|
251
287
|
const drag = dragRef.current;
|
|
@@ -255,7 +291,7 @@ function MorphingTabs({ items, value, defaultValue, onValueChange, onOrderChange
|
|
|
255
291
|
event.preventDefault();
|
|
256
292
|
if (!drag.moved) {
|
|
257
293
|
drag.moved = true;
|
|
258
|
-
event.currentTarget
|
|
294
|
+
capturePointer(event.currentTarget, event.pointerId);
|
|
259
295
|
if (drag.id === activeId) {
|
|
260
296
|
surfaceAnimationRef.current?.stop();
|
|
261
297
|
surfaceLeft.set(drag.startLeft);
|
|
@@ -268,8 +304,8 @@ function MorphingTabs({ items, value, defaultValue, onValueChange, onOrderChange
|
|
|
268
304
|
const visualLeft = Math.max(minLeft, Math.min(maxLeft, drag.startLeft + delta));
|
|
269
305
|
let targetIndex = drag.startIndex;
|
|
270
306
|
if (visualLeft >= drag.startLeft) {
|
|
271
|
-
for (let index = drag.startIndex + 1; index < drag.slotLefts.length; index += 1) if (visualLeft +
|
|
272
|
-
} else for (let index = drag.startIndex - 1; index >= 0; index -= 1) if (visualLeft <= drag.slotLefts[index] +
|
|
307
|
+
for (let index = drag.startIndex + 1; index < drag.slotLefts.length; index += 1) if (visualLeft + tabWidth / 2 >= drag.slotLefts[index]) targetIndex = index;
|
|
308
|
+
} else for (let index = drag.startIndex - 1; index >= 0; index -= 1) if (visualLeft <= drag.slotLefts[index] + tabWidth / 2) targetIndex = index;
|
|
273
309
|
dragLeft.set(visualLeft);
|
|
274
310
|
if (targetIndex !== drag.targetIndex) {
|
|
275
311
|
drag.targetIndex = targetIndex;
|
|
@@ -278,7 +314,8 @@ function MorphingTabs({ items, value, defaultValue, onValueChange, onOrderChange
|
|
|
278
314
|
}, [
|
|
279
315
|
activeId,
|
|
280
316
|
dragLeft,
|
|
281
|
-
surfaceLeft
|
|
317
|
+
surfaceLeft,
|
|
318
|
+
tabWidth
|
|
282
319
|
]);
|
|
283
320
|
const finishDrag = useCallback((pointerId) => {
|
|
284
321
|
const drag = dragRef.current;
|
|
@@ -392,18 +429,22 @@ function MorphingTabs({ items, value, defaultValue, onValueChange, onOrderChange
|
|
|
392
429
|
anyDragging: Boolean(draggingId),
|
|
393
430
|
surfaceHost: rootRef.current,
|
|
394
431
|
surfaceWidth,
|
|
432
|
+
tabWidth,
|
|
395
433
|
surfaceClassName: classNames?.activeTab,
|
|
396
434
|
zIndex: isDragging ? 30 : isActive ? 20 : 1,
|
|
397
|
-
className: cn("group absolute top-0 left-0 flex touch-pan-y
|
|
435
|
+
className: cn("group absolute top-0 left-0 flex touch-pan-y items-stretch", TOUCH_GESTURE_CLASS, item.disabled && "cursor-not-allowed", isDragging ? "cursor-grabbing" : "cursor-grab"),
|
|
398
436
|
registerPosition,
|
|
399
437
|
onPointerDown: (event) => startDrag(item.id, event),
|
|
400
438
|
onPointerMove: moveDrag,
|
|
401
439
|
onPointerUp: (event) => finishDrag(event.pointerId),
|
|
402
440
|
onPointerCancel: (event) => finishDrag(event.pointerId),
|
|
403
|
-
onLostPointerCapture: (event) =>
|
|
441
|
+
onLostPointerCapture: (event) => {
|
|
442
|
+
if (event.target !== event.currentTarget) return;
|
|
443
|
+
finishDrag(event.pointerId);
|
|
444
|
+
},
|
|
404
445
|
children: /* @__PURE__ */ jsxs("div", {
|
|
405
446
|
style: {
|
|
406
|
-
width:
|
|
447
|
+
width: tabWidth,
|
|
407
448
|
height: TAB_HEIGHT,
|
|
408
449
|
marginTop: TAB_TOP
|
|
409
450
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"morphing-tabs.js","names":["animateValue"],"sources":["../../../src/components/motion/morphing-tabs.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type ReactNode,\n type PointerEvent as ReactPointerEvent,\n useCallback,\n useEffect,\n useId,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { X } from \"lucide-react\";\nimport {\n AnimatePresence,\n animate as animateValue,\n type MotionValue,\n motion,\n useMotionValue,\n useReducedMotion,\n useSpring,\n useTransform,\n} from \"motion/react\";\nimport { createPortal } from \"react-dom\";\n\nimport { cn } from \"@kumix/utils\";\nimport { EASE_OUT, SPRING_GLIDE, SPRING_PRESS } from \"../../lib/ease\";\n\nexport type MorphingTabsItem = {\n id: string;\n label: string;\n icon?: ReactNode;\n content: ReactNode;\n disabled?: boolean;\n};\n\nexport type MorphingTabsClassNames = {\n root?: string;\n rail?: string;\n tab?: string;\n activeTab?: string;\n icon?: string;\n label?: string;\n close?: string;\n content?: string;\n};\n\nexport interface MorphingTabsProps {\n items: MorphingTabsItem[];\n value?: string | null;\n defaultValue?: string | null;\n onValueChange?: (id: string | null) => void;\n /** Called once after a pointer drag or keyboard reorder completes. */\n onOrderChange?: (ids: string[]) => void;\n /** Enables the close affordance on every tab when provided. */\n onClose?: (id: string) => void;\n ariaLabel?: string;\n className?: string;\n classNames?: MorphingTabsClassNames;\n}\n\ntype DragSession = {\n id: string;\n pointerId: number;\n originX: number;\n startLeft: number;\n startIndex: number;\n targetIndex: number;\n moved: boolean;\n finishing: boolean;\n startOrder: string[];\n slotLefts: number[];\n};\n\ntype SpringTabProps = {\n id: string;\n targetLeft: number;\n dragging: boolean;\n dragLeft: MotionValue<number>;\n surfaceLeft: MotionValue<number>;\n reduce: boolean;\n active: boolean;\n anyDragging: boolean;\n surfaceHost: HTMLDivElement | null;\n surfaceWidth: number;\n surfaceClassName?: string;\n zIndex: number;\n className: string;\n children: ReactNode;\n registerPosition: (id: string, position: MotionValue<number> | null) => void;\n onPointerDown: (event: ReactPointerEvent<HTMLDivElement>) => void;\n onPointerMove: (event: ReactPointerEvent<HTMLDivElement>) => void;\n onPointerUp: (event: ReactPointerEvent<HTMLDivElement>) => void;\n onPointerCancel: (event: ReactPointerEvent<HTMLDivElement>) => void;\n onLostPointerCapture: (event: ReactPointerEvent<HTMLDivElement>) => void;\n};\n\nconst DRAG_THRESHOLD = 5;\nconst TAB_WIDTH = 176;\nconst TAB_HEIGHT = 56;\nconst TAB_TOP = 24;\nconst TAB_RADIUS = 24;\nconst RAIL_HEIGHT = 80;\nconst SURFACE_INSET = 16;\nconst LIQUID_JOIN = 24;\nconst PANEL_RADIUS = 28;\n\nfunction sameOrder(a: string[], b: string[]) {\n return a.length === b.length && a.every((id, index) => id === b[index]);\n}\n\nfunction safeId(value: string) {\n return value.replace(/[^a-zA-Z0-9_-]/g, \"-\");\n}\n\nfunction moveItem(order: string[], from: number, to: number) {\n if (from === to) return order.slice();\n const next = order.slice();\n const [item] = next.splice(from, 1);\n next.splice(to, 0, item);\n return next;\n}\n\nfunction liquidTabPath(tabLeft: number, surfaceWidth: number) {\n const panelLeft = SURFACE_INSET;\n const panelRight = surfaceWidth - SURFACE_INSET;\n const left = Math.max(panelLeft, Math.min(panelRight - TAB_WIDTH, tabLeft));\n const right = left + TAB_WIDTH;\n const top = RAIL_HEIGHT - TAB_HEIGHT;\n const bottom = RAIL_HEIGHT;\n const leftJoin = Math.max(panelLeft, left - LIQUID_JOIN);\n const rightJoin = Math.min(panelRight, right + LIQUID_JOIN);\n const leftDepth = Math.min(LIQUID_JOIN, left - leftJoin);\n const rightDepth = Math.min(LIQUID_JOIN, rightJoin - right);\n const leftControl = leftDepth * 0.55;\n const rightControl = rightDepth * 0.55;\n const leftPanelRadius = Math.min(PANEL_RADIUS, leftJoin - panelLeft);\n const rightPanelRadius = Math.min(PANEL_RADIUS, panelRight - rightJoin);\n\n return [\n `M${panelLeft} ${bottom + PANEL_RADIUS}`,\n `V${bottom + leftPanelRadius}`,\n `Q${panelLeft} ${bottom} ${panelLeft + leftPanelRadius} ${bottom}`,\n `H${leftJoin}`,\n `C${leftJoin + leftControl} ${bottom} ${left} ${bottom - leftDepth + leftControl} ${left} ${bottom - leftDepth}`,\n `V${top + TAB_RADIUS}`,\n `Q${left} ${top} ${left + TAB_RADIUS} ${top}`,\n `H${right - TAB_RADIUS}`,\n `Q${right} ${top} ${right} ${top + TAB_RADIUS}`,\n `V${bottom - rightDepth}`,\n `C${right} ${bottom - rightDepth + rightControl} ${rightJoin - rightControl} ${bottom} ${rightJoin} ${bottom}`,\n `H${panelRight - rightPanelRadius}`,\n `Q${panelRight} ${bottom} ${panelRight} ${bottom + rightPanelRadius}`,\n `V${bottom + PANEL_RADIUS}`,\n \"Z\",\n ].join(\" \");\n}\n\nfunction SpringTab({\n id,\n targetLeft,\n dragging,\n dragLeft,\n surfaceLeft,\n reduce,\n active,\n anyDragging,\n surfaceHost,\n surfaceWidth,\n surfaceClassName,\n zIndex,\n className,\n children,\n registerPosition,\n onPointerDown,\n onPointerMove,\n onPointerUp,\n onPointerCancel,\n onLostPointerCapture,\n}: SpringTabProps) {\n const target = useMotionValue(targetLeft);\n const position = useSpring(target, SPRING_GLIDE);\n const settledTransform = useTransform(\n reduce ? target : position,\n (left) => `translate3d(${left}px, 0, 0)`,\n );\n const draggedTransform = useTransform(dragLeft, (left) => `translate3d(${left}px, 0, 0)`);\n\n useLayoutEffect(() => {\n target.set(targetLeft);\n if (reduce) position.jump(targetLeft);\n }, [position, reduce, target, targetLeft]);\n\n useLayoutEffect(() => {\n registerPosition(id, position);\n return () => registerPosition(id, null);\n }, [id, position, registerPosition]);\n\n const liquidDriver = anyDragging ? (dragging ? dragLeft : position) : surfaceLeft;\n\n return (\n <>\n {active && surfaceHost && surfaceWidth > SURFACE_INSET * 2\n ? createPortal(\n <svg\n aria-hidden=\"true\"\n focusable=\"false\"\n viewBox={`0 0 ${surfaceWidth} ${RAIL_HEIGHT + PANEL_RADIUS}`}\n preserveAspectRatio=\"none\"\n className={cn(\n \"pointer-events-none absolute inset-x-0 top-0 h-[108px] w-full text-[#fafaf8]\",\n dragging ? \"z-20\" : \"z-0\",\n surfaceClassName,\n )}\n >\n <LiquidSurfacePath\n key={anyDragging ? (dragging ? \"dragged\" : \"displaced\") : \"idle\"}\n left={liquidDriver}\n surfaceWidth={surfaceWidth}\n />\n </svg>,\n surfaceHost,\n )\n : null}\n <motion.div\n style={{\n zIndex,\n transform: dragging ? draggedTransform : settledTransform,\n }}\n className={className}\n onPointerDown={onPointerDown}\n onPointerMove={onPointerMove}\n onPointerUp={onPointerUp}\n onPointerCancel={onPointerCancel}\n onLostPointerCapture={onLostPointerCapture}\n >\n {children}\n </motion.div>\n </>\n );\n}\n\nfunction LiquidSurfacePath({\n left,\n surfaceWidth,\n}: {\n left: MotionValue<number>;\n surfaceWidth: number;\n}) {\n const path = useTransform(left, (value) => liquidTabPath(value, surfaceWidth));\n return <motion.path d={path} fill=\"currentColor\" />;\n}\n\nexport function MorphingTabs({\n items,\n value,\n defaultValue,\n onValueChange,\n onOrderChange,\n onClose,\n ariaLabel = \"Tabs\",\n className,\n classNames,\n}: MorphingTabsProps) {\n const reduce = Boolean(useReducedMotion());\n const uid = useId();\n const itemIds = useMemo(() => items.map((item) => item.id), [items]);\n const itemMap = useMemo(() => new Map(items.map((item) => [item.id, item])), [items]);\n const [order, setOrder] = useState(itemIds);\n const orderRef = useRef(order);\n orderRef.current = order;\n\n const [internalValue, setInternalValue] = useState<string | null>(\n defaultValue ?? itemIds[0] ?? null,\n );\n const controlled = value !== undefined;\n const currentValue = controlled ? (value ?? null) : internalValue;\n\n const rootRef = useRef<HTMLDivElement | null>(null);\n const railRef = useRef<HTMLDivElement | null>(null);\n const tabButtonRefs = useRef<Record<string, HTMLButtonElement | null>>({});\n const tabPositionRefs = useRef<Record<string, MotionValue<number> | null>>({});\n const dragRef = useRef<DragSession | null>(null);\n const dragAnimationRef = useRef<ReturnType<typeof animateValue> | null>(null);\n const surfaceAnimationRef = useRef<ReturnType<typeof animateValue> | null>(null);\n const [surfaceWidth, setSurfaceWidth] = useState(0);\n const [tabGap, setTabGap] = useState(12);\n const [draggingId, setDraggingId] = useState<string | null>(null);\n const [dragTargetIndex, setDragTargetIndex] = useState(-1);\n const dragLeft = useMotionValue(SURFACE_INSET);\n const surfaceLeft = useMotionValue(SURFACE_INSET);\n\n useEffect(() => {\n setOrder((current) => {\n const available = new Set(itemIds);\n const retained = current.filter((id) => available.has(id));\n const retainedSet = new Set(retained);\n const added = itemIds.filter((id) => !retainedSet.has(id));\n const next = [...retained, ...added];\n return sameOrder(current, next) ? current : next;\n });\n }, [itemIds]);\n\n const orderedItems = useMemo(\n () =>\n order.flatMap((id) => {\n const item = itemMap.get(id);\n return item ? [item] : [];\n }),\n [itemMap, order],\n );\n\n const firstEnabledItem = orderedItems.find((item) => !item.disabled) ?? orderedItems[0] ?? null;\n const activeItem =\n currentValue && itemMap.has(currentValue)\n ? (itemMap.get(currentValue) ?? null)\n : firstEnabledItem;\n const activeId = activeItem?.id ?? null;\n\n const slotLefts = useMemo(\n () => order.map((_, index) => SURFACE_INSET + index * (TAB_WIDTH + tabGap)),\n [order, tabGap],\n );\n\n const dragStartIndex = draggingId ? order.indexOf(draggingId) : -1;\n\n const visualIndexFor = useCallback(\n (index: number) => {\n if (dragStartIndex < 0 || dragTargetIndex < 0) return index;\n if (index === dragStartIndex) return dragTargetIndex;\n\n if (dragTargetIndex > dragStartIndex && index > dragStartIndex && index <= dragTargetIndex) {\n return index - 1;\n }\n if (dragTargetIndex < dragStartIndex && index >= dragTargetIndex && index < dragStartIndex) {\n return index + 1;\n }\n return index;\n },\n [dragStartIndex, dragTargetIndex],\n );\n\n useLayoutEffect(() => {\n const root = rootRef.current;\n const rail = railRef.current;\n if (!root || !rail) return;\n\n const measure = () => {\n setSurfaceWidth(root.clientWidth);\n const nextGap = Number.parseFloat(getComputedStyle(rail).columnGap);\n if (Number.isFinite(nextGap)) setTabGap(nextGap);\n };\n\n measure();\n const observer = new ResizeObserver(measure);\n observer.observe(root);\n return () => observer.disconnect();\n }, []);\n\n const setActive = useCallback(\n (id: string | null) => {\n if (id && itemMap.get(id)?.disabled) return;\n if (!controlled) setInternalValue(id);\n onValueChange?.(id);\n },\n [controlled, itemMap, onValueChange],\n );\n\n useEffect(() => {\n if (currentValue && itemMap.has(currentValue)) return;\n if (firstEnabledItem && firstEnabledItem.id !== currentValue) {\n setActive(firstEnabledItem.id);\n }\n }, [currentValue, firstEnabledItem, itemMap, setActive]);\n\n const activeOrderIndex = activeId ? order.indexOf(activeId) : -1;\n const activeVisualIndex = activeOrderIndex < 0 ? -1 : visualIndexFor(activeOrderIndex);\n\n useLayoutEffect(() => {\n if (\n !activeId ||\n activeVisualIndex < 0 ||\n activeId === draggingId ||\n !slotLefts[activeVisualIndex]\n ) {\n return;\n }\n\n surfaceAnimationRef.current?.stop();\n\n if (draggingId) return;\n\n surfaceAnimationRef.current = animateValue(\n surfaceLeft,\n slotLefts[activeVisualIndex],\n reduce ? { duration: 0 } : SPRING_GLIDE,\n );\n }, [activeId, activeVisualIndex, draggingId, reduce, slotLefts, surfaceLeft]);\n\n const commitOrder = useCallback(\n (next: string[], notify: boolean) => {\n orderRef.current = next;\n setOrder((current) => (sameOrder(current, next) ? current : next));\n if (notify) onOrderChange?.(next);\n },\n [onOrderChange],\n );\n\n const registerPosition = useCallback((id: string, position: MotionValue<number> | null) => {\n tabPositionRefs.current[id] = position;\n }, []);\n\n const startDrag = useCallback(\n (id: string, event: ReactPointerEvent<HTMLDivElement>) => {\n if (event.button !== 0 || itemMap.get(id)?.disabled || dragRef.current) {\n return;\n }\n\n const startIndex = orderRef.current.indexOf(id);\n if (startIndex < 0) return;\n const capturedSlots = orderRef.current.map(\n (_, index) => SURFACE_INSET + index * (TAB_WIDTH + tabGap),\n );\n const startLeft = capturedSlots[startIndex];\n\n dragAnimationRef.current?.stop();\n dragAnimationRef.current = null;\n dragLeft.set(startLeft);\n dragRef.current = {\n id,\n pointerId: event.pointerId,\n originX: event.clientX,\n startLeft,\n startIndex,\n targetIndex: startIndex,\n moved: false,\n finishing: false,\n startOrder: orderRef.current.slice(),\n slotLefts: capturedSlots,\n };\n },\n [dragLeft, itemMap, tabGap],\n );\n\n const moveDrag = useCallback(\n (event: ReactPointerEvent<HTMLDivElement>) => {\n const drag = dragRef.current;\n if (!drag || drag.finishing || drag.pointerId !== event.pointerId) return;\n\n const delta = event.clientX - drag.originX;\n if (!drag.moved && Math.abs(delta) < DRAG_THRESHOLD) return;\n event.preventDefault();\n\n if (!drag.moved) {\n drag.moved = true;\n event.currentTarget.setPointerCapture(event.pointerId);\n if (drag.id === activeId) {\n surfaceAnimationRef.current?.stop();\n surfaceLeft.set(drag.startLeft);\n }\n setDraggingId(drag.id);\n setDragTargetIndex(drag.startIndex);\n }\n\n const minLeft = drag.slotLefts[0];\n const maxLeft = drag.slotLefts[drag.slotLefts.length - 1];\n const visualLeft = Math.max(minLeft, Math.min(maxLeft, drag.startLeft + delta));\n let targetIndex = drag.startIndex;\n\n if (visualLeft >= drag.startLeft) {\n for (let index = drag.startIndex + 1; index < drag.slotLefts.length; index += 1) {\n if (visualLeft + TAB_WIDTH / 2 >= drag.slotLefts[index]) {\n targetIndex = index;\n }\n }\n } else {\n for (let index = drag.startIndex - 1; index >= 0; index -= 1) {\n if (visualLeft <= drag.slotLefts[index] + TAB_WIDTH / 2) {\n targetIndex = index;\n }\n }\n }\n\n dragLeft.set(visualLeft);\n if (targetIndex !== drag.targetIndex) {\n drag.targetIndex = targetIndex;\n setDragTargetIndex(targetIndex);\n }\n },\n [activeId, dragLeft, surfaceLeft],\n );\n\n const finishDrag = useCallback(\n (pointerId: number) => {\n const drag = dragRef.current;\n if (!drag || drag.pointerId !== pointerId || drag.finishing) return;\n\n if (!drag.moved) {\n dragRef.current = null;\n return;\n }\n\n drag.finishing = true;\n const targetLeft = drag.slotLefts[drag.targetIndex];\n const controls = animateValue(dragLeft, targetLeft, reduce ? { duration: 0 } : SPRING_GLIDE);\n dragAnimationRef.current = controls;\n\n controls.then(async () => {\n if (dragAnimationRef.current !== controls) return;\n const next = moveItem(drag.startOrder, drag.startIndex, drag.targetIndex);\n\n if (!reduce) {\n await new Promise<void>((resolve) => {\n const startedAt = performance.now();\n const check = () => {\n const settled = next.every((id, index) => {\n if (id === drag.id) return true;\n const position = tabPositionRefs.current[id];\n if (!position) return true;\n return (\n Math.abs(position.get() - drag.slotLefts[index]) < 0.5 &&\n Math.abs(position.getVelocity()) < 10\n );\n });\n\n if (settled || performance.now() - startedAt > 500) {\n resolve();\n return;\n }\n requestAnimationFrame(check);\n };\n check();\n });\n }\n\n if (dragAnimationRef.current !== controls) return;\n if (drag.id === activeId) {\n surfaceLeft.set(targetLeft);\n } else if (activeId) {\n const activePosition = tabPositionRefs.current[activeId];\n if (activePosition) surfaceLeft.set(activePosition.get());\n }\n tabPositionRefs.current[drag.id]?.jump(targetLeft);\n dragAnimationRef.current = null;\n dragRef.current = null;\n commitOrder(next, !sameOrder(drag.startOrder, next));\n setDraggingId(null);\n setDragTargetIndex(-1);\n });\n },\n [activeId, commitOrder, dragLeft, reduce, surfaceLeft],\n );\n\n useEffect(() => {\n const finishFromWindow = (event: PointerEvent) => {\n finishDrag(event.pointerId);\n };\n window.addEventListener(\"pointerup\", finishFromWindow, true);\n window.addEventListener(\"pointercancel\", finishFromWindow, true);\n return () => {\n window.removeEventListener(\"pointerup\", finishFromWindow, true);\n window.removeEventListener(\"pointercancel\", finishFromWindow, true);\n };\n }, [finishDrag]);\n\n const moveBy = useCallback(\n (id: string, direction: -1 | 1) => {\n const current = orderRef.current;\n const index = current.indexOf(id);\n const nextIndex = index + direction;\n if (index < 0 || nextIndex < 0 || nextIndex >= current.length || itemMap.get(id)?.disabled) {\n return;\n }\n commitOrder(moveItem(current, index, nextIndex), true);\n },\n [commitOrder, itemMap],\n );\n\n const handleTabKeyDown = useCallback(\n (id: string, event: React.KeyboardEvent<HTMLButtonElement>) => {\n const index = orderRef.current.indexOf(id);\n if (index < 0) return;\n\n if (event.altKey && (event.key === \"ArrowLeft\" || event.key === \"ArrowRight\")) {\n event.preventDefault();\n moveBy(id, event.key === \"ArrowLeft\" ? -1 : 1);\n return;\n }\n if (event.key !== \"ArrowLeft\" && event.key !== \"ArrowRight\") return;\n\n event.preventDefault();\n const direction = event.key === \"ArrowLeft\" ? -1 : 1;\n const nextIndex = (index + direction + orderRef.current.length) % orderRef.current.length;\n const nextId = orderRef.current[nextIndex];\n setActive(nextId);\n requestAnimationFrame(() => tabButtonRefs.current[nextId]?.focus());\n },\n [moveBy, setActive],\n );\n\n if (!orderedItems.length) return null;\n\n return (\n <div\n ref={rootRef}\n className={cn(\n \"relative isolate min-w-0 overflow-hidden rounded-[2rem] bg-[#292929] text-white\",\n classNames?.root,\n className,\n )}\n >\n <div className=\"relative h-20\">\n <div\n ref={railRef}\n role=\"tablist\"\n aria-label={ariaLabel}\n aria-orientation=\"horizontal\"\n className={cn(\"relative z-30 flex h-full gap-3 md:gap-4\", classNames?.rail)}\n >\n {orderedItems.map((item, index) => {\n const isActive = item.id === activeId;\n const isDragging = item.id === draggingId;\n const visualIndex = visualIndexFor(index);\n const targetLeft = slotLefts[visualIndex] ?? SURFACE_INSET;\n const tabId = `${uid}-tab-${safeId(item.id)}`;\n\n return (\n <SpringTab\n key={item.id}\n id={item.id}\n targetLeft={targetLeft}\n dragging={isDragging}\n dragLeft={dragLeft}\n surfaceLeft={surfaceLeft}\n reduce={reduce}\n active={isActive}\n anyDragging={Boolean(draggingId)}\n surfaceHost={rootRef.current}\n surfaceWidth={surfaceWidth}\n surfaceClassName={classNames?.activeTab}\n zIndex={isDragging ? 30 : isActive ? 20 : 1}\n className={cn(\n \"group absolute top-0 left-0 flex touch-pan-y select-none items-stretch\",\n item.disabled && \"cursor-not-allowed\",\n isDragging ? \"cursor-grabbing\" : \"cursor-grab\",\n )}\n registerPosition={registerPosition}\n onPointerDown={(event) => startDrag(item.id, event)}\n onPointerMove={moveDrag}\n onPointerUp={(event) => finishDrag(event.pointerId)}\n onPointerCancel={(event) => finishDrag(event.pointerId)}\n onLostPointerCapture={(event) => finishDrag(event.pointerId)}\n >\n <div\n style={{\n width: TAB_WIDTH,\n height: TAB_HEIGHT,\n marginTop: TAB_TOP,\n }}\n className=\"relative flex items-stretch\"\n >\n {!isActive ? (\n <span\n aria-hidden\n className={cn(\n \"absolute inset-x-0 top-0 bottom-2 rounded-[1.25rem] transition-colors duration-200\",\n isDragging ? \"bg-[#3a3a3a]\" : \"bg-transparent group-hover:bg-white/[0.06]\",\n )}\n />\n ) : null}\n\n <button\n ref={(node) => {\n tabButtonRefs.current[item.id] = node;\n }}\n id={tabId}\n type=\"button\"\n role=\"tab\"\n aria-selected={isActive}\n aria-controls={`${uid}-panel`}\n aria-disabled={item.disabled || undefined}\n tabIndex={isActive ? 0 : -1}\n disabled={item.disabled}\n onClick={() => {\n const drag = dragRef.current;\n if (drag?.id === item.id && drag.moved) return;\n setActive(item.id);\n }}\n onKeyDown={(event) => handleTabKeyDown(item.id, event)}\n className={cn(\n \"group relative z-10 flex h-full w-full min-w-0 items-center gap-2 overflow-hidden rounded-t-[1.5rem] px-3 text-left outline-none transition-colors\",\n isActive ? \"text-[#181818]\" : \"pb-2 text-white/70 hover:text-white\",\n classNames?.tab,\n )}\n >\n <span\n aria-hidden\n className={cn(\n \"pointer-events-none absolute inset-x-1 top-1 opacity-0 transition-opacity group-focus-visible:opacity-100\",\n isActive\n ? \"bottom-0 rounded-t-[1.25rem] border-black/20 border-x-2 border-t-2\"\n : \"bottom-2 rounded-[1rem] border-2 border-white/60\",\n )}\n />\n {item.icon ? (\n <span\n aria-hidden\n className={cn(\"grid size-8 shrink-0 place-items-center\", classNames?.icon)}\n >\n {item.icon}\n </span>\n ) : null}\n <span\n className={cn(\n \"min-w-0 truncate whitespace-nowrap font-medium text-base leading-none tracking-[-0.025em]\",\n classNames?.label,\n )}\n >\n {item.label}\n </span>\n </button>\n\n {onClose ? (\n <button\n type=\"button\"\n aria-label={`Close ${item.label}`}\n onPointerDown={(event) => event.stopPropagation()}\n onClick={(event) => {\n event.stopPropagation();\n onClose(item.id);\n }}\n className={cn(\n \"absolute top-1/2 right-2 z-20 grid size-6 -translate-y-1/2 place-items-center rounded-full text-[#9aa0a8] transition-colors hover:bg-black/[0.06] hover:text-[#4b5563] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-current\",\n !isActive &&\n \"top-[calc(50%-4px)] text-white/45 hover:bg-white/[0.08] hover:text-white/80\",\n classNames?.close,\n )}\n >\n <X aria-hidden className=\"size-3.5 stroke-[1.5]\" />\n </button>\n ) : null}\n </div>\n </SpringTab>\n );\n })}\n </div>\n </div>\n\n <div\n id={`${uid}-panel`}\n role=\"tabpanel\"\n aria-labelledby={`${uid}-tab-${safeId(activeId ?? \"empty\")}`}\n className={cn(\n \"relative z-20 mx-4 min-h-64 overflow-hidden rounded-[1.75rem] bg-[#fafaf8] text-[#181818]\",\n classNames?.content,\n )}\n >\n <AnimatePresence mode=\"popLayout\" initial={false}>\n {activeItem ? (\n <motion.div\n key={activeItem.id}\n initial={reduce ? { opacity: 0 } : { opacity: 0, y: 8, filter: \"blur(6px)\" }}\n animate={{ opacity: 1, y: 0, filter: \"blur(0px)\" }}\n exit={\n reduce\n ? {\n opacity: 0,\n transition: { duration: 0.08, ease: EASE_OUT },\n }\n : {\n opacity: 0,\n y: -5,\n filter: \"blur(5px)\",\n transition: { duration: 0.12, ease: EASE_OUT },\n }\n }\n transition={reduce ? { duration: 0.12, ease: EASE_OUT } : SPRING_PRESS}\n className=\"min-h-64\"\n >\n {activeItem.content}\n </motion.div>\n ) : null}\n </AnimatePresence>\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;AAkGA,MAAM,iBAAiB;AACvB,MAAM,YAAY;AAClB,MAAM,aAAa;AACnB,MAAM,UAAU;AAChB,MAAM,aAAa;AACnB,MAAM,cAAc;AACpB,MAAM,gBAAgB;AACtB,MAAM,cAAc;AACpB,MAAM,eAAe;AAErB,SAAS,UAAU,GAAa,GAAa;CAC3C,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,IAAI,UAAU,OAAO,EAAE,MAAM;AACxE;AAEA,SAAS,OAAO,OAAe;CAC7B,OAAO,MAAM,QAAQ,mBAAmB,GAAG;AAC7C;AAEA,SAAS,SAAS,OAAiB,MAAc,IAAY;CAC3D,IAAI,SAAS,IAAI,OAAO,MAAM,MAAM;CACpC,MAAM,OAAO,MAAM,MAAM;CACzB,MAAM,CAAC,QAAQ,KAAK,OAAO,MAAM,CAAC;CAClC,KAAK,OAAO,IAAI,GAAG,IAAI;CACvB,OAAO;AACT;AAEA,SAAS,cAAc,SAAiB,cAAsB;CAC5D,MAAM,YAAY;CAClB,MAAM,aAAa,eAAe;CAClC,MAAM,OAAO,KAAK,IAAI,WAAW,KAAK,IAAI,aAAa,WAAW,OAAO,CAAC;CAC1E,MAAM,QAAQ,OAAO;CACrB,MAAM,MAAM;CACZ,MAAM,SAAS;CACf,MAAM,WAAW,KAAK,IAAI,WAAW,OAAO,WAAW;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GAAG;MAAG,QAAQ;KAAY;KAC3E,SAAS;MAAE,SAAS;MAAG,GAAG;MAAG,QAAQ;KAAY;KACjD,MACE,SACI;MACE,SAAS;MACT,YAAY;OAAE,UAAU;OAAM,MAAM;MAAS;KAC/C,IACA;MACE,SAAS;MACT,GAAG;MACH,QAAQ;MACR,YAAY;OAAE,UAAU;OAAM,MAAM;MAAS;KAC/C;KAEN,YAAY,SAAS;MAAE,UAAU;MAAM,MAAM;KAAS,IAAI;KAC1D,WAAU;KAET,UAAA,WAAW;IACF,GApBL,WAAW,EAoBN,IACV;GACW,CAAA;EACd,CAAA,CACF;;AAET"}
|
|
1
|
+
{"version":3,"file":"morphing-tabs.js","names":["animateValue"],"sources":["../../../src/components/motion/morphing-tabs.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type ReactNode,\n type PointerEvent as ReactPointerEvent,\n useCallback,\n useEffect,\n useId,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { X } from \"lucide-react\";\nimport {\n AnimatePresence,\n animate as animateValue,\n type MotionValue,\n motion,\n useMotionValue,\n useReducedMotion,\n useSpring,\n useTransform,\n} from \"motion/react\";\nimport { createPortal } from \"react-dom\";\n\nimport { cn } from \"@kumix/utils\";\nimport { EASE_OUT, SPRING_GLIDE, SPRING_PRESS } from \"../../lib/ease\";\nimport { capturePointer, TOUCH_GESTURE_CLASS } from \"../../lib/touch\";\n\nexport type MorphingTabsItem = {\n id: string;\n label: string;\n icon?: ReactNode;\n content: ReactNode;\n disabled?: boolean;\n};\n\nexport type MorphingTabsClassNames = {\n root?: string;\n rail?: string;\n tab?: string;\n activeTab?: string;\n icon?: string;\n label?: string;\n close?: string;\n content?: string;\n};\n\nexport interface MorphingTabsProps {\n items: MorphingTabsItem[];\n value?: string | null;\n defaultValue?: string | null;\n onValueChange?: (id: string | null) => void;\n /** Called once after a pointer drag or keyboard reorder completes. */\n onOrderChange?: (ids: string[]) => void;\n /** Enables the close affordance on every tab when provided. */\n onClose?: (id: string) => void;\n ariaLabel?: string;\n className?: string;\n classNames?: MorphingTabsClassNames;\n}\n\ntype DragSession = {\n id: string;\n pointerId: number;\n originX: number;\n startLeft: number;\n startIndex: number;\n targetIndex: number;\n moved: boolean;\n finishing: boolean;\n startOrder: string[];\n slotLefts: number[];\n};\n\ntype SpringTabProps = {\n id: string;\n targetLeft: number;\n dragging: boolean;\n dragLeft: MotionValue<number>;\n surfaceLeft: MotionValue<number>;\n reduce: boolean;\n active: boolean;\n anyDragging: boolean;\n surfaceHost: HTMLDivElement | null;\n surfaceWidth: number;\n tabWidth: number;\n surfaceClassName?: string;\n zIndex: number;\n className: string;\n children: ReactNode;\n registerPosition: (id: string, position: MotionValue<number> | null) => void;\n onPointerDown: (event: ReactPointerEvent<HTMLDivElement>) => void;\n onPointerMove: (event: ReactPointerEvent<HTMLDivElement>) => void;\n onPointerUp: (event: ReactPointerEvent<HTMLDivElement>) => void;\n onPointerCancel: (event: ReactPointerEvent<HTMLDivElement>) => void;\n onLostPointerCapture: (event: ReactPointerEvent<HTMLDivElement>) => void;\n};\n\nconst DRAG_THRESHOLD = 5;\n// The design width of a tab, and the narrowest it may shrink to before the\n// label stops reading. See `tabWidth` in MorphingTabs.\nconst MAX_TAB_WIDTH = 176;\nconst MIN_TAB_WIDTH = 96;\nconst TAB_HEIGHT = 56;\nconst TAB_TOP = 24;\nconst TAB_RADIUS = 24;\nconst RAIL_HEIGHT = 80;\nconst SURFACE_INSET = 16;\nconst LIQUID_JOIN = 24;\nconst PANEL_RADIUS = 28;\n\nfunction sameOrder(a: string[], b: string[]) {\n return a.length === b.length && a.every((id, index) => id === b[index]);\n}\n\nfunction safeId(value: string) {\n return value.replace(/[^a-zA-Z0-9_-]/g, \"-\");\n}\n\nfunction moveItem(order: string[], from: number, to: number) {\n if (from === to) return order.slice();\n const next = order.slice();\n const [item] = next.splice(from, 1);\n next.splice(to, 0, item);\n return next;\n}\n\nfunction liquidTabPath(tabLeft: number, surfaceWidth: number, tabWidth: number) {\n const panelLeft = SURFACE_INSET;\n const panelRight = surfaceWidth - SURFACE_INSET;\n const left = Math.max(panelLeft, Math.min(panelRight - tabWidth, tabLeft));\n const right = left + tabWidth;\n const top = RAIL_HEIGHT - TAB_HEIGHT;\n const bottom = RAIL_HEIGHT;\n const leftJoin = Math.max(panelLeft, left - LIQUID_JOIN);\n const rightJoin = Math.min(panelRight, right + LIQUID_JOIN);\n const leftDepth = Math.min(LIQUID_JOIN, left - leftJoin);\n const rightDepth = Math.min(LIQUID_JOIN, rightJoin - right);\n const leftControl = leftDepth * 0.55;\n const rightControl = rightDepth * 0.55;\n const leftPanelRadius = Math.min(PANEL_RADIUS, leftJoin - panelLeft);\n const rightPanelRadius = Math.min(PANEL_RADIUS, panelRight - rightJoin);\n\n return [\n `M${panelLeft} ${bottom + PANEL_RADIUS}`,\n `V${bottom + leftPanelRadius}`,\n `Q${panelLeft} ${bottom} ${panelLeft + leftPanelRadius} ${bottom}`,\n `H${leftJoin}`,\n `C${leftJoin + leftControl} ${bottom} ${left} ${bottom - leftDepth + leftControl} ${left} ${bottom - leftDepth}`,\n `V${top + TAB_RADIUS}`,\n `Q${left} ${top} ${left + TAB_RADIUS} ${top}`,\n `H${right - TAB_RADIUS}`,\n `Q${right} ${top} ${right} ${top + TAB_RADIUS}`,\n `V${bottom - rightDepth}`,\n `C${right} ${bottom - rightDepth + rightControl} ${rightJoin - rightControl} ${bottom} ${rightJoin} ${bottom}`,\n `H${panelRight - rightPanelRadius}`,\n `Q${panelRight} ${bottom} ${panelRight} ${bottom + rightPanelRadius}`,\n `V${bottom + PANEL_RADIUS}`,\n \"Z\",\n ].join(\" \");\n}\n\nfunction SpringTab({\n id,\n targetLeft,\n dragging,\n dragLeft,\n surfaceLeft,\n reduce,\n active,\n anyDragging,\n surfaceHost,\n surfaceWidth,\n tabWidth,\n surfaceClassName,\n zIndex,\n className,\n children,\n registerPosition,\n onPointerDown,\n onPointerMove,\n onPointerUp,\n onPointerCancel,\n onLostPointerCapture,\n}: SpringTabProps) {\n const target = useMotionValue(targetLeft);\n const position = useSpring(target, SPRING_GLIDE);\n const settledTransform = useTransform(\n reduce ? target : position,\n (left) => `translate3d(${left}px, 0, 0)`,\n );\n const draggedTransform = useTransform(dragLeft, (left) => `translate3d(${left}px, 0, 0)`);\n\n useLayoutEffect(() => {\n target.set(targetLeft);\n if (reduce) position.jump(targetLeft);\n }, [position, reduce, target, targetLeft]);\n\n useLayoutEffect(() => {\n registerPosition(id, position);\n return () => registerPosition(id, null);\n }, [id, position, registerPosition]);\n\n const liquidDriver = anyDragging ? (dragging ? dragLeft : position) : surfaceLeft;\n\n return (\n <>\n {active && surfaceHost && surfaceWidth > SURFACE_INSET * 2\n ? createPortal(\n <svg\n aria-hidden=\"true\"\n focusable=\"false\"\n viewBox={`0 0 ${surfaceWidth} ${RAIL_HEIGHT + PANEL_RADIUS}`}\n preserveAspectRatio=\"none\"\n className={cn(\n \"pointer-events-none absolute inset-x-0 top-0 h-[108px] w-full text-[#fafaf8]\",\n dragging ? \"z-20\" : \"z-0\",\n surfaceClassName,\n )}\n >\n <LiquidSurfacePath\n key={anyDragging ? (dragging ? \"dragged\" : \"displaced\") : \"idle\"}\n left={liquidDriver}\n surfaceWidth={surfaceWidth}\n tabWidth={tabWidth}\n />\n </svg>,\n surfaceHost,\n )\n : null}\n <motion.div\n style={{\n zIndex,\n transform: dragging ? draggedTransform : settledTransform,\n }}\n className={className}\n onPointerDown={onPointerDown}\n onPointerMove={onPointerMove}\n onPointerUp={onPointerUp}\n onPointerCancel={onPointerCancel}\n onLostPointerCapture={onLostPointerCapture}\n >\n {children}\n </motion.div>\n </>\n );\n}\n\nfunction LiquidSurfacePath({\n left,\n surfaceWidth,\n tabWidth,\n}: {\n left: MotionValue<number>;\n surfaceWidth: number;\n tabWidth: number;\n}) {\n const path = useTransform(left, (value) => liquidTabPath(value, surfaceWidth, tabWidth));\n return <motion.path d={path} fill=\"currentColor\" />;\n}\n\nexport function MorphingTabs({\n items,\n value,\n defaultValue,\n onValueChange,\n onOrderChange,\n onClose,\n ariaLabel = \"Tabs\",\n className,\n classNames,\n}: MorphingTabsProps) {\n const reduce = Boolean(useReducedMotion());\n const uid = useId();\n const itemIds = useMemo(() => items.map((item) => item.id), [items]);\n const itemMap = useMemo(() => new Map(items.map((item) => [item.id, item])), [items]);\n const [order, setOrder] = useState(itemIds);\n const orderRef = useRef(order);\n orderRef.current = order;\n\n const [internalValue, setInternalValue] = useState<string | null>(\n defaultValue ?? itemIds[0] ?? null,\n );\n const controlled = value !== undefined;\n const currentValue = controlled ? (value ?? null) : internalValue;\n\n const rootRef = useRef<HTMLDivElement | null>(null);\n const railRef = useRef<HTMLDivElement | null>(null);\n const tabButtonRefs = useRef<Record<string, HTMLButtonElement | null>>({});\n const tabPositionRefs = useRef<Record<string, MotionValue<number> | null>>({});\n const dragRef = useRef<DragSession | null>(null);\n const dragAnimationRef = useRef<ReturnType<typeof animateValue> | null>(null);\n const surfaceAnimationRef = useRef<ReturnType<typeof animateValue> | null>(null);\n const [surfaceWidth, setSurfaceWidth] = useState(0);\n const [tabGap, setTabGap] = useState(12);\n const [draggingId, setDraggingId] = useState<string | null>(null);\n const [dragTargetIndex, setDragTargetIndex] = useState(-1);\n const dragLeft = useMotionValue(SURFACE_INSET);\n const surfaceLeft = useMotionValue(SURFACE_INSET);\n\n useEffect(() => {\n setOrder((current) => {\n const available = new Set(itemIds);\n const retained = current.filter((id) => available.has(id));\n const retainedSet = new Set(retained);\n const added = itemIds.filter((id) => !retainedSet.has(id));\n const next = [...retained, ...added];\n return sameOrder(current, next) ? current : next;\n });\n }, [itemIds]);\n\n const orderedItems = useMemo(\n () =>\n order.flatMap((id) => {\n const item = itemMap.get(id);\n return item ? [item] : [];\n }),\n [itemMap, order],\n );\n\n const firstEnabledItem = orderedItems.find((item) => !item.disabled) ?? orderedItems[0] ?? null;\n const activeItem =\n currentValue && itemMap.has(currentValue)\n ? (itemMap.get(currentValue) ?? null)\n : firstEnabledItem;\n const activeId = activeItem?.id ?? null;\n\n // The rail cannot scroll: the liquid surface is one continuous shape spanning\n // the panel, so its notch has to stay over the tab that cut it. Slots narrow\n // to fit the panel instead, in that order of sacrifice:\n // 1. the design width, down to a floor where a truncated label still reads;\n // 2. the gap between slots, so the floor survives one panel narrower;\n // 3. the floor itself — a cramped tab is still tappable, a clipped one is\n // not reachable at all.\n // Every tier fits inside the panel by construction, so no tab is ever cut off\n // and the notch never has to be clamped away from the tab that cut it.\n const { tabWidth, slotGap } = useMemo(() => {\n const count = order.length;\n if (!surfaceWidth || count === 0) {\n return { tabWidth: MAX_TAB_WIDTH, slotGap: tabGap };\n }\n const inner = surfaceWidth - SURFACE_INSET * 2;\n const widthAt = (gap: number) => Math.floor((inner - gap * (count - 1)) / count);\n\n if (widthAt(tabGap) >= MIN_TAB_WIDTH) {\n return {\n tabWidth: Math.min(MAX_TAB_WIDTH, widthAt(tabGap)),\n slotGap: tabGap,\n };\n }\n if (count > 1 && widthAt(0) >= MIN_TAB_WIDTH) {\n const gap = Math.floor((inner - MIN_TAB_WIDTH * count) / (count - 1));\n return { tabWidth: MIN_TAB_WIDTH, slotGap: Math.max(0, gap) };\n }\n return { tabWidth: Math.max(0, widthAt(0)), slotGap: 0 };\n }, [order.length, surfaceWidth, tabGap]);\n\n const slotLefts = useMemo(\n () => order.map((_, index) => SURFACE_INSET + index * (tabWidth + slotGap)),\n [order, slotGap, tabWidth],\n );\n\n const dragStartIndex = draggingId ? order.indexOf(draggingId) : -1;\n\n const visualIndexFor = useCallback(\n (index: number) => {\n if (dragStartIndex < 0 || dragTargetIndex < 0) return index;\n if (index === dragStartIndex) return dragTargetIndex;\n\n if (dragTargetIndex > dragStartIndex && index > dragStartIndex && index <= dragTargetIndex) {\n return index - 1;\n }\n if (dragTargetIndex < dragStartIndex && index >= dragTargetIndex && index < dragStartIndex) {\n return index + 1;\n }\n return index;\n },\n [dragStartIndex, dragTargetIndex],\n );\n\n useLayoutEffect(() => {\n const root = rootRef.current;\n const rail = railRef.current;\n if (!root || !rail) return;\n\n const measure = () => {\n setSurfaceWidth(root.clientWidth);\n const nextGap = Number.parseFloat(getComputedStyle(rail).columnGap);\n if (Number.isFinite(nextGap)) setTabGap(nextGap);\n };\n\n measure();\n const observer = new ResizeObserver(measure);\n observer.observe(root);\n return () => observer.disconnect();\n }, []);\n\n const setActive = useCallback(\n (id: string | null) => {\n if (id && itemMap.get(id)?.disabled) return;\n if (!controlled) setInternalValue(id);\n onValueChange?.(id);\n },\n [controlled, itemMap, onValueChange],\n );\n\n useEffect(() => {\n if (currentValue && itemMap.has(currentValue)) return;\n if (firstEnabledItem && firstEnabledItem.id !== currentValue) {\n setActive(firstEnabledItem.id);\n }\n }, [currentValue, firstEnabledItem, itemMap, setActive]);\n\n const activeOrderIndex = activeId ? order.indexOf(activeId) : -1;\n const activeVisualIndex = activeOrderIndex < 0 ? -1 : visualIndexFor(activeOrderIndex);\n\n useLayoutEffect(() => {\n if (\n !activeId ||\n activeVisualIndex < 0 ||\n activeId === draggingId ||\n !slotLefts[activeVisualIndex]\n ) {\n return;\n }\n\n surfaceAnimationRef.current?.stop();\n\n if (draggingId) return;\n\n surfaceAnimationRef.current = animateValue(\n surfaceLeft,\n slotLefts[activeVisualIndex],\n reduce ? { duration: 0 } : SPRING_GLIDE,\n );\n }, [activeId, activeVisualIndex, draggingId, reduce, slotLefts, surfaceLeft]);\n\n const commitOrder = useCallback(\n (next: string[], notify: boolean) => {\n orderRef.current = next;\n setOrder((current) => (sameOrder(current, next) ? current : next));\n if (notify) onOrderChange?.(next);\n },\n [onOrderChange],\n );\n\n const registerPosition = useCallback((id: string, position: MotionValue<number> | null) => {\n tabPositionRefs.current[id] = position;\n }, []);\n\n const startDrag = useCallback(\n (id: string, event: ReactPointerEvent<HTMLDivElement>) => {\n if (event.button !== 0 || itemMap.get(id)?.disabled || dragRef.current) {\n return;\n }\n\n const startIndex = orderRef.current.indexOf(id);\n if (startIndex < 0) return;\n const capturedSlots = orderRef.current.map(\n (_, index) => SURFACE_INSET + index * (tabWidth + slotGap),\n );\n const startLeft = capturedSlots[startIndex];\n\n dragAnimationRef.current?.stop();\n dragAnimationRef.current = null;\n dragLeft.set(startLeft);\n dragRef.current = {\n id,\n pointerId: event.pointerId,\n originX: event.clientX,\n startLeft,\n startIndex,\n targetIndex: startIndex,\n moved: false,\n finishing: false,\n startOrder: orderRef.current.slice(),\n slotLefts: capturedSlots,\n };\n },\n [dragLeft, itemMap, slotGap, tabWidth],\n );\n\n const moveDrag = useCallback(\n (event: ReactPointerEvent<HTMLDivElement>) => {\n const drag = dragRef.current;\n if (!drag || drag.finishing || drag.pointerId !== event.pointerId) return;\n\n const delta = event.clientX - drag.originX;\n if (!drag.moved && Math.abs(delta) < DRAG_THRESHOLD) return;\n event.preventDefault();\n\n if (!drag.moved) {\n drag.moved = true;\n capturePointer(event.currentTarget, event.pointerId);\n if (drag.id === activeId) {\n surfaceAnimationRef.current?.stop();\n surfaceLeft.set(drag.startLeft);\n }\n setDraggingId(drag.id);\n setDragTargetIndex(drag.startIndex);\n }\n\n const minLeft = drag.slotLefts[0];\n const maxLeft = drag.slotLefts[drag.slotLefts.length - 1];\n const visualLeft = Math.max(minLeft, Math.min(maxLeft, drag.startLeft + delta));\n let targetIndex = drag.startIndex;\n\n if (visualLeft >= drag.startLeft) {\n for (let index = drag.startIndex + 1; index < drag.slotLefts.length; index += 1) {\n if (visualLeft + tabWidth / 2 >= drag.slotLefts[index]) {\n targetIndex = index;\n }\n }\n } else {\n for (let index = drag.startIndex - 1; index >= 0; index -= 1) {\n if (visualLeft <= drag.slotLefts[index] + tabWidth / 2) {\n targetIndex = index;\n }\n }\n }\n\n dragLeft.set(visualLeft);\n if (targetIndex !== drag.targetIndex) {\n drag.targetIndex = targetIndex;\n setDragTargetIndex(targetIndex);\n }\n },\n [activeId, dragLeft, surfaceLeft, tabWidth],\n );\n\n const finishDrag = useCallback(\n (pointerId: number) => {\n const drag = dragRef.current;\n if (!drag || drag.pointerId !== pointerId || drag.finishing) return;\n\n if (!drag.moved) {\n dragRef.current = null;\n return;\n }\n\n drag.finishing = true;\n const targetLeft = drag.slotLefts[drag.targetIndex];\n const controls = animateValue(dragLeft, targetLeft, reduce ? { duration: 0 } : SPRING_GLIDE);\n dragAnimationRef.current = controls;\n\n controls.then(async () => {\n if (dragAnimationRef.current !== controls) return;\n const next = moveItem(drag.startOrder, drag.startIndex, drag.targetIndex);\n\n if (!reduce) {\n await new Promise<void>((resolve) => {\n const startedAt = performance.now();\n const check = () => {\n const settled = next.every((id, index) => {\n if (id === drag.id) return true;\n const position = tabPositionRefs.current[id];\n if (!position) return true;\n return (\n Math.abs(position.get() - drag.slotLefts[index]) < 0.5 &&\n Math.abs(position.getVelocity()) < 10\n );\n });\n\n if (settled || performance.now() - startedAt > 500) {\n resolve();\n return;\n }\n requestAnimationFrame(check);\n };\n check();\n });\n }\n\n if (dragAnimationRef.current !== controls) return;\n if (drag.id === activeId) {\n surfaceLeft.set(targetLeft);\n } else if (activeId) {\n const activePosition = tabPositionRefs.current[activeId];\n if (activePosition) surfaceLeft.set(activePosition.get());\n }\n tabPositionRefs.current[drag.id]?.jump(targetLeft);\n dragAnimationRef.current = null;\n dragRef.current = null;\n commitOrder(next, !sameOrder(drag.startOrder, next));\n setDraggingId(null);\n setDragTargetIndex(-1);\n });\n },\n [activeId, commitOrder, dragLeft, reduce, surfaceLeft],\n );\n\n useEffect(() => {\n const finishFromWindow = (event: PointerEvent) => {\n finishDrag(event.pointerId);\n };\n window.addEventListener(\"pointerup\", finishFromWindow, true);\n window.addEventListener(\"pointercancel\", finishFromWindow, true);\n return () => {\n window.removeEventListener(\"pointerup\", finishFromWindow, true);\n window.removeEventListener(\"pointercancel\", finishFromWindow, true);\n };\n }, [finishDrag]);\n\n const moveBy = useCallback(\n (id: string, direction: -1 | 1) => {\n const current = orderRef.current;\n const index = current.indexOf(id);\n const nextIndex = index + direction;\n if (index < 0 || nextIndex < 0 || nextIndex >= current.length || itemMap.get(id)?.disabled) {\n return;\n }\n commitOrder(moveItem(current, index, nextIndex), true);\n },\n [commitOrder, itemMap],\n );\n\n const handleTabKeyDown = useCallback(\n (id: string, event: React.KeyboardEvent<HTMLButtonElement>) => {\n const index = orderRef.current.indexOf(id);\n if (index < 0) return;\n\n if (event.altKey && (event.key === \"ArrowLeft\" || event.key === \"ArrowRight\")) {\n event.preventDefault();\n moveBy(id, event.key === \"ArrowLeft\" ? -1 : 1);\n return;\n }\n if (event.key !== \"ArrowLeft\" && event.key !== \"ArrowRight\") return;\n\n event.preventDefault();\n const direction = event.key === \"ArrowLeft\" ? -1 : 1;\n const nextIndex = (index + direction + orderRef.current.length) % orderRef.current.length;\n const nextId = orderRef.current[nextIndex];\n setActive(nextId);\n requestAnimationFrame(() => tabButtonRefs.current[nextId]?.focus());\n },\n [moveBy, setActive],\n );\n\n if (!orderedItems.length) return null;\n\n return (\n <div\n ref={rootRef}\n className={cn(\n \"relative isolate min-w-0 overflow-hidden rounded-[2rem] bg-[#292929] text-white\",\n classNames?.root,\n className,\n )}\n >\n <div className=\"relative h-20\">\n <div\n ref={railRef}\n role=\"tablist\"\n aria-label={ariaLabel}\n aria-orientation=\"horizontal\"\n className={cn(\"relative z-30 flex h-full gap-3 md:gap-4\", classNames?.rail)}\n >\n {orderedItems.map((item, index) => {\n const isActive = item.id === activeId;\n const isDragging = item.id === draggingId;\n const visualIndex = visualIndexFor(index);\n const targetLeft = slotLefts[visualIndex] ?? SURFACE_INSET;\n const tabId = `${uid}-tab-${safeId(item.id)}`;\n\n return (\n <SpringTab\n key={item.id}\n id={item.id}\n targetLeft={targetLeft}\n dragging={isDragging}\n dragLeft={dragLeft}\n surfaceLeft={surfaceLeft}\n reduce={reduce}\n active={isActive}\n anyDragging={Boolean(draggingId)}\n surfaceHost={rootRef.current}\n surfaceWidth={surfaceWidth}\n tabWidth={tabWidth}\n surfaceClassName={classNames?.activeTab}\n zIndex={isDragging ? 30 : isActive ? 20 : 1}\n className={cn(\n // The drag is ours end to end, so iPadOS must not answer the\n // press with its callout or a native drag of the label.\n \"group absolute top-0 left-0 flex touch-pan-y items-stretch\",\n TOUCH_GESTURE_CLASS,\n item.disabled && \"cursor-not-allowed\",\n isDragging ? \"cursor-grabbing\" : \"cursor-grab\",\n )}\n registerPosition={registerPosition}\n onPointerDown={(event) => startDrag(item.id, event)}\n onPointerMove={moveDrag}\n onPointerUp={(event) => finishDrag(event.pointerId)}\n onPointerCancel={(event) => finishDrag(event.pointerId)}\n // A touch is implicitly captured by whatever it landed on —\n // here the label inside the tab — so the moment the drag takes\n // the capture for the tab itself, that child *loses* it, and\n // the notification bubbles straight back up to this handler.\n // Ending the drag on it kills the gesture on the frame it\n // starts. Only the tab losing its own capture means the\n // platform took the pointer away. A mouse has no implicit\n // capture, which is why this only ever bit on a real finger.\n onLostPointerCapture={(event) => {\n if (event.target !== event.currentTarget) return;\n finishDrag(event.pointerId);\n }}\n >\n <div\n style={{\n width: tabWidth,\n height: TAB_HEIGHT,\n marginTop: TAB_TOP,\n }}\n className=\"relative flex items-stretch\"\n >\n {!isActive ? (\n <span\n aria-hidden\n className={cn(\n \"absolute inset-x-0 top-0 bottom-2 rounded-[1.25rem] transition-colors duration-200\",\n isDragging ? \"bg-[#3a3a3a]\" : \"bg-transparent group-hover:bg-white/[0.06]\",\n )}\n />\n ) : null}\n\n <button\n ref={(node) => {\n tabButtonRefs.current[item.id] = node;\n }}\n id={tabId}\n type=\"button\"\n role=\"tab\"\n aria-selected={isActive}\n aria-controls={`${uid}-panel`}\n aria-disabled={item.disabled || undefined}\n tabIndex={isActive ? 0 : -1}\n disabled={item.disabled}\n onClick={() => {\n const drag = dragRef.current;\n if (drag?.id === item.id && drag.moved) return;\n setActive(item.id);\n }}\n onKeyDown={(event) => handleTabKeyDown(item.id, event)}\n className={cn(\n \"group relative z-10 flex h-full w-full min-w-0 items-center gap-2 overflow-hidden rounded-t-[1.5rem] px-3 text-left outline-none transition-colors\",\n isActive ? \"text-[#181818]\" : \"pb-2 text-white/70 hover:text-white\",\n classNames?.tab,\n )}\n >\n <span\n aria-hidden\n className={cn(\n \"pointer-events-none absolute inset-x-1 top-1 opacity-0 transition-opacity group-focus-visible:opacity-100\",\n isActive\n ? \"bottom-0 rounded-t-[1.25rem] border-black/20 border-x-2 border-t-2\"\n : \"bottom-2 rounded-[1rem] border-2 border-white/60\",\n )}\n />\n {item.icon ? (\n <span\n aria-hidden\n className={cn(\"grid size-8 shrink-0 place-items-center\", classNames?.icon)}\n >\n {item.icon}\n </span>\n ) : null}\n <span\n className={cn(\n \"min-w-0 truncate whitespace-nowrap font-medium text-base leading-none tracking-[-0.025em]\",\n classNames?.label,\n )}\n >\n {item.label}\n </span>\n </button>\n\n {onClose ? (\n <button\n type=\"button\"\n aria-label={`Close ${item.label}`}\n onPointerDown={(event) => event.stopPropagation()}\n onClick={(event) => {\n event.stopPropagation();\n onClose(item.id);\n }}\n className={cn(\n \"absolute top-1/2 right-2 z-20 grid size-6 -translate-y-1/2 place-items-center rounded-full text-[#9aa0a8] transition-colors hover:bg-black/[0.06] hover:text-[#4b5563] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-current\",\n !isActive &&\n \"top-[calc(50%-4px)] text-white/45 hover:bg-white/[0.08] hover:text-white/80\",\n classNames?.close,\n )}\n >\n <X aria-hidden className=\"size-3.5 stroke-[1.5]\" />\n </button>\n ) : null}\n </div>\n </SpringTab>\n );\n })}\n </div>\n </div>\n\n <div\n id={`${uid}-panel`}\n role=\"tabpanel\"\n aria-labelledby={`${uid}-tab-${safeId(activeId ?? \"empty\")}`}\n className={cn(\n \"relative z-20 mx-4 min-h-64 overflow-hidden rounded-[1.75rem] bg-[#fafaf8] text-[#181818]\",\n classNames?.content,\n )}\n >\n <AnimatePresence mode=\"popLayout\" initial={false}>\n {activeItem ? (\n <motion.div\n key={activeItem.id}\n initial={reduce ? { opacity: 0 } : { opacity: 0, y: 8, filter: \"blur(6px)\" }}\n animate={{ opacity: 1, y: 0, filter: \"blur(0px)\" }}\n exit={\n reduce\n ? {\n opacity: 0,\n transition: { duration: 0.08, ease: EASE_OUT },\n }\n : {\n opacity: 0,\n y: -5,\n filter: \"blur(5px)\",\n transition: { duration: 0.12, ease: EASE_OUT },\n }\n }\n transition={reduce ? { duration: 0.12, ease: EASE_OUT } : SPRING_PRESS}\n className=\"min-h-64\"\n >\n {activeItem.content}\n </motion.div>\n ) : null}\n </AnimatePresence>\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;AAoGA,MAAM,iBAAiB;AAGvB,MAAM,gBAAgB;AACtB,MAAM,gBAAgB;AACtB,MAAM,aAAa;AACnB,MAAM,UAAU;AAChB,MAAM,aAAa;AACnB,MAAM,cAAc;AACpB,MAAM,gBAAgB;AACtB,MAAM,cAAc;AACpB,MAAM,eAAe;AAErB,SAAS,UAAU,GAAa,GAAa;CAC3C,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,IAAI,UAAU,OAAO,EAAE,MAAM;AACxE;AAEA,SAAS,OAAO,OAAe;CAC7B,OAAO,MAAM,QAAQ,mBAAmB,GAAG;AAC7C;AAEA,SAAS,SAAS,OAAiB,MAAc,IAAY;CAC3D,IAAI,SAAS,IAAI,OAAO,MAAM,MAAM;CACpC,MAAM,OAAO,MAAM,MAAM;CACzB,MAAM,CAAC,QAAQ,KAAK,OAAO,MAAM,CAAC;CAClC,KAAK,OAAO,IAAI,GAAG,IAAI;CACvB,OAAO;AACT;AAEA,SAAS,cAAc,SAAiB,cAAsB,UAAkB;CAC9E,MAAM,YAAY;CAClB,MAAM,aAAa,eAAe;CAClC,MAAM,OAAO,KAAK,IAAI,WAAW,KAAK,IAAI,aAAa,UAAU,OAAO,CAAC;CACzE,MAAM,QAAQ,OAAO;CACrB,MAAM,MAAM;CACZ,MAAM,SAAS;CACf,MAAM,WAAW,KAAK,IAAI,WAAW,OAAO,WAAW;CACvD,MAAM,YAAY,KAAK,IAAI,YAAY,QAAQ,WAAW;CAC1D,MAAM,YAAY,KAAK,I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FACA,YAAY,KACd;WAEC,UAAA,KAAK;UACF,CAAA;SACA;;QAEP,UACC,oBAAC,UAAD;SACE,MAAK;SACL,cAAY,SAAS,KAAK;SAC1B,gBAAgB,UAAU,MAAM,gBAAgB;SAChD,UAAU,UAAU;UAClB,MAAM,gBAAgB;UACtB,QAAQ,KAAK,EAAE;SACjB;SACA,WAAW,GACT,qPACA,CAAC,YACC,+EACF,YAAY,KACd;SAEA,UAAA,oBAAC,GAAD;UAAG,eAAA;UAAY,WAAU;SAAyB,CAAA;QAC5C,CAAA,IACN;OACD;;KACI,GAjIJ,KAAK,EAiID;IAEf,CAAC;GACE,CAAA;EACF,CAAA,GAEL,oBAAC,OAAD;GACE,IAAI,GAAG,IAAI;GACX,MAAK;GACL,mBAAiB,GAAG,IAAI,OAAO,OAAO,YAAY,OAAO;GACzD,WAAW,GACT,6FACA,YAAY,OACd;GAEA,UAAA,oBAAC,iBAAD;IAAiB,MAAK;IAAY,SAAS;IACxC,UAAA,aACC,oBAAC,OAAO,KAAR;KAEE,SAAS,SAAS,EAAE,SAAS,EAAE,IAAI;MAAE,SAAS;MAAG,GAAG;MAAG,QAAQ;KAAY;KAC3E,SAAS;MAAE,SAAS;MAAG,GAAG;MAAG,QAAQ;KAAY;KACjD,MACE,SACI;MACE,SAAS;MACT,YAAY;OAAE,UAAU;OAAM,MAAM;MAAS;KAC/C,IACA;MACE,SAAS;MACT,GAAG;MACH,QAAQ;MACR,YAAY;OAAE,UAAU;OAAM,MAAM;MAAS;KAC/C;KAEN,YAAY,SAAS;MAAE,UAAU;MAAM,MAAM;KAAS,IAAI;KAC1D,WAAU;KAET,UAAA,WAAW;IACF,GApBL,WAAW,EAoBN,IACV;GACW,CAAA;EACd,CAAA,CACF;;AAET"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notification-stack.d.ts","names":[],"sources":["../../../src/components/motion/notification-stack.tsx"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"notification-stack.d.ts","names":[],"sources":["../../../src/components/motion/notification-stack.tsx"],"mappings":";;KAqBY;EACV;EACA,OAAO;EACP,cAAc;EACd,WAAW;;KAGD;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf,OAAO;EACP;EACA;EACA,oBAAoB;EACpB;EACA;EACA;EACA;EACA;EACA;EACA,aAAa;;iBA0DC,oBACd,OACA,UACA,iBACA,kBACA,WACA,YACA,gBACA,eACA,YACA,WACA,cACC,yCAAsB,IAAA"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { useDismiss } from "../../hooks/use-dismiss.js";
|
|
3
|
+
import { useHoverGesture } from "../../hooks/use-hover-gesture.js";
|
|
4
|
+
import { useTapGesture } from "../../hooks/use-tap-gesture.js";
|
|
3
5
|
import { EASE_OUT, SPRING_LAYOUT } from "../../lib/ease.js";
|
|
4
6
|
import { ActionSwapText } from "./action-swap.js";
|
|
5
7
|
import { useCallback, useRef, useState } from "react";
|
|
@@ -38,13 +40,21 @@ function NotificationCardContent({ item, classNames }) {
|
|
|
38
40
|
}
|
|
39
41
|
function NotificationStack({ items, expanded, defaultExpanded = false, onExpandedChange, onViewAll, maxVisible = 3, collapsedLabel = "Notifications", expandedLabel = "View all", emptyLabel = "All caught up", className, classNames }) {
|
|
40
42
|
const reduce = useReducedMotion();
|
|
41
|
-
const canHover = useHoverCapable();
|
|
42
43
|
const hasFocus = useRef(false);
|
|
44
|
+
const rootRef = useRef(null);
|
|
45
|
+
const hover = useHoverGesture();
|
|
46
|
+
const tap = useTapGesture();
|
|
43
47
|
const [isExpanded, setIsExpanded] = useControllableExpanded({
|
|
44
48
|
expanded,
|
|
45
49
|
defaultExpanded,
|
|
46
50
|
onExpandedChange
|
|
47
51
|
});
|
|
52
|
+
const [tapExpanded, setTapExpanded] = useState(false);
|
|
53
|
+
const collapse = useCallback(() => {
|
|
54
|
+
setTapExpanded(false);
|
|
55
|
+
setIsExpanded(false);
|
|
56
|
+
}, [setIsExpanded]);
|
|
57
|
+
useDismiss(tapExpanded && isExpanded, collapse, rootRef, { behavior: "consume" });
|
|
48
58
|
const visibleItems = items.slice(0, Math.max(1, maxVisible));
|
|
49
59
|
const primaryItem = visibleItems[0];
|
|
50
60
|
const transition = reduce ? { duration: 0 } : SPRING_LAYOUT;
|
|
@@ -66,36 +76,43 @@ function NotificationStack({ items, expanded, defaultExpanded = false, onExpande
|
|
|
66
76
|
const handleBlur = (event) => {
|
|
67
77
|
if (event.currentTarget.contains(event.relatedTarget)) return;
|
|
68
78
|
hasFocus.current = false;
|
|
69
|
-
|
|
79
|
+
collapse();
|
|
70
80
|
};
|
|
71
81
|
const handleKeyDown = (event) => {
|
|
82
|
+
tap.drop();
|
|
72
83
|
if (event.key !== "Escape") return;
|
|
73
84
|
event.preventDefault();
|
|
74
|
-
|
|
75
|
-
event.currentTarget.blur();
|
|
85
|
+
collapse();
|
|
76
86
|
};
|
|
77
87
|
const handleClick = () => {
|
|
78
|
-
|
|
88
|
+
const gesture = tap.take();
|
|
89
|
+
if (!(gesture ? gesture.state : isExpanded)) {
|
|
79
90
|
setIsExpanded(true);
|
|
91
|
+
if (gesture && gesture.pointerType !== "mouse") setTapExpanded(true);
|
|
80
92
|
return;
|
|
81
93
|
}
|
|
82
94
|
if (onViewAll) {
|
|
83
95
|
onViewAll();
|
|
84
96
|
return;
|
|
85
97
|
}
|
|
86
|
-
|
|
98
|
+
collapse();
|
|
87
99
|
};
|
|
88
100
|
return /* @__PURE__ */ jsxs(motion.button, {
|
|
101
|
+
ref: rootRef,
|
|
89
102
|
type: "button",
|
|
90
103
|
initial: false,
|
|
91
104
|
"aria-expanded": isExpanded,
|
|
92
105
|
"aria-label": isExpanded ? `${items.length} notifications. ${expandedLabel}.` : `${items.length} notifications. Expand notifications.`,
|
|
93
|
-
onPointerEnter: () => {
|
|
94
|
-
if (
|
|
106
|
+
onPointerEnter: (event) => {
|
|
107
|
+
if (hover.enter(event)) setIsExpanded(true);
|
|
108
|
+
},
|
|
109
|
+
onPointerLeave: (event) => {
|
|
110
|
+
if (hover.leave(event) && !hasFocus.current) collapse();
|
|
95
111
|
},
|
|
96
|
-
|
|
97
|
-
|
|
112
|
+
onPointerDown: (event) => {
|
|
113
|
+
tap.start(event, isExpanded);
|
|
98
114
|
},
|
|
115
|
+
onPointerCancel: tap.drop,
|
|
99
116
|
onFocus: () => {
|
|
100
117
|
hasFocus.current = true;
|
|
101
118
|
setIsExpanded(true);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notification-stack.js","names":[],"sources":["../../../src/components/motion/notification-stack.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type FocusEvent,\n type KeyboardEvent,\n type ReactNode,\n useCallback,\n useRef,\n useState,\n} from \"react\";\nimport { ArrowUpRight, BellOff } from \"lucide-react\";\nimport { motion, type Transition, useReducedMotion } from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { useHoverCapable } from \"../../hooks/use-hover-capable\";\nimport { EASE_OUT, SPRING_LAYOUT } from \"../../lib/ease\";\nimport { ActionSwapText } from \"./action-swap\";\n\nexport type NotificationStackItem = {\n id: string;\n title: ReactNode;\n description?: ReactNode;\n trailing?: ReactNode;\n};\n\nexport type NotificationStackClassNames = {\n stack?: string;\n card?: string;\n content?: string;\n title?: string;\n description?: string;\n trailing?: string;\n footer?: string;\n count?: string;\n};\n\nexport interface NotificationStackProps {\n items: NotificationStackItem[];\n expanded?: boolean;\n defaultExpanded?: boolean;\n onExpandedChange?: (expanded: boolean) => void;\n onViewAll?: () => void;\n maxVisible?: number;\n collapsedLabel?: string;\n expandedLabel?: string;\n emptyLabel?: string;\n className?: string;\n classNames?: NotificationStackClassNames;\n}\n\nconst STACK_PEEK = 8;\nconst STACK_INSET = 12;\n\nfunction useControllableExpanded({\n expanded,\n defaultExpanded,\n onExpandedChange,\n}: {\n expanded?: boolean;\n defaultExpanded: boolean;\n onExpandedChange?: (expanded: boolean) => void;\n}) {\n const [internalExpanded, setInternalExpanded] = useState(defaultExpanded);\n const isControlled = expanded !== undefined;\n const value = expanded ?? internalExpanded;\n\n const setValue = useCallback(\n (next: boolean) => {\n if (!isControlled) setInternalExpanded(next);\n onExpandedChange?.(next);\n },\n [isControlled, onExpandedChange],\n );\n\n return [value, setValue] as const;\n}\n\nfunction NotificationCardContent({\n item,\n classNames,\n}: {\n item: NotificationStackItem;\n classNames?: NotificationStackClassNames;\n}) {\n return (\n <span className={cn(\"flex min-w-0 flex-col gap-1.5 py-4\", classNames?.content)}>\n <span className=\"flex min-w-0 items-start justify-between gap-3\">\n <span className={cn(\"min-w-0 font-medium text-sm leading-snug\", classNames?.title)}>\n {item.title}\n </span>\n {item.trailing ? (\n <span className={cn(\"shrink-0 text-xs\", classNames?.trailing)}>{item.trailing}</span>\n ) : null}\n </span>\n {item.description ? (\n <span\n className={cn(\"text-muted-foreground text-xs leading-relaxed\", classNames?.description)}\n >\n {item.description}\n </span>\n ) : null}\n </span>\n );\n}\n\nexport function NotificationStack({\n items,\n expanded,\n defaultExpanded = false,\n onExpandedChange,\n onViewAll,\n maxVisible = 3,\n collapsedLabel = \"Notifications\",\n expandedLabel = \"View all\",\n emptyLabel = \"All caught up\",\n className,\n classNames,\n}: NotificationStackProps) {\n const reduce = useReducedMotion();\n const canHover = useHoverCapable();\n const hasFocus = useRef(false);\n const [isExpanded, setIsExpanded] = useControllableExpanded({\n expanded,\n defaultExpanded,\n onExpandedChange,\n });\n\n const visibleItems = items.slice(0, Math.max(1, maxVisible));\n const primaryItem = visibleItems[0];\n const transition: Transition = reduce ? { duration: 0 } : SPRING_LAYOUT;\n const cardTransition: Transition = reduce ? { duration: 0 } : { duration: 0.32, ease: EASE_OUT };\n const backgroundTransition: Transition = reduce\n ? { duration: 0 }\n : { duration: 0.26, ease: EASE_OUT };\n\n if (!primaryItem) {\n return (\n <div\n className={cn(\n \"flex w-full max-w-[22rem] items-center justify-center gap-2 rounded-3xl bg-muted/70 px-5 py-8 font-medium text-muted-foreground text-sm\",\n className,\n )}\n >\n <BellOff className=\"h-4 w-4\" aria-hidden=\"true\" />\n {emptyLabel}\n </div>\n );\n }\n\n const handleBlur = (event: FocusEvent<HTMLButtonElement>) => {\n if (event.currentTarget.contains(event.relatedTarget)) return;\n hasFocus.current = false;\n setIsExpanded(false);\n };\n\n const handleKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {\n if (event.key !== \"Escape\") return;\n event.preventDefault();\n setIsExpanded(false);\n event.currentTarget.blur();\n };\n\n const handleClick = () => {\n if (!isExpanded) {\n setIsExpanded(true);\n return;\n }\n\n if (onViewAll) {\n onViewAll();\n return;\n }\n\n setIsExpanded(false);\n };\n\n return (\n <motion.button\n type=\"button\"\n initial={false}\n aria-expanded={isExpanded}\n aria-label={\n isExpanded\n ? `${items.length} notifications. ${expandedLabel}.`\n : `${items.length} notifications. Expand notifications.`\n }\n onPointerEnter={() => {\n if (canHover) setIsExpanded(true);\n }}\n onPointerLeave={() => {\n if (canHover && !hasFocus.current) setIsExpanded(false);\n }}\n onFocus={() => {\n hasFocus.current = true;\n setIsExpanded(true);\n }}\n onBlur={handleBlur}\n onKeyDown={handleKeyDown}\n onClick={handleClick}\n className={cn(\n \"relative z-10 block w-full max-w-[22rem] cursor-pointer rounded-3xl text-left text-foreground outline-none\",\n \"focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background\",\n className,\n )}\n >\n {/* This invisible first card gives the button its compact intrinsic footprint. */}\n <span aria-hidden=\"true\" className=\"invisible block p-3\">\n <span className=\"block\">\n <span\n className={cn(\"block rounded-2xl border border-transparent px-4\", classNames?.card)}\n >\n <NotificationCardContent item={primaryItem} classNames={classNames} />\n </span>\n </span>\n <span className=\"mt-2 block h-9\" />\n </span>\n\n <span className=\"absolute inset-x-0 bottom-0 block p-3\">\n <motion.span\n aria-hidden=\"true\"\n layout\n initial={false}\n transition={backgroundTransition}\n className=\"absolute inset-0 rounded-3xl bg-muted\"\n />\n <span className={cn(\"relative z-10 grid gap-1\", !isExpanded && \"pb-2\", classNames?.stack)}>\n {visibleItems.map((item, index) => {\n const isPrimary = index === 0;\n\n return (\n <motion.span\n key={item.id}\n layout=\"position\"\n initial={false}\n animate={{\n y: isExpanded ? 0 : index * STACK_PEEK,\n clipPath: isExpanded\n ? \"inset(0px 0px round 16px)\"\n : `inset(0px ${index * STACK_INSET}px round 16px)`,\n }}\n transition={cardTransition}\n className={cn(\n \"block rounded-2xl border border-border/60 bg-background px-4\",\n classNames?.card,\n )}\n style={{\n zIndex: visibleItems.length - index,\n gridColumn: 1,\n gridRow: isExpanded ? index + 1 : 1,\n }}\n >\n <span className={cn(\"block\", !isPrimary && !isExpanded && \"invisible\")}>\n <NotificationCardContent item={item} classNames={classNames} />\n </span>\n </motion.span>\n );\n })}\n </span>\n\n <motion.span\n layout=\"position\"\n transition={transition}\n className={cn(\n \"relative z-10 mt-2 flex min-h-9 items-center gap-2 px-1\",\n classNames?.footer,\n )}\n >\n <span\n className={cn(\n \"grid size-7 shrink-0 place-items-center rounded-full bg-orange-600 font-medium text-white text-xs shadow-[inset_0_1px_2px_rgb(0_0_0/0.2),inset_0_-1px_0_rgb(255_255_255/0.16)] dark:bg-orange-500\",\n classNames?.count,\n )}\n >\n {items.length}\n </span>\n <span className=\"flex items-center font-medium text-sm\">\n <ActionSwapText value={isExpanded ? \"expanded\" : \"collapsed\"} animation=\"roll\">\n {isExpanded ? (\n <span className=\"inline-flex items-center gap-1\">\n {expandedLabel}\n <ArrowUpRight className=\"size-4\" aria-hidden=\"true\" />\n </span>\n ) : (\n collapsedLabel\n )}\n </ActionSwapText>\n </span>\n </motion.span>\n </span>\n </motion.button>\n );\n}\n"],"mappings":";;;;;;;;;;AAkDA,MAAM,aAAa;AACnB,MAAM,cAAc;AAEpB,SAAS,wBAAwB,EAC/B,UACA,iBACA,oBAKC;CACD,MAAM,CAAC,kBAAkB,uBAAuB,SAAS,eAAe;CACxE,MAAM,eAAe,aAAa,KAAA;C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ACE,oBAAC,OAAO,MAAR;KACE,eAAY;KACZ,QAAA;KACA,SAAS;KACT,YAAY;KACZ,WAAU;IACX,CAAA;IACD,oBAAC,QAAD;KAAM,WAAW,GAAG,4BAA4B,CAAC,cAAc,QAAQ,YAAY,KAAK;KACrF,UAAA,aAAa,KAAK,MAAM,UAAU;MACjC,MAAM,YAAY,UAAU;MAE5B,OACE,oBAAC,OAAO,MAAR;OAEE,QAAO;OACP,SAAS;OACT,SAAS;QACP,GAAG,aAAa,IAAI,QAAQ;QAC5B,UAAU,aACN,8BACA,aAAa,QAAQ,YAAY;OACvC;OACA,YAAY;OACZ,WAAW,GACT,gEACA,YAAY,IACd;OACA,OAAO;QACL,QAAQ,aAAa,SAAS;QAC9B,YAAY;QACZ,SAAS,aAAa,QAAQ,IAAI;OACpC;OAEA,UAAA,oBAAC,QAAD;QAAM,WAAW,GAAG,SAAS,CAAC,aAAa,CAAC,cAAc,WAAW;QACnE,UAAA,oBAAC,yBAAD;SAA+B;SAAkB;QAAa,CAAA;OAC1D,CAAA;MACK,GAvBN,KAAK,EAuBC;KAEjB,CAAC;IACG,CAAA;IAEN,qBAAC,OAAO,MAAR;KACE,QAAO;KACK;KACZ,WAAW,GACT,2DACA,YAAY,MACd;KANF,UAAA,CAQE,oBAAC,QAAD;MACE,WAAW,GACT,qMACA,YAAY,KACd;MAEC,UAAA,MAAM;KACH,CAAA,GACN,oBAAC,QAAD;MAAM,WAAU;MACd,UAAA,oBAAC,gBAAD;OAAgB,OAAO,aAAa,aAAa;OAAa,WAAU;OACrE,UAAA,aACC,qBAAC,QAAD;QAAM,WAAU;QAAhB,UAAA,CACG,eACD,oBAAC,cAAD;SAAc,WAAU;SAAS,eAAY;QAAQ,CAAA,CACjD;OAEN,CAAA,IAAA;MAEY,CAAA;KACZ,CAAA,CACK;;GACT;EACO,CAAA,CAAA;;AAEnB"}
|
|
1
|
+
{"version":3,"file":"notification-stack.js","names":[],"sources":["../../../src/components/motion/notification-stack.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type FocusEvent,\n type KeyboardEvent,\n type PointerEvent,\n type ReactNode,\n useCallback,\n useRef,\n useState,\n} from \"react\";\nimport { ArrowUpRight, BellOff } from \"lucide-react\";\nimport { motion, type Transition, useReducedMotion } from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { useDismiss } from \"../../hooks/use-dismiss\";\nimport { useHoverGesture } from \"../../hooks/use-hover-gesture\";\nimport { useTapGesture } from \"../../hooks/use-tap-gesture\";\nimport { EASE_OUT, SPRING_LAYOUT } from \"../../lib/ease\";\nimport { ActionSwapText } from \"./action-swap\";\n\nexport type NotificationStackItem = {\n id: string;\n title: ReactNode;\n description?: ReactNode;\n trailing?: ReactNode;\n};\n\nexport type NotificationStackClassNames = {\n stack?: string;\n card?: string;\n content?: string;\n title?: string;\n description?: string;\n trailing?: string;\n footer?: string;\n count?: string;\n};\n\nexport interface NotificationStackProps {\n items: NotificationStackItem[];\n expanded?: boolean;\n defaultExpanded?: boolean;\n onExpandedChange?: (expanded: boolean) => void;\n onViewAll?: () => void;\n maxVisible?: number;\n collapsedLabel?: string;\n expandedLabel?: string;\n emptyLabel?: string;\n className?: string;\n classNames?: NotificationStackClassNames;\n}\n\nconst STACK_PEEK = 8;\nconst STACK_INSET = 12;\n\nfunction useControllableExpanded({\n expanded,\n defaultExpanded,\n onExpandedChange,\n}: {\n expanded?: boolean;\n defaultExpanded: boolean;\n onExpandedChange?: (expanded: boolean) => void;\n}) {\n const [internalExpanded, setInternalExpanded] = useState(defaultExpanded);\n const isControlled = expanded !== undefined;\n const value = expanded ?? internalExpanded;\n\n const setValue = useCallback(\n (next: boolean) => {\n if (!isControlled) setInternalExpanded(next);\n onExpandedChange?.(next);\n },\n [isControlled, onExpandedChange],\n );\n\n return [value, setValue] as const;\n}\n\nfunction NotificationCardContent({\n item,\n classNames,\n}: {\n item: NotificationStackItem;\n classNames?: NotificationStackClassNames;\n}) {\n return (\n <span className={cn(\"flex min-w-0 flex-col gap-1.5 py-4\", classNames?.content)}>\n <span className=\"flex min-w-0 items-start justify-between gap-3\">\n <span className={cn(\"min-w-0 font-medium text-sm leading-snug\", classNames?.title)}>\n {item.title}\n </span>\n {item.trailing ? (\n <span className={cn(\"shrink-0 text-xs\", classNames?.trailing)}>{item.trailing}</span>\n ) : null}\n </span>\n {item.description ? (\n <span\n className={cn(\"text-muted-foreground text-xs leading-relaxed\", classNames?.description)}\n >\n {item.description}\n </span>\n ) : null}\n </span>\n );\n}\n\nexport function NotificationStack({\n items,\n expanded,\n defaultExpanded = false,\n onExpandedChange,\n onViewAll,\n maxVisible = 3,\n collapsedLabel = \"Notifications\",\n expandedLabel = \"View all\",\n emptyLabel = \"All caught up\",\n className,\n classNames,\n}: NotificationStackProps) {\n const reduce = useReducedMotion();\n const hasFocus = useRef(false);\n const rootRef = useRef<HTMLButtonElement>(null);\n const hover = useHoverGesture();\n // What the last gesture on the stack was, and whether it was already\n // expanded when that gesture started. A click reports neither.\n const tap = useTapGesture<boolean>();\n const [isExpanded, setIsExpanded] = useControllableExpanded({\n expanded,\n defaultExpanded,\n onExpandedChange,\n });\n // Set by the tap that expands the stack, and the reason the outside-tap\n // dismisser exists at all — a hovering pointer has its own way out.\n const [tapExpanded, setTapExpanded] = useState(false);\n\n const collapse = useCallback(() => {\n setTapExpanded(false);\n setIsExpanded(false);\n }, [setIsExpanded]);\n\n // A pointer leaving the stack is what collapses it, and a finger never\n // leaves: without this the stack stays open for good once tapped, and when\n // `onViewAll` is set the next tap follows the link instead of closing. The\n // tap that lands somewhere else stands in for the pointer leaving, and it is\n // consumed rather than passed through — the expanded stack covers the page,\n // so the tap that dismisses it is aimed at nothing else.\n useDismiss(tapExpanded && isExpanded, collapse, rootRef, {\n behavior: \"consume\",\n });\n\n const visibleItems = items.slice(0, Math.max(1, maxVisible));\n const primaryItem = visibleItems[0];\n const transition: Transition = reduce ? { duration: 0 } : SPRING_LAYOUT;\n const cardTransition: Transition = reduce ? { duration: 0 } : { duration: 0.32, ease: EASE_OUT };\n const backgroundTransition: Transition = reduce\n ? { duration: 0 }\n : { duration: 0.26, ease: EASE_OUT };\n\n if (!primaryItem) {\n return (\n <div\n className={cn(\n \"flex w-full max-w-[22rem] items-center justify-center gap-2 rounded-3xl bg-muted/70 px-5 py-8 font-medium text-muted-foreground text-sm\",\n className,\n )}\n >\n <BellOff className=\"h-4 w-4\" aria-hidden=\"true\" />\n {emptyLabel}\n </div>\n );\n }\n\n const handleBlur = (event: FocusEvent<HTMLButtonElement>) => {\n if (event.currentTarget.contains(event.relatedTarget)) return;\n hasFocus.current = false;\n collapse();\n };\n\n const handleKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {\n // A key press is the start of a keyboard activation, never part of a tap:\n // whatever a taken-away gesture left behind must not be read as one.\n tap.drop();\n if (event.key !== \"Escape\") return;\n event.preventDefault();\n collapse();\n // Focus stays where the keyboard put it. Blurring here collapsed the stack\n // *and* threw the user back to the top of the document.\n };\n\n const handleClick = () => {\n const gesture = tap.take();\n // Read from where the gesture started, not from now: a browser that\n // focuses the stack on contact expands it mid-tap, and the first tap would\n // then follow `onViewAll` instead of opening the list it was meant to.\n const wasExpanded = gesture ? gesture.state : isExpanded;\n\n if (!wasExpanded) {\n setIsExpanded(true);\n if (gesture && gesture.pointerType !== \"mouse\") setTapExpanded(true);\n return;\n }\n\n if (onViewAll) {\n onViewAll();\n return;\n }\n\n collapse();\n };\n\n return (\n <motion.button\n ref={rootRef}\n type=\"button\"\n initial={false}\n aria-expanded={isExpanded}\n aria-label={\n isExpanded\n ? `${items.length} notifications. ${expandedLabel}.`\n : `${items.length} notifications. Expand notifications.`\n }\n // A tap reports as a hover on its way past — enter, leave, then click —\n // so an unfiltered hover path expands, collapses and expands again in\n // the space of one tap, springs and all. The tap has its own route\n // through `handleClick`.\n onPointerEnter={(event: PointerEvent<HTMLButtonElement>) => {\n if (hover.enter(event)) setIsExpanded(true);\n }}\n onPointerLeave={(event: PointerEvent<HTMLButtonElement>) => {\n if (hover.leave(event) && !hasFocus.current) collapse();\n }}\n onPointerDown={(event: PointerEvent<HTMLButtonElement>) => {\n tap.start(event, isExpanded);\n }}\n // The platform can take the gesture away mid-press — a scroll, a system\n // swipe — and no click follows it.\n onPointerCancel={tap.drop}\n onFocus={() => {\n hasFocus.current = true;\n setIsExpanded(true);\n }}\n onBlur={handleBlur}\n onKeyDown={handleKeyDown}\n onClick={handleClick}\n className={cn(\n \"relative z-10 block w-full max-w-[22rem] cursor-pointer rounded-3xl text-left text-foreground outline-none\",\n \"focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background\",\n className,\n )}\n >\n {/* This invisible first card gives the button its compact intrinsic footprint. */}\n <span aria-hidden=\"true\" className=\"invisible block p-3\">\n <span className=\"block\">\n <span\n className={cn(\"block rounded-2xl border border-transparent px-4\", classNames?.card)}\n >\n <NotificationCardContent item={primaryItem} classNames={classNames} />\n </span>\n </span>\n <span className=\"mt-2 block h-9\" />\n </span>\n\n <span className=\"absolute inset-x-0 bottom-0 block p-3\">\n <motion.span\n aria-hidden=\"true\"\n layout\n initial={false}\n transition={backgroundTransition}\n className=\"absolute inset-0 rounded-3xl bg-muted\"\n />\n <span className={cn(\"relative z-10 grid gap-1\", !isExpanded && \"pb-2\", classNames?.stack)}>\n {visibleItems.map((item, index) => {\n const isPrimary = index === 0;\n\n return (\n <motion.span\n key={item.id}\n layout=\"position\"\n initial={false}\n animate={{\n y: isExpanded ? 0 : index * STACK_PEEK,\n clipPath: isExpanded\n ? \"inset(0px 0px round 16px)\"\n : `inset(0px ${index * STACK_INSET}px round 16px)`,\n }}\n transition={cardTransition}\n className={cn(\n \"block rounded-2xl border border-border/60 bg-background px-4\",\n classNames?.card,\n )}\n style={{\n zIndex: visibleItems.length - index,\n gridColumn: 1,\n gridRow: isExpanded ? index + 1 : 1,\n }}\n >\n <span className={cn(\"block\", !isPrimary && !isExpanded && \"invisible\")}>\n <NotificationCardContent item={item} classNames={classNames} />\n </span>\n </motion.span>\n );\n })}\n </span>\n\n <motion.span\n layout=\"position\"\n transition={transition}\n className={cn(\n \"relative z-10 mt-2 flex min-h-9 items-center gap-2 px-1\",\n classNames?.footer,\n )}\n >\n <span\n className={cn(\n \"grid size-7 shrink-0 place-items-center rounded-full bg-orange-600 font-medium text-white text-xs shadow-[inset_0_1px_2px_rgb(0_0_0/0.2),inset_0_-1px_0_rgb(255_255_255/0.16)] dark:bg-orange-500\",\n classNames?.count,\n )}\n >\n {items.length}\n </span>\n <span className=\"flex items-center font-medium text-sm\">\n <ActionSwapText value={isExpanded ? \"expanded\" : \"collapsed\"} animation=\"roll\">\n {isExpanded ? (\n <span className=\"inline-flex items-center gap-1\">\n {expandedLabel}\n <ArrowUpRight className=\"size-4\" aria-hidden=\"true\" />\n </span>\n ) : (\n collapsedLabel\n )}\n </ActionSwapText>\n </span>\n </motion.span>\n </span>\n </motion.button>\n );\n}\n"],"mappings":";;;;;;;;;;;;AAqDA,MAAM,aAAa;AACnB,MAAM,cAAc;AAEpB,SAAS,wBAAwB,EAC/B,UACA,iBACA,oBAKC;CACD,MAAM,CAAC,kBAAkB,uBAAuB,SAAS,eAAe;CACxE,MAAM,eAAe,aAAa,KAAA;CAWlC,OAAO,CAVO,YAAY,kBAET,aACd,SAAkB;EACjB,IAAI,CAAC,cAAc,oBAAoB,IAAI;EAC3C,mBAAmB,IAAI;CACzB,GACA,CAAC,cAAc,gBAAgB,CAGX,CAAC;AACzB;AAEA,SAAS,wBAAwB,EAC/B,MACA,cAIC;CACD,OACE,qBAAC,QAAD;EAAM,WAAW,GAAG,sCAAsC,YAAY,OAAO;EAA7E,UAAA,CACE,qBAAC,QAAD;GAAM,WAAU;GAAhB,UAAA,CACE,oBAAC,QAAD;IAAM,WAAW,GAAG,4CAA4C,YAAY,KAAK;IAC9E,UAAA,KAAK;GACF,CAAA,GACL,KAAK,WACJ,oBAAC,QAAD;IAAM,WAAW,GAAG,oBAAoB,YAAY,QAAQ;IAAI,UAAA,KAAK;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popover-morph.tsx"],"mappings":";;KAwBK;KACA;
|
|
1
|
+
{"version":3,"file":"popover-morph.d.ts","names":[],"sources":["../../../src/components/motion/popover-morph.tsx"],"mappings":";;KAwBK;KACA;UAsBY;EACf,UAAU;;EAEV;;EAEA;EACA,gBAAgB;EAChB;;;;;;;iBAQc,eACd,UACA,MAAM,gBACN,aACA,cACA,aACC,oCAAiB,IAAA;UAoFH;EACf,UAAU;;;iBAcI,sBAAsB,YAAY,2BAAwB,aAAA,kDAAA;UAuCzD;EACf,UAAU;EACV,OAAO;EACP,QAAQ;;EAER;;EAEA;EACA;;iBAGc,sBACd,UACA,MACA,OACA,YACA,QACA,aACC,2CAAwB"}
|
|
@@ -20,8 +20,8 @@ function useMorphContext(component) {
|
|
|
20
20
|
*/
|
|
21
21
|
function MorphPopover({ children, open: controlledOpen, defaultOpen = false, onOpenChange, className }) {
|
|
22
22
|
const baseId = useId();
|
|
23
|
-
const
|
|
24
|
-
const
|
|
23
|
+
const [root, setRoot] = useState(null);
|
|
24
|
+
const [trigger, setTrigger] = useState(null);
|
|
25
25
|
const contentRef = useRef(null);
|
|
26
26
|
const [internalOpen, setInternalOpen] = useState(defaultOpen);
|
|
27
27
|
const controlled = controlledOpen !== void 0;
|
|
@@ -31,12 +31,23 @@ function MorphPopover({ children, open: controlledOpen, defaultOpen = false, onO
|
|
|
31
31
|
onOpenChange?.(next);
|
|
32
32
|
}, [controlled, onOpenChange]);
|
|
33
33
|
const toggle = useCallback(() => setOpen(!open), [setOpen, open]);
|
|
34
|
+
const anchorRef = useMemo(() => ({ current: trigger ?? root }), [root, trigger]);
|
|
35
|
+
const close = useCallback(() => {
|
|
36
|
+
setOpen(false);
|
|
37
|
+
const focused = document.activeElement;
|
|
38
|
+
if (!(focused instanceof HTMLElement && contentRef.current?.contains(focused))) return;
|
|
39
|
+
(trigger ?? (root && root.tabIndex >= 0 ? root : null))?.focus();
|
|
40
|
+
}, [
|
|
41
|
+
root,
|
|
42
|
+
setOpen,
|
|
43
|
+
trigger
|
|
44
|
+
]);
|
|
34
45
|
useEffect(() => {
|
|
35
46
|
if (!open) return;
|
|
36
|
-
const onKey = (e) => e.key === "Escape" &&
|
|
47
|
+
const onKey = (e) => e.key === "Escape" && close();
|
|
37
48
|
const onPointer = (e) => {
|
|
38
49
|
const target = e.target;
|
|
39
|
-
if (
|
|
50
|
+
if (root && !root.contains(target) && !contentRef.current?.contains(target)) close();
|
|
40
51
|
};
|
|
41
52
|
window.addEventListener("keydown", onKey);
|
|
42
53
|
window.addEventListener("pointerdown", onPointer);
|
|
@@ -44,25 +55,31 @@ function MorphPopover({ children, open: controlledOpen, defaultOpen = false, onO
|
|
|
44
55
|
window.removeEventListener("keydown", onKey);
|
|
45
56
|
window.removeEventListener("pointerdown", onPointer);
|
|
46
57
|
};
|
|
47
|
-
}, [
|
|
58
|
+
}, [
|
|
59
|
+
open,
|
|
60
|
+
root,
|
|
61
|
+
close
|
|
62
|
+
]);
|
|
48
63
|
const ctx = useMemo(() => ({
|
|
49
64
|
open,
|
|
50
65
|
setOpen,
|
|
51
66
|
toggle,
|
|
52
67
|
triggerId: `${baseId}-trigger`,
|
|
53
68
|
contentId: `${baseId}-content`,
|
|
54
|
-
triggerRef,
|
|
69
|
+
triggerRef: anchorRef,
|
|
70
|
+
registerTrigger: setTrigger,
|
|
55
71
|
contentRef
|
|
56
72
|
}), [
|
|
57
73
|
open,
|
|
58
74
|
setOpen,
|
|
59
75
|
toggle,
|
|
60
|
-
baseId
|
|
76
|
+
baseId,
|
|
77
|
+
anchorRef
|
|
61
78
|
]);
|
|
62
79
|
return /* @__PURE__ */ jsx(MorphContext.Provider, {
|
|
63
80
|
value: ctx,
|
|
64
81
|
children: /* @__PURE__ */ jsx("div", {
|
|
65
|
-
ref:
|
|
82
|
+
ref: setRoot,
|
|
66
83
|
className: cn("relative inline-flex", className),
|
|
67
84
|
children
|
|
68
85
|
})
|
|
@@ -83,9 +100,7 @@ function MorphPopoverTrigger({ children }) {
|
|
|
83
100
|
const childRef = child.props.ref;
|
|
84
101
|
return cloneElement(child, {
|
|
85
102
|
id: ctx.triggerId,
|
|
86
|
-
ref: mergeRefs(childRef,
|
|
87
|
-
ctx.triggerRef.current = node;
|
|
88
|
-
}),
|
|
103
|
+
ref: mergeRefs(childRef, ctx.registerTrigger),
|
|
89
104
|
onClick: (e) => {
|
|
90
105
|
childOnClick?.(e);
|
|
91
106
|
ctx.toggle();
|