Crates.io | sycamore-dnd |
lib.rs | sycamore-dnd |
version | 0.1.1 |
source | src |
created_at | 2023-04-11 08:23:31.826955 |
updated_at | 2023-04-11 08:23:31.826955 |
description | A drag and drop library for sycamore |
homepage | https://github.com/sycamore-components/sycamore-dnd |
repository | https://github.com/sycamore-components/sycamore-dnd |
max_upload_size | |
id | 835886 |
size | 27,224 |
A drag and drop library for sycamore
Adds the create_draggable
and create_droppable
functions that abstract the difficult
parts of drag and drop.
This library is still fairly low level and makes no assumptions about drop behaviour. This makes
it possible to do things like reading a file, but requires custom code for things like sortable
lists or other common drag and drop scenarios.
This library currently requires the GitHub version of Sycamore because of the features it offers.
Once the Attributes
change is released to crates.io
this will no longer be necessary.
#[component]
fn App<'cx, G: Html>(cx: Scope<'cx>) -> View<G> {
let inside = create_signal(cx, false);
let drop_inside = create_droppable(cx)
.on_drop(move |_: ()| inside.set(true))
.hovering_class("drag-over")
.build();
let drop_outside = create_droppable(cx)
.on_drop(move |_: ()| inside.set(false))
.hovering_class("drag-over")
.build();
let drag = create_draggable(cx)
.dragging_class("dragging")
.build();
view! { cx,
div(class = "container") {
div(style = "min-height:100px;width:100%;", ref = drop_outside) {
(if !*inside.get() {
view! { cx,
div(class = "item", ref = drag) {
"Drag me"
}
}
} else {
View::empty()
})
}
div(class="box", ref = drop_inside) {
(if *inside.get() {
view! { cx,
div(class = "item", ref = drag) {
"Drag me"
}
}
} else {
View::empty()
})
}
}
}
}