1use super::units::Length;
22
23#[derive(Clone, Debug)]
25pub enum Spacing {
26 All(Length),
28 VH(Length, Length),
30 THB(Length, Length, Length),
32 TRBL(Length, Length, Length, Length),
34}
35
36impl Spacing {
37 pub fn all(value: Length) -> Self {
39 Self::All(value)
40 }
41
42 pub fn vh(vertical: Length, horizontal: Length) -> Self {
44 Self::VH(vertical, horizontal)
45 }
46
47 pub fn thb(top: Length, horizontal: Length, bottom: Length) -> Self {
49 Self::THB(top, horizontal, bottom)
50 }
51
52 pub fn trbl(top: Length, right: Length, bottom: Length, left: Length) -> Self {
54 Self::TRBL(top, right, bottom, left)
55 }
56
57 pub fn to_css(&self) -> String {
59 match self {
60 Spacing::All(v) => v.to_css(),
61 Spacing::VH(v, h) => format!("{} {}", v.to_css(), h.to_css()),
62 Spacing::THB(t, h, b) => format!("{} {} {}", t.to_css(), h.to_css(), b.to_css()),
63 Spacing::TRBL(t, r, b, l) => {
64 format!(
65 "{} {} {} {}",
66 t.to_css(),
67 r.to_css(),
68 b.to_css(),
69 l.to_css()
70 )
71 }
72 }
73 }
74}
75
76pub type Margin = Spacing;
78
79pub type Padding = Spacing;
81
82#[derive(Clone, Debug)]
84pub enum Radius {
85 All(Length),
87 VH(Length, Length),
89 THB(Length, Length, Length),
91 TRBL(Length, Length, Length, Length),
93}
94
95impl Radius {
96 pub fn all(value: Length) -> Self {
98 Self::All(value)
99 }
100
101 pub fn vh(vertical: Length, horizontal: Length) -> Self {
103 Self::VH(vertical, horizontal)
104 }
105
106 pub fn to_css(&self) -> String {
108 match self {
109 Radius::All(v) => v.to_css(),
110 Radius::VH(v, h) => format!("{} {}", v.to_css(), h.to_css()),
111 Radius::THB(t, h, b) => format!("{} {} {}", t.to_css(), h.to_css(), b.to_css()),
112 Radius::TRBL(t, r, b, l) => {
113 format!(
114 "{} {} {} {}",
115 t.to_css(),
116 r.to_css(),
117 b.to_css(),
118 l.to_css()
119 )
120 }
121 }
122 }
123}
124
125pub use crate::tokens::spacing::SpacingTokens as SpacingScale;
127
128#[derive(Clone, Debug)]
130pub struct ResponsiveSpacing {
131 pub mobile: Spacing,
132 pub tablet: Option<Spacing>,
133 pub desktop: Option<Spacing>,
134}
135
136impl ResponsiveSpacing {
137 pub fn new(mobile: Spacing, tablet: Option<Spacing>, desktop: Option<Spacing>) -> Self {
139 Self {
140 mobile,
141 tablet,
142 desktop,
143 }
144 }
145
146 pub fn to_css(&self, class_name: &str) -> String {
148 let mut css = format!(".{} {{ padding: {}; }}\n", class_name, self.mobile.to_css());
149
150 if let Some(tablet) = &self.tablet {
151 css.push_str(&format!(
152 "@media (min-width: 768px) {{ .{} {{ padding: {}; }} }}\n",
153 class_name,
154 tablet.to_css()
155 ));
156 }
157
158 if let Some(desktop) = &self.desktop {
159 css.push_str(&format!(
160 "@media (min-width: 1024px) {{ .{} {{ padding: {}; }} }}\n",
161 class_name,
162 desktop.to_css()
163 ));
164 }
165
166 css
167 }
168}