Skip to main content

ferrox_front_ui/
lib.rs

1//! # Ferrox Front UI (`ferrox-front-ui`)
2//!
3//! `ferrox-front-ui` provides an enterprise-grade Glassmorphism Design System for WebAssembly:
4//! 12-column responsive layout grid (`Container`, `Row`, `Col`), Virtualized DataGrid (1,000,000+ rows),
5//! Design Tokens, and UI components (Buttons, Badges, Cards, Form Controls, Avatars, Progress Bars, Toasts, Spinners).
6
7pub 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;
15pub mod json_dashboard_builder;
16
17use ferrox_front_core::dom::{div, span, DomBuilder};
18use ferrox_front_core::reactivity::Signal;
19
20pub struct DataGridState {
21    pub scroll_top: Signal<f64>,
22    pub row_height: f64,
23    pub visible_rows: usize,
24}
25
26impl DataGridState {
27    pub fn new(row_height: f64, visible_rows: usize) -> Self {
28        Self {
29            scroll_top: Signal::new(0.0),
30            row_height,
31            visible_rows,
32        }
33    }
34}
35
36pub fn virtual_data_grid(
37    columns: Vec<&str>,
38    rows: Vec<Vec<&str>>,
39    state: &DataGridState
40) -> DomBuilder {
41    let total_rows = rows.len();
42    let total_height = total_rows as f64 * state.row_height;
43
44    let start_idx = (state.scroll_top.get() / state.row_height).floor() as usize;
45    let end_idx = (start_idx + state.visible_rows).min(total_rows);
46
47    let mut container = div()
48        .attr("class", "ferrox-table-wrapper")
49        .attr("style", &format!("height: {}px; overflow-y: auto; position: relative;", state.row_height * state.visible_rows as f64));
50    
51    let ghost = div()
52        .attr("style", &format!("height: {}px; width: 1px;", total_height));
53    container = container.child(ghost);
54
55    let mut content = div()
56        .attr("style", &format!("position: absolute; top: {}px; left: 0; width: 100%;", start_idx as f64 * state.row_height));
57
58    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);");
59    for col in columns {
60        thead = thead.child(span().attr("style", "flex: 1; padding: 12px 16px;").text(col));
61    }
62    content = content.child(thead);
63
64    for i in start_idx..end_idx {
65        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));
66        for cell in &rows[i] {
67            tr = tr.child(span().attr("style", "flex: 1; padding: 0 16px; font-size: 0.95rem;").text(cell));
68        }
69        content = content.child(tr);
70    }
71
72    container.child(content)
73}