Seregon/StratoSDK

StratoSDK is a framework with a declarative approach similar to Flutter/React, written and designed entirely for Rust.

Rust/27.3 KB/No license
examples/modern_dashboard/src/components/activity_list.rs
StratoSDK / examples / modern_dashboard / src / components / activity_list.rs
1use strato_widgets::{
2 Widget, Column, Container, Text, Row, Flex,
3 text::FontWeight,
4 layout::{CrossAxisAlignment, MainAxisAlignment},
5};
6use crate::theme::{AppTheme, BORDER_RADIUS_MD, SPACING_MD, SPACING_SM};
7 
8pub struct ActivityList {
9 theme: AppTheme,
10}
11 
12impl ActivityList {
13 pub fn new() -> Self {
14 Self {
15 theme: AppTheme::dark(),
16 }
17 }
18 
19 pub fn build(self) -> impl Widget {
20 let theme = self.theme;
21 
22 Container::new()
23 .background(theme.bg_secondary)
24 .border_radius(BORDER_RADIUS_MD)
25 .padding(SPACING_MD)
26 .child(
27 Column::new()
28 .spacing(SPACING_MD)
29 .cross_axis_alignment(CrossAxisAlignment::Stretch)
30 .children(vec![
31 Box::new(Text::new("Recent Activity")
32 .font_size(18.0)
33 .font_weight(FontWeight::Bold)
34 .color(theme.text_primary)) as Box<dyn Widget>,
35 
36 self.activity_item("New user registered", "2 min ago", theme.success),
37 self.activity_item("Server rebooted", "15 min ago", theme.warning),
38 self.activity_item("Database backup completed", "1 hour ago", theme.accent),
39 self.activity_item("Payment failed", "2 hours ago", theme.error),
40 ])
41 )
42 }
43 
44 fn activity_item(&self, title: &str, time: &str, dot_color: strato_core::types::Color) -> Box<dyn Widget> {
45 let theme = &self.theme;
46 
47 Box::new(Container::new()
48 .padding(SPACING_SM)
49 .child(
50 Row::new()
51 .spacing(SPACING_MD)
52 .cross_axis_alignment(CrossAxisAlignment::Center)
53 .children(vec![
54 // Status Dot
55 Box::new(Container::new()
56 .width(10.0)
57 .height(10.0)
58 .border_radius(5.0)
59 .background(dot_color)) as Box<dyn Widget>,
60 
61 // Content
62 Box::new(Flex::new(
63 Box::new(Column::new()
64 .spacing(4.0)
65 .children(vec![
66 Box::new(Text::new(title)
67 .color(theme.text_primary)
68 .font_weight(FontWeight::SemiBold)) as Box<dyn Widget>,
69 Box::new(Text::new(time)
70 .color(theme.text_secondary)
71 .font_size(12.0)) as Box<dyn Widget>,
72 ])
73 )
74 ).flex(1.0)) as Box<dyn Widget>,
75 ])
76 )
77 )
78 }
79}
80