{"slug":"swipeable-list","name":"Swipeable List","description":"Mobile-style list rows that swipe left or right to reveal contextual action buttons.","category":"blocks","source_url":"https://beui.dev/r/swipeable-list/raw","detail_url":"https://beui.dev/r/swipeable-list","raw_url":"https://beui.dev/r/swipeable-list/raw","page_url":"https://beui.dev/components/blocks/swipeable-list","markdown_url":"https://beui.dev/components/blocks/swipeable-list.md","published_at":"2026-06-15","updated_at":"2026-11-10","dependencies":["clsx","lucide-react","motion","react","tailwind-merge"],"internal":["@/components/motion/swipeable-list","@/lib/i18n","@/lib/touch","@/lib/utils"],"install_slugs":["swipeable-list"],"requires_theme":true,"props":[{"displayName":"SwipeableList","props":[{"name":"items","type":"SwipeableListItem[]","required":true,"defaultValue":null,"description":"Rows to render, each with optional left and right swipe actions."},{"name":"value","type":"SwipeableListValue | null","required":false,"defaultValue":null,"description":"The open row and side, or null when all are closed, for controlled use."},{"name":"defaultValue","type":"SwipeableListValue | null","required":false,"defaultValue":"null","description":"The initially open row and side when uncontrolled. Default: null"},{"name":"onValueChange","type":"((value: SwipeableListValue | null) => void)","required":false,"defaultValue":null,"description":"Called with the open row and side, or null, when a row opens or closes."},{"name":"onAction","type":"((payload: { item: SwipeableListItem; action: SwipeAction; side: SwipeSide; }) => void)","required":false,"defaultValue":null,"description":"Called with the row, action and side when an action button is pressed."},{"name":"actionWidth","type":"number","required":false,"defaultValue":"56","description":"Width of each revealed action button (px). Default: 56"},{"name":"revealThreshold","type":"number","required":false,"defaultValue":"34","description":"Minimum drag distance that opens a row on release (px). Default: 34"},{"name":"closeOnAction","type":"boolean","required":false,"defaultValue":"true","description":"Close the row after one of its actions runs. Default: true"},{"name":"className","type":"string","required":false,"defaultValue":null,"description":"Classes merged onto the root element."},{"name":"classNames","type":"SwipeableListClassNames","required":false,"defaultValue":null,"description":"Classes for each inner part, such as rows, rails, actions and text."},{"name":"renderItem","type":"((item: SwipeableListItem) => ReactNode)","required":false,"defaultValue":null,"description":"Custom content for a row's surface, in place of its title and description."},{"name":"labels","type":"Partial<{ actionsFor: string; showActions: string; }>","required":false,"defaultValue":null,"description":"Override any built-in string."}]}],"types":[{"name":"SwipeableListValue","file":"components/motion/swipeable-list.tsx","fields":[{"name":"id","type":"string","required":true,"description":"The `id` of the open row."},{"name":"side","type":"SwipeSide","required":true,"description":"Which action rail is revealed on the open row."}]},{"name":"SwipeAction","file":"components/motion/swipeable-list.tsx","fields":[{"name":"id","type":"string","required":true,"description":"Unique key for the action within its row."},{"name":"label","type":"ReactNode","required":true,"description":"Screen-reader name of the button; strings also become its `aria-label`."},{"name":"icon","type":"ReactNode","required":true,"description":"Icon shown inside the round action button."},{"name":"tone","type":"SwipeActionTone","required":false,"description":"Icon color for the action. Default: \"neutral\""},{"name":"disabled","type":"boolean","required":false,"description":"Dims the button and blocks presses."},{"name":"onClick","type":"(item: SwipeableListItem) => void","required":false,"description":"Called with the row when this action is pressed, before `onAction`."}]},{"name":"SwipeableListItem","file":"components/motion/swipeable-list.tsx","fields":[{"name":"id","type":"string","required":true,"description":"Unique key for the row, also used in `value`."},{"name":"title","type":"ReactNode","required":false,"description":"Main line of the row; a string also names its actions button."},{"name":"description","type":"ReactNode","required":false,"description":"Muted line under the title."},{"name":"meta","type":"ReactNode","required":false,"description":"Small trailing content at the row end, such as a time."},{"name":"leading","type":"ReactNode","required":false,"description":"Content before the text, such as an avatar or icon."},{"name":"content","type":"ReactNode","required":false,"description":"Custom row content in place of the default layout."},{"name":"leftActions","type":"SwipeAction[]","required":false,"description":"Actions revealed on the left edge by swiping right."},{"name":"rightActions","type":"SwipeAction[]","required":false,"description":"Actions revealed on the right edge by swiping left."},{"name":"disabled","type":"boolean","required":false,"description":"Dims the row and turns off swiping and its actions button."}]},{"name":"SwipeableListClassNames","file":"components/motion/swipeable-list.tsx","fields":[{"name":"root","type":"string","required":false,"description":"Classes for the list wrapper."},{"name":"item","type":"string","required":false,"description":"Classes for each row's outer frame."},{"name":"rail","type":"string","required":false,"description":"Classes for the layer behind the row that holds the actions."},{"name":"action","type":"string","required":false,"description":"Classes for each action button."},{"name":"surface","type":"string","required":false,"description":"Classes for the draggable card on top of the actions."},{"name":"leading","type":"string","required":false,"description":"Classes for the wrapper around `leading`."},{"name":"content","type":"string","required":false,"description":"Classes for the column that holds the title and description."},{"name":"title","type":"string","required":false,"description":"Classes for the title line."},{"name":"description","type":"string","required":false,"description":"Classes for the description line."},{"name":"meta","type":"string","required":false,"description":"Classes for the trailing meta content."}]}],"files":[{"path":"components/motion/swipeable-list.tsx","type":"component","content":"\"use client\";\n// beui.dev/components/blocks/swipeable-list\n\nimport { Ellipsis } from \"lucide-react\";\nimport {\n  animate,\n  motion,\n  type PanInfo,\n  useMotionValue,\n  useReducedMotion,\n} from \"motion/react\";\nimport {\n  type KeyboardEvent,\n  type ReactNode,\n  useCallback,\n  useEffect,\n  useId,\n  useRef,\n  useState,\n} from \"react\";\nimport { useMessages } from \"@/lib/i18n\";\nimport { TOUCH_GESTURE_CONTENT_CLASS } from \"@/lib/touch\";\nimport { cn } from \"@/lib/utils\";\n\n/** English defaults. Override per instance with `labels`, or app-wide with `LocaleProvider`. */\nexport const swipeableListMessages = {\n  actionsFor: \"Actions for {title}\",\n  showActions: \"Show actions\",\n};\n\nexport type SwipeableListMessages = typeof swipeableListMessages;\n\nexport type SwipeSide = \"left\" | \"right\";\n\nexport type SwipeableListValue = {\n  /** The `id` of the open row. */\n  id: string;\n  /** Which action rail is revealed on the open row. */\n  side: SwipeSide;\n};\n\nexport type SwipeActionTone =\n  | \"neutral\"\n  | \"primary\"\n  | \"success\"\n  | \"warning\"\n  | \"danger\";\n\nexport type SwipeAction = {\n  /** Unique key for the action within its row. */\n  id: string;\n  /** Screen-reader name of the button; strings also become its `aria-label`. */\n  label: ReactNode;\n  /** Icon shown inside the round action button. */\n  icon: ReactNode;\n  /** Icon color for the action. Default: \"neutral\" */\n  tone?: SwipeActionTone;\n  /** Dims the button and blocks presses. */\n  disabled?: boolean;\n  /** Called with the row when this action is pressed, before `onAction`. */\n  onClick?: (item: SwipeableListItem) => void;\n};\n\nexport type SwipeableListItem = {\n  /** Unique key for the row, also used in `value`. */\n  id: string;\n  /** Main line of the row; a string also names its actions button. */\n  title?: ReactNode;\n  /** Muted line under the title. */\n  description?: ReactNode;\n  /** Small trailing content at the row end, such as a time. */\n  meta?: ReactNode;\n  /** Content before the text, such as an avatar or icon. */\n  leading?: ReactNode;\n  /** Custom row content in place of the default layout. */\n  content?: ReactNode;\n  /** Actions revealed on the left edge by swiping right. */\n  leftActions?: SwipeAction[];\n  /** Actions revealed on the right edge by swiping left. */\n  rightActions?: SwipeAction[];\n  /** Dims the row and turns off swiping and its actions button. */\n  disabled?: boolean;\n};\n\nexport type SwipeableListClassNames = {\n  /** Classes for the list wrapper. */\n  root?: string;\n  /** Classes for each row's outer frame. */\n  item?: string;\n  /** Classes for the layer behind the row that holds the actions. */\n  rail?: string;\n  /** Classes for each action button. */\n  action?: string;\n  /** Classes for the draggable card on top of the actions. */\n  surface?: string;\n  /** Classes for the wrapper around `leading`. */\n  leading?: string;\n  /** Classes for the column that holds the title and description. */\n  content?: string;\n  /** Classes for the title line. */\n  title?: string;\n  /** Classes for the description line. */\n  description?: string;\n  /** Classes for the trailing meta content. */\n  meta?: string;\n};\n\nexport interface SwipeableListProps {\n  /** Rows to render, each with optional left and right swipe actions. */\n  items: SwipeableListItem[];\n  /** The open row and side, or null when all are closed, for controlled use. */\n  value?: SwipeableListValue | null;\n  /** The initially open row and side when uncontrolled. Default: null */\n  defaultValue?: SwipeableListValue | null;\n  /** Called with the open row and side, or null, when a row opens or closes. */\n  onValueChange?: (value: SwipeableListValue | null) => void;\n  /** Called with the row, action and side when an action button is pressed. */\n  onAction?: (payload: {\n    item: SwipeableListItem;\n    action: SwipeAction;\n    side: SwipeSide;\n  }) => void;\n  /** Width of each revealed action button (px). Default: 56 */\n  actionWidth?: number;\n  /** Minimum drag distance that opens a row on release (px). Default: 34 */\n  revealThreshold?: number;\n  /** Close the row after one of its actions runs. Default: true */\n  closeOnAction?: boolean;\n  /** Classes merged onto the root element. */\n  className?: string;\n  /** Classes for each inner part, such as rows, rails, actions and text. */\n  classNames?: SwipeableListClassNames;\n  /** Custom content for a row's surface, in place of its title and description. */\n  renderItem?: (item: SwipeableListItem) => ReactNode;\n  /** Override any built-in string. */\n  labels?: Partial<SwipeableListMessages>;\n}\n\n// Distance-based release spring keeps short rebounds and full reveals feeling\n// equally direct, closer to native mobile list interactions.\nconst ROW_SETTLE = {\n  type: \"spring\",\n  stiffness: 560,\n  damping: 48,\n  mass: 0.82,\n  restDelta: 0.5,\n  restSpeed: 8,\n} as const;\nconst OPEN_DISTANCE_RATIO = 0.46;\nconst CLOSE_DISTANCE_RATIO = 0.72;\nconst OPEN_VELOCITY = 720;\nconst CLOSE_VELOCITY = 320;\nconst FLING_DISTANCE = 14;\nconst RELEASE_VELOCITY_LIMIT = 1500;\n\nconst ACTION_TONE_CLASS: Record<SwipeActionTone, string> = {\n  neutral: \"text-muted-foreground group-hover:text-foreground\",\n  primary: \"text-foreground\",\n  success: \"text-emerald-600 dark:text-emerald-400\",\n  warning: \"text-amber-600 dark:text-amber-400\",\n  danger: \"text-destructive\",\n};\n\nfunction useControllableSwipeValue({\n  value,\n  defaultValue,\n  onValueChange,\n}: {\n  value?: SwipeableListValue | null;\n  defaultValue?: SwipeableListValue | null;\n  onValueChange?: (value: SwipeableListValue | null) => void;\n}) {\n  const [internalValue, setInternalValue] = useState(defaultValue ?? null);\n  const isControlled = value !== undefined;\n  const currentValue = isControlled ? value : internalValue;\n\n  const setValue = useCallback(\n    (next: SwipeableListValue | null) => {\n      if (!isControlled) {\n        setInternalValue(next);\n      }\n\n      onValueChange?.(next);\n    },\n    [isControlled, onValueChange],\n  );\n\n  return [currentValue, setValue] as const;\n}\n\nfunction isActionableSide(value: number, sideWidth: number) {\n  return sideWidth > 0 && Math.abs(value) > 0;\n}\n\nfunction clampReleaseVelocity(velocity: number) {\n  return Math.max(\n    -RELEASE_VELOCITY_LIMIT,\n    Math.min(RELEASE_VELOCITY_LIMIT, velocity),\n  );\n}\n\nfunction SwipeActionButton({\n  action,\n  actionWidth,\n  side,\n  focusable,\n  onAction,\n  className,\n}: {\n  action: SwipeAction;\n  actionWidth: number;\n  side: SwipeSide;\n  focusable: boolean;\n  onAction: (action: SwipeAction, side: SwipeSide) => void;\n  className?: string;\n}) {\n  return (\n    <button\n      type=\"button\"\n      disabled={action.disabled}\n      tabIndex={focusable ? 0 : -1}\n      aria-label={typeof action.label === \"string\" ? action.label : undefined}\n      onClick={() => onAction(action, side)}\n      className={cn(\n        \"group flex h-full shrink-0 items-center justify-center outline-none\",\n        \"focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background\",\n        \"disabled:pointer-events-none disabled:opacity-50\",\n        className,\n      )}\n      style={{ width: actionWidth }}\n    >\n      <span\n        className={cn(\n          \"grid h-9 w-9 place-items-center rounded-full transition-[background-color,color,transform] duration-150 group-hover:bg-background group-active:scale-95\",\n          ACTION_TONE_CLASS[action.tone ?? \"neutral\"],\n        )}\n      >\n        {action.icon}\n      </span>\n      <span className=\"sr-only\">{action.label}</span>\n    </button>\n  );\n}\n\nfunction SwipeableListRow({\n  item,\n  actionWidth,\n  revealThreshold,\n  openValue,\n  setOpenValue,\n  closeOnAction,\n  onAction,\n  classNames,\n  renderItem,\n  labels,\n}: {\n  item: SwipeableListItem;\n  actionWidth: number;\n  revealThreshold: number;\n  openValue: SwipeableListValue | null;\n  setOpenValue: (value: SwipeableListValue | null) => void;\n  closeOnAction: boolean;\n  onAction?: SwipeableListProps[\"onAction\"];\n  classNames?: SwipeableListClassNames;\n  renderItem?: (item: SwipeableListItem) => ReactNode;\n  labels?: Partial<SwipeableListMessages>;\n}) {\n  const t = useMessages(\"swipeableList\", swipeableListMessages, labels);\n  const reduce = useReducedMotion();\n  const railId = useId();\n  const railRef = useRef<HTMLDivElement>(null);\n  const toggleRef = useRef<HTMLButtonElement>(null);\n  // Set when the keyboard opens a side, so focus follows into its actions once\n  // the rail stops being inert.\n  const focusActions = useRef(false);\n  const x = useMotionValue(0);\n  const animationRef = useRef<{ stop: () => void } | null>(null);\n  const commandedTargetRef = useRef(0);\n  const leftActions = item.leftActions ?? [];\n  const rightActions = item.rightActions ?? [];\n  const leftWidth = leftActions.length * actionWidth;\n  const rightWidth = rightActions.length * actionWidth;\n  const openSide = openValue?.id === item.id ? openValue.side : null;\n  const targetX =\n    openSide === \"left\" ? leftWidth : openSide === \"right\" ? -rightWidth : 0;\n\n  const settleX = useCallback(\n    (nextX: number, velocity = 0) => {\n      commandedTargetRef.current = nextX;\n      animationRef.current?.stop();\n\n      if (reduce) {\n        x.set(nextX);\n        return;\n      }\n\n      animationRef.current = animate(x, nextX, {\n        ...ROW_SETTLE,\n        velocity: clampReleaseVelocity(velocity),\n        onComplete: () => x.set(nextX),\n      });\n    },\n    [reduce, x],\n  );\n\n  useEffect(() => {\n    return () => animationRef.current?.stop();\n  }, []);\n\n  useEffect(() => {\n    if (commandedTargetRef.current === targetX) {\n      return;\n    }\n\n    settleX(targetX);\n  }, [settleX, targetX]);\n\n  const getTargetX = useCallback(\n    (side: SwipeSide | null) =>\n      side === \"left\" ? leftWidth : side === \"right\" ? -rightWidth : 0,\n    [leftWidth, rightWidth],\n  );\n\n  const snapTo = useCallback(\n    (side: SwipeSide | null, velocity = 0) => {\n      setOpenValue(side ? { id: item.id, side } : null);\n      settleX(getTargetX(side), velocity);\n    },\n    [getTargetX, item.id, setOpenValue, settleX],\n  );\n\n  const onDragStart = useCallback(() => {\n    animationRef.current?.stop();\n\n    if (openValue && openValue.id !== item.id) {\n      setOpenValue(null);\n    }\n  }, [item.id, openValue, setOpenValue]);\n\n  const onDragEnd = useCallback(\n    (_: PointerEvent, info: PanInfo) => {\n      const velocity = info.velocity.x;\n      const latest = x.get();\n      const leftOpenThreshold = Math.max(\n        revealThreshold,\n        leftWidth * OPEN_DISTANCE_RATIO,\n      );\n      const rightOpenThreshold = Math.max(\n        revealThreshold,\n        rightWidth * OPEN_DISTANCE_RATIO,\n      );\n\n      if (openSide === \"left\") {\n        if (\n          latest < leftWidth * CLOSE_DISTANCE_RATIO ||\n          velocity < -CLOSE_VELOCITY\n        ) {\n          snapTo(null, velocity);\n          return;\n        }\n\n        snapTo(\"left\", velocity);\n        return;\n      }\n\n      if (openSide === \"right\") {\n        if (\n          Math.abs(latest) < rightWidth * CLOSE_DISTANCE_RATIO ||\n          velocity > CLOSE_VELOCITY\n        ) {\n          snapTo(null, velocity);\n          return;\n        }\n\n        snapTo(\"right\", velocity);\n        return;\n      }\n\n      if (\n        isActionableSide(latest, leftWidth) &&\n        (latest > leftOpenThreshold ||\n          (velocity > OPEN_VELOCITY && latest > FLING_DISTANCE))\n      ) {\n        snapTo(\"left\", velocity);\n        return;\n      }\n\n      if (\n        isActionableSide(latest, rightWidth) &&\n        (latest < -rightOpenThreshold ||\n          (velocity < -OPEN_VELOCITY && latest < -FLING_DISTANCE))\n      ) {\n        snapTo(\"right\", velocity);\n        return;\n      }\n\n      snapTo(null, velocity);\n    },\n    [\n      leftWidth,\n      openSide,\n      revealThreshold,\n      rightWidth,\n      snapTo,\n      x,\n    ],\n  );\n\n  const handleAction = useCallback(\n    (action: SwipeAction, side: SwipeSide) => {\n      action.onClick?.(item);\n      onAction?.({ item, action, side });\n\n      if (closeOnAction) {\n        // The rail turns inert as the row closes; keep focus on the row.\n        if (railRef.current?.contains(document.activeElement))\n          toggleRef.current?.focus();\n        snapTo(null);\n      }\n    },\n    [closeOnAction, item, onAction, snapTo],\n  );\n\n  useEffect(() => {\n    if (!openSide || !focusActions.current) return;\n    focusActions.current = false;\n    railRef.current\n      ?.querySelector<HTMLButtonElement>(\n        `[data-side=\"${openSide}\"] button:not(:disabled)`,\n      )\n      ?.focus();\n  }, [openSide]);\n\n  const hasActions = leftWidth > 0 || rightWidth > 0;\n  const openFromKeyboard = (side: SwipeSide) => {\n    if ((side === \"left\" ? leftWidth : rightWidth) === 0) return;\n    focusActions.current = true;\n    snapTo(side);\n  };\n\n  // Keyboard stand-in for the swipe: the arrow keys move the row the way a\n  // swipe would, Enter or Space opens the trailing actions, and Escape closes.\n  const onToggleKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {\n    if (event.key === \"ArrowLeft\") {\n      event.preventDefault();\n      if (openSide === \"left\") snapTo(null);\n      else openFromKeyboard(\"right\");\n    } else if (event.key === \"ArrowRight\") {\n      event.preventDefault();\n      if (openSide === \"right\") snapTo(null);\n      else openFromKeyboard(\"left\");\n    } else if (event.key === \"Escape\" && openSide) {\n      event.preventDefault();\n      snapTo(null);\n    }\n  };\n\n  const onRailKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n    if (event.key !== \"Escape\") return;\n    event.preventDefault();\n    toggleRef.current?.focus();\n    snapTo(null);\n  };\n\n  const defaultContent = (\n    <div className=\"flex min-w-0 items-center gap-3\">\n      {item.leading ? (\n        <div className={cn(\"shrink-0\", classNames?.leading)}>\n          {item.leading}\n        </div>\n      ) : null}\n      <div className={cn(\"min-w-0 flex-1\", classNames?.content)}>\n        {item.title ? (\n          <div\n            className={cn(\n              \"truncate text-sm font-medium text-foreground\",\n              classNames?.title,\n            )}\n          >\n            {item.title}\n          </div>\n        ) : null}\n        {item.description ? (\n          <div\n            className={cn(\n              \"mt-0.5 truncate text-xs text-muted-foreground\",\n              classNames?.description,\n            )}\n          >\n            {item.description}\n          </div>\n        ) : null}\n      </div>\n      {item.meta ? (\n        <div\n          className={cn(\n            \"shrink-0 text-xs font-medium text-muted-foreground\",\n            classNames?.meta,\n          )}\n        >\n          {item.meta}\n        </div>\n      ) : null}\n    </div>\n  );\n\n  return (\n    <div\n      className={cn(\n        \"relative isolate overflow-hidden rounded-2xl bg-muted\",\n        item.disabled && \"opacity-60\",\n        classNames?.item,\n      )}\n    >\n      <div\n        ref={railRef}\n        id={railId}\n        aria-hidden={!openSide}\n        inert={!openSide}\n        onKeyDown={onRailKeyDown}\n        className={cn(\n          \"absolute inset-0 z-0 flex overflow-hidden rounded-2xl\",\n          classNames?.rail,\n        )}\n      >\n        <div\n          data-side=\"left\"\n          className=\"flex h-full overflow-hidden rounded-l-2xl\"\n        >\n          {leftActions.map((action) => (\n            <SwipeActionButton\n              key={action.id}\n              action={action}\n              actionWidth={actionWidth}\n              className={classNames?.action}\n              focusable={openSide === \"left\"}\n              onAction={handleAction}\n              side=\"left\"\n            />\n          ))}\n        </div>\n        <div\n          data-side=\"right\"\n          className=\"ml-auto flex h-full overflow-hidden rounded-r-2xl\"\n        >\n          {rightActions.map((action) => (\n            <SwipeActionButton\n              key={action.id}\n              action={action}\n              actionWidth={actionWidth}\n              className={classNames?.action}\n              focusable={openSide === \"right\"}\n              onAction={handleAction}\n              side=\"right\"\n            />\n          ))}\n        </div>\n      </div>\n\n      <motion.div\n        drag={item.disabled ? false : \"x\"}\n        dragConstraints={{ left: -rightWidth, right: leftWidth }}\n        dragElastic={0.04}\n        dragMomentum={false}\n        onDragStart={onDragStart}\n        onDragEnd={onDragEnd}\n        style={{ x }}\n        className={cn(\n          // `touch-pan-y`, not `touch-none`: the row owns the horizontal\n          // swipe, the page keeps the vertical scroll through it.\n          \"relative z-10 min-h-[72px] cursor-grab touch-pan-y rounded-2xl border border-border bg-card px-4 py-3 shadow-sm active:cursor-grabbing\",\n          // The swipe is the row's, but what it carries is the consumer's:\n          // selection is only suppressed where the platform runs its own press\n          // gestures, so a mouse can still select and copy the row's text.\n          TOUCH_GESTURE_CONTENT_CLASS,\n          classNames?.surface,\n        )}\n      >\n        {renderItem ? renderItem(item) : item.content ?? defaultContent}\n        {hasActions && !item.disabled ? (\n          // Only visible while focused from the keyboard; pointers swipe.\n          <button\n            ref={toggleRef}\n            type=\"button\"\n            aria-label={\n              typeof item.title === \"string\"\n                ? t(\"actionsFor\", { title: item.title })\n                : t(\"showActions\")\n            }\n            aria-expanded={openSide !== null}\n            aria-controls={railId}\n            onClick={() =>\n              openSide\n                ? snapTo(null)\n                : openFromKeyboard(rightWidth > 0 ? \"right\" : \"left\")\n            }\n            onKeyDown={onToggleKeyDown}\n            className={cn(\n              \"sr-only grid place-items-center rounded-full bg-muted text-muted-foreground outline-none\",\n              \"focus-visible:not-sr-only focus-visible:absolute focus-visible:right-3 focus-visible:top-1/2 focus-visible:h-8 focus-visible:w-8 focus-visible:-translate-y-1/2 focus-visible:ring-2 focus-visible:ring-ring\",\n            )}\n          >\n            <Ellipsis aria-hidden className=\"h-4 w-4\" />\n          </button>\n        ) : null}\n      </motion.div>\n    </div>\n  );\n}\n\nexport function SwipeableList({\n  items,\n  value,\n  defaultValue = null,\n  onValueChange,\n  onAction,\n  actionWidth = 56,\n  revealThreshold = 34,\n  closeOnAction = true,\n  className,\n  classNames,\n  renderItem,\n  labels,\n}: SwipeableListProps) {\n  const [openValue, setOpenValue] = useControllableSwipeValue({\n    value,\n    defaultValue,\n    onValueChange,\n  });\n\n  return (\n    <div className={cn(\"flex w-full flex-col gap-2\", className, classNames?.root)}>\n      {items.map((item) => (\n        <SwipeableListRow\n          key={item.id}\n          item={item}\n          actionWidth={actionWidth}\n          revealThreshold={revealThreshold}\n          openValue={openValue}\n          setOpenValue={setOpenValue}\n          closeOnAction={closeOnAction}\n          onAction={onAction}\n          classNames={classNames}\n          renderItem={renderItem}\n          labels={labels}\n        />\n      ))}\n    </div>\n  );\n}\n"},{"path":"lib/i18n.tsx","type":"util","content":"\"use client\";\n\nimport {\n  createContext,\n  type ReactNode,\n  useCallback,\n  useContext,\n  useMemo,\n} from \"react\";\n\n/**\n * A component's messages. Plain strings with `{name}` placeholders, so a\n * dictionary stays JSON-serializable and can be passed from a server layout.\n * There are no plural forms: write messages that read correctly for any count.\n */\nexport type Messages = Record<string, string>;\n\n/** A language file: component namespace → any subset of that component's messages. */\nexport type LocaleMessages = Record<string, Partial<Messages>>;\n\ntype LocaleContextValue = {\n  locale?: string;\n  messages: LocaleMessages;\n};\n\nconst NO_MESSAGES: LocaleMessages = {};\n\nconst LocaleContext = createContext<LocaleContextValue>({ messages: NO_MESSAGES });\n\n/** Without a locale, digits stay plain so server and client render the same text. */\nexport function formatNumber(value: number, locale?: string) {\n  return locale ? new Intl.NumberFormat(locale).format(value) : String(value);\n}\n\nexport interface LocaleProviderProps {\n  /** BCP 47 tag, e.g. `de`, `pt-BR`. Drives `Intl` number formatting. */\n  locale: string;\n  /**\n   * Component namespace → translated strings. Missing keys fall back to English.\n   * Pass a stable object (a module constant, imported JSON or a memoized value):\n   * a new object each render gives every translated component a new `t`.\n   */\n  messages?: LocaleMessages;\n  children: ReactNode;\n}\n\nexport function LocaleProvider({ locale, messages = NO_MESSAGES, children }: LocaleProviderProps) {\n  const value = useMemo(() => ({ locale, messages }), [locale, messages]);\n  return <LocaleContext.Provider value={value}>{children}</LocaleContext.Provider>;\n}\n\nexport function useLocale(): { locale?: string } {\n  return { locale: useContext(LocaleContext).locale };\n}\n\n/**\n * Resolves a component's strings: `labels` prop, then the provider's\n * messages for `namespace`, then the component's English `defaults`.\n * Numbers passed as values are formatted for the provider's locale.\n */\nexport function useMessages<T extends Messages>(\n  namespace: string,\n  defaults: T,\n  labels?: Partial<T>,\n) {\n  const { locale, messages } = useContext(LocaleContext);\n  const provided = messages[namespace];\n  // Inline `labels={{ … }}` is a new object every render. Keying it by content\n  // keeps `t` one identity until a label changes, so effects and memos that\n  // depend on `t` don't re-run per render, and render-time reads never lag.\n  const labelsKey = labels ? JSON.stringify(labels) : \"\";\n  const stableLabels = useMemo(\n    () => (labelsKey ? (JSON.parse(labelsKey) as Partial<T>) : undefined),\n    [labelsKey],\n  );\n\n  return useCallback(\n    (key: keyof T & string, values?: Record<string, string | number>) => {\n      const template = stableLabels?.[key] ?? provided?.[key] ?? defaults[key];\n      if (!values) return template;\n      return template.replace(/\\{(\\w+)\\}/g, (match, name: string) => {\n        const value = values[name];\n        if (value === undefined) return match;\n        return typeof value === \"number\" ? formatNumber(value, locale) : value;\n      });\n    },\n    [defaults, stableLabels, locale, provided],\n  );\n}\n"},{"path":"lib/touch.ts","type":"util","content":"// Shared touch primitives. iOS and iPadOS run their own gestures on top of the\n// page - the long-press selection callout and the selection it drags in with\n// it - and they win: once the platform claims a touch it cancels ours\n// mid-gesture, so a press-and-hold or a drag simply dies. Surfaces that own\n// their gesture have to opt out.\n//\n// What the two classes below cover, precisely:\n// - `-webkit-touch-callout: none` stops iOS's long-press callout. WebKit-only:\n//   it is not a property other engines have, so it is inert everywhere else.\n// - `user-select: none` stops the long-press selection on every engine,\n//   Android included, and stops a drag from painting a selection under the\n//   cursor. It is inherited, so it reaches every descendant - which is why the\n//   two classes differ only in whether they apply it unconditionally.\n// What neither covers:\n// - Chrome for Android's long-press menu on a link or an image. No CSS\n//   suppresses it; a gesture surface that wraps one needs its own\n//   `onContextMenu` with `preventDefault()`.\n// - The native drag of an `<img>` or `<a>` descendant. `-webkit-user-drag` is\n//   not inherited and plain divs and buttons are not drag sources, so setting\n//   it on the surface does nothing - the child itself needs `draggable={false}`.\n\n/**\n * Classes for a surface that *is* the control: a thumb, a drum, a stage, a\n * handle, a hold button. Selection is suppressed on every input, because a\n * drag that highlights the control's own label is wrong on a mouse too.\n * Compose with `touch-none` when the surface also owns the scroll axis - leave\n * it off when the page must still scroll from there.\n */\nexport const TOUCH_GESTURE_CLASS = \"select-none [-webkit-touch-callout:none]\";\n\n/**\n * The same opt-out for a gesture surface that wraps content the consumer owns:\n * a scroller, a context-menu trigger, a sheet header, a list row. Selection is\n * suppressed only where the platform runs its own press gestures - a coarse\n * pointer - so a mouse user can still select and copy that content. If the\n * gesture itself would paint a selection under the cursor, add `select-none`\n * for the duration of the gesture rather than reaching for\n * `TOUCH_GESTURE_CLASS`.\n *\n * `pointer: coarse` describes the *primary* pointer and nothing else, so a\n * hybrid machine reads it wrong in both directions: a tablet with a mouse\n * plugged in keeps touch as primary and loses mouse selection, and a laptop\n * with a touchscreen keeps the mouse as primary and leaves selection live\n * under a finger. No media query can answer per interaction - the query is\n * about the device, and the question is about the gesture in progress. The\n * default stays here because it is right on the machines that are one thing or\n * the other, and losing a selection is a nuisance; where the miss costs a\n * *gesture* instead, the surface pairs it with `holdSelection` on the press.\n */\nexport const TOUCH_GESTURE_CONTENT_CLASS =\n  \"[-webkit-touch-callout:none] pointer-coarse:select-none\";\n\n/**\n * Suppress selection on `element` for as long as a gesture is running on it,\n * whatever the primary pointer of the machine happens to be. Returns the\n * release. Inline, so it wins over the class above and is gone again the\n * moment the gesture ends.\n *\n * For the press gestures a native selection would otherwise steal - a\n * long-press that opens a menu. Elsewhere prefer the classes: a surface that\n * takes selection away for the whole session is a surface whose text nobody\n * can copy.\n */\nexport function holdSelection(element: HTMLElement) {\n  element.style.setProperty(\"user-select\", \"none\");\n  element.style.setProperty(\"-webkit-user-select\", \"none\");\n  return () => {\n    element.style.removeProperty(\"user-select\");\n    element.style.removeProperty(\"-webkit-user-select\");\n  };\n}\n\n/**\n * Pointer capture, best effort. WebKit throws `NotFoundError` when the pointer\n * is already gone by the time the handler runs - routine on iOS, where the\n * system can claim the touch first - and an uncaught throw takes the rest of\n * the handler, the gesture included, down with it. Touch pointers carry\n * implicit capture anyway, so losing it is never fatal.\n */\nexport function capturePointer(element: Element, pointerId: number) {\n  try {\n    element.setPointerCapture(pointerId);\n  } catch {\n    // Pointer is no longer active - implicit capture still applies on touch.\n  }\n}\n\n/** Release a capture taken with `capturePointer`, ignoring a stale pointer. */\nexport function releasePointer(element: Element, pointerId: number) {\n  try {\n    if (element.hasPointerCapture(pointerId)) {\n      element.releasePointerCapture(pointerId);\n    }\n  } catch {\n    // Capture was already dropped by the browser.\n  }\n}\n\n/**\n * Whether this event came from a pointer that is *hovering*: not a touch, and\n * not currently pressed. Which input the user is holding right now is not\n * something a device capability can answer - a touchscreen laptop hovers and\n * taps, and iPadOS reports a fine hovering pointer for a finger - so both\n * paths stay live and each handler branches on the event it was given.\n *\n * A pen resting on the glass is making contact, not hovering: `buttons` is the\n * tell, and it sends a pen tap down the same route a finger takes.\n *\n * This answers what an *enter* asks. A leave is the other half of a pair and\n * has to be read against the enter that started it - `useHoverGesture` in\n * `lib/hooks/use-hover-gesture` does that, and hover surfaces should use it\n * rather than asking this question twice.\n */\nexport const isHoveringPointer = (event: {\n  pointerType: string;\n  buttons: number;\n}) => event.pointerType !== \"touch\" && event.buttons === 0;\n"},{"path":"lib/utils.ts","type":"util","content":"import { clsx, type ClassValue } from \"clsx\"\nimport { twMerge } from \"tailwind-merge\"\n\nexport function cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs))\n}\n"},{"path":"components/previews/blocks/swipeable-list.preview.tsx","type":"preview","content":"\"use client\";\n\nimport {\n  Check,\n  Clock3,\n  FileText,\n  Flag,\n  Mail,\n  Pin,\n  RotateCcw,\n  Trash2,\n  UserRound,\n} from \"lucide-react\";\nimport { useState } from \"react\";\nimport {\n  type SwipeAction,\n  SwipeableList,\n  type SwipeableListItem,\n} from \"@/components/motion/swipeable-list\";\n\nconst leftActions: SwipeAction[] = [\n  {\n    id: \"done\",\n    label: \"Done\",\n    icon: <Check className=\"h-4 w-4\" />,\n    tone: \"success\",\n  },\n  {\n    id: \"pin\",\n    label: \"Pin\",\n    icon: <Pin className=\"h-4 w-4\" />,\n    tone: \"primary\",\n  },\n];\n\nconst rightActions: SwipeAction[] = [\n  {\n    id: \"later\",\n    label: \"Later\",\n    icon: <Clock3 className=\"h-4 w-4\" />,\n    tone: \"warning\",\n  },\n  {\n    id: \"trash\",\n    label: \"Trash\",\n    icon: <Trash2 className=\"h-4 w-4\" />,\n    tone: \"danger\",\n  },\n];\n\nconst initialItems: SwipeableListItem[] = [\n  {\n    id: \"brief\",\n    title: \"Launch brief\",\n    description: \"Finalize the announcement copy\",\n    meta: \"9:41\",\n    leading: (\n      <div className=\"grid h-10 w-10 place-items-center rounded-full border border-border bg-background text-muted-foreground\">\n        <FileText className=\"h-4 w-4\" />\n      </div>\n    ),\n    leftActions,\n    rightActions,\n  },\n  {\n    id: \"feedback\",\n    title: \"Client feedback\",\n    description: \"Three comments need a response\",\n    meta: \"11:08\",\n    leading: (\n      <div className=\"grid h-10 w-10 place-items-center rounded-full border border-border bg-background text-muted-foreground\">\n        <Mail className=\"h-4 w-4\" />\n      </div>\n    ),\n    leftActions,\n    rightActions,\n  },\n  {\n    id: \"review\",\n    title: \"Design review\",\n    description: \"Check spacing before handoff\",\n    meta: \"13:20\",\n    leading: (\n      <div className=\"grid h-10 w-10 place-items-center rounded-full border border-border bg-background text-muted-foreground\">\n        <UserRound className=\"h-4 w-4\" />\n      </div>\n    ),\n    leftActions,\n    rightActions,\n  },\n  {\n    id: \"incident\",\n    title: \"Flagged run\",\n    description: \"Retry queue has one failed job\",\n    meta: \"Now\",\n    leading: (\n      <div className=\"grid h-10 w-10 place-items-center rounded-full border border-border bg-background text-muted-foreground\">\n        <Flag className=\"h-4 w-4\" />\n      </div>\n    ),\n    leftActions,\n    rightActions,\n  },\n];\n\nexport function SwipeableListPreview() {\n  const [items, setItems] = useState(initialItems);\n  const [lastAction, setLastAction] = useState(\"Ready\");\n\n  return (\n    <div className=\"flex min-h-96 w-full items-center justify-center\">\n      <div className=\"w-full max-w-sm rounded-3xl border border-border bg-background p-2 shadow-2xl\">\n        <div className=\"mb-3 flex items-center justify-between px-2\">\n          <div>\n            <p className=\"text-sm font-medium text-foreground\">Priority queue</p>\n            <p className=\"text-xs text-muted-foreground\">{lastAction}</p>\n          </div>\n          <button\n            type=\"button\"\n            onClick={() => {\n              setItems(initialItems);\n              setLastAction(\"Queue restored\");\n            }}\n            className=\"inline-flex h-8 items-center gap-1.5 rounded-full border border-border px-3 text-xs font-medium text-muted-foreground transition-colors hover:text-foreground\"\n          >\n            <RotateCcw className=\"h-3.5 w-3.5\" />\n            Reset\n          </button>\n        </div>\n\n        <SwipeableList\n          items={items}\n          onAction={({ item, action }) => {\n            setLastAction(`${action.label} · ${item.title}`);\n\n            if (action.id === \"trash\") {\n              setItems((current) => current.filter((entry) => entry.id !== item.id));\n            }\n          }}\n        />\n\n        <div className=\"mt-3 mb-1 flex items-center justify-between px-2 text-[11px] font-medium text-muted-foreground\">\n          <span>{items.length} open</span>\n          <span>Today</span>\n        </div>\n      </div>\n    </div>\n  );\n}\n"}]}