@kumix/ui 0.3.5 → 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 +11 -16
- 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 +26 -7
- package/dist/components/motion/bottom-sheet.js.map +1 -1
- package/dist/components/motion/combobox/list.js +2 -2
- package/dist/components/motion/combobox/list.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/project-folder.d.ts +27 -0
- package/dist/components/motion/project-folder.d.ts.map +1 -0
- package/dist/components/motion/project-folder.js +310 -0
- package/dist/components/motion/project-folder.js.map +1 -0
- 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/tabs.d.ts.map +1 -1
- package/dist/components/motion/tabs.js +2 -0
- package/dist/components/motion/tabs.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/alert.d.ts +1 -1
- package/dist/components/reui/badge.d.ts +2 -2
- package/dist/components/reui/frame.d.ts +2 -2
- package/dist/components/reui/icon-tile.d.ts +2 -2
- 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/sidebar.d.ts +1 -1
- package/dist/components/ui/toggle.d.ts +1 -1
- package/dist/{copy-menu-Bk5GP9Gp.js → copy-menu-1FKoMc9o.js} +9 -2
- package/dist/copy-menu-1FKoMc9o.js.map +1 -0
- package/dist/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 +3 -3
- package/dist/copy-menu-Bk5GP9Gp.js.map +0 -1
|
@@ -1,7 +1,9 @@
|
|
|
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
|
-
import { useId, useState } from "react";
|
|
6
|
+
import { useCallback, useId, useRef, useState } from "react";
|
|
5
7
|
import { cn } from "@kumix/utils";
|
|
6
8
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
7
9
|
import { AnimatePresence, motion, useReducedMotion } from "motion/react";
|
|
@@ -24,13 +26,18 @@ function DefaultPreview({ item }) {
|
|
|
24
26
|
function PreviewRail({ items, label = "Section navigation", orientation = "vertical", activeId, defaultActiveId, onActiveChange, onItemSelect, renderPreview, showPreview = true, previewSide = "after", highlightActive = false, itemSize = 24, children, className, railClassName, previewContainerClassName, previewClassName }) {
|
|
25
27
|
const uid = useId();
|
|
26
28
|
const reduce = useReducedMotion();
|
|
27
|
-
const
|
|
29
|
+
const rootRef = useRef(null);
|
|
28
30
|
const [internalActiveId, setInternalActiveId] = useState(defaultActiveId ?? items[0]?.id ?? "");
|
|
29
31
|
const [hoveredId, setHoveredId] = useState(null);
|
|
32
|
+
const [pinnedId, setPinnedId] = useState(null);
|
|
30
33
|
const [focusedId, setFocusedId] = useState(null);
|
|
34
|
+
const tap = useTapGesture();
|
|
35
|
+
const hover = useHoverGesture();
|
|
36
|
+
const clearPinned = useCallback(() => setPinnedId(null), []);
|
|
37
|
+
useDismiss(pinnedId !== null, clearPinned, rootRef);
|
|
31
38
|
const requestedActiveId = activeId ?? internalActiveId;
|
|
32
39
|
const selectedId = items.some((item) => item.id === requestedActiveId) ? requestedActiveId : items[0]?.id ?? "";
|
|
33
|
-
const displayedId = hoveredId ?? focusedId ?? "";
|
|
40
|
+
const displayedId = hoveredId ?? pinnedId ?? focusedId ?? "";
|
|
34
41
|
const highlightedId = displayedId || (highlightActive ? selectedId : "");
|
|
35
42
|
const displayedIndex = items.findIndex((item) => item.id === highlightedId);
|
|
36
43
|
const rowTemplate = items.length ? `repeat(${items.length}, ${itemSize}px)` : void 0;
|
|
@@ -41,14 +48,20 @@ function PreviewRail({ items, label = "Section navigation", orientation = "verti
|
|
|
41
48
|
};
|
|
42
49
|
return /* @__PURE__ */ jsxs(motion.div, {
|
|
43
50
|
layoutRoot: true,
|
|
51
|
+
ref: rootRef,
|
|
44
52
|
onBlur: (event) => {
|
|
45
|
-
if (!event.currentTarget.contains(event.relatedTarget))
|
|
53
|
+
if (!event.currentTarget.contains(event.relatedTarget)) {
|
|
54
|
+
setFocusedId(null);
|
|
55
|
+
setPinnedId(null);
|
|
56
|
+
}
|
|
46
57
|
},
|
|
47
58
|
className: cn("relative isolate flex w-full overflow-visible", isHorizontal ? "min-h-64 flex-col items-center justify-center" : "min-h-80", className),
|
|
48
59
|
children: [
|
|
49
60
|
/* @__PURE__ */ jsx("nav", {
|
|
50
61
|
"aria-label": label,
|
|
51
|
-
onPointerLeave: () =>
|
|
62
|
+
onPointerLeave: (event) => {
|
|
63
|
+
if (hover.leave(event)) setHoveredId(null);
|
|
64
|
+
},
|
|
52
65
|
style: isHorizontal ? { gridTemplateColumns: rowTemplate } : { gridTemplateRows: rowTemplate },
|
|
53
66
|
className: cn("relative z-10 grid shrink-0", isHorizontal ? "h-12 w-fit max-w-full justify-center self-center" : "w-12 content-center", railClassName),
|
|
54
67
|
children: items.map((item, index) => {
|
|
@@ -65,13 +78,27 @@ function PreviewRail({ items, label = "Section navigation", orientation = "verti
|
|
|
65
78
|
}) });
|
|
66
79
|
const sharedClassName = cn("relative flex text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background", isHorizontal ? "h-12 w-6 items-end justify-center" : "h-6 w-12 items-center");
|
|
67
80
|
const sharedStyle = isHorizontal ? { width: itemSize } : { height: itemSize };
|
|
68
|
-
const handlePointerEnter = () => {
|
|
69
|
-
if (
|
|
81
|
+
const handlePointerEnter = (event) => {
|
|
82
|
+
if (hover.enter(event)) setHoveredId(item.id);
|
|
70
83
|
};
|
|
84
|
+
const handlePointerDown = (event) => {
|
|
85
|
+
tap.start(event, pinnedId === item.id);
|
|
86
|
+
setFocusedId(null);
|
|
87
|
+
};
|
|
88
|
+
const dropGesture = () => tap.drop();
|
|
71
89
|
const handleFocus = (currentTarget) => {
|
|
72
90
|
if (currentTarget.matches(":focus-visible")) setFocusedId(item.id);
|
|
73
91
|
};
|
|
74
|
-
const handleSelect = () => {
|
|
92
|
+
const handleSelect = (event) => {
|
|
93
|
+
const gesture = tap.take();
|
|
94
|
+
if (gesture !== null && gesture.pointerType !== "mouse") {
|
|
95
|
+
if (item.href && !gesture.state) {
|
|
96
|
+
event.preventDefault();
|
|
97
|
+
setPinnedId(item.id);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
setPinnedId(item.id);
|
|
101
|
+
}
|
|
75
102
|
selectItem(item.id);
|
|
76
103
|
onItemSelect?.(item);
|
|
77
104
|
};
|
|
@@ -83,8 +110,9 @@ function PreviewRail({ items, label = "Section navigation", orientation = "verti
|
|
|
83
110
|
"aria-label": item.ariaLabel ?? item.label,
|
|
84
111
|
"aria-current": selected ? "page" : void 0,
|
|
85
112
|
onPointerEnter: handlePointerEnter,
|
|
86
|
-
|
|
87
|
-
|
|
113
|
+
onPointerDown: handlePointerDown,
|
|
114
|
+
onPointerCancel: dropGesture,
|
|
115
|
+
onKeyDown: dropGesture,
|
|
88
116
|
onFocus: (event) => handleFocus(event.currentTarget),
|
|
89
117
|
onClick: handleSelect,
|
|
90
118
|
style: sharedStyle,
|
|
@@ -96,8 +124,9 @@ function PreviewRail({ items, label = "Section navigation", orientation = "verti
|
|
|
96
124
|
"aria-label": item.ariaLabel ?? item.label,
|
|
97
125
|
"aria-current": selected ? "location" : void 0,
|
|
98
126
|
onPointerEnter: handlePointerEnter,
|
|
99
|
-
|
|
100
|
-
|
|
127
|
+
onPointerDown: handlePointerDown,
|
|
128
|
+
onPointerCancel: dropGesture,
|
|
129
|
+
onKeyDown: dropGesture,
|
|
101
130
|
onFocus: (event) => handleFocus(event.currentTarget),
|
|
102
131
|
onClick: handleSelect,
|
|
103
132
|
style: sharedStyle,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preview-rail.js","names":[],"sources":["../../../src/components/motion/preview-rail.tsx"],"sourcesContent":["\"use client\";\n\nimport { type ReactNode, useId, useState } from \"react\";\nimport { AnimatePresence, motion, 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\";\n\nexport interface PreviewRailItem {\n id: string;\n label: string;\n ariaLabel?: string;\n description?: ReactNode;\n href?: string;\n target?: \"_blank\" | \"_self\" | \"_parent\" | \"_top\";\n rel?: string;\n}\n\nexport interface PreviewRailProps {\n items: PreviewRailItem[];\n label?: string;\n orientation?: \"vertical\" | \"horizontal\";\n activeId?: string;\n defaultActiveId?: string;\n onActiveChange?: (id: string) => void;\n onItemSelect?: (item: PreviewRailItem) => void;\n renderPreview?: (item: PreviewRailItem) => ReactNode;\n showPreview?: boolean;\n previewSide?: \"before\" | \"after\";\n highlightActive?: boolean;\n itemSize?: number;\n children?: ReactNode;\n className?: string;\n railClassName?: string;\n previewContainerClassName?: string;\n previewClassName?: string;\n}\n\nfunction DefaultPreview({ item }: { item: PreviewRailItem }) {\n return (\n <div\n data-slot=\"preview-rail-card\"\n className=\"rounded-2xl border border-border bg-card p-4 shadow-sm\"\n >\n <p data-slot=\"preview-rail-title\" className=\"font-medium text-card-foreground\">\n {item.label}\n </p>\n {item.description ? (\n <div\n data-slot=\"preview-rail-description\"\n className=\"mt-1 text-muted-foreground text-sm leading-6\"\n >\n {item.description}\n </div>\n ) : null}\n </div>\n );\n}\n\nexport function PreviewRail({\n items,\n label = \"Section navigation\",\n orientation = \"vertical\",\n activeId,\n defaultActiveId,\n onActiveChange,\n onItemSelect,\n renderPreview,\n showPreview = true,\n previewSide = \"after\",\n highlightActive = false,\n itemSize = 24,\n children,\n className,\n railClassName,\n previewContainerClassName,\n previewClassName,\n}: PreviewRailProps) {\n const uid = useId();\n const reduce = useReducedMotion();\n const canHover = useHoverCapable();\n const [internalActiveId, setInternalActiveId] = useState(defaultActiveId ?? items[0]?.id ?? \"\");\n const [hoveredId, setHoveredId] = useState<string | null>(null);\n const [focusedId, setFocusedId] = useState<string | null>(null);\n\n const requestedActiveId = activeId ?? internalActiveId;\n const selectedId = items.some((item) => item.id === requestedActiveId)\n ? requestedActiveId\n : (items[0]?.id ?? \"\");\n const displayedId = hoveredId ?? focusedId ?? \"\";\n const highlightedId = displayedId || (highlightActive ? selectedId : \"\");\n const displayedIndex = items.findIndex((item) => item.id === highlightedId);\n const rowTemplate = items.length ? `repeat(${items.length}, ${itemSize}px)` : undefined;\n const isHorizontal = orientation === \"horizontal\";\n\n const selectItem = (id: string) => {\n if (activeId === undefined) setInternalActiveId(id);\n onActiveChange?.(id);\n };\n\n return (\n <motion.div\n layoutRoot\n onBlur={(event) => {\n if (!event.currentTarget.contains(event.relatedTarget)) {\n setFocusedId(null);\n }\n }}\n className={cn(\n \"relative isolate flex w-full overflow-visible\",\n isHorizontal ? \"min-h-64 flex-col items-center justify-center\" : \"min-h-80\",\n className,\n )}\n >\n <nav\n aria-label={label}\n onPointerLeave={() => setHoveredId(null)}\n style={\n isHorizontal ? { gridTemplateColumns: rowTemplate } : { gridTemplateRows: rowTemplate }\n }\n className={cn(\n \"relative z-10 grid shrink-0\",\n isHorizontal ? \"h-12 w-fit max-w-full justify-center self-center\" : \"w-12 content-center\",\n railClassName,\n )}\n >\n {items.map((item, index) => {\n const selected = item.id === selectedId;\n const highlighted = item.id === highlightedId;\n const distance =\n displayedIndex < 0 ? Number.POSITIVE_INFINITY : Math.abs(index - displayedIndex);\n const scale = highlighted ? 1 : distance === 1 ? 0.68 : distance === 2 ? 0.44 : 0.25;\n\n const itemContent = (\n <>\n <motion.span\n data-slot=\"preview-rail-tick\"\n aria-hidden=\"true\"\n animate={isHorizontal ? { scaleY: scale } : { scaleX: scale }}\n transition={reduce ? { duration: 0 } : SPRING_LAYOUT}\n className={cn(\n \"block bg-current\",\n isHorizontal ? \"h-12 w-0.5 origin-bottom\" : \"h-0.5 w-12 origin-left\",\n highlighted ? \"text-foreground\" : undefined,\n )}\n />\n </>\n );\n\n const sharedClassName = cn(\n \"relative flex text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background\",\n isHorizontal ? \"h-12 w-6 items-end justify-center\" : \"h-6 w-12 items-center\",\n );\n const sharedStyle = isHorizontal ? { width: itemSize } : { height: itemSize };\n const handlePointerEnter = () => {\n if (canHover) setHoveredId(item.id);\n };\n const handleFocus = (currentTarget: HTMLElement) => {\n if (currentTarget.matches(\":focus-visible\")) {\n setFocusedId(item.id);\n }\n };\n const handleSelect = () => {\n selectItem(item.id);\n onItemSelect?.(item);\n };\n\n return item.href ? (\n <a\n key={item.id}\n data-slot=\"preview-rail-item\"\n href={item.href}\n target={item.target}\n rel={item.rel ?? (item.target === \"_blank\" ? \"noreferrer noopener\" : undefined)}\n aria-label={item.ariaLabel ?? item.label}\n aria-current={selected ? \"page\" : undefined}\n onPointerEnter={handlePointerEnter}\n onMouseEnter={handlePointerEnter}\n onPointerDown={() => setFocusedId(null)}\n onFocus={(event) => handleFocus(event.currentTarget)}\n onClick={handleSelect}\n style={sharedStyle}\n className={sharedClassName}\n >\n {itemContent}\n </a>\n ) : (\n <button\n key={item.id}\n data-slot=\"preview-rail-item\"\n type=\"button\"\n aria-label={item.ariaLabel ?? item.label}\n aria-current={selected ? \"location\" : undefined}\n onPointerEnter={handlePointerEnter}\n onMouseEnter={handlePointerEnter}\n onPointerDown={() => setFocusedId(null)}\n onFocus={(event) => handleFocus(event.currentTarget)}\n onClick={handleSelect}\n style={sharedStyle}\n className={sharedClassName}\n >\n {itemContent}\n </button>\n );\n })}\n </nav>\n\n {showPreview ? (\n <div\n aria-hidden=\"true\"\n style={\n isHorizontal ? { gridTemplateColumns: rowTemplate } : { gridTemplateRows: rowTemplate }\n }\n className={cn(\n \"pointer-events-none absolute z-50 grid\",\n isHorizontal\n ? \"top-1/2 left-1/2 h-5 w-fit max-w-full -translate-x-1/2 -translate-y-1/2 justify-center\"\n : previewSide === \"before\"\n ? \"inset-y-0 right-16 left-4 content-center\"\n : \"inset-y-0 right-4 left-16 content-center\",\n previewContainerClassName,\n )}\n >\n {items.map((item) => (\n <div\n key={item.id}\n style={isHorizontal ? { width: itemSize } : { height: itemSize }}\n className={cn(\n \"relative flex items-center\",\n isHorizontal ? \"justify-center\" : undefined,\n )}\n >\n {item.id === displayedId ? (\n <div\n className={cn(\n isHorizontal\n ? \"absolute bottom-12 left-1/2 w-72 -translate-x-1/2\"\n : cn(\"w-full max-w-sm\", previewSide === \"before\" && \"ml-auto\"),\n previewClassName,\n )}\n >\n <motion.div\n layoutId={`preview-rail-card-${uid}`}\n transition={reduce ? { duration: 0 } : SPRING_LAYOUT}\n >\n <AnimatePresence mode=\"wait\" initial={false}>\n <motion.div\n key={item.id}\n initial={\n reduce ? { opacity: 0 } : { opacity: 0, y: 4, filter: \"blur(6px)\" }\n }\n animate={\n reduce ? { opacity: 1 } : { opacity: 1, y: 0, filter: \"blur(0px)\" }\n }\n exit={\n reduce\n ? { opacity: 0 }\n : {\n opacity: 0,\n y: -2,\n filter: \"blur(4px)\",\n transition: {\n duration: 0.12,\n ease: EASE_OUT,\n },\n }\n }\n transition={{\n duration: reduce ? 0 : 0.18,\n ease: EASE_OUT,\n }}\n >\n {renderPreview ? renderPreview(item) : <DefaultPreview item={item} />}\n </motion.div>\n </AnimatePresence>\n </motion.div>\n </div>\n ) : null}\n </div>\n ))}\n </div>\n ) : null}\n\n {children ? <div className=\"min-h-0 min-w-0 flex-1\">{children}</div> : null}\n </motion.div>\n );\n}\n"],"mappings":";;;;;;;;AAuCA,SAAS,eAAe,EAAE,QAAmC;CAC3D,OACE,qBAAC,OAAD;EACE,aAAU;EACV,WAAU;EAFZ,UAAA,CAIE,oBAAC,KAAD;GAAG,aAAU;GAAqB,WAAU;GACzC,UAAA,KAAK;EACL,CAAA,GACF,KAAK,cACJ,oBAAC,OAAD;GACE,aAAU;GACV,WAAU;GAET,UAAA,KAAK;EACH,CAAA,IACH,IACD;;AAET;AAEA,SAAgB,YAAY,EAC1B,OACA,QAAQ,sBACR,cAAc,YACd,UACA,iBACA,gBACA,cACA,eACA,cAAc,MACd,cAAc,SACd,kBAAkB,OAClB,WAAW,IACX,UACA,WACA,eACA,2BACA,oBACmB;CACnB,MAAM,MAAM,MAAM;CAClB,MAAM,SAAS,iBAAiB;CAChC,MAAM,WAAW,gBAAgB;CACjC,MAAM,CAAC,kBAAkB,uBAAuB,SAAS,mBAAmB,MAAM,EAAE,EAAE,MAAM,EAAE;CAC9F,MAAM,CAAC,WAAW,gBAAgB,SAAwB,IAAI;CAC9D,MAAM,CAAC,WAAW,gBAAgB,SAAw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,WACd,6CACA,4CACN,yBACF;IAEC,UAAA,MAAM,KAAK,SACV,oBAAC,OAAD;KAEE,OAAO,eAAe,EAAE,OAAO,SAAS,IAAI,EAAE,QAAQ,SAAS;KAC/D,WAAW,GACT,8BACA,eAAe,mBAAmB,KAAA,CACpC;KAEC,UAAA,KAAK,OAAO,cACX,oBAAC,OAAD;MACE,WAAW,GACT,eACI,sDACA,GAAG,mBAAmB,gBAAgB,YAAY,SAAS,GAC/D,gBACF;MAEA,UAAA,oBAAC,OAAO,KAAR;OACE,UAAU,qBAAqB;OAC/B,YAAY,SAAS,EAAE,UAAU,EAAE,IAAI;OAEvC,UAAA,oBAAC,iBAAD;QAAiB,MAAK;QAAO,SAAS;QACpC,UAAA,oBAAC,OAAO,KAAR;SAEE,SACE,SAAS,EAAE,SAAS,EAAE,IAAI;UAAE,SAAS;UAAG,GAAG;UAAG,QAAQ;SAAY;SAEpE,SACE,SAAS,EAAE,SAAS,EAAE,IAAI;UAAE,SAAS;UAAG,GAAG;UAAG,QAAQ;SAAY;SAEpE,MACE,SACI,EAAE,SAAS,EAAE,IACb;UACE,SAAS;UACT,GAAG;UACH,QAAQ;UACR,YAAY;WACV,UAAU;WACV,MAAM;UACR;SACF;SAEN,YAAY;UACV,UAAU,SAAS,IAAI;UACvB,MAAM;SACR;SAEC,UAAA,gBAAgB,cAAc,IAAI,IAAI,oBAAC,gBAAD,EAAsB,KAAO,CAAA;QAC1D,GA1BL,KAAK,EA0BA;OACG,CAAA;MACP,CAAA;KACT,CAAA,IACH;IACD,GArDE,KAAK,EAqDP,CACN;GACE,CAAA,IACH;GAEH,WAAW,oBAAC,OAAD;IAAK,WAAU;IAA0B;GAAc,CAAA,IAAI;EAC7D;;AAEhB"}
|
|
1
|
+
{"version":3,"file":"preview-rail.js","names":[],"sources":["../../../src/components/motion/preview-rail.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type MouseEvent,\n type PointerEvent,\n type ReactNode,\n useCallback,\n useId,\n useRef,\n useState,\n} from \"react\";\nimport { AnimatePresence, motion, 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\";\n\nexport interface PreviewRailItem {\n id: string;\n label: string;\n ariaLabel?: string;\n description?: ReactNode;\n href?: string;\n target?: \"_blank\" | \"_self\" | \"_parent\" | \"_top\";\n rel?: string;\n}\n\nexport interface PreviewRailProps {\n items: PreviewRailItem[];\n label?: string;\n orientation?: \"vertical\" | \"horizontal\";\n activeId?: string;\n defaultActiveId?: string;\n onActiveChange?: (id: string) => void;\n onItemSelect?: (item: PreviewRailItem) => void;\n renderPreview?: (item: PreviewRailItem) => ReactNode;\n showPreview?: boolean;\n previewSide?: \"before\" | \"after\";\n highlightActive?: boolean;\n itemSize?: number;\n children?: ReactNode;\n className?: string;\n railClassName?: string;\n previewContainerClassName?: string;\n previewClassName?: string;\n}\n\nfunction DefaultPreview({ item }: { item: PreviewRailItem }) {\n return (\n <div\n data-slot=\"preview-rail-card\"\n className=\"rounded-2xl border border-border bg-card p-4 shadow-sm\"\n >\n <p data-slot=\"preview-rail-title\" className=\"font-medium text-card-foreground\">\n {item.label}\n </p>\n {item.description ? (\n <div\n data-slot=\"preview-rail-description\"\n className=\"mt-1 text-muted-foreground text-sm leading-6\"\n >\n {item.description}\n </div>\n ) : null}\n </div>\n );\n}\n\nexport function PreviewRail({\n items,\n label = \"Section navigation\",\n orientation = \"vertical\",\n activeId,\n defaultActiveId,\n onActiveChange,\n onItemSelect,\n renderPreview,\n showPreview = true,\n previewSide = \"after\",\n highlightActive = false,\n itemSize = 24,\n children,\n className,\n railClassName,\n previewContainerClassName,\n previewClassName,\n}: PreviewRailProps) {\n const uid = useId();\n const reduce = useReducedMotion();\n const rootRef = useRef<HTMLDivElement>(null);\n const [internalActiveId, setInternalActiveId] = useState(defaultActiveId ?? items[0]?.id ?? \"\");\n const [hoveredId, setHoveredId] = useState<string | null>(null);\n // A finger cannot hover, so a tap lights the tick instead. Kept apart from\n // the hovered one: they end in different ways, and a stray mouse move must\n // not clear a tick the keyboard or a tap chose.\n const [pinnedId, setPinnedId] = useState<string | null>(null);\n const [focusedId, setFocusedId] = useState<string | null>(null);\n // A click carries no pointerType, so the pointerdown before it is what says\n // whether the activation was a tap. Keyboard activation has none at all.\n const tap = useTapGesture<boolean>();\n const hover = useHoverGesture();\n\n const clearPinned = useCallback(() => setPinnedId(null), []);\n\n // The next tap outside the rail stands in for the pointer leaving it. The\n // card is a preview, so that tap passes through to whatever it landed on.\n useDismiss(pinnedId !== null, clearPinned, rootRef);\n\n const requestedActiveId = activeId ?? internalActiveId;\n const selectedId = items.some((item) => item.id === requestedActiveId)\n ? requestedActiveId\n : (items[0]?.id ?? \"\");\n const displayedId = hoveredId ?? pinnedId ?? focusedId ?? \"\";\n const highlightedId = displayedId || (highlightActive ? selectedId : \"\");\n const displayedIndex = items.findIndex((item) => item.id === highlightedId);\n const rowTemplate = items.length ? `repeat(${items.length}, ${itemSize}px)` : undefined;\n const isHorizontal = orientation === \"horizontal\";\n\n const selectItem = (id: string) => {\n if (activeId === undefined) setInternalActiveId(id);\n onActiveChange?.(id);\n };\n\n return (\n <motion.div\n layoutRoot\n ref={rootRef}\n onBlur={(event) => {\n // Both tick sources leave with the focus: a tap does not always land\n // focus, but when it does, tabbing away must not strand the card.\n if (!event.currentTarget.contains(event.relatedTarget)) {\n setFocusedId(null);\n setPinnedId(null);\n }\n }}\n className={cn(\n \"relative isolate flex w-full overflow-visible\",\n isHorizontal ? \"min-h-64 flex-col items-center justify-center\" : \"min-h-80\",\n className,\n )}\n >\n <nav\n aria-label={label}\n onPointerLeave={(event) => {\n // A touch pointer leaves on lift, which would clear the tick the tap\n // just chose — that one is cleared by the outside tap instead.\n if (hover.leave(event)) setHoveredId(null);\n }}\n style={\n isHorizontal ? { gridTemplateColumns: rowTemplate } : { gridTemplateRows: rowTemplate }\n }\n className={cn(\n \"relative z-10 grid shrink-0\",\n isHorizontal ? \"h-12 w-fit max-w-full justify-center self-center\" : \"w-12 content-center\",\n railClassName,\n )}\n >\n {items.map((item, index) => {\n const selected = item.id === selectedId;\n const highlighted = item.id === highlightedId;\n const distance =\n displayedIndex < 0 ? Number.POSITIVE_INFINITY : Math.abs(index - displayedIndex);\n const scale = highlighted ? 1 : distance === 1 ? 0.68 : distance === 2 ? 0.44 : 0.25;\n\n const itemContent = (\n <>\n <motion.span\n data-slot=\"preview-rail-tick\"\n aria-hidden=\"true\"\n animate={isHorizontal ? { scaleY: scale } : { scaleX: scale }}\n transition={reduce ? { duration: 0 } : SPRING_LAYOUT}\n className={cn(\n \"block bg-current\",\n isHorizontal ? \"h-12 w-0.5 origin-bottom\" : \"h-0.5 w-12 origin-left\",\n highlighted ? \"text-foreground\" : undefined,\n )}\n />\n </>\n );\n\n const sharedClassName = cn(\n \"relative flex text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background\",\n isHorizontal ? \"h-12 w-6 items-end justify-center\" : \"h-6 w-12 items-center\",\n );\n const sharedStyle = isHorizontal ? { width: itemSize } : { height: itemSize };\n const handlePointerEnter = (event: PointerEvent<HTMLElement>) => {\n if (hover.enter(event)) setHoveredId(item.id);\n };\n const handlePointerDown = (event: PointerEvent<HTMLElement>) => {\n tap.start(event, pinnedId === item.id);\n setFocusedId(null);\n };\n // A gesture the platform takes away sends no click, and a key press\n // starts an activation that never had a pointer behind it: either\n // one leaves a record the next click would read as a tap of its own.\n const dropGesture = () => tap.drop();\n const handleFocus = (currentTarget: HTMLElement) => {\n if (currentTarget.matches(\":focus-visible\")) {\n setFocusedId(item.id);\n }\n };\n const handleSelect = (event: MouseEvent<HTMLElement>) => {\n const gesture = tap.take();\n const tapped = gesture !== null && gesture.pointerType !== \"mouse\";\n\n if (tapped) {\n // A link would otherwise show its preview and leave the page in\n // the same tap, so the card is never read: the first tap lights\n // the tick, the second follows the link.\n if (item.href && !gesture.state) {\n event.preventDefault();\n setPinnedId(item.id);\n return;\n }\n setPinnedId(item.id);\n }\n\n selectItem(item.id);\n onItemSelect?.(item);\n };\n\n return item.href ? (\n <a\n key={item.id}\n data-slot=\"preview-rail-item\"\n href={item.href}\n target={item.target}\n rel={item.rel ?? (item.target === \"_blank\" ? \"noreferrer noopener\" : undefined)}\n aria-label={item.ariaLabel ?? item.label}\n aria-current={selected ? \"page\" : undefined}\n onPointerEnter={handlePointerEnter}\n onPointerDown={handlePointerDown}\n onPointerCancel={dropGesture}\n onKeyDown={dropGesture}\n onFocus={(event) => handleFocus(event.currentTarget)}\n onClick={handleSelect}\n style={sharedStyle}\n className={sharedClassName}\n >\n {itemContent}\n </a>\n ) : (\n <button\n key={item.id}\n data-slot=\"preview-rail-item\"\n type=\"button\"\n aria-label={item.ariaLabel ?? item.label}\n aria-current={selected ? \"location\" : undefined}\n onPointerEnter={handlePointerEnter}\n onPointerDown={handlePointerDown}\n onPointerCancel={dropGesture}\n onKeyDown={dropGesture}\n onFocus={(event) => handleFocus(event.currentTarget)}\n onClick={handleSelect}\n style={sharedStyle}\n className={sharedClassName}\n >\n {itemContent}\n </button>\n );\n })}\n </nav>\n\n {showPreview ? (\n <div\n aria-hidden=\"true\"\n style={\n isHorizontal ? { gridTemplateColumns: rowTemplate } : { gridTemplateRows: rowTemplate }\n }\n className={cn(\n \"pointer-events-none absolute z-50 grid\",\n isHorizontal\n ? \"top-1/2 left-1/2 h-5 w-fit max-w-full -translate-x-1/2 -translate-y-1/2 justify-center\"\n : previewSide === \"before\"\n ? \"inset-y-0 right-16 left-4 content-center\"\n : \"inset-y-0 right-4 left-16 content-center\",\n previewContainerClassName,\n )}\n >\n {items.map((item) => (\n <div\n key={item.id}\n style={isHorizontal ? { width: itemSize } : { height: itemSize }}\n className={cn(\n \"relative flex items-center\",\n isHorizontal ? \"justify-center\" : undefined,\n )}\n >\n {item.id === displayedId ? (\n <div\n className={cn(\n isHorizontal\n ? \"absolute bottom-12 left-1/2 w-72 -translate-x-1/2\"\n : cn(\"w-full max-w-sm\", previewSide === \"before\" && \"ml-auto\"),\n previewClassName,\n )}\n >\n <motion.div\n layoutId={`preview-rail-card-${uid}`}\n transition={reduce ? { duration: 0 } : SPRING_LAYOUT}\n >\n <AnimatePresence mode=\"wait\" initial={false}>\n <motion.div\n key={item.id}\n initial={\n reduce ? { opacity: 0 } : { opacity: 0, y: 4, filter: \"blur(6px)\" }\n }\n animate={\n reduce ? { opacity: 1 } : { opacity: 1, y: 0, filter: \"blur(0px)\" }\n }\n exit={\n reduce\n ? { opacity: 0 }\n : {\n opacity: 0,\n y: -2,\n filter: \"blur(4px)\",\n transition: {\n duration: 0.12,\n ease: EASE_OUT,\n },\n }\n }\n transition={{\n duration: reduce ? 0 : 0.18,\n ease: EASE_OUT,\n }}\n >\n {renderPreview ? renderPreview(item) : <DefaultPreview item={item} />}\n </motion.div>\n </AnimatePresence>\n </motion.div>\n </div>\n ) : null}\n </div>\n ))}\n </div>\n ) : null}\n\n {children ? <div className=\"min-h-0 min-w-0 flex-1\">{children}</div> : null}\n </motion.div>\n );\n}\n"],"mappings":";;;;;;;;;;AAiDA,SAAS,eAAe,EAAE,QAAmC;CAC3D,OACE,qBAAC,OAAD;EACE,aAAU;EACV,WAAU;EAFZ,UAAA,CAIE,oBAAC,KAAD;GAAG,aAAU;GAAqB,WAAU;GACzC,UAAA,KAAK;EACL,CAAA,GACF,KAAK,cACJ,oBAAC,OAAD;GACE,aAAU;GACV,WAAU;GAET,UAAA,KAAK;EACH,CAAA,IACH,IACD;;AAET;AAEA,SAAgB,YAAY,EAC1B,OACA,QAAQ,sBACR,cAAc,YACd,UACA,iBACA,gBACA,cACA,eACA,cAAc,MACd,cAAc,SACd,kBAAkB,OAClB,WAAW,IACX,UACA,WACA,eACA,2BACA,oBACmB;CACnB,MAAM,MAA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;OAC/B,YAAY,SAAS,EAAE,UAAU,EAAE,IAAI;OAEvC,UAAA,oBAAC,iBAAD;QAAiB,MAAK;QAAO,SAAS;QACpC,UAAA,oBAAC,OAAO,KAAR;SAEE,SACE,SAAS,EAAE,SAAS,EAAE,IAAI;UAAE,SAAS;UAAG,GAAG;UAAG,QAAQ;SAAY;SAEpE,SACE,SAAS,EAAE,SAAS,EAAE,IAAI;UAAE,SAAS;UAAG,GAAG;UAAG,QAAQ;SAAY;SAEpE,MACE,SACI,EAAE,SAAS,EAAE,IACb;UACE,SAAS;UACT,GAAG;UACH,QAAQ;UACR,YAAY;WACV,UAAU;WACV,MAAM;UACR;SACF;SAEN,YAAY;UACV,UAAU,SAAS,IAAI;UACvB,MAAM;SACR;SAEC,UAAA,gBAAgB,cAAc,IAAI,IAAI,oBAAC,gBAAD,EAAsB,KAAO,CAAA;QAC1D,GA1BL,KAAK,EA0BA;OACG,CAAA;MACP,CAAA;KACT,CAAA,IACH;IACD,GArDE,KAAK,EAqDP,CACN;GACE,CAAA,IACH;GAEH,WAAW,oBAAC,OAAD;IAAK,WAAU;IAA0B;GAAc,CAAA,IAAI;EAC7D;;AAEhB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
//#region src/components/motion/project-folder.d.ts
|
|
3
|
+
type ProjectFolderPreview = {
|
|
4
|
+
id: string;
|
|
5
|
+
content: ReactNode;
|
|
6
|
+
};
|
|
7
|
+
interface ProjectFolderProps {
|
|
8
|
+
title: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
previews?: ProjectFolderPreview[];
|
|
11
|
+
count?: number;
|
|
12
|
+
itemLabel?: string;
|
|
13
|
+
open?: boolean;
|
|
14
|
+
defaultOpen?: boolean;
|
|
15
|
+
onOpenChange?: (open: boolean) => void;
|
|
16
|
+
expanded?: boolean;
|
|
17
|
+
defaultExpanded?: boolean;
|
|
18
|
+
onExpandedChange?: (expanded: boolean) => void;
|
|
19
|
+
onClick?: () => void;
|
|
20
|
+
disabled?: boolean;
|
|
21
|
+
ariaLabel?: string;
|
|
22
|
+
className?: string;
|
|
23
|
+
}
|
|
24
|
+
declare function ProjectFolder({ title, description, previews, count, itemLabel, open, defaultOpen, onOpenChange, expanded, defaultExpanded, onExpandedChange, onClick, disabled, ariaLabel, className }: ProjectFolderProps): import("react").JSX.Element;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { ProjectFolder, ProjectFolderPreview, ProjectFolderProps };
|
|
27
|
+
//# sourceMappingURL=project-folder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project-folder.d.ts","names":[],"sources":["../../../src/components/motion/project-folder.tsx"],"mappings":";;KAiBY;EACV;EACA,SAAS;;UAGM;EACf;EACA;EACA,WAAW;EACX;EACA;EACA;EACA;EACA,gBAAgB;EAChB;EACA;EACA,oBAAoB;EACpB;EACA;EACA;EACA;;iBA4Bc,gBACd,OACA,aACA,UACA,OACA,WACA,MACA,aACA,cACA,UACA,iBACA,kBACA,SACA,UACA,WACA,aACC,qCAAkB,IAAA"}
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useHoverCapable } from "../../hooks/use-hover-capable.js";
|
|
3
|
+
import { SPRING_LAYOUT, SPRING_PRESS } from "../../lib/ease.js";
|
|
4
|
+
import { useCallback, useEffect, useId, useRef, useState } from "react";
|
|
5
|
+
import { cn } from "@kumix/utils";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { AnimatePresence, LayoutGroup, motion, useReducedMotion } from "motion/react";
|
|
8
|
+
import { X } from "lucide-react";
|
|
9
|
+
import { createPortal } from "react-dom";
|
|
10
|
+
//#region src/components/motion/project-folder.tsx
|
|
11
|
+
const MAX_PREVIEWS = 5;
|
|
12
|
+
const FOCUSABLE_SELECTOR = [
|
|
13
|
+
"a[href]",
|
|
14
|
+
"button:not([disabled])",
|
|
15
|
+
"input:not([disabled])",
|
|
16
|
+
"select:not([disabled])",
|
|
17
|
+
"textarea:not([disabled])",
|
|
18
|
+
"[tabindex]:not([tabindex=\"-1\"])"
|
|
19
|
+
].join(",");
|
|
20
|
+
function getPreviewTransform(index, count) {
|
|
21
|
+
const offset = index - (count - 1) / 2;
|
|
22
|
+
const distance = Math.abs(offset);
|
|
23
|
+
const centerLift = Math.max(0, 2 - distance) * 8;
|
|
24
|
+
return {
|
|
25
|
+
x: offset * 44,
|
|
26
|
+
y: 8 - centerLift,
|
|
27
|
+
rotate: offset * 6,
|
|
28
|
+
scale: distance === 0 ? 1.04 : distance === 1 ? .95 : .88,
|
|
29
|
+
opacity: distance === 0 ? 1 : distance === 1 ? .78 : .58,
|
|
30
|
+
zIndex: 10 - distance
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function ProjectFolder({ title, description = "Updated recently", previews = [], count = previews.length, itemLabel = "file", open, defaultOpen = false, onOpenChange, expanded, defaultExpanded = false, onExpandedChange, onClick, disabled = false, ariaLabel, className }) {
|
|
34
|
+
const reduce = useReducedMotion();
|
|
35
|
+
const canHover = useHoverCapable();
|
|
36
|
+
const layoutGroupId = useId();
|
|
37
|
+
const dialogTitleId = `${layoutGroupId}-title`;
|
|
38
|
+
const hoveredRef = useRef(false);
|
|
39
|
+
const focusedRef = useRef(false);
|
|
40
|
+
const restoringFocusRef = useRef(false);
|
|
41
|
+
const folderButtonRef = useRef(null);
|
|
42
|
+
const closeButtonRef = useRef(null);
|
|
43
|
+
const dialogRef = useRef(null);
|
|
44
|
+
const [mounted, setMounted] = useState(false);
|
|
45
|
+
const [internalOpen, setInternalOpen] = useState(defaultOpen);
|
|
46
|
+
const [internalExpanded, setInternalExpanded] = useState(defaultExpanded);
|
|
47
|
+
const [isClosing, setIsClosing] = useState(false);
|
|
48
|
+
const openControlled = open !== void 0;
|
|
49
|
+
const expandedControlled = expanded !== void 0;
|
|
50
|
+
const isExpanded = expanded ?? internalExpanded;
|
|
51
|
+
const isOpen = (open ?? internalOpen) || isExpanded;
|
|
52
|
+
const previewItems = previews.slice(0, MAX_PREVIEWS);
|
|
53
|
+
const transition = reduce ? { duration: 0 } : SPRING_LAYOUT;
|
|
54
|
+
const countText = `${count} ${itemLabel}${count === 1 ? "" : "s"}`;
|
|
55
|
+
const setOpen = useCallback((next) => {
|
|
56
|
+
if (disabled) return;
|
|
57
|
+
if (!openControlled) setInternalOpen(next);
|
|
58
|
+
onOpenChange?.(next);
|
|
59
|
+
}, [
|
|
60
|
+
disabled,
|
|
61
|
+
onOpenChange,
|
|
62
|
+
openControlled
|
|
63
|
+
]);
|
|
64
|
+
const setExpanded = useCallback((next) => {
|
|
65
|
+
if (disabled || previewItems.length === 0) return;
|
|
66
|
+
if (!expandedControlled) setInternalExpanded(next);
|
|
67
|
+
onExpandedChange?.(next);
|
|
68
|
+
}, [
|
|
69
|
+
disabled,
|
|
70
|
+
expandedControlled,
|
|
71
|
+
onExpandedChange,
|
|
72
|
+
previewItems.length
|
|
73
|
+
]);
|
|
74
|
+
const finishClose = useCallback(() => {
|
|
75
|
+
setIsClosing(false);
|
|
76
|
+
restoringFocusRef.current = true;
|
|
77
|
+
requestAnimationFrame(() => folderButtonRef.current?.focus());
|
|
78
|
+
}, []);
|
|
79
|
+
const closeOverlay = useCallback(() => {
|
|
80
|
+
setIsClosing(true);
|
|
81
|
+
setOpen(false);
|
|
82
|
+
setExpanded(false);
|
|
83
|
+
}, [setExpanded, setOpen]);
|
|
84
|
+
useEffect(() => setMounted(true), []);
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
if (reduce && isClosing) finishClose();
|
|
87
|
+
}, [
|
|
88
|
+
finishClose,
|
|
89
|
+
isClosing,
|
|
90
|
+
reduce
|
|
91
|
+
]);
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
if (!isExpanded) return;
|
|
94
|
+
const previousOverflow = document.body.style.overflow;
|
|
95
|
+
const focusFrame = requestAnimationFrame(() => closeButtonRef.current?.focus());
|
|
96
|
+
document.body.style.overflow = "hidden";
|
|
97
|
+
const handleKeyDown = (event) => {
|
|
98
|
+
if (event.key === "Escape") {
|
|
99
|
+
event.preventDefault();
|
|
100
|
+
closeOverlay();
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (event.key !== "Tab" || !dialogRef.current) return;
|
|
104
|
+
const focusable = Array.from(dialogRef.current.querySelectorAll(FOCUSABLE_SELECTOR)).filter((element) => element.tabIndex >= 0);
|
|
105
|
+
const first = focusable[0];
|
|
106
|
+
const last = focusable.at(-1);
|
|
107
|
+
if (!first || !last) return;
|
|
108
|
+
if (event.shiftKey && document.activeElement === first) {
|
|
109
|
+
event.preventDefault();
|
|
110
|
+
last.focus();
|
|
111
|
+
} else if (!event.shiftKey && document.activeElement === last) {
|
|
112
|
+
event.preventDefault();
|
|
113
|
+
first.focus();
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
117
|
+
return () => {
|
|
118
|
+
cancelAnimationFrame(focusFrame);
|
|
119
|
+
document.body.style.overflow = previousOverflow;
|
|
120
|
+
document.removeEventListener("keydown", handleKeyDown);
|
|
121
|
+
};
|
|
122
|
+
}, [closeOverlay, isExpanded]);
|
|
123
|
+
const handleFolderClick = () => {
|
|
124
|
+
setIsClosing(false);
|
|
125
|
+
setExpanded(true);
|
|
126
|
+
setOpen(true);
|
|
127
|
+
onClick?.();
|
|
128
|
+
};
|
|
129
|
+
const overlay = isExpanded || isClosing ? /* @__PURE__ */ jsxs("div", {
|
|
130
|
+
ref: dialogRef,
|
|
131
|
+
role: "dialog",
|
|
132
|
+
"aria-modal": "true",
|
|
133
|
+
"aria-labelledby": dialogTitleId,
|
|
134
|
+
"aria-hidden": isExpanded ? void 0 : "true",
|
|
135
|
+
className: cn("fixed inset-0 z-50 flex items-start justify-center overflow-y-auto sm:items-center", isClosing && "pointer-events-none"),
|
|
136
|
+
children: [/* @__PURE__ */ jsx(AnimatePresence, {
|
|
137
|
+
initial: false,
|
|
138
|
+
children: isExpanded ? /* @__PURE__ */ jsx(motion.button, {
|
|
139
|
+
type: "button",
|
|
140
|
+
tabIndex: -1,
|
|
141
|
+
"aria-label": "Close file overlay",
|
|
142
|
+
onClick: closeOverlay,
|
|
143
|
+
initial: { opacity: 0 },
|
|
144
|
+
animate: { opacity: 1 },
|
|
145
|
+
exit: { opacity: 0 },
|
|
146
|
+
transition: reduce ? { duration: 0 } : { duration: .18 },
|
|
147
|
+
className: "absolute inset-0 cursor-default bg-background/80 backdrop-blur-xl"
|
|
148
|
+
}, "project-files-backdrop") : null
|
|
149
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
150
|
+
className: "relative z-10 w-full max-w-5xl px-6 py-8",
|
|
151
|
+
children: [/* @__PURE__ */ jsx(AnimatePresence, {
|
|
152
|
+
initial: false,
|
|
153
|
+
children: isExpanded ? /* @__PURE__ */ jsxs(motion.div, {
|
|
154
|
+
initial: {
|
|
155
|
+
opacity: 0,
|
|
156
|
+
y: reduce ? 0 : 8
|
|
157
|
+
},
|
|
158
|
+
animate: {
|
|
159
|
+
opacity: 1,
|
|
160
|
+
y: 0
|
|
161
|
+
},
|
|
162
|
+
exit: {
|
|
163
|
+
opacity: 0,
|
|
164
|
+
y: reduce ? 0 : -8
|
|
165
|
+
},
|
|
166
|
+
transition: reduce ? { duration: 0 } : { duration: .18 },
|
|
167
|
+
className: "mb-6 flex items-center justify-between gap-4",
|
|
168
|
+
children: [/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("h2", {
|
|
169
|
+
id: dialogTitleId,
|
|
170
|
+
className: "font-medium text-foreground text-xl",
|
|
171
|
+
children: title
|
|
172
|
+
}), /* @__PURE__ */ jsx("p", {
|
|
173
|
+
className: "mt-1 text-muted-foreground text-sm",
|
|
174
|
+
children: countText
|
|
175
|
+
})] }), /* @__PURE__ */ jsx("button", {
|
|
176
|
+
ref: closeButtonRef,
|
|
177
|
+
type: "button",
|
|
178
|
+
onClick: closeOverlay,
|
|
179
|
+
"aria-label": `Close ${title}`,
|
|
180
|
+
className: "flex size-10 items-center justify-center rounded-full border border-foreground/10 bg-background/50 text-muted-foreground backdrop-blur-xl transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
|
|
181
|
+
children: /* @__PURE__ */ jsx(X, {
|
|
182
|
+
className: "size-4",
|
|
183
|
+
"aria-hidden": "true"
|
|
184
|
+
})
|
|
185
|
+
})]
|
|
186
|
+
}, "project-files-header") : null
|
|
187
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
188
|
+
className: "grid grid-cols-2 place-items-center gap-3 sm:grid-cols-3 lg:grid-cols-5",
|
|
189
|
+
children: isExpanded ? previewItems.map((preview) => /* @__PURE__ */ jsx(motion.div, {
|
|
190
|
+
layoutId: `file-${preview.id}`,
|
|
191
|
+
transition,
|
|
192
|
+
className: "aspect-3/4 w-full max-w-40 overflow-hidden rounded-xl border border-foreground/10 bg-background/50 backdrop-blur-xl",
|
|
193
|
+
children: preview.content
|
|
194
|
+
}, preview.id)) : null
|
|
195
|
+
})]
|
|
196
|
+
})]
|
|
197
|
+
}) : null;
|
|
198
|
+
return /* @__PURE__ */ jsxs(LayoutGroup, {
|
|
199
|
+
id: layoutGroupId,
|
|
200
|
+
children: [/* @__PURE__ */ jsxs(motion.button, {
|
|
201
|
+
ref: folderButtonRef,
|
|
202
|
+
type: "button",
|
|
203
|
+
disabled,
|
|
204
|
+
"aria-label": ariaLabel,
|
|
205
|
+
"aria-haspopup": "dialog",
|
|
206
|
+
"aria-expanded": isExpanded,
|
|
207
|
+
"data-open": isOpen ? "true" : "false",
|
|
208
|
+
"data-expanded": isExpanded ? "true" : "false",
|
|
209
|
+
tabIndex: isExpanded ? -1 : void 0,
|
|
210
|
+
onPointerEnter: () => {
|
|
211
|
+
if (!canHover) return;
|
|
212
|
+
hoveredRef.current = true;
|
|
213
|
+
setOpen(true);
|
|
214
|
+
},
|
|
215
|
+
onPointerLeave: () => {
|
|
216
|
+
if (!canHover) return;
|
|
217
|
+
hoveredRef.current = false;
|
|
218
|
+
if (!isExpanded && !isClosing) setOpen(focusedRef.current);
|
|
219
|
+
},
|
|
220
|
+
onFocus: () => {
|
|
221
|
+
if (restoringFocusRef.current) {
|
|
222
|
+
restoringFocusRef.current = false;
|
|
223
|
+
focusedRef.current = false;
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
focusedRef.current = true;
|
|
227
|
+
setOpen(true);
|
|
228
|
+
},
|
|
229
|
+
onBlur: () => {
|
|
230
|
+
focusedRef.current = false;
|
|
231
|
+
if (!isExpanded && !isClosing) setOpen(hoveredRef.current);
|
|
232
|
+
},
|
|
233
|
+
onClick: handleFolderClick,
|
|
234
|
+
whileTap: reduce || disabled ? void 0 : { scale: .98 },
|
|
235
|
+
transition: reduce ? { duration: 0 } : SPRING_PRESS,
|
|
236
|
+
className: cn("perspective-[1200px] relative block h-56 w-72 select-none rounded-2xl text-left outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-4 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50", className),
|
|
237
|
+
children: [
|
|
238
|
+
/* @__PURE__ */ jsx(motion.span, {
|
|
239
|
+
"aria-hidden": "true",
|
|
240
|
+
animate: { rotateX: isOpen && !reduce ? 15 : 0 },
|
|
241
|
+
transition,
|
|
242
|
+
className: "absolute inset-0 origin-[center_bottom] rounded-2xl border border-foreground/10 bg-background/25 backdrop-blur-xl"
|
|
243
|
+
}),
|
|
244
|
+
/* @__PURE__ */ jsx("span", {
|
|
245
|
+
"aria-hidden": "true",
|
|
246
|
+
className: "pointer-events-none absolute inset-0",
|
|
247
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
248
|
+
className: "absolute top-0 left-1/2 block h-0 w-0",
|
|
249
|
+
children: /* @__PURE__ */ jsx(AnimatePresence, {
|
|
250
|
+
initial: false,
|
|
251
|
+
children: !isExpanded ? previewItems.map((preview, index) => {
|
|
252
|
+
const opened = getPreviewTransform(index, previewItems.length);
|
|
253
|
+
return /* @__PURE__ */ jsx(motion.span, {
|
|
254
|
+
layoutId: `file-${preview.id}`,
|
|
255
|
+
initial: false,
|
|
256
|
+
animate: isOpen && !reduce ? {
|
|
257
|
+
x: opened.x * 1.4,
|
|
258
|
+
y: opened.y - 8,
|
|
259
|
+
rotate: opened.rotate * 1.3,
|
|
260
|
+
scale: opened.scale * 1.02,
|
|
261
|
+
opacity: Math.min(1, opened.opacity + .18)
|
|
262
|
+
} : {
|
|
263
|
+
x: opened.x,
|
|
264
|
+
y: opened.y,
|
|
265
|
+
rotate: opened.rotate,
|
|
266
|
+
scale: opened.scale,
|
|
267
|
+
opacity: opened.opacity
|
|
268
|
+
},
|
|
269
|
+
transition,
|
|
270
|
+
onLayoutAnimationComplete: () => {
|
|
271
|
+
if (isClosing && index === 0) finishClose();
|
|
272
|
+
},
|
|
273
|
+
className: "absolute top-0 left-0 -ml-12 block h-40 w-24 overflow-hidden rounded-lg border border-foreground/10 bg-background/45 backdrop-blur-lg",
|
|
274
|
+
style: { zIndex: opened.zIndex },
|
|
275
|
+
children: preview.content
|
|
276
|
+
}, preview.id);
|
|
277
|
+
}) : null
|
|
278
|
+
})
|
|
279
|
+
})
|
|
280
|
+
}),
|
|
281
|
+
/* @__PURE__ */ jsxs(motion.span, {
|
|
282
|
+
initial: false,
|
|
283
|
+
animate: { rotateX: isOpen && !reduce ? -25 : 0 },
|
|
284
|
+
transition,
|
|
285
|
+
className: "backface-hidden absolute inset-x-0 bottom-0 z-20 origin-[center_bottom] overflow-hidden rounded-2xl border border-foreground/10 bg-background/60 backdrop-blur-2xl",
|
|
286
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
287
|
+
className: "flex h-16 items-center px-4",
|
|
288
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
289
|
+
className: "line-clamp-2 font-medium text-foreground text-xl leading-tight",
|
|
290
|
+
children: title
|
|
291
|
+
})
|
|
292
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
293
|
+
className: "flex h-12 items-center justify-between gap-3 border-foreground/10 border-t px-4",
|
|
294
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
295
|
+
className: "shrink-0 font-medium text-foreground/70 text-sm",
|
|
296
|
+
children: countText
|
|
297
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
298
|
+
className: "truncate text-muted-foreground text-sm",
|
|
299
|
+
children: description
|
|
300
|
+
})]
|
|
301
|
+
})]
|
|
302
|
+
})
|
|
303
|
+
]
|
|
304
|
+
}), mounted ? createPortal(overlay, document.body) : null]
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
//#endregion
|
|
308
|
+
export { ProjectFolder };
|
|
309
|
+
|
|
310
|
+
//# sourceMappingURL=project-folder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project-folder.js","names":[],"sources":["../../../src/components/motion/project-folder.tsx"],"sourcesContent":["\"use client\";\n\nimport { type ReactNode, useCallback, useEffect, useId, useRef, useState } from \"react\";\nimport { X } from \"lucide-react\";\nimport {\n AnimatePresence,\n LayoutGroup,\n motion,\n type Transition,\n useReducedMotion,\n} from \"motion/react\";\nimport { createPortal } from \"react-dom\";\n\nimport { cn } from \"@kumix/utils\";\nimport { useHoverCapable } from \"../../hooks/use-hover-capable\";\nimport { SPRING_LAYOUT, SPRING_PRESS } from \"../../lib/ease\";\n\nexport type ProjectFolderPreview = {\n id: string;\n content: ReactNode;\n};\n\nexport interface ProjectFolderProps {\n title: string;\n description?: string;\n previews?: ProjectFolderPreview[];\n count?: number;\n itemLabel?: string;\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n expanded?: boolean;\n defaultExpanded?: boolean;\n onExpandedChange?: (expanded: boolean) => void;\n onClick?: () => void;\n disabled?: boolean;\n ariaLabel?: string;\n className?: string;\n}\n\nconst MAX_PREVIEWS = 5;\nconst FOCUSABLE_SELECTOR = [\n \"a[href]\",\n \"button:not([disabled])\",\n \"input:not([disabled])\",\n \"select:not([disabled])\",\n \"textarea:not([disabled])\",\n '[tabindex]:not([tabindex=\"-1\"])',\n].join(\",\");\n\nfunction getPreviewTransform(index: number, count: number) {\n const offset = index - (count - 1) / 2;\n const distance = Math.abs(offset);\n const centerLift = Math.max(0, 2 - distance) * 8;\n\n return {\n x: offset * 44,\n y: 8 - centerLift,\n rotate: offset * 6,\n scale: distance === 0 ? 1.04 : distance === 1 ? 0.95 : 0.88,\n opacity: distance === 0 ? 1 : distance === 1 ? 0.78 : 0.58,\n zIndex: 10 - distance,\n };\n}\n\nexport function ProjectFolder({\n title,\n description = \"Updated recently\",\n previews = [],\n count = previews.length,\n itemLabel = \"file\",\n open,\n defaultOpen = false,\n onOpenChange,\n expanded,\n defaultExpanded = false,\n onExpandedChange,\n onClick,\n disabled = false,\n ariaLabel,\n className,\n}: ProjectFolderProps) {\n const reduce = useReducedMotion();\n const canHover = useHoverCapable();\n const layoutGroupId = useId();\n const dialogTitleId = `${layoutGroupId}-title`;\n const hoveredRef = useRef(false);\n const focusedRef = useRef(false);\n const restoringFocusRef = useRef(false);\n const folderButtonRef = useRef<HTMLButtonElement>(null);\n const closeButtonRef = useRef<HTMLButtonElement>(null);\n const dialogRef = useRef<HTMLDivElement>(null);\n const [mounted, setMounted] = useState(false);\n const [internalOpen, setInternalOpen] = useState(defaultOpen);\n const [internalExpanded, setInternalExpanded] = useState(defaultExpanded);\n const [isClosing, setIsClosing] = useState(false);\n const openControlled = open !== undefined;\n const expandedControlled = expanded !== undefined;\n const isExpanded = expanded ?? internalExpanded;\n const isOpen = (open ?? internalOpen) || isExpanded;\n const previewItems = previews.slice(0, MAX_PREVIEWS);\n const transition: Transition = reduce ? { duration: 0 } : SPRING_LAYOUT;\n const countText = `${count} ${itemLabel}${count === 1 ? \"\" : \"s\"}`;\n\n const setOpen = useCallback(\n (next: boolean) => {\n if (disabled) return;\n if (!openControlled) setInternalOpen(next);\n onOpenChange?.(next);\n },\n [disabled, onOpenChange, openControlled],\n );\n\n const setExpanded = useCallback(\n (next: boolean) => {\n if (disabled || previewItems.length === 0) return;\n if (!expandedControlled) setInternalExpanded(next);\n onExpandedChange?.(next);\n },\n [disabled, expandedControlled, onExpandedChange, previewItems.length],\n );\n\n const finishClose = useCallback(() => {\n setIsClosing(false);\n restoringFocusRef.current = true;\n requestAnimationFrame(() => folderButtonRef.current?.focus());\n }, []);\n\n const closeOverlay = useCallback(() => {\n setIsClosing(true);\n setOpen(false);\n setExpanded(false);\n }, [setExpanded, setOpen]);\n\n useEffect(() => setMounted(true), []);\n\n useEffect(() => {\n if (reduce && isClosing) finishClose();\n }, [finishClose, isClosing, reduce]);\n\n useEffect(() => {\n if (!isExpanded) return;\n\n const previousOverflow = document.body.style.overflow;\n const focusFrame = requestAnimationFrame(() => closeButtonRef.current?.focus());\n\n document.body.style.overflow = \"hidden\";\n\n const handleKeyDown = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") {\n event.preventDefault();\n closeOverlay();\n return;\n }\n if (event.key !== \"Tab\" || !dialogRef.current) return;\n\n const focusable = Array.from(\n dialogRef.current.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR),\n ).filter((element) => element.tabIndex >= 0);\n const first = focusable[0];\n const last = focusable.at(-1);\n if (!first || !last) return;\n\n if (event.shiftKey && document.activeElement === first) {\n event.preventDefault();\n last.focus();\n } else if (!event.shiftKey && document.activeElement === last) {\n event.preventDefault();\n first.focus();\n }\n };\n\n document.addEventListener(\"keydown\", handleKeyDown);\n return () => {\n cancelAnimationFrame(focusFrame);\n document.body.style.overflow = previousOverflow;\n document.removeEventListener(\"keydown\", handleKeyDown);\n };\n }, [closeOverlay, isExpanded]);\n\n const handleFolderClick = () => {\n setIsClosing(false);\n setExpanded(true);\n setOpen(true);\n onClick?.();\n };\n\n const overlay =\n isExpanded || isClosing ? (\n <div\n ref={dialogRef}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-labelledby={dialogTitleId}\n aria-hidden={isExpanded ? undefined : \"true\"}\n className={cn(\n \"fixed inset-0 z-50 flex items-start justify-center overflow-y-auto sm:items-center\",\n isClosing && \"pointer-events-none\",\n )}\n >\n <AnimatePresence initial={false}>\n {isExpanded ? (\n <motion.button\n key=\"project-files-backdrop\"\n type=\"button\"\n tabIndex={-1}\n aria-label=\"Close file overlay\"\n onClick={closeOverlay}\n initial={{ opacity: 0 }}\n animate={{ opacity: 1 }}\n exit={{ opacity: 0 }}\n transition={reduce ? { duration: 0 } : { duration: 0.18 }}\n className=\"absolute inset-0 cursor-default bg-background/80 backdrop-blur-xl\"\n />\n ) : null}\n </AnimatePresence>\n\n <div className=\"relative z-10 w-full max-w-5xl px-6 py-8\">\n <AnimatePresence initial={false}>\n {isExpanded ? (\n <motion.div\n key=\"project-files-header\"\n initial={{ opacity: 0, y: reduce ? 0 : 8 }}\n animate={{ opacity: 1, y: 0 }}\n exit={{ opacity: 0, y: reduce ? 0 : -8 }}\n transition={reduce ? { duration: 0 } : { duration: 0.18 }}\n className=\"mb-6 flex items-center justify-between gap-4\"\n >\n <div>\n <h2 id={dialogTitleId} className=\"font-medium text-foreground text-xl\">\n {title}\n </h2>\n <p className=\"mt-1 text-muted-foreground text-sm\">{countText}</p>\n </div>\n <button\n ref={closeButtonRef}\n type=\"button\"\n onClick={closeOverlay}\n aria-label={`Close ${title}`}\n className=\"flex size-10 items-center justify-center rounded-full border border-foreground/10 bg-background/50 text-muted-foreground backdrop-blur-xl transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n >\n <X className=\"size-4\" aria-hidden=\"true\" />\n </button>\n </motion.div>\n ) : null}\n </AnimatePresence>\n\n <div className=\"grid grid-cols-2 place-items-center gap-3 sm:grid-cols-3 lg:grid-cols-5\">\n {isExpanded\n ? previewItems.map((preview) => (\n <motion.div\n key={preview.id}\n layoutId={`file-${preview.id}`}\n transition={transition}\n className=\"aspect-3/4 w-full max-w-40 overflow-hidden rounded-xl border border-foreground/10 bg-background/50 backdrop-blur-xl\"\n >\n {preview.content}\n </motion.div>\n ))\n : null}\n </div>\n </div>\n </div>\n ) : null;\n\n return (\n <LayoutGroup id={layoutGroupId}>\n <motion.button\n ref={folderButtonRef}\n type=\"button\"\n disabled={disabled}\n aria-label={ariaLabel}\n aria-haspopup=\"dialog\"\n aria-expanded={isExpanded}\n data-open={isOpen ? \"true\" : \"false\"}\n data-expanded={isExpanded ? \"true\" : \"false\"}\n tabIndex={isExpanded ? -1 : undefined}\n onPointerEnter={() => {\n if (!canHover) return;\n hoveredRef.current = true;\n setOpen(true);\n }}\n onPointerLeave={() => {\n if (!canHover) return;\n hoveredRef.current = false;\n if (!isExpanded && !isClosing) setOpen(focusedRef.current);\n }}\n onFocus={() => {\n if (restoringFocusRef.current) {\n restoringFocusRef.current = false;\n focusedRef.current = false;\n return;\n }\n focusedRef.current = true;\n setOpen(true);\n }}\n onBlur={() => {\n focusedRef.current = false;\n if (!isExpanded && !isClosing) setOpen(hoveredRef.current);\n }}\n onClick={handleFolderClick}\n whileTap={reduce || disabled ? undefined : { scale: 0.98 }}\n transition={reduce ? { duration: 0 } : SPRING_PRESS}\n className={cn(\n \"perspective-[1200px] relative block h-56 w-72 select-none rounded-2xl text-left outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-4 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50\",\n className,\n )}\n >\n <motion.span\n aria-hidden=\"true\"\n animate={{ rotateX: isOpen && !reduce ? 15 : 0 }}\n transition={transition}\n className=\"absolute inset-0 origin-[center_bottom] rounded-2xl border border-foreground/10 bg-background/25 backdrop-blur-xl\"\n />\n\n <span aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0\">\n <span className=\"absolute top-0 left-1/2 block h-0 w-0\">\n <AnimatePresence initial={false}>\n {!isExpanded\n ? previewItems.map((preview, index) => {\n const opened = getPreviewTransform(index, previewItems.length);\n return (\n <motion.span\n key={preview.id}\n layoutId={`file-${preview.id}`}\n initial={false}\n animate={\n isOpen && !reduce\n ? {\n x: opened.x * 1.4,\n y: opened.y - 8,\n rotate: opened.rotate * 1.3,\n scale: opened.scale * 1.02,\n opacity: Math.min(1, opened.opacity + 0.18),\n }\n : {\n x: opened.x,\n y: opened.y,\n rotate: opened.rotate,\n scale: opened.scale,\n opacity: opened.opacity,\n }\n }\n transition={transition}\n onLayoutAnimationComplete={() => {\n if (isClosing && index === 0) finishClose();\n }}\n className=\"absolute top-0 left-0 -ml-12 block h-40 w-24 overflow-hidden rounded-lg border border-foreground/10 bg-background/45 backdrop-blur-lg\"\n style={{ zIndex: opened.zIndex }}\n >\n {preview.content}\n </motion.span>\n );\n })\n : null}\n </AnimatePresence>\n </span>\n </span>\n\n <motion.span\n initial={false}\n animate={{ rotateX: isOpen && !reduce ? -25 : 0 }}\n transition={transition}\n className=\"backface-hidden absolute inset-x-0 bottom-0 z-20 origin-[center_bottom] overflow-hidden rounded-2xl border border-foreground/10 bg-background/60 backdrop-blur-2xl\"\n >\n <span className=\"flex h-16 items-center px-4\">\n <span className=\"line-clamp-2 font-medium text-foreground text-xl leading-tight\">\n {title}\n </span>\n </span>\n <span className=\"flex h-12 items-center justify-between gap-3 border-foreground/10 border-t px-4\">\n <span className=\"shrink-0 font-medium text-foreground/70 text-sm\">{countText}</span>\n <span className=\"truncate text-muted-foreground text-sm\">{description}</span>\n </span>\n </motion.span>\n </motion.button>\n\n {mounted ? createPortal(overlay, document.body) : null}\n </LayoutGroup>\n );\n}\n"],"mappings":";;;;;;;;;;AAwCA,MAAM,eAAe;AACrB,MAAM,qBAAqB;CACzB;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,GAAG;AAEV,SAAS,oBAAoB,OAAe,OAAe;CACzD,MAAM,SAAS,SAAS,QAAQ,KAAK;CACrC,MAAM,WAAW,KAAK,IAAI,MAAM;CAChC,MAAM,aAAa,KAAK,IAAI,GAAG,IAAI,QAAQ,IAAI;CAE/C,OAAO;EACL,GAAG,SAAS;EACZ,GAAG,IAAI;EACP,QAAQ,S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AC,QAAD;OAAM,WAAU;OAA0C,UAAA;MAAkB,CAAA,CACxE;KACK,CAAA,CAAA;;GACA;EAEd,CAAA,GAAA,UAAU,aAAa,SAAS,SAAS,IAAI,IAAI,IACvC;;AAEjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pull-to-refresh.d.ts","names":[],"sources":["../../../src/components/motion/pull-to-refresh.tsx"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"pull-to-refresh.d.ts","names":[],"sources":["../../../src/components/motion/pull-to-refresh.tsx"],"mappings":";;KAwBY;UAEK;;EAEf,wBAAwB;EACxB,UAAU;;EAEV;EACA;;EAEA;;EAEA;;EAEA;EACA,eAAe;EACf,eAAe;EACf,kBAAkB;EAClB;EACA;EACA;EACA;;iBAsJc,gBACd,WACA,UACA,YACA,UACA,WACA,SACA,cACA,cACA,cACA,iBACA,WACA,WACA,kBACA,sBACC,qCAAkB,IAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { TOUCH_GESTURE_CONTENT_CLASS, capturePointer } from "../../lib/touch.js";
|
|
2
3
|
import { EASE_IN_OUT, EASE_OUT, SPRING_PANEL, SPRING_SWAP } from "../../lib/ease.js";
|
|
3
4
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
4
5
|
import { cn } from "@kumix/utils";
|
|
@@ -305,9 +306,9 @@ function PullToRefresh({ onRefresh, children, refreshing = false, disabled = fal
|
|
|
305
306
|
useEffect(() => {
|
|
306
307
|
return () => animationRef.current?.stop();
|
|
307
308
|
}, []);
|
|
308
|
-
const
|
|
309
|
-
if (event.pointerType
|
|
310
|
-
event.currentTarget
|
|
309
|
+
const startPointerPull = (event) => {
|
|
310
|
+
if (event.pointerType === "touch" || event.button !== 0 || event.currentTarget.scrollTop > 0 || disabled || isRefreshing) return;
|
|
311
|
+
capturePointer(event.currentTarget, event.pointerId);
|
|
311
312
|
gestureRef.current = {
|
|
312
313
|
active: true,
|
|
313
314
|
startX: event.clientX,
|
|
@@ -315,7 +316,7 @@ function PullToRefresh({ onRefresh, children, refreshing = false, disabled = fal
|
|
|
315
316
|
pointerId: event.pointerId
|
|
316
317
|
};
|
|
317
318
|
};
|
|
318
|
-
const
|
|
319
|
+
const movePointerPull = (event) => {
|
|
319
320
|
const gesture = gestureRef.current;
|
|
320
321
|
if (!gesture.active || gesture.pointerId !== event.pointerId) return;
|
|
321
322
|
const deltaX = event.clientX - gesture.startX;
|
|
@@ -331,15 +332,15 @@ function PullToRefresh({ onRefresh, children, refreshing = false, disabled = fal
|
|
|
331
332
|
"aria-busy": isRefreshing,
|
|
332
333
|
"data-state": status,
|
|
333
334
|
"data-disabled": disabled || void 0,
|
|
334
|
-
onPointerDown:
|
|
335
|
-
onPointerMove:
|
|
335
|
+
onPointerDown: startPointerPull,
|
|
336
|
+
onPointerMove: movePointerPull,
|
|
336
337
|
onPointerUp: (event) => {
|
|
337
338
|
if (gestureRef.current.pointerId === event.pointerId) finishPull();
|
|
338
339
|
},
|
|
339
340
|
onPointerCancel: (event) => {
|
|
340
341
|
if (gestureRef.current.pointerId === event.pointerId) finishPull();
|
|
341
342
|
},
|
|
342
|
-
className: cn("relative w-full overflow-y-auto overscroll-contain bg-background", status === "pulling" || status === "ready" ? "cursor-grabbing select-none" : "cursor-grab", (disabled || isRefreshing) && "cursor-default", className),
|
|
343
|
+
className: cn("relative w-full overflow-y-auto overscroll-contain bg-background", TOUCH_GESTURE_CONTENT_CLASS, status === "pulling" || status === "ready" ? "cursor-grabbing select-none" : "cursor-grab", (disabled || isRefreshing) && "cursor-default", className),
|
|
343
344
|
children: [/* @__PURE__ */ jsxs(motion.div, {
|
|
344
345
|
"aria-live": "polite",
|
|
345
346
|
"aria-atomic": "true",
|