orbit/kit/components/
card.rs

1// Card component for OrbitKit
2
3use crate::component::{Component, ComponentError, ComponentId, Context, Node};
4
5/// Card component
6#[derive(Debug)]
7pub struct Card {
8    /// Component ID for tracking
9    id: ComponentId,
10    /// Card title
11    pub title: Option<String>,
12    /// Card elevation (shadow level)
13    pub elevation: u8,
14    /// Card border radius
15    pub border_radius: String,
16    /// Whether the card has a border
17    pub bordered: bool,
18    /// Card padding
19    pub padding: String,
20    /// Child content
21    pub children: Option<String>,
22}
23
24/// Card props
25#[derive(Debug, Clone)]
26pub struct CardProps {
27    /// Card title
28    pub title: Option<String>,
29    /// Card elevation (shadow level)
30    pub elevation: Option<u8>,
31    /// Card border radius
32    pub border_radius: Option<String>,
33    /// Whether the card has a border
34    pub bordered: Option<bool>,
35    /// Card padding
36    pub padding: Option<String>,
37    /// Child content
38    pub children: Option<String>,
39}
40
41impl Default for Card {
42    fn default() -> Self {
43        Self {
44            id: ComponentId::new(),
45            title: None,
46            elevation: 1,
47            border_radius: "4px".to_string(),
48            bordered: false,
49            padding: "16px".to_string(),
50            children: None,
51        }
52    }
53}
54
55impl Component for Card {
56    type Props = CardProps;
57
58    fn component_id(&self) -> ComponentId {
59        self.id
60    }
61
62    fn create(props: Self::Props, _context: Context) -> Self {
63        Self {
64            id: ComponentId::new(),
65            title: props.title,
66            elevation: props.elevation.unwrap_or(1),
67            border_radius: props.border_radius.unwrap_or_else(|| "4px".to_string()),
68            bordered: props.bordered.unwrap_or(false),
69            padding: props.padding.unwrap_or_else(|| "16px".to_string()),
70            children: props.children,
71        }
72    }
73
74    fn update(&mut self, props: Self::Props) -> Result<(), ComponentError> {
75        self.title = props.title;
76        self.elevation = props.elevation.unwrap_or(self.elevation);
77        self.border_radius = props
78            .border_radius
79            .unwrap_or_else(|| self.border_radius.clone());
80        self.bordered = props.bordered.unwrap_or(self.bordered);
81        self.padding = props.padding.unwrap_or_else(|| self.padding.clone());
82        self.children = props.children;
83        Ok(())
84    }
85
86    fn as_any(&self) -> &dyn std::any::Any {
87        self
88    }
89
90    fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
91        self
92    }
93
94    fn render(&self) -> Result<Vec<Node>, ComponentError> {
95        // For now, return an empty Vec since we're not yet using the Node system
96        // In a real implementation, this would return the actual DOM nodes
97        Ok(vec![])
98    }
99}