use dioxus::prelude::*;
#[derive(Clone, PartialEq, Props)]
pub struct FigureProps {
pub src: String,
#[props(default)]
pub alt: String,
#[props(default)]
pub caption: String,
#[props(default)]
pub caption_align: String,
#[props(default = true)]
pub fluid: bool,
#[props(default)]
pub rounded: bool,
#[props(default)]
pub thumbnail: bool,
#[props(default)]
pub class: String,
#[props(default)]
pub img_class: String,
}
#[component]
pub fn Figure(props: FigureProps) -> Element {
let fig_class = if props.class.is_empty() {
"figure".to_string()
} else {
format!("figure {}", props.class)
};
let mut img_classes = vec!["figure-img".to_string()];
if props.fluid {
img_classes.push("img-fluid".to_string());
}
if props.rounded {
img_classes.push("rounded".to_string());
}
if props.thumbnail {
img_classes.push("img-thumbnail".to_string());
}
if !props.img_class.is_empty() {
img_classes.push(props.img_class.clone());
}
let img_class = img_classes.join(" ");
let caption_class = if props.caption_align.is_empty() {
"figure-caption".to_string()
} else {
format!("figure-caption text-{}", props.caption_align)
};
rsx! {
figure { class: "{fig_class}",
img {
class: "{img_class}",
src: "{props.src}",
alt: "{props.alt}",
}
if !props.caption.is_empty() {
figcaption { class: "{caption_class}", "{props.caption}" }
}
}
}
}
#[derive(Clone, PartialEq, Props)]
pub struct RatioProps {
#[props(default = "16x9".to_string())]
pub aspect: String,
#[props(default)]
pub class: String,
pub children: Element,
}
#[component]
pub fn Ratio(props: RatioProps) -> Element {
let full_class = if props.class.is_empty() {
format!("ratio ratio-{}", props.aspect)
} else {
format!("ratio ratio-{} {}", props.aspect, props.class)
};
rsx! {
div { class: "{full_class}",
{props.children}
}
}
}