@svelte-put/swipeable
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

@svelte-put/swipeable

npm.badge bundlephobia.badge docs.badge

Svelte action use:swipeable - event for setting up quick gestures on an element (swipe right to delete, for example).

svelte-put

This package is part of the @svelte-put family. For contributing guideline and more, refer to its readme.

Usage & Documentation

See the dedicated documentation page here.

Quick Start

<script lang="ts">
  import { swipe } from '@svelte-put/swipeable';

	const items = $state([1, 2, 3, 4, 5]);

  function delete(e: CustomEvent) {
		const id = e.target.dataset.id;
		items = items.filter(i => i !== id);
  }

	function archive(e: CustomEvent) {
		const id = e.target.dataset.id;
		// call backend API to archive...

		items = items.filter(i => i !== );
	}
</script>

<ul>
	{#each items as i}
		<li
			use:swipe={{ direction: 'horizontal', threshold: '50%' }}
			data-id={i}
			onswipeleft={archive}
			onswiperight={delete}
		>{i}</li>
	{/each}
</ul>

Package Sidebar

Install

npm i @svelte-put/swipeable

Weekly Downloads

9

Version

1.1.0

License

MIT

Unpacked Size

20.3 kB

Total Files

11

Last publish

Collaborators

  • vnphanquang