2023-07-15 00:55:02 +01:00
|
|
|
use leptos::html::Div;
|
|
|
|
use leptos::*;
|
|
|
|
use leptos_use::docs::{demo_or_body, BooleanDisplay};
|
|
|
|
use leptos_use::{use_drop_zone_with_options, UseDropZoneOptions, UseDropZoneReturn};
|
|
|
|
|
|
|
|
#[component]
|
2023-07-27 18:06:36 +01:00
|
|
|
fn Demo() -> impl IntoView {
|
|
|
|
let (dropped, set_dropped) = create_signal(false);
|
2023-07-15 00:55:02 +01:00
|
|
|
|
2023-07-27 18:06:36 +01:00
|
|
|
let drop_zone_el = create_node_ref::<Div>();
|
2023-07-15 00:55:02 +01:00
|
|
|
|
|
|
|
let UseDropZoneReturn {
|
|
|
|
is_over_drop_zone,
|
|
|
|
files,
|
|
|
|
} = use_drop_zone_with_options(
|
|
|
|
drop_zone_el,
|
|
|
|
UseDropZoneOptions::default()
|
|
|
|
.on_drop(move |_| set_dropped(true))
|
|
|
|
.on_enter(move |_| set_dropped(false)),
|
|
|
|
);
|
|
|
|
|
2023-07-27 19:48:21 +01:00
|
|
|
view! {
|
|
|
|
<div class="flex">
|
2023-07-15 00:55:02 +01:00
|
|
|
<div class="w-full h-auto relative">
|
2023-07-27 19:48:21 +01:00
|
|
|
<p>
|
|
|
|
Drop files into dropZone
|
|
|
|
</p>
|
2023-07-15 00:55:02 +01:00
|
|
|
<img width="64" src="use_drop_zone/demo/img/leptos-use-logo.svg" alt="Drop me"/>
|
|
|
|
<div
|
|
|
|
node_ref=drop_zone_el
|
|
|
|
class="flex flex-col w-full min-h-[200px] h-auto bg-gray-400/10 justify-center items-center pt-6"
|
|
|
|
>
|
|
|
|
<div>
|
2023-07-27 19:48:21 +01:00
|
|
|
is_over_drop_zone:
|
|
|
|
<BooleanDisplay value=is_over_drop_zone/>
|
2023-07-15 00:55:02 +01:00
|
|
|
</div>
|
|
|
|
<div>
|
2023-07-27 19:48:21 +01:00
|
|
|
dropped:
|
|
|
|
<BooleanDisplay value=dropped/>
|
2023-07-15 00:55:02 +01:00
|
|
|
</div>
|
|
|
|
<div class="flex flex-wrap justify-center items-center">
|
2023-07-27 19:48:21 +01:00
|
|
|
<For
|
|
|
|
each=files
|
|
|
|
key=|f| f.name()
|
2023-09-30 18:24:06 +01:00
|
|
|
let:file
|
|
|
|
>
|
|
|
|
<div class="w-200px bg-black-200/10 ma-2 pa-6">
|
|
|
|
<p>
|
|
|
|
Name:
|
|
|
|
{file.name()}
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
Size:
|
|
|
|
{file.size()}
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
Type:
|
|
|
|
{file.type_()}
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
Last modified:
|
|
|
|
{file.last_modified()}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</For>
|
2023-07-15 00:55:02 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
_ = console_log::init_with_level(log::Level::Debug);
|
|
|
|
console_error_panic_hook::set_once();
|
|
|
|
|
2023-07-27 18:06:36 +01:00
|
|
|
mount_to(demo_or_body(), || {
|
2023-07-27 19:48:21 +01:00
|
|
|
view! { <Demo/> }
|
2023-07-15 00:55:02 +01:00
|
|
|
})
|
|
|
|
}
|