Components · Drag

Slide to confirm <clay-slide-confirm>

A deliberate action: drag a clay ball along its groove to the end. Let go early and it rolls back; at the end it runs .action, then shows pending, success or error. Wraps ui-slider.

Markdown
slide-confirm-basic.html
slide-confirm-basic.html
<clay-slide-confirm color="rose" pending-label="Deleting…" success-label="History deleted" reset-after="2400">
  <ui-slider aria-label="Slide to delete history">
    <ui-slider-control>
      <ui-slider-track>
        <ui-slider-indicator></ui-slider-indicator>
        <ui-slider-thumb></ui-slider-thumb>
      </ui-slider-track>
    </ui-slider-control>
  </ui-slider>
</clay-slide-confirm>
slide-confirm-basic.ts
import type { ClaySlideConfirm } from "claymorph-ui/slide-confirm"

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

export default function setup(root: HTMLElement) {
  root.querySelector<ClaySlideConfirm>("clay-slide-confirm")!.action = () => wait(1400)
}

Use it for

  • An action that should be deliberate: delete, send money, publish to everyone.

Not for

  • Everyday actions: use a button.
  • Choosing a value: use a slider.

Installation

npmpnpmyarnbun
terminal
npm install claymorph-ui @ui-sdk/web @ui-sdk/core

Then import claymorph-ui/clay.css once and each element you use, like claymorph-ui/button.

Usage

index.html
<clay-slide-confirm color="rose" pending-label="Deleting…" success-label="History deleted">
  <ui-slider aria-label="Slide to delete history">
    <ui-slider-control>
      <ui-slider-track>
        <ui-slider-indicator></ui-slider-indicator>
        <ui-slider-thumb></ui-slider-thumb>
      </ui-slider-track>
    </ui-slider-control>
  </ui-slider>
</clay-slide-confirm>
main.ts
document.querySelector("clay-slide-confirm")!.action = () =>
  fetch("/api/history", { method: "DELETE" })

API reference

Attributes

NameTypeDefault
color

The fill the ball pulls behind it.

neutral | teal | lilac | sky | peach | mint | butter | rose | slate | ink | <color> teal
threshold

Share of the groove the ball must pass for letting go to confirm.

number 0.9
pending-label

Written in the groove while action runs.

string Working…
success-label

Written once it succeeds, and announced.

string Done
error-label

Written after a failure, and announced.

string Try again
reset-after

Milliseconds after a success before the ball rolls home. 0 stays confirmed. An error always resets after 2400 ms.

number 0

Properties and events

NameTypeDefault
action

Runs once the ball reaches the end. A rejected promise shows the error state.

() => unknown —
actionState

The current state, also on data-state.

"idle" | "pending" | "success" | "error" —
statechange

Fires on the element whenever the state changes.

CustomEvent<{ state }> —

Accessibility

  • It's a real ui-slider: arrows, Page Up/Down, Home and End move the ball, and End confirms.
  • The slider's aria-label is both its name and the text written in the groove, so write it as an instruction.
  • While pending the slider has aria-busy; success and error are announced by a status region.