tailwind_css/modules/spacing/padding_scroll/
mod.rs

1use super::*;
2
3#[doc=include_str!("readme.md")]
4#[derive(Clone, Debug)]
5pub struct TailwindScrollPadding {
6    negative: Negative,
7    axis: SpacingAxis,
8    size: SpacingSize,
9}
10
11// noinspection DuplicatedCode
12impl Display for TailwindScrollPadding {
13    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
14        self.negative.write(f)?;
15        write!(f, "{}-{}", self.axis, self.size)
16    }
17}
18
19// noinspection DuplicatedCode
20impl TailwindInstance for TailwindScrollPadding {
21    fn attributes(&self, _: &TailwindBuilder) -> CssAttributes {
22        let mut out = CssAttributes::default();
23        self.axis.write_attributes(&mut out, self.size.get_properties());
24        out
25    }
26}
27
28// noinspection DuplicatedCode
29impl TailwindScrollPadding {
30    /// https://tailwindcss.com/docs/scroll-padding
31    pub fn parse(pattern: &[&str], arbitrary: &TailwindArbitrary, negative: Negative) -> Result<Self> {
32        let (axis, rest) = match pattern {
33            ["p", rest @ ..] => (SpacingAxis::new("scroll-p", &["scroll-padding"]), rest),
34            ["pl", rest @ ..] => (SpacingAxis::new("scroll-pl", &["scroll-padding-left"]), rest),
35            ["pr", rest @ ..] => (SpacingAxis::new("scroll-pr", &["scroll-padding-right"]), rest),
36            ["pt", rest @ ..] => (SpacingAxis::new("scroll-pt", &["scroll-padding-top"]), rest),
37            ["pb", rest @ ..] => (SpacingAxis::new("scroll-pb", &["scroll-padding-bottom"]), rest),
38            ["px", rest @ ..] => (SpacingAxis::new("scroll-px", &["scroll-padding-left", "scroll-padding-right"]), rest),
39            ["py", rest @ ..] => (SpacingAxis::new("scroll-py", &["scroll-padding"]), rest),
40            _ => return syntax_error!("Unknown scroll-padding axis"),
41        };
42        let size = SpacingSize::parse(rest, arbitrary, &Self::check_valid)?;
43        Ok(Self { negative, axis, size })
44    }
45    /// https://tailwindcss.com/docs/scroll-padding#arbitrary-values
46    pub fn parse_arbitrary(arbitrary: &TailwindArbitrary, axis: SpacingAxis, negative: Negative) -> Result<Self> {
47        let size = SpacingSize::parse_arbitrary(arbitrary)?;
48        Ok(Self { negative, axis, size })
49    }
50    /// https://developer.mozilla.org/en-US/docs/Web/CSS/padding#syntax
51    pub fn check_valid(mode: &str) -> bool {
52        let set = BTreeSet::from_iter(vec!["inherit", "initial", "revert", "unset"]);
53        set.contains(mode)
54    }
55}