rustyle_css/css/
mod.rs

1//! Type-safe CSS properties and utilities
2//!
3//! This module provides type-safe APIs for working with CSS properties,
4//! colors, units, spacing, and layout utilities.
5
6pub mod at_rules;
7pub mod color;
8pub mod grid;
9pub mod layout;
10pub mod selectors;
11pub mod spacing;
12pub mod typography;
13pub mod units;
14
15pub use at_rules::{CustomMediaRule, FontFaceRule, LayerRule, SupportsRule};
16pub use color::{Color, ColorScale, SemanticColors};
17pub use grid::{GridArea, GridTemplate, GridTrack, Subgrid};
18pub use layout::{
19    AlignItems, ContainerQuery, ContainerQueryCondition, Display, FlexDirection, FlexGap,
20    JustifyContent,
21};
22pub use selectors::{HasSelector, IsSelector, ScopeRule, StartingStyle, WhereSelector};
23pub use spacing::{Margin, Padding, Radius, ResponsiveSpacing, Spacing, SpacingScale};
24pub use typography::{FontFamily, FontSize, FontWeight, LineHeight, TextStyle, TypographyScale};
25pub use units::{Angle, Length, Percentage, Time};
26
27/// Style builder for constructing type-safe CSS styles
28pub struct StyleBuilder {
29    styles: Vec<String>,
30}
31
32impl StyleBuilder {
33    /// Create a new style builder
34    pub fn new() -> Self {
35        Self { styles: Vec::new() }
36    }
37
38    /// Add a background color
39    pub fn background_color(mut self, color: Color) -> Self {
40        self.styles
41            .push(format!("background-color: {};", color.to_css()));
42        self
43    }
44
45    /// Add a color
46    pub fn color(mut self, color: Color) -> Self {
47        self.styles.push(format!("color: {};", color.to_css()));
48        self
49    }
50
51    /// Add padding
52    pub fn padding(mut self, padding: Spacing) -> Self {
53        self.styles.push(format!("padding: {};", padding.to_css()));
54        self
55    }
56
57    /// Add margin
58    pub fn margin(mut self, margin: Spacing) -> Self {
59        self.styles.push(format!("margin: {};", margin.to_css()));
60        self
61    }
62
63    /// Add border radius
64    pub fn border_radius(mut self, radius: Radius) -> Self {
65        self.styles
66            .push(format!("border-radius: {};", radius.to_css()));
67        self
68    }
69
70    /// Add font size
71    pub fn font_size(mut self, size: FontSize) -> Self {
72        self.styles.push(format!("font-size: {};", size.to_css()));
73        self
74    }
75
76    /// Add display property
77    pub fn display(mut self, display: Display) -> Self {
78        self.styles.push(format!("display: {};", display.to_css()));
79        self
80    }
81
82    /// Add flex direction
83    pub fn flex_direction(mut self, direction: FlexDirection) -> Self {
84        self.styles
85            .push(format!("flex-direction: {};", direction.to_css()));
86        self
87    }
88
89    /// Add justify content
90    pub fn justify_content(mut self, justify: JustifyContent) -> Self {
91        self.styles
92            .push(format!("justify-content: {};", justify.to_css()));
93        self
94    }
95
96    /// Add align items
97    pub fn align_items(mut self, align: AlignItems) -> Self {
98        self.styles
99            .push(format!("align-items: {};", align.to_css()));
100        self
101    }
102
103    /// Add a custom CSS property
104    pub fn property(mut self, property: &str, value: &str) -> Self {
105        self.styles.push(format!("{}: {};", property, value));
106        self
107    }
108
109    /// Build the CSS string
110    pub fn build(self) -> String {
111        self.styles.join(" ")
112    }
113}
114
115impl Default for StyleBuilder {
116    fn default() -> Self {
117        Self::new()
118    }
119}