tailwind_css_fixes/modules/background/attachment/
mod.rs

1use super::*;
2
3#[doc=include_str!("readme.md")]
4#[derive(Clone, Debug)]
5pub struct TailwindBackgroundAttachment {
6    kind: StandardValue,
7}
8
9crate::macros::sealed::keyword_instance!(TailwindBackgroundAttachment => "background-attachment");
10
11impl Display for TailwindBackgroundAttachment {
12    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
13        write!(f, "bg-")?;
14        match &self.kind {
15            StandardValue::Keyword(s) => match s.as_str() {
16                s @ ("fixed" | "local" | "scroll") => write!(f, "{}", s),
17                _ => write!(f, "attach-{}", s),
18            },
19            StandardValue::Arbitrary(s) => s.write_class(f, "attach-"),
20        }
21    }
22}
23
24impl TailwindBackgroundAttachment {
25    /// <https://tailwindcss.com/docs/background-attachment>
26    pub fn parse(pattern: &[&str], arbitrary: &TailwindArbitrary) -> Result<Self> {
27        Ok(Self { kind: StandardValue::parser("bg-attach", &Self::check_valid)(pattern, arbitrary)? })
28    }
29    /// <https://tailwindcss.com/docs/background-attachment>
30    pub fn parse_arbitrary(arbitrary: &TailwindArbitrary) -> Result<Self> {
31        StandardValue::parse_arbitrary(arbitrary).map(|kind| Self { kind })
32    }
33    /// <https://developer.mozilla.org/en-US/docs/Web/CSS/background-attachment#syntax>
34    pub fn check_valid(mode: &str) -> bool {
35        let set = BTreeSet::from_iter(vec!["fixed", "inherit", "initial", "local", "revert", "scroll", "unset"]);
36        set.contains(mode)
37    }
38}