Skip to main content

dioxus_bootstrap/
utilities.rs

1// Text utilities
2#[derive(Clone, Copy, PartialEq)]
3pub enum TextAlign {
4    Start,
5    Center,
6    End,
7    Justify,
8}
9
10impl Into<&'static str> for TextAlign {
11    fn into(self) -> &'static str {
12        match self {
13            TextAlign::Start => "text-start",
14            TextAlign::Center => "text-center",
15            TextAlign::End => "text-end",
16            TextAlign::Justify => "text-justify",
17        }
18    }
19}
20
21#[derive(Clone, Copy, PartialEq)]
22pub enum TextTransform {
23    Lowercase,
24    Uppercase,
25    Capitalize,
26}
27
28impl Into<&'static str> for TextTransform {
29    fn into(self) -> &'static str {
30        match self {
31            TextTransform::Lowercase => "text-lowercase",
32            TextTransform::Uppercase => "text-uppercase",
33            TextTransform::Capitalize => "text-capitalize",
34        }
35    }
36}
37
38#[derive(Clone, Copy, PartialEq)]
39pub enum FontWeight {
40    Bold,
41    Bolder,
42    SemiBold,
43    Medium,
44    Normal,
45    Light,
46    Lighter,
47}
48
49impl Into<&'static str> for FontWeight {
50    fn into(self) -> &'static str {
51        match self {
52            FontWeight::Bold => "fw-bold",
53            FontWeight::Bolder => "fw-bolder",
54            FontWeight::SemiBold => "fw-semibold",
55            FontWeight::Medium => "fw-medium",
56            FontWeight::Normal => "fw-normal",
57            FontWeight::Light => "fw-light",
58            FontWeight::Lighter => "fw-lighter",
59        }
60    }
61}
62
63// Display utilities
64#[derive(Clone, Copy, PartialEq)]
65pub enum Display {
66    None,
67    Inline,
68    InlineBlock,
69    Block,
70    Grid,
71    Table,
72    TableCell,
73    TableRow,
74    Flex,
75    InlineFlex,
76}
77
78impl Into<&'static str> for Display {
79    fn into(self) -> &'static str {
80        match self {
81            Display::None => "d-none",
82            Display::Inline => "d-inline",
83            Display::InlineBlock => "d-inline-block",
84            Display::Block => "d-block",
85            Display::Grid => "d-grid",
86            Display::Table => "d-table",
87            Display::TableCell => "d-table-cell",
88            Display::TableRow => "d-table-row",
89            Display::Flex => "d-flex",
90            Display::InlineFlex => "d-inline-flex",
91        }
92    }
93}
94
95// Flex utilities
96#[derive(Clone, Copy, PartialEq)]
97pub enum FlexDirection {
98    Row,
99    RowReverse,
100    Column,
101    ColumnReverse,
102}
103
104impl Into<&'static str> for FlexDirection {
105    fn into(self) -> &'static str {
106        match self {
107            FlexDirection::Row => "flex-row",
108            FlexDirection::RowReverse => "flex-row-reverse",
109            FlexDirection::Column => "flex-column",
110            FlexDirection::ColumnReverse => "flex-column-reverse",
111        }
112    }
113}
114
115#[derive(Clone, Copy, PartialEq)]
116pub enum FlexWrap {
117    Nowrap,
118    Wrap,
119    WrapReverse,
120}
121
122impl Into<&'static str> for FlexWrap {
123    fn into(self) -> &'static str {
124        match self {
125            FlexWrap::Nowrap => "flex-nowrap",
126            FlexWrap::Wrap => "flex-wrap",
127            FlexWrap::WrapReverse => "flex-wrap-reverse",
128        }
129    }
130}
131
132// Spacing utilities
133#[derive(Clone, Copy, PartialEq)]
134pub enum SpacingSize {
135    Zero,
136    One,
137    Two,
138    Three,
139    Four,
140    Five,
141    Auto,
142}
143
144impl Into<&'static str> for SpacingSize {
145    fn into(self) -> &'static str {
146        match self {
147            SpacingSize::Zero => "0",
148            SpacingSize::One => "1",
149            SpacingSize::Two => "2",
150            SpacingSize::Three => "3",
151            SpacingSize::Four => "4",
152            SpacingSize::Five => "5",
153            SpacingSize::Auto => "auto",
154        }
155    }
156}
157
158pub fn margin_class(size: SpacingSize) -> String {
159    let size_str: &str = size.into();
160    format!("m-{}", size_str)
161}
162
163pub fn margin_x_class(size: SpacingSize) -> String {
164    let size_str: &str = size.into();
165    format!("mx-{}", size_str)
166}
167
168pub fn margin_y_class(size: SpacingSize) -> String {
169    let size_str: &str = size.into();
170    format!("my-{}", size_str)
171}
172
173pub fn padding_class(size: SpacingSize) -> String {
174    let size_str: &str = size.into();
175    format!("p-{}", size_str)
176}
177
178pub fn padding_x_class(size: SpacingSize) -> String {
179    let size_str: &str = size.into();
180    format!("px-{}", size_str)
181}
182
183pub fn padding_y_class(size: SpacingSize) -> String {
184    let size_str: &str = size.into();
185    format!("py-{}", size_str)
186}
187
188// Color utilities
189#[derive(Clone, Copy, PartialEq)]
190pub enum TextColor {
191    Primary,
192    Secondary,
193    Success,
194    Danger,
195    Warning,
196    Info,
197    Light,
198    Dark,
199    Body,
200    Muted,
201    White,
202    Black50,
203    White50,
204}
205
206impl Into<&'static str> for TextColor {
207    fn into(self) -> &'static str {
208        match self {
209            TextColor::Primary => "text-primary",
210            TextColor::Secondary => "text-secondary",
211            TextColor::Success => "text-success",
212            TextColor::Danger => "text-danger",
213            TextColor::Warning => "text-warning",
214            TextColor::Info => "text-info",
215            TextColor::Light => "text-light",
216            TextColor::Dark => "text-dark",
217            TextColor::Body => "text-body",
218            TextColor::Muted => "text-muted",
219            TextColor::White => "text-white",
220            TextColor::Black50 => "text-black-50",
221            TextColor::White50 => "text-white-50",
222        }
223    }
224}
225
226// Border utilities
227#[derive(Clone, Copy, PartialEq)]
228pub enum BorderRadius {
229    None,
230    Small,
231    Normal,
232    Large,
233    Circle,
234    Pill,
235}
236
237impl Into<&'static str> for BorderRadius {
238    fn into(self) -> &'static str {
239        match self {
240            BorderRadius::None => "rounded-0",
241            BorderRadius::Small => "rounded-1",
242            BorderRadius::Normal => "rounded",
243            BorderRadius::Large => "rounded-3",
244            BorderRadius::Circle => "rounded-circle",
245            BorderRadius::Pill => "rounded-pill",
246        }
247    }
248}
249
250// Position utilities
251#[derive(Clone, Copy, PartialEq)]
252pub enum Position {
253    Static,
254    Relative,
255    Absolute,
256    Fixed,
257    Sticky,
258}
259
260impl Into<&'static str> for Position {
261    fn into(self) -> &'static str {
262        match self {
263            Position::Static => "position-static",
264            Position::Relative => "position-relative",
265            Position::Absolute => "position-absolute",
266            Position::Fixed => "position-fixed",
267            Position::Sticky => "position-sticky",
268        }
269    }
270}
271
272// Shadow utilities
273#[derive(Clone, Copy, PartialEq)]
274pub enum Shadow {
275    None,
276    Small,
277    Normal,
278    Large,
279}
280
281impl Into<&'static str> for Shadow {
282    fn into(self) -> &'static str {
283        match self {
284            Shadow::None => "shadow-none",
285            Shadow::Small => "shadow-sm",
286            Shadow::Normal => "shadow",
287            Shadow::Large => "shadow-lg",
288        }
289    }
290}