tailwind_css/modules/sizing/
display.rs

1use super::*;
2
3impl Display for SizingUnit {
4    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
5        match self {
6            Self::Min => write!(f, "min"),
7            Self::Max => write!(f, "max"),
8            Self::Fit => write!(f, "fit"),
9            Self::Auto => write!(f, "auto"),
10            Self::Full => write!(f, "full"),
11            Self::Screen => write!(f, "screen"),
12            Self::Fraction(numerator, denominator) => write!(f, "{}/{}", numerator, denominator),
13            Self::Length(x) => write!(f, "[{}]", x),
14        }
15    }
16}
17
18impl SizingUnit {
19    fn get_attribute(&self, is_width: bool) -> String {
20        let is_width = match is_width {
21            true => "vw",
22            false => "vh",
23        };
24        match self {
25            Self::Min => "min-content".to_string(),
26            Self::Max => "max-content".to_string(),
27            Self::Fit => "fit-content".to_string(),
28            Self::Auto => "auto".to_string(),
29            Self::Full => "100%".to_string(),
30            Self::Screen => format!("100{}", is_width),
31            Self::Fraction(numerator, denominator) => format!("{}%", *numerator as f32 / *denominator as f32),
32            Self::Length(x) => format!("{}", x),
33        }
34    }
35}
36
37impl Display for TailwindSizingKind {
38    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
39        match self {
40            Self::Width => f.write_str("w"),
41            Self::MinWidth => f.write_str("min-w"),
42            Self::MaxWidth => f.write_str("max-w"),
43            Self::Height => f.write_str("h"),
44            Self::MinHeight => f.write_str("min-h"),
45            Self::MaxHeight => f.write_str("max-h"),
46        }
47    }
48}
49
50impl Display for TailwindSizing {
51    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
52        write!(f, "{}-{}", self.kind, self.size)
53    }
54}
55
56impl TailwindInstance for TailwindSizing {
57    fn attributes(&self, _: &TailwindBuilder) -> CssAttributes {
58        let class = self.kind.to_string();
59        let width = self.size.get_attribute(true);
60        css_attributes! {
61            class => width
62        }
63    }
64}