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.
<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>
<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>
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)
}
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
npm install claymorph-ui @ui-sdk/web @ui-sdk/core
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
<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>
<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>
document.querySelector("clay-slide-confirm")!.action = () =>
fetch("/api/history", { method: "DELETE" })
document.querySelector("clay-slide-confirm")!.action = () =>
fetch("/api/history", { method: "DELETE" })
API reference
Attributes
| Name | Type | Default |
|---|---|---|
colorThe fill the ball pulls behind it. |
neutral | teal | lilac | sky | peach | mint | butter | rose | slate | ink | <color> |
teal |
thresholdShare of the groove the ball must pass for letting go to confirm. |
number |
0.9 |
pending-labelWritten in the groove while |
string |
Working… |
success-labelWritten once it succeeds, and announced. |
string |
Done |
error-labelWritten after a failure, and announced. |
string |
Try again |
reset-afterMilliseconds after a success before the ball rolls home. |
number |
0 |
Properties and events
| Name | Type | Default |
|---|---|---|
actionRuns once the ball reaches the end. A rejected promise shows the error state. |
() => unknown |
— |
actionStateThe current state, also on |
"idle" | "pending" | "success" | "error" |
— |
statechangeFires 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-labelis 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.