tailwind_css_fixes/modules/borders/ring/ring_width/
mod.rs1use super::*;
2
3#[doc=include_str!("readme.md")]
4#[derive(Clone, Debug)]
5pub struct TailwindRingWidth {
6    kind: UnitValue,
7}
8
9impl<T> From<T> for TailwindRingWidth
10where
11    T: Into<UnitValue>,
12{
13    fn from(kind: T) -> Self {
14        Self { kind: kind.into() }
15    }
16}
17
18impl Display for TailwindRingWidth {
20    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
21        if let UnitValue::Keyword(s) = &self.kind {
23            if s == "<DEFAULT>" {
24                return write!(f, "ring");
25            }
26        }
27        write!(f, "ring-{}", self.kind)
28    }
29}
30
31impl TailwindInstance for TailwindRingWidth {
33    fn attributes(&self, _: &TailwindBuilder) -> CssAttributes {
34        let width = self.kind.get_properties(|f| format!("{}px", f));
36
37        css_attributes! {
38            "--tw-ring-offset-shadow" => "0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color)",
39            "--tw-ring-shadow" => format!("0 0 0 calc({} + var(--tw-ring-offset-width)) var(--tw-ring-color)", width),
40            "box-shadow" => "var(--tw-ring-inset) var(--tw-ring-offset-shadow), var(--tw-ring-inset) var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000)"
41        }
42    }
43}
44
45impl TailwindRingWidth {
46    pub fn parse(pattern: &[&str], arbitrary: &TailwindArbitrary) -> Result<Self> {
47        let kind = UnitValue::positive_parser("ring", Self::check_valid, true, false, false)(pattern, arbitrary)?;
48        Ok(Self { kind })
49    }
50
51    pub fn check_valid(mode: &str) -> bool {
56        ["inherit", "initial", "revert", "unset"].contains(&mode)
57    }
58}