rustyle_css/tokens/
border.rs

1//! Border token system
2//!
3//! Provides consistent border widths, styles, and radius values.
4
5use crate::css::Length;
6
7/// Border width scale
8#[derive(Clone, Debug)]
9pub struct BorderWidthScale {
10    pub none: Length,
11    pub thin: Length,
12    pub base: Length,
13    pub thick: Length,
14}
15
16impl BorderWidthScale {
17    /// Create new border width scale
18    pub fn new(none: Length, thin: Length, base: Length, thick: Length) -> Self {
19        Self {
20            none,
21            thin,
22            base,
23            thick,
24        }
25    }
26}
27
28/// Border radius scale
29#[derive(Clone, Debug)]
30pub struct BorderRadiusScale {
31    pub none: Length,
32    pub sm: Length,
33    pub base: Length,
34    pub md: Length,
35    pub lg: Length,
36    pub xl: Length,
37    pub xl2: Length,
38    pub full: Length,
39}
40
41impl BorderRadiusScale {
42    /// Create new border radius scale
43    pub fn new(
44        none: Length,
45        sm: Length,
46        base: Length,
47        md: Length,
48        lg: Length,
49        xl: Length,
50        xl2: Length,
51        full: Length,
52    ) -> Self {
53        Self {
54            none,
55            sm,
56            base,
57            md,
58            lg,
59            xl,
60            xl2,
61            full,
62        }
63    }
64
65    /// Get radius by name
66    pub fn get(&self, name: &str) -> &Length {
67        match name {
68            "none" => &self.none,
69            "sm" => &self.sm,
70            "base" => &self.base,
71            "md" => &self.md,
72            "lg" => &self.lg,
73            "xl" => &self.xl,
74            "2xl" | "xl2" => &self.xl2,
75            "full" => &self.full,
76            _ => &self.base,
77        }
78    }
79}
80
81/// Comprehensive border token system
82#[derive(Clone, Debug)]
83pub struct BorderTokens {
84    pub width: BorderWidthScale,
85    pub radius: BorderRadiusScale,
86}
87
88impl BorderTokens {
89    /// Create new border tokens
90    pub fn new(width: BorderWidthScale, radius: BorderRadiusScale) -> Self {
91        Self { width, radius }
92    }
93
94    /// Convert border tokens to CSS custom properties
95    pub fn to_css_vars(&self) -> String {
96        format!(
97            "  --border-width-none: {};\n  --border-width-thin: {};\n  --border-width-base: {};\n  --border-width-thick: {};\n  --border-radius-none: {};\n  --border-radius-sm: {};\n  --border-radius-base: {};\n  --border-radius-md: {};\n  --border-radius-lg: {};\n  --border-radius-xl: {};\n  --border-radius-2xl: {};\n  --border-radius-full: {};\n",
98            self.width.none.to_css(),
99            self.width.thin.to_css(),
100            self.width.base.to_css(),
101            self.width.thick.to_css(),
102            self.radius.none.to_css(),
103            self.radius.sm.to_css(),
104            self.radius.base.to_css(),
105            self.radius.md.to_css(),
106            self.radius.lg.to_css(),
107            self.radius.xl.to_css(),
108            self.radius.xl2.to_css(),
109            self.radius.full.to_css(),
110        )
111    }
112}
113
114impl Default for BorderTokens {
115    fn default() -> Self {
116        Self {
117            width: BorderWidthScale::new(
118                Length::px(0.0),
119                Length::px(1.0),
120                Length::px(2.0),
121                Length::px(4.0),
122            ),
123            radius: BorderRadiusScale::new(
124                Length::px(0.0),
125                Length::rem(0.125),    // 2px
126                Length::rem(0.25),     // 4px
127                Length::rem(0.375),    // 6px
128                Length::rem(0.5),      // 8px
129                Length::rem(0.75),     // 12px
130                Length::rem(1.0),      // 16px
131                Length::percent(50.0), // 50% for full circle
132            ),
133        }
134    }
135}