logo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use super::*;

#[doc=include_str!("readme.md")]
#[derive(Clone, Debug)]
pub struct TailwindPosition {
    kind: StandardValue,
}

crate::macros::sealed::keyword_instance!(TailwindPosition => "position");

impl Display for TailwindPosition {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        self.kind.write_class(f, "position-", |f, s| match s {
            "static" | "relative" | "absolute" | "fixed" | "sticky" => write!(f, "{}", s),
            _ => Err(std::fmt::Error),
        })
    }
}

impl TailwindPosition {
    /// <https://tailwindcss.com/docs/position>
    pub fn parse(pattern: &[&str], arbitrary: &TailwindArbitrary) -> Result<Self> {
        let kind = StandardValue::parser("position", &Self::check_valid)(pattern, arbitrary)?;
        Ok(Self { kind })
    }
    /// <https://developer.mozilla.org/en-US/docs/Web/CSS/position#syntax>
    pub fn check_valid(mode: &str) -> bool {
        ["static", "relative", "absolute", "fixed", "sticky", "inherit", "initial", "revert", "unset"].contains(&mode)
    }
}