{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "swipe-actions",
  "title": "SwipeActions",
  "description": "A list row with actions beside it that a horizontal swipe reveals: swipe toward the start for the `trailing` actions (Delete, Archive), toward the end for the `leading` ones (Pin).",
  "registryDependencies": [
    "@ouro/button",
    "@ouro/lib-class-name-check",
    "@ouro/lib-cn",
    "@ouro/lib-env",
    "@ouro/lib-focus-handoff",
    "@ouro/lib-spring",
    "@ouro/lib-tones",
    "@ouro/lib-use-dev-messages",
    "@ouro/lib-use-drag",
    "@ouro/lib-use-reduced-motion",
    "@ouro/menu"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/swipe-actions/swipe-actions-styles.ts",
      "content": "export {\n  actionClass,\n  actionTones,\n  contentClass,\n  fadeClass,\n  FULL_SWIPE,\n  menuClass,\n  rootClass,\n  sideOf,\n  stripClass,\n  stripTones,\n  trackClass,\n  type SwipeSide,\n};\n\n// Class strings, values and helpers for SwipeActions, apart from the component so its file\n// exports only components (React Fast Refresh). Class strings are literal so the app's\n// Tailwind finds them when it compiles.\n\n/** A side of the row, in reading order: `leading` is the start edge, `trailing` the end edge. @internal */\ntype SwipeSide = \"leading\" | \"trailing\";\n\n/** The share of the row's width a swipe must pass for its release to run the primary action. @internal */\nconst FULL_SWIPE = 0.6;\n\n/**\n * The side an offset reveals: sliding the row toward the start (left, or right in a\n * right-to-left page) reveals the trailing actions.\n *\n * @internal\n */\nfunction sideOf(offset: number, rtl: boolean): SwipeSide {\n  return offset < 0 !== rtl ? \"trailing\" : \"leading\";\n}\n\n/**\n * The row. `touch-pan-y` gives the browser vertical pans, so a vertical swipe that starts\n * on a row scrolls the page, and leaves horizontal ones to the row. `overflow-clip` hides\n * the actions beside the row without making the row a scroller, which focus could scroll.\n *\n * @internal\n */\nconst rootClass = \"group/swipe relative box-border min-w-0 touch-pan-y overflow-clip\";\n\n/**\n * What slides: the content, with the actions attached to its two edges. The component\n * writes its `transform` directly: under a finger it follows the finger, and on release a\n * spring carries it to rest from where it is (`lib/ouro/spring`). No CSS transition, which\n * a finger could not catch mid-way. It is on its own layer only while it moves, so the rows\n * of a long list at rest hold no layers.\n *\n * @internal\n * @claim \"What slides: the content, with the\" registry/ouro/components/ouro/swipe-actions/swipe-actions.test.tsx verify:testExists(registry/ouro/components/ouro/swipe-actions/swipe-actions.test.tsx::SwipeActions > renders the row closed, with both sides out of reach and an actions button named after the row)\n * @claim \"No CSS transition, which a finger\" registry/ouro/components/ouro/swipe-actions/swipe-actions.touch.test.tsx verify:testExists(registry/ouro/components/ouro/swipe-actions/swipe-actions.touch.test.tsx::SwipeActions on a phone > writes the transform on the row's track and springs to rest without a CSS transition)\n * @claim \"It is on its own layer\" registry/ouro/components/ouro/swipe-actions/swipe-actions.test.tsx verify:fileLine(registry/ouro/components/ouro/swipe-actions/swipe-actions.test.tsx, /expect\\(getComputedStyle\\(track\\(element\\)\\)\\.willChange\\)\\.toBe\\(\"auto\"\\)/)\n * @claim \"It is on its own layer\" registry/ouro/components/ouro/swipe-actions/swipe-actions-styles.ts verify:fileLine(registry/ouro/components/ouro/swipe-actions/swipe-actions-styles.ts, /group-data-\\[dragging\\]/swipe:will-change-transform/)\n */\nconst trackClass = \"relative flex min-w-0 items-center group-data-[dragging]/swipe:will-change-transform group-data-[ouro-settling]/swipe:will-change-transform pointer-coarse:min-h-11\";\n\n/** The row the app passes in. @internal */\nconst contentClass = \"min-w-0 flex-1\";\n\n/**\n * The actions on one side, outside the content's edge until the row slides. The `::after`\n * continues the primary action's color past the buttons, so a swipe further than their\n * width shows no gap.\n *\n * @internal\n * @claim \"The `::after` continues the primary action's\" registry/ouro/components/ouro/swipe-actions/swipe-actions.touch.test.tsx verify:testExists(registry/ouro/components/ouro/swipe-actions/swipe-actions.touch.test.tsx::SwipeActions on a phone > follows a held finger, and past the full-swipe point shows only the primary action)\n * @claim \"The `::after` continues the primary action's\" registry/ouro/components/ouro/swipe-actions/swipe-actions.test.tsx verify:testExists(registry/ouro/components/ouro/swipe-actions/swipe-actions.test.tsx::SwipeActions > colors each action by its tone, the side by its primary action, and falls back to secondary)\n */\nconst stripClass = {\n  leading: \"absolute inset-y-0 end-full flex items-stretch after:absolute after:inset-y-0 after:end-full after:w-screen after:bg-inherit after:content-['']\",\n  trailing: \"absolute inset-y-0 start-full flex items-stretch after:absolute after:inset-y-0 after:start-full after:w-screen after:bg-inherit after:content-['']\",\n} as const;\n\n/** The color behind a side's actions: its primary action's. @internal */\nconst stripTones = {\n  primary: \"bg-primary\",\n  secondary: \"bg-secondary\",\n  destructive: \"bg-destructive\",\n  success: \"bg-success\",\n  warning: \"bg-warning\",\n} as const;\n\n/**\n * One action: a block as tall as the row and at least 72px wide, with 16px text on a touch screen. @internal\n *\n * @claim \"One action: a block as tall\" registry/ouro/components/ouro/swipe-actions/swipe-actions-styles.ts verify:fileLine(registry/ouro/components/ouro/swipe-actions/swipe-actions-styles.ts, /min-w-18/)\n * @claim \"One action: a block as tall\" registry/ouro/components/ouro/swipe-actions/swipe-actions.test.tsx verify:testExists(registry/ouro/components/ouro/swipe-actions/swipe-actions.test.tsx::SwipeActions > renders the row closed, with both sides out of reach and an actions button named after the row)\n */\nconst actionClass =\n  \"press relative m-0 box-border inline-flex min-w-18 shrink-0 cursor-pointer items-center justify-center border-0 forced-colors:border forced-colors:border-solid px-4 \" +\n  \"text-base font-medium whitespace-nowrap pointer-fine:text-sm \" +\n  \"outline-ring -outline-offset-2 focus-visible:outline-2 focus-visible:outline-solid active:opacity-80\";\n\n/** @internal */\nconst actionTones = {\n  primary: \"bg-primary text-primary-foreground\",\n  secondary: \"bg-secondary text-secondary-foreground\",\n  destructive: \"bg-destructive text-destructive-foreground\",\n  success: \"bg-success text-success-foreground\",\n  warning: \"bg-warning text-warning-foreground\",\n} as const;\n\n/** An action that is not the primary one fades out past the full-swipe point, so the primary action's color fills the side. @internal */\nconst fadeClass = \"group-data-full/swipe:opacity-0\";\n\n/**\n * The actions button's place at the end of the row. With a fine pointer it shows, 8px in\n * from the row's end so it does not touch the edge of an outlined group. On a touch screen\n * it is visually hidden, because the swipe and the long press are the ways there, and\n * stays in the accessibility tree; it shows when the keyboard focuses it, in a 44px column\n * so its touch target stays inside the row.\n *\n * @internal\n * @claim \"With a fine pointer it shows\" registry/ouro/components/ouro/swipe-actions/swipe-actions-styles.ts verify:fileLine(registry/ouro/components/ouro/swipe-actions/swipe-actions-styles.ts, /pointer-fine:pe-2/)\n * @claim \"On a touch screen it is\" registry/ouro/components/ouro/swipe-actions/swipe-actions.touch.test.tsx verify:testExists(registry/ouro/components/ouro/swipe-actions/swipe-actions.touch.test.tsx::SwipeActions on a phone > keeps the actions button for screen readers without showing it, and shows it for keyboard focus)\n */\nconst menuClass =\n  \"flex shrink-0 justify-center pointer-fine:pe-2 pointer-coarse:[&:not(:has(:focus-visible))]:sr-only pointer-coarse:has-[:focus-visible]:min-w-11\";\n",
      "type": "registry:ui",
      "target": "@components/ouro/swipe-actions/swipe-actions-styles.ts"
    },
    {
      "path": "registry/ouro/components/ouro/swipe-actions/swipe-actions.tsx",
      "content": "\"use client\";\n\nimport {\n  useCallback,\n  useEffect,\n  useLayoutEffect,\n  useRef,\n  useState,\n  type JSX,\n  type MouseEvent as ReactMouseEvent,\n  type PointerEvent as ReactPointerEvent,\n  type ReactNode,\n  type RefObject,\n} from \"react\";\nimport { useAppearanceClassNameCheck } from \"@/registry/ouro/lib/ouro/class-name-check\";\nimport { cn } from \"@/registry/ouro/lib/ouro/cn\";\nimport { rubberband, spring, type SpringHandle } from \"@/registry/ouro/lib/ouro/spring\";\nimport { renamedTones, type ToneName } from \"@/registry/ouro/lib/ouro/tones\";\nimport { useDevWarnings } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\nimport { useDrag } from \"@/registry/ouro/lib/ouro/use-drag\";\nimport { useReducedMotion } from \"@/registry/ouro/lib/ouro/use-reduced-motion\";\nimport { handOffFocus } from \"@/registry/ouro/lib/ouro/focus-handoff\";\nimport { Button } from \"@/registry/ouro/components/ouro/button/button\";\nimport { Menu } from \"@/registry/ouro/components/ouro/menu/menu\";\nimport {\n  actionClass,\n  actionTones,\n  contentClass,\n  fadeClass,\n  FULL_SWIPE,\n  menuClass,\n  rootClass,\n  sideOf,\n  stripClass,\n  stripTones,\n  trackClass,\n  type SwipeSide,\n} from \"@/registry/ouro/components/ouro/swipe-actions/swipe-actions-styles\";\n\n/** One action of a `SwipeActions` row: a button beside the row, and an item in the row's actions menu. */\nexport interface SwipeAction {\n  /** The button's text: a short verb, such as \"Delete\" or \"Pin\". */\n  label: string;\n  /** Runs when the action is chosen: by a tap on its button, from the actions menu, or by a full swipe when it is the first action of its side. The row then closes. */\n  onClick: () => void;\n  /**\n   * The button's color, a theme token name: `destructive` for an action that deletes.\n   * @default \"secondary\"\n   */\n  tone?: ToneName | (string & { 'danger is \"destructive\"; accent is \"primary\"; neutral is \"secondary\"': never }) | undefined;\n\n  /** Not a field. Ouro UI uses `onClick`: `{ label: \"Delete\", onClick: remove }`. */\n  onPress?: { 'Use onClick: { label: \"Delete\", onClick: remove }': never };\n  /** Not a field. Ouro UI uses `tone`: `{ label: \"Delete\", tone: \"destructive\", onClick: remove }`. */\n  variant?: { 'Use tone: { label: \"Delete\", tone: \"destructive\", onClick: remove }': never };\n}\n\n/** Props for {@link SwipeActions}. */\nexport interface SwipeActionsProps {\n  /**\n   * Names the row for its actions button: \"Braised short ribs\" gives \"Actions for Braised short ribs\". It is always required.\n   *\n   * @claim \"It is always required\" registry/ouro/components/ouro/swipe-actions/swipe-actions.test-d.ts verify:fileLine(registry/ouro/components/ouro/swipe-actions/swipe-actions.test-d.ts, /\\{\\schildren:\\s\"Row\"\\s\\}>\\(\\)\\.not\\.toExtend<SwipeActionsProps>/)\n   */\n  label: string;\n  /** The row itself, usually an `Item`. It may be a link (`<Item href>`): a tap follows it and a swipe does not. */\n  children: ReactNode;\n  /** The actions a swipe toward the end reveals at the start edge, the first one outermost. A full swipe runs the first. */\n  leading?: readonly SwipeAction[] | undefined;\n  /** The actions a swipe toward the start reveals at the end edge, the first one outermost. A full swipe runs the first. */\n  trailing?: readonly SwipeAction[] | undefined;\n  /**\n   * The accessible name of the row's actions button; `{label}` is the row's `label`.\n   * Translate it with the rest of your interface.\n   * @default \"Actions for {label}\"\n   */\n  actionsLabel?: string | undefined;\n  /** Layout only: margins (`mt-2`). Appearance classes warn in development; give an action a `tone`. */\n  className?: string | undefined;\n\n  /** Not a prop. Ouro UI names the side: `trailing={[{ label: \"Delete\", onClick: remove }]}`. */\n  actions?: { 'Use trailing={[{ label: \"Delete\", onClick: remove }]}': never };\n  /** Not a prop. Ouro UI uses `leading`, which follows the reading direction: `leading={[{ label: \"Pin\", onClick: pin }]}`. */\n  left?: { 'Use leading={[{ label: \"Pin\", onClick: pin }]}': never };\n  /** Not a prop. Ouro UI uses `trailing`, which follows the reading direction: `trailing={[{ label: \"Delete\", onClick: remove }]}`. */\n  right?: { 'Use trailing={[{ label: \"Delete\", onClick: remove }]}': never };\n  /** Not a prop. Ouro UI uses `leading`: `leading={[{ label: \"Pin\", onClick: pin }]}`. */\n  leftActions?: { 'Use leading={[{ label: \"Pin\", onClick: pin }]}': never };\n  /** Not a prop. Ouro UI uses `trailing`: `trailing={[{ label: \"Delete\", onClick: remove }]}`. */\n  rightActions?: { 'Use trailing={[{ label: \"Delete\", onClick: remove }]}': never };\n  /** Not a prop. Deleting is an action: `trailing={[{ label: \"Delete\", tone: \"destructive\", onClick: remove }]}`. */\n  onDelete?: { 'Use trailing={[{ label: \"Delete\", tone: \"destructive\", onClick: remove }]}': never };\n}\n\nconst trailingFix = 'trailing={[{ label: \"Delete\", tone: \"destructive\", onClick: remove }]}';\nconst leadingFix = 'leading={[{ label: \"Pin\", onClick: pin }]}';\n\nconst toneOf = (action: SwipeAction): ToneName => (action.tone !== undefined && Object.hasOwn(actionTones, action.tone) ? (action.tone as ToneName) : \"secondary\");\n\nfunction EllipsisIcon(): JSX.Element {\n  return (\n    <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" fill=\"currentColor\" className=\"size-4\">\n      <circle cx=\"3\" cy=\"8\" r=\"1.5\" />\n      <circle cx=\"8\" cy=\"8\" r=\"1.5\" />\n      <circle cx=\"13\" cy=\"8\" r=\"1.5\" />\n    </svg>\n  );\n}\n\n/** One side's buttons. They cannot be reached, by focus or by a screen reader, unless that side is open. */\nfunction Strip({\n  side,\n  actions,\n  open,\n  stripRef,\n  onAction,\n}: {\n  side: SwipeSide;\n  actions: readonly SwipeAction[];\n  open: boolean;\n  stripRef: RefObject<HTMLDivElement | null>;\n  onAction: (action: SwipeAction) => void;\n}): JSX.Element | null {\n  const primary = actions[0];\n  if (!primary) return null;\n  // The first action is outermost: last in the trailing side's reading order.\n  const ordered = side === \"trailing\" ? [...actions].reverse() : actions;\n  return (\n    <div\n      ref={stripRef}\n      data-ouro-swipe-actions-side={side}\n      data-open={open ? \"\" : undefined}\n      inert={!open}\n      className={cn(stripClass[side], stripTones[toneOf(primary)])}\n    >\n      {ordered.map((action, index) => (\n        <button\n          key={index}\n          type=\"button\"\n          data-tone={toneOf(action)}\n          data-primary={action === primary ? \"\" : undefined}\n          data-ouro-control=\"swipe-actions\"\n          data-ouro-part=\"action\"\n          className={cn(actionClass, actionTones[toneOf(action)], action !== primary && fadeClass)}\n          onClick={() => onAction(action)}\n        >\n          {action.label}\n        </button>\n      ))}\n    </div>\n  );\n}\n\n/**\n * A list row with actions beside it that a horizontal swipe reveals: swipe toward the\n * start for the `trailing` actions (Delete, Archive), toward the end for the `leading`\n * ones (Pin). Wrap the row, usually an `Item`, and name it with `label`. The swipe is for\n * touch and pen, and it is never the only way: a long press on the row opens the same\n * actions as a `Menu` at the finger, for anyone who cannot swipe, and the row's actions\n * button opens that menu too. A mouse sees the button at the end of the row, and its\n * right-click keeps the browser's own menu (\"Open in new tab\" for a row that is a link);\n * on a touch screen the button is hidden from sight, and a keyboard or screen reader\n * reaches it on any device. While a finger is down on the row, text selection and the iOS\n * callout are off, so the long press opens the menu.\n *\n * An action that removes its row (Delete, chosen from the actions menu by keyboard) hands focus\n * to the next row's actions button, or the row before's when it was the last, so a keyboard or\n * screen reader user keeps their place in the list.\n *\n * The first action of each side is its primary one: it sits at the outer edge, and a\n * swipe past 60% of the row runs it on release, with no confirmation. So make a\n * destructive primary action undoable: delete, then offer Undo in a toast, as in the\n * example. When it cannot be undone, open a `ConfirmDialog` from `onClick` instead.\n *\n * The row follows the finger. A quick flick opens or closes it however short, by the\n * direction it was moving at release; a slow release opens it past half the actions'\n * width. A flick alone never runs an action: that takes the distance. The row springs to\n * rest from where it was let go, and a new swipe can catch it on the way.\n *\n * A vertical swipe that starts on a row scrolls the page. A row that is a link follows it\n * on a tap, never on a swipe. One row is open at a time, and an open row closes on a tap\n * outside it, on a tap on the row, when the page scrolls and on Escape. `leading` and\n * `trailing` follow the reading direction. With reduced motion the row still follows the\n * finger, so a swipe shows what it is about to do, and on release it jumps to rest\n * instead of springing.\n *\n * Use `Item` with `actions` instead when the buttons should always show, and `Menu` with\n * `contextTrigger` for actions on something that is not a list row.\n *\n * @group Lists\n * @see https://ui.ouroboros.bot/docs/swipe-actions\n *\n * @example\n * <ItemGroup label=\"Recipes\">\n *   {recipes.map((recipe) => (\n *     <SwipeActions\n *       key={recipe.id}\n *       label={recipe.title}\n *       leading={[{ label: \"Pin\", tone: \"primary\", onClick: () => pin(recipe) }]}\n *       trailing={[\n *         {\n *           label: \"Delete\",\n *           tone: \"destructive\",\n *           onClick: () => {\n *             remove(recipe);\n *             toast(\"Recipe deleted\", { action: { label: \"Undo\", onClick: () => restore(recipe) } });\n *           },\n *         },\n *         { label: \"Archive\", onClick: () => archive(recipe) },\n *       ]}\n *     >\n *       <Item href={`/recipes/${recipe.id}`} title={recipe.title} />\n *     </SwipeActions>\n *   ))}\n * </ItemGroup>\n * @claim \"An action that removes its row\" registry/ouro/components/ouro/swipe-actions/swipe-actions.test.tsx verify:testExists(registry/ouro/components/ouro/swipe-actions/swipe-actions.test.tsx::SwipeActions > hands focus to %s actions button when an action chosen from the menu removes its row)\n * @claim \"The first action of each side\" registry/ouro/components/ouro/swipe-actions/swipe-actions.test.tsx verify:testExists(registry/ouro/components/ouro/swipe-actions/swipe-actions.test.tsx::SwipeActions > runs the primary action on a full swipe of either side)\n * @claim \"The first action of each side\" registry/ouro/components/ouro/swipe-actions/swipe-actions.touch.test.tsx verify:testExists(registry/ouro/components/ouro/swipe-actions/swipe-actions.touch.test.tsx::SwipeActions on a phone > commits the primary action with a full swipe, once, and closes the row)\n * @claim \"The first action of each side\" registry/ouro/components/ouro/swipe-actions/swipe-actions.test.tsx verify:testExists(registry/ouro/components/ouro/swipe-actions/swipe-actions.test.tsx::SwipeActions > does not run the primary action when a full swipe is flicked back, and opens the side instead of nothing)\n * @claim \"The swipe is for touch and\" registry/ouro/components/ouro/swipe-actions/swipe-actions.touch.test.tsx verify:testExists(registry/ouro/components/ouro/swipe-actions/swipe-actions.touch.test.tsx::SwipeActions on a phone > opens the actions as a menu on a long press, for a touch that cannot swipe)\n * @claim \"The swipe is for touch and\" registry/ouro/components/ouro/swipe-actions/swipe-actions.test.tsx verify:testExists(registry/ouro/components/ouro/swipe-actions/swipe-actions.test.tsx::SwipeActions > opens every action as a menu at the finger on a long press, and that press is not a tap or a swipe)\n * @claim \"A flick alone never runs an\" registry/ouro/components/ouro/swipe-actions/swipe-actions.test.tsx verify:testExists(registry/ouro/components/ouro/swipe-actions/swipe-actions.test.tsx::SwipeActions > does not run the primary action when a full swipe is flicked back, and opens the side instead of nothing)\n * @claim \"A flick alone never runs an\" registry/ouro/components/ouro/swipe-actions/swipe-actions.test.tsx verify:testExists(registry/ouro/components/ouro/swipe-actions/swipe-actions.test.tsx::SwipeActions > opens on a short flick toward the actions and closes on a flick back, whatever the distance)\n * @claim \"A row that is a link\" registry/ouro/components/ouro/swipe-actions/swipe-actions.touch.test.tsx verify:testExists(registry/ouro/components/ouro/swipe-actions/swipe-actions.touch.test.tsx::SwipeActions on a phone > does not follow the link on a swipe, closes an open row on a tap, and follows the link on the next tap)\n */\nexport function SwipeActions(props: SwipeActionsProps): JSX.Element {\n  const {\n    label,\n    children,\n    leading: leadingProp,\n    trailing: trailingProp,\n    actionsLabel = \"Actions for {label}\",\n    className,\n    // Guard props (hint types), dropped here so they never reach the DOM.\n    actions,\n    left,\n    right,\n    leftActions,\n    rightActions,\n    onDelete,\n  } = props;\n  const reduced = useReducedMotion();\n  const leading = leadingProp ?? [];\n  const trailing = trailingProp ?? [];\n  const all = [...leading, ...trailing];\n\n  useAppearanceClassNameCheck(\n    \"SwipeActions\",\n    className,\n    process.env.NODE_ENV !== \"production\"\n      ? (token: string) => `remove \"${token}\"; give an action a tone: { label: \"Delete\", tone: \"destructive\", onClick: remove }`\n      : /* istanbul ignore next @preserve -- production only */ \"\",\n  );\n  useDevWarnings(\n    \"SwipeActions\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => [\n          !label && [\"label is required; it names the row for its actions button\", '<SwipeActions label=\"Braised short ribs\">'],\n          all.length === 0 && [\"it has no actions\", `<SwipeActions label=\"…\" ${trailingFix}>`],\n          ...all.map((action): readonly [string, string] | false => {\n            const bad = action as { onPress?: unknown; variant?: unknown };\n            const tone = String(action.tone);\n            if (action.tone !== undefined && !Object.hasOwn(actionTones, tone)) {\n              const fix = Object.hasOwn(renamedTones, tone) ? renamedTones[tone]! : \"destructive\";\n              return [\n                `the action \"${action.label}\" has tone: \"${tone}\", which is not a tone; use \"primary\", \"secondary\", \"destructive\", \"success\", \"warning\"`,\n                `{ label: \"${action.label}\", tone: \"${fix}\", onClick: … }`,\n              ];\n            }\n            if (bad.onPress !== undefined) return [`the action \"${action.label}\" has onPress, which is not a field`, `{ label: \"${action.label}\", onClick: … }`];\n            if (bad.variant !== undefined) {\n              return [`the action \"${action.label}\" has variant, which is not a field`, `{ label: \"${action.label}\", tone: \"destructive\", onClick: … }`];\n            }\n            return false;\n          }),\n          actions !== undefined && [\"actions is not a prop; name the side\", trailingFix],\n          left !== undefined && [\"left is not a prop; the sides follow the reading direction\", leadingFix],\n          right !== undefined && [\"right is not a prop; the sides follow the reading direction\", trailingFix],\n          leftActions !== undefined && [\"leftActions is not a prop\", leadingFix],\n          rightActions !== undefined && [\"rightActions is not a prop\", trailingFix],\n          onDelete !== undefined && [\"onDelete is not a prop; deleting is an action\", trailingFix],\n        ]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n\n  const [open, setOpen] = useState<SwipeSide | null>(null);\n  /** Whether the long-press menu is open. */\n  const [pressed, setPressed] = useState(false);\n  const rootRef = useRef<HTMLDivElement>(null);\n  // The last element focus came to in the row or its actions menus: React's focus events reach the row through a menu's portal.\n  const focusedIn = useRef<EventTarget | null>(null);\n  const trackRef = useRef<HTMLDivElement>(null);\n  const contentRef = useRef<HTMLDivElement>(null);\n  const leadingRef = useRef<HTMLDivElement>(null);\n  const trailingRef = useRef<HTMLDivElement>(null);\n  // Whether the last touch on the row was a swipe or a long press, whose click (if the browser sends one) is not a tap.\n  const swiped = useRef(false);\n  // Whether the last press on the row was a finger's or a pen's: only theirs can be a long press.\n  const fingered = useRef(false);\n  // The side a press stopped the row on its way to: where it goes on if the press is only a tap.\n  const caught = useRef<SwipeSide | null | undefined>(undefined);\n  // Where the track is, in px from closed, and the spring carrying it to rest.\n  const x = useRef(0);\n  const settling = useRef<SpringHandle | undefined>(undefined);\n  /** The swipe under a finger: where the track was when the finger took it, and where the finger has it now. */\n  const swipe = useRef({ base: 0, rtl: false, width: 0, offset: 0, full: false });\n\n  /** Puts the track at `value`. Only the track's own `transform` changes, so nothing else restyles. */\n  const place = useCallback((value: number) => {\n    x.current = value;\n    trackRef.current!.style.transform = value === 0 ? \"\" : `translateX(${value}px)`;\n  }, []);\n\n  /** Stops the spring where it is, leaving the track there for a finger to take. */\n  const hold = useCallback(() => {\n    const running = settling.current;\n    if (!running) return;\n    settling.current = undefined;\n    place(running.stop().value);\n  }, [place]);\n\n  /**\n   * Brings the row to rest: open on a side, at that side's width, or closed. It springs\n   * there from where it is, with the `velocity` the finger left it and a little bounce\n   * after a `flick`; with reduced motion the spring is a jump.\n   */\n  const settle = useCallback(\n    (side: SwipeSide | null, velocity = 0, flick = false) => {\n      const root = rootRef.current!;\n      hold();\n      root.removeAttribute(\"data-dragging\");\n      root.removeAttribute(\"data-full\");\n      const strip = side === \"leading\" ? leadingRef.current : side === \"trailing\" ? trailingRef.current : null;\n      let target = 0;\n      if (side && strip) {\n        const rtl = getComputedStyle(root).direction === \"rtl\";\n        target = ((side === \"trailing\") !== rtl ? -1 : 1) * strip.getBoundingClientRect().width;\n      } else if (root.querySelector(\"[data-ouro-swipe-actions-side] :focus\")) {\n        // Focus on an action about to become inert moves to the actions button, not to the page.\n        root.querySelector<HTMLElement>(\"[data-ouro-swipe-actions-menu] button\")!.focus();\n      }\n      setOpen(side && strip ? side : null);\n      if (x.current === target) return;\n      const handle = spring({\n        from: x.current,\n        to: target,\n        velocity,\n        damping: flick ? 0.8 : 1,\n        reduced,\n        element: root,\n        onUpdate: place,\n        onRest: () => {\n          settling.current = undefined;\n        },\n      });\n      // With reduced motion the spring was a jump, and the row is at rest already.\n      if (handle.running) settling.current = handle;\n    },\n    [hold, place, reduced],\n  );\n\n  // An open row closes on a press outside it, when anything else scrolls and on Escape.\n  useEffect(() => {\n    if (!open) return;\n    const root = rootRef.current!;\n    const inside = (target: EventTarget | null) => target instanceof Node && root.contains(target);\n    const onPointerDown = (event: PointerEvent) => {\n      if (!inside(event.target)) settle(null);\n    };\n    const onScroll = (event: Event) => {\n      if (!inside(event.target)) settle(null);\n    };\n    const onKeyDown = (event: KeyboardEvent) => {\n      if (event.key !== \"Escape\") return;\n      // This Escape closes the row only, not a Dialog or Sheet the row sits in.\n      event.stopPropagation();\n      settle(null);\n    };\n    document.addEventListener(\"pointerdown\", onPointerDown, true);\n    document.addEventListener(\"keydown\", onKeyDown, true);\n    addEventListener(\"scroll\", onScroll, { capture: true, passive: true });\n    return () => {\n      document.removeEventListener(\"pointerdown\", onPointerDown, true);\n      document.removeEventListener(\"keydown\", onKeyDown, true);\n      removeEventListener(\"scroll\", onScroll, { capture: true });\n    };\n  }, [open, settle]);\n\n  // An open side whose actions the app took away closes.\n  useLayoutEffect(() => {\n    if (open && (open === \"leading\" ? leading : trailing).length === 0) settle(open);\n  });\n\n  // A row unmounted while it springs to rest (its action removed it) stops moving.\n  useEffect(() => () => void settling.current?.stop(), []);\n\n  /** Runs an action and closes the row, which carries on from the `velocity` a full swipe left it with. */\n  const run = (action: SwipeAction, velocity = 0, flick = false) => {\n    settle(null, velocity, flick);\n    action.onClick();\n  };\n\n  const actionsOn = (side: SwipeSide) => (side === \"leading\" ? leading : trailing);\n  const drag = useDrag({\n    axis: \"x\",\n    onPress: (event) => {\n      // A row still springing to rest stops under the finger, where it is.\n      if (event.pointerType === \"mouse\" || !settling.current) return;\n      caught.current = open;\n      hold();\n    },\n    onPressEnd: () => {\n      // Only a tap, or a scroll: the row goes on to where it was going.\n      const side = caught.current;\n      caught.current = undefined;\n      if (side !== undefined) settle(side);\n    },\n    onStart: ({ event }) => {\n      // A mouse selects text and clicks; its way to the actions is the actions button.\n      // A finger that has opened the long-press menu is choosing from it, not swiping.\n      if (event.pointerType === \"mouse\" || pressed) return false;\n      const root = rootRef.current!;\n      caught.current = undefined;\n      swiped.current = true;\n      root.setAttribute(\"data-dragging\", \"\");\n      swipe.current = {\n        base: x.current,\n        rtl: getComputedStyle(root).direction === \"rtl\",\n        width: root.getBoundingClientRect().width,\n        offset: x.current,\n        full: false,\n      };\n      return true;\n    },\n    onMove: ({ delta }) => {\n      const now = swipe.current;\n      // The row moves with the finger, from where the finger took hold of it.\n      const wanted = now.base + delta;\n      const reach = Math.abs(wanted);\n      if (actionsOn(sideOf(wanted, now.rtl)).length === 0) {\n        // Nothing on this side: the row resists, and will spring back.\n        now.offset = rubberband(wanted, now.width);\n        now.full = false;\n      } else {\n        // Past the row's own width it resists too.\n        now.offset = reach <= now.width ? wanted : Math.sign(wanted) * (now.width + rubberband(reach - now.width, now.width));\n        now.full = reach >= now.width * FULL_SWIPE;\n      }\n      rootRef.current!.toggleAttribute(\"data-full\", now.full);\n      // Following a finger is not an animation: the row does it with reduced motion too.\n      place(now.offset);\n    },\n    onEnd: ({ velocity, flick, cancelled }) => {\n      // The browser took the gesture: back to where the row was.\n      if (cancelled) return settle(open);\n      const { offset, full, rtl } = swipe.current;\n      const side = sideOf(offset, rtl);\n      const primary = actionsOn(side)[0];\n      if (!primary) return settle(null, velocity, flick);\n      // Whether the finger was still moving the row further open when it lifted.\n      const opening = Math.sign(velocity) === Math.sign(offset);\n      // A full swipe runs the primary action, unless the finger was flicking the row back.\n      if (full && (opening || !flick)) return run(primary, velocity, flick);\n      // A flick goes the way it was moving, however short. A slow release goes by distance.\n      const strip = side === \"leading\" ? leadingRef.current! : trailingRef.current!;\n      const opens = flick ? opening : Math.abs(offset) > strip.getBoundingClientRect().width / 2;\n      settle(opens ? side : null, velocity, flick);\n    },\n  });\n  // A tap on an action runs it with no release velocity.\n  const tapped = (action: SwipeAction) => run(action);\n  const dragRef = drag.ref;\n  const setRoot = useCallback(\n    (element: HTMLDivElement) => {\n      rootRef.current = element;\n      const release = dragRef(element);\n      return () => {\n        // A row an action removes (Delete) hands focus to the next row's actions button, or the one before. Focus is in\n        // one of the row's actions menus then, outside the row, so the row's own actions button takes it first.\n        if (document.activeElement === focusedIn.current) element.querySelector<HTMLElement>(\"[data-ouro-swipe-actions-menu] button\")?.focus();\n        handOffFocus(element);\n        rootRef.current = null;\n        release!();\n      };\n    },\n    [dragRef],\n  );\n  const onPointerDown = (event: ReactPointerEvent<HTMLDivElement>) => {\n    // React sends a press inside the actions menu here too, although the menu is not in\n    // the row: it is a press on the menu, not the start of a swipe.\n    if (!event.currentTarget.contains(event.target as Node)) return;\n    drag.onPointerDown(event);\n  };\n\n  const onClickCapture = (event: ReactMouseEvent<HTMLDivElement>) => {\n    // A click inside the actions menu is the menu's own.\n    if (!event.currentTarget.contains(event.target as Node)) return;\n    // A click from the keyboard or a screen reader (`detail` 0) is never part of a swipe.\n    const pointer = event.detail !== 0;\n    if (pointer && swiped.current) {\n      swiped.current = false;\n      event.preventDefault();\n      event.stopPropagation();\n      return;\n    }\n    // A tap on an open row closes it and does nothing else: it does not follow the row's link.\n    if (open && contentRef.current!.contains(event.target as Node)) {\n      settle(null);\n      if (pointer) {\n        event.preventDefault();\n        event.stopPropagation();\n      }\n    }\n  };\n\n  const content = (\n    <div ref={contentRef} data-ouro-swipe-actions-content=\"\" className={contentClass}>\n      {children}\n    </div>\n  );\n  const items = all.map((action) => ({\n    label: action.label,\n    onClick: action.onClick,\n    tone: toneOf(action) === \"destructive\" ? (\"destructive\" as const) : undefined,\n  }));\n  const onLongPress = (menuOpen: boolean) => {\n    // A finger that is already swiping the row is not pressing it.\n    if (menuOpen && rootRef.current!.hasAttribute(\"data-dragging\")) return;\n    setPressed(menuOpen);\n    // The menu is now the way to the actions, and the press that opened it is not a tap on\n    // the row. A row the press caught on its way open stays closed when the finger lifts.\n    if (menuOpen) {\n      caught.current = undefined;\n      settle(null);\n    }\n    swiped.current = menuOpen;\n  };\n\n  return (\n    <div\n      ref={setRoot}\n      data-ouro=\"swipe-actions\"\n      data-open={open ?? undefined}\n      className={cn(rootClass, className)}\n      // Any new press forgets the last swipe. On the way down, so content that keeps its presses to itself cannot leave the next tap swallowed.\n      onPointerDownCapture={(event) => {\n        swiped.current = false;\n        fingered.current = event.pointerType !== \"mouse\";\n      }}\n      // A mouse's right-click is the browser's: its menu has \"Open in new tab\" for a row that\n      // is a link, and a mouse has the actions button in sight. Menu never hears of it.\n      onContextMenuCapture={(event) => {\n        if (fingered.current || !event.currentTarget.contains(event.target as Node)) return;\n        event.stopPropagation();\n      }}\n      // The lift of the long press that opened the menu is not a tap, as on a phone. Chromium\n      // can send one, whose press lands on the menu's backdrop and, half a second after the\n      // menu opened, closes it.\n      onTouchEnd={(event) => {\n        if (pressed && event.currentTarget.contains(event.target as Node)) event.preventDefault();\n      }}\n      onPointerDown={onPointerDown}\n      onPointerMove={drag.onPointerMove}\n      onPointerUp={drag.onPointerUp}\n      onPointerCancel={drag.onPointerCancel}\n      onClickCapture={onClickCapture}\n      onFocus={(event) => void (focusedIn.current = event.target)}\n    >\n      <div ref={trackRef} data-ouro-swipe-actions-track=\"\" className={trackClass}>\n        <Strip side=\"leading\" actions={leading} open={open === \"leading\"} stripRef={leadingRef} onAction={tapped} />\n        {all.length > 0 ? (\n          // A long press on the row opens the actions at the finger: the way in for a touch that cannot swipe.\n          <Menu contextTrigger={content} open={pressed} onOpenChange={onLongPress} items={items} />\n        ) : (\n          content\n        )}\n        {all.length > 0 && (\n          <div data-ouro-swipe-actions-menu=\"\" className={menuClass}>\n            <Menu\n              trigger={\n                <Button variant=\"plain\" tone=\"secondary\" size=\"sm\" aria-label={actionsLabel.replaceAll(\"{label}\", label)} data-ouro-control=\"swipe-actions\" data-ouro-part=\"menu\">\n                  <EllipsisIcon />\n                </Button>\n              }\n              // Opening the menu closes a side the row had open: the menu is now the way to the actions.\n              onOpenChange={(menuOpen) => {\n                if (menuOpen) settle(null);\n              }}\n              items={items}\n            />\n          </div>\n        )}\n        <Strip side=\"trailing\" actions={trailing} open={open === \"trailing\"} stripRef={trailingRef} onAction={tapped} />\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/swipe-actions/swipe-actions.tsx"
    }
  ],
  "docs": "A list row with actions beside it that a horizontal swipe reveals: swipe toward the start for the `trailing` actions (Delete, Archive), toward the end for the `leading` ones (Pin). Import: import { SwipeActions } from \"@/components/ouro/swipe-actions/swipe-actions\", with @/components replaced by your components alias (aliases.components in components.json, such as ~/components). Also installed: button, kbd, menu, the helpers they import in lib/ouro. Needs ouro-base in your stylesheet: add that item once per app, from the same place as this one, if you have not. Docs: https://ui.ouroboros.bot/docs/swipe-actions.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}