# GlassSlideToConfirm

> A slide-to-confirm track. Drag its glass thumb to the end to run one deliberate action; let go early and it springs back.

```tsx
import { AlarmClock } from 'lucide-react'
import { useEffect, useState } from 'react'

import { GlassSlideToConfirm } from '@/components/liquid-glass'

const clock = () => new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', hourCycle: 'h23' })

// An alarm laid on its side: your own clock on the left, Snooze and the slide stacked on the
// right. Snooze is a plain button, no glass: flat orange. The track is bare (`fill={false}`):
// the thumb pulls no fill behind it and bends the label alone. With `mirror`, the held thumb's
// rim picks up the orange button above it.
// Where the two would not fit side by side (a phone), the clock moves on top.
export default function Demo() {
  // Read after mounting, so the server's time is never shown.
  const [time, setTime] = useState('')
  useEffect(() => {
    setTime(clock())
    const id = setInterval(() => setTime(clock()), 1000)
    return () => clearInterval(id)
  }, [])

  return (
    <div className="@container w-full max-w-2xl">
      <div className="flex flex-col items-center gap-8 @lg:flex-row @lg:justify-between">
        <div className="flex flex-col items-center @lg:items-start">
          <p className="flex items-center gap-2 text-lg text-neutral-500 dark:text-neutral-400">
            <AlarmClock className="size-5" />
            <span>
              <span className="font-light">Time to</span> <span className="font-display">wake up</span>
            </span>
          </p>
          <p className={`mt-1 text-7xl font-semibold tracking-tight text-neutral-900 tabular-nums dark:text-white ${time ? '' : 'invisible'}`}>{time || '00:00'}</p>
        </div>
        <div className="flex w-full max-w-72 flex-col gap-3">
          <button
            type="button"
            className="h-24 w-full cursor-pointer rounded-full bg-orange-500 text-xl font-semibold text-white transition-transform duration-150 outline-none focus-visible:ring-2 focus-visible:ring-orange-500 focus-visible:ring-offset-2 motion-safe:active:scale-[0.97]"
          >
            Snooze
          </button>
          <GlassSlideToConfirm
            size="xl"
            fill={false}
            mirror
            icon={<span className="size-7 rounded-md bg-current" />}
            fillClassName="bg-neutral-900 text-white dark:bg-white dark:text-neutral-900"
            successLabel="Stopped"
            resetAfter={2600}
            onConfirm={() => {}}
          >
            Slide to stop
          </GlassSlideToConfirm>
        </div>
      </div>
    </div>
  )
}
```

**Use it for**

- A routine action a stray tap must not trigger: send money, pay, unlock, start a shift.
- Phone-first surfaces, where a deliberate horizontal gesture replaces a confirm dialog.

**Not for**

- Easily undone actions: use GlassButton.
- An async action a single press may start: use GlassActionButton.
- Consequences people must read first: use a dialog.

```bash
npx shadcn@latest add https://onemorethink.dev/r/slide-to-confirm.json
```

## Usage

```tsx
import { GlassSlideToConfirm } from '@/components/liquid-glass'

<GlassSlideToConfirm
  pendingLabel="Sending"
  successLabel="Sent"
  errorLabel="Not sent, slide to retry"
  onConfirm={send} // return the promise
>
  Slide to send $240
</GlassSlideToConfirm>
```

## The flow

- **Idle.** The thumb rests at the start as frosted white glass; the instruction is written in the track.
- **Drag.** The thumb turns to clear glass and bends the fill and the label it passes; its chevron stays in place, in the fill's text colour. It stays round while held, and speed stretches it along its travel. The fill trails a moment behind, joined to the thumb by a bridge that thins as they pull apart, and the track and the fill swell around the thumb like a membrane. Pushed past the end the track stretches like a rubber band; pushed against the start the wall gives a little. The thumb stays round at both.
- **Let go early.** Below `threshold` the thumb springs back; the fill's tail follows and is absorbed after it.
- **Pending.** Past the threshold the thumb lands at the end, the track draws in to a ring around it and `pendingLabel` appears beside it while a spinner takes the chevron's place, until the promise from `onConfirm` settles.
- **Success.** The white glass takes the fill's colour and the chevron's stroke bends into a check, beside `successLabel`; the thumb swells and settles as the check appears. It stays confirmed, unless you set `resetAfter`: then the track opens first, `successLabel` leaving with its edge, and the thumb flies home after it, squashing a little as it lands against the start.
- **Error.** If `onConfirm` throws, the track opens again, the thumb returns and `errorLabel` replaces the instruction until the next slide.

## Examples

### A fill, and an action that takes a moment

```tsx
import { GlassSlideToConfirm } from '@/components/liquid-glass'

const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))

// Short and chunky: the `xl` track in a narrow width, with a one-word label.
export default function Demo() {
  return (
    <GlassSlideToConfirm className="max-w-64" size="xl" pendingLabel="Sending" successLabel="Sent" resetAfter={2600} onConfirm={() => wait(1400)}>
      Send
    </GlassSlideToConfirm>
  )
}
```

`fill={false}` leaves the track bare: the thumb pulls no fill behind it and bends the label alone, its icon dark on a light page and white on a dark one; `fillClassName` then colours only the success. `mirror` lets the held thumb's rim mirror the page around the track, so a colourful neighbour (the orange button in the preview at the top of this page) lights the rim that faces it, and the icon inside glows. Both are off unless you ask: the thumb mirrors only while it is clear, never at rest.

Colour the fill with `fillClassName`: its `bg-*` is the fill, its `text-*` is the label written on it, and the thumb's icon while the glass is clear. At rest the thumb is always frosted white glass with a dark icon (a flat white disc without WebGL2). The control fills its container, so set the width on a parent or with `className`.

## API reference

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `string` | — | The instruction in the track, and the slider's accessible name. |
| `onConfirm` | `() => unknown` | — | Required. Runs once the thumb reaches the end; return a promise to stay pending until it settles. |
| `onConfirmError` | `(error) => void` | — | Called when `onConfirm` throws; the thumb springs back. |
| `pendingLabel` | `string` | — | Written beside the spinner while `onConfirm` runs. |
| `successLabel` | `string` | — | Written beside the check after it succeeds. |
| `errorLabel` | `string` | — | Replaces the instruction after a failure, until the next slide. |
| `threshold` | `number` | `0.9` | Share of the track the thumb must pass before letting go confirms. |
| `resetAfter` | `number` | `0` | Milliseconds after a success before the track opens again. `0` stays confirmed. |
| `hint` | `boolean` | `true` | Nudges the thumb every few seconds until it has been touched. Off with reduced motion. |
| `icon` | `ReactNode` | `chevron` | The thumb's idle icon. |
| `size` | `'sm' \| 'md' \| 'lg' \| 'xl'` | `'md'` | Track height 40, 48, 56 or 96 px. |
| `fillClassName` | `string` | `'bg-[#3291FF] text-white'` | Classes of the fill: its colour and the colour of the text on it. |
| `fill` | `boolean` | `true` | `false` leaves the track bare: no fill behind the thumb; `fillClassName` colours the success alone. |
| `mirror` | `boolean` | `false` | The held thumb's rim mirrors the page around the track: a colourful neighbour lights the rim that faces it, and the icon glows. |
| `disabled` | `boolean` | `false` | Dims the control and ignores pointer and keyboard. |
| `className` | `string` | — | Width and position of the track. |

## Accessibility

- A real `role="slider"` named by its label, with `aria-valuenow` kept in step with the thumb.
- Arrow keys move the thumb in tenths, Page Up and Page Down in quarters, Home returns it and End confirms. Holding Space or Enter glides it to the end; letting go early springs it back.
- A `role="status"` region announces the pending, success and error labels. While pending or confirmed the slider is `aria-disabled`.
- Success is never colour alone: the chevron becomes a check and the label is written beside it.
- Vertical page scroll still works over the control on touch. With reduced motion each state shows at once.

Source: https://onemorethink.dev/docs/slide-to-confirm
