orbit/kit/
theme.rs

1// Theme support for OrbitKit
2
3use crate::component::{Component, ComponentError, ComponentId, Context, Node};
4use std::any::Any;
5
6/// Theme for OrbitKit
7#[derive(Debug, Clone)]
8pub struct Theme {
9    /// Primary color
10    pub primary_color: String,
11    /// Secondary color
12    pub secondary_color: String,
13    /// Text color
14    pub text_color: String,
15    /// Background color
16    pub background_color: String,
17    /// Error color
18    pub error_color: String,
19    /// Success color
20    pub success_color: String,
21    /// Warning color
22    pub warning_color: String,
23    /// Info color
24    pub info_color: String,
25    /// Border radius
26    pub border_radius: String,
27    /// Font family
28    pub font_family: String,
29    /// Font size
30    pub font_size: String,
31}
32
33impl Default for Theme {
34    fn default() -> Self {
35        Self {
36            primary_color: "#0070f3".to_string(),
37            secondary_color: "#f5f5f5".to_string(),
38            text_color: "#333333".to_string(),
39            background_color: "#ffffff".to_string(),
40            error_color: "#ff0000".to_string(),
41            success_color: "#00cc00".to_string(),
42            warning_color: "#ffcc00".to_string(),
43            info_color: "#0088cc".to_string(),
44            border_radius: "4px".to_string(),
45            font_family: "Arial, sans-serif".to_string(),
46            font_size: "16px".to_string(),
47        }
48    }
49}
50
51/// Theme provider component
52#[derive(Debug)]
53pub struct ThemeProvider {
54    /// Component ID for tracking
55    id: ComponentId,
56    /// Theme
57    pub theme: Theme,
58    /// Child content
59    pub children: Option<String>,
60}
61
62/// Theme provider props
63#[derive(Debug, Clone)]
64pub struct ThemeProviderProps {
65    /// Theme
66    pub theme: Option<Theme>,
67    /// Child content
68    pub children: Option<String>,
69}
70
71impl Component for ThemeProvider {
72    type Props = ThemeProviderProps;
73
74    fn component_id(&self) -> ComponentId {
75        self.id
76    }
77
78    fn create(props: Self::Props, _context: Context) -> Self {
79        Self {
80            id: ComponentId::new(),
81            theme: props.theme.unwrap_or_default(),
82            children: props.children,
83        }
84    }
85
86    fn update(&mut self, props: Self::Props) -> Result<(), ComponentError> {
87        self.theme = props.theme.unwrap_or_else(|| self.theme.clone());
88        self.children = props.children;
89        Ok(())
90    }
91
92    fn as_any(&self) -> &dyn Any {
93        self
94    }
95
96    fn as_any_mut(&mut self) -> &mut dyn Any {
97        self
98    }
99
100    fn render(&self) -> Result<Vec<Node>, ComponentError> {
101        // For now, return an empty Vec since we're not yet using the Node system
102        // In a real implementation, this would return the actual DOM nodes
103        Ok(vec![])
104    }
105}