Skip to main content

leptos_use_drop_zone/
options.rs

1use default_struct_builder::DefaultBuilder;
2use std::fmt::{Debug, Formatter};
3use std::sync::Arc;
4
5/// Options for [`use_drop_zone_with_options`](crate::use_drop_zone_with_options).
6#[derive(DefaultBuilder, Clone)]
7#[cfg_attr(feature = "ssr", allow(dead_code))]
8pub struct UseDropZoneOptions {
9    /// Event handler for the [`drop`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/drop_event) event
10    pub(crate) on_drop: Arc<dyn Fn(UseDropZoneEvent) + Send + Sync>,
11    /// Event handler for the [`dragenter`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dragenter_event) event
12    pub(crate) on_enter: Arc<dyn Fn(UseDropZoneEvent) + Send + Sync>,
13    /// Event handler for the [`dragleave`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dragleave_event) event
14    pub(crate) on_leave: Arc<dyn Fn(UseDropZoneEvent) + Send + Sync>,
15    /// Event handler for the [`dragover`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dragover_event) event
16    pub(crate) on_over: Arc<dyn Fn(UseDropZoneEvent) + Send + Sync>,
17}
18
19impl Default for UseDropZoneOptions {
20    fn default() -> Self {
21        Self {
22            on_drop: Arc::new(|_| {}),
23            on_enter: Arc::new(|_| {}),
24            on_leave: Arc::new(|_| {}),
25            on_over: Arc::new(|_| {}),
26        }
27    }
28}
29
30impl Debug for UseDropZoneOptions {
31    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
32        write!(f, "UseDropZoneOptions")
33    }
34}
35
36/// Event passed as argument to the event handler functions of `UseDropZoneOptions`.
37#[derive(Clone, Debug)]
38pub struct UseDropZoneEvent {
39    /// Files being handled
40    pub files: Vec<web_sys::File>,
41    /// The original drag event
42    pub event: web_sys::DragEvent,
43}