rustyle_css/
utils.rs

1//! Common utility functions and patterns
2
3use crate::css::{Color, Length, Radius, Spacing};
4
5/// Common flexbox utilities
6pub mod flex {
7    use crate::css::{AlignItems, FlexDirection, JustifyContent};
8
9    /// Create a flex container style
10    pub fn container(
11        direction: FlexDirection,
12        justify: JustifyContent,
13        align: AlignItems,
14    ) -> String {
15        format!(
16            "display: flex; flex-direction: {}; justify-content: {}; align-items: {};",
17            direction.to_css(),
18            justify.to_css(),
19            align.to_css()
20        )
21    }
22
23    /// Create a centered flex container
24    pub fn center() -> String {
25        container(
26            FlexDirection::Row,
27            JustifyContent::Center,
28            AlignItems::Center,
29        )
30    }
31
32    /// Create a space-between flex container
33    pub fn space_between() -> String {
34        container(
35            FlexDirection::Row,
36            JustifyContent::SpaceBetween,
37            AlignItems::Center,
38        )
39    }
40}
41
42/// Common spacing utilities
43pub mod spacing {
44    use super::*;
45
46    /// Create uniform spacing
47    pub fn uniform(value: Length) -> Spacing {
48        Spacing::all(value)
49    }
50
51    /// Create horizontal spacing
52    pub fn horizontal(value: Length) -> Spacing {
53        Spacing::vh(Length::Zero, value)
54    }
55
56    /// Create vertical spacing
57    pub fn vertical(value: Length) -> Spacing {
58        Spacing::vh(value, Length::Zero)
59    }
60}
61
62/// Common border radius utilities
63pub mod radius {
64    use super::*;
65
66    /// Create a small border radius
67    pub fn small() -> Radius {
68        Radius::all(Length::px(4.0))
69    }
70
71    /// Create a medium border radius
72    pub fn medium() -> Radius {
73        Radius::all(Length::px(8.0))
74    }
75
76    /// Create a large border radius
77    pub fn large() -> Radius {
78        Radius::all(Length::px(16.0))
79    }
80
81    /// Create a full border radius (circle)
82    pub fn full() -> Radius {
83        Radius::all(Length::percent(50.0))
84    }
85}
86
87/// Common color utilities
88pub mod colors {
89    use super::*;
90
91    /// Common color palette
92    pub mod palette {
93        use super::*;
94
95        pub fn blue() -> Color {
96            Color::hex("#007bff")
97        }
98
99        pub fn red() -> Color {
100            Color::hex("#dc3545")
101        }
102
103        pub fn green() -> Color {
104            Color::hex("#28a745")
105        }
106
107        pub fn yellow() -> Color {
108            Color::hex("#ffc107")
109        }
110
111        pub fn gray() -> Color {
112            Color::hex("#6c757d")
113        }
114    }
115}