Slide to Unlock

A drag-to-confirm control inspired by the original iPhone slide-to-unlock gesture.

motion-sv
Slide to unlock

Installation

pnpm dlx shadcn-svelte@latest add http://sveltekit-prerender/r/slide-to-unlock.json

Usage

usage.svelte

Features

  • Smooth drag interaction with spring physics via Motion Svelte
  • Composable compound components (track, handle, text)
  • Customizable handle and colors
  • Built-in shimmering text effect

Examples

Basic

Run a callback when the handle reaches the end of the track.

Reset

Return the handle to its starting position with the reset method.

Custom prompt

Change the instruction while the handle is being dragged.

Custom handle

Provide custom handle content, colors, and drag width.

Confirm action

Replace a one-time confirmation gesture with completion feedback.

Async action

Show processing and success states after the gesture completes.

Destructive confirmation

Add deliberate friction before a destructive action.

Props

SlideToUnlock

Root provider for the slide-to-unlock interaction.

NameTypeDefaultDescription
childrenSnippetrequiredTrack, text, and handle composition rendered inside the root.
handleWidthnumber56Width of the draggable handle in pixels.
onUnlock() => voidundefinedCalled when the handle reaches the end of the track.
refHTMLDivElement | nullnullBindable reference to the root element.
classstringundefinedAdditional classes applied to the root element.

SlideToUnlockTrack

Track that supplies the drag constraint boundary.

NameTypeDefaultDescription
childrenSnippetrequiredText and handle content rendered inside the track.
refHTMLDivElement | nullnullBindable reference to the track element.
classstringundefinedAdditional classes applied to the track.

SlideToUnlockText

Instruction text that fades with drag progress.

NameTypeDefaultDescription
childrenSnippet<[{ isDragging: boolean }]>requiredText renderer receiving the current dragging state.
styleMotionStylePropsundefinedAdditional Motion style values merged with the progress styles.
refHTMLDivElement | nullnullBindable reference to the text element.
classClassValueundefinedAdditional classes applied to the text element.

SlideToUnlockHandle

Draggable handle with a built-in arrow fallback.

NameTypeDefaultDescription
childrenSnippetdefault arrowOptional custom content rendered inside the handle.
styleMotionStylePropsundefinedAdditional Motion style values merged with the drag styles.
refHTMLDivElement | nullnullBindable reference to the handle element.
classClassValueundefinedAdditional classes applied to the handle.