tailwind_css_fixes/modules/background/repeat/
mod.rs

1use super::*;
2
3#[doc=include_str!("readme.md")]
4#[derive(Debug, Clone)]
5pub struct TailwindBackgroundRepeat {
6    kind: StandardValue,
7}
8
9crate::macros::sealed::keyword_instance!(TailwindBackgroundRepeat => "background-repeat");
10
11impl Display for TailwindBackgroundRepeat {
12    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
13        match &self.kind {
14            StandardValue::Keyword(s) => match s.as_str() {
15                "repeat" => write!(f, "bg-repeat"),
16                "no-repeat" => write!(f, "bg-no-repeat"),
17                "repeat-x" => write!(f, "bg-repeat-x"),
18                "repeat-y" => write!(f, "bg-repeat-y"),
19                _ => write!(f, "bg-repeat-{}", s),
20            },
21            StandardValue::Arbitrary(s) => s.write_class(f, "bg-repeat-"),
22        }
23    }
24}
25
26impl TailwindBackgroundRepeat {
27    /// <https://tailwindcss.com/docs/background-repeat>
28    pub fn parse(pattern: &[&str], arbitrary: &TailwindArbitrary) -> Result<Self> {
29        let kind = match pattern {
30            [] if arbitrary.is_none() => StandardValue::from("repeat"),
31            ["none"] => StandardValue::from("no-repeat"),
32            ["x"] => StandardValue::from("repeat-x"),
33            ["y"] => StandardValue::from("repeat-y"),
34            _ => StandardValue::parser("bg-repeat", &Self::check_valid)(pattern, arbitrary)?,
35        };
36        Ok(Self { kind })
37    }
38    /// <https://developer.mozilla.org/en-US/docs/Web/CSS/background-repeat#syntax>
39    pub fn check_valid(mode: &str) -> bool {
40        let set = BTreeSet::from_iter(vec![
41            "inherit",
42            "initial",
43            "no-repeat",
44            "repeat",
45            "repeat-x",
46            "repeat-y",
47            "revert",
48            "round",
49            "space",
50            "unset",
51        ]);
52        set.contains(mode)
53    }
54}