impulse_thaw/image/
mod.rs1use leptos::prelude::*;
2use thaw_utils::{class_list, mount_style};
3
4#[component]
5pub fn Image(
6 #[prop(optional, into)] class: MaybeProp<String>,
7 #[prop(optional, into)]
9 src: MaybeProp<String>,
10 #[prop(optional, into)]
12 alt: MaybeProp<String>,
13 #[prop(optional, into)]
15 width: MaybeProp<String>,
16 #[prop(optional, into)]
18 height: MaybeProp<String>,
19 #[prop(optional, into)]
21 shape: Signal<ImageShape>,
22 #[prop(optional, into)]
24 block: Signal<bool>,
25 #[prop(optional, into)]
27 shadow: Signal<bool>,
28 #[prop(optional, into)]
30 fit: Signal<ImageFit>,
31) -> impl IntoView {
32 mount_style("image", include_str!("./image.css"));
33
34 view! {
35 <img
36 class=class_list![
37 "thaw-image",
38 ("thaw-image--block", move || block.get()),
39 ("thaw-image--shadow", move || shadow.get()),
40 move || format!("thaw-image--{}", shape.get().as_str()),
41 move || format!("thaw-image--fit-{}", fit.get().as_str()),
42 class
43 ]
44 src=move || src.get()
45 alt=move || alt.get()
46 width=move || width.get()
47 height=move || height.get()
48 />
49 }
50}
51
52#[derive(Default, Clone)]
53pub enum ImageShape {
54 Circular,
55 Rounded,
56 #[default]
57 Square,
58}
59
60impl ImageShape {
61 pub fn as_str(&self) -> &'static str {
62 match self {
63 ImageShape::Circular => "circular",
64 ImageShape::Rounded => "rounded",
65 ImageShape::Square => "square",
66 }
67 }
68}
69
70#[derive(Default, Clone)]
71pub enum ImageFit {
72 None,
73 Contain,
74 Cover,
75 #[default]
76 Fill,
77 ScaleDown,
78}
79
80impl ImageFit {
81 pub fn as_str(&self) -> &'static str {
82 match self {
83 ImageFit::None => "none",
84 ImageFit::Contain => "contain",
85 ImageFit::Cover => "cover",
86 ImageFit::Fill => "fill",
87 ImageFit::ScaleDown => "scale-down",
88 }
89 }
90}