1pub mod layout;
8pub mod components;
9pub mod tokens;
10pub mod ferrox_datagrid;
11pub mod ferrox_kanban;
12pub mod ferrox_theme;
13pub mod ferrox_admin;
14pub mod ferrox_security_dashboard;
15
16use ferrox_front_core::dom::{div, span, DomBuilder};
17use ferrox_front_core::reactivity::Signal;
18
19pub struct DataGridState {
20 pub scroll_top: Signal<f64>,
21 pub row_height: f64,
22 pub visible_rows: usize,
23}
24
25impl DataGridState {
26 pub fn new(row_height: f64, visible_rows: usize) -> Self {
27 Self {
28 scroll_top: Signal::new(0.0),
29 row_height,
30 visible_rows,
31 }
32 }
33}
34
35pub fn virtual_data_grid(
36 columns: Vec<&str>,
37 rows: Vec<Vec<&str>>,
38 state: &DataGridState
39) -> DomBuilder {
40 let total_rows = rows.len();
41 let total_height = total_rows as f64 * state.row_height;
42
43 let start_idx = (state.scroll_top.get() / state.row_height).floor() as usize;
44 let end_idx = (start_idx + state.visible_rows).min(total_rows);
45
46 let mut container = div()
47 .attr("class", "ferrox-table-wrapper")
48 .attr("style", &format!("height: {}px; overflow-y: auto; position: relative;", state.row_height * state.visible_rows as f64));
49
50 let ghost = div()
51 .attr("style", &format!("height: {}px; width: 1px;", total_height));
52 container = container.child(ghost);
53
54 let mut content = div()
55 .attr("style", &format!("position: absolute; top: {}px; left: 0; width: 100%;", start_idx as f64 * state.row_height));
56
57 let mut thead = div().attr("class", "ferrox-thead").attr("style", "display: flex; background: rgba(0,0,0,0.4); font-weight: 700; border-bottom: var(--border-glass);");
58 for col in columns {
59 thead = thead.child(span().attr("style", "flex: 1; padding: 12px 16px;").text(col));
60 }
61 content = content.child(thead);
62
63 for i in start_idx..end_idx {
64 let mut tr = div().attr("class", "ferrox-tr").attr("style", &format!("display: flex; height: {}px; align-items: center; border-bottom: 1px solid rgba(255,255,255,0.05);", state.row_height));
65 for cell in &rows[i] {
66 tr = tr.child(span().attr("style", "flex: 1; padding: 0 16px; font-size: 0.95rem;").text(cell));
67 }
68 content = content.child(tr);
69 }
70
71 container.child(content)
72}