tailwind_css/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        self.kind.write_negative(f)?;
13        write!(f, "order-{}", self.kind)
14    }
15}
16
17impl TailwindInstance for TailWindOrder {
18    fn attributes(&self, _: &TailwindBuilder) -> CssAttributes {
19        css_attributes! {
20            "order" => self.kind
21        }
22    }
23}
24
25impl TailWindOrder {
26    pub fn parse(pattern: &[&str], arbitrary: &TailwindArbitrary, negative: Negative) -> Result<Self> {
27        let kind = match pattern {
28            ["none"] => NumericValue::from(0i32),
29            ["first"] => NumericValue::from(9999i32),
30            ["last"] => NumericValue::from(-9999i32),
31            [s] if Self::check_valid(s) => NumericValue::Keyword(s.to_string()),
32            _ => NumericValue::negative_parser("order", &Self::check_valid)(pattern, arbitrary, negative)?,
33        };
34        Ok(Self { kind })
35    }
36    pub fn parse_arbitrary(arbitrary: &TailwindArbitrary) -> Result<Self> {
37        Ok(Self { kind: NumericValue::parse_arbitrary(arbitrary)? })
38    }
39    /// https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit#syntax
40    pub fn check_valid(mode: &str) -> bool {
41        let set = BTreeSet::from_iter(vec!["inherit", "initial", "revert", "unset"]);
42        set.contains(mode)
43    }
44}