Skip to main content

dioxus_bootstrap_css/
types.rs

1use std::fmt;
2
3/// Bootstrap contextual color variants.
4///
5/// Maps to Bootstrap's color classes: `primary`, `secondary`, `success`,
6/// `danger`, `warning`, `info`, `light`, `dark`.
7///
8/// # Bootstrap HTML → Dioxus
9///
10/// | HTML class | Dioxus |
11/// |---|---|
12/// | `btn-primary` | `Button { color: Color::Primary }` |
13/// | `alert-danger` | `Alert { color: Color::Danger }` |
14/// | `text-bg-success` | `Badge { color: Color::Success }` |
15/// | `bg-warning` | `Toast { color: Color::Warning }` |
16#[derive(Clone, Copy, Debug, Default, PartialEq)]
17pub enum Color {
18    #[default]
19    Primary,
20    Secondary,
21    Success,
22    Danger,
23    Warning,
24    Info,
25    Light,
26    Dark,
27}
28
29impl fmt::Display for Color {
30    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31        match self {
32            Color::Primary => write!(f, "primary"),
33            Color::Secondary => write!(f, "secondary"),
34            Color::Success => write!(f, "success"),
35            Color::Danger => write!(f, "danger"),
36            Color::Warning => write!(f, "warning"),
37            Color::Info => write!(f, "info"),
38            Color::Light => write!(f, "light"),
39            Color::Dark => write!(f, "dark"),
40        }
41    }
42}
43
44/// Bootstrap component size variants.
45///
46/// # Bootstrap HTML → Dioxus
47///
48/// | HTML class | Dioxus |
49/// |---|---|
50/// | `btn-sm` | `Button { size: Size::Sm }` |
51/// | `btn-lg` | `Button { size: Size::Lg }` |
52/// | `form-control-sm` | `Input { size: Size::Sm }` |
53/// | `pagination-lg` | `Pagination { size: Size::Lg }` |
54#[derive(Clone, Copy, Debug, Default, PartialEq)]
55pub enum Size {
56    Sm,
57    #[default]
58    Md,
59    Lg,
60}
61
62impl fmt::Display for Size {
63    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
64        match self {
65            Size::Sm => write!(f, "sm"),
66            Size::Md => write!(f, "md"),
67            Size::Lg => write!(f, "lg"),
68        }
69    }
70}
71
72/// Bootstrap column span (1–12 or auto).
73///
74/// # Bootstrap HTML → Dioxus
75///
76/// | HTML class | Dioxus |
77/// |---|---|
78/// | `col-6` | `Col { xs: ColumnSize::Span(6) }` |
79/// | `col-md-4` | `Col { md: ColumnSize::Span(4) }` |
80/// | `col-auto` | `Col { xs: ColumnSize::Auto }` |
81/// | `col-lg-auto` | `Col { lg: ColumnSize::Auto }` |
82#[derive(Clone, Copy, Debug, PartialEq)]
83pub enum ColumnSize {
84    Auto,
85    Span(u8),
86}
87
88impl fmt::Display for ColumnSize {
89    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
90        match self {
91            ColumnSize::Auto => write!(f, "auto"),
92            ColumnSize::Span(n) => write!(f, "{n}"),
93        }
94    }
95}
96
97/// Bootstrap navbar responsive expand breakpoints.
98///
99/// Controls when the navbar switches from collapsed (hamburger) to expanded (horizontal).
100///
101/// # Bootstrap HTML → Dioxus
102///
103/// | HTML class | Dioxus |
104/// |---|---|
105/// | `navbar-expand-lg` | `Navbar { expand: NavbarExpand::Lg }` |
106/// | `navbar-expand` | `Navbar { expand: NavbarExpand::Always }` |
107#[derive(Clone, Copy, Debug, Default, PartialEq)]
108pub enum NavbarExpand {
109    Sm,
110    #[default]
111    Md,
112    Lg,
113    Xl,
114    Xxl,
115    Always,
116}
117
118impl fmt::Display for NavbarExpand {
119    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
120        match self {
121            NavbarExpand::Sm => write!(f, "navbar-expand-sm"),
122            NavbarExpand::Md => write!(f, "navbar-expand-md"),
123            NavbarExpand::Lg => write!(f, "navbar-expand-lg"),
124            NavbarExpand::Xl => write!(f, "navbar-expand-xl"),
125            NavbarExpand::Xxl => write!(f, "navbar-expand-xxl"),
126            NavbarExpand::Always => write!(f, "navbar-expand"),
127        }
128    }
129}
130
131/// Bootstrap modal size.
132///
133/// # Bootstrap HTML → Dioxus
134///
135/// | HTML class | Dioxus |
136/// |---|---|
137/// | `modal-sm` | `Modal { size: ModalSize::Sm }` |
138/// | (default) | `Modal { size: ModalSize::Default }` |
139/// | `modal-lg` | `Modal { size: ModalSize::Lg }` |
140/// | `modal-xl` | `Modal { size: ModalSize::Xl }` |
141#[derive(Clone, Copy, Debug, Default, PartialEq)]
142pub enum ModalSize {
143    Sm,
144    #[default]
145    Default,
146    Lg,
147    Xl,
148}
149
150/// Spinner animation style.
151///
152/// # Bootstrap HTML → Dioxus
153///
154/// | HTML class | Dioxus |
155/// |---|---|
156/// | `spinner-border` | `Spinner { style: SpinnerStyle::Border }` |
157/// | `spinner-grow` | `Spinner { style: SpinnerStyle::Grow }` |
158#[derive(Clone, Copy, Debug, Default, PartialEq)]
159pub enum SpinnerStyle {
160    #[default]
161    Border,
162    Grow,
163}