yew_bs/components/
stacks.rs

1use yew::prelude::*;
2#[derive(Clone, Copy, PartialEq, Debug)]
3pub enum StackDirection {
4    Vertical,
5    Horizontal,
6}
7impl StackDirection {
8    pub fn as_str(&self) -> &'static str {
9        match self {
10            StackDirection::Vertical => "vstack",
11            StackDirection::Horizontal => "hstack",
12        }
13    }
14}
15/// Gap spacing for stacks
16#[derive(Clone, Copy, PartialEq, Debug)]
17pub enum StackGap {
18    Gap0,
19    Gap1,
20    Gap2,
21    Gap3,
22    Gap4,
23    Gap5,
24}
25impl StackGap {
26    pub fn as_str(&self) -> &'static str {
27        match self {
28            StackGap::Gap0 => "gap-0",
29            StackGap::Gap1 => "gap-1",
30            StackGap::Gap2 => "gap-2",
31            StackGap::Gap3 => "gap-3",
32            StackGap::Gap4 => "gap-4",
33            StackGap::Gap5 => "gap-5",
34        }
35    }
36}
37#[derive(Properties, PartialEq)]
38pub struct StackProps {
39    pub direction: StackDirection,
40    #[prop_or_default]
41    pub gap: Option<StackGap>,
42    #[prop_or_default]
43    pub children: Children,
44    #[prop_or_default]
45    pub class: Option<AttrValue>,
46}
47#[function_component(Stack)]
48pub fn stack(props: &StackProps) -> Html {
49    let mut classes = Classes::new();
50    classes.push(props.direction.as_str());
51    if let Some(gap) = &props.gap {
52        classes.push(gap.as_str());
53    }
54    if let Some(custom_class) = &props.class {
55        classes.push(custom_class.to_string());
56    }
57    html! {
58        < div class = { classes } > { for props.children.iter() } </ div >
59    }
60}