ironhtml_bootstrap/
types.rs

1//! Shared type definitions for Bootstrap components.
2
3use core::fmt;
4
5/// Bootstrap contextual colors.
6///
7/// Used for buttons, alerts, badges, and other components.
8///
9/// ## Example
10///
11/// ```rust
12/// use ironhtml_bootstrap::Color;
13///
14/// let color = Color::Primary;
15/// assert_eq!(color.as_str(), "primary");
16/// ```
17#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
18pub enum Color {
19    #[default]
20    Primary,
21    Secondary,
22    Success,
23    Danger,
24    Warning,
25    Info,
26    Light,
27    Dark,
28}
29
30impl Color {
31    /// Returns the Bootstrap class suffix for this color.
32    #[must_use]
33    pub const fn as_str(self) -> &'static str {
34        match self {
35            Self::Primary => "primary",
36            Self::Secondary => "secondary",
37            Self::Success => "success",
38            Self::Danger => "danger",
39            Self::Warning => "warning",
40            Self::Info => "info",
41            Self::Light => "light",
42            Self::Dark => "dark",
43        }
44    }
45}
46
47impl fmt::Display for Color {
48    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
49        f.write_str(self.as_str())
50    }
51}
52
53/// Bootstrap component sizes.
54///
55/// ## Example
56///
57/// ```rust
58/// use ironhtml_bootstrap::Size;
59///
60/// let size = Size::Large;
61/// assert_eq!(size.as_btn_class(), "btn-lg");
62/// ```
63#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
64pub enum Size {
65    Small,
66    #[default]
67    Normal,
68    Large,
69}
70
71impl Size {
72    /// Returns the button size class (e.g., "btn-sm", "btn-lg").
73    /// Returns empty string for normal size.
74    #[must_use]
75    pub const fn as_btn_class(self) -> &'static str {
76        match self {
77            Self::Small => "btn-sm",
78            Self::Normal => "",
79            Self::Large => "btn-lg",
80        }
81    }
82}
83
84/// Bootstrap responsive breakpoints.
85///
86/// | Breakpoint | Size     | Class infix |
87/// |------------|----------|-------------|
88/// | Sm         | >=576px  | sm          |
89/// | Md         | >=768px  | md          |
90/// | Lg         | >=992px  | lg          |
91/// | Xl         | >=1200px | xl          |
92/// | Xxl        | >=1400px | xxl         |
93#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
94pub enum Breakpoint {
95    /// Small devices (>=576px)
96    Sm,
97    /// Medium devices (>=768px)
98    Md,
99    /// Large devices (>=992px)
100    Lg,
101    /// Extra large devices (>=1200px)
102    Xl,
103    /// Extra extra large devices (>=1400px)
104    Xxl,
105}
106
107impl Breakpoint {
108    /// Returns the Bootstrap class infix for this breakpoint.
109    #[must_use]
110    pub const fn as_str(self) -> &'static str {
111        match self {
112            Self::Sm => "sm",
113            Self::Md => "md",
114            Self::Lg => "lg",
115            Self::Xl => "xl",
116            Self::Xxl => "xxl",
117        }
118    }
119}
120
121impl fmt::Display for Breakpoint {
122    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
123        f.write_str(self.as_str())
124    }
125}
126
127/// Navbar expand breakpoint.
128///
129/// Determines at which screen size the navbar expands from collapsed to horizontal.
130#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
131pub enum NavbarExpand {
132    /// Always expanded (navbar-expand)
133    Always,
134    /// Expand at small breakpoint (navbar-expand-sm)
135    Sm,
136    /// Expand at medium breakpoint (navbar-expand-md)
137    Md,
138    /// Expand at large breakpoint (navbar-expand-lg) - most common
139    #[default]
140    Lg,
141    /// Expand at extra large breakpoint (navbar-expand-xl)
142    Xl,
143    /// Expand at extra extra large breakpoint (navbar-expand-xxl)
144    Xxl,
145}
146
147impl NavbarExpand {
148    /// Returns the Bootstrap navbar expand class.
149    #[must_use]
150    pub const fn as_class(self) -> &'static str {
151        match self {
152            Self::Always => "navbar-expand",
153            Self::Sm => "navbar-expand-sm",
154            Self::Md => "navbar-expand-md",
155            Self::Lg => "navbar-expand-lg",
156            Self::Xl => "navbar-expand-xl",
157            Self::Xxl => "navbar-expand-xxl",
158        }
159    }
160}