npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@react2svelte/swipeable

v0.1.4

Published

Svelte swipe event handler ported from react-swipeable

Downloads

176

Readme

@react2svelte/swipeable

npm version

An action to emit swipe and tap events on an element, based on react-swipeable v7.0.0. Many thanks to all the contributors of that package for their hard work!

This package provides a Svelte Action called swipeable to attach to any DOM element to react to swipe events.

Quickstart

Install the library

npm i @react2svelte/swipeable

And add it to your component

<script lang="ts">
  import { swipeable } from '@react2svelte/swipeable';
  import type { SwipeEventData } from '@react2svelte/swipeable';
  // ...

  function handler(e: CustomEvent<SwipeEventData>) {
    console.log('User swiped!', e.detail);
  }

</script>

<div
  use:swipeable  <!-- use the action -->
  on:swiped={handler} <!-- set a handler for the swiped event -->
/>

Type hints on the events

Add the following line to your app.d.ts file

/// <reference types="@react2svelte/swipeable" />

(There should already be a line with /// <reference types="@sveltejs/kit" />)

Emitted events

The swipeable action emits 10 new events:

General swipe events

  • swipedstart - emitted once, at the beginning of a swipe
  • swiping - emitted continuously as the user is swiping
  • swiped - emitted once the swipe is complete

Directional swipe events. These are like swiped but for specific directions only

  • swipedup - User swiped up.
  • swipeddown - User swiped down.
  • swipedleft - User swiped left.
  • swipedright - User swiped right.

Tap events

  • tap

Passthrough events

  • touchstartormousedown
  • touchendormouseup

Configuration

This library is based on react-swipeable, and all the same configuration options and default values apply. Configration can be set by passing an object to use declation:

<div
  use:swipeable={{
    delta: 10,                             // min distance(px) before a swipe starts. *See Notes*
    preventScrollOnSwipe: false,           // prevents scroll during swipe (*See Details*)
    trackTouch: true,                      // track touch input
    trackMouse: false,                     // track mouse input
    rotationAngle: 0,                      // set a rotation angle
    swipeDuration: Infinity,               // allowable duration of a swipe (ms). *See Notes*
    touchEventOptions: { passive: true },  // options for touch listeners (*See Details*)
    }}
/>

Please have a look at the react-swipeable documentation for additional information.

Swipe event data

All Event Handlers are called with the below event data, SwipeEventData.

{
  event,          // source event
  initial,        // initial swipe [x,y]
  first,          // true for the first event of a tracked swipe
  deltaX,         // x offset (current.x - initial.x)
  deltaY,         // y offset (current.y - initial.y)
  absX,           // absolute deltaX
  absY,           // absolute deltaY
  velocity,       // √(absX^2 + absY^2) / time - "absolute velocity" (speed)
  vxvy,           // [ deltaX/time, deltaY/time] - velocity per axis
  dir,            // direction of swipe (Left|Right|Up|Down)
}

Alternative: svelte-gestures

svelte-gestures provides pinch, pan and rotate gestures besides swiping and tapping. However, there is no support for the swiping functionality of swipeable, which provides continuous updates as the user is swiping, rather than just a final event ones the swipe is complete.

For the user it can be helpful to get visual feedback as they are swiping - for example and image in a gallery - and see the image move as they are swiping, not just once at the end of their swipe.

License

MIT