03_molecules/
03_molecules.rs

1//! Molecules Showcase Example
2//!
3//! Demonstrates the molecule components in tuiuiu.
4
5use tuiuiu::molecules::{
6    // Select components
7    Select, SelectOption, MultiSelect, RadioGroup,
8    // Autocomplete
9    Autocomplete, Suggestion,
10    // Table
11    Table, Column, Align,
12    // Tree
13    Tree, TreeNode,
14    // Calendar
15    Calendar,
16    // Tabs
17    Tabs, Tab, TabStyle,
18    // Code
19    CodeBlock, CodeTheme, Markdown,
20    // Charts
21    Sparkline, BarChart, BarItem, Gauge, GaugeStyle,
22};
23use tuiuiu::core::component::VNode;
24
25fn main() {
26    // Test Select
27    let select = Select::new()
28        .items(["Option 1", "Option 2", "Option 3"])
29        .selected(1)
30        .open(true)
31        .build();
32
33    println!("Select: {:?}\n", matches!(select, VNode::Box(_)));
34
35    // Test RadioGroup
36    let radio = RadioGroup::new()
37        .items(["Small", "Medium", "Large"])
38        .selected(1)
39        .label("Size")
40        .build();
41
42    println!("RadioGroup: {:?}\n", matches!(radio, VNode::Box(_)));
43
44    // Test Autocomplete
45    let autocomplete = Autocomplete::new()
46        .suggestions([
47            Suggestion::new("Rust").description("Systems programming"),
48            Suggestion::new("Python").description("Scripting"),
49            Suggestion::new("JavaScript").description("Web development"),
50        ])
51        .value("Ru")
52        .open(true)
53        .build();
54
55    println!("Autocomplete: {:?}\n", matches!(autocomplete, VNode::Box(_)));
56
57    // Test Table
58    let table = Table::new()
59        .columns([
60            Column::new("Name").width(20),
61            Column::new("Age").width(10).align(Align::Right),
62            Column::new("City").width(15),
63        ])
64        .rows([
65            vec!["Alice".to_string(), "30".to_string(), "NYC".to_string()],
66            vec!["Bob".to_string(), "25".to_string(), "LA".to_string()],
67            vec!["Carol".to_string(), "35".to_string(), "SF".to_string()],
68        ])
69        .build();
70
71    println!("Table: {:?}\n", matches!(table, VNode::Box(_)));
72
73    // Test Tree
74    let tree = Tree::new()
75        .nodes([
76            TreeNode::folder("src")
77                .expanded(true)
78                .children([
79                    TreeNode::file("main.rs"),
80                    TreeNode::file("lib.rs"),
81                    TreeNode::folder("core")
82                        .children([
83                            TreeNode::file("app.rs"),
84                            TreeNode::file("signals.rs"),
85                        ]),
86                ]),
87            TreeNode::file("Cargo.toml"),
88        ])
89        .build();
90
91    println!("Tree: {:?}\n", matches!(tree, VNode::Box(_)));
92
93    // Test Calendar
94    let calendar = Calendar::new()
95        .date(2025, 1)
96        .selected(15)
97        .today(2025, 1, 24)
98        .build();
99
100    println!("Calendar: {:?}\n", matches!(calendar, VNode::Box(_)));
101
102    // Test Tabs
103    let tabs = Tabs::new()
104        .tabs([
105            Tab::new("Overview"),
106            Tab::new("Details").disabled(),
107            Tab::new("Settings"),
108        ])
109        .active(0)
110        .build();
111
112    println!("Tabs: {:?}\n", matches!(tabs, VNode::Box(_)));
113
114    // Test CodeBlock
115    let code = CodeBlock::new(r#"
116fn main() {
117    println!("Hello, Tuiuiu!");
118}
119"#)
120        .rust()
121        .highlight([2])
122        .build();
123
124    println!("CodeBlock: {:?}\n", matches!(code, VNode::Box(_)));
125
126    // Test Markdown
127    let md = Markdown::new(r#"
128# Title
129## Subtitle
130
131- Item 1
132- Item 2
133
134> A quote
135
136`code`
137"#).build();
138
139    println!("Markdown: {:?}\n", matches!(md, VNode::Box(_)));
140
141    // Test Sparkline
142    let sparkline = Sparkline::new()
143        .data([1.0, 4.0, 2.0, 8.0, 5.0, 7.0, 3.0, 6.0])
144        .build();
145
146    println!("Sparkline: {:?}\n", matches!(sparkline, VNode::Box(_)));
147
148    // Test BarChart
149    let bar_chart = BarChart::new()
150        .items([
151            BarItem::new("A", 30.0),
152            BarItem::new("B", 50.0),
153            BarItem::new("C", 20.0),
154        ])
155        .build();
156
157    println!("BarChart: {:?}\n", matches!(bar_chart, VNode::Box(_)));
158
159    // Test Gauge (returns Text node, not Box)
160    let gauge = Gauge::new()
161        .value(75.0)
162        .max(100.0)
163        .label("Progress")
164        .build();
165
166    println!("Gauge: {:?}\n", matches!(gauge, VNode::Text(_)));
167
168    println!("✅ All molecules compiled and instantiated successfully!");
169}