@kumix/ui 0.3.6 → 0.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -24
- package/dist/cascader-types-BnH6wYD-.d.ts +183 -0
- package/dist/cascader-types-BnH6wYD-.d.ts.map +1 -0
- 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.d.ts.map +1 -1
- package/dist/components/motion/animated-sidebar.js +13 -3
- package/dist/components/motion/animated-sidebar.js.map +1 -1
- package/dist/components/motion/attachment-upload.d.ts.map +1 -1
- package/dist/components/motion/attachment-upload.js +9 -5
- package/dist/components/motion/attachment-upload.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 +78 -74
- package/dist/components/motion/bottom-sheet.js.map +1 -1
- package/dist/components/motion/center-morph-modal.d.ts.map +1 -1
- package/dist/components/motion/center-morph-modal.js +82 -88
- package/dist/components/motion/center-morph-modal.js.map +1 -1
- package/dist/components/motion/command-palette.d.ts.map +1 -1
- package/dist/components/motion/command-palette.js +51 -27
- 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/drawer.d.ts.map +1 -1
- package/dist/components/motion/drawer.js +30 -30
- package/dist/components/motion/drawer.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/loader.js +20 -22
- package/dist/components/motion/loader.js.map +1 -1
- package/dist/components/motion/morphing-modal.d.ts.map +1 -1
- package/dist/components/motion/morphing-modal.js +83 -83
- package/dist/components/motion/morphing-modal.js.map +1 -1
- package/dist/components/motion/morphing-search.d.ts +28 -0
- package/dist/components/motion/morphing-search.d.ts.map +1 -0
- package/dist/components/motion/morphing-search.js +418 -0
- package/dist/components/motion/morphing-search.js.map +1 -0
- package/dist/components/motion/morphing-tabs.d.ts.map +1 -1
- package/dist/components/motion/morphing-tabs.js +59 -18
- package/dist/components/motion/morphing-tabs.js.map +1 -1
- package/dist/components/motion/notification-stack.d.ts.map +1 -1
- package/dist/components/motion/notification-stack.js +28 -11
- package/dist/components/motion/notification-stack.js.map +1 -1
- package/dist/components/motion/popover-morph.d.ts.map +1 -1
- package/dist/components/motion/popover-morph.js +26 -11
- package/dist/components/motion/popover-morph.js.map +1 -1
- package/dist/components/motion/popover.d.ts.map +1 -1
- package/dist/components/motion/popover.js +39 -28
- package/dist/components/motion/popover.js.map +1 -1
- package/dist/components/motion/preview-rail.d.ts.map +1 -1
- package/dist/components/motion/preview-rail.js +42 -13
- package/dist/components/motion/preview-rail.js.map +1 -1
- package/dist/components/motion/project-folder.js +20 -20
- package/dist/components/motion/project-folder.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/cascader/cascader-async.d.ts +90 -0
- package/dist/components/reui/cascader/cascader-async.d.ts.map +1 -0
- package/dist/components/reui/cascader/cascader-async.js +549 -0
- package/dist/components/reui/cascader/cascader-async.js.map +1 -0
- package/dist/components/reui/cascader/cascader-columns.d.ts +29 -0
- package/dist/components/reui/cascader/cascader-columns.d.ts.map +1 -0
- package/dist/components/reui/cascader/cascader-columns.js +135 -0
- package/dist/components/reui/cascader/cascader-columns.js.map +1 -0
- package/dist/components/reui/cascader/cascader-context.d.ts +193 -0
- package/dist/components/reui/cascader/cascader-context.d.ts.map +1 -0
- package/dist/components/reui/cascader/cascader-context.js +59 -0
- package/dist/components/reui/cascader/cascader-context.js.map +1 -0
- package/dist/components/reui/cascader/cascader-footer.d.ts +85 -0
- package/dist/components/reui/cascader/cascader-footer.d.ts.map +1 -0
- package/dist/components/reui/cascader/cascader-footer.js +456 -0
- package/dist/components/reui/cascader/cascader-footer.js.map +1 -0
- package/dist/components/reui/cascader/cascader-i18n.d.ts +17 -0
- package/dist/components/reui/cascader/cascader-i18n.d.ts.map +1 -0
- package/dist/components/reui/cascader/cascader-i18n.js +68 -0
- package/dist/components/reui/cascader/cascader-i18n.js.map +1 -0
- package/dist/components/reui/cascader/cascader-item.d.ts +115 -0
- package/dist/components/reui/cascader/cascader-item.d.ts.map +1 -0
- package/dist/components/reui/cascader/cascader-item.js +530 -0
- package/dist/components/reui/cascader/cascader-item.js.map +1 -0
- package/dist/components/reui/cascader/cascader-lib.d.ts +141 -0
- package/dist/components/reui/cascader/cascader-lib.d.ts.map +1 -0
- package/dist/components/reui/cascader/cascader-lib.js +576 -0
- package/dist/components/reui/cascader/cascader-lib.js.map +1 -0
- package/dist/components/reui/cascader/cascader-nav.d.ts +59 -0
- package/dist/components/reui/cascader/cascader-nav.d.ts.map +1 -0
- package/dist/components/reui/cascader/cascader-nav.js +312 -0
- package/dist/components/reui/cascader/cascader-nav.js.map +1 -0
- package/dist/components/reui/cascader/cascader-types.d.ts +2 -0
- package/dist/components/reui/cascader/cascader-types.js +2 -0
- package/dist/components/reui/cascader/cascader-virtual.d.ts +65 -0
- package/dist/components/reui/cascader/cascader-virtual.d.ts.map +1 -0
- package/dist/components/reui/cascader/cascader-virtual.js +240 -0
- package/dist/components/reui/cascader/cascader-virtual.js.map +1 -0
- package/dist/components/reui/cascader/cascader.d.ts +322 -0
- package/dist/components/reui/cascader/cascader.d.ts.map +1 -0
- package/dist/components/reui/cascader/cascader.js +1459 -0
- package/dist/components/reui/cascader/cascader.js.map +1 -0
- package/dist/components/reui/event-calendar/event-calendar-event.d.ts +28 -47
- package/dist/components/reui/event-calendar/event-calendar-event.d.ts.map +1 -1
- package/dist/components/reui/event-calendar/event-calendar-event.js +26 -44
- package/dist/components/reui/event-calendar/event-calendar-event.js.map +1 -1
- package/dist/components/reui/event-calendar/event-calendar-nav.js +1 -1
- package/dist/components/reui/event-calendar/event-calendar-types.d.ts +19 -57
- package/dist/components/reui/event-calendar/event-calendar-types.d.ts.map +1 -1
- package/dist/components/reui/filters/filters-advanced.d.ts +52 -0
- package/dist/components/reui/filters/filters-advanced.d.ts.map +1 -0
- package/dist/components/reui/filters/filters-advanced.js +1191 -0
- package/dist/components/reui/filters/filters-advanced.js.map +1 -0
- package/dist/components/reui/filters/filters-builder.d.ts +43 -0
- package/dist/components/reui/filters/filters-builder.d.ts.map +1 -0
- package/dist/components/reui/filters/filters-builder.js +152 -0
- package/dist/components/reui/filters/filters-builder.js.map +1 -0
- package/dist/components/reui/filters/filters-chip.d.ts +79 -0
- package/dist/components/reui/filters/filters-chip.d.ts.map +1 -0
- package/dist/components/reui/filters/filters-chip.js +553 -0
- package/dist/components/reui/filters/filters-chip.js.map +1 -0
- package/dist/components/reui/filters/filters-context.d.ts +290 -0
- package/dist/components/reui/filters/filters-context.d.ts.map +1 -0
- package/dist/components/reui/filters/filters-context.js +277 -0
- package/dist/components/reui/filters/filters-context.js.map +1 -0
- package/dist/components/reui/filters/filters-date.d.ts +43 -0
- package/dist/components/reui/filters/filters-date.d.ts.map +1 -0
- package/dist/components/reui/filters/filters-date.js +143 -0
- package/dist/components/reui/filters/filters-date.js.map +1 -0
- package/dist/components/reui/filters/filters-dnd.d.ts +101 -0
- package/dist/components/reui/filters/filters-dnd.d.ts.map +1 -0
- package/dist/components/reui/filters/filters-dnd.js +454 -0
- package/dist/components/reui/filters/filters-dnd.js.map +1 -0
- package/dist/components/reui/filters/filters-draft.d.ts +2 -0
- package/dist/components/reui/filters/filters-draft.js +128 -0
- package/dist/components/reui/filters/filters-draft.js.map +1 -0
- package/dist/components/reui/filters/filters-editors.d.ts +91 -0
- package/dist/components/reui/filters/filters-editors.d.ts.map +1 -0
- package/dist/components/reui/filters/filters-editors.js +773 -0
- package/dist/components/reui/filters/filters-editors.js.map +1 -0
- package/dist/components/reui/filters/filters-i18n.d.ts +24 -0
- package/dist/components/reui/filters/filters-i18n.d.ts.map +1 -0
- package/dist/components/reui/filters/filters-i18n.js +127 -0
- package/dist/components/reui/filters/filters-i18n.js.map +1 -0
- package/dist/components/reui/filters/filters-lib.d.ts +171 -0
- package/dist/components/reui/filters/filters-lib.d.ts.map +1 -0
- package/dist/components/reui/filters/filters-lib.js +336 -0
- package/dist/components/reui/filters/filters-lib.js.map +1 -0
- package/dist/components/reui/filters/filters-operators.d.ts +49 -0
- package/dist/components/reui/filters/filters-operators.d.ts.map +1 -0
- package/dist/components/reui/filters/filters-operators.js +300 -0
- package/dist/components/reui/filters/filters-operators.js.map +1 -0
- package/dist/components/reui/filters/filters-query.d.ts +132 -0
- package/dist/components/reui/filters/filters-query.d.ts.map +1 -0
- package/dist/components/reui/filters/filters-query.js +476 -0
- package/dist/components/reui/filters/filters-query.js.map +1 -0
- package/dist/components/reui/filters/filters-types.d.ts +452 -0
- package/dist/components/reui/filters/filters-types.d.ts.map +1 -0
- package/dist/components/reui/filters/filters-types.js +2 -0
- package/dist/components/reui/filters/filters.d.ts +114 -0
- package/dist/components/reui/filters/filters.d.ts.map +1 -0
- package/dist/components/reui/filters/filters.js +638 -0
- package/dist/components/reui/filters/filters.js.map +1 -0
- package/dist/components/reui/frame.d.ts +1 -1
- package/dist/components/reui/gantt/gantt-bar.js +1 -1
- package/dist/components/reui/gantt/gantt-nav.js +1 -1
- package/dist/components/reui/gantt/gantt-types.d.ts +25 -71
- package/dist/components/reui/gantt/gantt-types.d.ts.map +1 -1
- package/dist/components/reui/gantt/gantt-view.js +1 -1
- package/dist/components/reui/icon-tile.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.d.ts +2 -2
- package/dist/components/ui/checkbox.js +1 -1
- package/dist/components/ui/checkbox.js.map +1 -1
- package/dist/components/ui/field.js +2 -2
- package/dist/components/ui/field.js.map +1 -1
- package/dist/components/ui/item.d.ts +2 -2
- package/dist/components/ui/marker.d.ts +1 -1
- package/dist/components/ui/radio-group.js +1 -1
- package/dist/components/ui/radio-group.js.map +1 -1
- package/dist/components/ui/sidebar.d.ts +1 -1
- package/dist/components/ui/sidebar.js +1 -1
- package/dist/components/ui/switch.js +1 -1
- package/dist/components/ui/switch.js.map +1 -1
- package/dist/components/ui/tabs.d.ts +1 -1
- package/dist/components/ui/toggle.d.ts +1 -1
- package/dist/{copy-menu-Bk5GP9Gp.js → copy-menu-1FKoMc9o.js} +9 -2
- package/dist/copy-menu-1FKoMc9o.js.map +1 -0
- package/dist/filters-draft-DEAl3TO-.d.ts +70 -0
- package/dist/filters-draft-DEAl3TO-.d.ts.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/text-shimmer.d.ts +2 -2
- package/dist/lib/text-shimmer.d.ts.map +1 -1
- package/dist/lib/text-shimmer.js +2 -2
- package/dist/lib/text-shimmer.js.map +1 -1
- 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/presence-gate-BekdC4Bo.js +24 -0
- package/dist/presence-gate-BekdC4Bo.js.map +1 -0
- package/dist/types-smkWN_7x.d.ts.map +1 -1
- package/package.json +9 -9
- package/dist/components/reui/filters.d.ts +0 -176
- package/dist/components/reui/filters.d.ts.map +0 -1
- package/dist/components/reui/filters.js +0 -1223
- package/dist/components/reui/filters.js.map +0 -1
- package/dist/copy-menu-Bk5GP9Gp.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project-folder.js","names":[],"sources":["../../../src/components/motion/project-folder.tsx"],"sourcesContent":["\"use client\";\n\nimport { type ReactNode, useCallback, useEffect, useId, useRef, useState } from \"react\";\nimport { X } from \"lucide-react\";\nimport {\n AnimatePresence,\n LayoutGroup,\n motion,\n type Transition,\n useReducedMotion,\n} from \"motion/react\";\nimport { createPortal } from \"react-dom\";\n\nimport { cn } from \"@kumix/utils\";\nimport { useHoverCapable } from \"../../hooks/use-hover-capable\";\nimport { SPRING_LAYOUT, SPRING_PRESS } from \"../../lib/ease\";\n\nexport type ProjectFolderPreview = {\n id: string;\n content: ReactNode;\n};\n\nexport interface ProjectFolderProps {\n title: string;\n description?: string;\n previews?: ProjectFolderPreview[];\n count?: number;\n itemLabel?: string;\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n expanded?: boolean;\n defaultExpanded?: boolean;\n onExpandedChange?: (expanded: boolean) => void;\n onClick?: () => void;\n disabled?: boolean;\n ariaLabel?: string;\n className?: string;\n}\n\nconst MAX_PREVIEWS = 5;\nconst FOCUSABLE_SELECTOR = [\n \"a[href]\",\n \"button:not([disabled])\",\n \"input:not([disabled])\",\n \"select:not([disabled])\",\n \"textarea:not([disabled])\",\n '[tabindex]:not([tabindex=\"-1\"])',\n].join(\",\");\n\nfunction getPreviewTransform(index: number, count: number) {\n const offset = index - (count - 1) / 2;\n const distance = Math.abs(offset);\n const centerLift = Math.max(0, 2 - distance) * 8;\n\n return {\n x: offset * 44,\n y: 8 - centerLift,\n rotate: offset * 6,\n scale: distance === 0 ? 1.04 : distance === 1 ? 0.95 : 0.88,\n opacity: distance === 0 ? 1 : distance === 1 ? 0.78 : 0.58,\n zIndex: 10 - distance,\n };\n}\n\nexport function ProjectFolder({\n title,\n description = \"Updated recently\",\n previews = [],\n count = previews.length,\n itemLabel = \"file\",\n open,\n defaultOpen = false,\n onOpenChange,\n expanded,\n defaultExpanded = false,\n onExpandedChange,\n onClick,\n disabled = false,\n ariaLabel,\n className,\n}: ProjectFolderProps) {\n const reduce = useReducedMotion();\n const canHover = useHoverCapable();\n const layoutGroupId = useId();\n const dialogTitleId = `${layoutGroupId}-title`;\n const hoveredRef = useRef(false);\n const focusedRef = useRef(false);\n const restoringFocusRef = useRef(false);\n const folderButtonRef = useRef<HTMLButtonElement>(null);\n const closeButtonRef = useRef<HTMLButtonElement>(null);\n const dialogRef = useRef<HTMLDivElement>(null);\n const [mounted, setMounted] = useState(false);\n const [internalOpen, setInternalOpen] = useState(defaultOpen);\n const [internalExpanded, setInternalExpanded] = useState(defaultExpanded);\n const [isClosing, setIsClosing] = useState(false);\n const openControlled = open !== undefined;\n const expandedControlled = expanded !== undefined;\n const isExpanded = expanded ?? internalExpanded;\n const isOpen = (open ?? internalOpen) || isExpanded;\n const previewItems = previews.slice(0, MAX_PREVIEWS);\n const transition: Transition = reduce ? { duration: 0 } : SPRING_LAYOUT;\n const countText = `${count} ${itemLabel}${count === 1 ? \"\" : \"s\"}`;\n\n const setOpen = useCallback(\n (next: boolean) => {\n if (disabled) return;\n if (!openControlled) setInternalOpen(next);\n onOpenChange?.(next);\n },\n [disabled, onOpenChange, openControlled],\n );\n\n const setExpanded = useCallback(\n (next: boolean) => {\n if (disabled || previewItems.length === 0) return;\n if (!expandedControlled) setInternalExpanded(next);\n onExpandedChange?.(next);\n },\n [disabled, expandedControlled, onExpandedChange, previewItems.length],\n );\n\n const finishClose = useCallback(() => {\n setIsClosing(false);\n restoringFocusRef.current = true;\n requestAnimationFrame(() => folderButtonRef.current?.focus());\n }, []);\n\n const closeOverlay = useCallback(() => {\n setIsClosing(true);\n setOpen(false);\n setExpanded(false);\n }, [setExpanded, setOpen]);\n\n useEffect(() => setMounted(true), []);\n\n useEffect(() => {\n if (reduce && isClosing) finishClose();\n }, [finishClose, isClosing, reduce]);\n\n useEffect(() => {\n if (!isExpanded) return;\n\n const previousOverflow = document.body.style.overflow;\n const focusFrame = requestAnimationFrame(() => closeButtonRef.current?.focus());\n\n document.body.style.overflow = \"hidden\";\n\n const handleKeyDown = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") {\n event.preventDefault();\n closeOverlay();\n return;\n }\n if (event.key !== \"Tab\" || !dialogRef.current) return;\n\n const focusable = Array.from(\n dialogRef.current.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR),\n ).filter((element) => element.tabIndex >= 0);\n const first = focusable[0];\n const last = focusable.at(-1);\n if (!first || !last) return;\n\n if (event.shiftKey && document.activeElement === first) {\n event.preventDefault();\n last.focus();\n } else if (!event.shiftKey && document.activeElement === last) {\n event.preventDefault();\n first.focus();\n }\n };\n\n document.addEventListener(\"keydown\", handleKeyDown);\n return () => {\n cancelAnimationFrame(focusFrame);\n document.body.style.overflow = previousOverflow;\n document.removeEventListener(\"keydown\", handleKeyDown);\n };\n }, [closeOverlay, isExpanded]);\n\n const handleFolderClick = () => {\n setIsClosing(false);\n setExpanded(true);\n setOpen(true);\n onClick?.();\n };\n\n const overlay =\n isExpanded || isClosing ? (\n <div\n ref={dialogRef}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-labelledby={dialogTitleId}\n aria-hidden={isExpanded ? undefined : \"true\"}\n className={cn(\n \"fixed inset-0 z-50 flex items-start justify-center overflow-y-auto sm:items-center\",\n isClosing && \"pointer-events-none\",\n )}\n >\n <AnimatePresence initial={false}>\n {isExpanded ? (\n <motion.button\n key=\"project-files-backdrop\"\n type=\"button\"\n tabIndex={-1}\n aria-label=\"Close file overlay\"\n onClick={closeOverlay}\n initial={{ opacity: 0 }}\n animate={{ opacity: 1 }}\n exit={{ opacity: 0 }}\n transition={reduce ? { duration: 0 } : { duration: 0.18 }}\n className=\"absolute inset-0 cursor-default bg-background/80 backdrop-blur-xl\"\n />\n ) : null}\n </AnimatePresence>\n\n <div className=\"relative z-10 w-full max-w-5xl px-6 py-8\">\n <AnimatePresence initial={false}>\n {isExpanded ? (\n <motion.div\n key=\"project-files-header\"\n initial={{ opacity: 0, y: reduce ? 0 : 8 }}\n animate={{ opacity: 1, y: 0 }}\n exit={{ opacity: 0, y: reduce ? 0 : -8 }}\n transition={reduce ? { duration: 0 } : { duration: 0.18 }}\n className=\"mb-6 flex items-center justify-between gap-4\"\n >\n <div>\n <h2 id={dialogTitleId} className=\"font-medium text-foreground text-xl\">\n {title}\n </h2>\n <p className=\"mt-1 text-muted-foreground text-sm\">{countText}</p>\n </div>\n <button\n ref={closeButtonRef}\n type=\"button\"\n onClick={closeOverlay}\n aria-label={`Close ${title}`}\n className=\"flex size-10 items-center justify-center rounded-full border border-foreground/10 bg-background/50 text-muted-foreground backdrop-blur-xl transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n >\n <X className=\"size-4\" aria-hidden=\"true\" />\n </button>\n </motion.div>\n ) : null}\n </AnimatePresence>\n\n <div className=\"grid grid-cols-2 place-items-center gap-3 sm:grid-cols-3 lg:grid-cols-5\">\n {isExpanded\n ? previewItems.map((preview) => (\n <motion.div\n key={preview.id}\n layoutId={`file-${preview.id}`}\n transition={transition}\n className=\"aspect-3/4 w-full max-w-40 overflow-hidden rounded-xl border border-foreground/10 bg-background/50 backdrop-blur-xl\"\n >\n {preview.content}\n </motion.div>\n ))\n : null}\n </div>\n </div>\n </div>\n ) : null;\n\n return (\n <LayoutGroup id={layoutGroupId}>\n <motion.button\n ref={folderButtonRef}\n type=\"button\"\n disabled={disabled}\n aria-label={ariaLabel}\n aria-haspopup=\"dialog\"\n aria-expanded={isExpanded}\n data-open={isOpen ? \"true\" : \"false\"}\n data-expanded={isExpanded ? \"true\" : \"false\"}\n tabIndex={isExpanded ? -1 : undefined}\n onPointerEnter={() => {\n if (!canHover) return;\n hoveredRef.current = true;\n setOpen(true);\n }}\n onPointerLeave={() => {\n if (!canHover) return;\n hoveredRef.current = false;\n if (!isExpanded && !isClosing) setOpen(focusedRef.current);\n }}\n onFocus={() => {\n if (restoringFocusRef.current) {\n restoringFocusRef.current = false;\n focusedRef.current = false;\n return;\n }\n focusedRef.current = true;\n setOpen(true);\n }}\n onBlur={() => {\n focusedRef.current = false;\n if (!isExpanded && !isClosing) setOpen(hoveredRef.current);\n }}\n onClick={handleFolderClick}\n whileTap={reduce || disabled ? undefined : { scale: 0.98 }}\n transition={reduce ? { duration: 0 } : SPRING_PRESS}\n className={cn(\n \"perspective-[1200px] relative block h-56 w-72 select-none rounded-2xl text-left outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-4 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50\",\n className,\n )}\n >\n <motion.span\n aria-hidden=\"true\"\n animate={{ rotateX: isOpen && !reduce ? 15 : 0 }}\n transition={transition}\n className=\"absolute inset-0 origin-[center_bottom] rounded-2xl border border-foreground/10 bg-background/25 backdrop-blur-xl\"\n />\n\n <span aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0\">\n <span className=\"absolute top-0 left-1/2 block h-0 w-0\">\n <AnimatePresence initial={false}>\n {!isExpanded\n ? previewItems.map((preview, index) => {\n const opened = getPreviewTransform(index, previewItems.length);\n return (\n <motion.span\n key={preview.id}\n layoutId={`file-${preview.id}`}\n initial={false}\n animate={\n isOpen && !reduce\n ? {\n x: opened.x * 1.4,\n y: opened.y - 8,\n rotate: opened.rotate * 1.3,\n scale: opened.scale * 1.02,\n opacity: Math.min(1, opened.opacity + 0.18),\n }\n : {\n x: opened.x,\n y: opened.y,\n rotate: opened.rotate,\n scale: opened.scale,\n opacity: opened.opacity,\n }\n }\n transition={transition}\n onLayoutAnimationComplete={() => {\n if (isClosing && index === 0) finishClose();\n }}\n className=\"absolute top-0 left-0 -ml-12 block h-40 w-24 overflow-hidden rounded-lg border border-foreground/10 bg-background/45 backdrop-blur-lg\"\n style={{ zIndex: opened.zIndex }}\n >\n {preview.content}\n </motion.span>\n );\n })\n : null}\n </AnimatePresence>\n </span>\n </span>\n\n <motion.span\n initial={false}\n animate={{ rotateX: isOpen && !reduce ? -25 : 0 }}\n transition={transition}\n className=\"backface-hidden absolute inset-x-0 bottom-0 z-20 origin-[center_bottom] overflow-hidden rounded-2xl border border-foreground/10 bg-background/60 backdrop-blur-2xl\"\n >\n <span className=\"flex h-16 items-center px-4\">\n <span className=\"line-clamp-2 font-medium text-foreground text-xl leading-tight\">\n {title}\n </span>\n </span>\n <span className=\"flex h-12 items-center justify-between gap-3 border-foreground/10 border-t px-4\">\n <span className=\"shrink-0 font-medium text-foreground/70 text-sm\">{countText}</span>\n <span className=\"truncate text-muted-foreground text-sm\">{description}</span>\n </span>\n </motion.span>\n </motion.button>\n\n {mounted ? createPortal(overlay, document.body) : null}\n </LayoutGroup>\n );\n}\n"],"mappings":";;;;;;;;;;AAwCA,MAAM,eAAe;AACrB,MAAM,qBAAqB;CACzB;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,GAAG;AAEV,SAAS,oBAAoB,OAAe,OAAe;CACzD,MAAM,SAAS,SAAS,QAAQ,KAAK;CACrC,MAAM,WAAW,KAAK,IAAI,MAAM;CAChC,MAAM,aAAa,KAAK,IAAI,GAAG,IAAI,QAAQ,IAAI;CAE/C,OAAO;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OAAM,WAAU;OAAmD,UAAA;MAAgB,CAAA,GACnF,oBAAC,QAAD;OAAM,WAAU;OAA0C,UAAA;MAAkB,CAAA,CACxE;KACK,CAAA,CAAA;;GACA;EAEd,CAAA,GAAA,UAAU,aAAa,SAAS,SAAS,IAAI,IAAI,IACvC;;AAEjB"}
|
|
1
|
+
{"version":3,"file":"project-folder.js","names":[],"sources":["../../../src/components/motion/project-folder.tsx"],"sourcesContent":["\"use client\";\n\nimport { type ReactNode, useCallback, useEffect, useId, useRef, useState } from \"react\";\nimport { X } from \"lucide-react\";\nimport {\n AnimatePresence,\n LayoutGroup,\n motion,\n type Transition,\n useReducedMotion,\n} from \"motion/react\";\nimport { createPortal } from \"react-dom\";\n\nimport { cn } from \"@kumix/utils\";\nimport { useHoverCapable } from \"../../hooks/use-hover-capable\";\nimport { SPRING_LAYOUT, SPRING_PRESS } from \"../../lib/ease\";\n\nexport type ProjectFolderPreview = {\n id: string;\n content: ReactNode;\n};\n\nexport interface ProjectFolderProps {\n title: string;\n description?: string;\n previews?: ProjectFolderPreview[];\n count?: number;\n itemLabel?: string;\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n expanded?: boolean;\n defaultExpanded?: boolean;\n onExpandedChange?: (expanded: boolean) => void;\n onClick?: () => void;\n disabled?: boolean;\n ariaLabel?: string;\n className?: string;\n}\n\nconst MAX_PREVIEWS = 5;\nconst FOCUSABLE_SELECTOR = [\n \"a[href]\",\n \"button:not([disabled])\",\n \"input:not([disabled])\",\n \"select:not([disabled])\",\n \"textarea:not([disabled])\",\n '[tabindex]:not([tabindex=\"-1\"])',\n].join(\",\");\n\nfunction getPreviewTransform(index: number, count: number) {\n const offset = index - (count - 1) / 2;\n const distance = Math.abs(offset);\n const centerLift = Math.max(0, 2 - distance) * 8;\n\n return {\n x: offset * 44,\n y: 8 - centerLift,\n rotate: offset * 6,\n scale: distance === 0 ? 1.04 : distance === 1 ? 0.95 : 0.88,\n opacity: distance === 0 ? 1 : distance === 1 ? 0.78 : 0.58,\n zIndex: 10 - distance,\n };\n}\n\nexport function ProjectFolder({\n title,\n description = \"Updated recently\",\n previews = [],\n count = previews.length,\n itemLabel = \"file\",\n open,\n defaultOpen = false,\n onOpenChange,\n expanded,\n defaultExpanded = false,\n onExpandedChange,\n onClick,\n disabled = false,\n ariaLabel,\n className,\n}: ProjectFolderProps) {\n const reduce = useReducedMotion();\n const canHover = useHoverCapable();\n const layoutGroupId = useId();\n const dialogTitleId = `${layoutGroupId}-title`;\n const hoveredRef = useRef(false);\n const focusedRef = useRef(false);\n const restoringFocusRef = useRef(false);\n const folderButtonRef = useRef<HTMLButtonElement>(null);\n const closeButtonRef = useRef<HTMLButtonElement>(null);\n const dialogRef = useRef<HTMLDivElement>(null);\n const [mounted, setMounted] = useState(false);\n const [internalOpen, setInternalOpen] = useState(defaultOpen);\n const [internalExpanded, setInternalExpanded] = useState(defaultExpanded);\n const [isClosing, setIsClosing] = useState(false);\n const openControlled = open !== undefined;\n const expandedControlled = expanded !== undefined;\n const isExpanded = expanded ?? internalExpanded;\n const isOpen = (open ?? internalOpen) || isExpanded;\n const previewItems = previews.slice(0, MAX_PREVIEWS);\n const transition: Transition = reduce ? { duration: 0 } : SPRING_LAYOUT;\n const countText = `${count} ${itemLabel}${count === 1 ? \"\" : \"s\"}`;\n\n const setOpen = useCallback(\n (next: boolean) => {\n if (disabled) return;\n if (!openControlled) setInternalOpen(next);\n onOpenChange?.(next);\n },\n [disabled, onOpenChange, openControlled],\n );\n\n const setExpanded = useCallback(\n (next: boolean) => {\n if (disabled || previewItems.length === 0) return;\n if (!expandedControlled) setInternalExpanded(next);\n onExpandedChange?.(next);\n },\n [disabled, expandedControlled, onExpandedChange, previewItems.length],\n );\n\n const finishClose = useCallback(() => {\n setIsClosing(false);\n restoringFocusRef.current = true;\n requestAnimationFrame(() => folderButtonRef.current?.focus());\n }, []);\n\n const closeOverlay = useCallback(() => {\n setIsClosing(true);\n setOpen(false);\n setExpanded(false);\n }, [setExpanded, setOpen]);\n\n useEffect(() => setMounted(true), []);\n\n useEffect(() => {\n if (reduce && isClosing) finishClose();\n }, [finishClose, isClosing, reduce]);\n\n useEffect(() => {\n if (!isExpanded) return;\n\n const previousOverflow = document.body.style.overflow;\n const focusFrame = requestAnimationFrame(() => closeButtonRef.current?.focus());\n\n document.body.style.overflow = \"hidden\";\n\n const handleKeyDown = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") {\n event.preventDefault();\n closeOverlay();\n return;\n }\n if (event.key !== \"Tab\" || !dialogRef.current) return;\n\n const focusable = Array.from(\n dialogRef.current.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR),\n ).filter((element) => element.tabIndex >= 0);\n const first = focusable[0];\n const last = focusable.at(-1);\n if (!first || !last) return;\n\n if (event.shiftKey && document.activeElement === first) {\n event.preventDefault();\n last.focus();\n } else if (!event.shiftKey && document.activeElement === last) {\n event.preventDefault();\n first.focus();\n }\n };\n\n document.addEventListener(\"keydown\", handleKeyDown);\n return () => {\n cancelAnimationFrame(focusFrame);\n document.body.style.overflow = previousOverflow;\n document.removeEventListener(\"keydown\", handleKeyDown);\n };\n }, [closeOverlay, isExpanded]);\n\n const handleFolderClick = () => {\n setIsClosing(false);\n setExpanded(true);\n setOpen(true);\n onClick?.();\n };\n\n // The chrome is two siblings: a backdrop spanning the viewport edges that\n // paints the scrim, and a transparent dialog inset off every edge that lays\n // out and scrolls the panel. The backdrop cannot nest inside that scroll box —\n // WebKit resolves a `position: fixed` descendant of an accelerated overflow\n // scroller against the scroller, not the viewport, so the insets would go\n // unscrimmed on a phone. The scroll box takes no pointer events and the panel\n // takes them back, so gutter presses still close the overlay. Accepted: the\n // 2rem inset sits outside the scroll box, so it stays put rather than\n // scrolling away with the content.\n const overlay =\n isExpanded || isClosing ? (\n <>\n <AnimatePresence initial={false}>\n {isExpanded ? (\n <motion.button\n key=\"project-files-backdrop\"\n type=\"button\"\n tabIndex={-1}\n aria-label=\"Close file overlay\"\n onClick={closeOverlay}\n initial={{ opacity: 0 }}\n animate={{ opacity: 1 }}\n exit={{ opacity: 0 }}\n transition={reduce ? { duration: 0 } : { duration: 0.18 }}\n className={cn(\n \"fixed inset-0 z-50 cursor-default bg-background/80 backdrop-blur-xl\",\n isClosing && \"pointer-events-none\",\n )}\n />\n ) : null}\n </AnimatePresence>\n\n <div\n ref={dialogRef}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-labelledby={dialogTitleId}\n aria-hidden={isExpanded ? undefined : \"true\"}\n className=\"pointer-events-none fixed inset-x-6 inset-y-8 z-50 flex items-start justify-center overflow-y-auto sm:items-center\"\n >\n {/* 61rem, not `max-w-5xl`: the cap is on a padding-free box, so it has to\n be the 64rem border box less the 3rem the gutters take. */}\n <div\n className={cn(\n \"pointer-events-auto relative z-10 w-full max-w-[61rem]\",\n isClosing && \"pointer-events-none\",\n )}\n >\n <AnimatePresence initial={false}>\n {isExpanded ? (\n <motion.div\n key=\"project-files-header\"\n initial={{ opacity: 0, y: reduce ? 0 : 8 }}\n animate={{ opacity: 1, y: 0 }}\n exit={{ opacity: 0, y: reduce ? 0 : -8 }}\n transition={reduce ? { duration: 0 } : { duration: 0.18 }}\n className=\"mb-6 flex items-center justify-between gap-4\"\n >\n <div>\n <h2 id={dialogTitleId} className=\"font-medium text-foreground text-xl\">\n {title}\n </h2>\n <p className=\"mt-1 text-muted-foreground text-sm\">{countText}</p>\n </div>\n <button\n ref={closeButtonRef}\n type=\"button\"\n onClick={closeOverlay}\n aria-label={`Close ${title}`}\n className=\"flex size-10 items-center justify-center rounded-full border border-foreground/10 bg-background/50 text-muted-foreground backdrop-blur-xl transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n >\n <X className=\"size-4\" aria-hidden=\"true\" />\n </button>\n </motion.div>\n ) : null}\n </AnimatePresence>\n\n <div className=\"grid grid-cols-2 place-items-center gap-3 sm:grid-cols-3 lg:grid-cols-5\">\n {isExpanded\n ? previewItems.map((preview) => (\n <motion.div\n key={preview.id}\n layoutId={`file-${preview.id}`}\n transition={transition}\n className=\"aspect-3/4 w-full max-w-40 overflow-hidden rounded-xl border border-foreground/10 bg-background/50 backdrop-blur-xl\"\n >\n {preview.content}\n </motion.div>\n ))\n : null}\n </div>\n </div>\n </div>\n </>\n ) : null;\n\n return (\n <LayoutGroup id={layoutGroupId}>\n <motion.button\n ref={folderButtonRef}\n type=\"button\"\n disabled={disabled}\n aria-label={ariaLabel}\n aria-haspopup=\"dialog\"\n aria-expanded={isExpanded}\n data-open={isOpen ? \"true\" : \"false\"}\n data-expanded={isExpanded ? \"true\" : \"false\"}\n tabIndex={isExpanded ? -1 : undefined}\n onPointerEnter={() => {\n if (!canHover) return;\n hoveredRef.current = true;\n setOpen(true);\n }}\n onPointerLeave={() => {\n if (!canHover) return;\n hoveredRef.current = false;\n if (!isExpanded && !isClosing) setOpen(focusedRef.current);\n }}\n onFocus={() => {\n if (restoringFocusRef.current) {\n restoringFocusRef.current = false;\n focusedRef.current = false;\n return;\n }\n focusedRef.current = true;\n setOpen(true);\n }}\n onBlur={() => {\n focusedRef.current = false;\n if (!isExpanded && !isClosing) setOpen(hoveredRef.current);\n }}\n onClick={handleFolderClick}\n whileTap={reduce || disabled ? undefined : { scale: 0.98 }}\n transition={reduce ? { duration: 0 } : SPRING_PRESS}\n className={cn(\n \"perspective-[1200px] relative block h-56 w-72 select-none rounded-2xl text-left outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-4 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50\",\n className,\n )}\n >\n <motion.span\n aria-hidden=\"true\"\n animate={{ rotateX: isOpen && !reduce ? 15 : 0 }}\n transition={transition}\n className=\"absolute inset-0 origin-[center_bottom] rounded-2xl border border-foreground/10 bg-background/25 backdrop-blur-xl\"\n />\n\n <span aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0\">\n <span className=\"absolute top-0 left-1/2 block h-0 w-0\">\n <AnimatePresence initial={false}>\n {!isExpanded\n ? previewItems.map((preview, index) => {\n const opened = getPreviewTransform(index, previewItems.length);\n return (\n <motion.span\n key={preview.id}\n layoutId={`file-${preview.id}`}\n initial={false}\n animate={\n isOpen && !reduce\n ? {\n x: opened.x * 1.4,\n y: opened.y - 8,\n rotate: opened.rotate * 1.3,\n scale: opened.scale * 1.02,\n opacity: Math.min(1, opened.opacity + 0.18),\n }\n : {\n x: opened.x,\n y: opened.y,\n rotate: opened.rotate,\n scale: opened.scale,\n opacity: opened.opacity,\n }\n }\n transition={transition}\n onLayoutAnimationComplete={() => {\n if (isClosing && index === 0) finishClose();\n }}\n className=\"absolute top-0 left-0 -ml-12 block h-40 w-24 overflow-hidden rounded-lg border border-foreground/10 bg-background/45 backdrop-blur-lg\"\n style={{ zIndex: opened.zIndex }}\n >\n {preview.content}\n </motion.span>\n );\n })\n : null}\n </AnimatePresence>\n </span>\n </span>\n\n <motion.span\n initial={false}\n animate={{ rotateX: isOpen && !reduce ? -25 : 0 }}\n transition={transition}\n className=\"backface-hidden absolute inset-x-0 bottom-0 z-20 origin-[center_bottom] overflow-hidden rounded-2xl border border-foreground/10 bg-background/60 backdrop-blur-2xl\"\n >\n <span className=\"flex h-16 items-center px-4\">\n <span className=\"line-clamp-2 font-medium text-foreground text-xl leading-tight\">\n {title}\n </span>\n </span>\n <span className=\"flex h-12 items-center justify-between gap-3 border-foreground/10 border-t px-4\">\n <span className=\"shrink-0 font-medium text-foreground/70 text-sm\">{countText}</span>\n <span className=\"truncate text-muted-foreground text-sm\">{description}</span>\n </span>\n </motion.span>\n </motion.button>\n\n {mounted ? createPortal(overlay, document.body) : null}\n </LayoutGroup>\n );\n}\n"],"mappings":";;;;;;;;;;AAwCA,MAAM,eAAe;AACrB,MAAM,qBAAqB;CACzB;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,GAAG;AAEV,SAAS,oBAAoB,OAAe,OAAe;CACzD,MAAM,SAAS,SAAS,QAAQ,KAAK;CACrC,MAAM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AAM,WAAU;MACd,UAAA,oBAAC,QAAD;OAAM,WAAU;OACb,UAAA;MACG,CAAA;KACF,CAAA,GACN,qBAAC,QAAD;MAAM,WAAU;MAAhB,UAAA,CACE,oBAAC,QAAD;OAAM,WAAU;OAAmD,UAAA;MAAgB,CAAA,GACnF,oBAAC,QAAD;OAAM,WAAU;OAA0C,UAAA;MAAkB,CAAA,CACxE;KACK,CAAA,CAAA;;GACA;EAEd,CAAA,GAAA,UAAU,aAAa,SAAS,SAAS,IAAI,IAAI,IACvC;;AAEjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pull-to-refresh.d.ts","names":[],"sources":["../../../src/components/motion/pull-to-refresh.tsx"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"pull-to-refresh.d.ts","names":[],"sources":["../../../src/components/motion/pull-to-refresh.tsx"],"mappings":";;KAwBY;UAEK;;EAEf,wBAAwB;EACxB,UAAU;;EAEV;EACA;;EAEA;;EAEA;;EAEA;EACA,eAAe;EACf,eAAe;EACf,kBAAkB;EAClB;EACA;EACA;EACA;;iBAsJc,gBACd,WACA,UACA,YACA,UACA,WACA,SACA,cACA,cACA,cACA,iBACA,WACA,WACA,kBACA,sBACC,qCAAkB,IAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { TOUCH_GESTURE_CONTENT_CLASS, capturePointer } from "../../lib/touch.js";
|
|
2
3
|
import { EASE_IN_OUT, EASE_OUT, SPRING_PANEL, SPRING_SWAP } from "../../lib/ease.js";
|
|
3
4
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
4
5
|
import { cn } from "@kumix/utils";
|
|
@@ -305,9 +306,9 @@ function PullToRefresh({ onRefresh, children, refreshing = false, disabled = fal
|
|
|
305
306
|
useEffect(() => {
|
|
306
307
|
return () => animationRef.current?.stop();
|
|
307
308
|
}, []);
|
|
308
|
-
const
|
|
309
|
-
if (event.pointerType
|
|
310
|
-
event.currentTarget
|
|
309
|
+
const startPointerPull = (event) => {
|
|
310
|
+
if (event.pointerType === "touch" || event.button !== 0 || event.currentTarget.scrollTop > 0 || disabled || isRefreshing) return;
|
|
311
|
+
capturePointer(event.currentTarget, event.pointerId);
|
|
311
312
|
gestureRef.current = {
|
|
312
313
|
active: true,
|
|
313
314
|
startX: event.clientX,
|
|
@@ -315,7 +316,7 @@ function PullToRefresh({ onRefresh, children, refreshing = false, disabled = fal
|
|
|
315
316
|
pointerId: event.pointerId
|
|
316
317
|
};
|
|
317
318
|
};
|
|
318
|
-
const
|
|
319
|
+
const movePointerPull = (event) => {
|
|
319
320
|
const gesture = gestureRef.current;
|
|
320
321
|
if (!gesture.active || gesture.pointerId !== event.pointerId) return;
|
|
321
322
|
const deltaX = event.clientX - gesture.startX;
|
|
@@ -331,15 +332,15 @@ function PullToRefresh({ onRefresh, children, refreshing = false, disabled = fal
|
|
|
331
332
|
"aria-busy": isRefreshing,
|
|
332
333
|
"data-state": status,
|
|
333
334
|
"data-disabled": disabled || void 0,
|
|
334
|
-
onPointerDown:
|
|
335
|
-
onPointerMove:
|
|
335
|
+
onPointerDown: startPointerPull,
|
|
336
|
+
onPointerMove: movePointerPull,
|
|
336
337
|
onPointerUp: (event) => {
|
|
337
338
|
if (gestureRef.current.pointerId === event.pointerId) finishPull();
|
|
338
339
|
},
|
|
339
340
|
onPointerCancel: (event) => {
|
|
340
341
|
if (gestureRef.current.pointerId === event.pointerId) finishPull();
|
|
341
342
|
},
|
|
342
|
-
className: cn("relative w-full overflow-y-auto overscroll-contain bg-background", status === "pulling" || status === "ready" ? "cursor-grabbing select-none" : "cursor-grab", (disabled || isRefreshing) && "cursor-default", className),
|
|
343
|
+
className: cn("relative w-full overflow-y-auto overscroll-contain bg-background", TOUCH_GESTURE_CONTENT_CLASS, status === "pulling" || status === "ready" ? "cursor-grabbing select-none" : "cursor-grab", (disabled || isRefreshing) && "cursor-default", className),
|
|
343
344
|
children: [/* @__PURE__ */ jsxs(motion.div, {
|
|
344
345
|
"aria-live": "polite",
|
|
345
346
|
"aria-atomic": "true",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pull-to-refresh.js","names":[],"sources":["../../../src/components/motion/pull-to-refresh.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type ReactNode,\n type PointerEvent as ReactPointerEvent,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from \"react\";\nimport {\n AnimatePresence,\n animate,\n type MotionValue,\n motion,\n useMotionValue,\n useReducedMotion,\n useTransform,\n} from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { EASE_IN_OUT, EASE_OUT, SPRING_PANEL, SPRING_SWAP } from \"../../lib/ease\";\n\nexport type PullToRefreshStatus = \"idle\" | \"pulling\" | \"ready\" | \"refreshing\";\n\nexport interface PullToRefreshProps {\n /** Runs after the user pulls beyond the threshold and releases. */\n onRefresh: () => void | Promise<void>;\n children: ReactNode;\n /** Keeps the indicator active while an externally managed refresh runs. */\n refreshing?: boolean;\n disabled?: boolean;\n /** Resisted pull distance in pixels required to refresh. */\n threshold?: number;\n /** Maximum resisted pull distance in pixels. */\n maxPull?: number;\n /** Content offset in pixels while refreshing. */\n holdDistance?: number;\n pullingLabel?: ReactNode;\n releaseLabel?: ReactNode;\n refreshingLabel?: ReactNode;\n ariaLabel?: string;\n className?: string;\n contentClassName?: string;\n indicatorClassName?: string;\n}\n\ntype Gesture = {\n active: boolean;\n startX: number;\n startY: number;\n pointerId: number | null;\n};\n\nconst EMPTY_GESTURE: Gesture = {\n active: false,\n startX: 0,\n startY: 0,\n pointerId: null,\n};\n\n// This character needs a compact repeating rhythm rather than a settling\n// spring: a small orbit and blink that read as activity without feeling busy.\nconst CHARACTER_LOOP = {\n duration: 0.9,\n ease: EASE_IN_OUT,\n repeat: Number.POSITIVE_INFINITY,\n} as const;\nconst CALM_PULSE = {\n duration: 1.2,\n ease: EASE_IN_OUT,\n repeat: Number.POSITIVE_INFINITY,\n} as const;\nconst LABEL_SWAP = { duration: 0.16, ease: EASE_OUT } as const;\n\nfunction resistedDistance(distance: number, maxPull: number) {\n return maxPull * (1 - Math.exp(-Math.max(0, distance) / maxPull));\n}\n\nfunction RefreshBuddy({\n progress,\n status,\n reduce,\n}: {\n progress: MotionValue<number>;\n status: PullToRefreshStatus;\n reduce: boolean;\n}) {\n const lift = useTransform(progress, [0, 1], [-7, 0]);\n const tilt = useTransform(progress, [0, 1], [-10, 0]);\n const stretch = useTransform(progress, [0, 0.55, 1], [0.68, 1.1, 0.92]);\n const ready = status === \"ready\";\n const refreshing = status === \"refreshing\";\n\n return (\n <motion.span\n style={reduce ? undefined : { y: lift, rotate: tilt, scaleY: stretch }}\n className=\"block h-9 w-9 origin-bottom\"\n >\n <motion.svg\n aria-hidden=\"true\"\n viewBox=\"0 0 36 36\"\n style={{ opacity: 1 }}\n className=\"h-full w-full overflow-visible\"\n animate={\n refreshing\n ? reduce\n ? { opacity: [0.55, 1, 0.55] }\n : { y: [0, -2, 0], rotate: [-3, 3, -3] }\n : reduce\n ? { opacity: 1 }\n : { y: 0, rotate: 0, scale: ready ? 1.08 : 1 }\n }\n transition={refreshing ? (reduce ? CALM_PULSE : CHARACTER_LOOP) : SPRING_SWAP}\n >\n <motion.g\n style={{ transformOrigin: \"18px 18px\" }}\n animate={\n refreshing && !reduce\n ? { rotate: [0, 360] }\n : reduce\n ? undefined\n : { rotate: ready ? 0 : -35 }\n }\n transition={refreshing ? (reduce ? CALM_PULSE : CHARACTER_LOOP) : SPRING_SWAP}\n className={cn(\n \"transition-opacity duration-150\",\n ready || refreshing ? \"opacity-100\" : \"opacity-0\",\n )}\n >\n <path\n d=\"M18 2.5a15.5 15.5 0 0 1 12.7 6.6\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"1.5\"\n strokeLinecap=\"round\"\n className=\"text-muted-foreground\"\n />\n <circle cx=\"31.3\" cy=\"10.2\" r=\"2.2\" className=\"fill-foreground\" />\n </motion.g>\n\n <rect x=\"7\" y=\"7\" width=\"22\" height=\"22\" rx=\"9\" className=\"fill-foreground\" />\n\n <motion.g\n style={{ opacity: 1, transformOrigin: \"18px 16px\" }}\n animate={\n refreshing && !reduce\n ? { scaleY: [1, 1, 0.15, 1, 1] }\n : reduce\n ? { opacity: 1 }\n : { scaleY: ready ? 1.18 : 1 }\n }\n transition={refreshing && !reduce ? CHARACTER_LOOP : SPRING_SWAP}\n >\n <circle cx=\"14.2\" cy=\"16\" r=\"1.45\" className=\"fill-background\" />\n <circle cx=\"21.8\" cy=\"16\" r=\"1.45\" className=\"fill-background\" />\n </motion.g>\n\n <path\n d=\"M14.5 21h7\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"1.5\"\n strokeLinecap=\"round\"\n className={cn(\n \"text-background transition-opacity duration-150\",\n ready || refreshing ? \"opacity-0\" : \"opacity-100\",\n )}\n />\n <path\n d=\"M14 20.5c1 2.4 7 2.4 8 0\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"1.5\"\n strokeLinecap=\"round\"\n className={cn(\n \"text-background transition-opacity duration-150\",\n ready ? \"opacity-100\" : \"opacity-0\",\n )}\n />\n <circle\n cx=\"18\"\n cy=\"21\"\n r=\"1.6\"\n className={cn(\n \"fill-background transition-opacity duration-150\",\n refreshing ? \"opacity-100\" : \"opacity-0\",\n )}\n />\n </motion.svg>\n </motion.span>\n );\n}\n\nexport function PullToRefresh({\n onRefresh,\n children,\n refreshing = false,\n disabled = false,\n threshold = 76,\n maxPull = 132,\n holdDistance = 68,\n pullingLabel = \"Pull to refresh\",\n releaseLabel = \"Release to refresh\",\n refreshingLabel = \"Refreshing\",\n ariaLabel = \"Refreshable content\",\n className,\n contentClassName,\n indicatorClassName,\n}: PullToRefreshProps) {\n const rootRef = useRef<HTMLElement>(null);\n const gestureRef = useRef<Gesture>({ ...EMPTY_GESTURE });\n const animationRef = useRef<{ stop: () => void } | null>(null);\n const statusRef = useRef<PullToRefreshStatus>(\"idle\");\n const disabledRef = useRef(disabled);\n const externalRefreshingRef = useRef(refreshing);\n const refreshingRef = useRef(refreshing);\n const [status, setStatusState] = useState<PullToRefreshStatus>(\"idle\");\n const [internalRefreshing, setInternalRefreshing] = useState(false);\n const reduce = useReducedMotion();\n const pullThreshold = Math.max(24, threshold);\n const pullLimit = Math.max(maxPull, pullThreshold + 24);\n const restingDistance = Math.min(Math.max(0, holdDistance), pullThreshold);\n const y = useMotionValue(0);\n const progress = useTransform(y, [0, pullThreshold], [0, 1]);\n const indicatorOpacity = useTransform(y, [0, 10, pullThreshold], [0, 0.45, 1]);\n const indicatorScale = useTransform(y, [0, pullThreshold], [0.86, 1]);\n const isRefreshing = refreshing || internalRefreshing;\n\n disabledRef.current = disabled;\n externalRefreshingRef.current = refreshing;\n refreshingRef.current = isRefreshing;\n\n const setStatus = useCallback((next: PullToRefreshStatus) => {\n if (statusRef.current === next) return;\n statusRef.current = next;\n setStatusState(next);\n }, []);\n\n const settle = useCallback(\n (target: number) => {\n animationRef.current?.stop();\n\n if (reduce) {\n y.set(target);\n return;\n }\n\n animationRef.current = animate(y, target, SPRING_PANEL);\n },\n [reduce, y],\n );\n\n const updatePull = useCallback(\n (distance: number) => {\n if (disabledRef.current || refreshingRef.current) return;\n animationRef.current?.stop();\n\n const next = resistedDistance(distance, pullLimit);\n y.set(next);\n setStatus(next >= pullThreshold ? \"ready\" : \"pulling\");\n },\n [pullLimit, pullThreshold, setStatus, y],\n );\n\n const runRefresh = useCallback(async () => {\n if (disabledRef.current || refreshingRef.current) return;\n\n setInternalRefreshing(true);\n setStatus(\"refreshing\");\n settle(restingDistance);\n\n try {\n await onRefresh();\n } finally {\n setInternalRefreshing(false);\n\n // A synchronous refresh can resolve before React commits the temporary\n // internal state, so release here instead of relying only on the effect.\n if (!externalRefreshingRef.current) {\n setStatus(\"idle\");\n settle(0);\n }\n }\n }, [onRefresh, restingDistance, setStatus, settle]);\n\n const finishPull = useCallback(() => {\n const shouldRefresh =\n y.get() >= pullThreshold && !disabledRef.current && !refreshingRef.current;\n\n gestureRef.current = { ...EMPTY_GESTURE };\n\n if (shouldRefresh) {\n void runRefresh();\n return;\n }\n\n setStatus(\"idle\");\n settle(0);\n }, [pullThreshold, runRefresh, setStatus, settle, y]);\n\n useEffect(() => {\n if (isRefreshing) {\n setStatus(\"refreshing\");\n settle(restingDistance);\n return;\n }\n\n if (statusRef.current === \"refreshing\") {\n setStatus(\"idle\");\n settle(0);\n }\n }, [isRefreshing, restingDistance, setStatus, settle]);\n\n useEffect(() => {\n const root = rootRef.current;\n if (!root) return;\n\n const onTouchStart = (event: TouchEvent) => {\n if (\n event.touches.length !== 1 ||\n root.scrollTop > 0 ||\n disabledRef.current ||\n refreshingRef.current\n ) {\n return;\n }\n\n const touch = event.touches[0];\n gestureRef.current = {\n active: true,\n startX: touch.clientX,\n startY: touch.clientY,\n pointerId: null,\n };\n };\n\n const onTouchMove = (event: TouchEvent) => {\n const gesture = gestureRef.current;\n const touch = event.touches[0];\n if (!gesture.active || !touch) return;\n\n const deltaX = touch.clientX - gesture.startX;\n const deltaY = touch.clientY - gesture.startY;\n\n if (root.scrollTop > 0 || deltaY < 0) {\n gestureRef.current = { ...EMPTY_GESTURE };\n return;\n }\n\n if (Math.abs(deltaX) > deltaY) return;\n\n event.preventDefault();\n updatePull(deltaY);\n };\n\n const onTouchEnd = () => {\n if (gestureRef.current.active) finishPull();\n };\n\n root.addEventListener(\"touchstart\", onTouchStart, { passive: true });\n root.addEventListener(\"touchmove\", onTouchMove, { passive: false });\n root.addEventListener(\"touchend\", onTouchEnd);\n root.addEventListener(\"touchcancel\", onTouchEnd);\n\n return () => {\n root.removeEventListener(\"touchstart\", onTouchStart);\n root.removeEventListener(\"touchmove\", onTouchMove);\n root.removeEventListener(\"touchend\", onTouchEnd);\n root.removeEventListener(\"touchcancel\", onTouchEnd);\n };\n }, [finishPull, updatePull]);\n\n useEffect(() => {\n return () => animationRef.current?.stop();\n }, []);\n\n const startMousePull = (event: ReactPointerEvent<HTMLElement>) => {\n if (\n event.pointerType !== \"mouse\" ||\n event.button !== 0 ||\n event.currentTarget.scrollTop > 0 ||\n disabled ||\n isRefreshing\n ) {\n return;\n }\n\n event.currentTarget.setPointerCapture(event.pointerId);\n gestureRef.current = {\n active: true,\n startX: event.clientX,\n startY: event.clientY,\n pointerId: event.pointerId,\n };\n };\n\n const moveMousePull = (event: ReactPointerEvent<HTMLElement>) => {\n const gesture = gestureRef.current;\n if (!gesture.active || gesture.pointerId !== event.pointerId) return;\n\n const deltaX = event.clientX - gesture.startX;\n const deltaY = event.clientY - gesture.startY;\n if (deltaY < 0 || Math.abs(deltaX) > deltaY) return;\n\n event.preventDefault();\n updatePull(deltaY);\n };\n\n const label =\n status === \"refreshing\" ? refreshingLabel : status === \"ready\" ? releaseLabel : pullingLabel;\n\n return (\n <section\n ref={rootRef}\n aria-label={ariaLabel}\n aria-busy={isRefreshing}\n data-state={status}\n data-disabled={disabled || undefined}\n onPointerDown={startMousePull}\n onPointerMove={moveMousePull}\n onPointerUp={(event) => {\n if (gestureRef.current.pointerId === event.pointerId) finishPull();\n }}\n onPointerCancel={(event) => {\n if (gestureRef.current.pointerId === event.pointerId) finishPull();\n }}\n className={cn(\n \"relative w-full overflow-y-auto overscroll-contain bg-background\",\n status === \"pulling\" || status === \"ready\" ? \"cursor-grabbing select-none\" : \"cursor-grab\",\n (disabled || isRefreshing) && \"cursor-default\",\n className,\n )}\n >\n <motion.div\n aria-live=\"polite\"\n aria-atomic=\"true\"\n style={\n reduce\n ? { opacity: indicatorOpacity }\n : { opacity: indicatorOpacity, scale: indicatorScale }\n }\n className={cn(\n \"pointer-events-none absolute inset-x-0 top-0 z-20 flex h-[4.25rem] flex-col items-center justify-center gap-0.5 bg-linear-to-b from-background via-background/95 to-transparent font-medium text-[11px] text-muted-foreground\",\n indicatorClassName,\n )}\n >\n <RefreshBuddy progress={progress} status={status} reduce={Boolean(reduce)} />\n <span className=\"relative h-4 min-w-24 text-center\">\n <AnimatePresence initial={false} mode=\"wait\">\n <motion.span\n key={status}\n initial={reduce ? { opacity: 0 } : { opacity: 0, y: 3 }}\n animate={reduce ? { opacity: 1 } : { opacity: 1, y: 0 }}\n exit={reduce ? { opacity: 0 } : { opacity: 0, y: -3 }}\n transition={LABEL_SWAP}\n className=\"absolute inset-x-0 whitespace-nowrap\"\n >\n {label}\n </motion.span>\n </AnimatePresence>\n </span>\n </motion.div>\n\n <motion.div\n style={reduce ? undefined : { y }}\n className={cn(\n \"relative z-10 min-h-full bg-inherit will-change-transform\",\n contentClassName,\n )}\n >\n {children}\n </motion.div>\n </section>\n );\n}\n"],"mappings":";;;;;;;AAsDA,MAAM,gBAAyB;CAC7B,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,WAAW;AACb;AAIA,MAAM,iBAAiB;CACrB,UAAU;CACV,MAAM;CACN,QAAQ,OAAO;AACjB;AACA,MAAM,aAAa;CACjB,UAAU;CACV,MAAM;CACN,QAAQ,OAAO;AACjB;AACA,MAAM,aAAa;CAAE,UAAU;CAAM,MAAM;AAAS;AAEpD,SAAS,iBAAiB,UAAkB,SAAiB;CAC3D,OAAO,WAAW,IAAI,KAAK,IAAI,CAAC,KAAK,IAAI,GAAG,QAAQ,IAAI,OAAO;AACjE;AAEA,SAAS,aAAa,EACpB,UACA,QACA,UAKC;CACD,MAAM,OAAO,aAAa,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;CACnD,MAAM,OAAO,aAAa,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;CACpD,MAAM,UAAU,aAAa,UAAU;EAAC;EAAG;EAAM;CAAC,GAAG;EAAC;EAAM;EAAK;CAAI,CAAC;CACtE,MAAM,QAAQ,WAAW;CACzB,MAAM,aAAa,WAAW;CAE9B,OACE,oBAAC,OAAO,MAAR;EACE,OAAO,SAAS,KAAA,IAAY;GAAE,GAAG;GAAM,QAAQ;GAAM,QAAQ;EAAQ;EACrE,WAAU;EAEV,UAAA,qBAAC,OAAO,KAA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AW;EACnE;EACA,WAAW,GACT,oEACA,WAAW,aAAa,WAAW,UAAU,gCAAgC,gBAC5E,YAAY,iBAAiB,kBAC9B,SACF;EAnBF,UAAA,CAqBE,qBAAC,OAAO,KAAR;GACE,aAAU;GACV,eAAY;GACZ,OACE,SACI,EAAE,SAAS,iBAAiB,IAC5B;IAAE,SAAS;IAAkB,OAAO;GAAe;GAEzD,WAAW,GACT,iOACA,kBACF;GAXF,UAAA,CAaE,oBAAC,cAAD;IAAwB;IAAkB;IAAQ,QAAQ,QAAQ,MAAM;GAAI,CAAA,GAC5E,oBAAC,QAAD;IAAM,WAAU;IACd,UAAA,oBAAC,iBAAD;KAAiB,SAAS;KAAO,MAAK;KACpC,UAAA,oBAAC,OAAO,MAAR;MAEE,SAAS,SAAS,EAAE,SAAS,EAAE,IAAI;OAAE,SAAS;OAAG,GAAG;MAAE;MACtD,SAAS,SAAS,EAAE,SAAS,EAAE,IAAI;OAAE,SAAS;OAAG,GAAG;MAAE;MACtD,MAAM,SAAS,EAAE,SAAS,EAAE,IAAI;OAAE,SAAS;OAAG,GAAG;MAAG;MACpD,YAAY;MACZ,WAAU;MAET,UAAA;KACU,GARN,MAQM;IACE,CAAA;GACb,CAAA,CACI;EAEZ,CAAA,GAAA,oBAAC,OAAO,KAAR;GACE,OAAO,SAAS,KAAA,IAAY,EAAE,EAAE;GAChC,WAAW,GACT,6DACA,gBACF;GAEC;EACS,CAAA,CACL;;AAEb"}
|
|
1
|
+
{"version":3,"file":"pull-to-refresh.js","names":[],"sources":["../../../src/components/motion/pull-to-refresh.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type ReactNode,\n type PointerEvent as ReactPointerEvent,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from \"react\";\nimport {\n AnimatePresence,\n animate,\n type MotionValue,\n motion,\n useMotionValue,\n useReducedMotion,\n useTransform,\n} from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { EASE_IN_OUT, EASE_OUT, SPRING_PANEL, SPRING_SWAP } from \"../../lib/ease\";\nimport { capturePointer, TOUCH_GESTURE_CONTENT_CLASS } from \"../../lib/touch\";\n\nexport type PullToRefreshStatus = \"idle\" | \"pulling\" | \"ready\" | \"refreshing\";\n\nexport interface PullToRefreshProps {\n /** Runs after the user pulls beyond the threshold and releases. */\n onRefresh: () => void | Promise<void>;\n children: ReactNode;\n /** Keeps the indicator active while an externally managed refresh runs. */\n refreshing?: boolean;\n disabled?: boolean;\n /** Resisted pull distance in pixels required to refresh. */\n threshold?: number;\n /** Maximum resisted pull distance in pixels. */\n maxPull?: number;\n /** Content offset in pixels while refreshing. */\n holdDistance?: number;\n pullingLabel?: ReactNode;\n releaseLabel?: ReactNode;\n refreshingLabel?: ReactNode;\n ariaLabel?: string;\n className?: string;\n contentClassName?: string;\n indicatorClassName?: string;\n}\n\ntype Gesture = {\n active: boolean;\n startX: number;\n startY: number;\n pointerId: number | null;\n};\n\nconst EMPTY_GESTURE: Gesture = {\n active: false,\n startX: 0,\n startY: 0,\n pointerId: null,\n};\n\n// This character needs a compact repeating rhythm rather than a settling\n// spring: a small orbit and blink that read as activity without feeling busy.\nconst CHARACTER_LOOP = {\n duration: 0.9,\n ease: EASE_IN_OUT,\n repeat: Number.POSITIVE_INFINITY,\n} as const;\nconst CALM_PULSE = {\n duration: 1.2,\n ease: EASE_IN_OUT,\n repeat: Number.POSITIVE_INFINITY,\n} as const;\nconst LABEL_SWAP = { duration: 0.16, ease: EASE_OUT } as const;\n\nfunction resistedDistance(distance: number, maxPull: number) {\n return maxPull * (1 - Math.exp(-Math.max(0, distance) / maxPull));\n}\n\nfunction RefreshBuddy({\n progress,\n status,\n reduce,\n}: {\n progress: MotionValue<number>;\n status: PullToRefreshStatus;\n reduce: boolean;\n}) {\n const lift = useTransform(progress, [0, 1], [-7, 0]);\n const tilt = useTransform(progress, [0, 1], [-10, 0]);\n const stretch = useTransform(progress, [0, 0.55, 1], [0.68, 1.1, 0.92]);\n const ready = status === \"ready\";\n const refreshing = status === \"refreshing\";\n\n return (\n <motion.span\n style={reduce ? undefined : { y: lift, rotate: tilt, scaleY: stretch }}\n className=\"block h-9 w-9 origin-bottom\"\n >\n <motion.svg\n aria-hidden=\"true\"\n viewBox=\"0 0 36 36\"\n style={{ opacity: 1 }}\n className=\"h-full w-full overflow-visible\"\n animate={\n refreshing\n ? reduce\n ? { opacity: [0.55, 1, 0.55] }\n : { y: [0, -2, 0], rotate: [-3, 3, -3] }\n : reduce\n ? { opacity: 1 }\n : { y: 0, rotate: 0, scale: ready ? 1.08 : 1 }\n }\n transition={refreshing ? (reduce ? CALM_PULSE : CHARACTER_LOOP) : SPRING_SWAP}\n >\n <motion.g\n style={{ transformOrigin: \"18px 18px\" }}\n animate={\n refreshing && !reduce\n ? { rotate: [0, 360] }\n : reduce\n ? undefined\n : { rotate: ready ? 0 : -35 }\n }\n transition={refreshing ? (reduce ? CALM_PULSE : CHARACTER_LOOP) : SPRING_SWAP}\n className={cn(\n \"transition-opacity duration-150\",\n ready || refreshing ? \"opacity-100\" : \"opacity-0\",\n )}\n >\n <path\n d=\"M18 2.5a15.5 15.5 0 0 1 12.7 6.6\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"1.5\"\n strokeLinecap=\"round\"\n className=\"text-muted-foreground\"\n />\n <circle cx=\"31.3\" cy=\"10.2\" r=\"2.2\" className=\"fill-foreground\" />\n </motion.g>\n\n <rect x=\"7\" y=\"7\" width=\"22\" height=\"22\" rx=\"9\" className=\"fill-foreground\" />\n\n <motion.g\n style={{ opacity: 1, transformOrigin: \"18px 16px\" }}\n animate={\n refreshing && !reduce\n ? { scaleY: [1, 1, 0.15, 1, 1] }\n : reduce\n ? { opacity: 1 }\n : { scaleY: ready ? 1.18 : 1 }\n }\n transition={refreshing && !reduce ? CHARACTER_LOOP : SPRING_SWAP}\n >\n <circle cx=\"14.2\" cy=\"16\" r=\"1.45\" className=\"fill-background\" />\n <circle cx=\"21.8\" cy=\"16\" r=\"1.45\" className=\"fill-background\" />\n </motion.g>\n\n <path\n d=\"M14.5 21h7\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"1.5\"\n strokeLinecap=\"round\"\n className={cn(\n \"text-background transition-opacity duration-150\",\n ready || refreshing ? \"opacity-0\" : \"opacity-100\",\n )}\n />\n <path\n d=\"M14 20.5c1 2.4 7 2.4 8 0\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"1.5\"\n strokeLinecap=\"round\"\n className={cn(\n \"text-background transition-opacity duration-150\",\n ready ? \"opacity-100\" : \"opacity-0\",\n )}\n />\n <circle\n cx=\"18\"\n cy=\"21\"\n r=\"1.6\"\n className={cn(\n \"fill-background transition-opacity duration-150\",\n refreshing ? \"opacity-100\" : \"opacity-0\",\n )}\n />\n </motion.svg>\n </motion.span>\n );\n}\n\nexport function PullToRefresh({\n onRefresh,\n children,\n refreshing = false,\n disabled = false,\n threshold = 76,\n maxPull = 132,\n holdDistance = 68,\n pullingLabel = \"Pull to refresh\",\n releaseLabel = \"Release to refresh\",\n refreshingLabel = \"Refreshing\",\n ariaLabel = \"Refreshable content\",\n className,\n contentClassName,\n indicatorClassName,\n}: PullToRefreshProps) {\n const rootRef = useRef<HTMLElement>(null);\n const gestureRef = useRef<Gesture>({ ...EMPTY_GESTURE });\n const animationRef = useRef<{ stop: () => void } | null>(null);\n const statusRef = useRef<PullToRefreshStatus>(\"idle\");\n const disabledRef = useRef(disabled);\n const externalRefreshingRef = useRef(refreshing);\n const refreshingRef = useRef(refreshing);\n const [status, setStatusState] = useState<PullToRefreshStatus>(\"idle\");\n const [internalRefreshing, setInternalRefreshing] = useState(false);\n const reduce = useReducedMotion();\n const pullThreshold = Math.max(24, threshold);\n const pullLimit = Math.max(maxPull, pullThreshold + 24);\n const restingDistance = Math.min(Math.max(0, holdDistance), pullThreshold);\n const y = useMotionValue(0);\n const progress = useTransform(y, [0, pullThreshold], [0, 1]);\n const indicatorOpacity = useTransform(y, [0, 10, pullThreshold], [0, 0.45, 1]);\n const indicatorScale = useTransform(y, [0, pullThreshold], [0.86, 1]);\n const isRefreshing = refreshing || internalRefreshing;\n\n disabledRef.current = disabled;\n externalRefreshingRef.current = refreshing;\n refreshingRef.current = isRefreshing;\n\n const setStatus = useCallback((next: PullToRefreshStatus) => {\n if (statusRef.current === next) return;\n statusRef.current = next;\n setStatusState(next);\n }, []);\n\n const settle = useCallback(\n (target: number) => {\n animationRef.current?.stop();\n\n if (reduce) {\n y.set(target);\n return;\n }\n\n animationRef.current = animate(y, target, SPRING_PANEL);\n },\n [reduce, y],\n );\n\n const updatePull = useCallback(\n (distance: number) => {\n if (disabledRef.current || refreshingRef.current) return;\n animationRef.current?.stop();\n\n const next = resistedDistance(distance, pullLimit);\n y.set(next);\n setStatus(next >= pullThreshold ? \"ready\" : \"pulling\");\n },\n [pullLimit, pullThreshold, setStatus, y],\n );\n\n const runRefresh = useCallback(async () => {\n if (disabledRef.current || refreshingRef.current) return;\n\n setInternalRefreshing(true);\n setStatus(\"refreshing\");\n settle(restingDistance);\n\n try {\n await onRefresh();\n } finally {\n setInternalRefreshing(false);\n\n // A synchronous refresh can resolve before React commits the temporary\n // internal state, so release here instead of relying only on the effect.\n if (!externalRefreshingRef.current) {\n setStatus(\"idle\");\n settle(0);\n }\n }\n }, [onRefresh, restingDistance, setStatus, settle]);\n\n const finishPull = useCallback(() => {\n const shouldRefresh =\n y.get() >= pullThreshold && !disabledRef.current && !refreshingRef.current;\n\n gestureRef.current = { ...EMPTY_GESTURE };\n\n if (shouldRefresh) {\n void runRefresh();\n return;\n }\n\n setStatus(\"idle\");\n settle(0);\n }, [pullThreshold, runRefresh, setStatus, settle, y]);\n\n useEffect(() => {\n if (isRefreshing) {\n setStatus(\"refreshing\");\n settle(restingDistance);\n return;\n }\n\n if (statusRef.current === \"refreshing\") {\n setStatus(\"idle\");\n settle(0);\n }\n }, [isRefreshing, restingDistance, setStatus, settle]);\n\n useEffect(() => {\n const root = rootRef.current;\n if (!root) return;\n\n const onTouchStart = (event: TouchEvent) => {\n if (\n event.touches.length !== 1 ||\n root.scrollTop > 0 ||\n disabledRef.current ||\n refreshingRef.current\n ) {\n return;\n }\n\n const touch = event.touches[0];\n gestureRef.current = {\n active: true,\n startX: touch.clientX,\n startY: touch.clientY,\n pointerId: null,\n };\n };\n\n const onTouchMove = (event: TouchEvent) => {\n const gesture = gestureRef.current;\n const touch = event.touches[0];\n if (!gesture.active || !touch) return;\n\n const deltaX = touch.clientX - gesture.startX;\n const deltaY = touch.clientY - gesture.startY;\n\n if (root.scrollTop > 0 || deltaY < 0) {\n gestureRef.current = { ...EMPTY_GESTURE };\n return;\n }\n\n if (Math.abs(deltaX) > deltaY) return;\n\n event.preventDefault();\n updatePull(deltaY);\n };\n\n const onTouchEnd = () => {\n if (gestureRef.current.active) finishPull();\n };\n\n root.addEventListener(\"touchstart\", onTouchStart, { passive: true });\n root.addEventListener(\"touchmove\", onTouchMove, { passive: false });\n root.addEventListener(\"touchend\", onTouchEnd);\n root.addEventListener(\"touchcancel\", onTouchEnd);\n\n return () => {\n root.removeEventListener(\"touchstart\", onTouchStart);\n root.removeEventListener(\"touchmove\", onTouchMove);\n root.removeEventListener(\"touchend\", onTouchEnd);\n root.removeEventListener(\"touchcancel\", onTouchEnd);\n };\n }, [finishPull, updatePull]);\n\n useEffect(() => {\n return () => animationRef.current?.stop();\n }, []);\n\n const startPointerPull = (event: ReactPointerEvent<HTMLElement>) => {\n // Everything but touch: a finger is driven by the native listeners above,\n // which can `preventDefault` the page scroll a passive React handler\n // cannot. A pen fires no touch events at all, so this is its only route.\n if (\n event.pointerType === \"touch\" ||\n event.button !== 0 ||\n event.currentTarget.scrollTop > 0 ||\n disabled ||\n isRefreshing\n ) {\n return;\n }\n\n capturePointer(event.currentTarget, event.pointerId);\n gestureRef.current = {\n active: true,\n startX: event.clientX,\n startY: event.clientY,\n pointerId: event.pointerId,\n };\n };\n\n const movePointerPull = (event: ReactPointerEvent<HTMLElement>) => {\n const gesture = gestureRef.current;\n if (!gesture.active || gesture.pointerId !== event.pointerId) return;\n\n const deltaX = event.clientX - gesture.startX;\n const deltaY = event.clientY - gesture.startY;\n if (deltaY < 0 || Math.abs(deltaX) > deltaY) return;\n\n event.preventDefault();\n updatePull(deltaY);\n };\n\n const label =\n status === \"refreshing\" ? refreshingLabel : status === \"ready\" ? releaseLabel : pullingLabel;\n\n return (\n <section\n ref={rootRef}\n aria-label={ariaLabel}\n aria-busy={isRefreshing}\n data-state={status}\n data-disabled={disabled || undefined}\n onPointerDown={startPointerPull}\n onPointerMove={movePointerPull}\n onPointerUp={(event) => {\n if (gestureRef.current.pointerId === event.pointerId) finishPull();\n }}\n onPointerCancel={(event) => {\n if (gestureRef.current.pointerId === event.pointerId) finishPull();\n }}\n className={cn(\n \"relative w-full overflow-y-auto overscroll-contain bg-background\",\n // No `touch-none` here — this element is the scroller, and the pull\n // only takes over once the content is already at the top. The callout\n // has to be off from the first frame though: iOS decides on it while\n // the finger is still resting, long before the pull is recognised.\n // Whatever the consumer renders inside stays selectable with a mouse;\n // only the pull itself suppresses selection, and only while it runs,\n // so dragging the page down cannot highlight it on the way.\n TOUCH_GESTURE_CONTENT_CLASS,\n status === \"pulling\" || status === \"ready\" ? \"cursor-grabbing select-none\" : \"cursor-grab\",\n (disabled || isRefreshing) && \"cursor-default\",\n className,\n )}\n >\n <motion.div\n aria-live=\"polite\"\n aria-atomic=\"true\"\n style={\n reduce\n ? { opacity: indicatorOpacity }\n : { opacity: indicatorOpacity, scale: indicatorScale }\n }\n className={cn(\n \"pointer-events-none absolute inset-x-0 top-0 z-20 flex h-[4.25rem] flex-col items-center justify-center gap-0.5 bg-linear-to-b from-background via-background/95 to-transparent font-medium text-[11px] text-muted-foreground\",\n indicatorClassName,\n )}\n >\n <RefreshBuddy progress={progress} status={status} reduce={Boolean(reduce)} />\n <span className=\"relative h-4 min-w-24 text-center\">\n <AnimatePresence initial={false} mode=\"wait\">\n <motion.span\n key={status}\n initial={reduce ? { opacity: 0 } : { opacity: 0, y: 3 }}\n animate={reduce ? { opacity: 1 } : { opacity: 1, y: 0 }}\n exit={reduce ? { opacity: 0 } : { opacity: 0, y: -3 }}\n transition={LABEL_SWAP}\n className=\"absolute inset-x-0 whitespace-nowrap\"\n >\n {label}\n </motion.span>\n </AnimatePresence>\n </span>\n </motion.div>\n\n <motion.div\n style={reduce ? undefined : { y }}\n className={cn(\n \"relative z-10 min-h-full bg-inherit will-change-transform\",\n contentClassName,\n )}\n >\n {children}\n </motion.div>\n </section>\n );\n}\n"],"mappings":";;;;;;;;AAuDA,MAAM,gBAAyB;CAC7B,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,WAAW;AACb;AAIA,MAAM,iBAAiB;CACrB,UAAU;CACV,MAAM;CACN,QAAQ,OAAO;AACjB;AACA,MAAM,aAAa;CACjB,UAAU;CACV,MAAM;CACN,QAAQ,OAAO;AACjB;AACA,MAAM,aAAa;CAAE,UAAU;CAAM,MAAM;AAAS;AAEpD,SAAS,iBAAiB,UAAkB,SAAiB;CAC3D,OAAO,WAAW,IAAI,KAAK,IAAI,CAAC,KAAK,IAAI,GAAG,QAAQ,IAAI,OAAO;AACjE;AAEA,SAAS,aAAa,EACpB,UACA,QACA,UAKC;CACD,MAAM,OAAO,aAAa,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;CACnD,MAAM,OAAO,aAAa,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;CACpD,MAAM,UAAU,aAAa,UAAU;EAAC;EAAG;EAAM;CAAC,GAAG;EAAC;EAAM;EAAK;CAAI,CAAC;CACtE,MAAM,QAAQ,WAAW;CACzB,MAAM,aAAa,WAAW;CAE9B,OACE,oBAAC,OAAO,MAAR;EACE,OAAO,SAAS,KAAA,IAAY;GAAE,GAAG;GAAM,QAAQ;GAAM,QAAQ;EAAQ;EACrE,WAAU;EAEV,UAAA,qBAAC,OAAO,KAAR;GACE,eAAY;GACZ,SAAQ;GACR,OAAO,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AAW,aAAa,WAAW,UAAU,gCAAgC,gBAC5E,YAAY,iBAAiB,kBAC9B,SACF;EA3BF,UAAA,CA6BE,qBAAC,OAAO,KAAR;GACE,aAAU;GACV,eAAY;GACZ,OACE,SACI,EAAE,SAAS,iBAAiB,IAC5B;IAAE,SAAS;IAAkB,OAAO;GAAe;GAEzD,WAAW,GACT,iOACA,kBACF;GAXF,UAAA,CAaE,oBAAC,cAAD;IAAwB;IAAkB;IAAQ,QAAQ,QAAQ,MAAM;GAAI,CAAA,GAC5E,oBAAC,QAAD;IAAM,WAAU;IACd,UAAA,oBAAC,iBAAD;KAAiB,SAAS;KAAO,MAAK;KACpC,UAAA,oBAAC,OAAO,MAAR;MAEE,SAAS,SAAS,EAAE,SAAS,EAAE,IAAI;OAAE,SAAS;OAAG,GAAG;MAAE;MACtD,SAAS,SAAS,EAAE,SAAS,EAAE,IAAI;OAAE,SAAS;OAAG,GAAG;MAAE;MACtD,MAAM,SAAS,EAAE,SAAS,EAAE,IAAI;OAAE,SAAS;OAAG,GAAG;MAAG;MACpD,YAAY;MACZ,WAAU;MAET,UAAA;KACU,GARN,MAQM;IACE,CAAA;GACb,CAAA,CACI;EAEZ,CAAA,GAAA,oBAAC,OAAO,KAAR;GACE,OAAO,SAAS,KAAA,IAAY,EAAE,EAAE;GAChC,WAAW,GACT,6DACA,gBACF;GAEC;EACS,CAAA,CACL;;AAEb"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"range-slider-bubble.d.ts","names":[],"sources":["../../../src/components/motion/range-slider-bubble.tsx"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"range-slider-bubble.d.ts","names":[],"sources":["../../../src/components/motion/range-slider-bubble.tsx"],"mappings":";;UAwBiB,0BAA0B;;EAEzC,UAAU;EACV;;;;;;;iBAQc,eAAe,QAAQ,cAAc,WAAW,oCAAiB,IAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { TOUCH_GESTURE_CLASS } from "../../lib/touch.js";
|
|
2
3
|
import { useSlider } from "../../hooks/use-slider.js";
|
|
3
4
|
import { SPRING_GLIDE, SPRING_PANEL, SPRING_PRESS } from "../../lib/ease.js";
|
|
4
5
|
import { useEffect } from "react";
|
|
@@ -49,7 +50,7 @@ function BubbleSlider({ format, className, ...options }) {
|
|
|
49
50
|
className: cn("relative flex h-20 w-full items-end px-5 pb-5", options.disabled ? "pointer-events-none opacity-50" : void 0, className),
|
|
50
51
|
children: /* @__PURE__ */ jsxs("div", {
|
|
51
52
|
...trackProps,
|
|
52
|
-
className: cn("relative h-2 w-full touch-none
|
|
53
|
+
className: cn("relative h-2 w-full touch-none rounded-full bg-muted", TOUCH_GESTURE_CLASS, options.disabled ? void 0 : "cursor-grab active:cursor-grabbing"),
|
|
53
54
|
children: [
|
|
54
55
|
/* @__PURE__ */ jsx(motion.div, {
|
|
55
56
|
className: "absolute inset-y-0 left-0 rounded-full bg-foreground",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"range-slider-bubble.js","names":[],"sources":["../../../src/components/motion/range-slider-bubble.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect } from \"react\";\nimport {\n AnimatePresence,\n motion,\n useMotionTemplate,\n useMotionValue,\n useReducedMotion,\n useSpring,\n useTransform,\n useVelocity,\n} from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { type SliderOptions, useSlider } from \"../../hooks/use-slider\";\nimport { SPRING_GLIDE, SPRING_PANEL, SPRING_PRESS } from \"../../lib/ease\";\n\n// Loose enough that the bubble keeps leaning a beat after the pointer stops.\nconst SPRING_TILT = { stiffness: 260, damping: 22, mass: 0.4 } as const;\n/** Drag speed (px/s of track percent) that maxes out lean and squash. */\nconst FULL_TILT = 320;\n\nexport interface BubbleSliderProps extends SliderOptions {\n /** Formats the value shown in the bubble. */\n format?: (value: number) => string;\n className?: string;\n}\n\n/**\n * Slider with a value bubble that pops out of the thumb on grab and reacts to\n * how fast you drag: it leans into the direction of travel and squashes along\n * the way, then settles upright when you let go.\n */\nexport function BubbleSlider({ format, className, ...options }: BubbleSliderProps) {\n const reduce = useReducedMotion();\n // A bare number needs no valueText — it would only repeat aria-valuenow.\n const { percent, current, dragging, trackProps, sliderProps } = useSlider({\n ...options,\n formatValueText: options.formatValueText ?? format,\n });\n // The value is already snapped to the step — rounding here would only make\n // the bubble disagree with aria-valuenow on a fractional scale.\n const readout = format ? format(current) : current;\n\n const target = useMotionValue(percent);\n useEffect(() => {\n target.set(percent);\n }, [percent, target]);\n const smooth = useSpring(target, SPRING_GLIDE);\n const pos = reduce ? target : smooth;\n const left = useMotionTemplate`${pos}%`;\n\n // One spring drives the whole reaction: lean is signed, squash reads its\n // magnitude. Two springs off the same velocity would just run twice.\n const velocity = useVelocity(pos);\n const lean = useSpring(\n useTransform(velocity, [-FULL_TILT, 0, FULL_TILT], [1, 0, -1], { clamp: true }),\n SPRING_TILT,\n );\n const tilt = useTransform(lean, (v) => v * 16);\n const squash = useTransform(lean, (v) => 1 + Math.abs(v) * 0.18);\n const stretch = useTransform(lean, (v) => 1 - Math.abs(v) * 0.12);\n\n return (\n <div\n className={cn(\n // px/pb leave room for the thumb, the bubble and the 48px hit area to\n // overhang the 8px track without escaping the component's own box\n \"relative flex h-20 w-full items-end px-5 pb-5\",\n options.disabled ? \"pointer-events-none opacity-50\" : undefined,\n className,\n )}\n >\n <div\n {...trackProps}\n className={cn(\n \"relative h-2 w-full touch-none
|
|
1
|
+
{"version":3,"file":"range-slider-bubble.js","names":[],"sources":["../../../src/components/motion/range-slider-bubble.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect } from \"react\";\nimport {\n AnimatePresence,\n motion,\n useMotionTemplate,\n useMotionValue,\n useReducedMotion,\n useSpring,\n useTransform,\n useVelocity,\n} from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { type SliderOptions, useSlider } from \"../../hooks/use-slider\";\nimport { SPRING_GLIDE, SPRING_PANEL, SPRING_PRESS } from \"../../lib/ease\";\nimport { TOUCH_GESTURE_CLASS } from \"../../lib/touch\";\n\n// Loose enough that the bubble keeps leaning a beat after the pointer stops.\nconst SPRING_TILT = { stiffness: 260, damping: 22, mass: 0.4 } as const;\n/** Drag speed (px/s of track percent) that maxes out lean and squash. */\nconst FULL_TILT = 320;\n\nexport interface BubbleSliderProps extends SliderOptions {\n /** Formats the value shown in the bubble. */\n format?: (value: number) => string;\n className?: string;\n}\n\n/**\n * Slider with a value bubble that pops out of the thumb on grab and reacts to\n * how fast you drag: it leans into the direction of travel and squashes along\n * the way, then settles upright when you let go.\n */\nexport function BubbleSlider({ format, className, ...options }: BubbleSliderProps) {\n const reduce = useReducedMotion();\n // A bare number needs no valueText — it would only repeat aria-valuenow.\n const { percent, current, dragging, trackProps, sliderProps } = useSlider({\n ...options,\n formatValueText: options.formatValueText ?? format,\n });\n // The value is already snapped to the step — rounding here would only make\n // the bubble disagree with aria-valuenow on a fractional scale.\n const readout = format ? format(current) : current;\n\n const target = useMotionValue(percent);\n useEffect(() => {\n target.set(percent);\n }, [percent, target]);\n const smooth = useSpring(target, SPRING_GLIDE);\n const pos = reduce ? target : smooth;\n const left = useMotionTemplate`${pos}%`;\n\n // One spring drives the whole reaction: lean is signed, squash reads its\n // magnitude. Two springs off the same velocity would just run twice.\n const velocity = useVelocity(pos);\n const lean = useSpring(\n useTransform(velocity, [-FULL_TILT, 0, FULL_TILT], [1, 0, -1], { clamp: true }),\n SPRING_TILT,\n );\n const tilt = useTransform(lean, (v) => v * 16);\n const squash = useTransform(lean, (v) => 1 + Math.abs(v) * 0.18);\n const stretch = useTransform(lean, (v) => 1 - Math.abs(v) * 0.12);\n\n return (\n <div\n className={cn(\n // px/pb leave room for the thumb, the bubble and the 48px hit area to\n // overhang the 8px track without escaping the component's own box\n \"relative flex h-20 w-full items-end px-5 pb-5\",\n options.disabled ? \"pointer-events-none opacity-50\" : undefined,\n className,\n )}\n >\n <div\n {...trackProps}\n className={cn(\n \"relative h-2 w-full touch-none rounded-full bg-muted\",\n TOUCH_GESTURE_CLASS,\n options.disabled ? undefined : \"cursor-grab active:cursor-grabbing\",\n )}\n >\n <motion.div\n className=\"absolute inset-y-0 left-0 rounded-full bg-foreground\"\n style={{ width: left }}\n />\n\n {/* thumb — overhangs the track by half its width at both ends, which the\n wrapper's padding leaves room for */}\n <motion.div\n className=\"absolute top-1/2 size-5 rounded-full border-2 border-foreground bg-background shadow-sm\"\n style={{ left, x: \"-50%\", y: \"-50%\" }}\n animate={reduce ? undefined : { scale: dragging ? 1.25 : 1 }}\n transition={SPRING_PRESS}\n />\n\n {/* bubble — anchored to the thumb, leaning with drag velocity */}\n <motion.div className=\"pointer-events-none absolute bottom-6\" style={{ left, x: \"-50%\" }}>\n <AnimatePresence>\n {dragging ? (\n <motion.div\n initial={reduce ? { opacity: 0 } : { opacity: 0, scale: 0.4, y: 10 }}\n animate={reduce ? { opacity: 1 } : { opacity: 1, scale: 1, y: 0 }}\n exit={\n reduce\n ? { opacity: 0, transition: { duration: 0.12 } }\n : { opacity: 0, scale: 0.5, y: 8, transition: { duration: 0.12 } }\n }\n transition={reduce ? { duration: 0.12 } : SPRING_PANEL}\n style={\n reduce ? undefined : { rotate: tilt, scaleX: squash, scaleY: stretch, originY: 1 }\n }\n className=\"relative rounded-xl bg-foreground px-2.5 py-1 font-medium text-background text-sm tabular-nums shadow-md\"\n >\n {readout}\n <span className=\"absolute -bottom-1 left-1/2 size-2.5 -translate-x-1/2 rotate-45 rounded-[3px] bg-foreground\" />\n </motion.div>\n ) : null}\n </AnimatePresence>\n </motion.div>\n\n {/* 8px of track is not a touch target — pad the hit area out to 48px */}\n <button\n type=\"button\"\n {...sliderProps}\n className=\"absolute inset-x-0 -inset-y-5 touch-none rounded-full outline-none ring-foreground/30 focus-visible:ring-4\"\n />\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;AAoBA,MAAM,cAAc;CAAE,WAAW;CAAK,SAAS;CAAI,MAAM;AAAI;;AAE7D,M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;KAC3D,YAAY;IACb,CAAA;IAGD,oBAAC,OAAO,KAAR;KAAY,WAAU;KAAwC,OAAO;MAAE;MAAM,GAAG;KAAO;KACrF,UAAA,oBAAC,iBAAD,EAAA,UACG,WACC,qBAAC,OAAO,KAAR;MACE,SAAS,SAAS,EAAE,SAAS,EAAE,IAAI;OAAE,SAAS;OAAG,OAAO;OAAK,GAAG;MAAG;MACnE,SAAS,SAAS,EAAE,SAAS,EAAE,IAAI;OAAE,SAAS;OAAG,OAAO;OAAG,GAAG;MAAE;MAChE,MACE,SACI;OAAE,SAAS;OAAG,YAAY,EAAE,UAAU,IAAK;MAAE,IAC7C;OAAE,SAAS;OAAG,OAAO;OAAK,GAAG;OAAG,YAAY,EAAE,UAAU,IAAK;MAAE;MAErE,YAAY,SAAS,EAAE,UAAU,IAAK,IAAI;MAC1C,OACE,SAAS,KAAA,IAAY;OAAE,QAAQ;OAAM,QAAQ;OAAQ,QAAQ;OAAS,SAAS;MAAE;MAEnF,WAAU;MAZZ,UAAA,CAcG,SACD,oBAAC,QAAD,EAAM,WAAU,8FAA+F,CAAA,CACrG;KACV,CAAA,IAAA,KACW,CAAA;IACP,CAAA;IAGZ,oBAAC,UAAD;KACE,MAAK;KACL,GAAI;KACJ,WAAU;IACX,CAAA;GACE;;CACF,CAAA;AAET"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"range-slider-fluid.d.ts","names":[],"sources":["../../../src/components/motion/range-slider-fluid.tsx"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"range-slider-fluid.d.ts","names":[],"sources":["../../../src/components/motion/range-slider-fluid.tsx"],"mappings":";;UAiBiB,yBAAyB;;EAExC;;EAEA,UAAU;EACV;;;;;;;iBAQc,cACd,OAGA,QACA,cACG,WACF,mCAAgB,IAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { TOUCH_GESTURE_CLASS } from "../../lib/touch.js";
|
|
2
3
|
import { useSlider } from "../../hooks/use-slider.js";
|
|
3
4
|
import { SPRING_GLIDE, SPRING_PRESS } from "../../lib/ease.js";
|
|
4
5
|
import { useEffect } from "react";
|
|
@@ -35,7 +36,7 @@ function FluidSlider({ label, format = (v) => `${v}%`, className, ...options })
|
|
|
35
36
|
...trackProps,
|
|
36
37
|
animate: reduce ? void 0 : { scale: dragging ? 1.03 : 1 },
|
|
37
38
|
transition: SPRING_PRESS,
|
|
38
|
-
className: cn("relative flex h-12 w-full touch-none
|
|
39
|
+
className: cn("relative flex h-12 w-full touch-none overflow-hidden rounded-full bg-muted", TOUCH_GESTURE_CLASS, options.disabled ? "pointer-events-none opacity-50" : "cursor-grab active:cursor-grabbing", className),
|
|
39
40
|
children: [
|
|
40
41
|
/* @__PURE__ */ jsx("div", {
|
|
41
42
|
className: "pointer-events-none absolute inset-0 flex items-center justify-between px-5 font-medium text-foreground text-sm",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"range-slider-fluid.js","names":[],"sources":["../../../src/components/motion/range-slider-fluid.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect } from \"react\";\nimport {\n motion,\n useMotionTemplate,\n useMotionValue,\n useReducedMotion,\n useSpring,\n useTransform,\n} from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { type SliderOptions, useSlider } from \"../../hooks/use-slider\";\nimport { SPRING_GLIDE, SPRING_PRESS } from \"../../lib/ease\";\n\nexport interface FluidSliderProps extends SliderOptions {\n /** Text shown on the left of the track. */\n label?: string;\n /** Formats the value shown on the right. */\n format?: (value: number) => string;\n className?: string;\n}\n\n/**\n * Thumbless slider: the whole pill is the control. The fill glides to the new\n * value behind a rounded liquid cap, and the label reads inverted wherever the\n * fill has covered it.\n */\nexport function FluidSlider({\n label,\n // The value arrives already snapped to the step. Rounding it again would\n // only make the label and the announcement disagree with aria-valuenow.\n format = (v) => `${v}%`,\n className,\n ...options\n}: FluidSliderProps) {\n const reduce = useReducedMotion();\n const { percent, current, dragging, trackProps, sliderProps } = useSlider({\n ...options,\n formatValueText: options.formatValueText ?? format,\n });\n\n const target = useMotionValue(percent);\n useEffect(() => {\n target.set(percent);\n }, [percent, target]);\n const smooth = useSpring(target, SPRING_GLIDE);\n const pos = reduce ? target : smooth;\n // Reveal the fill by clipping a full-width layer rather than animating its\n // width: at 0% the clip is empty, so no hairline of a sub-pixel-wide box is\n // left behind, and the label inside is never scaled or re-laid out.\n const uncovered = useTransform(pos, (v) => 100 - v);\n const clipPath = useMotionTemplate`inset(0 ${uncovered}% 0 0 round 9999px)`;\n\n const row = (\n <>\n {label ? <span className=\"truncate\">{label}</span> : <span />}\n <span className=\"tabular-nums\">{format(current)}</span>\n </>\n );\n\n return (\n <motion.div\n {...trackProps}\n animate={reduce ? undefined : { scale: dragging ? 1.03 : 1 }}\n transition={SPRING_PRESS}\n className={cn(\n \"relative flex h-12 w-full touch-none
|
|
1
|
+
{"version":3,"file":"range-slider-fluid.js","names":[],"sources":["../../../src/components/motion/range-slider-fluid.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect } from \"react\";\nimport {\n motion,\n useMotionTemplate,\n useMotionValue,\n useReducedMotion,\n useSpring,\n useTransform,\n} from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { type SliderOptions, useSlider } from \"../../hooks/use-slider\";\nimport { SPRING_GLIDE, SPRING_PRESS } from \"../../lib/ease\";\nimport { TOUCH_GESTURE_CLASS } from \"../../lib/touch\";\n\nexport interface FluidSliderProps extends SliderOptions {\n /** Text shown on the left of the track. */\n label?: string;\n /** Formats the value shown on the right. */\n format?: (value: number) => string;\n className?: string;\n}\n\n/**\n * Thumbless slider: the whole pill is the control. The fill glides to the new\n * value behind a rounded liquid cap, and the label reads inverted wherever the\n * fill has covered it.\n */\nexport function FluidSlider({\n label,\n // The value arrives already snapped to the step. Rounding it again would\n // only make the label and the announcement disagree with aria-valuenow.\n format = (v) => `${v}%`,\n className,\n ...options\n}: FluidSliderProps) {\n const reduce = useReducedMotion();\n const { percent, current, dragging, trackProps, sliderProps } = useSlider({\n ...options,\n formatValueText: options.formatValueText ?? format,\n });\n\n const target = useMotionValue(percent);\n useEffect(() => {\n target.set(percent);\n }, [percent, target]);\n const smooth = useSpring(target, SPRING_GLIDE);\n const pos = reduce ? target : smooth;\n // Reveal the fill by clipping a full-width layer rather than animating its\n // width: at 0% the clip is empty, so no hairline of a sub-pixel-wide box is\n // left behind, and the label inside is never scaled or re-laid out.\n const uncovered = useTransform(pos, (v) => 100 - v);\n const clipPath = useMotionTemplate`inset(0 ${uncovered}% 0 0 round 9999px)`;\n\n const row = (\n <>\n {label ? <span className=\"truncate\">{label}</span> : <span />}\n <span className=\"tabular-nums\">{format(current)}</span>\n </>\n );\n\n return (\n <motion.div\n {...trackProps}\n animate={reduce ? undefined : { scale: dragging ? 1.03 : 1 }}\n transition={SPRING_PRESS}\n className={cn(\n \"relative flex h-12 w-full touch-none overflow-hidden rounded-full bg-muted\",\n TOUCH_GESTURE_CLASS,\n options.disabled ? \"pointer-events-none opacity-50\" : \"cursor-grab active:cursor-grabbing\",\n className,\n )}\n >\n {/* uncovered label — sits on the muted track */}\n <div className=\"pointer-events-none absolute inset-0 flex items-center justify-between px-5 font-medium text-foreground text-sm\">\n {row}\n </div>\n\n {/* fill + the same label, both clipped to the value, so the text inverts\n as the fill covers it and lines up glyph for glyph with the copy\n underneath. The clip's rounded right edge is the liquid cap. */}\n <motion.div className=\"absolute inset-0\" style={{ clipPath }}>\n <div className=\"absolute inset-0 bg-foreground\" />\n <div className=\"pointer-events-none absolute inset-0 flex items-center justify-between px-5 font-medium text-background text-sm\">\n {row}\n </div>\n </motion.div>\n\n {/* focusable, keyboard-controlled handle surface. The ring is inset — an\n outset one is clipped away by the track's overflow-hidden. */}\n <button\n type=\"button\"\n {...sliderProps}\n className=\"absolute inset-0 touch-none rounded-full outline-none ring-foreground/40 ring-inset focus-visible:ring-4\"\n />\n </motion.div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;AA8BA,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ruler.d.ts","names":[],"sources":["../../../src/components/motion/range-slider-ruler.tsx"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"range-slider-ruler.d.ts","names":[],"sources":["../../../src/components/motion/range-slider-ruler.tsx"],"mappings":";;UAkBiB,yBAAyB;;EAExC;;EAEA;;EAEA;EACA;;;;;;iBAOc,cACd,KACA,YACA,MACA,cACG,WACF,mCAAgB,IAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { TOUCH_GESTURE_CLASS } from "../../lib/touch.js";
|
|
2
3
|
import { snapSliderValue, useSlider } from "../../hooks/use-slider.js";
|
|
3
4
|
import { useEffect, useRef } from "react";
|
|
4
5
|
import { cn } from "@kumix/utils";
|
|
@@ -79,7 +80,7 @@ function RulerSlider({ gap = 14, majorEvery = 5, unit, className, ...options })
|
|
|
79
80
|
});
|
|
80
81
|
return /* @__PURE__ */ jsxs("div", {
|
|
81
82
|
...rootProps,
|
|
82
|
-
className: cn("relative w-full touch-none
|
|
83
|
+
className: cn("relative w-full touch-none overflow-hidden", TOUCH_GESTURE_CLASS, options.disabled ? "pointer-events-none opacity-50" : "cursor-grab active:cursor-grabbing", "rounded-2xl outline-none ring-foreground/30 focus-visible:ring-4", className),
|
|
83
84
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
84
85
|
className: "pointer-events-none flex items-baseline justify-center gap-1 pt-1 pb-3",
|
|
85
86
|
children: [/* @__PURE__ */ jsx("span", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"range-slider-ruler.js","names":[],"sources":["../../../src/components/motion/range-slider-ruler.tsx"],"sourcesContent":["\"use client\";\n\nimport { type KeyboardEvent, useEffect, useRef } from \"react\";\nimport {\n animate,\n motion,\n useMotionValue,\n useMotionValueEvent,\n useReducedMotion,\n} from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { type SliderOptions, snapSliderValue, useSlider } from \"../../hooks/use-slider\";\n\n// Settle spring for the snap after a flick — quick, no overshoot past the tick.\nconst SPRING_SNAP = { type: \"spring\", stiffness: 500, damping: 40, mass: 0.6 } as const;\n\nexport interface RulerSliderProps extends SliderOptions {\n /** Pixels between two steps. */\n gap?: number;\n /** Label every Nth step; those ticks are drawn tall. */\n majorEvery?: number;\n /** Unit shown next to the value. */\n unit?: string;\n className?: string;\n}\n\n/**\n * Ruler slider: the scale scrolls under a fixed needle instead of a handle\n * moving along a track. Flicks carry momentum and settle onto the nearest tick.\n */\nexport function RulerSlider({\n gap = 14,\n majorEvery = 5,\n unit,\n className,\n ...options\n}: RulerSliderProps) {\n const reduce = useReducedMotion();\n // Decimal places the step implies, so 0.5 reads \"72.5\" and 1 reads \"72\".\n // Fixed width keeps the readout from jittering as the value rolls; tick\n // labels stay trimmed so a whole-number scale is not littered with \".0\".\n // ponytail: reads 0 decimals for an exponential step (1e-7) — no such scale\n // is legible on a ruler anyway, so no parsing beyond this.\n const decimals = String(options.step ?? 1).split(\".\")[1]?.length ?? 0;\n const readout = (value: number) => value.toFixed(decimals);\n\n const { current, min, max, step, commit, sliderProps } = useSlider({\n ...options,\n // \"72.5 kg\" beats a bare \"72.5\" for a screen reader — but a caller who\n // formats the announcement itself outranks the unit.\n formatValueText: options.formatValueText ?? (unit ? (v) => `${readout(v)} ${unit}` : undefined),\n });\n\n // The range need not divide by the step (0–10 by 4). Full ticks stop at the\n // last whole one and max gets a tick of its own, so the scale never runs past\n // the value the slider can actually report.\n const span = Number(((max - min) / step).toFixed(6));\n const wholeSteps = Math.floor(span);\n const remainder = span - wholeSteps;\n const maxOffset = span * gap;\n const x = useMotionValue(-((current - min) / step) * gap);\n // While the pointer drives the strip (or its momentum still runs), x owns the\n // value; outside of that the value owns x.\n const interacting = useRef(false);\n // True only while the pointer is down. It keeps a cancelled momentum's\n // transition end from snapping underneath a fresh grab.\n const holding = useRef(false);\n // A new gesture or key press bumps this, so a snap that resolves late cannot\n // clear interacting underneath an active drag.\n const gesture = useRef(0);\n\n // ponytail: every tick is in the DOM — fine to a few hundred (80 units at\n // step 0.5 is 161). Window to the visible span if a finer step is ever needed.\n // Each tick carries an offset because max sits `remainder` of a step past the\n // last whole tick. Whenever remainder is under 0.5 that point falls inside\n // the previous box, so an appended flex box can never centre on it.\n const ticks = Array.from({ length: wholeSteps + 1 }, (_, i) => ({\n // toFixed trims float dust from fractional steps (0.1 + 0.2 …).\n value: Number((min + i * step).toFixed(6)),\n major: i % majorEvery === 0,\n offset: i * gap,\n }));\n // A tiny remainder puts this label close to the one before it. That is what\n // a scale ending a hair past a step looks like.\n if (remainder > 0) ticks.push({ value: max, major: true, offset: maxOffset });\n\n const snapToTick = () => {\n // The same nearest-tick rule useSlider applies. max counts as a candidate\n // when the step does not divide the range, so a flick near the end does\n // not settle on the last whole step.\n const target = snapSliderValue(min + (-x.get() / gap) * step, min, max, step);\n const snapped = -((target - min) / step) * gap;\n const id = ++gesture.current;\n if (reduce) {\n x.set(snapped);\n interacting.current = false;\n return;\n }\n animate(x, snapped, SPRING_SNAP).then(() => {\n if (gesture.current === id) interacting.current = false;\n });\n };\n\n // A key press takes the scale back from momentum: without this the coasting\n // strip keeps committing its own value and swallows the keyboard input.\n const rootProps = {\n ...sliderProps,\n onKeyDown: (event: KeyboardEvent<HTMLDivElement>) => {\n x.stop();\n gesture.current++;\n interacting.current = false;\n holding.current = false;\n sliderProps.onKeyDown(event);\n },\n };\n\n useEffect(() => {\n if (interacting.current) return;\n x.set(-((current - min) / step) * gap);\n }, [current, min, step, gap, x]);\n\n useMotionValueEvent(x, \"change\", (v) => {\n if (!interacting.current) return;\n commit(min + (-v / gap) * step);\n });\n\n return (\n <div\n {...rootProps}\n className={cn(\n \"relative w-full touch-none select-none overflow-hidden\",\n options.disabled ? \"pointer-events-none opacity-50\" : \"cursor-grab active:cursor-grabbing\",\n \"rounded-2xl outline-none ring-foreground/30 focus-visible:ring-4\",\n className,\n )}\n >\n <div className=\"pointer-events-none flex items-baseline justify-center gap-1 pt-1 pb-3\">\n <span className=\"font-semibold text-3xl text-foreground tabular-nums\">\n {readout(current)}\n </span>\n {unit ? <span className=\"text-muted-foreground text-sm\">{unit}</span> : null}\n </div>\n\n {/* masked, not overlaid with background-coloured gradients — the fade has\n to work on any surface the slider is dropped onto */}\n <div className=\"mask-[linear-gradient(to_right,transparent,black_18%,black_82%,transparent)] relative h-12\">\n {/* strip — dragged directly, so momentum comes from the drag gesture */}\n <motion.div\n drag={options.disabled ? false : \"x\"}\n dragConstraints={{ left: -maxOffset, right: 0 }}\n dragElastic={0.03}\n dragMomentum={!reduce}\n dragTransition={{ power: 0.22, timeConstant: 320 }}\n onDragStart={() => {\n gesture.current++;\n interacting.current = true;\n holding.current = true;\n }}\n // Momentum end when there is momentum, drag end when there is not.\n onDragTransitionEnd={() => {\n if (!holding.current) snapToTick();\n }}\n onDragEnd={() => {\n holding.current = false;\n if (reduce) snapToTick();\n }}\n // The ticks are positioned rather than laid out, so the row needs an\n // explicit width plus half a gap of slop each side to cover the\n // whole drag surface.\n style={{ x, marginLeft: -gap / 2, width: maxOffset + gap }}\n className=\"absolute inset-y-0 left-1/2\"\n >\n {ticks.map((tick) => (\n // pb reserves the label row, so minor ticks need no spacer node\n <span\n key={tick.value}\n className=\"absolute bottom-0 flex -translate-x-1/2 flex-col items-center pb-[18px]\"\n style={{ left: tick.offset + gap / 2 }}\n >\n <span\n className={cn(\n \"w-px rounded-full\",\n // minor ticks at /45 clear the 3:1 non-text floor in both themes\n tick.major ? \"h-7 bg-foreground/70\" : \"h-3.5 bg-foreground/45\",\n )}\n />\n {tick.major ? (\n <span className=\"absolute bottom-0 text-[10px] text-muted-foreground tabular-nums\">\n {tick.value}\n </span>\n ) : null}\n </span>\n ))}\n </motion.div>\n\n {/* needle — the read head the scale moves under */}\n <div className=\"pointer-events-none absolute bottom-5 left-1/2 -translate-x-1/2\">\n <span className=\"block h-9 w-[3px] rounded-full bg-foreground\" />\n </div>\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;;;AAeA,MAAM,cAA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;IACnC;IACA,iBAAiB;KACf,QAAQ,UAAU;KAClB,IAAI,QAAQ,WAAW;IACzB;IAIA,OAAO;KAAE;KAAG,YAAY,CAAC,MAAM;KAAG,OAAO,YAAY;IAAI;IACzD,WAAU;IAET,UAAA,MAAM,KAAK,SAEV,qBAAC,QAAD;KAEE,WAAU;KACV,OAAO,EAAE,MAAM,KAAK,SAAS,MAAM,EAAE;KAHvC,UAAA,CAKE,oBAAC,QAAD,EACE,WAAW,GACT,qBAEA,KAAK,QAAQ,yBAAyB,wBACxC,EACD,CAAA,GACA,KAAK,QACJ,oBAAC,QAAD;MAAM,WAAU;MACb,UAAA,KAAK;KACF,CAAA,IACJ,IACA;IAhBC,GAAA,KAAK,KAgBN,CACP;GACS,CAAA,GAGZ,oBAAC,OAAD;IAAK,WAAU;IACb,UAAA,oBAAC,QAAD,EAAM,WAAU,+CAAgD,CAAA;GAC7D,CAAA,CACF;EACF,CAAA,CAAA;;AAET"}
|
|
1
|
+
{"version":3,"file":"range-slider-ruler.js","names":[],"sources":["../../../src/components/motion/range-slider-ruler.tsx"],"sourcesContent":["\"use client\";\n\nimport { type KeyboardEvent, useEffect, useRef } from \"react\";\nimport {\n animate,\n motion,\n useMotionValue,\n useMotionValueEvent,\n useReducedMotion,\n} from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { type SliderOptions, snapSliderValue, useSlider } from \"../../hooks/use-slider\";\nimport { TOUCH_GESTURE_CLASS } from \"../../lib/touch\";\n\n// Settle spring for the snap after a flick — quick, no overshoot past the tick.\nconst SPRING_SNAP = { type: \"spring\", stiffness: 500, damping: 40, mass: 0.6 } as const;\n\nexport interface RulerSliderProps extends SliderOptions {\n /** Pixels between two steps. */\n gap?: number;\n /** Label every Nth step; those ticks are drawn tall. */\n majorEvery?: number;\n /** Unit shown next to the value. */\n unit?: string;\n className?: string;\n}\n\n/**\n * Ruler slider: the scale scrolls under a fixed needle instead of a handle\n * moving along a track. Flicks carry momentum and settle onto the nearest tick.\n */\nexport function RulerSlider({\n gap = 14,\n majorEvery = 5,\n unit,\n className,\n ...options\n}: RulerSliderProps) {\n const reduce = useReducedMotion();\n // Decimal places the step implies, so 0.5 reads \"72.5\" and 1 reads \"72\".\n // Fixed width keeps the readout from jittering as the value rolls; tick\n // labels stay trimmed so a whole-number scale is not littered with \".0\".\n // ponytail: reads 0 decimals for an exponential step (1e-7) — no such scale\n // is legible on a ruler anyway, so no parsing beyond this.\n const decimals = String(options.step ?? 1).split(\".\")[1]?.length ?? 0;\n const readout = (value: number) => value.toFixed(decimals);\n\n const { current, min, max, step, commit, sliderProps } = useSlider({\n ...options,\n // \"72.5 kg\" beats a bare \"72.5\" for a screen reader — but a caller who\n // formats the announcement itself outranks the unit.\n formatValueText: options.formatValueText ?? (unit ? (v) => `${readout(v)} ${unit}` : undefined),\n });\n\n // The range need not divide by the step (0–10 by 4). Full ticks stop at the\n // last whole one and max gets a tick of its own, so the scale never runs past\n // the value the slider can actually report.\n const span = Number(((max - min) / step).toFixed(6));\n const wholeSteps = Math.floor(span);\n const remainder = span - wholeSteps;\n const maxOffset = span * gap;\n const x = useMotionValue(-((current - min) / step) * gap);\n // While the pointer drives the strip (or its momentum still runs), x owns the\n // value; outside of that the value owns x.\n const interacting = useRef(false);\n // True only while the pointer is down. It keeps a cancelled momentum's\n // transition end from snapping underneath a fresh grab.\n const holding = useRef(false);\n // A new gesture or key press bumps this, so a snap that resolves late cannot\n // clear interacting underneath an active drag.\n const gesture = useRef(0);\n\n // ponytail: every tick is in the DOM — fine to a few hundred (80 units at\n // step 0.5 is 161). Window to the visible span if a finer step is ever needed.\n // Each tick carries an offset because max sits `remainder` of a step past the\n // last whole tick. Whenever remainder is under 0.5 that point falls inside\n // the previous box, so an appended flex box can never centre on it.\n const ticks = Array.from({ length: wholeSteps + 1 }, (_, i) => ({\n // toFixed trims float dust from fractional steps (0.1 + 0.2 …).\n value: Number((min + i * step).toFixed(6)),\n major: i % majorEvery === 0,\n offset: i * gap,\n }));\n // A tiny remainder puts this label close to the one before it. That is what\n // a scale ending a hair past a step looks like.\n if (remainder > 0) ticks.push({ value: max, major: true, offset: maxOffset });\n\n const snapToTick = () => {\n // The same nearest-tick rule useSlider applies. max counts as a candidate\n // when the step does not divide the range, so a flick near the end does\n // not settle on the last whole step.\n const target = snapSliderValue(min + (-x.get() / gap) * step, min, max, step);\n const snapped = -((target - min) / step) * gap;\n const id = ++gesture.current;\n if (reduce) {\n x.set(snapped);\n interacting.current = false;\n return;\n }\n animate(x, snapped, SPRING_SNAP).then(() => {\n if (gesture.current === id) interacting.current = false;\n });\n };\n\n // A key press takes the scale back from momentum: without this the coasting\n // strip keeps committing its own value and swallows the keyboard input.\n const rootProps = {\n ...sliderProps,\n onKeyDown: (event: KeyboardEvent<HTMLDivElement>) => {\n x.stop();\n gesture.current++;\n interacting.current = false;\n holding.current = false;\n sliderProps.onKeyDown(event);\n },\n };\n\n useEffect(() => {\n if (interacting.current) return;\n x.set(-((current - min) / step) * gap);\n }, [current, min, step, gap, x]);\n\n useMotionValueEvent(x, \"change\", (v) => {\n if (!interacting.current) return;\n commit(min + (-v / gap) * step);\n });\n\n return (\n <div\n {...rootProps}\n className={cn(\n \"relative w-full touch-none overflow-hidden\",\n TOUCH_GESTURE_CLASS,\n options.disabled ? \"pointer-events-none opacity-50\" : \"cursor-grab active:cursor-grabbing\",\n \"rounded-2xl outline-none ring-foreground/30 focus-visible:ring-4\",\n className,\n )}\n >\n <div className=\"pointer-events-none flex items-baseline justify-center gap-1 pt-1 pb-3\">\n <span className=\"font-semibold text-3xl text-foreground tabular-nums\">\n {readout(current)}\n </span>\n {unit ? <span className=\"text-muted-foreground text-sm\">{unit}</span> : null}\n </div>\n\n {/* masked, not overlaid with background-coloured gradients — the fade has\n to work on any surface the slider is dropped onto */}\n <div className=\"mask-[linear-gradient(to_right,transparent,black_18%,black_82%,transparent)] relative h-12\">\n {/* strip — dragged directly, so momentum comes from the drag gesture */}\n <motion.div\n drag={options.disabled ? false : \"x\"}\n dragConstraints={{ left: -maxOffset, right: 0 }}\n dragElastic={0.03}\n dragMomentum={!reduce}\n dragTransition={{ power: 0.22, timeConstant: 320 }}\n onDragStart={() => {\n gesture.current++;\n interacting.current = true;\n holding.current = true;\n }}\n // Momentum end when there is momentum, drag end when there is not.\n onDragTransitionEnd={() => {\n if (!holding.current) snapToTick();\n }}\n onDragEnd={() => {\n holding.current = false;\n if (reduce) snapToTick();\n }}\n // The ticks are positioned rather than laid out, so the row needs an\n // explicit width plus half a gap of slop each side to cover the\n // whole drag surface.\n style={{ x, marginLeft: -gap / 2, width: maxOffset + gap }}\n className=\"absolute inset-y-0 left-1/2\"\n >\n {ticks.map((tick) => (\n // pb reserves the label row, so minor ticks need no spacer node\n <span\n key={tick.value}\n className=\"absolute bottom-0 flex -translate-x-1/2 flex-col items-center pb-[18px]\"\n style={{ left: tick.offset + gap / 2 }}\n >\n <span\n className={cn(\n \"w-px rounded-full\",\n // minor ticks at /45 clear the 3:1 non-text floor in both themes\n tick.major ? \"h-7 bg-foreground/70\" : \"h-3.5 bg-foreground/45\",\n )}\n />\n {tick.major ? (\n <span className=\"absolute bottom-0 text-[10px] text-muted-foreground tabular-nums\">\n {tick.value}\n </span>\n ) : null}\n </span>\n ))}\n </motion.div>\n\n {/* needle — the read head the scale moves under */}\n <div className=\"pointer-events-none absolute bottom-5 left-1/2 -translate-x-1/2\">\n <span className=\"block h-9 w-[3px] rounded-full bg-foreground\" />\n </div>\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;;;;AAgBA,MAAM,cAAc;CAAE,MAAM;CAAU,WAAW;CAAK,SAAS;CAAI,MAAM;AAAI;;;;;AAgB7E,SAAgB,YAAY,EAC1B,MAAM,IACN,aAAa,GACb,MACA,WACA,GAAG,WACgB;CACnB,MAAM,SAAS,iBAAiB;CAMhC,MAAM,WAAW,OAAO,QAAQ,QAAQ,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,EAAE,UAAU;CACpE,MAAM,WAAW,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AC,QAAD,EACE,WAAW,GACT,qBAEA,KAAK,QAAQ,yBAAyB,wBACxC,EACD,CAAA,GACA,KAAK,QACJ,oBAAC,QAAD;MAAM,WAAU;MACb,UAAA,KAAK;KACF,CAAA,IACJ,IACA;IAhBC,GAAA,KAAK,KAgBN,CACP;GACS,CAAA,GAGZ,oBAAC,OAAD;IAAK,WAAU;IACb,UAAA,oBAAC,QAAD,EAAM,WAAU,+CAAgD,CAAA;GAC7D,CAAA,CACF;EACF,CAAA,CAAA;;AAET"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"range-slider-wave.d.ts","names":[],"sources":["../../../src/components/motion/range-slider-wave.tsx"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"range-slider-wave.d.ts","names":[],"sources":["../../../src/components/motion/range-slider-wave.tsx"],"mappings":";;UAgBiB,wBAAwB;;EAEvC;EACA;;;;;;;iBAQc,aAAa,MAAa,cAAc,WAAW,kCAAe,IAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { TOUCH_GESTURE_CLASS } from "../../lib/touch.js";
|
|
2
3
|
import { useSlider } from "../../hooks/use-slider.js";
|
|
3
4
|
import { useMemo } from "react";
|
|
4
5
|
import { cn } from "@kumix/utils";
|
|
@@ -36,7 +37,7 @@ function WaveSlider({ bars = BARS, className, ...options }) {
|
|
|
36
37
|
});
|
|
37
38
|
return /* @__PURE__ */ jsxs("div", {
|
|
38
39
|
...trackProps,
|
|
39
|
-
className: cn("relative flex h-20 w-full touch-none
|
|
40
|
+
className: cn("relative flex h-20 w-full touch-none items-center justify-between gap-1", TOUCH_GESTURE_CLASS, options.disabled ? "pointer-events-none opacity-50" : "cursor-grab active:cursor-grabbing", className),
|
|
40
41
|
children: [lanes.map((lane) => /* @__PURE__ */ jsx(motion.span, {
|
|
41
42
|
className: cn("h-14 flex-1 origin-center rounded-full", lane.filled ? "bg-foreground" : "bg-foreground/45"),
|
|
42
43
|
animate: { scaleY: reduce ? .4 : .22 + lane.crest * (dragging ? .78 : .6) },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"range-slider-wave.js","names":[],"sources":["../../../src/components/motion/range-slider-wave.tsx"],"sourcesContent":["\"use client\";\n\nimport { useMemo } from \"react\";\nimport { motion, useReducedMotion } from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { type SliderOptions, useSlider } from \"../../hooks/use-slider\";\n\n// Per-bar spring: soft enough that the crest wobbles as it travels.\nconst SPRING_BAR = { type: \"spring\", stiffness: 420, damping: 20, mass: 0.5 } as const;\n/** Bar count that reads as a wave without turning into a stripe pattern. */\nconst BARS = 32;\n/** Width of the crest in bars — bigger spreads the bell wider. */\nconst SPREAD = 2.6;\n\nexport interface WaveSliderProps extends SliderOptions {\n /** Number of bars drawn across the track. */\n bars?: number;\n className?: string;\n}\n\n/**\n * Equalizer slider: bars rise into a crest around the handle position and fall\n * back as it passes, so the value reads as a travelling wave. Bars up to the\n * value are filled, the rest stay muted.\n */\nexport function WaveSlider({ bars = BARS, className, ...options }: WaveSliderProps) {\n const reduce = useReducedMotion();\n const { percent, dragging, trackProps, sliderProps } = useSlider(options);\n\n // Keys only change when the bar count does — the list never reorders.\n const keys = useMemo(() => Array.from({ length: bars }, (_, i) => `bar-${i}`), [bars]);\n\n const head = (percent / 100) * (bars - 1);\n const lanes = keys.map((key, i) => {\n const distance = Math.abs(i - head);\n return {\n key,\n distance,\n // Gaussian crest centred on the handle.\n crest: Math.exp(-(distance ** 2) / (2 * SPREAD ** 2)),\n filled: i <= Math.round(head),\n };\n });\n\n return (\n <div\n {...trackProps}\n className={cn(\n \"relative flex h-20 w-full touch-none
|
|
1
|
+
{"version":3,"file":"range-slider-wave.js","names":[],"sources":["../../../src/components/motion/range-slider-wave.tsx"],"sourcesContent":["\"use client\";\n\nimport { useMemo } from \"react\";\nimport { motion, useReducedMotion } from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { type SliderOptions, useSlider } from \"../../hooks/use-slider\";\nimport { TOUCH_GESTURE_CLASS } from \"../../lib/touch\";\n\n// Per-bar spring: soft enough that the crest wobbles as it travels.\nconst SPRING_BAR = { type: \"spring\", stiffness: 420, damping: 20, mass: 0.5 } as const;\n/** Bar count that reads as a wave without turning into a stripe pattern. */\nconst BARS = 32;\n/** Width of the crest in bars — bigger spreads the bell wider. */\nconst SPREAD = 2.6;\n\nexport interface WaveSliderProps extends SliderOptions {\n /** Number of bars drawn across the track. */\n bars?: number;\n className?: string;\n}\n\n/**\n * Equalizer slider: bars rise into a crest around the handle position and fall\n * back as it passes, so the value reads as a travelling wave. Bars up to the\n * value are filled, the rest stay muted.\n */\nexport function WaveSlider({ bars = BARS, className, ...options }: WaveSliderProps) {\n const reduce = useReducedMotion();\n const { percent, dragging, trackProps, sliderProps } = useSlider(options);\n\n // Keys only change when the bar count does — the list never reorders.\n const keys = useMemo(() => Array.from({ length: bars }, (_, i) => `bar-${i}`), [bars]);\n\n const head = (percent / 100) * (bars - 1);\n const lanes = keys.map((key, i) => {\n const distance = Math.abs(i - head);\n return {\n key,\n distance,\n // Gaussian crest centred on the handle.\n crest: Math.exp(-(distance ** 2) / (2 * SPREAD ** 2)),\n filled: i <= Math.round(head),\n };\n });\n\n return (\n <div\n {...trackProps}\n className={cn(\n \"relative flex h-20 w-full touch-none items-center justify-between gap-1\",\n TOUCH_GESTURE_CLASS,\n options.disabled ? \"pointer-events-none opacity-50\" : \"cursor-grab active:cursor-grabbing\",\n className,\n )}\n >\n {lanes.map((lane) => (\n <motion.span\n key={lane.key}\n className={cn(\n \"h-14 flex-1 origin-center rounded-full\",\n // /45 keeps the unfilled track above the 3:1 non-text contrast\n // floor in both themes (measured 4.16 dark / 3.13 light)\n lane.filled ? \"bg-foreground\" : \"bg-foreground/45\",\n )}\n animate={{\n scaleY: reduce ? 0.4 : 0.22 + lane.crest * (dragging ? 0.78 : 0.6),\n }}\n transition={\n reduce\n ? { duration: 0 }\n : { ...SPRING_BAR, delay: Math.min(lane.distance * 0.012, 0.12) }\n }\n />\n ))}\n\n <button\n type=\"button\"\n {...sliderProps}\n className=\"absolute inset-0 touch-none rounded-xl outline-none ring-foreground/30 focus-visible:ring-4\"\n />\n </div>\n );\n}\n"],"mappings":";;;;;;;;AAUA,MAAM,aAAa;CAAE,MAAM;CAAU,WAAW;CAAK,SAAS;CAAI,MAAM;AAAI;;AAE5E,MAAM,OAAO;;AAEb,MAAM,SAAS;;;;;;AAaf,SAAgB,WAAW,EAAE,OAAO,MAAM,WAAW,GAAG,WAA4B;CAClF,MAAM,SAAS,iBAAiB;CAChC,MAAM,EAAE,SAAS,UAAU,YAAY,gBAAgB,UAAU,OAAO;CAGxE,MAAM,OAAO,cAAc,MAAM,KAAK,EAAE,QAAQ,KAAK,IAAI,GAAG,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC;CAErF,MAAM,OAAQ,UAAU,OAAQ,OAAO;CACvC,MAAM,QAAQ,KAAK,KAAK,KAAK,MAAM;EACjC,MAAM,WAAW,KAAK,IAAI,IAAI,IAAI;EAClC,OAAO;GACL;GACA;GAEA,OAAO,KAAK,IAAI,EAAE,YAAY,MAAM,IAAI,UAAU,EAAE;GACpD,QAAQ,KAAK,KAAK,MAAM,IAAI;EAC9B;CACF,CAAC;CAED,OACE,qBAAC,OAAD;EACE,GAAI;EACJ,WAAW,GACT,2EACA,qBACA,QAAQ,WAAW,mCAAmC,sCACtD,SACF;EAPF,UAAA,CASG,MAAM,KAAK,SACV,oBAAC,OAAO,MAAR;GAEE,WAAW,GACT,0CAGA,KAAK,SAAS,kBAAkB,kBAClC;GACA,SAAS,EACP,QAAQ,SAAS,KAAM,MAAO,KAAK,SAAS,WAAW,MAAO,IAChE;GACA,YACE,SACI,EAAE,UAAU,EAAE,IACd;IAAE,GAAG;IAAY,OAAO,KAAK,IAAI,KAAK,WAAW,MAAO,GAAI;GAAE;EAErE,GAfM,KAAK,GAeX,CACF,GAED,oBAAC,UAAD;GACE,MAAK;GACL,GAAI;GACJ,WAAU;EACX,CAAA,CACE;;AAET"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"range-slider.d.ts","names":[],"sources":["../../../src/components/motion/range-slider.tsx"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"range-slider.d.ts","names":[],"sources":["../../../src/components/motion/range-slider.tsx"],"mappings":";;UAoBiB,yBAAyB;;EAExC;EACA;;iBAGc,cAAc,WAAkB,cAAc,WAAW,mCAAgB,IAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { TOUCH_GESTURE_CLASS } from "../../lib/touch.js";
|
|
2
3
|
import { useSlider } from "../../hooks/use-slider.js";
|
|
3
4
|
import { SPRING_GLIDE } from "../../lib/ease.js";
|
|
4
5
|
import { useEffect } from "react";
|
|
@@ -27,7 +28,7 @@ function RangeSlider({ showTicks = true, className, ...options }) {
|
|
|
27
28
|
const ticks = showTicks && steps > 0 && steps <= 50 ? Array.from({ length: steps + 1 }, (_, i) => Number((min + i * step).toFixed(6))) : [];
|
|
28
29
|
return /* @__PURE__ */ jsxs("div", {
|
|
29
30
|
...trackProps,
|
|
30
|
-
className: cn("relative flex h-10 w-full touch-none
|
|
31
|
+
className: cn("relative flex h-10 w-full touch-none items-center overflow-hidden rounded-lg bg-muted", TOUCH_GESTURE_CLASS, options.disabled ? "pointer-events-none opacity-50" : "cursor-grab active:cursor-grabbing", className),
|
|
31
32
|
children: [
|
|
32
33
|
/* @__PURE__ */ jsx(motion.div, {
|
|
33
34
|
className: "absolute inset-y-0 left-0 bg-foreground/15",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"range-slider.js","names":[],"sources":["../../../src/components/motion/range-slider.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect } from \"react\";\nimport {\n motion,\n useMotionTemplate,\n useMotionValue,\n useReducedMotion,\n useSpring,\n useTransform,\n} from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { type SliderOptions, useSlider } from \"../../hooks/use-slider\";\nimport { SPRING_GLIDE } from \"../../lib/ease\";\n\n// Bouncy grab feedback for the thumb scale only.\nconst SPRING_BOUNCY = { type: \"spring\", stiffness: 500, damping: 14, mass: 0.7 } as const;\n\nexport interface RangeSliderProps extends SliderOptions {\n /** Render a tick dot at each step. */\n showTicks?: boolean;\n className?: string;\n}\n\nexport function RangeSlider({ showTicks = true, className, ...options }: RangeSliderProps) {\n const reduce = useReducedMotion();\n const { percent, dragging, min, max, step, trackProps, sliderProps } = useSlider(options);\n\n // Spring-smoothed position drives both the thumb and the fill.\n const target = useMotionValue(percent);\n useEffect(() => {\n target.set(percent);\n }, [percent, target]);\n const smooth = useSpring(target, SPRING_GLIDE);\n const pos = reduce ? target : smooth;\n const left = useMotionTemplate`${pos}%`;\n // Self-offset the thumb from 0% (flush left) to -100% (flush right) of its\n // own width so it stays fully inside the track at both ends — no clip, no gap.\n const thumbX = useTransform(pos, (p) => `${-p}%`);\n\n // Floor rather than round, so a range the step does not divide (0 to 10 by 4)\n // stops its dots at the last whole step instead of drawing one past max.\n // toFixed comes first because 0.3/0.1 is 2.9999999999999996, which would\n // floor to 2 and drop the last dot.\n const steps = Math.floor(Number(((max - min) / step).toFixed(6)));\n const ticks =\n showTicks && steps > 0 && steps <= 50\n ? Array.from({ length: steps + 1 }, (_, i) => Number((min + i * step).toFixed(6)))\n : [];\n\n return (\n <div\n {...trackProps}\n className={cn(\n \"relative flex h-10 w-full touch-none
|
|
1
|
+
{"version":3,"file":"range-slider.js","names":[],"sources":["../../../src/components/motion/range-slider.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect } from \"react\";\nimport {\n motion,\n useMotionTemplate,\n useMotionValue,\n useReducedMotion,\n useSpring,\n useTransform,\n} from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { type SliderOptions, useSlider } from \"../../hooks/use-slider\";\nimport { SPRING_GLIDE } from \"../../lib/ease\";\nimport { TOUCH_GESTURE_CLASS } from \"../../lib/touch\";\n\n// Bouncy grab feedback for the thumb scale only.\nconst SPRING_BOUNCY = { type: \"spring\", stiffness: 500, damping: 14, mass: 0.7 } as const;\n\nexport interface RangeSliderProps extends SliderOptions {\n /** Render a tick dot at each step. */\n showTicks?: boolean;\n className?: string;\n}\n\nexport function RangeSlider({ showTicks = true, className, ...options }: RangeSliderProps) {\n const reduce = useReducedMotion();\n const { percent, dragging, min, max, step, trackProps, sliderProps } = useSlider(options);\n\n // Spring-smoothed position drives both the thumb and the fill.\n const target = useMotionValue(percent);\n useEffect(() => {\n target.set(percent);\n }, [percent, target]);\n const smooth = useSpring(target, SPRING_GLIDE);\n const pos = reduce ? target : smooth;\n const left = useMotionTemplate`${pos}%`;\n // Self-offset the thumb from 0% (flush left) to -100% (flush right) of its\n // own width so it stays fully inside the track at both ends — no clip, no gap.\n const thumbX = useTransform(pos, (p) => `${-p}%`);\n\n // Floor rather than round, so a range the step does not divide (0 to 10 by 4)\n // stops its dots at the last whole step instead of drawing one past max.\n // toFixed comes first because 0.3/0.1 is 2.9999999999999996, which would\n // floor to 2 and drop the last dot.\n const steps = Math.floor(Number(((max - min) / step).toFixed(6)));\n const ticks =\n showTicks && steps > 0 && steps <= 50\n ? Array.from({ length: steps + 1 }, (_, i) => Number((min + i * step).toFixed(6)))\n : [];\n\n return (\n <div\n {...trackProps}\n className={cn(\n \"relative flex h-10 w-full touch-none items-center overflow-hidden rounded-lg bg-muted\",\n TOUCH_GESTURE_CLASS,\n options.disabled ? \"pointer-events-none opacity-50\" : \"cursor-grab active:cursor-grabbing\",\n className,\n )}\n >\n {/* fill — runs from the left edge to the thumb, consistent tone */}\n <motion.div className=\"absolute inset-y-0 left-0 bg-foreground/15\" style={{ width: left }} />\n\n {/* Ticks, inset by half the thumb's width. That inset is the span the\n thumb's own centre travels, so a dot sits where the thumb lands. */}\n <div className=\"pointer-events-none absolute inset-x-[3px] inset-y-0\">\n {ticks.map((t) => {\n const tp = ((t - min) / (max - min)) * 100;\n return (\n <span\n key={t}\n className=\"absolute top-1/2 size-1 -translate-x-1/2 -translate-y-1/2 rounded-full bg-foreground/25\"\n style={{ left: `${tp}%` }}\n />\n );\n })}\n </div>\n\n {/* vertical bar thumb — contained at both ends via thumbX */}\n <motion.div\n {...sliderProps}\n animate={reduce ? undefined : { scaleY: dragging ? 1.35 : 1 }}\n transition={SPRING_BOUNCY}\n className=\"absolute top-1/2 h-5 w-1.5 rounded-sm bg-foreground shadow-sm outline-none ring-foreground/30 ring-inset focus-visible:ring-4\"\n style={{ left, x: thumbX, y: \"-50%\" }}\n />\n </div>\n );\n}\n"],"mappings":";;;;;;;;;AAkBA,MAAM,gBAAgB;CAAE,MAAM;CAAU,WAAW;CAAK,SAAS;CAAI,MAAM;AAAI;AAQ/E,SAAgB,YAAY,EAAE,YAAY,MAAM,WAAW,GAAG,WAA6B;CACzF,MAAM,SAAS,iBAAiB;CAChC,MAAM,EAAE,SAAS,UAAU,KAAK,KAAK,MAAM,YAAY,gBAAgB,UAAU,OAAO;CAGxF,MAAM,SAAS,eAAe,OAAO;CACrC,gBAAgB;EACd,OAAO,IAAI,OAAO;CACpB,GAAG,CAAC,SAAS,MAAM,CAAC;CACpB,MAAM,SAAS,UAAU,QAAQ,YAAY;CAC7C,MAAM,MAAM,SAAS,SAAS;CAC9B,MAAM,OAAO,iBAAiB,GAAG,IAAI;CAGrC,MAAM,SAAS,aAAa,MAAM,MAAM,GAAG,CAAC,EAAE,EAAE;CAMhD,MAAM,QAAQ,KAAK,MAAM,SAAS,MAAM,OAAO,KAAA,CAAM,QAAQ,CAAC,CAAC,CAAC;CAChE,MAAM,QACJ,aAAa,QAAQ,KAAK,SAAS,KAC/B,MAAM,KAAK,EAAE,QAAQ,QAAQ,EAAE,IAAI,GAAG,MAAM,QAAQ,MAAM,IAAI,KAAA,CAAM,QAAQ,CAAC,CAAC,CAAC,IAC/E,CAAC;CAEP,OACE,qBAAC,OAAD;EACE,GAAI;EACJ,WAAW,GACT,yFACA,qBACA,QAAQ,WAAW,mCAAmC,sCACtD,SACF;EAPF,UAAA;GAUE,oBAAC,OAAO,KAAR;IAAY,WAAU;IAA6C,OAAO,EAAE,OAAO,KAAK;GAAI,CAAA;GAI5F,oBAAC,OAAD;IAAK,WAAU;IACZ,UAAA,MAAM,KAAK,MAAM;KAChB,MAAM,MAAO,IAAI,QAAQ,MAAM,OAAQ;KACvC,OACE,oBAAC,QAAD;MAEE,WAAU;MACV,OAAO,EAAE,MAAM,GAAG,GAAG,GAAG;KACzB,GAHM,CAGN;IAEL,CAAC;GACE,CAAA;GAGL,oBAAC,OAAO,KAAR;IACE,GAAI;IACJ,SAAS,SAAS,KAAA,IAAY,EAAE,QAAQ,WAAW,OAAO,EAAE;IAC5D,YAAY;IACZ,WAAU;IACV,OAAO;KAAE;KAAM,GAAG;KAAQ,GAAG;IAAO;GACrC,CAAA;EACE;;AAET"}
|
|
@@ -4,11 +4,25 @@ interface SelectProps {
|
|
|
4
4
|
value?: string;
|
|
5
5
|
defaultValue?: string;
|
|
6
6
|
onValueChange?: (value: string) => void;
|
|
7
|
+
/**
|
|
8
|
+
* Controlled open state of the panel. A layout that stacks selects can hold
|
|
9
|
+
* this to keep exactly one panel open — the panel is absolutely positioned
|
|
10
|
+
* inside its field, so two open at once paint over each other's options.
|
|
11
|
+
*/
|
|
12
|
+
open?: boolean;
|
|
13
|
+
/** Uncontrolled initial open state. Default false. */
|
|
14
|
+
defaultOpen?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Fires whenever the panel opens or closes. The panel is absolutely
|
|
17
|
+
* positioned inside the field, so a layout that stacks selects has to know
|
|
18
|
+
* which one is open to paint it above its neighbours.
|
|
19
|
+
*/
|
|
20
|
+
onOpenChange?: (open: boolean) => void;
|
|
7
21
|
disabled?: boolean;
|
|
8
22
|
className?: string;
|
|
9
23
|
children: ReactNode;
|
|
10
24
|
}
|
|
11
|
-
declare function Select({ value, defaultValue, onValueChange, disabled, className, children }: SelectProps): import("react").JSX.Element;
|
|
25
|
+
declare function Select({ value, defaultValue, onValueChange, open: openProp, defaultOpen, onOpenChange, disabled, className, children }: SelectProps): import("react").JSX.Element;
|
|
12
26
|
interface SelectTriggerProps {
|
|
13
27
|
className?: string;
|
|
14
28
|
children: ReactNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select.d.ts","names":[],"sources":["../../../src/components/motion/select.tsx"],"mappings":";;UA6DiB;EACf;EACA;EACA,iBAAiB;
|
|
1
|
+
{"version":3,"file":"select.d.ts","names":[],"sources":["../../../src/components/motion/select.tsx"],"mappings":";;UA6DiB;EACf;EACA;EACA,iBAAiB;;;;;;EAMjB;;EAEA;;;;;;EAMA,gBAAgB;EAChB;EACA;EACA,UAAU;;iBAGI,SACd,OACA,cACA,eACA,MAAM,UACN,aACA,cACA,UACA,WACA,YACC,8BAAW,IAAA;UAkGG;EACf;EACA,UAAU;;iBAGI,gBAAgB,WAAW,YAAY,qCAAkB,IAAA;UAuDxD;EACf;EACA;;iBAGc,cAAc,aAAa,aAAa,mCAAgB,IAAA;UAUvD;EACf;EACA,UAAU;;iBAGI,gBAAgB,WAAW,YAAY,qCAAkB,IAAA;UAkHxD;EACf;EACA;EACA;EACA,UAAU;;iBAGI,aAAa,OAAO,UAAkB,WAAW,YAAY,kCAAe,IAAA"}
|