1use crate::component::{Component, ComponentError, ComponentId, Context, Node};
4use std::any::Any;
5
6#[derive(Debug, Clone)]
8pub struct Theme {
9 pub primary_color: String,
11 pub secondary_color: String,
13 pub text_color: String,
15 pub background_color: String,
17 pub error_color: String,
19 pub success_color: String,
21 pub warning_color: String,
23 pub info_color: String,
25 pub border_radius: String,
27 pub font_family: String,
29 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#[derive(Debug)]
53pub struct ThemeProvider {
54 id: ComponentId,
56 pub theme: Theme,
58 pub children: Option<String>,
60}
61
62#[derive(Debug, Clone)]
64pub struct ThemeProviderProps {
65 pub theme: Option<Theme>,
67 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 Ok(vec![])
104 }
105}