rustyle_css/components/
progress.rs

1//! Progress component styles
2//!
3//! Provides type-safe progress bar styling with variants and sizes.
4
5use super::{ComponentStyle, Size, Variant};
6use crate::css::{Color, Radius};
7use crate::tokens::{BorderTokens, ColorTokens, SpacingTokens};
8
9/// Progress style configuration
10#[derive(Clone, Debug)]
11pub struct ProgressStyle {
12    pub variant: Variant,
13    pub size: Size,
14    pub tokens: Option<ProgressTokens>,
15}
16
17/// Progress design tokens
18#[derive(Clone, Debug)]
19pub struct ProgressTokens {
20    pub colors: ColorTokens,
21    pub spacing: SpacingTokens,
22    pub borders: BorderTokens,
23}
24
25impl ProgressStyle {
26    /// Create a new progress style
27    pub fn new(variant: Variant, size: Size) -> Self {
28        Self {
29            variant,
30            size,
31            tokens: None,
32        }
33    }
34
35    /// Set custom tokens
36    pub fn tokens(mut self, tokens: ProgressTokens) -> Self {
37        self.tokens = Some(tokens);
38        self
39    }
40
41    fn background_color(&self) -> Color {
42        let default_colors = ColorTokens::default();
43        let colors = self
44            .tokens
45            .as_ref()
46            .map(|t| &t.colors)
47            .unwrap_or(&default_colors);
48
49        colors.secondary.c200.clone()
50    }
51
52    fn fill_color(&self) -> Color {
53        let default_colors = ColorTokens::default();
54        let colors = self
55            .tokens
56            .as_ref()
57            .map(|t| &t.colors)
58            .unwrap_or(&default_colors);
59
60        match &self.variant {
61            Variant::Primary => colors.primary.c500.clone(),
62            Variant::Secondary => colors.secondary.c500.clone(),
63            Variant::Success => colors.semantic.success.clone(),
64            Variant::Error => colors.semantic.error.clone(),
65            Variant::Warning => colors.semantic.warning.clone(),
66            Variant::Info => colors.semantic.info.clone(),
67        }
68    }
69
70    fn height(&self) -> String {
71        match &self.size {
72            Size::Small => "4px".to_string(),
73            Size::Medium => "8px".to_string(),
74            Size::Large => "12px".to_string(),
75            Size::ExtraLarge => "16px".to_string(),
76        }
77    }
78
79    fn border_radius(&self) -> Radius {
80        let default_borders = BorderTokens::default();
81        let borders = self
82            .tokens
83            .as_ref()
84            .map(|t| &t.borders)
85            .unwrap_or(&default_borders);
86
87        Radius::all(borders.radius.full.clone())
88    }
89}
90
91impl ComponentStyle for ProgressStyle {
92    fn to_css(&self) -> String {
93        let mut css = String::new();
94
95        css.push_str(&format!(
96            "background-color: {}; ",
97            self.background_color().to_css()
98        ));
99        css.push_str(&format!(
100            "border-radius: {}; ",
101            self.border_radius().to_css()
102        ));
103        css.push_str(&format!("height: {}; ", self.height()));
104        css.push_str("width: 100%; ");
105        css.push_str("overflow: hidden; ");
106        css.push_str("position: relative; ");
107
108        css
109    }
110
111    fn class_name(&self) -> &str {
112        "rustyle-progress"
113    }
114}
115
116impl Default for ProgressStyle {
117    fn default() -> Self {
118        Self::new(Variant::Primary, Size::Medium)
119    }
120}