All Projects → brunomolteni → svelte-sortable-list

brunomolteni / svelte-sortable-list

Licence: other
A svelte 3 component that implements a list with animated drag-n-drop functionality.

Programming Languages

HTML
75241 projects

Labels

Projects that are alternatives of or similar to svelte-sortable-list

ctx-core
A composable monorepo web-service/front-end toolkit
Stars: ✭ 25 (-75.73%)
Mutual labels:  svelte
tikz
Random collection of standalone TikZ images
Stars: ✭ 87 (-15.53%)
Mutual labels:  svelte
svelte-marquee-text
[CSS GPU Animation] Marquee Text for Svelte
Stars: ✭ 47 (-54.37%)
Mutual labels:  svelte
svelte-typescript-setups
Examples and tests of different bundler setups for Svelte with Typescript and PostCSS (Tailwind)
Stars: ✭ 50 (-51.46%)
Mutual labels:  svelte
d3-fdg-svelte
d3 Force Directed Graph example (d3-force) implemented in sveltejs. REPL:
Stars: ✭ 31 (-69.9%)
Mutual labels:  svelte
auth
Sapper Authentication Implementation for Wordpress
Stars: ✭ 18 (-82.52%)
Mutual labels:  svelte
sdk-for-svelte
Appwrite SDK for Svelte 🧡 ⚠️ Warning - this SDK was designed to support Appwrite 0.9 and is not compatible with the latest Appwrite versions. We are planing to refactor it as part of the SDK Generator for better support and maintenance.
Stars: ✭ 69 (-33.01%)
Mutual labels:  svelte
wallet-adapter
Modular TypeScript wallet adapters and components for Solana applications.
Stars: ✭ 964 (+835.92%)
Mutual labels:  svelte
kzilla.xyz
Shorten the URL. Broaden the reach.
Stars: ✭ 34 (-66.99%)
Mutual labels:  svelte
perfect-home
firefox newtab/home replacement
Stars: ✭ 101 (-1.94%)
Mutual labels:  svelte
svelte-portable-text
Svelte component for rendering block content
Stars: ✭ 30 (-70.87%)
Mutual labels:  svelte
sveltekit-magic
An implementation of passwordless authentication using Magic with SvelteKit.
Stars: ✭ 38 (-63.11%)
Mutual labels:  svelte
aqua-fanpage
⚓ 湊あくあ Fanpage created with Svelte and Sveltestrap.
Stars: ✭ 30 (-70.87%)
Mutual labels:  svelte
kahi-ui
Straight-forward Svelte UI for the Web
Stars: ✭ 169 (+64.08%)
Mutual labels:  svelte
portfolio-svelte
My over-complicated personal site. A place to show off work and writing, and a place to try weird stuff.
Stars: ✭ 24 (-76.7%)
Mutual labels:  svelte
svelte-writable-derived
Two-way data-transforming stores for Svelte
Stars: ✭ 65 (-36.89%)
Mutual labels:  svelte
app-idea-generator
💡 Generate app ideas to take inspiration from, or to have a laugh
Stars: ✭ 13 (-87.38%)
Mutual labels:  svelte
svelte-template-hot
Copy of official Svelte template with added HMR support
Stars: ✭ 61 (-40.78%)
Mutual labels:  svelte
vite-plugin-webfont-dl
⚡ Webfont Download Vite Plugin - Make your Vite site load faster
Stars: ✭ 69 (-33.01%)
Mutual labels:  svelte
svelte-grid-responsive
Responsive grid system based on Bootstrap for Svelte
Stars: ✭ 41 (-60.19%)
Mutual labels:  svelte

🔃 SortableList

This component renders a list of items which can be reordered by draggin and dropping and implements FLIP animation for adding/removing/reordering items in the list.

To make the component work you need two thing at least: setting the list prop and responding to on:reorder event.

Basic Example ( Open in REPL )

<script>
import SortableList from 'svelte-sortable-list';

let list = ["First Item", "Second Item", "Third Item"];
const sortList = ev => {list = ev.detail};
</script>

<SortableList 
    {list} 
    on:sort={sortList}
/>

⤵️ Props and Slot

name type required default
list Array ✔️ ✖️
key String ✖️
slot Component <p>{key ? item[key] : item}</p>

The way this works is that you are required to pass a list prop to the component, which could be an array with anything inside, but if the array contains objects or arrays you must pass the key prop to specify what property is going to be used as key (needs to be unique to each object in the array).

You can customize what element is used as the list item passing any element as the child. If you do this you can access the item data by setting let:item on <SortableList> and {item} on your element ( you can also access the index in let:index).

⤴️ Events

The component handles all the internal functionality but since you are passing the list as a prop, it can't actually change the data you pass to it, so you need to respond to an event that gets triggered any time you sort items. This is done using the on:sort event handler, which gets passed an event object that contains the list inside the details property ( this is the default way of handling event data in svelte).

Complete Example ( Open in REPL )

<script>
import SortableList from 'svelte-sortable-list';
import Component from './Component.svelte';

let list = [
	{id: 1, name: 'First Item'},
	{id: 2, name: 'Second Item'},
	{id: 3, name: 'Third Item'}
];
const sortList = ev => {list = ev.detail};
</script>

<SortableList 
    {list} 
    key="id" 
    on:sort={sortList}
    let:item 
>
    <Component {item} />
</SortableList>
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].