leptos_struct_table/class_providers/mod.rs
1mod bootstrap;
2mod tailwind;
3
4use crate::ColumnSort;
5pub use bootstrap::*;
6pub use tailwind::*;
7
8/// A trait for providing classes for the table.
9pub trait TableClassesProvider {
10 /// Create a new instance of the class provider.
11 fn new() -> Self;
12
13 /// Get the class attribute for the thead.
14 /// The `prop_class` parameter contains the classes specified in the
15 /// `thead_class` prop of the [`TableContent`] component.
16 fn thead(&self, prop_class: &str) -> String {
17 prop_class.to_string()
18 }
19
20 /// Get the classes for the thead row.
21 /// The `prop_class` parameter contains the classes specified in the
22 /// `thead_row_class` prop of the [`TableContent`] component.
23 fn thead_row(&self, prop_class: &str) -> String {
24 prop_class.to_string()
25 }
26
27 /// Get the classes for the thead cells.
28 /// The `sort` parameter contains the sort state of the column.
29 /// The `macro_class` parameter contains the classes specified in the `head_class` macro attribute of the field.
30 fn thead_cell(&self, sort: ColumnSort, macro_class: &str) -> String {
31 format!("{} {}", sort.as_class(), macro_class)
32 }
33
34 /// Get the classes for the thead cells' inner element.
35 fn thead_cell_inner(&self) -> String {
36 "".to_string()
37 }
38
39 /// Get the classes for the tbody.
40 /// The `prop_class` parameter contains the classes specified in the
41 /// `tbody_class` prop of the [`TableContent`] component.
42 fn tbody(&self, prop_class: &str) -> String {
43 prop_class.to_string()
44 }
45
46 #[allow(unused_variables)]
47 /// Get the classes for the body rows.
48 /// The `row_index` parameter contains the index of the row. The first row has index 0.
49 /// The `selected` parameter indicates whether the row is selected.
50 /// The `prop_class` parameter contains the classes specified in the `row_class`
51 /// prop of the [`TableContent`] component.
52 fn row(&self, row_index: usize, selected: bool, prop_class: &str) -> String {
53 prop_class.to_string() + if selected { " selected" } else { "" }
54 }
55
56 #[allow(unused_variables)]
57 /// Get the classes for the elements inside of the cells of rows that are currently
58 /// being loaded.
59 /// The `prop_class` parameter contains the classes specified in the
60 /// `loading_cell_class` prop of the [`TableContent`] component.
61 fn loading_cell(&self, row_index: usize, col_index: usize, prop_class: &str) -> String {
62 prop_class.to_string()
63 }
64
65 #[allow(unused_variables)]
66 /// Get the classes for the elements inside of the cells of rows that are currently
67 /// being loaded. Usually this will be some loading indicator like a sceleton bar.
68 /// The `prop_class` parameter contains the classes specified in the
69 /// `loading_cell_inner_class` prop of the [`TableContent`] component.
70 fn loading_cell_inner(&self, row_index: usize, col_index: usize, prop_class: &str) -> String {
71 prop_class.to_string()
72 }
73
74 /// Get the classes for the body cells.
75 /// The `macro_class` parameter contains the classes specified in the `class` macro attribute of the field.
76 fn cell(&self, macro_class: &str) -> String {
77 macro_class.to_string()
78 }
79}
80
81#[derive(Copy, Clone)]
82pub struct DummyTableClassesProvider;
83
84impl TableClassesProvider for DummyTableClassesProvider {
85 fn new() -> Self {
86 Self
87 }
88}