use leptos::prelude::*;
use thaw_utils::{class_list, mount_style};
#[component]
pub fn Image(
#[prop(optional, into)] class: MaybeProp<String>,
#[prop(optional, into)]
src: MaybeProp<String>,
#[prop(optional, into)]
alt: MaybeProp<String>,
#[prop(optional, into)]
width: MaybeProp<String>,
#[prop(optional, into)]
height: MaybeProp<String>,
#[prop(optional, into)]
shape: Signal<ImageShape>,
#[prop(optional, into)]
block: Signal<bool>,
#[prop(optional, into)]
shadow: Signal<bool>,
#[prop(optional, into)]
fit: Signal<ImageFit>,
) -> impl IntoView {
mount_style("image", include_str!("./image.css"));
view! {
<img
class=class_list![
"thaw-image",
("thaw-image--block", move || block.get()),
("thaw-image--shadow", move || shadow.get()),
move || format!("thaw-image--{}", shape.get().as_str()),
move || format!("thaw-image--fit-{}", fit.get().as_str()),
class
]
src=move || src.get()
alt=move || alt.get()
width=move || width.get()
height=move || height.get()
/>
}
}
#[derive(Default, Clone)]
pub enum ImageShape {
Circular,
Rounded,
#[default]
Square,
}
impl ImageShape {
pub fn as_str(&self) -> &'static str {
match self {
ImageShape::Circular => "circular",
ImageShape::Rounded => "rounded",
ImageShape::Square => "square",
}
}
}
#[derive(Default, Clone)]
pub enum ImageFit {
None,
Contain,
Cover,
#[default]
Fill,
ScaleDown,
}
impl ImageFit {
pub fn as_str(&self) -> &'static str {
match self {
ImageFit::None => "none",
ImageFit::Contain => "contain",
ImageFit::Cover => "cover",
ImageFit::Fill => "fill",
ImageFit::ScaleDown => "scale-down",
}
}
}