tailwind_css_fixes/modules/layouts/isolate/
mod.rs

1use super::*;
2
3#[doc=include_str!("readme.md")]
4#[derive(Clone, Debug)]
5pub struct TailwindIsolation {
6    kind: StandardValue,
7}
8
9crate::macros::sealed::keyword_instance!(TailwindIsolation => "isolation");
10
11impl Display for TailwindIsolation {
12    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
13        self.kind.write_class(f, "isolation-", |s| match s {
14            // Special Case: The output is just the keyword itself, without the "isolation-" prefix.
15            "isolate" => KeywordClassFormat::CustomClassname("isolate"),
16
17            // General Rule: The output requires a prefix.
18            keyword if TailwindIsolation::check_valid(keyword) => KeywordClassFormat::AddAsSuffix,
19            
20            // Anything else is invalid.
21            _ => KeywordClassFormat::InvalidKeyword,
22        })
23    }
24}
25
26impl TailwindIsolation {
27    /// https://tailwindcss.com/docs/isolation
28    pub fn parse(pattern: &[&str], arbitrary: &TailwindArbitrary) -> Result<Self> {
29        let kind = StandardValue::parser("isolate", &Self::check_valid)(pattern, arbitrary)?;
30        Ok(Self { kind })
31    }
32    /// https://developer.mozilla.org/en-US/docs/Web/CSS/isolation#syntax
33    pub fn check_valid(mode: &str) -> bool {
34        let set = BTreeSet::from_iter(vec![
35            // Keyword values
36            "auto", "isolate", // Global values
37            "inherit", "initial", "revert", "unset",
38        ]);
39        set.contains(mode)
40    }
41}