{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "swipe-actions",
  "title": "Swipe Actions",
  "description": "iOS-style list rows you swipe to reveal actions, with threshold haptics, a full-swipe snap, and keyboard support.",
  "dependencies": [
    "@rexa-developer/tiks",
    "lucide-react",
    "motion",
    "web-haptics"
  ],
  "files": [
    {
      "path": "src/registry/components/swipe-actions/swipe-actions.tsx",
      "content": "\"use client\";\n\nimport { useTiks } from \"@rexa-developer/tiks/react\";\nimport { Ellipsis } from \"lucide-react\";\nimport {\n\ttype AnimationPlaybackControls,\n\tanimate,\n\tLayoutGroup,\n\ttype MotionValue,\n\tmotion,\n\tuseMotionValue,\n\tuseReducedMotion,\n\tuseTransform,\n} from \"motion/react\";\nimport {\n\tcreateContext,\n\ttype FocusEvent,\n\ttype KeyboardEvent,\n\ttype MouseEvent,\n\ttype PointerEvent,\n\ttype ReactNode,\n\tuseCallback,\n\tuseContext,\n\tuseEffect,\n\tuseId,\n\tuseLayoutEffect,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n} from \"react\";\nimport { useWebHaptics } from \"web-haptics/react\";\nimport { cn } from \"@/lib/utils\";\n\nconst snapSpring = { type: \"spring\", stiffness: 500, damping: 40 } as const;\nconst armSpring = { type: \"spring\", stiffness: 700, damping: 35 } as const;\nconst collapseTransition = { duration: 0.22, ease: \"easeOut\" } as const;\nconst fadeTransition = { duration: 0.12, ease: \"easeOut\" } as const;\nconst popTransition = { duration: 0.28, ease: \"easeOut\" } as const;\n\n/** Pointer travel, in px, before a gesture commits to an axis. */\nconst AXIS_LOCK = 8;\n/** Share of the action group a release must pass to stay open. */\nconst REVEAL_RATIO = 0.4;\n/** Release speed, in px/s, that fires the outermost action. */\nconst FLICK_VELOCITY = 800;\n/** Fastest release, in px/s, so one jumpy pointer event can't fling the row. */\nconst MAX_VELOCITY = 4000;\n/** Seconds of release velocity added when deciding to open or close. */\nconst PROJECT_SECONDS = 0.08;\n/** Resistance past the furthest travel. */\nconst ELASTIC = 0.1;\n/** Distance, in px, a drag must back off a line before it can cross again. */\nconst HYSTERESIS = 12;\n/** Most of the row an action group may cover when revealed. */\nconst MAX_GROUP_RATIO = 0.75;\n/** Minimum gap, in px, between the revealed actions and the arm line. */\nconst MIN_ARM_GAP = 32;\n/** Ms after opening that pointer clicks on actions are ignored, so a double-click on ⋯ can't fire one. */\nconst OPEN_GUARD_MS = 350;\n\ntype Side = \"leading\" | \"trailing\";\ntype RowState =\n\t| \"idle\"\n\t| \"dragging\"\n\t| \"revealed\"\n\t| \"armed\"\n\t| \"committing\"\n\t| \"collapsed\"\n\t| \"disabled\";\n\nexport type SwipeActionTone = \"default\" | \"blue\" | \"amber\" | \"destructive\";\n\nexport interface SwipeAction {\n\tid: string;\n\t/** Visible label and accessible name. */\n\tlabel: string;\n\ticon?: ReactNode;\n\ttone?: SwipeActionTone;\n\t/** Collapse the row before calling `onAction`. */\n\tdestructive?: boolean;\n\t/** Ask \"Confirm?\" in place before firing. */\n\tconfirm?: boolean;\n\t/** Live region message once the action fires. Defaults to `label: row label`. */\n\tannounce?: string;\n\t/** Rejecting springs the row back and plays an error. */\n\tonAction: () => void | Promise<void>;\n}\n\nexport interface SwipeActionsProps {\n\tchildren: ReactNode;\n\t/** Revealed by swiping toward the end edge, listed from the start edge in. */\n\tleading?: SwipeAction[];\n\t/** Revealed by swiping toward the start edge, listed from the content out. */\n\ttrailing?: SwipeAction[];\n\t/** Fire the outermost action on a long swipe or a fast flick. */\n\tfullSwipe?: boolean;\n\t/** Share of the row width that arms a full swipe. */\n\tfullSwipeThreshold?: number;\n\t/** Width of each action, in px. Shrinks to fit narrow rows. */\n\tactionWidth?: number;\n\t/** Show a ⋯ button on hover that reveals the actions. */\n\tshowHandle?: boolean;\n\t/** Show labels under icons. Inherits from `SwipeList`. */\n\tshowLabels?: boolean;\n\t/** Play a toggle when arming and a swoosh or pop when an action fires. */\n\tsound?: boolean;\n\t/** Trigger haptics on supported devices. */\n\thaptics?: boolean;\n\tdisabled?: boolean;\n\t/** Accessible name for the row, used in announcements. */\n\tlabel: string;\n\tclassName?: string;\n}\n\nexport interface SwipeListProps {\n\tchildren: ReactNode;\n\t/** `inset` rounded cards with a gap, or `plain` edge-to-edge rows. */\n\tvariant?: \"inset\" | \"plain\";\n\t/** Show labels under icons for every row. */\n\tshowLabels?: boolean;\n\t/** Accessible name for the list. */\n\tlabel?: string;\n\tclassName?: string;\n}\n\nconst tones: Record<SwipeActionTone, string> = {\n\tdefault: \"bg-zinc-500 text-white dark:bg-zinc-600\",\n\tblue: \"bg-blue-500 text-white\",\n\tamber: \"bg-amber-500 text-white\",\n\tdestructive: \"bg-red-500 text-white\",\n};\n\ntype SwipeListContextValue = {\n\tvariant: \"inset\" | \"plain\";\n\tshowLabels: boolean;\n\tregister: (id: string, close: () => void) => () => void;\n\tnotifyOpen: (id: string) => void;\n\tannounce: (message: string) => void;\n};\n\nconst SwipeListContext = createContext<SwipeListContextValue | null>(null);\n\nfunction clamp(value: number, min: number, max: number) {\n\treturn Math.min(Math.max(value, min), max);\n}\n\n/** Polite status region; a counter forces repeat messages to be read again. */\nfunction useAnnouncer() {\n\tconst [message, setMessage] = useState({ text: \"\", count: 0 });\n\tconst region = (\n\t\t<span role=\"status\" aria-live=\"polite\" className=\"sr-only\">\n\t\t\t{message.text}\n\t\t\t{message.count % 2 ? \"​\" : \"\"}\n\t\t</span>\n\t);\n\tconst announce = useCallback(\n\t\t(text: string) =>\n\t\t\tsetMessage((previous) => ({ text, count: previous.count + 1 })),\n\t\t[],\n\t);\n\treturn { region, announce };\n}\n\nexport function SwipeList({\n\tchildren,\n\tvariant = \"plain\",\n\tshowLabels = true,\n\tlabel,\n\tclassName,\n}: SwipeListProps) {\n\tconst rowsRef = useRef(new Map<string, () => void>());\n\tconst { region, announce } = useAnnouncer();\n\n\tconst value = useMemo<SwipeListContextValue>(\n\t\t() => ({\n\t\t\tvariant,\n\t\t\tshowLabels,\n\t\t\tregister: (id, close) => {\n\t\t\t\trowsRef.current.set(id, close);\n\t\t\t\treturn () => {\n\t\t\t\t\trowsRef.current.delete(id);\n\t\t\t\t};\n\t\t\t},\n\t\t\tnotifyOpen: (id) => {\n\t\t\t\tfor (const [other, close] of rowsRef.current) {\n\t\t\t\t\tif (other !== id) close();\n\t\t\t\t}\n\t\t\t},\n\t\t\tannounce,\n\t\t}),\n\t\t[variant, showLabels, announce],\n\t);\n\n\treturn (\n\t\t<SwipeListContext.Provider value={value}>\n\t\t\t<LayoutGroup>\n\t\t\t\t<div\n\t\t\t\t\trole=\"list\"\n\t\t\t\t\taria-label={label}\n\t\t\t\t\tdata-slot=\"swipe-list\"\n\t\t\t\t\tdata-variant={variant}\n\t\t\t\t\tclassName={cn(\"flex flex-col\", className)}\n\t\t\t\t>\n\t\t\t\t\t{children}\n\t\t\t\t</div>\n\t\t\t</LayoutGroup>\n\t\t\t{region}\n\t\t</SwipeListContext.Provider>\n\t);\n}\n\nfunction ActionButton({\n\taction,\n\tside,\n\tcount,\n\tsign,\n\tx,\n\tstretch,\n\tpopScale,\n\tstretchTarget,\n\twidth: actionWidth,\n\tshowLabel,\n\treduceMotion,\n\tconfirming,\n\tonPress,\n}: {\n\taction: SwipeAction;\n\tside: Side;\n\tcount: number;\n\tsign: number;\n\tx: MotionValue<number>;\n\tstretch: MotionValue<number>;\n\tpopScale: MotionValue<number>;\n\tstretchTarget: boolean;\n\twidth: number;\n\tshowLabel: boolean;\n\treduceMotion: boolean;\n\tconfirming: boolean;\n\tonPress: (event: MouseEvent<HTMLButtonElement>) => void;\n}) {\n\t// Buttons split the revealed width; the stretch target eats the others' share.\n\tconst width = useTransform([x, stretch], ([value, grow]: number[]) => {\n\t\tconst revealed = Math.max(0, value * sign);\n\t\tif (count === 1) return revealed;\n\t\tconst share = (revealed / count) * (1 - grow);\n\t\treturn stretchTarget ? revealed - share * (count - 1) : share;\n\t});\n\tconst progress = useTransform(width, (value) =>\n\t\tclamp(value / actionWidth, 0, 1),\n\t);\n\tconst iconScale = useTransform(progress, (value) =>\n\t\treduceMotion ? 1 : 0.6 + 0.4 * value,\n\t);\n\tconst opacity = useTransform(progress, (value) => (reduceMotion ? 1 : value));\n\n\treturn (\n\t\t<motion.button\n\t\t\ttype=\"button\"\n\t\t\tdata-slot=\"swipe-actions-action\"\n\t\t\tdata-tone={action.tone ?? \"default\"}\n\t\t\tdata-confirming={confirming || undefined}\n\t\t\taria-label={confirming ? `Confirm ${action.label}` : undefined}\n\t\t\tonClick={onPress}\n\t\t\tstyle={{ width }}\n\t\t\tclassName={cn(\n\t\t\t\t\"relative flex h-full min-w-0 cursor-pointer overflow-hidden outline-none focus-visible:ring-2 focus-visible:ring-white/80 focus-visible:ring-inset\",\n\t\t\t\tside === \"leading\" ? \"justify-end\" : \"justify-start\",\n\t\t\t\ttones[action.tone ?? \"default\"],\n\t\t\t)}\n\t\t>\n\t\t\t<motion.span\n\t\t\t\tstyle={{ width: actionWidth, opacity }}\n\t\t\t\tclassName=\"flex h-full shrink-0 flex-col items-center justify-center gap-1 px-1\"\n\t\t\t>\n\t\t\t\t{action.icon ? (\n\t\t\t\t\t<motion.span\n\t\t\t\t\t\taria-hidden\n\t\t\t\t\t\tstyle={{ scale: iconScale }}\n\t\t\t\t\t\tclassName=\"flex [&_svg:not([class*='size-'])]:size-5\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<motion.span\n\t\t\t\t\t\t\tstyle={{ scale: stretchTarget ? popScale : 1 }}\n\t\t\t\t\t\t\tclassName=\"flex\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{action.icon}\n\t\t\t\t\t\t</motion.span>\n\t\t\t\t\t</motion.span>\n\t\t\t\t) : null}\n\t\t\t\t<span\n\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t\"max-w-full truncate font-medium text-xs leading-none\",\n\t\t\t\t\t\t!showLabel && !confirming && action.icon && \"sr-only\",\n\t\t\t\t\t)}\n\t\t\t\t>\n\t\t\t\t\t{confirming ? \"Confirm?\" : action.label}\n\t\t\t\t</span>\n\t\t\t</motion.span>\n\t\t</motion.button>\n\t);\n}\n\nexport function SwipeActions({\n\tchildren,\n\tleading = [],\n\ttrailing = [],\n\tfullSwipe = true,\n\tfullSwipeThreshold = 0.6,\n\tactionWidth = 76,\n\tshowHandle = true,\n\tshowLabels: showLabelsProp,\n\tsound = true,\n\thaptics = true,\n\tdisabled = false,\n\tlabel,\n\tclassName,\n}: SwipeActionsProps) {\n\tconst list = useContext(SwipeListContext);\n\tconst variant = list?.variant ?? \"plain\";\n\tconst showLabels = showLabelsProp ?? list?.showLabels ?? true;\n\tconst id = useId();\n\tconst reduceMotion = useReducedMotion() ?? false;\n\tconst { trigger: haptic } = useWebHaptics();\n\tconst {\n\t\ttoggle: playToggle,\n\t\tswoosh: playSwoosh,\n\t\tpop: playPop,\n\t\terror: playError,\n\t} = useTiks({\n\t\t// Sound stays on under reduced motion; only movement is reduced.\n\t\trespectReducedMotion: false,\n\t});\n\tconst { region, announce: announceLocally } = useAnnouncer();\n\tconst announce = list?.announce ?? announceLocally;\n\n\tconst collapserRef = useRef<HTMLDivElement>(null);\n\tconst rootRef = useRef<HTMLDivElement>(null);\n\tconst x = useMotionValue(0);\n\tconst stretch = useMotionValue(0);\n\tconst popScale = useMotionValue(1);\n\tconst surfaceOpacity = useMotionValue(1);\n\n\tconst [openSide, setOpenSide] = useState<Side | null>(null);\n\tconst [confirming, setConfirming] = useState<string | null>(null);\n\tconst [rowWidth, setRowWidth] = useState(0);\n\tconst [dir, setDir] = useState(1);\n\n\tconst openRef = useRef<Side | null>(null);\n\tconst busyRef = useRef(false);\n\tconst suppressClickRef = useRef(false);\n\tconst openedAtRef = useRef(0);\n\tconst xAnimationRef = useRef<AnimationPlaybackControls | null>(null);\n\tconst savedBoxRef = useRef<{\n\t\theight: number;\n\t\tpaddingTop: string;\n\t\tpaddingBottom: string;\n\t} | null>(null);\n\tconst cuesRef = useRef({\n\t\tside: null as Side | null,\n\t\tpastReveal: false,\n\t\tarmed: false,\n\t});\n\tconst dragRef = useRef<{\n\t\tpointerId: number;\n\t\tstartX: number;\n\t\tstartY: number;\n\t\torigin: number;\n\t\tlocked: boolean;\n\t\tscale: number;\n\t} | null>(null);\n\n\tconst actionsOf = (side: Side) => (side === \"leading\" ? leading : trailing);\n\t/** +1 when the side opens by moving content right. Flips in RTL. */\n\tconst signOf = (side: Side) => (side === \"leading\" ? dir : -dir);\n\tconst sideOf = (value: number): Side | null =>\n\t\tvalue === 0 ? null : value * dir > 0 ? \"leading\" : \"trailing\";\n\tconst outermostOf = (side: Side) => {\n\t\tconst actions = actionsOf(side);\n\t\treturn side === \"leading\" ? actions[0] : actions[actions.length - 1];\n\t};\n\tconst widthOf = (side: Side) => {\n\t\tconst count = actionsOf(side).length;\n\t\tif (!count || !rowWidth) return actionWidth;\n\t\treturn Math.min(actionWidth, (rowWidth * MAX_GROUP_RATIO) / count);\n\t};\n\tconst revealOf = (side: Side) => widthOf(side) * actionsOf(side).length;\n\tconst armAtOf = (side: Side) =>\n\t\tMath.max(fullSwipeThreshold * rowWidth, revealOf(side) + MIN_ARM_GAP);\n\n\tconst setRowState = (state: RowState) => {\n\t\tif (rootRef.current) rootRef.current.dataset.state = state;\n\t};\n\n\tconst moveTo = (target: number, velocity = 0) => {\n\t\txAnimationRef.current?.stop();\n\t\txAnimationRef.current = null;\n\t\tif (reduceMotion) {\n\t\t\tif (x.get() === target) return;\n\t\t\t// No travel: the row reappears in place with a short fade.\n\t\t\tx.jump(target);\n\t\t\tsurfaceOpacity.jump(0);\n\t\t\tanimate(surfaceOpacity, 1, fadeTransition);\n\t\t\treturn;\n\t\t}\n\t\txAnimationRef.current = animate(x, target, {\n\t\t\t...snapSpring,\n\t\t\tvelocity,\n\t\t\trestDelta: 0.5,\n\t\t});\n\t};\n\n\tconst setStretch = (on: boolean) => {\n\t\tif (reduceMotion) stretch.jump(on ? 1 : 0);\n\t\telse animate(stretch, on ? 1 : 0, armSpring);\n\t};\n\n\tconst pop = () => {\n\t\tif (!reduceMotion) animate(popScale, [1, 1.15, 1], popTransition);\n\t};\n\n\tconst open = (side: Side, velocity = 0) => {\n\t\topenedAtRef.current = performance.now();\n\t\topenRef.current = side;\n\t\tsetOpenSide(side);\n\t\tlist?.notifyOpen(id);\n\t\tsetRowState(\"revealed\");\n\t\tmoveTo(signOf(side) * revealOf(side), velocity);\n\t};\n\n\tconst close = (velocity = 0) => {\n\t\topenRef.current = null;\n\t\tsetOpenSide(null);\n\t\tsetConfirming(null);\n\t\tcuesRef.current.armed = false;\n\t\tsetStretch(false);\n\t\tif (!busyRef.current) setRowState(\"idle\");\n\t\tmoveTo(0, velocity);\n\t};\n\n\t/** Keeps focus out of a tray that is about to go inert. */\n\tconst reclaimFocus = () => {\n\t\tconst root = rootRef.current;\n\t\tif (\n\t\t\troot?.contains(document.activeElement) &&\n\t\t\tdocument.activeElement !== root\n\t\t)\n\t\t\troot.focus({ preventScroll: true });\n\t};\n\n\tconst collapse = async () => {\n\t\tconst element = collapserRef.current;\n\t\tif (!element) return;\n\t\tconst style = getComputedStyle(element);\n\t\tsavedBoxRef.current = {\n\t\t\theight: element.offsetHeight,\n\t\t\tpaddingTop: style.paddingTop,\n\t\t\tpaddingBottom: style.paddingBottom,\n\t\t};\n\t\tif (reduceMotion) {\n\t\t\tawait animate(element, { opacity: 0 }, fadeTransition);\n\t\t\tObject.assign(element.style, {\n\t\t\t\theight: \"0px\",\n\t\t\t\tpaddingTop: \"0px\",\n\t\t\t\tpaddingBottom: \"0px\",\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tawait animate(\n\t\t\telement,\n\t\t\t{\n\t\t\t\theight: [savedBoxRef.current.height, 0],\n\t\t\t\tpaddingTop: [savedBoxRef.current.paddingTop, \"0px\"],\n\t\t\t\tpaddingBottom: [savedBoxRef.current.paddingBottom, \"0px\"],\n\t\t\t\topacity: [1, 0],\n\t\t\t},\n\t\t\tcollapseTransition,\n\t\t);\n\t};\n\n\tconst expand = async () => {\n\t\tconst element = collapserRef.current;\n\t\tconst saved = savedBoxRef.current;\n\t\tif (!element || !saved) return;\n\t\tawait animate(\n\t\t\telement,\n\t\t\t{\n\t\t\t\theight: saved.height,\n\t\t\t\tpaddingTop: saved.paddingTop,\n\t\t\t\tpaddingBottom: saved.paddingBottom,\n\t\t\t\topacity: 1,\n\t\t\t},\n\t\t\treduceMotion ? fadeTransition : collapseTransition,\n\t\t);\n\t\tfor (const property of [\n\t\t\t\"height\",\n\t\t\t\"padding-top\",\n\t\t\t\"padding-bottom\",\n\t\t\t\"opacity\",\n\t\t])\n\t\t\telement.style.removeProperty(property);\n\t\tsavedBoxRef.current = null;\n\t};\n\n\tconst fail = (action: SwipeAction) => {\n\t\tif (sound) playError();\n\t\tif (haptics) void haptic(\"error\");\n\t\tannounce(`${action.label} failed: ${label}`);\n\t};\n\n\t/** The next row's root, so focus has somewhere to go when this one leaves. */\n\tconst neighbourRow = () => {\n\t\tconst item = collapserRef.current?.parentElement;\n\t\tconst sibling = item?.nextElementSibling ?? item?.previousElementSibling;\n\t\treturn sibling?.querySelector<HTMLElement>('[data-slot=\"swipe-actions\"]');\n\t};\n\n\tconst fire = async (side: Side, action: SwipeAction, velocity = 0) => {\n\t\tif (busyRef.current || disabled) return;\n\t\tconst sign = signOf(side);\n\n\t\tif (action.confirm && confirming !== action.id) {\n\t\t\t// First press asks in place; the action fills the group.\n\t\t\tcuesRef.current.armed = false;\n\t\t\topenedAtRef.current = performance.now();\n\t\t\tsetConfirming(action.id);\n\t\t\topenRef.current = side;\n\t\t\tsetOpenSide(side);\n\t\t\tlist?.notifyOpen(id);\n\t\t\tsetRowState(\"revealed\");\n\t\t\tsetStretch(true);\n\t\t\tpop();\n\t\t\tif (sound) playToggle(true);\n\t\t\tif (haptics) void haptic(\"medium\");\n\t\t\tmoveTo(sign * revealOf(side), velocity);\n\t\t\treturn;\n\t\t}\n\n\t\tbusyRef.current = true;\n\t\tsetRowState(\"committing\");\n\t\tif (action.destructive) {\n\t\t\tif (sound) playPop();\n\t\t\tif (haptics) void haptic(\"rigid\");\n\t\t} else {\n\t\t\tif (sound) playSwoosh();\n\t\t\tif (haptics) void haptic(\"success\");\n\t\t}\n\t\tannounce(action.announce ?? `${action.label}: ${label}`);\n\n\t\tif (!action.destructive) {\n\t\t\treclaimFocus();\n\t\t\tbusyRef.current = false;\n\t\t\tclose(velocity);\n\t\t\tsetRowState(\"committing\");\n\t\t\ttry {\n\t\t\t\tawait action.onAction();\n\t\t\t} catch {\n\t\t\t\tfail(action);\n\t\t\t} finally {\n\t\t\t\tif (!openRef.current && !dragRef.current) setRowState(\"idle\");\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst hadFocus = rootRef.current?.contains(document.activeElement);\n\t\topenRef.current = null;\n\t\tsetOpenSide(null);\n\t\tsetConfirming(null);\n\t\tif (!reduceMotion) {\n\t\t\txAnimationRef.current?.stop();\n\t\t\txAnimationRef.current = animate(x, sign * rowWidth, {\n\t\t\t\t...snapSpring,\n\t\t\t\tvelocity,\n\t\t\t});\n\t\t}\n\t\tawait collapse();\n\t\tsetRowState(\"collapsed\");\n\t\tif (hadFocus)\n\t\t\t(neighbourRow() ?? rootRef.current)?.focus({ preventScroll: true });\n\t\ttry {\n\t\t\tawait action.onAction();\n\t\t} catch {\n\t\t\tfail(action);\n\t\t\txAnimationRef.current?.stop();\n\t\t\tx.jump(0);\n\t\t\tcuesRef.current.armed = false;\n\t\t\tstretch.jump(0);\n\t\t\tawait expand();\n\t\t\tbusyRef.current = false;\n\t\t\tsetRowState(\"idle\");\n\t\t}\n\t};\n\n\t// Latest handlers for the imperative listeners, so they never re-bind.\n\tconst api = useRef({ close, track: (_value: number) => {} });\n\tuseLayoutEffect(() => {\n\t\tapi.current = {\n\t\t\tclose,\n\t\t\t// Threshold cues, only while a finger or mouse drives the row.\n\t\t\ttrack: (value) => {\n\t\t\t\tif (!dragRef.current?.locked) return;\n\t\t\t\tconst cues = cuesRef.current;\n\t\t\t\tconst side = sideOf(value);\n\t\t\t\tif (side !== cues.side) {\n\t\t\t\t\tcues.side = side;\n\t\t\t\t\tcues.pastReveal = false;\n\t\t\t\t}\n\t\t\t\tif (!side) return;\n\t\t\t\tconst distance = Math.abs(value);\n\t\t\t\tconst revealLine = revealOf(side) * REVEAL_RATIO;\n\t\t\t\tif (!cues.pastReveal && distance >= revealLine) {\n\t\t\t\t\tcues.pastReveal = true;\n\t\t\t\t\tif (haptics) void haptic(\"selection\");\n\t\t\t\t} else if (cues.pastReveal && distance < revealLine - HYSTERESIS) {\n\t\t\t\t\tcues.pastReveal = false;\n\t\t\t\t}\n\t\t\t\tif (!fullSwipe) return;\n\t\t\t\tconst armAt = armAtOf(side);\n\t\t\t\tif (!cues.armed && distance >= armAt) {\n\t\t\t\t\tcues.armed = true;\n\t\t\t\t\tsetRowState(\"armed\");\n\t\t\t\t\tif (sound) playToggle(true);\n\t\t\t\t\tif (haptics) void haptic(\"medium\");\n\t\t\t\t\tif (!reduceMotion) {\n\t\t\t\t\t\tanimate(stretch, 1, armSpring);\n\t\t\t\t\t\tpop();\n\t\t\t\t\t}\n\t\t\t\t} else if (cues.armed && distance < armAt - HYSTERESIS) {\n\t\t\t\t\tcues.armed = false;\n\t\t\t\t\tsetRowState(\"dragging\");\n\t\t\t\t\tif (sound) playToggle(false);\n\t\t\t\t\tif (haptics) void haptic(\"soft\");\n\t\t\t\t\tif (!reduceMotion) animate(stretch, 0, armSpring);\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t});\n\n\tuseEffect(() => x.on(\"change\", (value) => api.current.track(value)), [x]);\n\n\tuseEffect(() => {\n\t\tif (!list) return;\n\t\treturn list.register(id, () => {\n\t\t\tif (openRef.current) api.current.close();\n\t\t});\n\t}, [list, id]);\n\n\t// Row size and direction.\n\tuseLayoutEffect(() => {\n\t\tconst root = rootRef.current;\n\t\tif (!root) return;\n\t\tconst measure = () => {\n\t\t\tsetDir(getComputedStyle(root).direction === \"rtl\" ? -1 : 1);\n\t\t\tsetRowWidth(root.offsetWidth);\n\t\t};\n\t\tmeasure();\n\t\tconst observer = new ResizeObserver(measure);\n\t\tobserver.observe(root);\n\t\treturn () => observer.disconnect();\n\t}, []);\n\n\t// A resize while open keeps the actions fully revealed.\n\t// biome-ignore lint/correctness/useExhaustiveDependencies: only re-anchor on resize\n\tuseEffect(() => {\n\t\tconst side = openRef.current;\n\t\tif (!side || dragRef.current || busyRef.current) return;\n\t\txAnimationRef.current?.stop();\n\t\tx.jump(signOf(side) * revealOf(side));\n\t}, [rowWidth, dir]);\n\n\t// Tapping elsewhere or scrolling closes an open row.\n\tuseEffect(() => {\n\t\tif (!openSide) return;\n\t\tconst onPointerDown = (event: globalThis.PointerEvent) => {\n\t\t\tif (!rootRef.current?.contains(event.target as Node)) api.current.close();\n\t\t};\n\t\tconst onScroll = (event: Event) => {\n\t\t\tif (dragRef.current?.locked) return;\n\t\t\tif (rootRef.current?.contains(event.target as Node)) return;\n\t\t\tapi.current.close();\n\t\t};\n\t\tdocument.addEventListener(\"pointerdown\", onPointerDown, true);\n\t\twindow.addEventListener(\"scroll\", onScroll, true);\n\t\treturn () => {\n\t\t\tdocument.removeEventListener(\"pointerdown\", onPointerDown, true);\n\t\t\twindow.removeEventListener(\"scroll\", onScroll, true);\n\t\t};\n\t}, [openSide]);\n\n\t// iOS can still scroll the page under a captured pointer; block it mid-drag.\n\tuseEffect(() => {\n\t\tconst root = rootRef.current;\n\t\tif (!root) return;\n\t\tconst onTouchMove = (event: TouchEvent) => {\n\t\t\tif (dragRef.current?.locked) event.preventDefault();\n\t\t};\n\t\troot.addEventListener(\"touchmove\", onTouchMove, { passive: false });\n\t\treturn () => root.removeEventListener(\"touchmove\", onTouchMove);\n\t}, []);\n\n\tuseEffect(() => () => xAnimationRef.current?.stop(), []);\n\n\t/** Follows the pointer, with resistance past the furthest travel. */\n\tconst resist = (raw: number) => {\n\t\tconst side = sideOf(raw);\n\t\tif (!side || !actionsOf(side).length) return 0;\n\t\tconst sign = signOf(side);\n\t\tconst distance = raw * sign;\n\t\tconst max = fullSwipe ? rowWidth : revealOf(side);\n\t\tif (distance <= max) return raw;\n\t\treturn sign * (reduceMotion ? max : max + (distance - max) * ELASTIC);\n\t};\n\n\tconst release = () => {\n\t\tconst value = x.get();\n\t\tconst side = sideOf(value);\n\t\tconst velocity = clamp(x.getVelocity(), -MAX_VELOCITY, MAX_VELOCITY);\n\t\tif (!side) return close(velocity);\n\t\tconst sign = signOf(side);\n\t\tconst distance = value * sign;\n\t\tconst speed = velocity * sign;\n\t\tconst reveal = revealOf(side);\n\t\tconst outermost = outermostOf(side);\n\t\tif (\n\t\t\tfullSwipe &&\n\t\t\toutermost &&\n\t\t\t(cuesRef.current.armed || (speed > FLICK_VELOCITY && distance >= reveal))\n\t\t) {\n\t\t\t// A flick skips the arm line, so stretch the outermost action here.\n\t\t\tif (!cuesRef.current.armed && !reduceMotion)\n\t\t\t\tanimate(stretch, 1, armSpring);\n\t\t\tvoid fire(side, outermost, velocity);\n\t\t\treturn;\n\t\t}\n\t\tconst projected = distance + speed * PROJECT_SECONDS;\n\t\tif (projected >= reveal * REVEAL_RATIO) open(side, velocity);\n\t\telse close(velocity);\n\t};\n\n\tconst handlePointerDown = (event: PointerEvent<HTMLDivElement>) => {\n\t\tif (disabled || busyRef.current || event.button !== 0 || !event.isPrimary)\n\t\t\treturn;\n\t\tconst root = event.currentTarget;\n\t\tconst rect = root.getBoundingClientRect();\n\t\tdragRef.current = {\n\t\t\tpointerId: event.pointerId,\n\t\t\tstartX: event.clientX,\n\t\t\tstartY: event.clientY,\n\t\t\torigin: x.get(),\n\t\t\tlocked: false,\n\t\t\t// CSS zoom and transforms scale client coordinates; work in local px.\n\t\t\tscale: rect.width / (root.offsetWidth || 1) || 1,\n\t\t};\n\t};\n\n\tconst handlePointerMove = (event: PointerEvent<HTMLDivElement>) => {\n\t\tconst drag = dragRef.current;\n\t\tif (!drag || drag.pointerId !== event.pointerId) return;\n\t\tconst dx = (event.clientX - drag.startX) / drag.scale;\n\t\tif (!drag.locked) {\n\t\t\tconst dy = (event.clientY - drag.startY) / drag.scale;\n\t\t\tif (Math.max(Math.abs(dx), Math.abs(dy)) < AXIS_LOCK) return;\n\t\t\tif (Math.abs(dy) > Math.abs(dx)) {\n\t\t\t\t// Vertical: leave the gesture to the page.\n\t\t\t\tdragRef.current = null;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst root = event.currentTarget;\n\t\t\troot.setPointerCapture(event.pointerId);\n\t\t\troot.dataset.dragging = \"\";\n\t\t\txAnimationRef.current?.stop();\n\t\t\txAnimationRef.current = null;\n\t\t\tdrag.locked = true;\n\t\t\t// Count travel from the lock line so a fast first move isn't lost.\n\t\t\tdrag.startX += Math.sign(dx) * AXIS_LOCK * drag.scale;\n\t\t\tdrag.origin = x.get();\n\t\t\tconst side = sideOf(drag.origin);\n\t\t\tcuesRef.current = {\n\t\t\t\tside,\n\t\t\t\tpastReveal: side\n\t\t\t\t\t? Math.abs(drag.origin) >= revealOf(side) * REVEAL_RATIO\n\t\t\t\t\t: false,\n\t\t\t\tarmed: false,\n\t\t\t};\n\t\t\tif (confirming) {\n\t\t\t\tsetConfirming(null);\n\t\t\t\tsetStretch(false);\n\t\t\t}\n\t\t\tsetRowState(\"dragging\");\n\t\t}\n\t\tx.set(resist(drag.origin + (event.clientX - drag.startX) / drag.scale));\n\t};\n\n\tconst endDrag = (event: PointerEvent<HTMLDivElement>) => {\n\t\tconst drag = dragRef.current;\n\t\tif (!drag || drag.pointerId !== event.pointerId) return;\n\t\tdragRef.current = null;\n\t\tif (!drag.locked) return;\n\t\tconst root = event.currentTarget;\n\t\tif (root.hasPointerCapture(event.pointerId))\n\t\t\troot.releasePointerCapture(event.pointerId);\n\t\tdelete root.dataset.dragging;\n\t\t// The click that follows a drag belongs to the drag.\n\t\tsuppressClickRef.current = true;\n\t\tsetTimeout(() => {\n\t\t\tsuppressClickRef.current = false;\n\t\t}, 0);\n\t\trelease();\n\t};\n\n\tconst handleClickCapture = (event: MouseEvent<HTMLDivElement>) => {\n\t\tif (!suppressClickRef.current) return;\n\t\tsuppressClickRef.current = false;\n\t\tevent.preventDefault();\n\t\tevent.stopPropagation();\n\t};\n\n\t// A tap on the content of an open row closes it instead of activating it.\n\tconst handleContentClickCapture = (event: MouseEvent<HTMLDivElement>) => {\n\t\tif (!openRef.current || event.detail === 0) return;\n\t\tevent.preventDefault();\n\t\tevent.stopPropagation();\n\t\tclose();\n\t};\n\n\tconst sideFor = (push: number): Side =>\n\t\tpush * dir > 0 ? \"leading\" : \"trailing\";\n\tconst handleSide: Side | null = trailing.length\n\t\t? \"trailing\"\n\t\t: leading.length\n\t\t\t? \"leading\"\n\t\t\t: null;\n\n\tconst handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n\t\tif (disabled || busyRef.current) return;\n\t\tconst root = event.currentTarget;\n\t\tconst target = event.target as HTMLElement;\n\t\tif (event.key === \"Escape\" && openRef.current) {\n\t\t\tevent.preventDefault();\n\t\t\tclose();\n\t\t\troot.focus({ preventScroll: true });\n\t\t\treturn;\n\t\t}\n\t\tconst fromRow = target === root;\n\t\tconst fromTray = !!target.closest('[data-slot=\"swipe-actions-tray\"]');\n\t\tif (!fromRow && !fromTray) return;\n\n\t\tif (event.key === \"ArrowRight\" || event.key === \"ArrowLeft\") {\n\t\t\tconst push = event.key === \"ArrowRight\" ? 1 : -1;\n\t\t\tconst current = openRef.current;\n\t\t\tif (current) {\n\t\t\t\tif (signOf(current) === push) return;\n\t\t\t\tevent.preventDefault();\n\t\t\t\tclose();\n\t\t\t\troot.focus({ preventScroll: true });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst side = sideFor(push);\n\t\t\tif (!actionsOf(side).length) return;\n\t\t\tevent.preventDefault();\n\t\t\topen(side);\n\t\t\treturn;\n\t\t}\n\n\t\tif (event.key === \"Delete\" || event.key === \"Backspace\") {\n\t\t\tconst candidates = ([\"trailing\", \"leading\"] as const).flatMap((side) =>\n\t\t\t\tactionsOf(side).map((action) => ({ side, action })),\n\t\t\t);\n\t\t\tconst match =\n\t\t\t\tcandidates.find(\n\t\t\t\t\t({ action }) => action.destructive && action.tone === \"destructive\",\n\t\t\t\t) ?? candidates.find(({ action }) => action.destructive);\n\t\t\tif (!match) return;\n\t\t\tevent.preventDefault();\n\t\t\tvoid fire(match.side, match.action);\n\t\t}\n\t};\n\n\tconst handleBlur = (event: FocusEvent<HTMLDivElement>) => {\n\t\tconst next = event.relatedTarget as Node | null;\n\t\tif (next && !event.currentTarget.contains(next) && openRef.current) close();\n\t};\n\n\tconst renderTray = (side: Side) => {\n\t\tconst actions = actionsOf(side);\n\t\tif (!actions.length) return null;\n\t\tconst sign = signOf(side);\n\t\tconst width = widthOf(side);\n\t\tconst outermost = outermostOf(side);\n\t\tconst isOpen = openSide === side;\n\t\treturn (\n\t\t\t<Tray\n\t\t\t\tid={`${id}-${side}`}\n\t\t\t\tside={side}\n\t\t\t\tsign={sign}\n\t\t\t\tx={x}\n\t\t\t\tinert={!isOpen || disabled}\n\t\t\t\tclassName={tones[outermost?.tone ?? \"default\"]}\n\t\t\t>\n\t\t\t\t{actions.map((action) => (\n\t\t\t\t\t<ActionButton\n\t\t\t\t\t\tkey={action.id}\n\t\t\t\t\t\taction={action}\n\t\t\t\t\t\tside={side}\n\t\t\t\t\t\tcount={actions.length}\n\t\t\t\t\t\tsign={sign}\n\t\t\t\t\t\tx={x}\n\t\t\t\t\t\tstretch={stretch}\n\t\t\t\t\t\tpopScale={popScale}\n\t\t\t\t\t\tstretchTarget={\n\t\t\t\t\t\t\tconfirming && isOpen\n\t\t\t\t\t\t\t\t? confirming === action.id\n\t\t\t\t\t\t\t\t: action === outermost\n\t\t\t\t\t\t}\n\t\t\t\t\t\twidth={width}\n\t\t\t\t\t\tshowLabel={showLabels}\n\t\t\t\t\t\treduceMotion={reduceMotion}\n\t\t\t\t\t\tconfirming={isOpen && confirming === action.id}\n\t\t\t\t\t\tonPress={(event) => {\n\t\t\t\t\t\t\t// Keyboard clicks have no detail and are never accidental.\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tevent.detail > 0 &&\n\t\t\t\t\t\t\t\tperformance.now() - openedAtRef.current < OPEN_GUARD_MS\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\tvoid fire(side, action);\n\t\t\t\t\t\t}}\n\t\t\t\t\t/>\n\t\t\t\t))}\n\t\t\t</Tray>\n\t\t);\n\t};\n\n\treturn (\n\t\t<motion.div\n\t\t\tlayout={list && !reduceMotion ? \"position\" : undefined}\n\t\t\trole={list ? \"listitem\" : undefined}\n\t\t\tdata-slot=\"swipe-actions-item\"\n\t\t\tclassName=\"group/swipe-item\"\n\t\t>\n\t\t\t<div\n\t\t\t\tref={collapserRef}\n\t\t\t\tclassName={cn(\n\t\t\t\t\t\"overflow-hidden\",\n\t\t\t\t\tvariant === \"inset\" && \"pb-2 group-last/swipe-item:pb-0\",\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t<div\n\t\t\t\t\tref={rootRef}\n\t\t\t\t\trole=\"group\"\n\t\t\t\t\taria-label={label}\n\t\t\t\t\ttabIndex={disabled ? -1 : 0}\n\t\t\t\t\tdata-slot=\"swipe-actions\"\n\t\t\t\t\tdata-state={disabled ? \"disabled\" : \"idle\"}\n\t\t\t\t\tdata-variant={variant}\n\t\t\t\t\tdata-open={openSide ?? undefined}\n\t\t\t\t\tdata-disabled={disabled || undefined}\n\t\t\t\t\tonPointerDown={handlePointerDown}\n\t\t\t\t\tonPointerMove={handlePointerMove}\n\t\t\t\t\tonPointerUp={endDrag}\n\t\t\t\t\tonPointerCancel={endDrag}\n\t\t\t\t\tonClickCapture={handleClickCapture}\n\t\t\t\t\tonKeyDown={handleKeyDown}\n\t\t\t\t\tonBlur={handleBlur}\n\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t\"group/swipe relative isolate touch-pan-y overflow-hidden outline-none focus-visible:outline-2 focus-visible:outline-ring focus-visible:-outline-offset-2 data-dragging:cursor-grabbing data-dragging:select-none data-disabled:opacity-60\",\n\t\t\t\t\t\tvariant === \"inset\"\n\t\t\t\t\t\t\t? \"rounded-xl border bg-card text-card-foreground shadow-xs\"\n\t\t\t\t\t\t\t: \"border-b bg-background group-last/swipe-item:border-b-0\",\n\t\t\t\t\t\tclassName,\n\t\t\t\t\t)}\n\t\t\t\t>\n\t\t\t\t\t<motion.div style={{ opacity: surfaceOpacity }} className=\"relative\">\n\t\t\t\t\t\t{renderTray(\"leading\")}\n\t\t\t\t\t\t{renderTray(\"trailing\")}\n\t\t\t\t\t\t<motion.div\n\t\t\t\t\t\t\tdata-slot=\"swipe-actions-content\"\n\t\t\t\t\t\t\tonClickCapture={handleContentClickCapture}\n\t\t\t\t\t\t\tstyle={{ x }}\n\t\t\t\t\t\t\tclassName=\"relative z-10 bg-inherit will-change-transform\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{children}\n\t\t\t\t\t\t\t{showHandle && handleSide && !disabled ? (\n\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\ttabIndex={-1}\n\t\t\t\t\t\t\t\t\tdata-slot=\"swipe-actions-handle\"\n\t\t\t\t\t\t\t\t\taria-expanded={openSide !== null}\n\t\t\t\t\t\t\t\t\taria-controls={`${id}-${openSide ?? handleSide}`}\n\t\t\t\t\t\t\t\t\taria-label={\n\t\t\t\t\t\t\t\t\t\topenSide\n\t\t\t\t\t\t\t\t\t\t\t? `Hide actions for ${label}`\n\t\t\t\t\t\t\t\t\t\t\t: `Show actions for ${label}`\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tonClick={() => (openSide ? close() : open(handleSide))}\n\t\t\t\t\t\t\t\t\tclassName=\"absolute end-2 top-1/2 flex size-7 -translate-y-1/2 cursor-pointer items-center justify-center rounded-full border bg-background text-muted-foreground opacity-0 shadow-xs outline-none transition-[opacity,color] duration-150 hover:text-foreground focus-visible:opacity-100 group-hover/swipe:opacity-100 group-data-dragging/swipe:opacity-0 [@media(hover:none)]:sr-only\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<Ellipsis aria-hidden className=\"size-4\" />\n\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t</motion.div>\n\t\t\t\t\t</motion.div>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t\t{list ? null : region}\n\t\t</motion.div>\n\t);\n}\n\nfunction Tray({\n\tid,\n\tside,\n\tsign,\n\tx,\n\tinert,\n\tclassName,\n\tchildren,\n}: {\n\tid: string;\n\tside: Side;\n\tsign: number;\n\tx: MotionValue<number>;\n\tinert: boolean;\n\tclassName?: string;\n\tchildren: ReactNode;\n}) {\n\tconst width = useTransform(x, (value) => Math.max(0, value * sign));\n\treturn (\n\t\t<motion.div\n\t\t\tid={id}\n\t\t\tinert={inert}\n\t\t\tdata-slot=\"swipe-actions-tray\"\n\t\t\tdata-side={side}\n\t\t\tstyle={{ width }}\n\t\t\tclassName={cn(\n\t\t\t\t\"absolute inset-y-0 flex overflow-hidden\",\n\t\t\t\tside === \"leading\" ? \"start-0\" : \"end-0\",\n\t\t\t\tclassName,\n\t\t\t)}\n\t\t>\n\t\t\t{children}\n\t\t</motion.div>\n\t);\n}\n\nexport default SwipeActions;\n",
      "type": "registry:component",
      "target": "@components/swipe-actions.tsx"
    }
  ],
  "meta": {
    "createdAt": "2026-10-24",
    "image": "https://cdn.tentui.com/images/components/swipe-actions",
    "video": "https://cdn.tentui.com/videos/components/swipe-actions"
  },
  "docs": "https://tentui.com/components/swipe-actions",
  "categories": [
    "lists"
  ],
  "type": "registry:component"
}