tailwind_css_fixes/modules/borders/ring/ring_offset_width/
mod.rs

1use super::*;
2
3#[doc=include_str!("readme.md")]
4#[derive(Clone, Debug)]
5pub struct TailwindRingOffsetWidth {
6    kind: UnitValue,
7}
8
9impl<T> From<T> for TailwindRingOffsetWidth
10where
11    T: Into<UnitValue>,
12{
13    fn from(kind: T) -> Self {
14        Self { kind: kind.into() }
15    }
16}
17
18/// Generates the class name, e.g., `ring-offset-4`.
19impl Display for TailwindRingOffsetWidth {
20    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
21        write!(f, "ring-offset-{}", self.kind)
22    }
23}
24
25/// Generates the exact CSS variables as tailwind v4.1.12
26impl TailwindInstance for TailwindRingOffsetWidth {
27    fn attributes(&self, _: &TailwindBuilder) -> CssAttributes {
28        let width = self.kind.get_properties(|f| format!("{}px", f));
29
30        css_attributes! {
31            "--tw-ring-offset-width" => width,
32            "--tw-ring-offset-shadow" => "var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color)"
33        }
34    }
35}
36
37impl TailwindRingOffsetWidth {
38    /// <https://tailwindcss.com/docs/ring-width>
39    pub fn parse(pattern: &[&str], arbitrary: &TailwindArbitrary) -> Result<Self> {
40        let kind = UnitValue::positive_parser("ring-offset", Self::check_valid, true, false, false)(pattern, arbitrary)?;
41        Ok(Self { kind })
42    }
43
44    pub fn check_valid(mode: &str) -> bool {
45        ["inherit", "initial", "revert", "unset"].contains(&mode)
46    }
47}