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
59
60
61
62
63
64
use super::*;
impl Display for SizingUnit {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::Min => write!(f, "min"),
Self::Max => write!(f, "max"),
Self::Fit => write!(f, "fit"),
Self::Auto => write!(f, "auto"),
Self::Full => write!(f, "full"),
Self::Screen => write!(f, "screen"),
Self::Fraction(numerator, denominator) => write!(f, "{}/{}", numerator, denominator),
Self::Length(x) => write!(f, "[{}]", x),
}
}
}
impl SizingUnit {
fn get_attribute(&self, is_width: bool) -> String {
let is_width = match is_width {
true => "vw",
false => "vh",
};
match self {
Self::Min => format!("min-content"),
Self::Max => format!("max-content"),
Self::Fit => format!("fit-content"),
Self::Auto => format!("auto"),
Self::Full => format!("100%"),
Self::Screen => format!("100{}", is_width),
Self::Fraction(numerator, denominator) => format!("{}%", *numerator as f32 / *denominator as f32),
Self::Length(x) => format!("{}", x),
}
}
}
impl Display for TailwindSizingKind {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::Width => f.write_str("w"),
Self::MinWidth => f.write_str("min-w"),
Self::MaxWidth => f.write_str("max-w"),
Self::Height => f.write_str("h"),
Self::MinHeight => f.write_str("min-h"),
Self::MaxHeight => f.write_str("max-h"),
}
}
}
impl Display for TailwindSizing {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}-{}", self.kind, self.size)
}
}
impl TailwindInstance for TailwindSizing {
fn attributes(&self, _: &TailwindBuilder) -> BTreeSet<CssAttribute> {
let class = self.kind.to_string();
let width = self.size.get_attribute(true);
css_attributes! {
class => width
}
}
}