feat: add upload component

This commit is contained in:
luoxiao 2023-10-22 22:48:17 +08:00
parent 16f8ba13c3
commit 0f0fde49a3
7 changed files with 90 additions and 0 deletions

View file

@ -40,6 +40,7 @@ pub fn App() -> impl IntoView {
<Route path="/skeleton" view=SkeletonPage/> <Route path="/skeleton" view=SkeletonPage/>
<Route path="/switch" view=SwitchPage/> <Route path="/switch" view=SwitchPage/>
<Route path="/tag" view=TagPage/> <Route path="/tag" view=TagPage/>
<Route path="/upload" view=UploadPage/>
</Route> </Route>
<Route path="/mobile/tabbar" view=TabbarDemoPage/> <Route path="/mobile/tabbar" view=TabbarDemoPage/>
<Route path="/mobile/nav-bar" view=NavBarDemoPage/> <Route path="/mobile/nav-bar" view=NavBarDemoPage/>

View file

@ -145,6 +145,10 @@ fn gen_menu_data() -> Vec<MenuGroupOption> {
value: "switch".into(), value: "switch".into(),
label: "Switch".into(), label: "Switch".into(),
}, },
MenuItemOption {
value: "upload".into(),
label: "Upload".into(),
},
], ],
}, },
MenuGroupOption { MenuGroupOption {

View file

@ -30,6 +30,7 @@ mod table;
mod tabs; mod tabs;
mod tag; mod tag;
mod toast; mod toast;
mod upload;
pub use alert::*; pub use alert::*;
pub use auto_complete::*; pub use auto_complete::*;
@ -63,3 +64,4 @@ pub use table::*;
pub use tabs::*; pub use tabs::*;
pub use tag::*; pub use tag::*;
pub use toast::*; pub use toast::*;
pub use upload::*;

View file

@ -0,0 +1,36 @@
use crate::components::{Demo, DemoCode};
use leptos::*;
use melt_ui::*;
use prisms::highlight_str;
#[component]
pub fn UploadPage() -> impl IntoView {
view! {
<div style="width: 896px; margin: 0 auto;">
<h1>"Upload(TODO)"</h1>
<Demo>
<Upload>
<Button>
"upload"
</Button>
</Upload>
<DemoCode
slot
html=highlight_str!(
r#"
<Upload>
<Button>
"upload"
</Button>
</Upload>
"#,
"rust"
)
>
""
</DemoCode>
</Demo>
</div>
}
}

View file

@ -31,6 +31,7 @@ mod tabs;
mod tag; mod tag;
mod teleport; mod teleport;
mod theme; mod theme;
mod upload;
mod utils; mod utils;
mod wave; mod wave;
@ -64,5 +65,6 @@ pub use table::*;
pub use tabs::*; pub use tabs::*;
pub use tag::*; pub use tag::*;
pub use theme::Theme; pub use theme::Theme;
pub use upload::*;
pub use utils::{mount_style::mount_style, signal::SignalWatch}; pub use utils::{mount_style::mount_style, signal::SignalWatch};
pub use wave::*; pub use wave::*;

40
src/upload/mod.rs Normal file
View file

@ -0,0 +1,40 @@
use leptos::*;
use crate::mount_style;
// TODO
#[component]
pub fn Upload(
#[prop(optional, into)] accept: MaybeSignal<String>,
#[prop(optional, into)] multiple: MaybeSignal<bool>,
children: Children,
) -> impl IntoView {
mount_style("upload", include_str!("./upload.css"));
let on_file_addition = move || {
};
let input_ref = create_node_ref::<html::Input>();
let on_change = move |_| {
if let Some(input_ref) = input_ref.get_untracked() {
}
};
let on_click= move |_| {
if let Some(input_ref) = input_ref.get_untracked() {
input_ref.click();
}
};
view! {
<div class="melt-upload">
<input
class="melt-upload__input"
ref=input_ref
type="file"
accept=move || accept.get()
multiple=move || multiple.get()
on:change=on_change
/>
<div class="melt-upload__trigger" on:click=on_click>
{children()}
</div>
</div>
}
}

5
src/upload/upload.css Normal file
View file

@ -0,0 +1,5 @@
.melt-upload__input {
width: 0;
height: 0;
opacity: 0;
}