{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "snap-sheet",
  "title": "Snap Sheet",
  "description": "A bottom sheet you drag between snap points, with detent haptics, a rubber band, and flick to close.",
  "dependencies": [
    "@base-ui/react",
    "@rexa-developer/tiks",
    "lucide-react",
    "motion",
    "web-haptics"
  ],
  "files": [
    {
      "path": "src/registry/components/snap-sheet/snap-sheet.tsx",
      "content": "\"use client\";\n\nimport { Dialog as DialogPrimitive } from \"@base-ui/react/dialog\";\nimport { useTiks } from \"@rexa-developer/tiks/react\";\nimport { XIcon } from \"lucide-react\";\nimport {\n\ttype AnimationPlaybackControls,\n\tanimate,\n\ttype MotionValue,\n\tmotion,\n\tuseMotionValue,\n\tuseReducedMotion,\n\tuseTransform,\n} from \"motion/react\";\nimport {\n\ttype ComponentProps,\n\tcreateContext,\n\ttype KeyboardEvent,\n\ttype MouseEvent,\n\ttype PointerEvent,\n\ttype ReactNode,\n\ttype RefObject,\n\tuseCallback,\n\tuseContext,\n\tuseEffect,\n\tuseLayoutEffect,\n\tuseRef,\n\tuseState,\n\tuseSyncExternalStore,\n} from \"react\";\nimport { useWebHaptics } from \"web-haptics/react\";\nimport { cn } from \"@/lib/utils\";\n\nconst settleSpring = {\n\ttype: \"spring\",\n\tstiffness: 400,\n\tdamping: 40,\n\tmass: 0.9,\n} as const;\nconst openSpring = { type: \"spring\", stiffness: 320, damping: 34 } as const;\nconst reducedTween = {\n\ttype: \"tween\",\n\tduration: 0.12,\n\tease: \"easeOut\",\n} as const;\n\n/** Seconds of release velocity projected ahead before picking a snap point. */\nconst PROJECTION_SECONDS = 0.2;\n/** Downward release speed, in px/s, that closes the sheet from its lowest snap. */\nconst DISMISS_VELOCITY = 1000;\n/** Fastest release, in px/s, so one jumpy pointer event can't fling the sheet. */\nconst MAX_VELOCITY = 4000;\n/** Share of the pointer's travel past full height that the sheet follows. */\nconst RUBBER_BAND = 0.3;\n/** Px past full height where the rubber band hits its limit. */\nconst RUBBER_LIMIT = 16;\n/** Px band around a snap point a drag must clear before it counts as crossed. */\nconst DETENT_HYSTERESIS = 6;\n/** Pointer travel, in px, before a press turns into a drag or a scroll. */\nconst DRAG_SLOP = 4;\n/** Px kept free above the sheet at full height. Matches the height classes. */\nconst TOP_GAP = 24;\n/** Px around the floating variant. Matches its inset classes. */\nconst FLOATING_INSET = 8;\n/** Px past the bottom edge a closed sheet rests at, so its shadow is hidden too. */\nconst CLOSED_OVERSHOOT = 24;\n/** Px from a target where a settling sheet counts as landed for its cue. */\nconst LANDING_DISTANCE = 2;\nconst BACKGROUND_SCALE = 0.94;\nconst BACKGROUND_RADIUS = 12;\nconst BACKGROUND_OFFSET = 10;\n/** Off-screen until the first measure, so the sheet never flashes at full height. */\nconst UNMEASURED_Y = 10_000;\nconst NO_DRAG_SELECTOR =\n\t\"input, textarea, select, [contenteditable=''], [contenteditable='true'], [data-sheet-no-drag]\";\nconst DEFAULT_SNAP_POINTS: SnapPoint[] = [0.5, 1];\n\n/** A fraction of the viewport height, or a px string such as `\"148px\"`. */\nexport type SnapPoint = number | `${number}px`;\ntype DesktopMode = \"bottom\" | \"dialog\" | \"sheet\";\ntype Phase =\n\t| \"closed\"\n\t| \"opening\"\n\t| \"open\"\n\t| \"dragging\"\n\t| \"settling\"\n\t| \"closing\";\ntype CloseCue = \"flick\" | \"plain\" | null;\ntype Layout = {\n\t/** `y` of each snap point; 0 is full height. */\n\tsnaps: number[];\n\t/** `y` with the sheet fully off-screen. */\n\tclosed: number;\n\t/** Height of the sheet element. */\n\tmax: number;\n};\ntype Drag = {\n\tpointerId: number;\n\tstartX: number;\n\tstartY: number;\n\tstartSheetY: number;\n\tscale: number;\n\tscroller: HTMLElement | null;\n\tdecided: \"sheet\" | \"none\" | null;\n\tfromLowest: boolean;\n\thitLimit: boolean;\n\tsides: number[];\n};\n\nexport interface SnapSheetProps {\n\t/** Controlled open state. */\n\topen?: boolean;\n\t/** Initial open state when uncontrolled. */\n\tdefaultOpen?: boolean;\n\tonOpenChange?: (open: boolean) => void;\n\t/**\n\t * Heights the sheet rests at, lowest first. Numbers are fractions of the\n\t * viewport height and px strings are fixed heights. `1` is as tall as the\n\t * sheet gets: the viewport less a 24 px gap.\n\t */\n\tsnapPoints?: SnapPoint[];\n\t/** Controlled index into `snapPoints`. */\n\tactiveSnap?: number;\n\t/** Snap point the sheet opens to when uncontrolled. */\n\tdefaultSnap?: number;\n\t/** Called when a drag, key press, or handle tap picks a new snap point. */\n\tonSnapChange?: (index: number) => void;\n\t/**\n\t * Dim the page, trap focus, and lock scroll. Turn it off for map- or\n\t * player-style sheets that leave the page interactive.\n\t */\n\tmodal?: boolean;\n\t/** Let a downward drag, a flick, Esc, or an overlay click close the sheet. */\n\tdismissible?: boolean;\n\t/** Scale `[data-sheet-wrapper]` back as the sheet reaches full height. */\n\tscaleBackground?: boolean;\n\t/** How the sheet renders from the `md` breakpoint up. */\n\tdesktop?: DesktopMode;\n\t/** Only start drags from `SnapSheet.Handle`. */\n\thandleOnly?: boolean;\n\t/** Play a click per snap, a pop at full height, and a swoosh on open and dismiss. */\n\tsound?: boolean;\n\t/** Trigger haptics on supported devices. */\n\thaptics?: boolean;\n\t/** Play cues for open and snap changes that come from props too. */\n\tsoundOnProgrammatic?: boolean;\n\tchildren?: ReactNode;\n}\n\ntype SnapSheetContextValue = {\n\ty: MotionValue<number>;\n\toverlayOpacity: MotionValue<number>;\n\tdialogScale: MotionValue<number>;\n\tprogress: MotionValue<number>;\n\tsheetX: MotionValue<string>;\n\tmode: DesktopMode;\n\tmodal: boolean;\n\tsnapIndex: number;\n\tsnapCount: number;\n\tsnapLabel: string;\n\tannouncement: string;\n\tsetPopup: (node: HTMLDivElement | null) => void;\n\tcontainerRef: RefObject<HTMLElement | null>;\n\tfloatingRef: RefObject<boolean>;\n\tshouldMoveFocus: () => boolean;\n\tstepSnap: (index: number) => void;\n\thandlePointerDown: (event: PointerEvent<HTMLDivElement>) => void;\n\tconsumeClick: () => boolean;\n};\n\nconst SnapSheetContext = createContext<SnapSheetContextValue | null>(null);\n\nfunction useSnapSheet() {\n\tconst context = useContext(SnapSheetContext);\n\tif (!context) {\n\t\tthrow new Error(\"SnapSheet parts must be rendered inside <SnapSheet>.\");\n\t}\n\treturn context;\n}\n\nfunction clamp(value: number, min: number, max: number) {\n\treturn Math.min(Math.max(value, min), max);\n}\n\nfunction toPx(point: SnapPoint, frame: number) {\n\treturn typeof point === \"number\" ? point * frame : Number.parseFloat(point);\n}\n\nfunction describeSnap(points: SnapPoint[], index: number) {\n\tconst point = points[index];\n\tconst last = index === points.length - 1;\n\tif (typeof point === \"number\") {\n\t\tif (last && point >= 0.85) return \"Full height\";\n\t\tif (Math.abs(point - 0.5) < 0.05) return \"Half height\";\n\t\tif (index === 0) return \"Peek height\";\n\t\treturn `${Math.round(point * 100)}% height`;\n\t}\n\tif (index === 0) return \"Peek height\";\n\tif (last) return \"Full height\";\n\treturn `Height ${index + 1} of ${points.length}`;\n}\n\n/** Which side of `snap` a sheet at `y` sits on: -1 above, 1 below, 0 inside the band. */\nfunction sideOf(y: number, snap: number) {\n\tif (y < snap - DETENT_HYSTERESIS / 2) return -1;\n\tif (y > snap + DETENT_HYSTERESIS / 2) return 1;\n\treturn 0;\n}\n\n/** The nearest element between `target` and `sheet` that scrolls vertically. */\nfunction findScroller(target: Element, sheet: HTMLElement) {\n\tlet node: Element | null = target;\n\twhile (node && node !== sheet) {\n\t\tif (node instanceof HTMLElement && node.scrollHeight > node.clientHeight) {\n\t\t\tconst { overflowY } = getComputedStyle(node);\n\t\t\tif (overflowY === \"auto\" || overflowY === \"scroll\") return node;\n\t\t}\n\t\tnode = node.parentElement;\n\t}\n\treturn null;\n}\n\nfunction resolveContainer(\n\tcontainer: HTMLElement | RefObject<HTMLElement | null> | null | undefined,\n) {\n\tif (!container) return null;\n\treturn container instanceof HTMLElement ? container : container.current;\n}\n\nfunction subscribeDesktop(onChange: () => void) {\n\tconst query = window.matchMedia(\"(min-width: 768px)\");\n\tquery.addEventListener(\"change\", onChange);\n\treturn () => query.removeEventListener(\"change\", onChange);\n}\n\nfunction useIsDesktop() {\n\treturn useSyncExternalStore(\n\t\tsubscribeDesktop,\n\t\t() => window.matchMedia(\"(min-width: 768px)\").matches,\n\t\t() => false,\n\t);\n}\n\nfunction SnapSheet({\n\topen: openProp,\n\tdefaultOpen = false,\n\tonOpenChange,\n\tsnapPoints = DEFAULT_SNAP_POINTS,\n\tactiveSnap,\n\tdefaultSnap = 0,\n\tonSnapChange,\n\tmodal = true,\n\tdismissible = true,\n\tscaleBackground = false,\n\tdesktop = \"bottom\",\n\thandleOnly = false,\n\tsound = true,\n\thaptics = true,\n\tsoundOnProgrammatic = false,\n\tchildren,\n}: SnapSheetProps) {\n\tconst snapCount = Math.max(1, snapPoints.length);\n\tconst [uncontrolledOpen, setUncontrolledOpen] = useState(defaultOpen);\n\tconst open = openProp ?? uncontrolledOpen;\n\t// Stays mounted through the close animation, then unmounts.\n\tconst [rendered, setRendered] = useState(open);\n\tif (open && !rendered) setRendered(true);\n\n\tconst [uncontrolledSnap, setUncontrolledSnap] = useState(defaultSnap);\n\tconst snapIndex = clamp(activeSnap ?? uncontrolledSnap, 0, snapCount - 1);\n\tconst [announcement, setAnnouncement] = useState(\"\");\n\tconst [popup, setPopupState] = useState<HTMLDivElement | null>(null);\n\n\tconst isDesktop = useIsDesktop();\n\tconst mode: DesktopMode = isDesktop ? desktop : \"bottom\";\n\tconst shouldReduceMotion = useReducedMotion() ?? false;\n\tconst { trigger: haptic } = useWebHaptics();\n\tconst {\n\t\tclick: playClick,\n\t\tpop: playPop,\n\t\tswoosh: playSwoosh,\n\t} = useTiks({\n\t\t// Sound stays on under reduced motion; only movement is reduced.\n\t\trespectReducedMotion: false,\n\t});\n\n\tconst y = useMotionValue(UNMEASURED_Y);\n\tconst progress = useMotionValue(0);\n\tconst popupRef = useRef<HTMLDivElement | null>(null);\n\tconst containerRef = useRef<HTMLElement | null>(null);\n\tconst floatingRef = useRef(false);\n\tconst wrapperRef = useRef<HTMLElement | null>(null);\n\tconst directionRef = useRef(1);\n\tconst phaseRef = useRef<Phase>(\"closed\");\n\tconst layoutRef = useRef<Layout | null>(null);\n\tconst animationRef = useRef<AnimationPlaybackControls | null>(null);\n\tconst dragRef = useRef<Drag | null>(null);\n\t/** Snap index the sheet rests at or is heading to. */\n\tconst indexRef = useRef(snapIndex);\n\t/** Snap index the sheet last came to rest at, for \"settled somewhere new\". */\n\tconst settledIndexRef = useRef(snapIndex);\n\tconst landingRef = useRef<{ y: number; index: number } | null>(null);\n\tconst userOpenRef = useRef(false);\n\tconst suppressClickRef = useRef(false);\n\n\t// Latest values for the imperative handlers below, so they never re-bind.\n\tconst latest = useRef({\n\t\topen,\n\t\tsnapPoints,\n\t\tsnapIndex,\n\t\tactiveSnap,\n\t\tdefaultSnap,\n\t\tmode,\n\t\tmodal,\n\t\tdismissible,\n\t\tscaleBackground,\n\t\thandleOnly,\n\t\tsound,\n\t\thaptics,\n\t\tsoundOnProgrammatic,\n\t\tshouldReduceMotion,\n\t\tonOpenChange,\n\t\tonSnapChange,\n\t});\n\tuseLayoutEffect(() => {\n\t\tlatest.current = {\n\t\t\topen,\n\t\t\tsnapPoints,\n\t\t\tsnapIndex,\n\t\t\tactiveSnap,\n\t\t\tdefaultSnap,\n\t\t\tmode,\n\t\t\tmodal,\n\t\t\tdismissible,\n\t\t\tscaleBackground,\n\t\t\thandleOnly,\n\t\t\tsound,\n\t\t\thaptics,\n\t\t\tsoundOnProgrammatic,\n\t\t\tshouldReduceMotion,\n\t\t\tonOpenChange,\n\t\t\tonSnapChange,\n\t\t};\n\t});\n\n\tconst overlayOpacity = useTransform(() => {\n\t\tconst value = y.get();\n\t\tconst amount = progress.get();\n\t\tconst layout = layoutRef.current;\n\t\tif (latest.current.mode !== \"bottom\") return amount;\n\t\tif (!layout) return 0;\n\t\tconst top = layout.snaps[layout.snaps.length - 1] ?? 0;\n\t\t// Modal sheets dim from closed; non-modal ones only near full height.\n\t\tconst from =\n\t\t\tlatest.current.modal || layout.snaps.length < 2\n\t\t\t\t? layout.closed\n\t\t\t\t: (layout.snaps[layout.snaps.length - 2] ?? layout.closed);\n\t\treturn clamp((from - value) / (from - top || 1), 0, 1);\n\t});\n\tconst dialogScale = useTransform(progress, [0, 1], [0.96, 1]);\n\tconst sheetX = useTransform(\n\t\t() => `${(1 - progress.get()) * 100 * directionRef.current}%`,\n\t);\n\n\tconst setPhase = useCallback((phase: Phase) => {\n\t\tphaseRef.current = phase;\n\t\tif (popupRef.current) popupRef.current.dataset.sheetState = phase;\n\t}, []);\n\n\tconst setPopup = useCallback((node: HTMLDivElement | null) => {\n\t\tpopupRef.current = node;\n\t\tif (node) node.dataset.sheetState = phaseRef.current;\n\t\tsetPopupState(node);\n\t}, []);\n\n\tconst measure = useCallback(() => {\n\t\tconst element = popupRef.current;\n\t\tif (!element) return null;\n\t\tconst max = element.offsetHeight;\n\t\tconst inset = floatingRef.current ? FLOATING_INSET : 0;\n\t\tconst frame = max + TOP_GAP + inset;\n\t\tconst snaps = latest.current.snapPoints.map(\n\t\t\t(point) => max - clamp(toPx(point, frame), 0, max),\n\t\t);\n\t\tif (snaps.length === 0) snaps.push(0);\n\t\tlayoutRef.current = { snaps, closed: max + inset + CLOSED_OVERSHOOT, max };\n\t\tdirectionRef.current =\n\t\t\tgetComputedStyle(element).direction === \"rtl\" ? -1 : 1;\n\t\treturn layoutRef.current;\n\t}, []);\n\n\tconst stop = useCallback(() => {\n\t\tanimationRef.current?.stop();\n\t\tanimationRef.current = null;\n\t}, []);\n\n\tconst runTo = useCallback(\n\t\t(\n\t\t\tvalue: MotionValue<number>,\n\t\t\tto: number,\n\t\t\ttransition: typeof settleSpring | typeof openSpring,\n\t\t\tvelocity: number,\n\t\t\tonComplete: () => void,\n\t\t) => {\n\t\t\tstop();\n\t\t\tif (value.get() === to) {\n\t\t\t\tonComplete();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tanimationRef.current = animate(value, to, {\n\t\t\t\t...(latest.current.shouldReduceMotion\n\t\t\t\t\t? reducedTween\n\t\t\t\t\t: { ...transition, velocity }),\n\t\t\t\trestDelta: 0.5,\n\t\t\t\tonComplete: () => {\n\t\t\t\t\tanimationRef.current = null;\n\t\t\t\t\tonComplete();\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t\t[stop],\n\t);\n\n\tconst playSnapCue = useCallback(\n\t\t(index: number) => {\n\t\t\tconst { sound, haptics, snapPoints } = latest.current;\n\t\t\tconst top = index === snapPoints.length - 1;\n\t\t\tif (sound) (top ? playPop : playClick)();\n\t\t\tif (haptics) void haptic(top ? \"light\" : \"selection\");\n\t\t},\n\t\t[haptic, playClick, playPop],\n\t);\n\n\tconst resetWrapper = useCallback(() => {\n\t\tconst wrapper = wrapperRef.current;\n\t\tif (!wrapper) return;\n\t\twrapper.style.removeProperty(\"transform\");\n\t\twrapper.style.removeProperty(\"transform-origin\");\n\t\twrapper.style.removeProperty(\"border-radius\");\n\t\twrapper.style.removeProperty(\"overflow\");\n\t\twrapper.style.removeProperty(\"will-change\");\n\t\twrapperRef.current = null;\n\t}, []);\n\n\tconst attachWrapper = useCallback(() => {\n\t\tresetWrapper();\n\t\tconst { scaleBackground, shouldReduceMotion, mode } = latest.current;\n\t\tif (!scaleBackground || shouldReduceMotion || mode !== \"bottom\") return;\n\t\tconst root = containerRef.current ?? document;\n\t\tconst wrapper = root.querySelector<HTMLElement>(\"[data-sheet-wrapper]\");\n\t\tif (!wrapper) return;\n\t\twrapper.style.transformOrigin = \"center top\";\n\t\twrapper.style.willChange = \"transform\";\n\t\twrapperRef.current = wrapper;\n\t}, [resetWrapper]);\n\n\tconst animateOpen = useCallback(\n\t\t(cue: boolean) => {\n\t\t\tconst layout = measure();\n\t\t\tif (!layout) return;\n\t\t\tconst fromClosed = phaseRef.current === \"closed\";\n\t\t\tconst index = clamp(latest.current.snapIndex, 0, layout.snaps.length - 1);\n\t\t\tindexRef.current = index;\n\t\t\tsettledIndexRef.current = index;\n\t\t\tlandingRef.current = null;\n\t\t\tattachWrapper();\n\t\t\tsetPhase(\"opening\");\n\t\t\tif (latest.current.mode === \"bottom\") {\n\t\t\t\tif (fromClosed) y.jump(layout.closed);\n\t\t\t\tprogress.jump(1);\n\t\t\t\trunTo(y, layout.snaps[index] ?? 0, openSpring, 0, () =>\n\t\t\t\t\tsetPhase(\"open\"),\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\ty.jump(0);\n\t\t\t\tif (fromClosed) progress.jump(0);\n\t\t\t\trunTo(progress, 1, openSpring, 0, () => setPhase(\"open\"));\n\t\t\t}\n\t\t\tif (cue && latest.current.sound) playSwoosh();\n\t\t},\n\t\t[attachWrapper, measure, playSwoosh, progress, runTo, setPhase, y],\n\t);\n\n\tconst animateClose = useCallback(\n\t\t(velocity: number, cue: CloseCue) => {\n\t\t\tconst finish = () => {\n\t\t\t\tsetPhase(\"closed\");\n\t\t\t\tresetWrapper();\n\t\t\t\t// A controlled parent can refuse to close; come back up.\n\t\t\t\tif (latest.current.open) {\n\t\t\t\t\tanimateOpen(false);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tsetRendered(false);\n\t\t\t\t// Uncontrolled sheets open at their default snap point again.\n\t\t\t\tif (latest.current.activeSnap === undefined) {\n\t\t\t\t\tconst index = clamp(\n\t\t\t\t\t\tlatest.current.defaultSnap,\n\t\t\t\t\t\t0,\n\t\t\t\t\t\tlatest.current.snapPoints.length - 1,\n\t\t\t\t\t);\n\t\t\t\t\tindexRef.current = index;\n\t\t\t\t\tsetUncontrolledSnap(index);\n\t\t\t\t}\n\t\t\t};\n\t\t\tlandingRef.current = null;\n\t\t\tsetPhase(\"closing\");\n\t\t\tconst layout = layoutRef.current;\n\t\t\tif (latest.current.mode === \"bottom\" && layout) {\n\t\t\t\trunTo(y, layout.closed, openSpring, velocity, finish);\n\t\t\t} else {\n\t\t\t\trunTo(progress, 0, openSpring, 0, finish);\n\t\t\t}\n\t\t\tif (cue) {\n\t\t\t\tif (latest.current.sound) playSwoosh();\n\t\t\t\tif (cue === \"flick\" && latest.current.haptics) void haptic(\"nudge\");\n\t\t\t}\n\t\t},\n\t\t[\n\t\t\tanimateOpen,\n\t\t\thaptic,\n\t\t\tplaySwoosh,\n\t\t\tprogress,\n\t\t\tresetWrapper,\n\t\t\trunTo,\n\t\t\tsetPhase,\n\t\t\ty,\n\t\t],\n\t);\n\n\tconst setOpen = useCallback((next: boolean) => {\n\t\tif (latest.current.open === next) return;\n\t\tsetUncontrolledOpen(next);\n\t\tlatest.current.onOpenChange?.(next);\n\t}, []);\n\n\tconst requestClose = useCallback(\n\t\t(cue: CloseCue, velocity = 0) => {\n\t\t\tconst phase = phaseRef.current;\n\t\t\tif (phase === \"closed\" || phase === \"closing\") return;\n\t\t\tsetOpen(false);\n\t\t\tanimateClose(velocity, cue);\n\t\t},\n\t\t[animateClose, setOpen],\n\t);\n\n\tconst settle = useCallback(\n\t\t(index: number, { velocity = 0, cue = false } = {}) => {\n\t\t\tconst layout = layoutRef.current;\n\t\t\tif (!layout) return;\n\t\t\tconst target = layout.snaps[index] ?? 0;\n\t\t\tindexRef.current = index;\n\t\t\tlandingRef.current =\n\t\t\t\tcue && index !== settledIndexRef.current ? { y: target, index } : null;\n\t\t\tsetPhase(\"settling\");\n\t\t\trunTo(y, target, settleSpring, velocity, () => {\n\t\t\t\tsettledIndexRef.current = index;\n\t\t\t\tsetPhase(\"open\");\n\t\t\t\tconst landing = landingRef.current;\n\t\t\t\tif (landing) {\n\t\t\t\t\tlandingRef.current = null;\n\t\t\t\t\tplaySnapCue(landing.index);\n\t\t\t\t}\n\t\t\t});\n\t\t},\n\t\t[playSnapCue, runTo, setPhase, y],\n\t);\n\n\t/** Moves to a snap picked by the user and reports it. */\n\tconst commitSnap = useCallback(\n\t\t(index: number, velocity = 0) => {\n\t\t\tsettle(index, { velocity, cue: true });\n\t\t\tif (index === latest.current.snapIndex) return;\n\t\t\tsetUncontrolledSnap(index);\n\t\t\tsetAnnouncement(\n\t\t\t\t`Sheet at ${describeSnap(latest.current.snapPoints, index).toLowerCase()}`,\n\t\t\t);\n\t\t\tlatest.current.onSnapChange?.(index);\n\t\t},\n\t\t[settle],\n\t);\n\n\t// Open and close from state, whether it changed here or through props.\n\tuseLayoutEffect(() => {\n\t\tif (!popup) return;\n\t\tconst phase = phaseRef.current;\n\t\tif (open) {\n\t\t\tif (phase === \"closed\" || phase === \"closing\") {\n\t\t\t\tconst cue = userOpenRef.current || latest.current.soundOnProgrammatic;\n\t\t\t\tanimateOpen(cue);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (phase === \"closed\") {\n\t\t\tsetRendered(false);\n\t\t} else if (phase !== \"closing\") {\n\t\t\tanimateClose(0, latest.current.soundOnProgrammatic ? \"plain\" : null);\n\t\t}\n\t}, [open, popup, animateOpen, animateClose]);\n\n\t// Controlled snap: glide there, unless a drag is in progress (the drag wins).\n\tuseEffect(() => {\n\t\tif (activeSnap === undefined) return;\n\t\tconst phase = phaseRef.current;\n\t\tif (phase === \"dragging\" || phase === \"closed\" || phase === \"closing\") {\n\t\t\treturn;\n\t\t}\n\t\tconst index = clamp(activeSnap, 0, snapCount - 1);\n\t\tif (index === indexRef.current) return;\n\t\tsettle(index, { cue: latest.current.soundOnProgrammatic });\n\t}, [activeSnap, snapCount, settle]);\n\n\t// The one place that reacts to movement: detents, the rubber band,\n\t// landing cues, and the background scale.\n\tuseEffect(() => {\n\t\tconst sync = (value: number) => {\n\t\t\tconst layout = layoutRef.current;\n\t\t\tif (!layout) return;\n\t\t\tconst { haptics } = latest.current;\n\t\t\tconst landing = landingRef.current;\n\t\t\tif (landing && Math.abs(value - landing.y) < LANDING_DISTANCE) {\n\t\t\t\tlandingRef.current = null;\n\t\t\t\tplaySnapCue(landing.index);\n\t\t\t}\n\n\t\t\tconst top = layout.snaps[layout.snaps.length - 1] ?? 0;\n\t\t\tconst drag = dragRef.current;\n\t\t\tif (phaseRef.current === \"dragging\" && drag) {\n\t\t\t\tif (!drag.hitLimit && value < top - RUBBER_LIMIT) {\n\t\t\t\t\tdrag.hitLimit = true;\n\t\t\t\t\tif (haptics) void haptic(\"rigid\");\n\t\t\t\t}\n\t\t\t\tlet crossed = false;\n\t\t\t\tlayout.snaps.forEach((snap, index) => {\n\t\t\t\t\tconst side = sideOf(value, snap);\n\t\t\t\t\tif (side === 0 || side === drag.sides[index]) return;\n\t\t\t\t\tif (drag.sides[index] !== 0) crossed = true;\n\t\t\t\t\tdrag.sides[index] = side;\n\t\t\t\t});\n\t\t\t\tif (crossed && haptics) void haptic(\"soft\");\n\t\t\t}\n\n\t\t\tconst wrapper = wrapperRef.current;\n\t\t\tif (!wrapper) return;\n\t\t\tconst from =\n\t\t\t\tlayout.snaps.length > 1\n\t\t\t\t\t? (layout.snaps[layout.snaps.length - 2] ?? layout.closed)\n\t\t\t\t\t: layout.closed;\n\t\t\tconst amount = clamp((from - value) / (from - top || 1), 0, 1);\n\t\t\tif (amount === 0) {\n\t\t\t\twrapper.style.removeProperty(\"transform\");\n\t\t\t\twrapper.style.removeProperty(\"border-radius\");\n\t\t\t\twrapper.style.removeProperty(\"overflow\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst scale = 1 - (1 - BACKGROUND_SCALE) * amount;\n\t\t\twrapper.style.transform = `translateY(${BACKGROUND_OFFSET * amount}px) scale(${scale})`;\n\t\t\twrapper.style.borderRadius = `${BACKGROUND_RADIUS * amount}px`;\n\t\t\twrapper.style.overflow = \"hidden\";\n\t\t};\n\t\treturn y.on(\"change\", sync);\n\t}, [haptic, playSnapCue, y]);\n\n\t// Recompute snap px on resize, rotation, and the iOS address bar.\n\tuseLayoutEffect(() => {\n\t\tif (!popup) return;\n\t\tlet lastHeight = popup.offsetHeight;\n\t\tconst observer = new ResizeObserver(() => {\n\t\t\tif (latest.current.mode !== \"bottom\") return;\n\t\t\tif (popup.offsetHeight === lastHeight) return;\n\t\t\tlastHeight = popup.offsetHeight;\n\t\t\tconst layout = measure();\n\t\t\tif (!layout) return;\n\t\t\tconst target = layout.snaps[indexRef.current] ?? 0;\n\t\t\tconst phase = phaseRef.current;\n\t\t\tif (phase === \"open\") {\n\t\t\t\ty.jump(target);\n\t\t\t} else if (phase === \"opening\" || phase === \"settling\") {\n\t\t\t\trunTo(y, target, settleSpring, y.getVelocity(), () => setPhase(\"open\"));\n\t\t\t}\n\t\t});\n\t\tobserver.observe(popup);\n\t\treturn () => observer.disconnect();\n\t}, [popup, measure, runTo, setPhase, y]);\n\n\t// Keep the sheet above the virtual keyboard.\n\tuseEffect(() => {\n\t\tconst viewport = window.visualViewport;\n\t\tif (!popup || !viewport || containerRef.current) return;\n\t\tconst update = () => {\n\t\t\tconst keyboard =\n\t\t\t\tviewport.scale > 1.01\n\t\t\t\t\t? 0\n\t\t\t\t\t: Math.max(\n\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\tMath.round(\n\t\t\t\t\t\t\t\twindow.innerHeight - viewport.height - viewport.offsetTop,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\tpopup.style.setProperty(\"--snap-sheet-keyboard\", `${keyboard}px`);\n\t\t};\n\t\tupdate();\n\t\tviewport.addEventListener(\"resize\", update);\n\t\tviewport.addEventListener(\"scroll\", update);\n\t\treturn () => {\n\t\t\tviewport.removeEventListener(\"resize\", update);\n\t\t\tviewport.removeEventListener(\"scroll\", update);\n\t\t};\n\t}, [popup]);\n\n\t// Switching between bottom and desktop layouts while open.\n\tuseLayoutEffect(() => {\n\t\tconst phase = phaseRef.current;\n\t\tif (phase === \"closed\" || phase === \"closing\") return;\n\t\tstop();\n\t\tattachWrapper();\n\t\tif (mode === \"bottom\") {\n\t\t\tconst layout = measure();\n\t\t\tprogress.jump(1);\n\t\t\tif (layout) y.jump(layout.snaps[indexRef.current] ?? 0);\n\t\t} else {\n\t\t\ty.jump(0);\n\t\t\tprogress.jump(1);\n\t\t}\n\t\tsetPhase(\"open\");\n\t}, [mode, attachWrapper, measure, progress, setPhase, stop, y]);\n\n\tuseEffect(\n\t\t() => () => {\n\t\t\tstop();\n\t\t\tresetWrapper();\n\t\t},\n\t\t[stop, resetWrapper],\n\t);\n\n\tconst beginDrag = useCallback(\n\t\t(drag: Drag, clientY: number) => {\n\t\t\tconst layout = layoutRef.current;\n\t\t\tconst sheet = popupRef.current;\n\t\t\tif (!layout || !sheet) return;\n\t\t\tstop();\n\t\t\tlandingRef.current = null;\n\t\t\tdrag.startY = clientY;\n\t\t\tdrag.startSheetY = y.get();\n\t\t\tdrag.sides = layout.snaps.map((snap) => sideOf(drag.startSheetY, snap));\n\t\t\tsetPhase(\"dragging\");\n\t\t\ttry {\n\t\t\t\tsheet.setPointerCapture(drag.pointerId);\n\t\t\t} catch {\n\t\t\t\t// The pointer may already be gone.\n\t\t\t}\n\t\t\twindow.getSelection()?.removeAllRanges();\n\t\t\tsuppressClickRef.current = true;\n\t\t},\n\t\t[setPhase, stop, y],\n\t);\n\n\t/** Settles on the first move past the slop: the sheet drags or the content scrolls. */\n\tconst decide = useCallback(\n\t\t(drag: Drag, clientX: number, clientY: number) => {\n\t\t\tconst dx = clientX - drag.startX;\n\t\t\tconst dy = clientY - drag.startY;\n\t\t\tif (Math.abs(dx) < DRAG_SLOP && Math.abs(dy) < DRAG_SLOP) return;\n\t\t\t// Axis lock: sideways swipes belong to carousels and the browser.\n\t\t\tif (Math.abs(dx) > Math.abs(dy)) {\n\t\t\t\tdrag.decided = \"none\";\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst layout = layoutRef.current;\n\t\t\tconst top = layout?.snaps[layout.snaps.length - 1] ?? 0;\n\t\t\tconst atFull = y.get() <= top + 1;\n\t\t\tconst scroller = drag.scroller;\n\t\t\tconst scrolls = scroller && (dy < 0 || scroller.scrollTop > 0);\n\t\t\tdrag.decided = atFull && scrolls ? \"none\" : \"sheet\";\n\t\t\tif (drag.decided === \"sheet\") beginDrag(drag, clientY);\n\t\t},\n\t\t[beginDrag, y],\n\t);\n\n\tconst release = useCallback(\n\t\t(drag: Drag) => {\n\t\t\tconst layout = layoutRef.current;\n\t\t\tif (!layout) return;\n\t\t\tconst { dismissible } = latest.current;\n\t\t\tconst velocity = clamp(y.getVelocity(), -MAX_VELOCITY, MAX_VELOCITY);\n\t\t\tconst current = y.get();\n\t\t\tconst lowest = layout.snaps[0] ?? 0;\n\t\t\tif (\n\t\t\t\tdismissible &&\n\t\t\t\tvelocity > DISMISS_VELOCITY &&\n\t\t\t\t(drag.fromLowest || current >= lowest)\n\t\t\t) {\n\t\t\t\trequestClose(\"flick\", velocity);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst projected = current + velocity * PROJECTION_SECONDS;\n\t\t\tlet nearest = 0;\n\t\t\tlayout.snaps.forEach((snap, index) => {\n\t\t\t\tif (\n\t\t\t\t\tMath.abs(snap - projected) <\n\t\t\t\t\tMath.abs((layout.snaps[nearest] ?? 0) - projected)\n\t\t\t\t) {\n\t\t\t\t\tnearest = index;\n\t\t\t\t}\n\t\t\t});\n\t\t\tconst nearestDistance = Math.abs(\n\t\t\t\t(layout.snaps[nearest] ?? 0) - projected,\n\t\t\t);\n\t\t\tif (\n\t\t\t\tdismissible &&\n\t\t\t\tMath.abs(layout.closed - projected) < nearestDistance\n\t\t\t) {\n\t\t\t\trequestClose(\"flick\", Math.max(velocity, 0));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcommitSnap(nearest, velocity);\n\t\t},\n\t\t[commitSnap, requestClose, y],\n\t);\n\n\tconst handlePointerDown = useCallback(\n\t\t(event: PointerEvent<HTMLDivElement>) => {\n\t\t\tconst { mode, handleOnly } = latest.current;\n\t\t\tif (mode !== \"bottom\" || !event.isPrimary) return;\n\t\t\tif (event.pointerType === \"mouse\" && event.button !== 0) return;\n\t\t\tconst phase = phaseRef.current;\n\t\t\tif (phase === \"closed\" || phase === \"closing\") return;\n\t\t\tconst target = event.target as HTMLElement;\n\t\t\tconst sheet = event.currentTarget;\n\t\t\tconst onHandle = Boolean(\n\t\t\t\ttarget.closest(\"[data-slot='snap-sheet-handle']\"),\n\t\t\t);\n\t\t\tif (handleOnly && !onHandle) return;\n\t\t\tif (!onHandle && target.closest(NO_DRAG_SELECTOR)) return;\n\t\t\tconst rect = sheet.getBoundingClientRect();\n\t\t\tsuppressClickRef.current = false;\n\t\t\tdragRef.current = {\n\t\t\t\tpointerId: event.pointerId,\n\t\t\t\tstartX: event.clientX,\n\t\t\t\tstartY: event.clientY,\n\t\t\t\tstartSheetY: y.get(),\n\t\t\t\t// CSS zoom and transforms scale client coordinates; work in local px.\n\t\t\t\tscale: rect.height / (sheet.offsetHeight || 1) || 1,\n\t\t\t\tscroller: onHandle ? null : findScroller(target, sheet),\n\t\t\t\tdecided: null,\n\t\t\t\tfromLowest: settledIndexRef.current === 0,\n\t\t\t\thitLimit: false,\n\t\t\t\tsides: [],\n\t\t\t};\n\t\t},\n\t\t[y],\n\t);\n\n\t// Follow the gesture on window: before it's decided, the pointer can leave\n\t// the sheet, and capturing on press would retarget clicks inside it.\n\tuseEffect(() => {\n\t\tif (!popup) return;\n\t\tconst onPointerMove = (event: globalThis.PointerEvent) => {\n\t\t\tconst drag = dragRef.current;\n\t\t\tif (!drag || drag.pointerId !== event.pointerId) return;\n\t\t\tif (drag.decided === null) decide(drag, event.clientX, event.clientY);\n\t\t\tif (drag.decided !== \"sheet\") return;\n\t\t\tconst layout = layoutRef.current;\n\t\t\tif (!layout) return;\n\t\t\tconst raw = drag.startSheetY + (event.clientY - drag.startY) / drag.scale;\n\t\t\tconst top = layout.snaps[layout.snaps.length - 1] ?? 0;\n\t\t\tconst lowest = layout.snaps[0] ?? 0;\n\t\t\tlet next = raw;\n\t\t\tif (raw < top) {\n\t\t\t\tnext = top - (top - raw) * RUBBER_BAND;\n\t\t\t} else if (!latest.current.dismissible && raw > lowest) {\n\t\t\t\tnext = lowest + (raw - lowest) * RUBBER_BAND;\n\t\t\t}\n\t\t\ty.set(Math.min(next, layout.closed));\n\t\t};\n\t\tconst onPointerUp = (event: globalThis.PointerEvent) => {\n\t\t\tconst drag = dragRef.current;\n\t\t\tif (!drag || drag.pointerId !== event.pointerId) return;\n\t\t\tdragRef.current = null;\n\t\t\tif (popup.hasPointerCapture(event.pointerId)) {\n\t\t\t\tpopup.releasePointerCapture(event.pointerId);\n\t\t\t}\n\t\t\tif (drag.decided === \"sheet\") release(drag);\n\t\t};\n\t\twindow.addEventListener(\"pointermove\", onPointerMove);\n\t\twindow.addEventListener(\"pointerup\", onPointerUp);\n\t\twindow.addEventListener(\"pointercancel\", onPointerUp);\n\t\treturn () => {\n\t\t\twindow.removeEventListener(\"pointermove\", onPointerMove);\n\t\t\twindow.removeEventListener(\"pointerup\", onPointerUp);\n\t\t\twindow.removeEventListener(\"pointercancel\", onPointerUp);\n\t\t};\n\t}, [popup, decide, release, y]);\n\n\t// iOS and Android start scrolling unless the first touchmove is cancelled.\n\tuseEffect(() => {\n\t\tif (!popup) return;\n\t\tconst onTouchMove = (event: TouchEvent) => {\n\t\t\tconst drag = dragRef.current;\n\t\t\tconst touch = event.touches[0];\n\t\t\tif (!drag || !touch) return;\n\t\t\tif (drag.decided === null) decide(drag, touch.clientX, touch.clientY);\n\t\t\tif (drag.decided === \"sheet\" && event.cancelable) event.preventDefault();\n\t\t};\n\t\tpopup.addEventListener(\"touchmove\", onTouchMove, { passive: false });\n\t\treturn () => popup.removeEventListener(\"touchmove\", onTouchMove);\n\t}, [popup, decide]);\n\n\tconst stepSnap = useCallback(\n\t\t(index: number) => {\n\t\t\tconst phase = phaseRef.current;\n\t\t\tif (phase === \"closed\" || phase === \"closing\" || phase === \"dragging\") {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcommitSnap(clamp(index, 0, latest.current.snapPoints.length - 1));\n\t\t},\n\t\t[commitSnap],\n\t);\n\n\tconst consumeClick = useCallback(() => {\n\t\tconst suppressed = suppressClickRef.current;\n\t\tsuppressClickRef.current = false;\n\t\treturn suppressed;\n\t}, []);\n\n\tconst shouldMoveFocus = useCallback(\n\t\t() => latest.current.modal || userOpenRef.current,\n\t\t[],\n\t);\n\n\tconst handleOpenChange = useCallback(\n\t\t(next: boolean, details: DialogPrimitive.Root.ChangeEventDetails) => {\n\t\t\tif (next) {\n\t\t\t\tuserOpenRef.current = true;\n\t\t\t\tsetOpen(true);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst userDismissal =\n\t\t\t\tdetails.reason === \"escape-key\" || details.reason === \"outside-press\";\n\t\t\tif (userDismissal && !latest.current.dismissible) return;\n\t\t\trequestClose(\"plain\");\n\t\t},\n\t\t[requestClose, setOpen],\n\t);\n\n\t// Opens that don't come through the trigger stay silent and keep focus.\n\tuseLayoutEffect(() => {\n\t\tif (!open) userOpenRef.current = false;\n\t}, [open]);\n\n\treturn (\n\t\t<SnapSheetContext.Provider\n\t\t\tvalue={{\n\t\t\t\ty,\n\t\t\t\toverlayOpacity,\n\t\t\t\tdialogScale,\n\t\t\t\tprogress,\n\t\t\t\tsheetX,\n\t\t\t\tmode,\n\t\t\t\tmodal,\n\t\t\t\tsnapIndex,\n\t\t\t\tsnapCount,\n\t\t\t\tsnapLabel: describeSnap(snapPoints, snapIndex),\n\t\t\t\tannouncement,\n\t\t\t\tsetPopup,\n\t\t\t\tcontainerRef,\n\t\t\t\tfloatingRef,\n\t\t\t\tshouldMoveFocus,\n\t\t\t\tstepSnap,\n\t\t\t\thandlePointerDown,\n\t\t\t\tconsumeClick,\n\t\t\t}}\n\t\t>\n\t\t\t<DialogPrimitive.Root\n\t\t\t\topen={rendered}\n\t\t\t\tonOpenChange={handleOpenChange}\n\t\t\t\tmodal={modal}\n\t\t\t\tdisablePointerDismissal={!modal || !dismissible}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</DialogPrimitive.Root>\n\t\t</SnapSheetContext.Provider>\n\t);\n}\n\nfunction SnapSheetTrigger(props: DialogPrimitive.Trigger.Props) {\n\treturn <DialogPrimitive.Trigger data-slot=\"snap-sheet-trigger\" {...props} />;\n}\n\nexport interface SnapSheetContentProps {\n\tclassName?: string;\n\toverlayClassName?: string;\n\t/**\n\t * Element to render into instead of `document.body`, such as a phone frame.\n\t * Give it `position: relative` and `overflow: clip`.\n\t */\n\tcontainer?: HTMLElement | RefObject<HTMLElement | null> | null;\n\t/** `attached` spans the width with rounded top corners; `floating` is inset and fully rounded. */\n\tvariant?: \"attached\" | \"floating\";\n\tchildren?: ReactNode;\n}\n\nfunction SnapSheetContent({\n\tclassName,\n\toverlayClassName,\n\tcontainer,\n\tvariant = \"attached\",\n\tchildren,\n}: SnapSheetContentProps) {\n\tconst {\n\t\ty,\n\t\toverlayOpacity,\n\t\tdialogScale,\n\t\tprogress,\n\t\tsheetX,\n\t\tmode,\n\t\tmodal,\n\t\tannouncement,\n\t\tsetPopup,\n\t\tcontainerRef,\n\t\tfloatingRef,\n\t\tshouldMoveFocus,\n\t\thandlePointerDown,\n\t} = useSnapSheet();\n\tconst contained = Boolean(container);\n\tconst floating = variant === \"floating\";\n\n\tuseLayoutEffect(() => {\n\t\tcontainerRef.current = resolveContainer(container);\n\t\tfloatingRef.current = floating;\n\t});\n\n\tconst style =\n\t\tmode === \"dialog\"\n\t\t\t? { opacity: progress, scale: dialogScale }\n\t\t\t: mode === \"sheet\"\n\t\t\t\t? { x: sheetX }\n\t\t\t\t: { y };\n\n\treturn (\n\t\t<DialogPrimitive.Portal container={container}>\n\t\t\t<DialogPrimitive.Backdrop\n\t\t\t\tdata-slot=\"snap-sheet-overlay\"\n\t\t\t\tforceRender\n\t\t\t\trender={<motion.div style={{ opacity: overlayOpacity }} />}\n\t\t\t\tclassName={cn(\n\t\t\t\t\t\"inset-0 z-50 bg-black/40\",\n\t\t\t\t\tcontained ? \"absolute\" : \"fixed\",\n\t\t\t\t\t!modal && \"pointer-events-none\",\n\t\t\t\t\toverlayClassName,\n\t\t\t\t)}\n\t\t\t/>\n\t\t\t<DialogPrimitive.Popup\n\t\t\t\tref={setPopup}\n\t\t\t\tdata-slot=\"snap-sheet-content\"\n\t\t\t\tdata-mode={mode}\n\t\t\t\tdata-variant={variant}\n\t\t\t\taria-modal={modal || undefined}\n\t\t\t\tinitialFocus={shouldMoveFocus}\n\t\t\t\trender={<motion.div style={style} />}\n\t\t\t\tonPointerDown={handlePointerDown}\n\t\t\t\tclassName={cn(\n\t\t\t\t\t\"group/sheet z-50 flex flex-col overscroll-contain border border-border/70 bg-background text-foreground outline-none\",\n\t\t\t\t\tcontained ? \"absolute\" : \"fixed\",\n\t\t\t\t\tmode === \"bottom\" && [\n\t\t\t\t\t\t\"touch-none will-change-transform data-[sheet-state=dragging]:select-none\",\n\t\t\t\t\t\t\"shadow-[0_-12px_40px_-16px_rgb(0_0_0/0.35)]\",\n\t\t\t\t\t\tfloating\n\t\t\t\t\t\t\t? \"inset-x-2 bottom-2 mx-auto max-w-xl rounded-[28px]\"\n\t\t\t\t\t\t\t: \"inset-x-0 bottom-0 mx-auto w-full max-w-xl rounded-t-[22px] border-b-0\",\n\t\t\t\t\t\tcontained\n\t\t\t\t\t\t\t? floating\n\t\t\t\t\t\t\t\t? \"h-[calc(100%-32px)]\"\n\t\t\t\t\t\t\t\t: \"h-[calc(100%-24px)]\"\n\t\t\t\t\t\t\t: floating\n\t\t\t\t\t\t\t\t? \"mb-[var(--snap-sheet-keyboard,0px)] h-[calc(100dvh-32px-var(--snap-sheet-keyboard,0px))]\"\n\t\t\t\t\t\t\t\t: \"mb-[var(--snap-sheet-keyboard,0px)] h-[calc(100dvh-24px-var(--snap-sheet-keyboard,0px))]\",\n\t\t\t\t\t],\n\t\t\t\t\tmode === \"dialog\" &&\n\t\t\t\t\t\t\"top-1/2 left-1/2 max-h-[calc(100dvh-4rem)] w-[calc(100%-2rem)] max-w-lg -translate-x-1/2 -translate-y-1/2 rounded-2xl pt-4 shadow-2xl\",\n\t\t\t\t\tmode === \"sheet\" &&\n\t\t\t\t\t\t\"inset-y-0 end-0 w-full max-w-md border-y-0 border-e-0 pt-4 shadow-2xl\",\n\t\t\t\t\tclassName,\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t\t<span aria-live=\"polite\" className=\"sr-only\">\n\t\t\t\t\t{announcement}\n\t\t\t\t</span>\n\t\t\t</DialogPrimitive.Popup>\n\t\t</DialogPrimitive.Portal>\n\t);\n}\n\nfunction SnapSheetHandle({\n\tclassName,\n\tonClick,\n\tonKeyDown,\n\t...props\n}: Omit<ComponentProps<\"button\">, \"children\">) {\n\tconst { mode, snapIndex, snapCount, snapLabel, stepSnap, consumeClick } =\n\t\tuseSnapSheet();\n\tif (mode !== \"bottom\") return null;\n\n\tconst handleClick = (event: MouseEvent<HTMLButtonElement>) => {\n\t\tonClick?.(event);\n\t\tif (consumeClick() || event.defaultPrevented) return;\n\t\t// Tapping or pressing Enter cycles through the snap points.\n\t\tstepSnap((snapIndex + 1) % snapCount);\n\t};\n\n\tconst handleKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {\n\t\tonKeyDown?.(event);\n\t\tif (event.defaultPrevented) return;\n\t\tconst targets: Record<string, number> = {\n\t\t\tArrowUp: snapIndex + 1,\n\t\t\tArrowRight: snapIndex + 1,\n\t\t\tArrowDown: snapIndex - 1,\n\t\t\tArrowLeft: snapIndex - 1,\n\t\t\tHome: 0,\n\t\t\tEnd: snapCount - 1,\n\t\t};\n\t\tconst target = targets[event.key];\n\t\tif (target === undefined) return;\n\t\tevent.preventDefault();\n\t\tstepSnap(target);\n\t};\n\n\treturn (\n\t\t<button\n\t\t\ttype=\"button\"\n\t\t\trole=\"slider\"\n\t\t\taria-label=\"Resize sheet\"\n\t\t\taria-orientation=\"vertical\"\n\t\t\taria-valuemin={0}\n\t\t\taria-valuemax={snapCount - 1}\n\t\t\taria-valuenow={snapIndex}\n\t\t\taria-valuetext={snapLabel}\n\t\t\tdata-slot=\"snap-sheet-handle\"\n\t\t\tonClick={handleClick}\n\t\t\tonKeyDown={handleKeyDown}\n\t\t\tclassName={cn(\n\t\t\t\t\"group/handle mx-auto flex h-6 w-16 shrink-0 cursor-grab touch-none items-center justify-center rounded-full outline-none focus-visible:ring-3 focus-visible:ring-ring/50 group-data-[sheet-state=dragging]/sheet:cursor-grabbing\",\n\t\t\t\tclassName,\n\t\t\t)}\n\t\t\t{...props}\n\t\t>\n\t\t\t<span className=\"h-[5px] w-9 rounded-full bg-muted-foreground/35 transition-[width,background-color] duration-200 ease-out group-hover/handle:bg-muted-foreground/50 group-data-[sheet-state=dragging]/sheet:w-11 group-data-[sheet-state=dragging]/sheet:bg-muted-foreground/60\" />\n\t\t</button>\n\t);\n}\n\nfunction SnapSheetTitle({ className, ...props }: DialogPrimitive.Title.Props) {\n\treturn (\n\t\t<DialogPrimitive.Title\n\t\t\tdata-slot=\"snap-sheet-title\"\n\t\t\tclassName={cn(\"font-semibold text-base text-foreground\", className)}\n\t\t\t{...props}\n\t\t/>\n\t);\n}\n\nfunction SnapSheetDescription({\n\tclassName,\n\t...props\n}: DialogPrimitive.Description.Props) {\n\treturn (\n\t\t<DialogPrimitive.Description\n\t\t\tdata-slot=\"snap-sheet-description\"\n\t\t\tclassName={cn(\"text-muted-foreground text-sm\", className)}\n\t\t\t{...props}\n\t\t/>\n\t);\n}\n\nfunction SnapSheetClose({\n\tclassName,\n\tchildren,\n\t...props\n}: DialogPrimitive.Close.Props) {\n\treturn (\n\t\t<DialogPrimitive.Close\n\t\t\tdata-slot=\"snap-sheet-close\"\n\t\t\tclassName={cn(\n\t\t\t\t!children &&\n\t\t\t\t\t\"inline-flex size-8 cursor-pointer items-center justify-center rounded-full bg-muted text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:ring-3 focus-visible:ring-ring/50\",\n\t\t\t\tclassName,\n\t\t\t)}\n\t\t\t{...props}\n\t\t>\n\t\t\t{children ?? (\n\t\t\t\t<>\n\t\t\t\t\t<XIcon className=\"size-4\" />\n\t\t\t\t\t<span className=\"sr-only\">Close</span>\n\t\t\t\t</>\n\t\t\t)}\n\t\t</DialogPrimitive.Close>\n\t);\n}\n\nSnapSheet.Trigger = SnapSheetTrigger;\nSnapSheet.Content = SnapSheetContent;\nSnapSheet.Handle = SnapSheetHandle;\nSnapSheet.Title = SnapSheetTitle;\nSnapSheet.Description = SnapSheetDescription;\nSnapSheet.Close = SnapSheetClose;\n\nexport {\n\tSnapSheet,\n\tSnapSheetClose,\n\tSnapSheetContent,\n\tSnapSheetDescription,\n\tSnapSheetHandle,\n\tSnapSheetTitle,\n\tSnapSheetTrigger,\n};\n\nexport default SnapSheet;\n",
      "type": "registry:component",
      "target": "@components/snap-sheet.tsx"
    }
  ],
  "meta": {
    "createdAt": "2026-10-24",
    "image": "https://cdn.tentui.com/images/components/snap-sheet",
    "video": "https://cdn.tentui.com/videos/components/snap-sheet"
  },
  "docs": "https://tentui.com/components/snap-sheet",
  "categories": [
    "overlays"
  ],
  "type": "registry:component"
}