cabin_tailwind/utilities/
ring.rs1use std::fmt;
6
7pub use offset::width as offset;
8
9use crate::{Length, Property, Utility};
10
11const BOX_SHADOW: &str = "box-shadow";
12
13pub struct RingColor<V = &'static str>(pub(crate) V);
14
15include!(concat!(env!("OUT_DIR"), "/ring-color.rs"));
16
17pub mod offset {
18 use super::*;
19
20 pub struct RingOffsetColor<V = &'static str>(pub(crate) V);
21
22 include!(concat!(env!("OUT_DIR"), "/ring-offset-color.rs"));
23
24 pub fn width(x: i16) -> RingOffsetWidth {
29 RingOffsetWidth(Length::Px(f32::from(x)))
30 }
31
32 pub fn widthf(x: f32) -> RingOffsetWidth {
37 RingOffsetWidth(Length::Px(x))
38 }
39
40 pub struct RingOffsetWidth(pub Length);
41
42 impl Utility for RingOffsetWidth {
43 fn declarations(&self, f: &mut dyn fmt::Write) -> fmt::Result {
44 write!(f, "--tw-ring-offset-width: {};", self.0)?;
45 write!(
46 f,
47 "box-shadow: 0 0 0 var(--tw-ring-offset-width) \
48 var(--tw-ring-offset-color), var(--tw-ring-shadow);",
49 )?;
50 Ok(())
51 }
52 }
53
54 impl<V: fmt::Display> Utility for RingOffsetColor<V> {
55 fn declarations(&self, f: &mut dyn fmt::Write) -> fmt::Result {
56 writeln!(f, "--tw-ring-offset-color: {};", self.0)?;
57 writeln!(
58 f,
59 "box-shadow: 0 0 0 var(--tw-ring-offset-width) \
60 var(--tw-ring-offset-color), var(--tw-ring-shadow);"
61 )?;
62 Ok(())
63 }
64 }
65}
66
67pub const INSET: Property = Property("--tw-ring-inset", "inset");
72
73pub const DEFAULT: Property<RingWidth> = Property(BOX_SHADOW, RingWidth(Length::Px(3.0)));
74
75pub fn width(x: i16) -> RingWidth {
79 RingWidth(Length::Px(f32::from(x)))
80}
81
82pub fn widthf(x: f32) -> RingWidth {
86 RingWidth(Length::Px(x))
87}
88
89pub struct RingWidth(pub Length);
90
91impl Utility for RingWidth {
92 fn declarations(&self, f: &mut dyn fmt::Write) -> fmt::Result {
93 write!(f, "--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);")?;
94 write!(f, "--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc({} + var(--tw-ring-offset-width)) var(--tw-ring-color);", self.0)?;
95 write!(f, "box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);")?;
96 Ok(())
97 }
98}
99
100impl<V: fmt::Display> Utility for RingColor<V> {
101 fn declarations(&self, f: &mut dyn fmt::Write) -> fmt::Result {
102 writeln!(f, "--tw-ring-color: {};", self.0)?;
103 Ok(())
104 }
105}