tailwind_css_fixes/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 TailwindSizingKind {
38    fn is_width(self) -> bool {
39        matches!(self, Self::Width | Self::MinWidth | Self::MaxWidth)
40    }
41}
42
43impl Display for TailwindSizingKind {
44    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
45        match self {
46            Self::Width => f.write_str("width"),
47            Self::MinWidth => f.write_str("min-width"),
48            Self::MaxWidth => f.write_str("max-width"),
49            Self::Height => f.write_str("height"),
50            Self::MinHeight => f.write_str("min-height"),
51            Self::MaxHeight => f.write_str("max-height"),
52        }
53    }
54}
55
56impl Display for TailwindSizing {
57    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
58        write!(f, "{}-{}", self.kind, self.size)
59    }
60}
61
62impl TailwindInstance for TailwindSizing {
63    fn attributes(&self, _: &TailwindBuilder) -> CssAttributes {
64        let class = self.kind.to_string();
65        let width = self.size.get_attribute(self.kind.is_width());
66        css_attributes! {
67            class => width
68        }
69    }
70}