@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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"popover-morph.js","names":[],"sources":["../../../src/components/motion/popover-morph.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n cloneElement,\n createContext,\n isValidElement,\n type ReactElement,\n type ReactNode,\n type Ref,\n useCallback,\n useContext,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { createPortal } from \"react-dom\";\n\nimport { cn } from \"@kumix/utils\";\nimport { EASE_OUT, SPRING_PANEL } from \"../../lib/ease\";\nimport { usePopoverPortalPosition } from \"./popover-position\";\n\ntype Side = \"top\" | \"bottom\";\ntype Align = \"start\" | \"end\";\n\ntype MorphContextValue = {\n open: boolean;\n setOpen: (open: boolean) => void;\n toggle: () => void;\n triggerId: string;\n contentId: string;\n triggerRef: React.MutableRefObject<HTMLElement | null>;\n contentRef: React.MutableRefObject<HTMLDivElement | null>;\n};\n\nconst MorphContext = createContext<MorphContextValue | null>(null);\n\nfunction useMorphContext(component: string) {\n const ctx = useContext(MorphContext);\n if (!ctx) throw new Error(`${component} must be used within <MorphPopover>`);\n return ctx;\n}\n\nexport interface MorphPopoverProps {\n children: ReactNode;\n /** Controlled open state. */\n open?: boolean;\n /** Uncontrolled initial open state. */\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n className?: string;\n}\n\n/**\n * A popover whose panel morphs open from the trigger corner: it's laid out at\n * full size but clipped to the corner nearest the trigger, then unclips as one\n * piece. Closes on outside pointer / Escape. Controlled or uncontrolled.\n */\nexport function MorphPopover({\n children,\n open: controlledOpen,\n defaultOpen = false,\n onOpenChange,\n className,\n}: MorphPopoverProps) {\n const baseId = useId();\n const rootRef = useRef<HTMLDivElement>(null);\n const triggerRef = useRef<HTMLElement | null>(null);\n const contentRef = useRef<HTMLDivElement | null>(null);\n const [internalOpen, setInternalOpen] = useState(defaultOpen);\n const controlled = controlledOpen !== undefined;\n const open = controlled ? controlledOpen : internalOpen;\n\n const setOpen = useCallback(\n (next: boolean) => {\n if (!controlled) setInternalOpen(next);\n onOpenChange?.(next);\n },\n [controlled, onOpenChange],\n );\n const toggle = useCallback(() => setOpen(!open), [setOpen, open]);\n\n useEffect(() => {\n if (!open) return;\n const onKey = (e: KeyboardEvent) => e.key === \"Escape\" && setOpen(false);\n const onPointer = (e: PointerEvent) => {\n const target = e.target as Node;\n if (\n rootRef.current &&\n !rootRef.current.contains(target) &&\n !contentRef.current?.contains(target)\n )\n setOpen(false);\n };\n window.addEventListener(\"keydown\", onKey);\n window.addEventListener(\"pointerdown\", onPointer);\n return () => {\n window.removeEventListener(\"keydown\", onKey);\n window.removeEventListener(\"pointerdown\", onPointer);\n };\n }, [open, setOpen]);\n\n const ctx = useMemo<MorphContextValue>(\n () => ({\n open,\n setOpen,\n toggle,\n triggerId: `${baseId}-trigger`,\n contentId: `${baseId}-content`,\n triggerRef,\n contentRef,\n }),\n [open, setOpen, toggle, baseId],\n );\n\n return (\n <MorphContext.Provider value={ctx}>\n <div ref={rootRef} className={cn(\"relative inline-flex\", className)}>\n {children}\n </div>\n </MorphContext.Provider>\n );\n}\n\nexport interface MorphPopoverTriggerProps {\n children: ReactElement;\n}\n\nfunction mergeRefs<T>(...refs: Array<Ref<T> | undefined>) {\n return (node: T | null) => {\n for (const ref of refs) {\n if (typeof ref === \"function\") ref(node);\n else if (ref && typeof ref === \"object\")\n (ref as React.MutableRefObject<T | null>).current = node;\n }\n };\n}\n\n/** Wraps a single element, toggling the popover on click. */\nexport function MorphPopoverTrigger({ children }: MorphPopoverTriggerProps) {\n const ctx = useMorphContext(\"MorphPopoverTrigger\");\n if (!isValidElement(children)) return children;\n\n const child = children as ReactElement<Record<string, unknown>>;\n const childOnClick = child.props.onClick as ((e: unknown) => void) | undefined;\n const childRef = (child.props as { ref?: Ref<HTMLElement> }).ref;\n\n return cloneElement(child, {\n id: ctx.triggerId,\n ref: mergeRefs(childRef, (node: HTMLElement | null) => {\n ctx.triggerRef.current = node;\n }),\n onClick: (e: unknown) => {\n childOnClick?.(e);\n ctx.toggle();\n },\n \"aria-haspopup\": \"dialog\",\n \"aria-expanded\": ctx.open,\n \"aria-controls\": ctx.open ? ctx.contentId : undefined,\n });\n}\n\nconst originFor = (side: Side, align: Align) =>\n `${side === \"bottom\" ? \"top\" : \"bottom\"} ${align === \"end\" ? \"right\" : \"left\"}`;\n\n// A clip that hides everything but the corner nearest the trigger, so the\n// panel appears to grow out of it. inset(top right bottom left).\nfunction clipHidden(side: Side, align: Align, radius: number) {\n const top = side === \"bottom\" ? \"0%\" : \"92%\";\n const bottom = side === \"bottom\" ? \"92%\" : \"0%\";\n const right = align === \"end\" ? \"0%\" : \"92%\";\n const left = align === \"end\" ? \"92%\" : \"0%\";\n return `inset(${top} ${right} ${bottom} ${left} round ${radius}px)`;\n}\nconst clipShown = (radius: number) => `inset(0% 0% 0% 0% round ${radius}px)`;\n\n// Preserve the original spring character on the wrapper, but tween the complex\n// clip-path so it cannot snap when the spring resolves its final distance.\nconst MORPH_CLIP_TRANSITION = { duration: 0.32, ease: EASE_OUT } as const;\n\nexport interface MorphPopoverContentProps {\n children: ReactNode;\n side?: Side;\n align?: Align;\n /** Gap between trigger and panel, in px. Default 8. */\n sideOffset?: number;\n /** Panel corner radius, in px. Default 16. */\n radius?: number;\n className?: string;\n}\n\nexport function MorphPopoverContent({\n children,\n side = \"bottom\",\n align = \"end\",\n sideOffset = 8,\n radius = 16,\n className,\n}: MorphPopoverContentProps) {\n const ctx = useMorphContext(\"MorphPopoverContent\");\n const reduce = useReducedMotion() ?? false;\n const [portalReady, setPortalReady] = useState(false);\n const layout = usePopoverPortalPosition(ctx.triggerRef, ctx.contentRef, portalReady && ctx.open);\n\n useEffect(() => setPortalReady(true), []);\n const left = layout\n ? align === \"end\"\n ? layout.trigger.left + layout.trigger.width - layout.content.width\n : layout.trigger.left\n : 0;\n const top = layout\n ? side === \"bottom\"\n ? layout.trigger.top + layout.trigger.height + sideOffset\n : layout.trigger.top - layout.content.height - sideOffset\n : 0;\n\n // Both directions travel between the exact same hidden/show states. Exit\n // targets \"hidden\" directly instead of introducing separate choreography.\n const wrap = reduce\n ? undefined\n : {\n hidden: { opacity: 0, scale: 0.96, transition: SPRING_PANEL },\n show: { opacity: 1, scale: 1, transition: SPRING_PANEL },\n };\n const clip = reduce\n ? undefined\n : {\n hidden: {\n clipPath: clipHidden(side, align, radius),\n transition: MORPH_CLIP_TRANSITION,\n },\n show: {\n clipPath: clipShown(radius),\n transition: MORPH_CLIP_TRANSITION,\n },\n };\n\n // Keep the server and first client render identical, then mount the portal.\n if (!portalReady) return null;\n\n return createPortal(\n <AnimatePresence>\n {ctx.open ? (\n <motion.div\n data-morph-popover-portal=\"\"\n // Wrapper carries the shadow as a drop-shadow filter, which hugs the\n // clipped shape below (box-shadow would just get clipped away).\n variants={wrap}\n initial={reduce ? { opacity: 0 } : \"hidden\"}\n animate={reduce ? { opacity: 1 } : \"show\"}\n exit={reduce ? { opacity: 0 } : \"hidden\"}\n transition={reduce ? { duration: 0.12 } : undefined}\n style={{\n left,\n top,\n visibility: layout ? \"visible\" : \"hidden\",\n transformOrigin: originFor(side, align),\n }}\n className=\"filter-[drop-shadow(0_10px_18px_rgba(0,0,0,0.14))] fixed z-9999\"\n >\n <motion.div\n ref={ctx.contentRef}\n id={ctx.contentId}\n role=\"dialog\"\n aria-labelledby={ctx.triggerId}\n variants={clip}\n style={{ borderRadius: radius }}\n className={cn(\"overflow-hidden border border-border bg-background\", className)}\n >\n {children}\n </motion.div>\n </motion.div>\n ) : null}\n </AnimatePresence>,\n document.body,\n );\n}\n"],"mappings":";;;;;;;;;AAqCA,MAAM,eAAe,cAAwC,IAAI;AAEjE,SAAS,gBAAgB,WAAmB;CAC1C,MAAM,MAAM,WAAW,YAA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,UAAU;GACV,OAAO,EAAE,cAAc,OAAO;GAC9B,WAAW,GAAG,sDAAsD,SAAS;GAE5E;EACS,CAAA;CACF,CAAA,IACV,KACW,CAAA,GACjB,SAAS,IACX;AACF"}
|
|
1
|
+
{"version":3,"file":"popover-morph.js","names":[],"sources":["../../../src/components/motion/popover-morph.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n cloneElement,\n createContext,\n isValidElement,\n type ReactElement,\n type ReactNode,\n type Ref,\n useCallback,\n useContext,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { createPortal } from \"react-dom\";\n\nimport { cn } from \"@kumix/utils\";\nimport { EASE_OUT, SPRING_PANEL } from \"../../lib/ease\";\nimport { usePopoverPortalPosition } from \"./popover-position\";\n\ntype Side = \"top\" | \"bottom\";\ntype Align = \"start\" | \"end\";\n\ntype MorphContextValue = {\n open: boolean;\n setOpen: (open: boolean) => void;\n toggle: () => void;\n triggerId: string;\n contentId: string;\n /** The element the panel measures against — see `registerTrigger`. */\n triggerRef: React.MutableRefObject<HTMLElement | null>;\n registerTrigger: (node: HTMLElement | null) => void;\n contentRef: React.MutableRefObject<HTMLDivElement | null>;\n};\n\nconst MorphContext = createContext<MorphContextValue | null>(null);\n\nfunction useMorphContext(component: string) {\n const ctx = useContext(MorphContext);\n if (!ctx) throw new Error(`${component} must be used within <MorphPopover>`);\n return ctx;\n}\n\nexport interface MorphPopoverProps {\n children: ReactNode;\n /** Controlled open state. */\n open?: boolean;\n /** Uncontrolled initial open state. */\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n className?: string;\n}\n\n/**\n * A popover whose panel morphs open from the trigger corner: it's laid out at\n * full size but clipped to the corner nearest the trigger, then unclips as one\n * piece. Closes on outside pointer / Escape. Controlled or uncontrolled.\n */\nexport function MorphPopover({\n children,\n open: controlledOpen,\n defaultOpen = false,\n onOpenChange,\n className,\n}: MorphPopoverProps) {\n const baseId = useId();\n const [root, setRoot] = useState<HTMLDivElement | null>(null);\n const [trigger, setTrigger] = useState<HTMLElement | null>(null);\n const contentRef = useRef<HTMLDivElement | null>(null);\n const [internalOpen, setInternalOpen] = useState(defaultOpen);\n const controlled = controlledOpen !== undefined;\n const open = controlled ? controlledOpen : internalOpen;\n\n const setOpen = useCallback(\n (next: boolean) => {\n if (!controlled) setInternalOpen(next);\n onOpenChange?.(next);\n },\n [controlled, onOpenChange],\n );\n const toggle = useCallback(() => setOpen(!open), [setOpen, open]);\n\n // A trigger normally registers itself through MorphPopoverTrigger. It can't\n // when something else already clones the element — a Tooltip wrapping the\n // button, say — and an unregistered trigger leaves the panel with nothing to\n // measure against, so it renders permanently invisible. The root boxes the\n // trigger exactly (the content portals out of it), so it stands in until a\n // real trigger registers, and stands in again if that one unmounts. Both are\n // state, so a trigger arriving while the panel is open re-anchors it.\n const anchorRef = useMemo<React.MutableRefObject<HTMLElement | null>>(\n () => ({ current: trigger ?? root }),\n [root, trigger],\n );\n\n // The panel is a `role=\"dialog\"` and goes inert the moment it closes, so\n // focus cannot be left sitting inside it: a dismissal hands it back to the\n // trigger, the way the ARIA dialog pattern asks. A pointer dismissal takes\n // the focus onward itself when it lands on something focusable — this only\n // catches the case where it would otherwise be stranded. When no trigger has\n // registered, the root anchor stands in only if it can actually hold focus;\n // there is nowhere better than where the keyboard already is, so leave it.\n const close = useCallback(() => {\n setOpen(false);\n const focused = document.activeElement;\n const inPanel = focused instanceof HTMLElement && contentRef.current?.contains(focused);\n if (!inPanel) return;\n const restore = trigger ?? (root && root.tabIndex >= 0 ? root : null);\n restore?.focus();\n }, [root, setOpen, trigger]);\n\n useEffect(() => {\n if (!open) return;\n const onKey = (e: KeyboardEvent) => e.key === \"Escape\" && close();\n const onPointer = (e: PointerEvent) => {\n const target = e.target as Node;\n if (root && !root.contains(target) && !contentRef.current?.contains(target)) close();\n };\n window.addEventListener(\"keydown\", onKey);\n window.addEventListener(\"pointerdown\", onPointer);\n return () => {\n window.removeEventListener(\"keydown\", onKey);\n window.removeEventListener(\"pointerdown\", onPointer);\n };\n }, [open, root, close]);\n\n const ctx = useMemo<MorphContextValue>(\n () => ({\n open,\n setOpen,\n toggle,\n triggerId: `${baseId}-trigger`,\n contentId: `${baseId}-content`,\n triggerRef: anchorRef,\n registerTrigger: setTrigger,\n contentRef,\n }),\n [open, setOpen, toggle, baseId, anchorRef],\n );\n\n return (\n <MorphContext.Provider value={ctx}>\n <div ref={setRoot} className={cn(\"relative inline-flex\", className)}>\n {children}\n </div>\n </MorphContext.Provider>\n );\n}\n\nexport interface MorphPopoverTriggerProps {\n children: ReactElement;\n}\n\nfunction mergeRefs<T>(...refs: Array<Ref<T> | undefined>) {\n return (node: T | null) => {\n for (const ref of refs) {\n if (typeof ref === \"function\") ref(node);\n else if (ref && typeof ref === \"object\")\n (ref as React.MutableRefObject<T | null>).current = node;\n }\n };\n}\n\n/** Wraps a single element, toggling the popover on click. */\nexport function MorphPopoverTrigger({ children }: MorphPopoverTriggerProps) {\n const ctx = useMorphContext(\"MorphPopoverTrigger\");\n if (!isValidElement(children)) return children;\n\n const child = children as ReactElement<Record<string, unknown>>;\n const childOnClick = child.props.onClick as ((e: unknown) => void) | undefined;\n const childRef = (child.props as { ref?: Ref<HTMLElement> }).ref;\n\n return cloneElement(child, {\n id: ctx.triggerId,\n ref: mergeRefs(childRef, ctx.registerTrigger),\n onClick: (e: unknown) => {\n childOnClick?.(e);\n ctx.toggle();\n },\n \"aria-haspopup\": \"dialog\",\n \"aria-expanded\": ctx.open,\n \"aria-controls\": ctx.open ? ctx.contentId : undefined,\n });\n}\n\nconst originFor = (side: Side, align: Align) =>\n `${side === \"bottom\" ? \"top\" : \"bottom\"} ${align === \"end\" ? \"right\" : \"left\"}`;\n\n// A clip that hides everything but the corner nearest the trigger, so the\n// panel appears to grow out of it. inset(top right bottom left).\nfunction clipHidden(side: Side, align: Align, radius: number) {\n const top = side === \"bottom\" ? \"0%\" : \"92%\";\n const bottom = side === \"bottom\" ? \"92%\" : \"0%\";\n const right = align === \"end\" ? \"0%\" : \"92%\";\n const left = align === \"end\" ? \"92%\" : \"0%\";\n return `inset(${top} ${right} ${bottom} ${left} round ${radius}px)`;\n}\nconst clipShown = (radius: number) => `inset(0% 0% 0% 0% round ${radius}px)`;\n\n// Preserve the original spring character on the wrapper, but tween the complex\n// clip-path so it cannot snap when the spring resolves its final distance.\nconst MORPH_CLIP_TRANSITION = { duration: 0.32, ease: EASE_OUT } as const;\n\nexport interface MorphPopoverContentProps {\n children: ReactNode;\n side?: Side;\n align?: Align;\n /** Gap between trigger and panel, in px. Default 8. */\n sideOffset?: number;\n /** Panel corner radius, in px. Default 16. */\n radius?: number;\n className?: string;\n}\n\nexport function MorphPopoverContent({\n children,\n side = \"bottom\",\n align = \"end\",\n sideOffset = 8,\n radius = 16,\n className,\n}: MorphPopoverContentProps) {\n const ctx = useMorphContext(\"MorphPopoverContent\");\n const reduce = useReducedMotion() ?? false;\n const [portalReady, setPortalReady] = useState(false);\n const layout = usePopoverPortalPosition(ctx.triggerRef, ctx.contentRef, portalReady && ctx.open);\n\n useEffect(() => setPortalReady(true), []);\n const left = layout\n ? align === \"end\"\n ? layout.trigger.left + layout.trigger.width - layout.content.width\n : layout.trigger.left\n : 0;\n const top = layout\n ? side === \"bottom\"\n ? layout.trigger.top + layout.trigger.height + sideOffset\n : layout.trigger.top - layout.content.height - sideOffset\n : 0;\n\n // Both directions travel between the exact same hidden/show states. Exit\n // targets \"hidden\" directly instead of introducing separate choreography.\n const wrap = reduce\n ? undefined\n : {\n hidden: { opacity: 0, scale: 0.96, transition: SPRING_PANEL },\n show: { opacity: 1, scale: 1, transition: SPRING_PANEL },\n };\n const clip = reduce\n ? undefined\n : {\n hidden: {\n clipPath: clipHidden(side, align, radius),\n transition: MORPH_CLIP_TRANSITION,\n },\n show: {\n clipPath: clipShown(radius),\n transition: MORPH_CLIP_TRANSITION,\n },\n };\n\n // Keep the server and first client render identical, then mount the portal.\n if (!portalReady) return null;\n\n return createPortal(\n <AnimatePresence>\n {ctx.open ? (\n <motion.div\n data-morph-popover-portal=\"\"\n // Wrapper carries the shadow as a drop-shadow filter, which hugs the\n // clipped shape below (box-shadow would just get clipped away).\n variants={wrap}\n initial={reduce ? { opacity: 0 } : \"hidden\"}\n animate={reduce ? { opacity: 1 } : \"show\"}\n exit={reduce ? { opacity: 0 } : \"hidden\"}\n transition={reduce ? { duration: 0.12 } : undefined}\n style={{\n left,\n top,\n visibility: layout ? \"visible\" : \"hidden\",\n transformOrigin: originFor(side, align),\n }}\n className=\"filter-[drop-shadow(0_10px_18px_rgba(0,0,0,0.14))] fixed z-9999\"\n >\n <motion.div\n ref={ctx.contentRef}\n id={ctx.contentId}\n role=\"dialog\"\n aria-labelledby={ctx.triggerId}\n variants={clip}\n style={{ borderRadius: radius }}\n className={cn(\"overflow-hidden border border-border bg-background\", className)}\n >\n {children}\n </motion.div>\n </motion.div>\n ) : null}\n </AnimatePresence>,\n document.body,\n );\n}\n"],"mappings":";;;;;;;;;AAuCA,MAAM,eAAe,cAAwC,IAAI;AAEjE,SAAS,gBAAgB,WAAmB;CAC1C,MAAM,MAAM,WAAW,YAAY;CACnC,IAAI,CAAC,KAAK,MAAM,IAAI,MAAM,GAAG,UAAU,oCAAoC;CAC3E,OAAO;AACT;;;;;;AAiBA,SAAgB,aAAa,EAC3B,UACA,MAAM,gBACN,cAAc,OACd,cACA,aACoB;CACpB,MAAM,SAAS,MAAM;CACrB,MAAM,CAAC,MAAM,WAAW,SAAgC,IAAI;CAC5D,MAAM,CAAC,SAAS,cAAc,SAA6B,IAAI;CAC/D,MAAM,aAAa,OAA8B,IAAI;CACrD,MAAM,CAAC,cAAc,mBAAmB,SAAS,WAAW;CAC5D,MAAM,aAAa,mBAAmB,KAAA;CACtC,MAAM,OAAO,aAAa,iBAAiB;CAE3C,MAAM,UAAU,aACb,SAAkB;EACjB,IAAI,CAAC,YAAY,gBAAgB,IAAI;EACrC,eAAe,IAAI;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version":3,"file":"popover.d.ts","names":[],"sources":["../../../src/components/motion/popover.tsx"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"popover.d.ts","names":[],"sources":["../../../src/components/motion/popover.tsx"],"mappings":";;KAiCK;KACA;KACA;UA8LY;EACf,UAAU;;EAEV;;EAEA;EACA,gBAAgB;;EAEhB,UAAU;;EAEV,OAAO;;EAEP,QAAQ;;EAER;;EAEA;;EAEA;EACA;;iBAGc,UACd,UACA,MAAM,gBACN,aACA,cACA,SACA,MACA,OACA,YACA,aACA,aACA,aACC,+BAAY,IAAA;UA4IE;;EAEf,UAAU;;iBAGI,iBAAiB,YAAY,sBAAmB,aAAA,kDAAA;UA6E/C;EACf,UAAU;EACV;;iBAGc,iBAAiB,UAAU,aAAa,sCAAmB"}
|
|
@@ -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 { t as usePopoverPortalPosition } from "../../popover-position-BUqYCq8X.js";
|
|
3
6
|
import { cloneElement, createContext, isValidElement, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
4
7
|
import { cn } from "@kumix/utils";
|
|
@@ -18,6 +21,16 @@ const GOO_CLOSE_SPRING = {
|
|
|
18
21
|
};
|
|
19
22
|
const HOVER_CLOSE_DELAY = 120;
|
|
20
23
|
const CIRCLE_KAPPA = .5523;
|
|
24
|
+
function makeHoverHandlers(hover, enter, leave) {
|
|
25
|
+
return {
|
|
26
|
+
onPointerEnter: (event) => {
|
|
27
|
+
if (hover.enter(event)) enter();
|
|
28
|
+
},
|
|
29
|
+
onPointerLeave: (event) => {
|
|
30
|
+
if (hover.leave(event)) leave();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
21
34
|
const lerp = (a, b, t) => a + (b - a) * t;
|
|
22
35
|
function buildGeo(tW, tH, cW, cH, side, align, gap, panelRadius) {
|
|
23
36
|
const py = side === "bottom" ? tH + gap : -(gap + cH);
|
|
@@ -109,6 +122,7 @@ function Popover({ children, open: controlledOpen, defaultOpen = false, onOpenCh
|
|
|
109
122
|
const triggerRef = useRef(null);
|
|
110
123
|
const contentRef = useRef(null);
|
|
111
124
|
const closeTimer = useRef(null);
|
|
125
|
+
const rootHover = useHoverGesture();
|
|
112
126
|
const progress = useMotionValue(defaultOpen ? 1 : 0);
|
|
113
127
|
const [internalOpen, setInternalOpen] = useState(defaultOpen);
|
|
114
128
|
const controlled = controlledOpen !== void 0;
|
|
@@ -141,24 +155,13 @@ function Popover({ children, open: controlledOpen, defaultOpen = false, onOpenCh
|
|
|
141
155
|
progress,
|
|
142
156
|
reduce
|
|
143
157
|
]);
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
window.addEventListener("keydown", onKey);
|
|
152
|
-
if (trigger === "click") window.addEventListener("pointerdown", onPointer);
|
|
153
|
-
return () => {
|
|
154
|
-
window.removeEventListener("keydown", onKey);
|
|
155
|
-
window.removeEventListener("pointerdown", onPointer);
|
|
156
|
-
};
|
|
157
|
-
}, [
|
|
158
|
-
open,
|
|
159
|
-
setOpen,
|
|
160
|
-
trigger
|
|
161
|
-
]);
|
|
158
|
+
const close = useCallback(() => {
|
|
159
|
+
setOpen(false);
|
|
160
|
+
const focused = document.activeElement;
|
|
161
|
+
if (focused instanceof HTMLElement && contentRef.current?.contains(focused)) triggerRef.current?.focus();
|
|
162
|
+
}, [setOpen]);
|
|
163
|
+
const ignoreContent = useCallback((target) => Boolean(contentRef.current?.contains(target)), []);
|
|
164
|
+
useDismiss(open, close, rootRef, { ignore: ignoreContent });
|
|
162
165
|
const ctx = useMemo(() => ({
|
|
163
166
|
open,
|
|
164
167
|
setOpen,
|
|
@@ -194,10 +197,7 @@ function Popover({ children, open: controlledOpen, defaultOpen = false, onOpenCh
|
|
|
194
197
|
contentId,
|
|
195
198
|
progress
|
|
196
199
|
]);
|
|
197
|
-
const hoverHandlers = trigger === "hover" ? {
|
|
198
|
-
onMouseEnter: openHover,
|
|
199
|
-
onMouseLeave: scheduleClose
|
|
200
|
-
} : {};
|
|
200
|
+
const hoverHandlers = trigger === "hover" ? makeHoverHandlers(rootHover, openHover, scheduleClose) : {};
|
|
201
201
|
return /* @__PURE__ */ jsx(PopoverContext.Provider, {
|
|
202
202
|
value: ctx,
|
|
203
203
|
children: /* @__PURE__ */ jsx("div", {
|
|
@@ -216,17 +216,30 @@ function mergeRefs(...refs) {
|
|
|
216
216
|
}
|
|
217
217
|
function PopoverTrigger({ children }) {
|
|
218
218
|
const ctx = usePopoverContext("PopoverTrigger");
|
|
219
|
+
const tap = useTapGesture();
|
|
219
220
|
if (!isValidElement(children)) return children;
|
|
220
221
|
const child = children;
|
|
221
222
|
const childProps = child.props;
|
|
222
223
|
const childRef = childProps.ref;
|
|
223
224
|
const compose = (name, handler) => (event) => {
|
|
224
225
|
childProps[name]?.(event);
|
|
225
|
-
if (!event.defaultPrevented) handler();
|
|
226
|
+
if (!event.defaultPrevented) handler(event);
|
|
227
|
+
};
|
|
228
|
+
const observe = (name, handler) => (event) => {
|
|
229
|
+
childProps[name]?.(event);
|
|
230
|
+
handler(event);
|
|
226
231
|
};
|
|
227
232
|
const handlers = ctx.triggerMode === "hover" ? {
|
|
228
233
|
onFocus: compose("onFocus", ctx.openHover),
|
|
229
|
-
onBlur: compose("onBlur", ctx.scheduleClose)
|
|
234
|
+
onBlur: compose("onBlur", ctx.scheduleClose),
|
|
235
|
+
onPointerDown: observe("onPointerDown", (event) => tap.start(event, ctx.open)),
|
|
236
|
+
onPointerCancel: observe("onPointerCancel", tap.drop),
|
|
237
|
+
onKeyDown: observe("onKeyDown", tap.drop),
|
|
238
|
+
onClick: compose("onClick", () => {
|
|
239
|
+
const gesture = tap.take();
|
|
240
|
+
if (!gesture || gesture.pointerType === "mouse") return;
|
|
241
|
+
ctx.setOpen(!gesture.state);
|
|
242
|
+
})
|
|
230
243
|
} : { onClick: compose("onClick", ctx.toggle) };
|
|
231
244
|
return cloneElement(child, {
|
|
232
245
|
...handlers,
|
|
@@ -250,6 +263,7 @@ function PopoverContent({ children, className }) {
|
|
|
250
263
|
const [portalReady, setPortalReady] = useState(false);
|
|
251
264
|
const { side, align, gap, panelRadius, gooStrength, reduce, gooId, contentId, progress, triggerRef, contentRef, open, triggerMode, openHover, scheduleClose } = ctx;
|
|
252
265
|
const measureRef = contentRef;
|
|
266
|
+
const panelHover = useHoverGesture();
|
|
253
267
|
const blobRef = useRef(null);
|
|
254
268
|
const clipRef = useRef(null);
|
|
255
269
|
const geoRef = useRef(null);
|
|
@@ -279,10 +293,7 @@ function PopoverContent({ children, className }) {
|
|
|
279
293
|
render
|
|
280
294
|
]);
|
|
281
295
|
useMotionValueEvent(progress, "change", (p) => render(geoRef.current, p));
|
|
282
|
-
const hoverHandlers = triggerMode === "hover" ? {
|
|
283
|
-
onMouseEnter: openHover,
|
|
284
|
-
onMouseLeave: scheduleClose
|
|
285
|
-
} : {};
|
|
296
|
+
const hoverHandlers = triggerMode === "hover" ? makeHoverHandlers(panelHover, openHover, scheduleClose) : {};
|
|
286
297
|
if (!portalReady) return null;
|
|
287
298
|
return createPortal(/* @__PURE__ */ jsxs("div", {
|
|
288
299
|
"data-popover-portal": "",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"popover.js","names":[],"sources":["../../../src/components/motion/popover.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n cloneElement,\n createContext,\n isValidElement,\n type ReactElement,\n type ReactNode,\n type Ref,\n useCallback,\n useContext,\n useEffect,\n useId,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport {\n animate,\n type MotionValue,\n useMotionValue,\n useMotionValueEvent,\n useReducedMotion,\n} from \"motion/react\";\nimport { createPortal } from \"react-dom\";\n\nimport { cn } from \"@kumix/utils\";\nimport { usePopoverPortalPosition } from \"./popover-position\";\n\ntype Side = \"top\" | \"bottom\";\ntype Align = \"start\" | \"center\" | \"end\";\ntype TriggerMode = \"click\" | \"hover\";\n\n// This morph needs less bounce than layout motion: too much overshoot makes\n// the liquid neck balloon past the final panel edges.\nconst GOO_OPEN_SPRING = {\n type: \"spring\",\n visualDuration: 0.3,\n bounce: 0.15,\n} as const;\nconst GOO_CLOSE_SPRING = {\n type: \"spring\",\n visualDuration: 0.21,\n bounce: 0.15,\n} as const;\nconst HOVER_CLOSE_DELAY = 120;\nconst CIRCLE_KAPPA = 0.5523;\n\nconst lerp = (a: number, b: number, t: number) => a + (b - a) * t;\n\ninterface Rect {\n x: number;\n y: number;\n w: number;\n h: number;\n r: number;\n}\ninterface Geo {\n layerW: number;\n layerH: number;\n left: number;\n top: number;\n trigger: Rect;\n panel: Rect;\n}\n\n// Trigger rect and panel rect in a shared local coordinate box.\nfunction buildGeo(\n tW: number,\n tH: number,\n cW: number,\n cH: number,\n side: Side,\n align: Align,\n gap: number,\n panelRadius: number,\n): Geo {\n const py = side === \"bottom\" ? tH + gap : -(gap + cH);\n const px = align === \"start\" ? 0 : align === \"end\" ? tW - cW : (tW - cW) / 2;\n\n const left = Math.min(0, px);\n const top = Math.min(0, py);\n const layerW = Math.max(tW, px + cW) - left;\n const layerH = Math.max(tH, py + cH) - top;\n\n const triggerRadius = Math.min(tH / 2, panelRadius);\n\n return {\n layerW,\n layerH,\n left,\n top,\n trigger: { x: -left, y: -top, w: tW, h: tH, r: triggerRadius },\n panel: { x: px - left, y: py - top, w: cW, h: cH, r: panelRadius },\n };\n}\n\nfunction rectAtProgress(geo: Geo, progress: number): Rect {\n const trigger = geo.trigger;\n const panel = geo.panel;\n\n return {\n x: lerp(trigger.x, panel.x, progress),\n y: lerp(trigger.y, panel.y, progress),\n w: lerp(trigger.w, panel.w, progress),\n h: lerp(trigger.h, panel.h, progress),\n r: lerp(trigger.r, panel.r, progress),\n };\n}\n\nfunction insetFor(rect: Rect, layerW: number, layerH: number) {\n const top = rect.y;\n const right = layerW - (rect.x + rect.w);\n const bottom = layerH - (rect.y + rect.h);\n const left = rect.x;\n return `inset(${top}px ${right}px ${bottom}px ${left}px round ${rect.r}px)`;\n}\n\nfunction roundedRectShape(rect: Rect) {\n const radius = Math.max(0, Math.min(rect.r, rect.w / 2, rect.h / 2));\n const control = radius * CIRCLE_KAPPA;\n const x1 = rect.x;\n const y1 = rect.y;\n const x2 = rect.x + rect.w;\n const y2 = rect.y + rect.h;\n const px = (value: number) => `${value.toFixed(3)}px`;\n\n return (\n `shape(from ${px(x1 + radius)} ${px(y1)}, ` +\n `line to ${px(x2 - radius)} ${px(y1)}, ` +\n `curve to ${px(x2)} ${px(y1 + radius)} with ${px(x2 - radius + control)} ${px(y1)} / ${px(x2)} ${px(y1 + radius - control)}, ` +\n `line to ${px(x2)} ${px(y2 - radius)}, ` +\n `curve to ${px(x2 - radius)} ${px(y2)} with ${px(x2)} ${px(y2 - radius + control)} / ${px(x2 - radius + control)} ${px(y2)}, ` +\n `line to ${px(x1 + radius)} ${px(y2)}, ` +\n `curve to ${px(x1)} ${px(y2 - radius)} with ${px(x1 + radius - control)} ${px(y2)} / ${px(x1)} ${px(y2 - radius + control)}, ` +\n `line to ${px(x1)} ${px(y1 + radius)}, ` +\n `curve to ${px(x1 + radius)} ${px(y1)} with ${px(x1)} ${px(y1 + radius - control)} / ${px(x1 + radius - control)} ${px(y1)}, ` +\n \"close)\"\n );\n}\n\nfunction clipForProgress(geo: Geo, progress: number, supportsShape: boolean) {\n const rect = rectAtProgress(geo, progress);\n return supportsShape ? roundedRectShape(rect) : insetFor(rect, geo.layerW, geo.layerH);\n}\n\nfunction roundedRectPath(rect: Rect) {\n const radius = Math.max(0, Math.min(rect.r, rect.w / 2, rect.h / 2));\n const n = (value: number) => value.toFixed(3);\n const x1 = rect.x;\n const y1 = rect.y;\n const x2 = rect.x + rect.w;\n const y2 = rect.y + rect.h;\n const arc = `A${n(radius)} ${n(radius)} 0 0 1`;\n\n // A zero radius makes every arc degenerate to a line, so this also draws\n // plain rectangles.\n return (\n `M${n(x1 + radius)} ${n(y1)}` +\n `H${n(x2 - radius)}${arc} ${n(x2)} ${n(y1 + radius)}` +\n `V${n(y2 - radius)}${arc} ${n(x2 - radius)} ${n(y2)}` +\n `H${n(x1 + radius)}${arc} ${n(x1)} ${n(y2 - radius)}` +\n `V${n(y1 + radius)}${arc} ${n(x1 + radius)} ${n(y1)}Z`\n );\n}\n\n// The goo layer is portalled above the page, so its copy of the trigger pill\n// would cover the real trigger's label and focus ring. Punching the trigger\n// back out keeps the real one visible and clips the blur to the layer box.\n// This is a clip path rather than a CSS mask on purpose: WebKit silently\n// ignores `mask: url(#id)` pointing at an SVG <mask> element, which left the\n// label hidden behind the goo in Safari.\nfunction triggerCutout(geo: Geo) {\n const layer = { x: 0, y: 0, w: geo.layerW, h: geo.layerH, r: 0 };\n return `path(evenodd, \"${roundedRectPath(layer)} ${roundedRectPath(geo.trigger)}\")`;\n}\n\ninterface PopoverContextValue {\n open: boolean;\n setOpen: (open: boolean) => void;\n toggle: () => void;\n openHover: () => void;\n scheduleClose: () => void;\n triggerMode: TriggerMode;\n side: Side;\n align: Align;\n gap: number;\n panelRadius: number;\n gooStrength: number;\n reduce: boolean;\n gooId: string;\n contentId: string;\n progress: MotionValue<number>;\n triggerRef: React.MutableRefObject<HTMLElement | null>;\n contentRef: React.MutableRefObject<HTMLDivElement | null>;\n}\n\nconst PopoverContext = createContext<PopoverContextValue | null>(null);\n\nfunction usePopoverContext(component: string) {\n const ctx = useContext(PopoverContext);\n if (!ctx) throw new Error(`${component} must be used within <Popover>`);\n return ctx;\n}\n\nexport interface PopoverProps {\n children: ReactNode;\n /** Controlled open state. */\n open?: boolean;\n /** Uncontrolled initial open state. */\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n /** How the popover is summoned. Default \"click\". */\n trigger?: TriggerMode;\n /** Which side of the trigger the panel oozes out of. Default \"bottom\". */\n side?: Side;\n /** Alignment along the trigger's edge. Default \"center\". */\n align?: Align;\n /** Gap between trigger and panel, in px — the length of the gooey neck. Default 14. */\n sideOffset?: number;\n /** Corner radius of the open panel, in px. Default 16. */\n panelRadius?: number;\n /** Blur radius feeding the goo filter — higher melts more. Default 8. */\n gooStrength?: number;\n className?: string;\n}\n\nexport function Popover({\n children,\n open: controlledOpen,\n defaultOpen = false,\n onOpenChange,\n trigger = \"click\",\n side = \"bottom\",\n align = \"center\",\n sideOffset = 14,\n panelRadius = 16,\n gooStrength = 8,\n className,\n}: PopoverProps) {\n const reduce = useReducedMotion() ?? false;\n const gooId = useId().replace(/:/g, \"\");\n const contentId = useId();\n const rootRef = useRef<HTMLDivElement>(null);\n const triggerRef = useRef<HTMLElement | null>(null);\n const contentRef = useRef<HTMLDivElement | null>(null);\n const closeTimer = useRef<ReturnType<typeof setTimeout> | null>(null);\n const progress = useMotionValue(defaultOpen ? 1 : 0);\n\n const [internalOpen, setInternalOpen] = useState(defaultOpen);\n const controlled = controlledOpen !== undefined;\n const open = controlled ? controlledOpen : internalOpen;\n\n const setOpen = useCallback(\n (next: boolean) => {\n if (!controlled) setInternalOpen(next);\n onOpenChange?.(next);\n },\n [controlled, onOpenChange],\n );\n\n const cancelClose = useCallback(() => {\n if (closeTimer.current) {\n clearTimeout(closeTimer.current);\n closeTimer.current = null;\n }\n }, []);\n\n const openHover = useCallback(() => {\n cancelClose();\n setOpen(true);\n }, [cancelClose, setOpen]);\n\n const scheduleClose = useCallback(() => {\n cancelClose();\n closeTimer.current = setTimeout(() => setOpen(false), HOVER_CLOSE_DELAY);\n }, [cancelClose, setOpen]);\n\n const toggle = useCallback(() => setOpen(!open), [setOpen, open]);\n\n useEffect(() => () => cancelClose(), [cancelClose]);\n\n useEffect(() => {\n const animation = animate(\n progress,\n open ? 1 : 0,\n reduce ? { duration: 0 } : open ? GOO_OPEN_SPRING : GOO_CLOSE_SPRING,\n );\n return () => animation.stop();\n }, [open, progress, reduce]);\n\n useEffect(() => {\n if (!open) return;\n const onKey = (e: KeyboardEvent) => e.key === \"Escape\" && setOpen(false);\n // The panel is portalled, so both trees participate in outside detection.\n const onPointer = (e: PointerEvent) => {\n const target = e.target as Node;\n if (\n rootRef.current &&\n !rootRef.current.contains(target) &&\n !contentRef.current?.contains(target)\n )\n setOpen(false);\n };\n window.addEventListener(\"keydown\", onKey);\n if (trigger === \"click\") window.addEventListener(\"pointerdown\", onPointer);\n return () => {\n window.removeEventListener(\"keydown\", onKey);\n window.removeEventListener(\"pointerdown\", onPointer);\n };\n }, [open, setOpen, trigger]);\n\n const ctx = useMemo<PopoverContextValue>(\n () => ({\n open,\n setOpen,\n toggle,\n openHover,\n scheduleClose,\n triggerMode: trigger,\n side,\n align,\n gap: sideOffset,\n panelRadius,\n gooStrength,\n reduce,\n gooId,\n contentId,\n progress,\n triggerRef,\n contentRef,\n }),\n [\n open,\n setOpen,\n toggle,\n openHover,\n scheduleClose,\n trigger,\n side,\n align,\n sideOffset,\n panelRadius,\n gooStrength,\n reduce,\n gooId,\n contentId,\n progress,\n ],\n );\n\n const hoverHandlers =\n trigger === \"hover\" ? { onMouseEnter: openHover, onMouseLeave: scheduleClose } : {};\n\n return (\n <PopoverContext.Provider value={ctx}>\n <div\n ref={rootRef}\n className={cn(\"relative isolate inline-flex\", className)}\n {...hoverHandlers}\n >\n {children}\n </div>\n </PopoverContext.Provider>\n );\n}\n\nfunction mergeRefs<T>(...refs: Array<Ref<T> | undefined>) {\n return (node: T | null) => {\n for (const ref of refs) {\n if (typeof ref === \"function\") ref(node);\n else if (ref && typeof ref === \"object\")\n (ref as React.MutableRefObject<T | null>).current = node;\n }\n };\n}\n\nexport interface PopoverTriggerProps {\n /** A single focusable element (e.g. a Button) that opens the popover. */\n children: ReactElement;\n}\n\nexport function PopoverTrigger({ children }: PopoverTriggerProps) {\n const ctx = usePopoverContext(\"PopoverTrigger\");\n\n if (!isValidElement(children)) return children;\n\n const child = children as ReactElement<Record<string, unknown>>;\n const childProps = child.props;\n const childRef = (childProps as { ref?: Ref<HTMLElement> }).ref;\n\n const compose =\n (name: string, handler: () => void) => (event: { defaultPrevented?: boolean }) => {\n (childProps[name] as ((e: unknown) => void) | undefined)?.(event);\n if (!event.defaultPrevented) handler();\n };\n\n const handlers: Record<string, unknown> =\n ctx.triggerMode === \"hover\"\n ? {\n onFocus: compose(\"onFocus\", ctx.openHover),\n onBlur: compose(\"onBlur\", ctx.scheduleClose),\n }\n : { onClick: compose(\"onClick\", ctx.toggle) };\n\n return cloneElement(child, {\n ...handlers,\n ref: mergeRefs(childRef, (node: HTMLElement | null) => {\n ctx.triggerRef.current = node;\n }),\n // Above the goo layer (z-[-1]) so the neck reads behind it.\n className: cn(\"relative z-0\", childProps.className as string | undefined),\n \"aria-haspopup\": \"dialog\",\n \"aria-expanded\": ctx.open,\n \"aria-controls\": ctx.open ? ctx.contentId : undefined,\n \"data-state\": ctx.open ? \"open\" : \"closed\",\n });\n}\n\nconst ALIGN_ORIGIN: Record<Align, string> = {\n start: \"left\",\n center: \"center\",\n end: \"right\",\n};\n\nexport interface PopoverContentProps {\n children: ReactNode;\n className?: string;\n}\n\nexport function PopoverContent({ children, className }: PopoverContentProps) {\n const ctx = usePopoverContext(\"PopoverContent\");\n const [portalReady, setPortalReady] = useState(false);\n const {\n side,\n align,\n gap,\n panelRadius,\n gooStrength,\n reduce,\n gooId,\n contentId,\n progress,\n triggerRef,\n contentRef,\n open,\n triggerMode,\n openHover,\n scheduleClose,\n } = ctx;\n\n const measureRef = contentRef;\n const blobRef = useRef<HTMLDivElement>(null);\n const clipRef = useRef<HTMLDivElement>(null);\n const geoRef = useRef<Geo | null>(null);\n const supportsShapeRef = useRef(false);\n const layout = usePopoverPortalPosition(triggerRef, measureRef, portalReady);\n\n useEffect(() => setPortalReady(true), []);\n\n const geo = useMemo(\n () =>\n buildGeo(\n layout?.trigger.width ?? 0,\n layout?.trigger.height ?? 0,\n layout?.content.width ?? 0,\n layout?.content.height ?? 0,\n side,\n align,\n gap,\n panelRadius,\n ),\n [layout, side, align, gap, panelRadius],\n );\n\n // Morph the same clip on the goo body and the content, so the whole popover\n // oozes as one and the text reveals with it.\n const render = useCallback((g: Geo | null, p: number) => {\n if (!g || g.layerW === 0) return;\n const clip = clipForProgress(g, p, supportsShapeRef.current);\n if (blobRef.current) blobRef.current.style.clipPath = clip;\n if (clipRef.current) clipRef.current.style.clipPath = clip;\n }, []);\n\n useLayoutEffect(() => {\n supportsShapeRef.current =\n typeof CSS !== \"undefined\" &&\n typeof CSS.supports === \"function\" &&\n CSS.supports(\"clip-path\", \"shape(from 0px 0px, line to 1px 1px, close)\");\n geoRef.current = geo;\n render(geo, progress.get());\n }, [geo, progress, render]);\n\n useMotionValueEvent(progress, \"change\", (p) => render(geoRef.current, p));\n\n const hoverHandlers =\n triggerMode === \"hover\" ? { onMouseEnter: openHover, onMouseLeave: scheduleClose } : {};\n\n // Match the server and first client render, then attach the portal after\n // hydration. This preserves SSR without regenerating the page on the client.\n if (!portalReady) return null;\n\n return createPortal(\n <div\n data-popover-portal=\"\"\n className=\"pointer-events-none fixed top-0 left-0 isolate z-9999 size-0\"\n style={{\n visibility: layout ? \"visible\" : \"hidden\",\n transform: `translate3d(${layout?.trigger.left ?? 0}px, ${layout?.trigger.top ?? 0}px, 0)`,\n }}\n >\n {/* Goo filter: blur, sharpen the alpha back into solid shapes, then lay\n the crisp original on top so blobs merge with liquid edges. */}\n <svg aria-hidden width=\"0\" height=\"0\" className=\"absolute\">\n <title>Popover visual effects</title>\n <defs>\n <filter id={gooId} x=\"-50%\" y=\"-50%\" width=\"200%\" height=\"200%\">\n <feGaussianBlur in=\"SourceGraphic\" stdDeviation={gooStrength} result=\"blur\" />\n <feColorMatrix\n in=\"blur\"\n mode=\"matrix\"\n values=\"1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 22 -10\"\n result=\"goo\"\n />\n <feComposite in=\"SourceGraphic\" in2=\"goo\" operator=\"atop\" />\n </filter>\n </defs>\n </svg>\n\n {/* Goo body: static trigger pill + morphing blob. */}\n <div\n aria-hidden\n className=\"pointer-events-none absolute z-[-1]\"\n style={{\n left: geo.left,\n top: geo.top,\n width: geo.layerW,\n height: geo.layerH,\n filter: reduce ? undefined : `url(#${gooId})`,\n clipPath: triggerCutout(geo),\n }}\n >\n <div\n className=\"absolute bg-popover\"\n style={{\n left: geo.trigger.x,\n top: geo.trigger.y,\n width: geo.trigger.w,\n height: geo.trigger.h,\n borderRadius: geo.trigger.r,\n }}\n />\n <div\n ref={blobRef}\n className=\"absolute inset-0 bg-popover\"\n style={{\n clipPath: clipForProgress(geo, progress.get(), false),\n }}\n />\n </div>\n\n {/* Content is clipped by the same morph. The portal wrapper stays\n pointer-transparent; only the fully open panel accepts interaction. */}\n <div\n className=\"pointer-events-none absolute z-10\"\n style={{\n left: geo.left,\n top: geo.top,\n width: geo.layerW,\n height: geo.layerH,\n }}\n >\n <div\n ref={clipRef}\n inert={!open}\n className=\"absolute inset-0\"\n style={{\n clipPath: clipForProgress(geo, progress.get(), false),\n pointerEvents: open ? \"auto\" : \"none\",\n }}\n >\n <div\n ref={measureRef}\n id={contentId}\n role=\"dialog\"\n {...hoverHandlers}\n style={{\n position: \"absolute\",\n left: geo.panel.x,\n top: geo.panel.y,\n transformOrigin: `${ALIGN_ORIGIN[align]} ${side === \"bottom\" ? \"top\" : \"bottom\"}`,\n }}\n className={cn(\n \"w-max max-w-[min(92vw,20rem)] p-4 text-popover-foreground outline-none\",\n className,\n )}\n >\n {children}\n </div>\n </div>\n </div>\n </div>,\n document.body,\n );\n}\n"],"mappings":";;;;;;;;AAoCA,MAAM,kBAAkB;CACtB,MAAM;CACN,gBAAgB;CAChB,QAAQ;AACV;AACA,MAAM,mBAAmB;CACvB,MAAM;CACN,gBAAgB;CAChB,QAAQ;AACV;AACA,MAAM,oBAAoB;AAC1B,MAAM,eAAe;AAErB,MAAM,QAAQ,GAAW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J,MAAK;MACL,GAAI;MACJ,OAAO;OACL,UAAU;OACV,MAAM,IAAI,MAAM;OAChB,KAAK,IAAI,MAAM;OACf,iBAAiB,GAAG,aAAa,OAAO,GAAG,SAAS,WAAW,QAAQ;MACzE;MACA,WAAW,GACT,0EACA,SACF;MAEC;KACE,CAAA;IACF,CAAA;GACF,CAAA;EACF;CACL,CAAA,GAAA,SAAS,IACX;AACF"}
|
|
1
|
+
{"version":3,"file":"popover.js","names":[],"sources":["../../../src/components/motion/popover.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n cloneElement,\n createContext,\n isValidElement,\n type ReactElement,\n type ReactNode,\n type Ref,\n useCallback,\n useContext,\n useEffect,\n useId,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport {\n animate,\n type MotionValue,\n useMotionValue,\n useMotionValueEvent,\n useReducedMotion,\n} from \"motion/react\";\nimport { createPortal } from \"react-dom\";\n\nimport { cn } from \"@kumix/utils\";\nimport { useDismiss } from \"../../hooks/use-dismiss\";\nimport { type HoverGesture, useHoverGesture } from \"../../hooks/use-hover-gesture\";\nimport { useTapGesture } from \"../../hooks/use-tap-gesture\";\nimport { usePopoverPortalPosition } from \"./popover-position\";\n\ntype Side = \"top\" | \"bottom\";\ntype Align = \"start\" | \"center\" | \"end\";\ntype TriggerMode = \"click\" | \"hover\";\n\n// This morph needs less bounce than layout motion: too much overshoot makes\n// the liquid neck balloon past the final panel edges.\nconst GOO_OPEN_SPRING = {\n type: \"spring\",\n visualDuration: 0.3,\n bounce: 0.15,\n} as const;\nconst GOO_CLOSE_SPRING = {\n type: \"spring\",\n visualDuration: 0.21,\n bounce: 0.15,\n} as const;\nconst HOVER_CLOSE_DELAY = 120;\nconst CIRCLE_KAPPA = 0.5523;\n\n// `onPointerEnter`/`onPointerLeave` rather than the mouse pair: a tap fires\n// compatibility mouseenter/mouseleave that carry no pointerType at all, and\n// they are what made the panel flicker open and shut under a finger. The\n// gesture pairs the two, so the panel a pen tap opened is not closed again by\n// the boundary event that ends the same tap.\nfunction makeHoverHandlers(hover: HoverGesture, enter: () => void, leave: () => void) {\n return {\n onPointerEnter: (event: React.PointerEvent) => {\n if (hover.enter(event)) enter();\n },\n onPointerLeave: (event: React.PointerEvent) => {\n if (hover.leave(event)) leave();\n },\n };\n}\n\nconst lerp = (a: number, b: number, t: number) => a + (b - a) * t;\n\ninterface Rect {\n x: number;\n y: number;\n w: number;\n h: number;\n r: number;\n}\ninterface Geo {\n layerW: number;\n layerH: number;\n left: number;\n top: number;\n trigger: Rect;\n panel: Rect;\n}\n\n// Trigger rect and panel rect in a shared local coordinate box.\nfunction buildGeo(\n tW: number,\n tH: number,\n cW: number,\n cH: number,\n side: Side,\n align: Align,\n gap: number,\n panelRadius: number,\n): Geo {\n const py = side === \"bottom\" ? tH + gap : -(gap + cH);\n const px = align === \"start\" ? 0 : align === \"end\" ? tW - cW : (tW - cW) / 2;\n\n const left = Math.min(0, px);\n const top = Math.min(0, py);\n const layerW = Math.max(tW, px + cW) - left;\n const layerH = Math.max(tH, py + cH) - top;\n\n const triggerRadius = Math.min(tH / 2, panelRadius);\n\n return {\n layerW,\n layerH,\n left,\n top,\n trigger: { x: -left, y: -top, w: tW, h: tH, r: triggerRadius },\n panel: { x: px - left, y: py - top, w: cW, h: cH, r: panelRadius },\n };\n}\n\nfunction rectAtProgress(geo: Geo, progress: number): Rect {\n const trigger = geo.trigger;\n const panel = geo.panel;\n\n return {\n x: lerp(trigger.x, panel.x, progress),\n y: lerp(trigger.y, panel.y, progress),\n w: lerp(trigger.w, panel.w, progress),\n h: lerp(trigger.h, panel.h, progress),\n r: lerp(trigger.r, panel.r, progress),\n };\n}\n\nfunction insetFor(rect: Rect, layerW: number, layerH: number) {\n const top = rect.y;\n const right = layerW - (rect.x + rect.w);\n const bottom = layerH - (rect.y + rect.h);\n const left = rect.x;\n return `inset(${top}px ${right}px ${bottom}px ${left}px round ${rect.r}px)`;\n}\n\nfunction roundedRectShape(rect: Rect) {\n const radius = Math.max(0, Math.min(rect.r, rect.w / 2, rect.h / 2));\n const control = radius * CIRCLE_KAPPA;\n const x1 = rect.x;\n const y1 = rect.y;\n const x2 = rect.x + rect.w;\n const y2 = rect.y + rect.h;\n const px = (value: number) => `${value.toFixed(3)}px`;\n\n return (\n `shape(from ${px(x1 + radius)} ${px(y1)}, ` +\n `line to ${px(x2 - radius)} ${px(y1)}, ` +\n `curve to ${px(x2)} ${px(y1 + radius)} with ${px(x2 - radius + control)} ${px(y1)} / ${px(x2)} ${px(y1 + radius - control)}, ` +\n `line to ${px(x2)} ${px(y2 - radius)}, ` +\n `curve to ${px(x2 - radius)} ${px(y2)} with ${px(x2)} ${px(y2 - radius + control)} / ${px(x2 - radius + control)} ${px(y2)}, ` +\n `line to ${px(x1 + radius)} ${px(y2)}, ` +\n `curve to ${px(x1)} ${px(y2 - radius)} with ${px(x1 + radius - control)} ${px(y2)} / ${px(x1)} ${px(y2 - radius + control)}, ` +\n `line to ${px(x1)} ${px(y1 + radius)}, ` +\n `curve to ${px(x1 + radius)} ${px(y1)} with ${px(x1)} ${px(y1 + radius - control)} / ${px(x1 + radius - control)} ${px(y1)}, ` +\n \"close)\"\n );\n}\n\nfunction clipForProgress(geo: Geo, progress: number, supportsShape: boolean) {\n const rect = rectAtProgress(geo, progress);\n return supportsShape ? roundedRectShape(rect) : insetFor(rect, geo.layerW, geo.layerH);\n}\n\nfunction roundedRectPath(rect: Rect) {\n const radius = Math.max(0, Math.min(rect.r, rect.w / 2, rect.h / 2));\n const n = (value: number) => value.toFixed(3);\n const x1 = rect.x;\n const y1 = rect.y;\n const x2 = rect.x + rect.w;\n const y2 = rect.y + rect.h;\n const arc = `A${n(radius)} ${n(radius)} 0 0 1`;\n\n // A zero radius makes every arc degenerate to a line, so this also draws\n // plain rectangles.\n return (\n `M${n(x1 + radius)} ${n(y1)}` +\n `H${n(x2 - radius)}${arc} ${n(x2)} ${n(y1 + radius)}` +\n `V${n(y2 - radius)}${arc} ${n(x2 - radius)} ${n(y2)}` +\n `H${n(x1 + radius)}${arc} ${n(x1)} ${n(y2 - radius)}` +\n `V${n(y1 + radius)}${arc} ${n(x1 + radius)} ${n(y1)}Z`\n );\n}\n\n// The goo layer is portalled above the page, so its copy of the trigger pill\n// would cover the real trigger's label and focus ring. Punching the trigger\n// back out keeps the real one visible and clips the blur to the layer box.\n// This is a clip path rather than a CSS mask on purpose: WebKit silently\n// ignores `mask: url(#id)` pointing at an SVG <mask> element, which left the\n// label hidden behind the goo in Safari.\nfunction triggerCutout(geo: Geo) {\n const layer = { x: 0, y: 0, w: geo.layerW, h: geo.layerH, r: 0 };\n return `path(evenodd, \"${roundedRectPath(layer)} ${roundedRectPath(geo.trigger)}\")`;\n}\n\ninterface PopoverContextValue {\n open: boolean;\n setOpen: (open: boolean) => void;\n toggle: () => void;\n openHover: () => void;\n scheduleClose: () => void;\n triggerMode: TriggerMode;\n side: Side;\n align: Align;\n gap: number;\n panelRadius: number;\n gooStrength: number;\n reduce: boolean;\n gooId: string;\n contentId: string;\n progress: MotionValue<number>;\n triggerRef: React.MutableRefObject<HTMLElement | null>;\n contentRef: React.MutableRefObject<HTMLDivElement | null>;\n}\n\nconst PopoverContext = createContext<PopoverContextValue | null>(null);\n\nfunction usePopoverContext(component: string) {\n const ctx = useContext(PopoverContext);\n if (!ctx) throw new Error(`${component} must be used within <Popover>`);\n return ctx;\n}\n\nexport interface PopoverProps {\n children: ReactNode;\n /** Controlled open state. */\n open?: boolean;\n /** Uncontrolled initial open state. */\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n /** How the popover is summoned. Default \"click\". */\n trigger?: TriggerMode;\n /** Which side of the trigger the panel oozes out of. Default \"bottom\". */\n side?: Side;\n /** Alignment along the trigger's edge. Default \"center\". */\n align?: Align;\n /** Gap between trigger and panel, in px — the length of the gooey neck. Default 14. */\n sideOffset?: number;\n /** Corner radius of the open panel, in px. Default 16. */\n panelRadius?: number;\n /** Blur radius feeding the goo filter — higher melts more. Default 8. */\n gooStrength?: number;\n className?: string;\n}\n\nexport function Popover({\n children,\n open: controlledOpen,\n defaultOpen = false,\n onOpenChange,\n trigger = \"click\",\n side = \"bottom\",\n align = \"center\",\n sideOffset = 14,\n panelRadius = 16,\n gooStrength = 8,\n className,\n}: PopoverProps) {\n const reduce = useReducedMotion() ?? false;\n const gooId = useId().replace(/:/g, \"\");\n const contentId = useId();\n const rootRef = useRef<HTMLDivElement>(null);\n const triggerRef = useRef<HTMLElement | null>(null);\n const contentRef = useRef<HTMLDivElement | null>(null);\n const closeTimer = useRef<ReturnType<typeof setTimeout> | null>(null);\n const rootHover = useHoverGesture();\n const progress = useMotionValue(defaultOpen ? 1 : 0);\n\n const [internalOpen, setInternalOpen] = useState(defaultOpen);\n const controlled = controlledOpen !== undefined;\n const open = controlled ? controlledOpen : internalOpen;\n\n const setOpen = useCallback(\n (next: boolean) => {\n if (!controlled) setInternalOpen(next);\n onOpenChange?.(next);\n },\n [controlled, onOpenChange],\n );\n\n const cancelClose = useCallback(() => {\n if (closeTimer.current) {\n clearTimeout(closeTimer.current);\n closeTimer.current = null;\n }\n }, []);\n\n const openHover = useCallback(() => {\n cancelClose();\n setOpen(true);\n }, [cancelClose, setOpen]);\n\n const scheduleClose = useCallback(() => {\n cancelClose();\n closeTimer.current = setTimeout(() => setOpen(false), HOVER_CLOSE_DELAY);\n }, [cancelClose, setOpen]);\n\n const toggle = useCallback(() => setOpen(!open), [setOpen, open]);\n\n useEffect(() => () => cancelClose(), [cancelClose]);\n\n useEffect(() => {\n const animation = animate(\n progress,\n open ? 1 : 0,\n reduce ? { duration: 0 } : open ? GOO_OPEN_SPRING : GOO_CLOSE_SPRING,\n );\n return () => animation.stop();\n }, [open, progress, reduce]);\n\n // The panel is a `role=\"dialog\"` and goes inert the moment it closes, so\n // focus cannot be left sitting inside it: Escape hands it back to the\n // trigger, the way the ARIA dialog pattern asks. A pointer dismissal takes\n // the focus onward itself when it lands on something focusable — this only\n // catches the case where it would otherwise be stranded.\n const close = useCallback(() => {\n setOpen(false);\n const focused = document.activeElement;\n const inPanel = focused instanceof HTMLElement && contentRef.current?.contains(focused);\n if (inPanel) triggerRef.current?.focus();\n }, [setOpen]);\n // The panel is portalled, so both trees participate in outside detection.\n const ignoreContent = useCallback(\n (target: Element) => Boolean(contentRef.current?.contains(target)),\n [],\n );\n // A hover trigger opens on tap as well now, so it needs the same outside\n // dismissal the click trigger always had. The gesture passes through to\n // whatever it landed on, which is the light-dismiss bargain the platform's\n // own popovers strike.\n useDismiss(open, close, rootRef, { ignore: ignoreContent });\n\n const ctx = useMemo<PopoverContextValue>(\n () => ({\n open,\n setOpen,\n toggle,\n openHover,\n scheduleClose,\n triggerMode: trigger,\n side,\n align,\n gap: sideOffset,\n panelRadius,\n gooStrength,\n reduce,\n gooId,\n contentId,\n progress,\n triggerRef,\n contentRef,\n }),\n [\n open,\n setOpen,\n toggle,\n openHover,\n scheduleClose,\n trigger,\n side,\n align,\n sideOffset,\n panelRadius,\n gooStrength,\n reduce,\n gooId,\n contentId,\n progress,\n ],\n );\n\n const hoverHandlers =\n trigger === \"hover\" ? makeHoverHandlers(rootHover, openHover, scheduleClose) : {};\n\n return (\n <PopoverContext.Provider value={ctx}>\n <div\n ref={rootRef}\n className={cn(\"relative isolate inline-flex\", className)}\n {...hoverHandlers}\n >\n {children}\n </div>\n </PopoverContext.Provider>\n );\n}\n\nfunction mergeRefs<T>(...refs: Array<Ref<T> | undefined>) {\n return (node: T | null) => {\n for (const ref of refs) {\n if (typeof ref === \"function\") ref(node);\n else if (ref && typeof ref === \"object\")\n (ref as React.MutableRefObject<T | null>).current = node;\n }\n };\n}\n\nexport interface PopoverTriggerProps {\n /** A single focusable element (e.g. a Button) that opens the popover. */\n children: ReactElement;\n}\n\nexport function PopoverTrigger({ children }: PopoverTriggerProps) {\n const ctx = usePopoverContext(\"PopoverTrigger\");\n // What the last gesture on the trigger was, and whether the panel was\n // already open when it started. A click reports neither.\n const tap = useTapGesture<boolean>();\n\n if (!isValidElement(children)) return children;\n\n const child = children as ReactElement<Record<string, unknown>>;\n const childProps = child.props;\n const childRef = (childProps as { ref?: Ref<HTMLElement> }).ref;\n\n const compose =\n <E extends { defaultPrevented?: boolean }>(name: string, handler: (event: E) => void) =>\n (event: E) => {\n (childProps[name] as ((e: unknown) => void) | undefined)?.(event);\n if (!event.defaultPrevented) handler(event);\n };\n\n // Observation, not action. `compose` steps aside for a child that handled\n // the event itself, which is right for anything that *does* something — but\n // a child preventing the pointerdown default (to hold focus, say) has not\n // said the gesture didn't happen. Skipping the record there left the panel\n // reading whatever the gesture before it had put in.\n const observe =\n <E,>(name: string, handler: (event: E) => void) =>\n (event: E) => {\n (childProps[name] as ((e: unknown) => void) | undefined)?.(event);\n handler(event);\n };\n\n // The hover trigger keeps its hover path and *adds* a tap one, rather than\n // swapping mode on a device that reports a touchscreen: a touchscreen laptop\n // has both inputs and the mouse must keep working. A hovering pointer has\n // already opened the panel on its way in, and a keyboard press arrives with\n // no pointerdown behind it, so only a tap toggles here. Which panel state\n // the tap acts on is read from the gesture's start, because a browser that\n // focuses the trigger on contact would otherwise open it mid-gesture and let\n // the click close it again.\n const handlers: Record<string, unknown> =\n ctx.triggerMode === \"hover\"\n ? {\n onFocus: compose(\"onFocus\", ctx.openHover),\n onBlur: compose(\"onBlur\", ctx.scheduleClose),\n onPointerDown: observe<React.PointerEvent>(\"onPointerDown\", (event) =>\n tap.start(event, ctx.open),\n ),\n onPointerCancel: observe(\"onPointerCancel\", tap.drop),\n onKeyDown: observe(\"onKeyDown\", tap.drop),\n onClick: compose(\"onClick\", () => {\n const gesture = tap.take();\n if (!gesture || gesture.pointerType === \"mouse\") return;\n ctx.setOpen(!gesture.state);\n }),\n }\n : { onClick: compose(\"onClick\", ctx.toggle) };\n\n return cloneElement(child, {\n ...handlers,\n ref: mergeRefs(childRef, (node: HTMLElement | null) => {\n ctx.triggerRef.current = node;\n }),\n // Above the goo layer (z-[-1]) so the neck reads behind it.\n className: cn(\"relative z-0\", childProps.className as string | undefined),\n \"aria-haspopup\": \"dialog\",\n \"aria-expanded\": ctx.open,\n \"aria-controls\": ctx.open ? ctx.contentId : undefined,\n \"data-state\": ctx.open ? \"open\" : \"closed\",\n });\n}\n\nconst ALIGN_ORIGIN: Record<Align, string> = {\n start: \"left\",\n center: \"center\",\n end: \"right\",\n};\n\nexport interface PopoverContentProps {\n children: ReactNode;\n className?: string;\n}\n\nexport function PopoverContent({ children, className }: PopoverContentProps) {\n const ctx = usePopoverContext(\"PopoverContent\");\n const [portalReady, setPortalReady] = useState(false);\n const {\n side,\n align,\n gap,\n panelRadius,\n gooStrength,\n reduce,\n gooId,\n contentId,\n progress,\n triggerRef,\n contentRef,\n open,\n triggerMode,\n openHover,\n scheduleClose,\n } = ctx;\n\n const measureRef = contentRef;\n const panelHover = useHoverGesture();\n const blobRef = useRef<HTMLDivElement>(null);\n const clipRef = useRef<HTMLDivElement>(null);\n const geoRef = useRef<Geo | null>(null);\n const supportsShapeRef = useRef(false);\n const layout = usePopoverPortalPosition(triggerRef, measureRef, portalReady);\n\n useEffect(() => setPortalReady(true), []);\n\n const geo = useMemo(\n () =>\n buildGeo(\n layout?.trigger.width ?? 0,\n layout?.trigger.height ?? 0,\n layout?.content.width ?? 0,\n layout?.content.height ?? 0,\n side,\n align,\n gap,\n panelRadius,\n ),\n [layout, side, align, gap, panelRadius],\n );\n\n // Morph the same clip on the goo body and the content, so the whole popover\n // oozes as one and the text reveals with it.\n const render = useCallback((g: Geo | null, p: number) => {\n if (!g || g.layerW === 0) return;\n const clip = clipForProgress(g, p, supportsShapeRef.current);\n if (blobRef.current) blobRef.current.style.clipPath = clip;\n if (clipRef.current) clipRef.current.style.clipPath = clip;\n }, []);\n\n useLayoutEffect(() => {\n supportsShapeRef.current =\n typeof CSS !== \"undefined\" &&\n typeof CSS.supports === \"function\" &&\n CSS.supports(\"clip-path\", \"shape(from 0px 0px, line to 1px 1px, close)\");\n geoRef.current = geo;\n render(geo, progress.get());\n }, [geo, progress, render]);\n\n useMotionValueEvent(progress, \"change\", (p) => render(geoRef.current, p));\n\n const hoverHandlers =\n triggerMode === \"hover\" ? makeHoverHandlers(panelHover, openHover, scheduleClose) : {};\n\n // Match the server and first client render, then attach the portal after\n // hydration. This preserves SSR without regenerating the page on the client.\n if (!portalReady) return null;\n\n return createPortal(\n <div\n data-popover-portal=\"\"\n className=\"pointer-events-none fixed top-0 left-0 isolate z-9999 size-0\"\n style={{\n visibility: layout ? \"visible\" : \"hidden\",\n transform: `translate3d(${layout?.trigger.left ?? 0}px, ${layout?.trigger.top ?? 0}px, 0)`,\n }}\n >\n {/* Goo filter: blur, sharpen the alpha back into solid shapes, then lay\n the crisp original on top so blobs merge with liquid edges. */}\n <svg aria-hidden width=\"0\" height=\"0\" className=\"absolute\">\n <title>Popover visual effects</title>\n <defs>\n <filter id={gooId} x=\"-50%\" y=\"-50%\" width=\"200%\" height=\"200%\">\n <feGaussianBlur in=\"SourceGraphic\" stdDeviation={gooStrength} result=\"blur\" />\n <feColorMatrix\n in=\"blur\"\n mode=\"matrix\"\n values=\"1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 22 -10\"\n result=\"goo\"\n />\n <feComposite in=\"SourceGraphic\" in2=\"goo\" operator=\"atop\" />\n </filter>\n </defs>\n </svg>\n\n {/* Goo body: static trigger pill + morphing blob. */}\n <div\n aria-hidden\n className=\"pointer-events-none absolute z-[-1]\"\n style={{\n left: geo.left,\n top: geo.top,\n width: geo.layerW,\n height: geo.layerH,\n filter: reduce ? undefined : `url(#${gooId})`,\n clipPath: triggerCutout(geo),\n }}\n >\n <div\n className=\"absolute bg-popover\"\n style={{\n left: geo.trigger.x,\n top: geo.trigger.y,\n width: geo.trigger.w,\n height: geo.trigger.h,\n borderRadius: geo.trigger.r,\n }}\n />\n <div\n ref={blobRef}\n className=\"absolute inset-0 bg-popover\"\n style={{\n clipPath: clipForProgress(geo, progress.get(), false),\n }}\n />\n </div>\n\n {/* Content is clipped by the same morph. The portal wrapper stays\n pointer-transparent; only the fully open panel accepts interaction. */}\n <div\n className=\"pointer-events-none absolute z-10\"\n style={{\n left: geo.left,\n top: geo.top,\n width: geo.layerW,\n height: geo.layerH,\n }}\n >\n <div\n ref={clipRef}\n inert={!open}\n className=\"absolute inset-0\"\n style={{\n clipPath: clipForProgress(geo, progress.get(), false),\n pointerEvents: open ? \"auto\" : \"none\",\n }}\n >\n <div\n ref={measureRef}\n id={contentId}\n role=\"dialog\"\n {...hoverHandlers}\n style={{\n position: \"absolute\",\n left: geo.panel.x,\n top: geo.panel.y,\n transformOrigin: `${ALIGN_ORIGIN[align]} ${side === \"bottom\" ? \"top\" : \"bottom\"}`,\n }}\n className={cn(\n \"w-max max-w-[min(92vw,20rem)] p-4 text-popover-foreground outline-none\",\n className,\n )}\n >\n {children}\n </div>\n </div>\n </div>\n </div>,\n document.body,\n );\n}\n"],"mappings":";;;;;;;;;;;AAuCA,MAAM,kBAAkB;CACtB,MAAM;CACN,gBAAgB;CAChB,QAAQ;AACV;AACA,MAAM,mBAAmB;CACvB,MAAM;CACN,gBAAgB;CAChB,QAAQ;AACV;AACA,MAAM,oBAAoB;AAC1B,MAAM,eAAe;AAOrB,SAAS,kBAAkB,OAAqB,OAAmB,OAAmB;CACpF,OAAO;EACL,iBAAiB,UAA8B;GAC7C,IAAI,MAAM,MAAM,KAAK,GAAG,MAAM;EAChC;EACA,iBAAiB,UAA8B;GAC7C,IAAI,MAAM,MAAM,KAAK,GAAG,MAAM;EAChC;CACF;AACF;AAEA,MAAM,QAAQ,GAAW,GAAW,MAAc,KAAK,IAAI,KAAK;AAmBhE,SAAS,SACP,IACA,IACA,IACA,IACA,MACA,OACA,KACA,aACK;CACL,MAAM,KAAK,SAAS,WAAW,KAAK,MAAM,EAAE,MAAM;CAClD,MAAM,KAAK,UAAU,UAAU,IAAI,UAAU,QAAQ,KAAK,MAAM,KAAK,MAAM;CAE3E,MAAM,OAAO,KAAK,IAAI,GAAG,EAAE;CAC3B,MAAM,MAAM,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EA,UAAA,oBAAC,OAAD;MACE,KAAK;MACL,IAAI;MACJ,MAAK;MACL,GAAI;MACJ,OAAO;OACL,UAAU;OACV,MAAM,IAAI,MAAM;OAChB,KAAK,IAAI,MAAM;OACf,iBAAiB,GAAG,aAAa,OAAO,GAAG,SAAS,WAAW,QAAQ;MACzE;MACA,WAAW,GACT,0EACA,SACF;MAEC;KACE,CAAA;IACF,CAAA;GACF,CAAA;EACF;CACL,CAAA,GAAA,SAAS,IACX;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preview-rail.d.ts","names":[],"sources":["../../../src/components/motion/preview-rail.tsx"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"preview-rail.d.ts","names":[],"sources":["../../../src/components/motion/preview-rail.tsx"],"mappings":";;UAmBiB;EACf;EACA;EACA;EACA,cAAc;EACd;EACA;EACA;;UAGe;EACf,OAAO;EACP;EACA;EACA;EACA;EACA,kBAAkB;EAClB,gBAAgB,MAAM;EACtB,iBAAiB,MAAM,oBAAoB;EAC3C;EACA;EACA;EACA;EACA,WAAW;EACX;EACA;EACA;EACA;;iBAwBc,cACd,OACA,OACA,aACA,UACA,iBACA,gBACA,cACA,eACA,aACA,aACA,iBACA,UACA,UACA,WACA,eACA,2BACA,oBACC,mCAAgB,IAAA"}
|
|
@@ -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,QAA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,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;E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,eACI,2FACA,gBAAgB,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 +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",
|