use crate::{mount_style, utils::AsyncCallback}; use leptos::*; use web_sys::FileList; #[component] pub fn Upload( #[prop(optional, into)] accept: MaybeSignal, #[prop(optional, into)] multiple: MaybeSignal, #[prop(optional, into)] on_before_upload: Option>, children: Children, ) -> impl IntoView { mount_style("upload", include_str!("./upload.css")); let on_file_addition = move |files: FileList| { spawn_local(async move { if let Some(on_before_upload) = on_before_upload { let is_allow = on_before_upload.call(files).await; if is_allow { //TODO submit } } }); }; let input_ref = create_node_ref::(); let on_change = move |_| { if let Some(input_ref) = input_ref.get_untracked() { if let Some(files) = input_ref.files() { on_file_addition(files); } } }; let on_click = move |_| { if let Some(input_ref) = input_ref.get_untracked() { input_ref.click(); } }; view! {
{children()}
} }