yew_bs/components/
object_fit.rs1use yew::prelude::*;
2#[derive(Clone, Copy, PartialEq, Debug)]
3pub enum ObjectFitVariant {
4 Contain,
5 Cover,
6 Fill,
7 Scale,
8 None,
9}
10impl ObjectFitVariant {
11 pub fn as_str(&self) -> &'static str {
12 match self {
13 ObjectFitVariant::Contain => "object-fit-contain",
14 ObjectFitVariant::Cover => "object-fit-cover",
15 ObjectFitVariant::Fill => "object-fit-fill",
16 ObjectFitVariant::Scale => "object-fit-scale",
17 ObjectFitVariant::None => "object-fit-none",
18 }
19 }
20}
21#[derive(Properties, PartialEq)]
23pub struct ObjectFitProps {
24 pub fit: ObjectFitVariant,
26 #[prop_or_default]
28 pub children: Children,
29 #[prop_or_default]
31 pub class: Option<AttrValue>,
32}
33#[function_component(ObjectFit)]
37pub fn object_fit(props: &ObjectFitProps) -> Html {
38 let mut classes = Classes::new();
39 classes.push(props.fit.as_str());
40 if let Some(custom_class) = &props.class {
41 classes.push(custom_class.to_string());
42 }
43 html! {
44 < div class = { classes } > { for props.children.iter() } </ div >
45 }
46}