Svelte Swipe To Action

A highly customizable swipe-to-action component for Svelte 5

npm i svelte-swipe-to-action

Preview

Slide to confirm

Confirmed!

STATUS
pending
VALUE
0
HOLD
no
THRESHOLD
below

Events

Interact with the slider to see events

Options

{
  "width": 400,
  "height": 56,
  "threshold": 75,
  "label": "Slide to confirm",
  "completeLabel": "Confirmed!",
  "trackColor": "#f3f4f6",
  "completeTrackColor": "#22c55e",
  "trackBorderColor": "#d1d5db",
  "trackBorderWidth": 1,
  "trackRadius": 10,
  "thumbColor": "#6b7280",
  "completeThumbColor": "#16a34a",
  "thumbRadius": 8,
  "labelColor": "#6b7280",
  "completeLabelColor": "#ffffff",
  "labelSize": "md"
}

Usage

<script lang="ts">
  import Swipe from 'svelte-swipe-to-action';
  import type { SwipeOptions } from 'svelte-swipe-to-action';
  let status = $state(false);
  const opts: SwipeOptions = {
    "width": 400,
    "height": 56,
    "threshold": 75,
    "label": "Slide to confirm",
    "completeLabel": "Confirmed!",
    "trackColor": "#f3f4f6",
    "completeTrackColor": "#22c55e",
    "trackBorderColor": "#d1d5db",
    "trackBorderWidth": 1,
    "trackRadius": 10,
    "thumbColor": "#6b7280",
    "completeThumbColor": "#16a34a",
    "thumbRadius": 8,
    "labelColor": "#6b7280",
    "completeLabelColor": "#ffffff",
    "labelSize": "md"
  };
</script>

<Swipe
  options={opts}
  bind:status
/>

Props

PropTypeDefaultDescription
statusbooleanfalseTwo-way bindable confirmed state
valuenumber0Current slider value (0-100)
holdbooleanfalseWhether slider is being held
optionsSwipeOptionsAll appearance and layout props
chevronIconSnippetchevronCustom thumb icon
completeIconSnippetcheckmarkCustom completed icon

Events

EventSignatureDescription
oninput(event: Event, value: number)Fires continuously while the slider is being dragged
oncomplete(event: Event, isComplete: boolean, value: number)Fires when the slider is released above the threshold
oncancel(event: Event, isComplete: boolean, value: number)Fires when the slider is released below the threshold
onpassthreshold(event: Event, side: boolean, value: number)Fires when the slider crosses the threshold in either direction (side: true = forward)

Swipe Options

All properties in the options object:

OptionTypeDefaultDescription
widthnumber400Slider width in pixels
heightnumber50Slider height in pixels (also sets thumb size)
thresholdnumber80Percentage (0-100) of slide required to confirm
labelstringSlide to ...Text shown on the slider before completion
completeLabelstringCompleteText shown after the slider is confirmed
rtlModebooleanfalseEnables right-to-left sliding direction
trackColorstring#fffBackground color of the slider track
completeTrackColorstring#4caf50Track background color after confirmed
trackBorderColorstringtransparentBorder color of the track
trackBorderWidthnumber1Track border width in pixels
trackRadiusnumber0Track border radius in pixels
trackClassstringAdditional CSS class for the track
completeTrackClassstringCSS class for the track when confirmed
thumbColorstring#dddColor of the slider thumb (handle)
completeThumbColorstring#dddThumb color after confirmed
thumbRadiusnumber0Thumb border radius in pixels
labelColorstring#000Text color of the label
labelClassstringAdditional CSS class for the label
completeLabelColorstring#000Text color of the completed label
completeLabelClassstringAdditional CSS class for the completed label
labelSizestring'md'Text size preset: 'xs', 'sm', 'md', 'lg', 'xl'. Scales with height

svelte-swipe-to-action v1.0.0 — MIT License — Made with ❤️ by kodaicoder