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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use super::*;

#[doc=include_str!("readme.md")]
#[derive(Clone, Debug)]
pub struct TailwindSkew {
    negative: Negative,
    axis: AxisXY,
    degree: IntegerOnly,
}

impl Display for TailwindSkew {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        self.negative.write(f)?;
        match self.axis {
            AxisXY::X => write!(f, "skew-x-{}", self.degree),
            AxisXY::Y => write!(f, "skew-y-{}", self.degree),
            AxisXY::N => write!(f, "skew-{}", self.degree),
        }
    }
}

impl TailwindInstance for TailwindSkew {
    fn attributes(&self, _: &TailwindBuilder) -> CssAttributes {
        let skew = match self.axis {
            AxisXY::X => format!("skewX({}deg)", self.degree),
            AxisXY::Y => format!("skewY({}deg)", self.degree),
            AxisXY::N => format!("skew({}deg)", self.degree),
        };
        css_attributes! {
            "transform" => skew
        }
    }
}

impl TailwindSkew {
    // <https://tailwindcss.com/docs/skew>
    pub fn parse(pattern: &[&str], arbitrary: &TailwindArbitrary, negative: Negative) -> Result<Self> {
        let (axis, rest) = match pattern {
            ["x", rest @ ..] => (AxisXY::X, rest),
            ["y", rest @ ..] => (AxisXY::Y, rest),
            _ => (AxisXY::X, pattern),
        };
        let degree = IntegerOnly::parser("skew")(rest, arbitrary)?;
        Ok(Self { negative: negative.into(), degree, axis })
    }
    pub fn parse_arbitrary(arbitrary: &TailwindArbitrary, negative: Negative, axis: AxisXY) -> Result<Self> {
        let degree = IntegerOnly::parse_arbitrary(arbitrary)?;
        Ok(Self { negative: negative.into(), degree, axis })
    }
}