tailwind_css/modules/flexbox/justify/justify_content/
mod.rs

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