tarb / svelte-dnd-list

Simple and lightweight Svelte Drag and Drop library
MIT License
47 stars 4 forks source link

Support variable heights per item #5

Open maps82 opened 1 year ago

maps82 commented 1 year ago

For the lib to behave correctly it is necessary to specify an itemSize in pixels. It would be awesome if it would work with dynamic sizes per item. Is this planned or even possible in the current implementation?

anurag-dhamala commented 7 months ago

Looks like I have found a workaround to adjust items of different sizes.

Give itemSize to around 200-300 (play around with it; dragging the items around), and give itemClass. (Say, the itemClass is "single-item"). Then, give the css to it in your global css file as below:

.single-item { 
   height: fit-content !important;
}

The DragDropList component should look something similar to this:

<DragDropList
                    id="verticalY"
                    type={VerticalDropZone}
                    itemSize={300}
                    itemClass="single-item"
                    itemCount={items.length}
                    on:drop={onDrop}
                    let:index
                    keyFn={(index)=> {
                        return items[index].id
                    }}
>