yew_bs/components/
common.rs

1use yew::prelude::*;
2#[derive(Clone, Copy, PartialEq, Debug)]
3pub enum Breakpoint {
4    Xs,
5    Sm,
6    Md,
7    Lg,
8    Xl,
9    Xxl,
10}
11impl Breakpoint {
12    pub fn as_str(&self) -> &'static str {
13        match self {
14            Breakpoint::Xs => "xs",
15            Breakpoint::Sm => "sm",
16            Breakpoint::Md => "md",
17            Breakpoint::Lg => "lg",
18            Breakpoint::Xl => "xl",
19            Breakpoint::Xxl => "xxl",
20        }
21    }
22}
23/// Bootstrap color variants
24#[derive(Clone, Copy, PartialEq, Debug)]
25pub enum Variant {
26    Primary,
27    Secondary,
28    Success,
29    Danger,
30    Warning,
31    Info,
32    Light,
33    Dark,
34}
35impl Variant {
36    pub fn as_str(&self) -> &'static str {
37        match self {
38            Variant::Primary => "primary",
39            Variant::Secondary => "secondary",
40            Variant::Success => "success",
41            Variant::Danger => "danger",
42            Variant::Warning => "warning",
43            Variant::Info => "info",
44            Variant::Light => "light",
45            Variant::Dark => "dark",
46        }
47    }
48}
49#[derive(Clone, Copy, PartialEq, Debug)]
50pub enum Size {
51    Small,
52    Medium,
53    Large,
54}
55impl Size {
56    pub fn as_str(&self) -> &'static str {
57        match self {
58            Size::Small => "sm",
59            Size::Medium => "",
60            Size::Large => "lg",
61        }
62    }
63}
64/// Helper function to combine CSS classes
65pub fn classes(classes: Vec<&str>) -> Classes {
66    let mut result = Classes::new();
67    for class in classes {
68        if !class.is_empty() {
69            result.push(class.to_string());
70        }
71    }
72    result
73}
74/// Helper function to generate column classes
75pub fn column_classes(
76    xs: Option<u8>,
77    sm: Option<u8>,
78    md: Option<u8>,
79    lg: Option<u8>,
80    xl: Option<u8>,
81    xxl: Option<u8>,
82    class: Option<AttrValue>,
83) -> Classes {
84    let mut result = Classes::new();
85    if xs.is_none() && sm.is_none() && md.is_none() && lg.is_none() && xl.is_none()
86        && xxl.is_none()
87    {
88        result.push("col");
89    } else {
90        if let Some(size) = xs {
91            result.push(format!("col-{}", size));
92        }
93        if let Some(size) = sm {
94            result.push(format!("col-sm-{}", size));
95        }
96        if let Some(size) = md {
97            result.push(format!("col-md-{}", size));
98        }
99        if let Some(size) = lg {
100            result.push(format!("col-lg-{}", size));
101        }
102        if let Some(size) = xl {
103            result.push(format!("col-xl-{}", size));
104        }
105        if let Some(size) = xxl {
106            result.push(format!("col-xxl-{}", size));
107        }
108    }
109    if let Some(custom_class) = class {
110        result.push(custom_class);
111    }
112    result
113}
114/// Text alignment options available in Bootstrap
115#[derive(Clone, Copy, PartialEq, Debug)]
116pub enum TextAlign {
117    Start,
118    Center,
119    End,
120    Justify,
121}
122impl TextAlign {
123    pub fn as_str(&self) -> &'static str {
124        match self {
125            TextAlign::Start => "text-start",
126            TextAlign::Center => "text-center",
127            TextAlign::End => "text-end",
128            TextAlign::Justify => "text-justify",
129        }
130    }
131}
132#[derive(Clone, Copy, PartialEq, Debug)]
133pub enum TextWrap {
134    Wrap,
135    Nowrap,
136    Break,
137}
138impl TextWrap {
139    pub fn as_str(&self) -> &'static str {
140        match self {
141            TextWrap::Wrap => "text-wrap",
142            TextWrap::Nowrap => "text-nowrap",
143            TextWrap::Break => "text-break",
144        }
145    }
146}
147/// Text transform options available in Bootstrap
148#[derive(Clone, Copy, PartialEq, Debug)]
149pub enum TextTransform {
150    Lowercase,
151    Uppercase,
152    Capitalize,
153}
154impl TextTransform {
155    pub fn as_str(&self) -> &'static str {
156        match self {
157            TextTransform::Lowercase => "text-lowercase",
158            TextTransform::Uppercase => "text-uppercase",
159            TextTransform::Capitalize => "text-capitalize",
160        }
161    }
162}
163#[derive(Clone, Copy, PartialEq, Debug)]
164pub enum FontWeight {
165    Bold,
166    Bolder,
167    Semibold,
168    Normal,
169    Light,
170    Lighter,
171}
172impl FontWeight {
173    pub fn as_str(&self) -> &'static str {
174        match self {
175            FontWeight::Bold => "fw-bold",
176            FontWeight::Bolder => "fw-bolder",
177            FontWeight::Semibold => "fw-semibold",
178            FontWeight::Normal => "fw-normal",
179            FontWeight::Light => "fw-light",
180            FontWeight::Lighter => "fw-lighter",
181        }
182    }
183}
184/// Font style options available in Bootstrap
185#[derive(Clone, Copy, PartialEq, Debug)]
186pub enum FontStyle {
187    Italic,
188    Normal,
189}
190impl FontStyle {
191    pub fn as_str(&self) -> &'static str {
192        match self {
193            FontStyle::Italic => "fst-italic",
194            FontStyle::Normal => "fst-normal",
195        }
196    }
197}
198#[derive(Clone, Copy, PartialEq, Debug)]
199pub enum TextDecoration {
200    Underline,
201    LineThrough,
202    None,
203}
204impl TextDecoration {
205    pub fn as_str(&self) -> &'static str {
206        match self {
207            TextDecoration::Underline => "text-decoration-underline",
208            TextDecoration::LineThrough => "text-decoration-line-through",
209            TextDecoration::None => "text-decoration-none",
210        }
211    }
212}
213/// Line height options available in Bootstrap
214#[derive(Clone, Copy, PartialEq, Debug)]
215pub enum LineHeight {
216    Lh1,
217    LhSm,
218    LhBase,
219    LhLg,
220}
221impl LineHeight {
222    pub fn as_str(&self) -> &'static str {
223        match self {
224            LineHeight::Lh1 => "lh-1",
225            LineHeight::LhSm => "lh-sm",
226            LineHeight::LhBase => "lh-base",
227            LineHeight::LhLg => "lh-lg",
228        }
229    }
230}