tailwind_css_fixes/modules/flexbox/grid/grid_flow/
mod.rs

1use super::*;
2
3#[doc=include_str!("readme.md")]
4#[derive(Debug, Clone)]
5pub struct TailwindGridFlow {
6    kind: StandardValue,
7}
8
9crate::macros::sealed::keyword_instance!(TailwindGridFlow => "grid-auto-flow");
10
11impl Display for TailwindGridFlow {
12    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
13        self.kind.write_class(f, "grid-flow-", |s| match s {
14            "column dense" => KeywordClassFormat::AddAsSuffixCustom("col-dense"),
15            "row dense" => KeywordClassFormat::AddAsSuffixCustom("row-dense"),
16
17            keyword if TailwindGridFlow::check_valid(keyword) => KeywordClassFormat::AddAsSuffix,
18
19            _ => KeywordClassFormat::InvalidKeyword,
20        })
21    }
22}
23
24impl TailwindGridFlow {
25    /// <https://tailwindcss.com/docs/grid-auto-flow>
26    pub fn parse(pattern: &[&str], arbitrary: &TailwindArbitrary) -> Result<Self> {
27        let kind = match pattern {
28            ["row"] => StandardValue::from("row"),
29            ["col"] => StandardValue::from("column"),
30            ["dense"] => StandardValue::from("dense"),
31            ["col", "dense"] => StandardValue::from("column dense"),
32            ["row", "dense"] => StandardValue::from("row dense"),
33            _ => StandardValue::parser("grid-auto", &Self::check_valid)(pattern, arbitrary)?,
34        };
35        Ok(Self { kind })
36    }
37    /// <https://developer.mozilla.org/en-US/docs/Web/CSS/grid-auto-flow#syntax>
38    pub fn check_valid(mode: &str) -> bool {
39        let set = BTreeSet::from_iter(vec!["column", "row", "dense", "row dense", "column dense", "inherit", "initial", "revert", "unset"]);
40        set.contains(mode)
41    }
42}