# Slide to send

> The confirm step of a payment: carry the thumb to the person you are paying and the money drains into their avatar.

The control at the foot of a send-money or checkout sheet, where a plain button is too easy to tap by accident and a confirm dialog gets clicked through. The person you are paying sits at the end of the track. You carry the thumb to them and the track fills behind it; the words under the fill turn white, so "Slide to send $240.00" stays readable the whole way. Let go early and it springs home with the speed you let go at; a confident flick from past halfway counts. Let go against their photo and the fill drains into it: its tail runs up the track after the thumb and the money is gone into their avatar, which gives a little as it takes it. A badge on the avatar turns while your onSend runs and becomes a check when it resolves; the label says "Sent to Priya" and stays. If it throws, the money comes back out of the avatar and slides home, and the reason takes the label.

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/slide-to-send.json
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: `lucide-react`
- Hairline UI components it needs (the CLI installs them too): none
- Docs and live preview: https://hairlineui.com/ui/slide-to-send
- Registry item (source): https://hairlineui.com/r/slide-to-send.json

## Usage

```tsx
import { SlideToSend } from "@/components/slide-to-send";

<SlideToSend
  amount={240}
  to={{ name: "Priya Raman", avatar: "/people/priya.jpg" }}
  onSend={() => sendMoney({ to: "priya", amount: 240 })}
/>
```

## Send with your API

Resolve when the transfer is accepted and throw with a short reason when it isn't; the slider shows the reason and gives the money back. Send an idempotency key so a retry can never pay twice.

```tsx
"use client";
import { SlideToSend } from "@/components/slide-to-send";

export function PayBack({ friend, amount }: { friend: { id: string; name: string; photo: string }; amount: number }) {
  return (
    <SlideToSend
      amount={amount}
      format={{ style: "currency", currency: "EUR" }}
      to={{ name: friend.name, avatar: friend.photo }}
      onSend={async () => {
        const res = await fetch("/api/transfers", {
          method: "POST",
          headers: { "Content-Type": "application/json", "Idempotency-Key": crypto.randomUUID() },
          body: JSON.stringify({ to: friend.id, amount }),
        });
        if (!res.ok) throw new Error((await res.json()).message ?? "Couldn't send. Try again.");
      }}
    />
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `amount` | `number` | – | The amount, written in the label. |
| `to` | `{ name: string; avatar?: string }` | – | The recipient, at the end of the track. Without a photo, their initials. |
| `onSend` | `() => unknown \| Promise<unknown>` | – | Your transfer. Resolve when it went through; throw to give the money back, with the Error's message as the reason. |
| `format / locales` | `Intl.NumberFormatOptions / string \| string[]` | `{ style: "currency", currency: "USD" }` | How the amount is written. |
| `labels` | `{ slide?, sending?, sent?, failed? }` | – | The words, by default "Slide to send $240.00", "Sending to Priya", "Sent to Priya" and "Couldn't send. Try again." |
| `disabled` | `boolean` | `false` | Dimmed and still, e.g. while the amount is being entered. |
| `sound` | `boolean` | `false` | A soft tick in reach, a knock as it lands, and two notes when it is sent (synthesised, no files). |
| `onStatusChange` | `(status: "idle" \| "sending" \| "sent" \| "error") => void` | – | Every change of state. |

## States

- **idle**: A 56px track with the thumb on the left, the recipient's photo on the right and "Slide to send $240.00" between them, a light sweeping it the way you slide.
- **dragging**: The thumb follows the pointer with no lag and the track fills behind it in the primary colour; the words under the fill turn white. Past the start it gives a few pixels, no more.
- **in reach**: From 70% of the way the avatar leans in, up to 6%; touching it gives a soft tick and, on phones, a short buzz.
- **let go early**: The thumb springs home from where it was, carrying the speed you let go with; nothing is sent.
- **sending**: The thumb slips under the avatar and the fill's tail runs up the track after it until the money is gone into them (about 0.4s); the avatar gives a little, a badge on it turns and the label lifts to "Sending to Priya".
- **sent**: The badge turns emerald and a check draws itself; the label lifts to "Sent to Priya" and stays. Remount the component to take another payment.
- **failed**: The avatar shakes once, the money comes back out and springs home, and the error's message takes the label in red for 3.6s. Slide again to retry.
- **reduced motion**: The thumb still follows the pointer, but let go it jumps home or into the avatar; labels change in place.

## What it handles

Money needs a step that can't happen by accident. The usual one is a dialog that asks "Are you sure?" and gets clicked through, or a slider that ends on a check mark and says nothing about who got the money.

- **Deliberate, in place**: Nothing goes until the thumb reaches the person; a tap on the track only nudges the thumb to show the way.
- **Readable all the way**: The words under the fill turn white as it passes, so the amount is never covered by the thing confirming it.
- **You see who got it**: The fill drains into the recipient's photo, a badge turns on it while it sends and becomes a check.
- **Failure gives it back**: If onSend throws, the money comes back out of the avatar and slides home, with the error's message as the label.
- **Real physics**: The release speed is carried into the spring, a short flick from past halfway counts, and nothing re-renders while you drag.
- **Keyboard and screen readers**: Enter or Space sends from the thumb; its label says the amount and the person, and each step is announced.

## Replaces

slide to confirm, swipe to pay, confirm payment dialog, hold to confirm for payments, payment success state

## Where it fits

- **Send money**: The last step of paying a friend back or splitting a bill, under the amount.
- **Payouts**: Release a payout to a seller, a creator or a contractor.
- **Crypto and trading**: Confirm a send to a saved wallet or a withdrawal to an account.
- **Payroll and invoices**: Pay one invoice or one person's pay from its review sheet.

## Notes

- The thumb is a button labelled with the amount and the person; Enter or Space sends from it, and Escape during a drag sends it home.
- Sending, sent and failure messages are announced from a status region outside the button.
- The thumb, the fill, the white words and the avatar move by transform only, from three springs, without re-rendering while you drag.
- onSend is called once per send, the moment the slide is committed; nothing can send while one is in flight. It stays sent until it is remounted (a new key).
- Fills the width it is given (at least 248px); the track is the page background with a 1px border, so it reads on cards and grey panels.

License: MIT (https://hairlineui.com/license#components)
