1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//! Utility types for flexbox-related classes.
/// Implement this type for the Props object for a tag that can use flexbox.
pub trait FlexBoxContainerProps {
fn prefix() -> &'static str;
}
/// ContainerType will either be ColProps or RowProps.
#[derive(Clone, PartialEq)]
pub enum FlexBoxClass<T: FlexBoxContainerProps> {
/// Maps to the class "flex-nowrap"
NoWrap,
/// Maps to the class "col-auto or row-auto"
Auto(T),
/// Maps to d-flex or d-inline-flex.
DFlex{inline: bool, size: Option<super::size::ExtendedSize>},
/// Maps to either flex-row, flex-col, flex-row-reverse, flex-col-reverse
Flex{reverse: bool, container: T},
/// Maps to p-{size}
Pad{size: u8}
}
use FlexBoxClass::*;
impl<T: FlexBoxContainerProps + Into<&'static str>> Into<String> for FlexBoxClass<T> {
fn into(self) -> String {
match self {
NoWrap => "no-wrap".to_string(),
Auto(t) => format!("{}-auto", T::prefix()),
DFlex { inline, size } => {
match size {
Some(s) => if inline {
let s: &str = s.into();
format!("d-{}-inline-flex", s)
} else {
let s: &str = s.into();
format!("d-{}-flex", s)
},
None => if inline {
"d-inline-flex".to_string()
} else {
"d-flex".to_string()
}
}
},
Flex{reverse, container} => if reverse {
let t: &str = container.into();
format!("flex-{}-reverse", t)
} else {
let t: &str = container.into();
format!("flex-{}", t)
}
_ => "".to_string()
}
}
}
pub type FlexBoxClassSet<T> = Vec<FlexBoxClass<T>>;