mirror of
https://github.com/adoyle0/thaw.git
synced 2025-01-22 22:09:22 -05:00
✨ feat: add image component
This commit is contained in:
parent
f2405604d2
commit
808e844c3d
6 changed files with 59 additions and 0 deletions
|
@ -31,6 +31,9 @@ pub fn App(cx: Scope) -> impl IntoView {
|
||||||
<Route path="/input" view=move |cx| view! {cx,
|
<Route path="/input" view=move |cx| view! {cx,
|
||||||
<InputPage />
|
<InputPage />
|
||||||
} />
|
} />
|
||||||
|
<Route path="/image" view=move |cx| view! {cx,
|
||||||
|
<ImagePage />
|
||||||
|
} />
|
||||||
</Route>
|
</Route>
|
||||||
</Routes>
|
</Routes>
|
||||||
<Routes base="/mobile".to_string()>
|
<Routes base="/mobile".to_string()>
|
||||||
|
|
|
@ -37,6 +37,7 @@ pub fn ComponentsPage(cx: Scope) -> impl IntoView {
|
||||||
<MenuItem key="slider" label="slider" />
|
<MenuItem key="slider" label="slider" />
|
||||||
<MenuItem key="tabbar" label="tabbar" />
|
<MenuItem key="tabbar" label="tabbar" />
|
||||||
<MenuItem key="input" label="input" />
|
<MenuItem key="input" label="input" />
|
||||||
|
<MenuItem key="image" label="image" />
|
||||||
</Menu>
|
</Menu>
|
||||||
</aside>
|
</aside>
|
||||||
<main>
|
<main>
|
||||||
|
|
12
examples/basic/src/pages/image/mod.rs
Normal file
12
examples/basic/src/pages/image/mod.rs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
use leptos::*;
|
||||||
|
use melt_ui::*;
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn ImagePage(cx: Scope) -> impl IntoView {
|
||||||
|
view! { cx,
|
||||||
|
<>
|
||||||
|
<Image src="https://s3.bmp.ovh/imgs/2021/10/2c3b013418d55659.jpg" width="500px"/>
|
||||||
|
<Image width="200px" height="200px"/>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
mod components;
|
mod components;
|
||||||
mod home;
|
mod home;
|
||||||
|
mod image;
|
||||||
mod input;
|
mod input;
|
||||||
mod menu;
|
mod menu;
|
||||||
mod mobile;
|
mod mobile;
|
||||||
|
@ -8,6 +9,7 @@ mod tabbar;
|
||||||
|
|
||||||
pub use components::*;
|
pub use components::*;
|
||||||
pub use home::*;
|
pub use home::*;
|
||||||
|
pub use image::*;
|
||||||
pub use input::*;
|
pub use input::*;
|
||||||
pub use menu::*;
|
pub use menu::*;
|
||||||
pub use mobile::*;
|
pub use mobile::*;
|
||||||
|
|
39
src/image/mod.rs
Normal file
39
src/image/mod.rs
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
|
||||||
|
use leptos::*;
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn Image(
|
||||||
|
cx: Scope,
|
||||||
|
#[prop(optional, into)] src: MaybeSignal<String>,
|
||||||
|
#[prop(optional, into)] alt: MaybeSignal<String>,
|
||||||
|
#[prop(optional, into)] width: MaybeSignal<String>,
|
||||||
|
#[prop(optional, into)] height: MaybeSignal<String>,
|
||||||
|
#[prop(optional, into)] border_radius: MaybeSignal<String>,
|
||||||
|
#[prop(optional, into)] object_fit: MaybeSignal<String>,
|
||||||
|
) -> impl IntoView {
|
||||||
|
|
||||||
|
let style = move || {
|
||||||
|
let mut style = String::new();
|
||||||
|
|
||||||
|
let width = width.get();
|
||||||
|
if !width.is_empty() {
|
||||||
|
style.push_str(&format!("width: {width};"))
|
||||||
|
}
|
||||||
|
|
||||||
|
let height = height.get();
|
||||||
|
if !height.is_empty() {
|
||||||
|
style.push_str(&format!("height: {height};"))
|
||||||
|
}
|
||||||
|
|
||||||
|
let border_radius = border_radius.get();
|
||||||
|
if !border_radius.is_empty() {
|
||||||
|
style.push_str(&format!("border-radius: {border_radius};"))
|
||||||
|
}
|
||||||
|
|
||||||
|
style
|
||||||
|
};
|
||||||
|
view! {
|
||||||
|
cx,
|
||||||
|
<img src=move || src.get() alt=move || alt.get() style=style object_fit=move || object_fit.get()/>
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ mod button;
|
||||||
mod card;
|
mod card;
|
||||||
mod checkbox;
|
mod checkbox;
|
||||||
mod components;
|
mod components;
|
||||||
|
mod image;
|
||||||
mod input;
|
mod input;
|
||||||
mod menu;
|
mod menu;
|
||||||
pub mod mobile;
|
pub mod mobile;
|
||||||
|
@ -17,6 +18,7 @@ mod wave;
|
||||||
|
|
||||||
pub use button::*;
|
pub use button::*;
|
||||||
pub use checkbox::*;
|
pub use checkbox::*;
|
||||||
|
pub use image::*;
|
||||||
pub use input::*;
|
pub use input::*;
|
||||||
pub use menu::*;
|
pub use menu::*;
|
||||||
pub use modal::*;
|
pub use modal::*;
|
||||||
|
|
Loading…
Add table
Reference in a new issue