1use dioxus::prelude::*;
2use std::collections::HashMap;
3
4#[derive(PartialEq, Props, Clone, Default)]
6pub struct Column {
7 pub id: &'static str,
9
10 pub header: &'static str,
12
13 #[props(default)]
15 pub sortable: bool,
16
17 #[props(default = 100)]
19 pub min_width: u32,
20
21 #[props(default)]
23 pub style: Option<&'static str>,
24
25 #[props(default)]
27 pub class: Option<&'static str>,
28}
29
30#[derive(PartialEq, Props, Clone)]
32pub struct TableTexts {
33 #[props(default = "Loading...")]
35 pub loading: &'static str,
36
37 #[props(default = "No results found")]
39 pub empty: &'static str,
40
41 #[props(default = "Search...")]
43 pub search_placeholder: &'static str,
44
45 #[props(default = "Previous")]
47 pub previous_button: &'static str,
48
49 #[props(default = "Next")]
51 pub next_button: &'static str,
52
53 #[props(default = "Page {current} of {total}")]
55 pub page_indicator: &'static str,
56}
57
58impl Default for TableTexts {
59 fn default() -> Self {
60 Self {
61 loading: "Loading...",
62 empty: "No results found",
63 search_placeholder: "Search...",
64 previous_button: "Previous",
65 next_button: "Next",
66 page_indicator: "Page {current} of {total}",
67 }
68 }
69}
70
71#[derive(Clone, PartialEq)]
73pub struct TableClasses {
74 pub container: &'static str,
76
77 pub table: &'static str,
79
80 pub thead: &'static str,
82
83 pub tbody: &'static str,
85
86 pub pagination: &'static str,
88
89 pub search_input: &'static str,
91
92 pub header_cell: &'static str,
94
95 pub body_cell: &'static str,
97
98 pub row: &'static str,
100
101 pub loading_row: &'static str,
103
104 pub empty_row: &'static str,
106
107 pub pagination_button: &'static str,
109}
110
111impl Default for TableClasses {
112 fn default() -> Self {
113 Self {
114 container: "table-container",
115 table: "table",
116 thead: "thead",
117 tbody: "tbody",
118 pagination: "pagination-controls",
119 search_input: "search-input",
120 header_cell: "th",
121 body_cell: "td",
122 row: "tr",
123 loading_row: "loading-row",
124 empty_row: "empty-row",
125 pagination_button: "pagination-button",
126 }
127 }
128}
129
130#[derive(PartialEq, Props, Clone)]
132pub struct TableProps {
133 #[props(default)]
135 pub data: Vec<HashMap<&'static str, String>>,
136
137 #[props(default)]
139 pub columns: Vec<Column>,
140
141 #[props(default = 10)]
143 pub page_size: usize,
144
145 #[props(default)]
147 pub loading: bool,
148
149 #[props(default = false)]
151 pub paginate: bool,
152
153 #[props(default = false)]
155 pub search: bool,
156
157 #[props(default)]
159 pub texts: TableTexts,
160
161 #[props(default)]
163 pub classes: TableClasses,
164}
165
166#[derive(PartialEq, Clone, Copy, Default)]
168pub enum SortOrder {
169 #[default]
171 Asc,
172 Desc,
174}