tailwind_css_fixes/modules/flexbox/order/
mod.rs

1use super::*;
2use crate::NumericValue;
3
4#[doc=include_str!("readme.md")]
5#[derive(Debug, Clone)]
6pub struct TailWindOrder {
7    kind: NumericValue,
8}
9
10impl Display for TailWindOrder {
11    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
12        match &self.kind {
13            NumericValue::Number { n, .. } => match *n as i32 {
14                -9999 => write!(f, "order-first"),
15                9999 => write!(f, "order-last"),
16                _ => {
17                    self.kind.write_class_name(f, "order-")
18                }
19            },
20            // For Keyword and Arbitrary variants
21            _ => {
22                self.kind.write_class_name(f, "order-")
23            },
24        }
25    }
26}
27
28impl TailwindInstance for TailWindOrder {
29    fn attributes(&self, _: &TailwindBuilder) -> CssAttributes {
30        css_attributes! {
31            "order" => self.kind
32        }
33    }
34}
35
36impl TailWindOrder {
37    pub fn parse(pattern: &[&str], arbitrary: &TailwindArbitrary, negative: Negative) -> Result<Self> {
38        let kind = match pattern {
39            ["none"] => NumericValue::from(0i32),
40            ["first"] => NumericValue::from(-9999i32),
41            ["last"] => NumericValue::from(9999i32),
42            [s] if Self::check_valid(s) => NumericValue::Keyword(s.to_string()),
43            _ => NumericValue::negative_parser("order", &Self::check_valid)(pattern, arbitrary, negative)?,
44        };
45        Ok(Self { kind })
46    }
47    pub fn parse_arbitrary(arbitrary: &TailwindArbitrary) -> Result<Self> {
48        Ok(Self { kind: NumericValue::parse_arbitrary(arbitrary)? })
49    }
50    /// https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit#syntax
51    pub fn check_valid(mode: &str) -> bool {
52        let set = BTreeSet::from_iter(vec!["inherit", "initial", "revert", "unset"]);
53        set.contains(mode)
54    }
55}