# Swipe actions

Swipe a message or a thread for retry, copy, pin or delete, with a commit line for a long swipe and a small bump when you cross it.

> chatcn Pro: needs a Pro license (https://chatcn.dev/pro). Install from the `@chatcn-pro` registry with your license token; setup at https://chatcn.dev/docs/chatcn-pro.

Example: Swipe actions. Swipe a chat left to archive or delete (keep going to delete), right to pin. Preview: https://chatcn.dev/preview/swipe-actions-demo

## Installation

```bash
npx shadcn@latest add @chatcn-pro/swipe-actions
```

## Usage

```tsx
import { SwipeActions } from "@/components/ui/chatcn/pro/swipe-actions"

<SwipeActions
  leading={[{ id: "pin", label: "Pin", icon: <PinIcon />, tone: "amber", onAction: pin }]}
  trailing={[
    { id: "archive", label: "Archive", icon: <ArchiveIcon />, onAction: archive },
    { id: "delete", label: "Delete", icon: <TrashIcon />, tone: "red", onAction: remove },  // a long swipe runs this one
  ]}
>
  <ThreadRow thread={thread} />
</SwipeActions>
```

The row follows the finger and the actions slide out from under it, spreading as it goes. Let go past half of the actions' width, or flick, and it rests open; tap the row to close it. Keep going past the commit line (60% of the row) and the outer action takes the whole strip, its icon gives a small bump and the device vibrates briefly where it can; let go and the row slides away, the action runs and the row comes back. Everything moves on one critically damped spring driven frame by frame, so a new touch catches the row mid flight. Only a clearly sideways move starts a swipe, so lists still scroll. One row is open at a time. For keyboards, a menu button with the same actions appears when the row is tabbed into. Physical directions follow right to left layouts.

## Examples

### States

Example: States. On messages at phone width: reply on one side, copy and retry on the other. Preview: https://chatcn.dev/preview/swipe-actions-states

## Props

| Prop | Type | Notes |
| --- | --- | --- |
| `leading` | `SwipeAction[]` | The start side; the first is what a long swipe runs |
| `trailing` | `SwipeAction[]` | The end side; the last is what a long swipe runs |
| `menu` | `boolean` | The keyboard menu. Default true |
| `disabled` | `boolean` | No swiping |
| `labels` | `{ more }` | The menu button's name |

## Keyboard

| Key | Action |
| --- | --- |
| Tab | Shows the actions menu button for the row |
| Enter | Opens the menu |

## Accessibility

- The swipe strip is decoration; the same actions are real menu items for keyboards and screen readers.
- Name the menu button per row through `labels.more`.
- Colors follow the kit's meanings: red for delete, amber for pin, never color alone.

## Motion

A critically damped spring, about 350 ms to rest, carrying the release velocity. Under reduced motion rows jump to rest and nothing vibrates.

Source: https://chatcn.dev/docs/components/swipe-actions