@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, releasePointer } from "../../lib/touch.js";
|
|
2
3
|
import { Children, useCallback, useEffect, useRef, useState } from "react";
|
|
3
4
|
import { cn } from "@kumix/utils";
|
|
4
5
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -150,7 +151,7 @@ function CylinderCarousel({ children, itemSize = 200, visibleItems = 5, variant
|
|
|
150
151
|
e.preventDefault();
|
|
151
152
|
stopGlide();
|
|
152
153
|
draggingRef.current = true;
|
|
153
|
-
e.currentTarget
|
|
154
|
+
capturePointer(e.currentTarget, e.pointerId);
|
|
154
155
|
const now = performance.now();
|
|
155
156
|
drag.current = {
|
|
156
157
|
startX: e.clientX,
|
|
@@ -177,7 +178,7 @@ function CylinderCarousel({ children, itemSize = 200, visibleItems = 5, variant
|
|
|
177
178
|
const onPointerUp = useCallback((e) => {
|
|
178
179
|
if (!draggingRef.current) return;
|
|
179
180
|
draggingRef.current = false;
|
|
180
|
-
|
|
181
|
+
releasePointer(e.currentTarget, e.pointerId);
|
|
181
182
|
const d = drag.current;
|
|
182
183
|
const dt = d.lastT - d.prevT;
|
|
183
184
|
const vpx = dt > 0 ? (d.lastX - d.prevX) / dt : 0;
|
|
@@ -248,7 +249,7 @@ function CylinderCarousel({ children, itemSize = 200, visibleItems = 5, variant
|
|
|
248
249
|
onPointerLeave: () => {
|
|
249
250
|
hoverRef.current = false;
|
|
250
251
|
},
|
|
251
|
-
className: cn("relative w-full touch-none
|
|
252
|
+
className: cn("relative w-full touch-none outline-none [clip-path:inset(0)]", TOUCH_GESTURE_CLASS, "cursor-grab active:cursor-grabbing", "focus-visible:ring-2 focus-visible:ring-foreground/20", className),
|
|
252
253
|
style: { height: stageHeight },
|
|
253
254
|
children: items.map((item, i) => /* @__PURE__ */ jsx(CarouselBall, {
|
|
254
255
|
scroll,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cylinder-carousel.js","names":[],"sources":["../../../src/components/motion/cylinder-carousel.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n Children,\n type ReactNode,\n type PointerEvent as ReactPointerEvent,\n type WheelEvent as ReactWheelEvent,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from \"react\";\nimport {\n type AnimationPlaybackControls,\n animate,\n type MotionValue,\n motion,\n useMotionValue,\n useReducedMotion,\n useTransform,\n} from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\n\n// Carousel-specific: a soft spring that receives the release velocity, so a\n// flick keeps rolling freely, drifts past the snap point and eases back.\nconst GLIDE_SPRING = { stiffness: 40, damping: 20, mass: 3 };\n\n// How far a flick keeps rolling: projected items = release velocity * momentum.\nconst FLICK_MOMENTUM = 0.45;\nconst MAX_FLICK_ITEMS = 6;\n\nexport interface CylinderCarouselProps {\n children: ReactNode;\n /** Max item box size in px (square) at full size, i.e. at the container\n * edge. Balls shrink below this automatically so the row keeps breathing\n * room in narrow containers. */\n itemSize?: number;\n /** How many item slots span the container width. */\n visibleItems?: number;\n /** \"concave\" (default): inside of the cylinder — center ball smallest and\n * dipped, growing toward the edges. \"convex\": outside of the cylinder —\n * center ball biggest and raised, shrinking toward the edges. */\n variant?: \"concave\" | \"convex\";\n /** Scale of the smallest ball (center for concave, edges for convex);\n * the biggest reaches 1. */\n minScale?: number;\n /** Items rolled per item-width dragged — above 1 the wall outruns the\n * pointer, which reads as a lighter, freer roll. */\n dragSpeed?: number;\n /** Curve depth in px: for concave, how far the edge balls ride above the\n * center one (valley); for convex, how far below (arch). 0 = flat line.\n * Defaults to 35% of the item size. */\n arc?: number;\n /** Snap to the nearest item when the roll settles. */\n snap?: boolean;\n /** Roll on its own until interacted with. */\n autoRotate?: boolean;\n /** Auto-roll speed in items per second. */\n autoRotateSpeed?: number;\n defaultIndex?: number;\n onIndexChange?: (index: number) => void;\n /** Stage height in px. Defaults to `itemSize`. */\n height?: number;\n className?: string;\n}\n\n// The frame edge sits at this wall angle; how far the wall curves in frame.\nconst THETA_EDGE = (72 * Math.PI) / 180;\n// Wall angle past which a ball is parked far off-stage (always hidden there).\nconst THETA_CLAMP = (95 * Math.PI) / 180;\n\n/**\n * One ball on the inside wall of the cylinder, rendered through a single\n * perspective projection: the ball sits at wall angle θ, the camera slightly\n * above the ball line, so horizontal position, size and height all share one\n * 1/(cosθ + k) depth term. Center = far wall: smallest, highest, moving\n * slowest; edges = nearest: full size, level, moving fastest, sliding off to\n * be clipped. Nothing overlaps, fades or reorders — the edge is the exit.\n */\nfunction CarouselBall({\n scroll,\n index,\n count,\n alpha,\n k,\n projection,\n gap,\n edgeOffset,\n minScale,\n convex,\n arc,\n halfWidth,\n itemSize,\n children,\n}: {\n scroll: MotionValue<number>;\n index: number;\n count: number;\n /** Wall angle per item step, in radians. */\n alpha: number;\n /** Camera distance term for the horizontal projection. */\n k: number;\n /** Projection strength: maps sinθ/(cosθ+k) to px so θE lands on the edge. */\n projection: number;\n /** Uniform slot width in px — convex spacing. */\n gap: number;\n /** Offset at which a ball's center sits on the container edge. */\n edgeOffset: number;\n minScale: number;\n convex: boolean;\n /** Curve depth in px between the center ball and the edge balls. */\n arc: number;\n halfWidth: number;\n itemSize: number;\n children: ReactNode;\n}) {\n // Nearest wrapped offset so items loop around continuously.\n const offset = useTransform(scroll, (s) => {\n let o = index - s;\n o -= Math.round(o / count) * count;\n return o;\n });\n // Concave spacing follows the interior perspective (slow, tight center);\n // convex pairs its big center balls with uniform spacing — the interior\n // projection would collapse them into each other.\n const x = useTransform(offset, (o) => {\n if (convex) return o * gap;\n const th = Math.max(-THETA_CLAMP, Math.min(THETA_CLAMP, o * alpha));\n return (projection * Math.sin(th)) / (Math.cos(th) + k);\n });\n // Linear in wall angle, not in depth (the depth curve is near-flat around\n // the center, which made the middle three read as equal): every step is\n // visibly bigger than the last — growing outward (concave) or inward\n // (convex).\n const scale = useTransform(offset, (o) => {\n const t = Math.min(Math.abs(o) / edgeOffset, THETA_CLAMP / THETA_EDGE);\n return convex ? 1 - (1 - minScale) * t : minScale + (1 - minScale) * t;\n });\n // Parabola centered on the stage — valley for concave (center ball dips\n // arc/2 below the midline, edges rise arc/2 above), arch for convex — and\n // deliberately unclamped: a ball keeps following the same curve as it\n // crosses the edge, so entries never pop.\n const y = useTransform(x, (px) => {\n const t = px / halfWidth;\n const valley = arc * (0.5 - t * t);\n return convex ? -valley : valley;\n });\n // Fully off-stage balls stop painting (matters for canvas/shader children).\n const visibility = useTransform(x, (px) =>\n Math.abs(px) > halfWidth + itemSize ? \"hidden\" : \"visible\",\n );\n\n return (\n <motion.div\n className=\"absolute top-1/2 left-1/2\"\n style={{\n x,\n y,\n scale,\n visibility,\n width: itemSize,\n height: itemSize,\n marginLeft: -itemSize / 2,\n marginTop: -itemSize / 2,\n }}\n >\n {children}\n </motion.div>\n );\n}\n\nexport function CylinderCarousel({\n children,\n itemSize = 200,\n visibleItems = 5,\n variant = \"concave\",\n minScale = 0.55,\n dragSpeed = 1.5,\n arc: arcProp,\n snap = true,\n autoRotate = false,\n autoRotateSpeed = 0.4,\n defaultIndex = 0,\n onIndexChange,\n height,\n className,\n}: CylinderCarouselProps) {\n const reduce = useReducedMotion() ?? false;\n const items = Children.toArray(children);\n const count = items.length;\n\n const stageRef = useRef<HTMLDivElement>(null);\n const [width, setWidth] = useState(0);\n useEffect(() => {\n const el = stageRef.current;\n if (!el) return;\n const ro = new ResizeObserver(([entry]) => {\n setWidth(entry.contentRect.width);\n });\n ro.observe(el);\n return () => ro.disconnect();\n }, []);\n // Sized so `visibleItems` balls sit fully in frame and the next one out on\n // each side straddles the container edge, half visible.\n const stageWidth = width || 800;\n const halfWidth = stageWidth / 2;\n const edgeOffset = (visibleItems + 1) / 2;\n\n // Fit: the resting row's diameters may take at most ~66% of the stage — the\n // rest is air between balls plus the half-visible ball on each edge.\n // `itemSize` only caps the result.\n const convex = variant === \"convex\";\n let scaleSum = 0;\n for (let i = 0; i < visibleItems; i++) {\n const t = Math.abs(i - (visibleItems - 1) / 2) / edgeOffset;\n scaleSum += convex ? 1 - (1 - minScale) * t : minScale + (1 - minScale) * t;\n }\n const size = Math.min(itemSize, (stageWidth * 0.65) / scaleSum);\n\n const gap = stageWidth / (visibleItems + 1);\n const arc = arcProp ?? size * 0.35;\n\n // Perspective constants. The ball one slot past the frame edge sits at wall\n // angle THETA_EDGE with its center right on the container edge — scale 1,\n // half of it in view; k falls out of the requested minScale (clamped so the\n // projection stays monotonic up to THETA_CLAMP).\n const alpha = THETA_EDGE / edgeOffset;\n const k = Math.max(0.2, (minScale - Math.cos(THETA_EDGE)) / (1 - minScale));\n const projection = (halfWidth * (Math.cos(THETA_EDGE) + k)) / Math.sin(THETA_EDGE);\n\n // scroll is in item units (continuous); item i sits at x = (i - scroll) * gap.\n // Drags write it 1:1 so the wall sticks to the pointer; releases hand the\n // pointer velocity to a soft spring so the roll glides on and settles free.\n const scroll = useMotionValue(defaultIndex);\n const indexRef = useRef(defaultIndex);\n const [, setActiveIndex] = useState(defaultIndex);\n const glideRef = useRef<AnimationPlaybackControls | null>(null);\n const draggingRef = useRef(false);\n const hoverRef = useRef(false);\n\n useEffect(() => {\n if (count === 0) return;\n const unsub = scroll.on(\"change\", (v) => {\n const idx = ((Math.round(v) % count) + count) % count;\n if (idx !== indexRef.current) {\n indexRef.current = idx;\n setActiveIndex(idx);\n onIndexChange?.(idx);\n }\n });\n return unsub;\n }, [scroll, count, onIndexChange]);\n\n const stopGlide = useCallback(() => {\n glideRef.current?.stop();\n glideRef.current = null;\n }, []);\n\n // Spring toward `to`, carrying `velocity` (items/s) through so motion never\n // steps — the roll leaves the finger at finger speed.\n const glideTo = useCallback(\n (to: number, velocity: number) => {\n stopGlide();\n if (reduce) {\n scroll.set(to);\n return;\n }\n glideRef.current = animate(scroll, to, {\n type: \"spring\",\n ...GLIDE_SPRING,\n velocity,\n restDelta: 0.001,\n restSpeed: 0.005,\n });\n },\n [scroll, stopGlide, reduce],\n );\n\n const settle = useCallback(\n (velocity: number) => {\n const projected =\n scroll.get() +\n Math.max(-MAX_FLICK_ITEMS, Math.min(MAX_FLICK_ITEMS, velocity * FLICK_MOMENTUM));\n glideTo(snap ? Math.round(projected) : projected, velocity);\n },\n [scroll, snap, glideTo],\n );\n\n const drag = useRef({\n startX: 0,\n startScroll: 0,\n lastX: 0,\n lastT: 0,\n prevX: 0,\n prevT: 0,\n });\n\n const onPointerDown = useCallback(\n (e: ReactPointerEvent) => {\n e.preventDefault();\n stopGlide();\n draggingRef.current = true;\n e.currentTarget.setPointerCapture(e.pointerId);\n const now = performance.now();\n drag.current = {\n startX: e.clientX,\n startScroll: scroll.get(),\n lastX: e.clientX,\n lastT: now,\n prevX: e.clientX,\n prevT: now,\n };\n },\n [scroll, stopGlide],\n );\n\n const onPointerMove = useCallback(\n (e: ReactPointerEvent) => {\n if (!draggingRef.current) return;\n const d = drag.current;\n scroll.set(d.startScroll - ((e.clientX - d.startX) * dragSpeed) / gap);\n d.prevX = d.lastX;\n d.prevT = d.lastT;\n d.lastX = e.clientX;\n d.lastT = performance.now();\n },\n [scroll, gap, dragSpeed],\n );\n\n const onPointerUp = useCallback(\n (e: ReactPointerEvent) => {\n if (!draggingRef.current) return;\n draggingRef.current = false;\n if (e.currentTarget.hasPointerCapture(e.pointerId)) {\n e.currentTarget.releasePointerCapture(e.pointerId);\n }\n const d = drag.current;\n const dt = d.lastT - d.prevT;\n const vpx = dt > 0 ? (d.lastX - d.prevX) / dt : 0; // px per ms\n settle((-vpx * dragSpeed * 1000) / gap); // items per second\n },\n [settle, gap, dragSpeed],\n );\n\n const rollBy = useCallback(\n (dir: number) => {\n glideTo(Math.round(scroll.get()) + dir, scroll.getVelocity());\n },\n [scroll, glideTo],\n );\n\n const wheelSettleRef = useRef<number | undefined>(undefined);\n const onWheel = useCallback(\n (e: ReactWheelEvent) => {\n stopGlide();\n const delta = Math.abs(e.deltaX) > Math.abs(e.deltaY) ? e.deltaX : e.deltaY;\n scroll.set(scroll.get() + delta / gap);\n if (wheelSettleRef.current) window.clearTimeout(wheelSettleRef.current);\n wheelSettleRef.current = window.setTimeout(() => settle(scroll.getVelocity()), 140);\n },\n [scroll, gap, settle, stopGlide],\n );\n\n useEffect(() => {\n if (!autoRotate || reduce || count === 0) return;\n let raf = 0;\n let last = performance.now();\n const tick = (now: number) => {\n const dt = (now - last) / 1000;\n last = now;\n if (!draggingRef.current && !hoverRef.current && !glideRef.current) {\n scroll.set(scroll.get() + autoRotateSpeed * dt);\n }\n raf = requestAnimationFrame(tick);\n };\n raf = requestAnimationFrame(tick);\n return () => cancelAnimationFrame(raf);\n }, [autoRotate, autoRotateSpeed, reduce, count, scroll]);\n\n const stageHeight = height ?? size;\n\n return (\n <div\n ref={stageRef}\n role=\"application\"\n aria-roledescription=\"carousel\"\n // biome-ignore lint/a11y/noNoninteractiveTabindex: focusable custom carousel widget\n tabIndex={0}\n onKeyDown={(e) => {\n if (e.key === \"ArrowRight\") {\n e.preventDefault();\n rollBy(1);\n } else if (e.key === \"ArrowLeft\") {\n e.preventDefault();\n rollBy(-1);\n }\n }}\n onPointerDown={onPointerDown}\n onPointerMove={onPointerMove}\n onPointerUp={onPointerUp}\n onPointerCancel={onPointerUp}\n onWheel={onWheel}\n onPointerEnter={() => {\n hoverRef.current = true;\n }}\n onPointerLeave={() => {\n hoverRef.current = false;\n }}\n className={cn(\n // clip-path, not overflow: it also clips the GPU-composited balls\n \"relative w-full touch-none select-none outline-none [clip-path:inset(0)]\",\n \"cursor-grab active:cursor-grabbing\",\n \"focus-visible:ring-2 focus-visible:ring-foreground/20\",\n className,\n )}\n style={{ height: stageHeight }}\n >\n {items.map((item, i) => (\n <CarouselBall\n key={i}\n scroll={scroll}\n index={i}\n count={count}\n alpha={alpha}\n k={k}\n projection={projection}\n gap={gap}\n edgeOffset={edgeOffset}\n minScale={minScale}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
|
|
1
|
+
{"version":3,"file":"cylinder-carousel.js","names":[],"sources":["../../../src/components/motion/cylinder-carousel.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n Children,\n type ReactNode,\n type PointerEvent as ReactPointerEvent,\n type WheelEvent as ReactWheelEvent,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from \"react\";\nimport {\n type AnimationPlaybackControls,\n animate,\n type MotionValue,\n motion,\n useMotionValue,\n useReducedMotion,\n useTransform,\n} from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { capturePointer, releasePointer, TOUCH_GESTURE_CLASS } from \"../../lib/touch\";\n\n// Carousel-specific: a soft spring that receives the release velocity, so a\n// flick keeps rolling freely, drifts past the snap point and eases back.\nconst GLIDE_SPRING = { stiffness: 40, damping: 20, mass: 3 };\n\n// How far a flick keeps rolling: projected items = release velocity * momentum.\nconst FLICK_MOMENTUM = 0.45;\nconst MAX_FLICK_ITEMS = 6;\n\nexport interface CylinderCarouselProps {\n children: ReactNode;\n /** Max item box size in px (square) at full size, i.e. at the container\n * edge. Balls shrink below this automatically so the row keeps breathing\n * room in narrow containers. */\n itemSize?: number;\n /** How many item slots span the container width. */\n visibleItems?: number;\n /** \"concave\" (default): inside of the cylinder — center ball smallest and\n * dipped, growing toward the edges. \"convex\": outside of the cylinder —\n * center ball biggest and raised, shrinking toward the edges. */\n variant?: \"concave\" | \"convex\";\n /** Scale of the smallest ball (center for concave, edges for convex);\n * the biggest reaches 1. */\n minScale?: number;\n /** Items rolled per item-width dragged — above 1 the wall outruns the\n * pointer, which reads as a lighter, freer roll. */\n dragSpeed?: number;\n /** Curve depth in px: for concave, how far the edge balls ride above the\n * center one (valley); for convex, how far below (arch). 0 = flat line.\n * Defaults to 35% of the item size. */\n arc?: number;\n /** Snap to the nearest item when the roll settles. */\n snap?: boolean;\n /** Roll on its own until interacted with. */\n autoRotate?: boolean;\n /** Auto-roll speed in items per second. */\n autoRotateSpeed?: number;\n defaultIndex?: number;\n onIndexChange?: (index: number) => void;\n /** Stage height in px. Defaults to `itemSize`. */\n height?: number;\n className?: string;\n}\n\n// The frame edge sits at this wall angle; how far the wall curves in frame.\nconst THETA_EDGE = (72 * Math.PI) / 180;\n// Wall angle past which a ball is parked far off-stage (always hidden there).\nconst THETA_CLAMP = (95 * Math.PI) / 180;\n\n/**\n * One ball on the inside wall of the cylinder, rendered through a single\n * perspective projection: the ball sits at wall angle θ, the camera slightly\n * above the ball line, so horizontal position, size and height all share one\n * 1/(cosθ + k) depth term. Center = far wall: smallest, highest, moving\n * slowest; edges = nearest: full size, level, moving fastest, sliding off to\n * be clipped. Nothing overlaps, fades or reorders — the edge is the exit.\n */\nfunction CarouselBall({\n scroll,\n index,\n count,\n alpha,\n k,\n projection,\n gap,\n edgeOffset,\n minScale,\n convex,\n arc,\n halfWidth,\n itemSize,\n children,\n}: {\n scroll: MotionValue<number>;\n index: number;\n count: number;\n /** Wall angle per item step, in radians. */\n alpha: number;\n /** Camera distance term for the horizontal projection. */\n k: number;\n /** Projection strength: maps sinθ/(cosθ+k) to px so θE lands on the edge. */\n projection: number;\n /** Uniform slot width in px — convex spacing. */\n gap: number;\n /** Offset at which a ball's center sits on the container edge. */\n edgeOffset: number;\n minScale: number;\n convex: boolean;\n /** Curve depth in px between the center ball and the edge balls. */\n arc: number;\n halfWidth: number;\n itemSize: number;\n children: ReactNode;\n}) {\n // Nearest wrapped offset so items loop around continuously.\n const offset = useTransform(scroll, (s) => {\n let o = index - s;\n o -= Math.round(o / count) * count;\n return o;\n });\n // Concave spacing follows the interior perspective (slow, tight center);\n // convex pairs its big center balls with uniform spacing — the interior\n // projection would collapse them into each other.\n const x = useTransform(offset, (o) => {\n if (convex) return o * gap;\n const th = Math.max(-THETA_CLAMP, Math.min(THETA_CLAMP, o * alpha));\n return (projection * Math.sin(th)) / (Math.cos(th) + k);\n });\n // Linear in wall angle, not in depth (the depth curve is near-flat around\n // the center, which made the middle three read as equal): every step is\n // visibly bigger than the last — growing outward (concave) or inward\n // (convex).\n const scale = useTransform(offset, (o) => {\n const t = Math.min(Math.abs(o) / edgeOffset, THETA_CLAMP / THETA_EDGE);\n return convex ? 1 - (1 - minScale) * t : minScale + (1 - minScale) * t;\n });\n // Parabola centered on the stage — valley for concave (center ball dips\n // arc/2 below the midline, edges rise arc/2 above), arch for convex — and\n // deliberately unclamped: a ball keeps following the same curve as it\n // crosses the edge, so entries never pop.\n const y = useTransform(x, (px) => {\n const t = px / halfWidth;\n const valley = arc * (0.5 - t * t);\n return convex ? -valley : valley;\n });\n // Fully off-stage balls stop painting (matters for canvas/shader children).\n const visibility = useTransform(x, (px) =>\n Math.abs(px) > halfWidth + itemSize ? \"hidden\" : \"visible\",\n );\n\n return (\n <motion.div\n className=\"absolute top-1/2 left-1/2\"\n style={{\n x,\n y,\n scale,\n visibility,\n width: itemSize,\n height: itemSize,\n marginLeft: -itemSize / 2,\n marginTop: -itemSize / 2,\n }}\n >\n {children}\n </motion.div>\n );\n}\n\nexport function CylinderCarousel({\n children,\n itemSize = 200,\n visibleItems = 5,\n variant = \"concave\",\n minScale = 0.55,\n dragSpeed = 1.5,\n arc: arcProp,\n snap = true,\n autoRotate = false,\n autoRotateSpeed = 0.4,\n defaultIndex = 0,\n onIndexChange,\n height,\n className,\n}: CylinderCarouselProps) {\n const reduce = useReducedMotion() ?? false;\n const items = Children.toArray(children);\n const count = items.length;\n\n const stageRef = useRef<HTMLDivElement>(null);\n const [width, setWidth] = useState(0);\n useEffect(() => {\n const el = stageRef.current;\n if (!el) return;\n const ro = new ResizeObserver(([entry]) => {\n setWidth(entry.contentRect.width);\n });\n ro.observe(el);\n return () => ro.disconnect();\n }, []);\n // Sized so `visibleItems` balls sit fully in frame and the next one out on\n // each side straddles the container edge, half visible.\n const stageWidth = width || 800;\n const halfWidth = stageWidth / 2;\n const edgeOffset = (visibleItems + 1) / 2;\n\n // Fit: the resting row's diameters may take at most ~66% of the stage — the\n // rest is air between balls plus the half-visible ball on each edge.\n // `itemSize` only caps the result.\n const convex = variant === \"convex\";\n let scaleSum = 0;\n for (let i = 0; i < visibleItems; i++) {\n const t = Math.abs(i - (visibleItems - 1) / 2) / edgeOffset;\n scaleSum += convex ? 1 - (1 - minScale) * t : minScale + (1 - minScale) * t;\n }\n const size = Math.min(itemSize, (stageWidth * 0.65) / scaleSum);\n\n const gap = stageWidth / (visibleItems + 1);\n const arc = arcProp ?? size * 0.35;\n\n // Perspective constants. The ball one slot past the frame edge sits at wall\n // angle THETA_EDGE with its center right on the container edge — scale 1,\n // half of it in view; k falls out of the requested minScale (clamped so the\n // projection stays monotonic up to THETA_CLAMP).\n const alpha = THETA_EDGE / edgeOffset;\n const k = Math.max(0.2, (minScale - Math.cos(THETA_EDGE)) / (1 - minScale));\n const projection = (halfWidth * (Math.cos(THETA_EDGE) + k)) / Math.sin(THETA_EDGE);\n\n // scroll is in item units (continuous); item i sits at x = (i - scroll) * gap.\n // Drags write it 1:1 so the wall sticks to the pointer; releases hand the\n // pointer velocity to a soft spring so the roll glides on and settles free.\n const scroll = useMotionValue(defaultIndex);\n const indexRef = useRef(defaultIndex);\n const [, setActiveIndex] = useState(defaultIndex);\n const glideRef = useRef<AnimationPlaybackControls | null>(null);\n const draggingRef = useRef(false);\n const hoverRef = useRef(false);\n\n useEffect(() => {\n if (count === 0) return;\n const unsub = scroll.on(\"change\", (v) => {\n const idx = ((Math.round(v) % count) + count) % count;\n if (idx !== indexRef.current) {\n indexRef.current = idx;\n setActiveIndex(idx);\n onIndexChange?.(idx);\n }\n });\n return unsub;\n }, [scroll, count, onIndexChange]);\n\n const stopGlide = useCallback(() => {\n glideRef.current?.stop();\n glideRef.current = null;\n }, []);\n\n // Spring toward `to`, carrying `velocity` (items/s) through so motion never\n // steps — the roll leaves the finger at finger speed.\n const glideTo = useCallback(\n (to: number, velocity: number) => {\n stopGlide();\n if (reduce) {\n scroll.set(to);\n return;\n }\n glideRef.current = animate(scroll, to, {\n type: \"spring\",\n ...GLIDE_SPRING,\n velocity,\n restDelta: 0.001,\n restSpeed: 0.005,\n });\n },\n [scroll, stopGlide, reduce],\n );\n\n const settle = useCallback(\n (velocity: number) => {\n const projected =\n scroll.get() +\n Math.max(-MAX_FLICK_ITEMS, Math.min(MAX_FLICK_ITEMS, velocity * FLICK_MOMENTUM));\n glideTo(snap ? Math.round(projected) : projected, velocity);\n },\n [scroll, snap, glideTo],\n );\n\n const drag = useRef({\n startX: 0,\n startScroll: 0,\n lastX: 0,\n lastT: 0,\n prevX: 0,\n prevT: 0,\n });\n\n const onPointerDown = useCallback(\n (e: ReactPointerEvent) => {\n e.preventDefault();\n stopGlide();\n draggingRef.current = true;\n capturePointer(e.currentTarget, e.pointerId);\n const now = performance.now();\n drag.current = {\n startX: e.clientX,\n startScroll: scroll.get(),\n lastX: e.clientX,\n lastT: now,\n prevX: e.clientX,\n prevT: now,\n };\n },\n [scroll, stopGlide],\n );\n\n const onPointerMove = useCallback(\n (e: ReactPointerEvent) => {\n if (!draggingRef.current) return;\n const d = drag.current;\n scroll.set(d.startScroll - ((e.clientX - d.startX) * dragSpeed) / gap);\n d.prevX = d.lastX;\n d.prevT = d.lastT;\n d.lastX = e.clientX;\n d.lastT = performance.now();\n },\n [scroll, gap, dragSpeed],\n );\n\n const onPointerUp = useCallback(\n (e: ReactPointerEvent) => {\n if (!draggingRef.current) return;\n draggingRef.current = false;\n releasePointer(e.currentTarget, e.pointerId);\n const d = drag.current;\n const dt = d.lastT - d.prevT;\n const vpx = dt > 0 ? (d.lastX - d.prevX) / dt : 0; // px per ms\n settle((-vpx * dragSpeed * 1000) / gap); // items per second\n },\n [settle, gap, dragSpeed],\n );\n\n const rollBy = useCallback(\n (dir: number) => {\n glideTo(Math.round(scroll.get()) + dir, scroll.getVelocity());\n },\n [scroll, glideTo],\n );\n\n const wheelSettleRef = useRef<number | undefined>(undefined);\n const onWheel = useCallback(\n (e: ReactWheelEvent) => {\n stopGlide();\n const delta = Math.abs(e.deltaX) > Math.abs(e.deltaY) ? e.deltaX : e.deltaY;\n scroll.set(scroll.get() + delta / gap);\n if (wheelSettleRef.current) window.clearTimeout(wheelSettleRef.current);\n wheelSettleRef.current = window.setTimeout(() => settle(scroll.getVelocity()), 140);\n },\n [scroll, gap, settle, stopGlide],\n );\n\n useEffect(() => {\n if (!autoRotate || reduce || count === 0) return;\n let raf = 0;\n let last = performance.now();\n const tick = (now: number) => {\n const dt = (now - last) / 1000;\n last = now;\n if (!draggingRef.current && !hoverRef.current && !glideRef.current) {\n scroll.set(scroll.get() + autoRotateSpeed * dt);\n }\n raf = requestAnimationFrame(tick);\n };\n raf = requestAnimationFrame(tick);\n return () => cancelAnimationFrame(raf);\n }, [autoRotate, autoRotateSpeed, reduce, count, scroll]);\n\n const stageHeight = height ?? size;\n\n return (\n <div\n ref={stageRef}\n role=\"application\"\n aria-roledescription=\"carousel\"\n // biome-ignore lint/a11y/noNoninteractiveTabindex: focusable custom carousel widget\n tabIndex={0}\n onKeyDown={(e) => {\n if (e.key === \"ArrowRight\") {\n e.preventDefault();\n rollBy(1);\n } else if (e.key === \"ArrowLeft\") {\n e.preventDefault();\n rollBy(-1);\n }\n }}\n onPointerDown={onPointerDown}\n onPointerMove={onPointerMove}\n onPointerUp={onPointerUp}\n onPointerCancel={onPointerUp}\n onWheel={onWheel}\n onPointerEnter={() => {\n hoverRef.current = true;\n }}\n onPointerLeave={() => {\n hoverRef.current = false;\n }}\n className={cn(\n // clip-path, not overflow: it also clips the GPU-composited balls\n \"relative w-full touch-none outline-none [clip-path:inset(0)]\",\n // The stage drives the roll from the press itself, so iOS must not\n // claim the same touch for its callout or a slide drag.\n TOUCH_GESTURE_CLASS,\n \"cursor-grab active:cursor-grabbing\",\n \"focus-visible:ring-2 focus-visible:ring-foreground/20\",\n className,\n )}\n style={{ height: stageHeight }}\n >\n {items.map((item, i) => (\n <CarouselBall\n key={i}\n scroll={scroll}\n index={i}\n count={count}\n alpha={alpha}\n k={k}\n projection={projection}\n gap={gap}\n edgeOffset={edgeOffset}\n minScale={minScale}\n convex={conv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
29
29
|
activeId?: string;
|
|
30
30
|
onAction?: (item: ExpandableActionBarItem) => void;
|
|
31
31
|
size?: ExpandableActionBarSize;
|
|
32
|
+
/**
|
|
33
|
+
* Expand when a pointer that hovers rests on the bar. Default true. It also
|
|
34
|
+
* governs the touch equivalent: with no hover to reveal the labels, the
|
|
35
|
+
* first tap expands the bar and runs no action, and the second one acts.
|
|
36
|
+
* Set false to make every tap and click act immediately.
|
|
37
|
+
*/
|
|
32
38
|
expandOnHover?: boolean;
|
|
33
39
|
expandOnFocus?: boolean;
|
|
34
40
|
collapseDelay?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expandable-action-bar.d.ts","names":[],"sources":["../../../src/components/motion/expandable-action-bar.tsx"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"expandable-action-bar.d.ts","names":[],"sources":["../../../src/components/motion/expandable-action-bar.tsx"],"mappings":";;KAqBY;KAEA;EACV;EACA,OAAO;EACP,MAAM;EACN;EACA;EACA;EACA,QAAQ;EACR,WAAW;;KAGD;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf,OAAO;EACP;EACA;EACA,oBAAoB;EACpB;EACA,YAAY,MAAM;EAClB,OAAO;;;;;;;EAOP;EACA;EACA;EACA;EACA,aAAa;EACb,cACE,MAAM,yBACN;IAAS;IAAmB;QACzB;;iBAwDS,sBACd,OACA,UACA,iBACA,kBACA,UACA,UACA,MACA,eACA,eACA,eACA,WACA,YACA,cACC,2CAAwB,IAAA;iBAyQX,uBAAuB,OAAO;;;;;cAAA"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
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";
|
|
2
5
|
import { useCallback, useEffect, useId, useMemo, useRef, useState } from "react";
|
|
3
6
|
import { cn } from "@kumix/utils";
|
|
4
7
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -45,7 +48,11 @@ function ExpandableActionBar({ items, expanded, defaultExpanded = false, onExpan
|
|
|
45
48
|
onExpandedChange
|
|
46
49
|
});
|
|
47
50
|
const [hoveredId, setHoveredId] = useState(null);
|
|
51
|
+
const [tapExpanded, setTapExpanded] = useState(false);
|
|
48
52
|
const collapseTimer = useRef(null);
|
|
53
|
+
const trackRef = useRef(null);
|
|
54
|
+
const tap = useTapGesture();
|
|
55
|
+
const hover = useHoverGesture();
|
|
49
56
|
const clearCollapseTimer = useCallback(() => {
|
|
50
57
|
if (collapseTimer.current) window.clearTimeout(collapseTimer.current);
|
|
51
58
|
collapseTimer.current = null;
|
|
@@ -59,6 +66,7 @@ function ExpandableActionBar({ items, expanded, defaultExpanded = false, onExpan
|
|
|
59
66
|
const timer = window.setTimeout(() => {
|
|
60
67
|
setIsExpanded(false);
|
|
61
68
|
setHoveredId(null);
|
|
69
|
+
setTapExpanded(false);
|
|
62
70
|
}, collapseDelay);
|
|
63
71
|
collapseTimer.current = timer;
|
|
64
72
|
}, [
|
|
@@ -67,10 +75,17 @@ function ExpandableActionBar({ items, expanded, defaultExpanded = false, onExpan
|
|
|
67
75
|
setIsExpanded
|
|
68
76
|
]);
|
|
69
77
|
useEffect(() => clearCollapseTimer, [clearCollapseTimer]);
|
|
70
|
-
const
|
|
71
|
-
|
|
78
|
+
const wasExpanded = useRef(isExpanded);
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
if (wasExpanded.current && !isExpanded) setTapExpanded(false);
|
|
81
|
+
wasExpanded.current = isExpanded;
|
|
82
|
+
}, [isExpanded]);
|
|
83
|
+
useDismiss(tapExpanded && isExpanded, close, trackRef, { behavior: "consume" });
|
|
84
|
+
const onRootPointerEnter = (event) => {
|
|
85
|
+
if (hover.enter(event) && expandOnHover) open();
|
|
72
86
|
};
|
|
73
|
-
const
|
|
87
|
+
const onRootPointerLeave = (event) => {
|
|
88
|
+
if (!hover.leave(event)) return;
|
|
74
89
|
setHoveredId(null);
|
|
75
90
|
if (expandOnHover) close();
|
|
76
91
|
};
|
|
@@ -86,15 +101,16 @@ function ExpandableActionBar({ items, expanded, defaultExpanded = false, onExpan
|
|
|
86
101
|
id: layoutId,
|
|
87
102
|
children: /* @__PURE__ */ jsx(motion.div, {
|
|
88
103
|
layout: "size",
|
|
89
|
-
|
|
90
|
-
|
|
104
|
+
onPointerEnter: onRootPointerEnter,
|
|
105
|
+
onPointerLeave: onRootPointerLeave,
|
|
91
106
|
onFocus: onRootFocus,
|
|
92
107
|
onBlur: onRootBlur,
|
|
93
108
|
transition: ITEM_TRANSITION,
|
|
94
|
-
className: cn("inline-flex", classNames?.root, className),
|
|
109
|
+
className: cn("inline-flex max-w-full", classNames?.root, className),
|
|
95
110
|
children: /* @__PURE__ */ jsx(motion.div, {
|
|
111
|
+
ref: trackRef,
|
|
96
112
|
layout: "size",
|
|
97
|
-
className: cn("relative inline-flex items-center overflow-hidden rounded-full border border-border bg-card/90 shadow-2xl backdrop-blur-xl", SIZE_CLASS[size], classNames?.track),
|
|
113
|
+
className: cn("scrollbar-hide relative inline-flex max-w-full items-center overflow-x-auto overflow-y-hidden rounded-full border border-border bg-card/90 shadow-2xl backdrop-blur-xl", SIZE_CLASS[size], classNames?.track),
|
|
98
114
|
transition: ITEM_TRANSITION,
|
|
99
115
|
children: items.map((item) => {
|
|
100
116
|
const isActive = item.active || activeId === item.id;
|
|
@@ -104,18 +120,31 @@ function ExpandableActionBar({ items, expanded, defaultExpanded = false, onExpan
|
|
|
104
120
|
type: "button",
|
|
105
121
|
disabled: item.disabled,
|
|
106
122
|
title: typeof item.label === "string" ? item.label : void 0,
|
|
107
|
-
|
|
123
|
+
onPointerEnter: (event) => {
|
|
124
|
+
if (!hover.enter(event)) return;
|
|
108
125
|
clearCollapseTimer();
|
|
109
126
|
setHoveredId(item.id);
|
|
110
127
|
},
|
|
128
|
+
onPointerDown: (event) => {
|
|
129
|
+
tap.start(event, isExpanded);
|
|
130
|
+
},
|
|
131
|
+
onPointerCancel: tap.drop,
|
|
132
|
+
onKeyDown: tap.drop,
|
|
111
133
|
onClick: (event) => {
|
|
112
134
|
event.currentTarget.blur();
|
|
135
|
+
const gesture = tap.take();
|
|
136
|
+
if (gesture !== null && gesture.pointerType !== "mouse" && !gesture.state && !tapExpanded && expandOnHover) {
|
|
137
|
+
setTapExpanded(true);
|
|
138
|
+
open();
|
|
139
|
+
setHoveredId(item.id);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
113
142
|
item.onClick?.();
|
|
114
143
|
onAction?.(item);
|
|
115
144
|
},
|
|
116
145
|
whileTap: reduce || item.disabled ? void 0 : { scale: .96 },
|
|
117
146
|
transition: ITEM_TRANSITION,
|
|
118
|
-
className: cn("relative isolate inline-flex items-center justify-center overflow-hidden rounded-full font-medium text-muted-foreground outline-none transition-[color,background-color] duration-150 ease-out", "focus-visible:text-foreground disabled:pointer-events-none disabled:opacity-40", isHighlighted && "text-foreground", ITEM_SIZE_CLASS[size], classNames?.item, isActive && classNames?.activeItem),
|
|
147
|
+
className: cn("relative isolate inline-flex shrink-0 items-center justify-center overflow-hidden rounded-full font-medium text-muted-foreground outline-none transition-[color,background-color] duration-150 ease-out", "focus-visible:text-foreground disabled:pointer-events-none disabled:opacity-40", isHighlighted && "text-foreground", ITEM_SIZE_CLASS[size], classNames?.item, isActive && classNames?.activeItem),
|
|
119
148
|
children: [isHighlighted ? /* @__PURE__ */ jsx(motion.span, {
|
|
120
149
|
layoutId: "action-bar-highlight",
|
|
121
150
|
className: "absolute inset-0 -z-10 rounded-full bg-primary/[0.07]",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expandable-action-bar.js","names":[],"sources":["../../../src/components/motion/expandable-action-bar.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type FocusEvent,\n type MouseEvent,\n type ReactNode,\n useCallback,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { LayoutGroup, motion, type Transition, useReducedMotion } from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\n\nexport type ExpandableActionBarSize = \"sm\" | \"md\";\n\nexport type ExpandableActionBarItem = {\n id: string;\n label: ReactNode;\n icon: ReactNode;\n onClick?: () => void;\n disabled?: boolean;\n active?: boolean;\n badge?: ReactNode;\n shortcut?: ReactNode;\n};\n\nexport type ExpandableActionBarClassNames = {\n root?: string;\n track?: string;\n item?: string;\n activeItem?: string;\n icon?: string;\n label?: string;\n badge?: string;\n shortcut?: string;\n};\n\nexport interface ExpandableActionBarProps {\n items: ExpandableActionBarItem[];\n expanded?: boolean;\n defaultExpanded?: boolean;\n onExpandedChange?: (expanded: boolean) => void;\n activeId?: string;\n onAction?: (item: ExpandableActionBarItem) => void;\n size?: ExpandableActionBarSize;\n expandOnHover?: boolean;\n expandOnFocus?: boolean;\n collapseDelay?: number;\n className?: string;\n classNames?: ExpandableActionBarClassNames;\n renderItem?: (\n item: ExpandableActionBarItem,\n state: { expanded: boolean; active: boolean },\n ) => ReactNode;\n}\n\nconst ITEM_TRANSITION: Transition = {\n type: \"spring\",\n stiffness: 460,\n damping: 34,\n mass: 0.62,\n};\n\nconst LABEL_TRANSITION: Transition = {\n type: \"spring\",\n stiffness: 380,\n damping: 32,\n mass: 0.7,\n};\n\nconst SIZE_CLASS: Record<ExpandableActionBarSize, string> = {\n sm: \"min-h-9 gap-1 p-1 text-xs\",\n md: \"min-h-11 gap-1.5 p-1.5 text-sm\",\n};\n\nconst ITEM_SIZE_CLASS: Record<ExpandableActionBarSize, string> = {\n sm: \"h-7 min-w-7 px-1.5\",\n md: \"h-8 min-w-8 px-2\",\n};\n\nconst ICON_SIZE_CLASS: Record<ExpandableActionBarSize, string> = {\n sm: \"h-3.5 w-3.5\",\n md: \"h-4 w-4\",\n};\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 ?? false);\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\nexport function ExpandableActionBar({\n items,\n expanded,\n defaultExpanded = false,\n onExpandedChange,\n activeId,\n onAction,\n size = \"md\",\n expandOnHover = true,\n expandOnFocus = true,\n collapseDelay = 90,\n className,\n classNames,\n renderItem,\n}: ExpandableActionBarProps) {\n const reduce = useReducedMotion();\n const layoutId = useId();\n const [isExpanded, setIsExpanded] = useControllableExpanded({\n expanded,\n defaultExpanded,\n onExpandedChange,\n });\n const [hoveredId, setHoveredId] = useState<string | null>(null);\n const collapseTimer = useRef<number | null>(null);\n\n const clearCollapseTimer = useCallback(() => {\n if (collapseTimer.current) window.clearTimeout(collapseTimer.current);\n collapseTimer.current = null;\n }, []);\n\n const open = useCallback(() => {\n clearCollapseTimer();\n setIsExpanded(true);\n }, [clearCollapseTimer, setIsExpanded]);\n\n const close = useCallback(() => {\n clearCollapseTimer();\n const timer = window.setTimeout(() => {\n setIsExpanded(false);\n setHoveredId(null);\n }, collapseDelay);\n collapseTimer.current = timer;\n }, [clearCollapseTimer, collapseDelay, setIsExpanded]);\n\n useEffect(() => clearCollapseTimer, [clearCollapseTimer]);\n\n const onRootMouseEnter = () => {\n if (expandOnHover) open();\n };\n\n const onRootMouseLeave = () => {\n setHoveredId(null);\n if (expandOnHover) close();\n };\n\n const onRootFocus = () => {\n if (expandOnFocus) open();\n };\n\n const onRootBlur = (event: FocusEvent<HTMLDivElement>) => {\n if (!event.currentTarget.contains(event.relatedTarget as Node) && expandOnFocus) {\n close();\n }\n };\n\n const activeItemId = activeId ?? items.find((item) => item.active)?.id;\n const highlightId = hoveredId ?? activeItemId;\n\n return (\n <LayoutGroup id={layoutId}>\n <motion.div\n layout=\"size\"\n onMouseEnter={onRootMouseEnter}\n onMouseLeave={onRootMouseLeave}\n onFocus={onRootFocus}\n onBlur={onRootBlur}\n transition={ITEM_TRANSITION}\n className={cn(\"inline-flex\", classNames?.root, className)}\n >\n <motion.div\n layout=\"size\"\n className={cn(\n \"relative inline-flex items-center overflow-hidden rounded-full border border-border bg-card/90 shadow-2xl backdrop-blur-xl\",\n SIZE_CLASS[size],\n classNames?.track,\n )}\n transition={ITEM_TRANSITION}\n >\n {items.map((item) => {\n const isActive = item.active || activeId === item.id;\n const isHighlighted = highlightId === item.id;\n\n return (\n <motion.button\n key={item.id}\n layout=\"position\"\n type=\"button\"\n disabled={item.disabled}\n title={typeof item.label === \"string\" ? item.label : undefined}\n onMouseEnter={() => {\n clearCollapseTimer();\n setHoveredId(item.id);\n }}\n onClick={(event: MouseEvent<HTMLButtonElement>) => {\n event.currentTarget.blur();\n item.onClick?.();\n onAction?.(item);\n }}\n whileTap={reduce || item.disabled ? undefined : { scale: 0.96 }}\n transition={ITEM_TRANSITION}\n className={cn(\n \"relative isolate inline-flex items-center justify-center overflow-hidden rounded-full font-medium text-muted-foreground outline-none transition-[color,background-color] duration-150 ease-out\",\n \"focus-visible:text-foreground disabled:pointer-events-none disabled:opacity-40\",\n isHighlighted && \"text-foreground\",\n ITEM_SIZE_CLASS[size],\n classNames?.item,\n isActive && classNames?.activeItem,\n )}\n >\n {isHighlighted ? (\n <motion.span\n layoutId=\"action-bar-highlight\"\n className=\"absolute inset-0 -z-10 rounded-full bg-primary/[0.07]\"\n transition={ITEM_TRANSITION}\n />\n ) : null}\n\n {renderItem ? (\n renderItem(item, { expanded: isExpanded, active: isActive })\n ) : (\n <>\n <span\n className={cn(\n \"inline-flex shrink-0 items-center justify-center\",\n ICON_SIZE_CLASS[size],\n classNames?.icon,\n )}\n >\n {item.icon}\n </span>\n\n <motion.span\n aria-hidden={!isExpanded}\n animate={\n reduce\n ? {\n width: isExpanded ? \"auto\" : 0,\n opacity: isExpanded ? 1 : 0,\n marginLeft: isExpanded ? 8 : 0,\n x: 0,\n filter: \"blur(0px)\",\n }\n : {\n width: isExpanded ? \"auto\" : 0,\n opacity: isExpanded ? 1 : 0,\n x: isExpanded ? 0 : -4,\n marginLeft: isExpanded ? 8 : 0,\n filter: isExpanded ? \"blur(0px)\" : \"blur(3px)\",\n }\n }\n transition={reduce ? { duration: 0 } : LABEL_TRANSITION}\n className={cn(\n \"inline-block overflow-hidden whitespace-nowrap\",\n classNames?.label,\n )}\n >\n {item.label}\n </motion.span>\n\n {item.shortcut ? (\n <motion.span\n aria-hidden={!isExpanded}\n animate={{\n width: isExpanded ? \"auto\" : 0,\n opacity: isExpanded ? 1 : 0,\n marginLeft: isExpanded ? 4 : 0,\n }}\n transition={LABEL_TRANSITION}\n className={cn(\n \"hidden overflow-hidden whitespace-nowrap text-[10px] text-muted-foreground sm:inline-block\",\n classNames?.shortcut,\n )}\n >\n {item.shortcut}\n </motion.span>\n ) : null}\n\n {item.badge ? (\n <span\n className={cn(\n \"ml-0.5 inline-flex h-4 min-w-4 items-center justify-center rounded-full bg-destructive px-1 text-[10px] text-primary-foreground leading-none\",\n !isExpanded && \"absolute top-0.5 right-0.5\",\n classNames?.badge,\n )}\n >\n {item.badge}\n </span>\n ) : null}\n </>\n )}\n </motion.button>\n );\n })}\n </motion.div>\n </motion.div>\n </LayoutGroup>\n );\n}\n\nexport function useExpandableActionBar(items: ExpandableActionBarItem[]) {\n const [expanded, setExpanded] = useState(false);\n const [activeId, setActiveId] = useState(items[0]?.id);\n\n const activeItem = useMemo(() => items.find((item) => item.id === activeId), [activeId, items]);\n\n return useMemo(\n () => ({ expanded, setExpanded, activeId, setActiveId, activeItem }),\n [activeId, activeItem, expanded],\n );\n}\n"],"mappings":";;;;;;AA4DA,MAAM,kBAA8B;CAClC,MAAM;CACN,WAAW;CACX,SAAS;CACT,MAAM;AACR;AAEA,MAAM,mBAA+B;CACnC,MAAM;CACN,WAAW;CACX,S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a,cAAc,MAAM,MAAM,SAAS,KAAK,OAAO,QAAQ,GAAG,CAAC,UAAU,KAAK,CAAC;CAE9F,OAAO,eACE;EAAE;EAAU;EAAa;EAAU;EAAa;CAAW,IAClE;EAAC;EAAU;EAAY;CAAQ,CACjC;AACF"}
|
|
1
|
+
{"version":3,"file":"expandable-action-bar.js","names":[],"sources":["../../../src/components/motion/expandable-action-bar.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type FocusEvent,\n type MouseEvent,\n type PointerEvent,\n type ReactNode,\n useCallback,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { LayoutGroup, 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\";\n\nexport type ExpandableActionBarSize = \"sm\" | \"md\";\n\nexport type ExpandableActionBarItem = {\n id: string;\n label: ReactNode;\n icon: ReactNode;\n onClick?: () => void;\n disabled?: boolean;\n active?: boolean;\n badge?: ReactNode;\n shortcut?: ReactNode;\n};\n\nexport type ExpandableActionBarClassNames = {\n root?: string;\n track?: string;\n item?: string;\n activeItem?: string;\n icon?: string;\n label?: string;\n badge?: string;\n shortcut?: string;\n};\n\nexport interface ExpandableActionBarProps {\n items: ExpandableActionBarItem[];\n expanded?: boolean;\n defaultExpanded?: boolean;\n onExpandedChange?: (expanded: boolean) => void;\n activeId?: string;\n onAction?: (item: ExpandableActionBarItem) => void;\n size?: ExpandableActionBarSize;\n /**\n * Expand when a pointer that hovers rests on the bar. Default true. It also\n * governs the touch equivalent: with no hover to reveal the labels, the\n * first tap expands the bar and runs no action, and the second one acts.\n * Set false to make every tap and click act immediately.\n */\n expandOnHover?: boolean;\n expandOnFocus?: boolean;\n collapseDelay?: number;\n className?: string;\n classNames?: ExpandableActionBarClassNames;\n renderItem?: (\n item: ExpandableActionBarItem,\n state: { expanded: boolean; active: boolean },\n ) => ReactNode;\n}\n\nconst ITEM_TRANSITION: Transition = {\n type: \"spring\",\n stiffness: 460,\n damping: 34,\n mass: 0.62,\n};\n\nconst LABEL_TRANSITION: Transition = {\n type: \"spring\",\n stiffness: 380,\n damping: 32,\n mass: 0.7,\n};\n\nconst SIZE_CLASS: Record<ExpandableActionBarSize, string> = {\n sm: \"min-h-9 gap-1 p-1 text-xs\",\n md: \"min-h-11 gap-1.5 p-1.5 text-sm\",\n};\n\nconst ITEM_SIZE_CLASS: Record<ExpandableActionBarSize, string> = {\n sm: \"h-7 min-w-7 px-1.5\",\n md: \"h-8 min-w-8 px-2\",\n};\n\nconst ICON_SIZE_CLASS: Record<ExpandableActionBarSize, string> = {\n sm: \"h-3.5 w-3.5\",\n md: \"h-4 w-4\",\n};\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 ?? false);\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\nexport function ExpandableActionBar({\n items,\n expanded,\n defaultExpanded = false,\n onExpandedChange,\n activeId,\n onAction,\n size = \"md\",\n expandOnHover = true,\n expandOnFocus = true,\n collapseDelay = 90,\n className,\n classNames,\n renderItem,\n}: ExpandableActionBarProps) {\n const reduce = useReducedMotion();\n const layoutId = useId();\n const [isExpanded, setIsExpanded] = useControllableExpanded({\n expanded,\n defaultExpanded,\n onExpandedChange,\n });\n const [hoveredId, setHoveredId] = useState<string | null>(null);\n // Set by the tap that expands the bar, 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 const collapseTimer = useRef<number | null>(null);\n const trackRef = useRef<HTMLDivElement | null>(null);\n // What the last gesture on an action was, and whether the bar was already\n // expanded when it started. A click reports neither.\n const tap = useTapGesture<boolean>();\n const hover = useHoverGesture();\n\n const clearCollapseTimer = useCallback(() => {\n if (collapseTimer.current) window.clearTimeout(collapseTimer.current);\n collapseTimer.current = null;\n }, []);\n\n const open = useCallback(() => {\n clearCollapseTimer();\n setIsExpanded(true);\n }, [clearCollapseTimer, setIsExpanded]);\n\n const close = useCallback(() => {\n clearCollapseTimer();\n const timer = window.setTimeout(() => {\n setIsExpanded(false);\n setHoveredId(null);\n setTapExpanded(false);\n }, collapseDelay);\n collapseTimer.current = timer;\n }, [clearCollapseTimer, collapseDelay, setIsExpanded]);\n\n useEffect(() => clearCollapseTimer, [clearCollapseTimer]);\n\n // A collapse from outside takes the labels with it, so the arm the tap that\n // expanded the bar left behind has to go too — otherwise the next tap runs\n // an action whose label nobody can read. Only on the way down from expanded:\n // a controlled bar that declined to expand at all keeps its arm, which is\n // what lets its second tap act.\n const wasExpanded = useRef(isExpanded);\n useEffect(() => {\n if (wasExpanded.current && !isExpanded) setTapExpanded(false);\n wasExpanded.current = isExpanded;\n }, [isExpanded]);\n\n // A finger never hovers and Safari does not focus a button on tap, so a bar a\n // tap expanded would have nothing to close it. The tap that lands elsewhere\n // stands in for the pointer leaving — and it is consumed rather than passed\n // through, because the labelled bar is exactly the kind of surface people\n // dismiss by tapping just past it, over whatever control is there.\n useDismiss(tapExpanded && isExpanded, close, trackRef, {\n behavior: \"consume\",\n });\n\n const onRootPointerEnter = (event: PointerEvent<HTMLDivElement>) => {\n // The gesture is told about every enter, `expandOnHover` or not: it is\n // what the matching leave is read against.\n if (hover.enter(event) && expandOnHover) open();\n };\n\n const onRootPointerLeave = (event: PointerEvent<HTMLDivElement>) => {\n if (!hover.leave(event)) return;\n setHoveredId(null);\n if (expandOnHover) close();\n };\n\n const onRootFocus = () => {\n if (expandOnFocus) open();\n };\n\n const onRootBlur = (event: FocusEvent<HTMLDivElement>) => {\n if (!event.currentTarget.contains(event.relatedTarget as Node) && expandOnFocus) {\n close();\n }\n };\n\n const activeItemId = activeId ?? items.find((item) => item.active)?.id;\n const highlightId = hoveredId ?? activeItemId;\n\n return (\n <LayoutGroup id={layoutId}>\n <motion.div\n layout=\"size\"\n // Pointer events, not the mouse pair: a tap fires compatibility\n // mouseenter/mouseleave that carry no pointerType, and the bar growing\n // under a stationary finger fired the leave before the click ever\n // landed — so one tap expanded, collapsed and ran nothing.\n onPointerEnter={onRootPointerEnter}\n onPointerLeave={onRootPointerLeave}\n onFocus={onRootFocus}\n onBlur={onRootBlur}\n transition={ITEM_TRANSITION}\n className={cn(\"inline-flex max-w-full\", classNames?.root, className)}\n >\n <motion.div\n ref={trackRef}\n layout=\"size\"\n className={cn(\n // Labelled actions can outgrow the space the bar sits in — the pill\n // stays inside it and scrolls its rail rather than running off the\n // edge, where the last action is unreachable.\n \"scrollbar-hide relative inline-flex max-w-full items-center overflow-x-auto overflow-y-hidden rounded-full border border-border bg-card/90 shadow-2xl backdrop-blur-xl\",\n SIZE_CLASS[size],\n classNames?.track,\n )}\n transition={ITEM_TRANSITION}\n >\n {items.map((item) => {\n const isActive = item.active || activeId === item.id;\n const isHighlighted = highlightId === item.id;\n\n return (\n <motion.button\n key={item.id}\n layout=\"position\"\n type=\"button\"\n disabled={item.disabled}\n title={typeof item.label === \"string\" ? item.label : undefined}\n onPointerEnter={(event: PointerEvent<HTMLButtonElement>) => {\n if (!hover.enter(event)) return;\n clearCollapseTimer();\n setHoveredId(item.id);\n }}\n onPointerDown={(event: PointerEvent<HTMLButtonElement>) => {\n tap.start(event, isExpanded);\n }}\n // A gesture the platform takes away sends no click, and a key\n // press starts an activation that never had a pointer behind\n // it: either one would otherwise leave the finger in place for\n // the next click to spend.\n onPointerCancel={tap.drop}\n onKeyDown={tap.drop}\n onClick={(event: MouseEvent<HTMLButtonElement>) => {\n event.currentTarget.blur();\n const gesture = tap.take();\n // Nothing reveals the labels to a finger, so the first tap\n // expands the bar and the next one runs the action. The bar\n // state is read from the gesture's start: a browser that\n // focuses the button on contact expands it mid-tap, and that\n // first tap would otherwise fire the action it was meant to\n // reveal. `tapExpanded` arms the second tap, so a controlled\n // bar that declines to expand still runs the action rather\n // than swallowing every tap.\n const firstTap =\n gesture !== null &&\n gesture.pointerType !== \"mouse\" &&\n !gesture.state &&\n !tapExpanded;\n if (firstTap && expandOnHover) {\n setTapExpanded(true);\n open();\n setHoveredId(item.id);\n return;\n }\n item.onClick?.();\n onAction?.(item);\n }}\n whileTap={reduce || item.disabled ? undefined : { scale: 0.96 }}\n transition={ITEM_TRANSITION}\n className={cn(\n \"relative isolate inline-flex shrink-0 items-center justify-center overflow-hidden rounded-full font-medium text-muted-foreground outline-none transition-[color,background-color] duration-150 ease-out\",\n \"focus-visible:text-foreground disabled:pointer-events-none disabled:opacity-40\",\n isHighlighted && \"text-foreground\",\n ITEM_SIZE_CLASS[size],\n classNames?.item,\n isActive && classNames?.activeItem,\n )}\n >\n {isHighlighted ? (\n <motion.span\n layoutId=\"action-bar-highlight\"\n className=\"absolute inset-0 -z-10 rounded-full bg-primary/[0.07]\"\n transition={ITEM_TRANSITION}\n />\n ) : null}\n\n {renderItem ? (\n renderItem(item, { expanded: isExpanded, active: isActive })\n ) : (\n <>\n <span\n className={cn(\n \"inline-flex shrink-0 items-center justify-center\",\n ICON_SIZE_CLASS[size],\n classNames?.icon,\n )}\n >\n {item.icon}\n </span>\n\n <motion.span\n aria-hidden={!isExpanded}\n animate={\n reduce\n ? {\n width: isExpanded ? \"auto\" : 0,\n opacity: isExpanded ? 1 : 0,\n marginLeft: isExpanded ? 8 : 0,\n x: 0,\n filter: \"blur(0px)\",\n }\n : {\n width: isExpanded ? \"auto\" : 0,\n opacity: isExpanded ? 1 : 0,\n x: isExpanded ? 0 : -4,\n marginLeft: isExpanded ? 8 : 0,\n filter: isExpanded ? \"blur(0px)\" : \"blur(3px)\",\n }\n }\n transition={reduce ? { duration: 0 } : LABEL_TRANSITION}\n className={cn(\n \"inline-block overflow-hidden whitespace-nowrap\",\n classNames?.label,\n )}\n >\n {item.label}\n </motion.span>\n\n {item.shortcut ? (\n <motion.span\n aria-hidden={!isExpanded}\n animate={{\n width: isExpanded ? \"auto\" : 0,\n opacity: isExpanded ? 1 : 0,\n marginLeft: isExpanded ? 4 : 0,\n }}\n transition={LABEL_TRANSITION}\n className={cn(\n \"hidden overflow-hidden whitespace-nowrap text-[10px] text-muted-foreground sm:inline-block\",\n classNames?.shortcut,\n )}\n >\n {item.shortcut}\n </motion.span>\n ) : null}\n\n {item.badge ? (\n <span\n className={cn(\n \"ml-0.5 inline-flex h-4 min-w-4 items-center justify-center rounded-full bg-destructive px-1 text-[10px] text-primary-foreground leading-none\",\n !isExpanded && \"absolute top-0.5 right-0.5\",\n classNames?.badge,\n )}\n >\n {item.badge}\n </span>\n ) : null}\n </>\n )}\n </motion.button>\n );\n })}\n </motion.div>\n </motion.div>\n </LayoutGroup>\n );\n}\n\nexport function useExpandableActionBar(items: ExpandableActionBarItem[]) {\n const [expanded, setExpanded] = useState(false);\n const [activeId, setActiveId] = useState(items[0]?.id);\n\n const activeItem = useMemo(() => items.find((item) => item.id === activeId), [activeId, items]);\n\n return useMemo(\n () => ({ expanded, setExpanded, activeId, setActiveId, activeItem }),\n [activeId, activeItem, expanded],\n );\n}\n"],"mappings":";;;;;;;;;AAsEA,MAAM,kBAA8B;CAClC,MAAM;CACN,WAAW;CACX,SAAS;CACT,MAAM;AACR;AAEA,MAAM,mBAA+B;CACnC,MAAM;CACN,WAAW;CACX,SAAS;CACT,MAAM;AACR;AAEA,MAAM,aAAsD;CAC1D,IAAI;CACJ,IAAI;AACN;AAEA,MAAM,kBAA2D;CAC/D,IAAI;CACJ,IAAI;AACN;AAEA,MAAM,kBAA2D;CAC/D,IAAI;CACJ,IAAI;AACN;AAEA,SAAS,wBAAwB,EAC/B,UACA,iBACA,oBAKC;CACD,MAAM,CAAC,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C;QACd,SAAS;SACP,OAAO,aAAa,SAAS;SAC7B,SAAS,aAAa,IAAI;SAC1B,YAAY,aAAa,IAAI;QAC/B;QACA,YAAY;QACZ,WAAW,GACT,8FACA,YAAY,QACd;QAEC,UAAA,KAAK;OACK,CAAA,IACX;OAEH,KAAK,QACJ,oBAAC,QAAD;QACE,WAAW,GACT,gJACA,CAAC,cAAc,8BACf,YAAY,KACd;QAEC,UAAA,KAAK;OACF,CAAA,IACJ;MACJ,EAAA,CAAA,CAES;KAxIR,GAAA,KAAK,EAwIG;IAEnB,CAAC;GACS,CAAA;EACF,CAAA;CACD,CAAA;AAEjB;AAEA,SAAgB,uBAAuB,OAAkC;CACvE,MAAM,CAAC,UAAU,eAAe,SAAS,KAAK;CAC9C,MAAM,CAAC,UAAU,eAAe,SAAS,MAAM,EAAE,EAAE,EAAE;CAErD,MAAM,aAAa,cAAc,MAAM,MAAM,SAAS,KAAK,OAAO,QAAQ,GAAG,CAAC,UAAU,KAAK,CAAC;CAE9F,OAAO,eACE;EAAE;EAAU;EAAa;EAAU;EAAa;CAAW,IAClE;EAAC;EAAU;EAAY;CAAQ,CACjC;AACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ReactNode } from "react";
|
|
2
2
|
import { HTMLMotionProps } from "motion/react";
|
|
3
3
|
//#region src/components/motion/hold-action-button.d.ts
|
|
4
|
-
interface HoldActionButtonProps extends Omit<HTMLMotionProps<"button">, "children" | "type" | "onClick" | "onPointerDown" | "onPointerUp" | "onPointerCancel" | "onPointerLeave" | "onKeyDown" | "onKeyUp"> {
|
|
4
|
+
interface HoldActionButtonProps extends Omit<HTMLMotionProps<"button">, "children" | "type" | "onClick" | "onPointerDown" | "onPointerUp" | "onPointerCancel" | "onPointerLeave" | "onPointerMove" | "onKeyDown" | "onKeyUp"> {
|
|
5
5
|
children: ReactNode;
|
|
6
6
|
type?: "vertical" | "horizontal";
|
|
7
7
|
holdingLabel?: ReactNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hold-action-button.d.ts","names":[],"sources":["../../../src/components/motion/hold-action-button.tsx"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"hold-action-button.d.ts","names":[],"sources":["../../../src/components/motion/hold-action-button.tsx"],"mappings":";;;UAgBiB,8BACP,KACN;EAYF,UAAU;EACV;EACA,eAAe;EACf,gBAAgB;EAChB;EACA;EACA;EACA;;cAGW,kCAAgB,0BAAA,KAAA,gDAAA,cAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { TOUCH_GESTURE_CLASS, capturePointer, releasePointer } from "../../lib/touch.js";
|
|
2
3
|
import { EASE_OUT, SPRING_PRESS } from "../../lib/ease.js";
|
|
3
4
|
import { forwardRef, useRef, useState } from "react";
|
|
4
5
|
import { cn } from "@kumix/utils";
|
|
@@ -22,13 +23,21 @@ const HoldActionButton = forwardRef(function HoldActionButton({ children, type =
|
|
|
22
23
|
};
|
|
23
24
|
const handlePointerDown = (event) => {
|
|
24
25
|
if (event.button !== 0) return;
|
|
25
|
-
event.currentTarget.setPointerCapture(event.pointerId);
|
|
26
26
|
startHold();
|
|
27
|
+
capturePointer(event.currentTarget, event.pointerId);
|
|
27
28
|
};
|
|
28
29
|
const handlePointerUp = (event) => {
|
|
29
|
-
|
|
30
|
+
releasePointer(event.currentTarget, event.pointerId);
|
|
30
31
|
cancelHold();
|
|
31
32
|
};
|
|
33
|
+
const handlePointerLeave = (event) => {
|
|
34
|
+
if (event.pointerType !== "touch") cancelHold();
|
|
35
|
+
};
|
|
36
|
+
const handlePointerMove = (event) => {
|
|
37
|
+
if (!holding) return;
|
|
38
|
+
const rect = event.currentTarget.getBoundingClientRect();
|
|
39
|
+
if (event.clientX < rect.left || event.clientX > rect.right || event.clientY < rect.top || event.clientY > rect.bottom) cancelHold();
|
|
40
|
+
};
|
|
32
41
|
const handleKeyDown = (event) => {
|
|
33
42
|
if ((event.key === " " || event.key === "Enter") && !event.repeat) {
|
|
34
43
|
event.preventDefault();
|
|
@@ -56,66 +65,71 @@ const HoldActionButton = forwardRef(function HoldActionButton({ children, type =
|
|
|
56
65
|
disabled,
|
|
57
66
|
"aria-label": typeof children === "string" ? children : void 0,
|
|
58
67
|
onPointerDown: handlePointerDown,
|
|
68
|
+
onPointerMove: handlePointerMove,
|
|
59
69
|
onPointerUp: handlePointerUp,
|
|
60
70
|
onPointerCancel: cancelHold,
|
|
61
|
-
onPointerLeave:
|
|
71
|
+
onPointerLeave: handlePointerLeave,
|
|
62
72
|
onKeyDown: handleKeyDown,
|
|
63
73
|
onKeyUp: handleKeyUp,
|
|
64
74
|
onContextMenu: (event) => event.preventDefault(),
|
|
65
75
|
whileTap: reduce || disabled ? void 0 : { scale: .98 },
|
|
66
76
|
transition: SPRING_PRESS,
|
|
67
|
-
className: cn("relative inline-grid h-16 min-w-72 touch-none
|
|
77
|
+
className: cn("relative inline-grid h-16 min-w-72 touch-none place-items-center overflow-hidden rounded-(--hold-radius) bg-primary px-8 text-primary-foreground", "[--hold-radius:22px]", TOUCH_GESTURE_CLASS, "outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 focus-visible:ring-offset-background", "disabled:pointer-events-none disabled:opacity-50", className),
|
|
68
78
|
...rest,
|
|
69
|
-
children: [/* @__PURE__ */ jsx(
|
|
79
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
70
80
|
"aria-hidden": "true",
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
opacity: active ? 1 : 0,
|
|
74
|
-
transform: "none"
|
|
75
|
-
} : {
|
|
76
|
-
opacity: 1,
|
|
77
|
-
transform: active ? activeTransform : idleTransform
|
|
78
|
-
},
|
|
79
|
-
transition: active ? {
|
|
80
|
-
duration: holdDuration / 1e3,
|
|
81
|
-
ease: "linear"
|
|
82
|
-
} : {
|
|
83
|
-
duration: reduce ? .15 : .24,
|
|
84
|
-
ease: EASE_OUT
|
|
85
|
-
},
|
|
86
|
-
onAnimationComplete: handleFillComplete,
|
|
87
|
-
className: cn("absolute inset-0 bg-sky-400 will-change-[opacity,transform]", fillClassName),
|
|
88
|
-
children: !reduce ? type === "horizontal" ? /* @__PURE__ */ jsx(motion.svg, {
|
|
89
|
-
viewBox: "0 0 24 240",
|
|
90
|
-
preserveAspectRatio: "none",
|
|
81
|
+
className: "pointer-events-none absolute inset-0 [clip-path:inset(0_round_var(--hold-radius))]",
|
|
82
|
+
children: /* @__PURE__ */ jsx(motion.span, {
|
|
91
83
|
"aria-hidden": "true",
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
84
|
+
initial: false,
|
|
85
|
+
animate: reduce ? {
|
|
86
|
+
opacity: active ? 1 : 0,
|
|
87
|
+
transform: "none"
|
|
88
|
+
} : {
|
|
89
|
+
opacity: 1,
|
|
90
|
+
transform: active ? activeTransform : idleTransform
|
|
97
91
|
},
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
viewBox: "0 0 240 24",
|
|
105
|
-
preserveAspectRatio: "none",
|
|
106
|
-
"aria-hidden": "true",
|
|
107
|
-
animate: { transform: active ? "translateX(-50%)" : "translateX(0%)" },
|
|
108
|
-
transition: {
|
|
109
|
-
duration: 1.1,
|
|
110
|
-
ease: "linear",
|
|
111
|
-
repeat: active ? Number.POSITIVE_INFINITY : 0
|
|
92
|
+
transition: active ? {
|
|
93
|
+
duration: holdDuration / 1e3,
|
|
94
|
+
ease: "linear"
|
|
95
|
+
} : {
|
|
96
|
+
duration: reduce ? .15 : .24,
|
|
97
|
+
ease: EASE_OUT
|
|
112
98
|
},
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
99
|
+
onAnimationComplete: handleFillComplete,
|
|
100
|
+
className: cn("absolute inset-0 bg-sky-400 will-change-[opacity,transform]", fillClassName),
|
|
101
|
+
children: !reduce ? type === "horizontal" ? /* @__PURE__ */ jsx(motion.svg, {
|
|
102
|
+
viewBox: "0 0 24 240",
|
|
103
|
+
preserveAspectRatio: "none",
|
|
104
|
+
"aria-hidden": "true",
|
|
105
|
+
animate: { transform: active ? "translateY(-50%)" : "translateY(0%)" },
|
|
106
|
+
transition: {
|
|
107
|
+
duration: 1.1,
|
|
108
|
+
ease: "linear",
|
|
109
|
+
repeat: active ? Number.POSITIVE_INFINITY : 0
|
|
110
|
+
},
|
|
111
|
+
className: "absolute top-0 -right-5 h-[200%] w-6 text-sky-400",
|
|
112
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
113
|
+
d: "M0 0h12C2 20 2 40 12 60s10 40 0 60-10 40 0 60 10 40 0 60H0Z",
|
|
114
|
+
fill: "currentColor"
|
|
115
|
+
})
|
|
116
|
+
}) : /* @__PURE__ */ jsx(motion.svg, {
|
|
117
|
+
viewBox: "0 0 240 24",
|
|
118
|
+
preserveAspectRatio: "none",
|
|
119
|
+
"aria-hidden": "true",
|
|
120
|
+
animate: { transform: active ? "translateX(-50%)" : "translateX(0%)" },
|
|
121
|
+
transition: {
|
|
122
|
+
duration: 1.1,
|
|
123
|
+
ease: "linear",
|
|
124
|
+
repeat: active ? Number.POSITIVE_INFINITY : 0
|
|
125
|
+
},
|
|
126
|
+
className: "absolute -top-5 left-0 h-6 w-[200%] text-sky-400",
|
|
127
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
128
|
+
d: "M0 12C20 2 40 2 60 12s40 10 60 0 40-10 60 0 40 10 60 0v12H0Z",
|
|
129
|
+
fill: "currentColor"
|
|
130
|
+
})
|
|
131
|
+
}) : null
|
|
132
|
+
})
|
|
119
133
|
}), /* @__PURE__ */ jsxs("span", {
|
|
120
134
|
className: cn("relative z-10 grid place-items-center font-medium text-base tracking-[-0.01em]", labelClassName),
|
|
121
135
|
children: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hold-action-button.js","names":[],"sources":["../../../src/components/motion/hold-action-button.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n forwardRef,\n type KeyboardEvent,\n type PointerEvent,\n type ReactNode,\n useRef,\n useState,\n} from \"react\";\nimport { type HTMLMotionProps, motion, useReducedMotion } from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { EASE_OUT, SPRING_PRESS } from \"../../lib/ease\";\n\nexport interface HoldActionButtonProps\n extends Omit<\n HTMLMotionProps<\"button\">,\n | \"children\"\n | \"type\"\n | \"onClick\"\n | \"onPointerDown\"\n | \"onPointerUp\"\n | \"onPointerCancel\"\n | \"onPointerLeave\"\n | \"onKeyDown\"\n | \"onKeyUp\"\n > {\n children: ReactNode;\n type?: \"vertical\" | \"horizontal\";\n holdingLabel?: ReactNode;\n completeLabel?: ReactNode;\n holdDuration?: number;\n onHoldComplete?: () => void;\n fillClassName?: string;\n labelClassName?: string;\n}\n\nexport const HoldActionButton = forwardRef<HTMLButtonElement, HoldActionButtonProps>(\n function HoldActionButton(\n {\n children,\n type = \"vertical\",\n holdingLabel = \"Keep holding\",\n completeLabel = \"Done\",\n holdDuration = 1600,\n onHoldComplete,\n fillClassName,\n labelClassName,\n className,\n disabled,\n ...rest\n },\n ref,\n ) {\n const reduce = useReducedMotion();\n const completedRef = useRef(false);\n const [holding, setHolding] = useState(false);\n const [completed, setCompleted] = useState(false);\n\n const startHold = () => {\n if (disabled || holding) return;\n completedRef.current = false;\n setCompleted(false);\n setHolding(true);\n };\n\n const cancelHold = () => {\n setHolding(false);\n setCompleted(false);\n };\n\n const handlePointerDown = (event: PointerEvent<HTMLButtonElement>) => {\n if (event.button !== 0) return;\n event.currentTarget.setPointerCapture(event.pointerId);\n startHold();\n };\n\n const handlePointerUp = (event: PointerEvent<HTMLButtonElement>) => {\n if (event.currentTarget.hasPointerCapture(event.pointerId)) {\n event.currentTarget.releasePointerCapture(event.pointerId);\n }\n cancelHold();\n };\n\n const handleKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {\n if ((event.key === \" \" || event.key === \"Enter\") && !event.repeat) {\n event.preventDefault();\n startHold();\n }\n };\n\n const handleKeyUp = (event: KeyboardEvent<HTMLButtonElement>) => {\n if (event.key === \" \" || event.key === \"Enter\") {\n event.preventDefault();\n cancelHold();\n }\n };\n\n const handleFillComplete = () => {\n if (!holding || completedRef.current) return;\n completedRef.current = true;\n setCompleted(true);\n onHoldComplete?.();\n };\n\n const active = holding || completed;\n const activeTransform = type === \"horizontal\" ? \"translateX(0%)\" : \"translateY(0%)\";\n const idleTransform = type === \"horizontal\" ? \"translateX(-100%)\" : \"translateY(115%)\";\n\n return (\n <motion.button\n ref={ref}\n type=\"button\"\n disabled={disabled}\n aria-label={typeof children === \"string\" ? children : undefined}\n onPointerDown={handlePointerDown}\n onPointerUp={handlePointerUp}\n onPointerCancel={cancelHold}\n onPointerLeave={cancelHold}\n onKeyDown={handleKeyDown}\n onKeyUp={handleKeyUp}\n onContextMenu={(event) => event.preventDefault()}\n whileTap={reduce || disabled ? undefined : { scale: 0.98 }}\n transition={SPRING_PRESS}\n className={cn(\n \"relative inline-grid h-16 min-w-72 touch-none select-none place-items-center overflow-hidden rounded-[22px] bg-primary px-8 text-primary-foreground\",\n \"outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 focus-visible:ring-offset-background\",\n \"disabled:pointer-events-none disabled:opacity-50\",\n className,\n )}\n {...rest}\n >\n <motion.span\n aria-hidden=\"true\"\n initial={false}\n animate={\n reduce\n ? { opacity: active ? 1 : 0, transform: \"none\" }\n : {\n opacity: 1,\n transform: active ? activeTransform : idleTransform,\n }\n }\n transition={\n active\n ? { duration: holdDuration / 1000, ease: \"linear\" }\n : { duration: reduce ? 0.15 : 0.24, ease: EASE_OUT }\n }\n onAnimationComplete={handleFillComplete}\n className={cn(\n \"absolute inset-0 bg-sky-400 will-change-[opacity,transform]\",\n fillClassName,\n )}\n >\n {!reduce ? (\n type === \"horizontal\" ? (\n <motion.svg\n viewBox=\"0 0 24 240\"\n preserveAspectRatio=\"none\"\n aria-hidden=\"true\"\n animate={{\n transform: active ? \"translateY(-50%)\" : \"translateY(0%)\",\n }}\n transition={{\n duration: 1.1,\n ease: \"linear\",\n repeat: active ? Number.POSITIVE_INFINITY : 0,\n }}\n className=\"absolute top-0 -right-5 h-[200%] w-6 text-sky-400\"\n >\n <path\n d=\"M0 0h12C2 20 2 40 12 60s10 40 0 60-10 40 0 60 10 40 0 60H0Z\"\n fill=\"currentColor\"\n />\n </motion.svg>\n ) : (\n <motion.svg\n viewBox=\"0 0 240 24\"\n preserveAspectRatio=\"none\"\n aria-hidden=\"true\"\n animate={{\n transform: active ? \"translateX(-50%)\" : \"translateX(0%)\",\n }}\n transition={{\n duration: 1.1,\n ease: \"linear\",\n repeat: active ? Number.POSITIVE_INFINITY : 0,\n }}\n className=\"absolute -top-5 left-0 h-6 w-[200%] text-sky-400\"\n >\n <path\n d=\"M0 12C20 2 40 2 60 12s40 10 60 0 40-10 60 0 40 10 60 0v12H0Z\"\n fill=\"currentColor\"\n />\n </motion.svg>\n )\n ) : null}\n </motion.span>\n\n <span\n className={cn(\n \"relative z-10 grid place-items-center font-medium text-base tracking-[-0.01em]\",\n labelClassName,\n )}\n >\n <motion.span\n animate={{ opacity: active ? 0 : 1 }}\n transition={{ duration: reduce ? 0 : 0.12, ease: EASE_OUT }}\n className=\"col-start-1 row-start-1\"\n >\n {children}\n </motion.span>\n <motion.span\n aria-hidden={!holding || completed}\n animate={{ opacity: holding && !completed ? 1 : 0 }}\n transition={{ duration: reduce ? 0 : 0.12, ease: EASE_OUT }}\n className=\"col-start-1 row-start-1\"\n >\n {holdingLabel}\n </motion.span>\n <motion.span\n aria-hidden={!completed}\n animate={{ opacity: completed ? 1 : 0 }}\n transition={{ duration: reduce ? 0 : 0.12, ease: EASE_OUT }}\n className=\"col-start-1 row-start-1\"\n >\n {completeLabel}\n </motion.span>\n </span>\n </motion.button>\n );\n },\n);\n"],"mappings":";;;;;;;AAsCA,MAAa,mBAAmB,WAC9B,SAA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AAY;MAAE,UAAU,SAAS,IAAI;MAAM,MAAM;KAAS;KAC1D,WAAU;KAET;IACU,CAAA;IACb,oBAAC,OAAO,MAAR;KACE,eAAa,CAAC,WAAW;KACzB,SAAS,EAAE,SAAS,WAAW,CAAC,YAAY,IAAI,EAAE;KAClD,YAAY;MAAE,UAAU,SAAS,IAAI;MAAM,MAAM;KAAS;KAC1D,WAAU;KAET,UAAA;IACU,CAAA;IACb,oBAAC,OAAO,MAAR;KACE,eAAa,CAAC;KACd,SAAS,EAAE,SAAS,YAAY,IAAI,EAAE;KACtC,YAAY;MAAE,UAAU,SAAS,IAAI;MAAM,MAAM;KAAS;KAC1D,WAAU;KAET,UAAA;IACU,CAAA;GACT;EACO,CAAA,CAAA;;AAEnB,CACF"}
|
|
1
|
+
{"version":3,"file":"hold-action-button.js","names":[],"sources":["../../../src/components/motion/hold-action-button.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n forwardRef,\n type KeyboardEvent,\n type PointerEvent,\n type ReactNode,\n useRef,\n useState,\n} from \"react\";\nimport { type HTMLMotionProps, motion, useReducedMotion } from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { EASE_OUT, SPRING_PRESS } from \"../../lib/ease\";\nimport { capturePointer, releasePointer, TOUCH_GESTURE_CLASS } from \"../../lib/touch\";\n\nexport interface HoldActionButtonProps\n extends Omit<\n HTMLMotionProps<\"button\">,\n | \"children\"\n | \"type\"\n | \"onClick\"\n | \"onPointerDown\"\n | \"onPointerUp\"\n | \"onPointerCancel\"\n | \"onPointerLeave\"\n | \"onPointerMove\"\n | \"onKeyDown\"\n | \"onKeyUp\"\n > {\n children: ReactNode;\n type?: \"vertical\" | \"horizontal\";\n holdingLabel?: ReactNode;\n completeLabel?: ReactNode;\n holdDuration?: number;\n onHoldComplete?: () => void;\n fillClassName?: string;\n labelClassName?: string;\n}\n\nexport const HoldActionButton = forwardRef<HTMLButtonElement, HoldActionButtonProps>(\n function HoldActionButton(\n {\n children,\n type = \"vertical\",\n holdingLabel = \"Keep holding\",\n completeLabel = \"Done\",\n holdDuration = 1600,\n onHoldComplete,\n fillClassName,\n labelClassName,\n className,\n disabled,\n ...rest\n },\n ref,\n ) {\n const reduce = useReducedMotion();\n const completedRef = useRef(false);\n const [holding, setHolding] = useState(false);\n const [completed, setCompleted] = useState(false);\n\n const startHold = () => {\n if (disabled || holding) return;\n completedRef.current = false;\n setCompleted(false);\n setHolding(true);\n };\n\n const cancelHold = () => {\n setHolding(false);\n setCompleted(false);\n };\n\n const handlePointerDown = (event: PointerEvent<HTMLButtonElement>) => {\n if (event.button !== 0) return;\n // Start first: capture is a convenience, and a browser that refuses it\n // must not take the hold down with it.\n startHold();\n capturePointer(event.currentTarget, event.pointerId);\n };\n\n const handlePointerUp = (event: PointerEvent<HTMLButtonElement>) => {\n releasePointer(event.currentTarget, event.pointerId);\n cancelHold();\n };\n\n const handlePointerLeave = (event: PointerEvent<HTMLButtonElement>) => {\n // Only reached when the capture below was refused: a captured pointer gets\n // no boundary events at all. A finger does not get this reading either way\n // — WebKit fires leave repeatedly for a touch that never moved, which\n // would cancel every hold on the frame it started.\n if (event.pointerType !== \"touch\") cancelHold();\n };\n\n const handlePointerMove = (event: PointerEvent<HTMLButtonElement>) => {\n // Leaving the button abandons the hold, and while the pointer is captured\n // nothing announces that: no boundary events, and `touch-none` means a\n // finger sliding off cannot scroll and so cannot cancel either. Measure it\n // instead — off the button ends the hold, wherever the pointer then goes.\n if (!holding) return;\n\n const rect = event.currentTarget.getBoundingClientRect();\n const outside =\n event.clientX < rect.left ||\n event.clientX > rect.right ||\n event.clientY < rect.top ||\n event.clientY > rect.bottom;\n\n if (outside) cancelHold();\n };\n\n const handleKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {\n if ((event.key === \" \" || event.key === \"Enter\") && !event.repeat) {\n event.preventDefault();\n startHold();\n }\n };\n\n const handleKeyUp = (event: KeyboardEvent<HTMLButtonElement>) => {\n if (event.key === \" \" || event.key === \"Enter\") {\n event.preventDefault();\n cancelHold();\n }\n };\n\n const handleFillComplete = () => {\n if (!holding || completedRef.current) return;\n completedRef.current = true;\n setCompleted(true);\n onHoldComplete?.();\n };\n\n const active = holding || completed;\n const activeTransform = type === \"horizontal\" ? \"translateX(0%)\" : \"translateY(0%)\";\n const idleTransform = type === \"horizontal\" ? \"translateX(-100%)\" : \"translateY(115%)\";\n\n return (\n <motion.button\n ref={ref}\n type=\"button\"\n disabled={disabled}\n aria-label={typeof children === \"string\" ? children : undefined}\n onPointerDown={handlePointerDown}\n onPointerMove={handlePointerMove}\n onPointerUp={handlePointerUp}\n onPointerCancel={cancelHold}\n onPointerLeave={handlePointerLeave}\n onKeyDown={handleKeyDown}\n onKeyUp={handleKeyUp}\n onContextMenu={(event) => event.preventDefault()}\n whileTap={reduce || disabled ? undefined : { scale: 0.98 }}\n transition={SPRING_PRESS}\n className={cn(\n \"relative inline-grid h-16 min-w-72 touch-none place-items-center overflow-hidden rounded-(--hold-radius) bg-primary px-8 text-primary-foreground\",\n \"[--hold-radius:22px]\",\n TOUCH_GESTURE_CLASS,\n \"outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 focus-visible:ring-offset-background\",\n \"disabled:pointer-events-none disabled:opacity-50\",\n className,\n )}\n {...rest}\n >\n {/* Safari hands the fill its own compositing layer and then stops\n applying the button's rounded overflow clip to it, so the liquid\n bleeds past the corners. clip-path survives compositing. It lives on\n this static layer rather than the button so it never cuts the focus\n ring, and reads the same radius so the two cannot drift apart. */}\n <span\n aria-hidden=\"true\"\n className=\"pointer-events-none absolute inset-0 [clip-path:inset(0_round_var(--hold-radius))]\"\n >\n <motion.span\n aria-hidden=\"true\"\n initial={false}\n animate={\n reduce\n ? { opacity: active ? 1 : 0, transform: \"none\" }\n : {\n opacity: 1,\n transform: active ? activeTransform : idleTransform,\n }\n }\n transition={\n active\n ? { duration: holdDuration / 1000, ease: \"linear\" }\n : { duration: reduce ? 0.15 : 0.24, ease: EASE_OUT }\n }\n onAnimationComplete={handleFillComplete}\n className={cn(\n \"absolute inset-0 bg-sky-400 will-change-[opacity,transform]\",\n fillClassName,\n )}\n >\n {!reduce ? (\n type === \"horizontal\" ? (\n <motion.svg\n viewBox=\"0 0 24 240\"\n preserveAspectRatio=\"none\"\n aria-hidden=\"true\"\n animate={{\n transform: active ? \"translateY(-50%)\" : \"translateY(0%)\",\n }}\n transition={{\n duration: 1.1,\n ease: \"linear\",\n repeat: active ? Number.POSITIVE_INFINITY : 0,\n }}\n className=\"absolute top-0 -right-5 h-[200%] w-6 text-sky-400\"\n >\n <path\n d=\"M0 0h12C2 20 2 40 12 60s10 40 0 60-10 40 0 60 10 40 0 60H0Z\"\n fill=\"currentColor\"\n />\n </motion.svg>\n ) : (\n <motion.svg\n viewBox=\"0 0 240 24\"\n preserveAspectRatio=\"none\"\n aria-hidden=\"true\"\n animate={{\n transform: active ? \"translateX(-50%)\" : \"translateX(0%)\",\n }}\n transition={{\n duration: 1.1,\n ease: \"linear\",\n repeat: active ? Number.POSITIVE_INFINITY : 0,\n }}\n className=\"absolute -top-5 left-0 h-6 w-[200%] text-sky-400\"\n >\n <path\n d=\"M0 12C20 2 40 2 60 12s40 10 60 0 40-10 60 0 40 10 60 0v12H0Z\"\n fill=\"currentColor\"\n />\n </motion.svg>\n )\n ) : null}\n </motion.span>\n </span>\n\n <span\n className={cn(\n \"relative z-10 grid place-items-center font-medium text-base tracking-[-0.01em]\",\n labelClassName,\n )}\n >\n <motion.span\n animate={{ opacity: active ? 0 : 1 }}\n transition={{ duration: reduce ? 0 : 0.12, ease: EASE_OUT }}\n className=\"col-start-1 row-start-1\"\n >\n {children}\n </motion.span>\n <motion.span\n aria-hidden={!holding || completed}\n animate={{ opacity: holding && !completed ? 1 : 0 }}\n transition={{ duration: reduce ? 0 : 0.12, ease: EASE_OUT }}\n className=\"col-start-1 row-start-1\"\n >\n {holdingLabel}\n </motion.span>\n <motion.span\n aria-hidden={!completed}\n animate={{ opacity: completed ? 1 : 0 }}\n transition={{ duration: reduce ? 0 : 0.12, ease: EASE_OUT }}\n className=\"col-start-1 row-start-1\"\n >\n {completeLabel}\n </motion.span>\n </span>\n </motion.button>\n );\n },\n);\n"],"mappings":";;;;;;;;AAwCA,MAAa,mBAAmB,WAC9B,SAAS,iBACP,EACE,UACA,OAAO,YACP,eAAe,gBACf,gBAAgB,QAChB,eAAe,MACf,gBACA,eACA,gBACA,WACA,UACA,GAAG,QAEL,KACA;CACA,MAAM,SAAS,iBAAiB;CAChC,MAAM,eAAe,OAAO,KAAK;CACjC,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAC5C,MAAM,CAAC,WAAW,gBAAgB,SAAS,KAAK;CAEhD,MAAM,kBAAkB;EACtB,IAAI,YAAY,SAAS;EACzB,aAAa,UAAU;EACvB,aAAa,KAAK;EAClB,WAAW,IAAI;CACjB;CAEA,MAAM,mBAAmB;EACvB,WAAW,KAAK;EAChB,aAAa,KAAK;CACpB;CAEA,MAAM,qBAAqB,UAA2C;EACpE,IAAI,MAAM,WAAW,GAAG;EAGxB,UAAU;EACV,eAAe,MAAM,eAAe,MAAM,SAAS;CACrD;CAEA,MAAM,mBAAmB,UAA2C;EAClE,eAAe,MAAM,eAAe,MAAM,SAAS;EACnD,WAAW;CACb;CAEA,MAAM,sBAAsB,UAA2C;EAKrE,IAAI,MAAM,gBAAgB,SAAS,WAAW;CAChD;CAEA,MAAM,qBAAqB,UAA2C;EAKpE,IAAI,CAAC,SAAS;EAEd,MAAM,OAAO,MAAM,cAAc,sBAAsB;EAOvD,IALE,MAAM,UAAU,KAAK,QACrB,MAAM,UAAU,KAAK,SACrB,MAAM,UAAU,KAAK,OACrB,MAAM,UAAU,KAAK,QAEV,WAAW;CAC1B;CAEA,MAAM,iBAAiB,UAA4C;EACjE,KAAK,MAAM,QAAQ,OAAO,MAAM,QAAQ,YAAY,CAAC,MAAM,QAAQ;GACjE,MAAM,eAAe;GACrB,UAAU;EACZ;CACF;CAEA,MAAM,eAAe,UAA4C;EA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V,UAAA,oBAAC,QAAD;MACE,GAAE;MACF,MAAK;KACN,CAAA;IACS,CAAA,IAEZ,oBAAC,OAAO,KAAR;KACE,SAAQ;KACR,qBAAoB;KACpB,eAAY;KACZ,SAAS,EACP,WAAW,SAAS,qBAAqB,iBAC3C;KACA,YAAY;MACV,UAAU;MACV,MAAM;MACN,QAAQ,SAAS,OAAO,oBAAoB;KAC9C;KACA,WAAU;KAEV,UAAA,oBAAC,QAAD;MACE,GAAE;MACF,MAAK;KACN,CAAA;IACS,CAAA,IAEZ;GACO,CAAA;EACT,CAAA,GAEN,qBAAC,QAAD;GACE,WAAW,GACT,kFACA,cACF;GAJF,UAAA;IAME,oBAAC,OAAO,MAAR;KACE,SAAS,EAAE,SAAS,SAAS,IAAI,EAAE;KACnC,YAAY;MAAE,UAAU,SAAS,IAAI;MAAM,MAAM;KAAS;KAC1D,WAAU;KAET;IACU,CAAA;IACb,oBAAC,OAAO,MAAR;KACE,eAAa,CAAC,WAAW;KACzB,SAAS,EAAE,SAAS,WAAW,CAAC,YAAY,IAAI,EAAE;KAClD,YAAY;MAAE,UAAU,SAAS,IAAI;MAAM,MAAM;KAAS;KAC1D,WAAU;KAET,UAAA;IACU,CAAA;IACb,oBAAC,OAAO,MAAR;KACE,eAAa,CAAC;KACd,SAAS,EAAE,SAAS,YAAY,IAAI,EAAE;KACtC,YAAY;MAAE,UAAU,SAAS,IAAI;MAAM,MAAM;KAAS;KAC1D,WAAU;KAET,UAAA;IACU,CAAA;GACT;EACO,CAAA,CAAA;;AAEnB,CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"morphing-tabs.d.ts","names":[],"sources":["../../../src/components/motion/morphing-tabs.tsx"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"morphing-tabs.d.ts","names":[],"sources":["../../../src/components/motion/morphing-tabs.tsx"],"mappings":";;KA8BY;EACV;EACA;EACA,OAAO;EACP,SAAS;EACT;;KAGU;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf,OAAO;EACP;EACA;EACA,iBAAiB;;EAEjB,iBAAiB;;EAEjB,WAAW;EACX;EACA;EACA,aAAa;;iBA2MC,eACd,OACA,OACA,cACA,eACA,eACA,SACA,WACA,WACA,cACC,oCAAiB,IAAA"}
|