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)]
19 pub cell: Option<Callback<String, Element>>,
20
21 #[props(default = 100)]
23 pub min_width: u32,
24
25 #[props(default)]
27 pub style: Option<&'static str>,
28
29 #[props(default)]
31 pub class: Option<&'static str>,
32}
33
34#[derive(PartialEq, Props, Clone)]
36pub struct TableTexts {
37 #[props(default = "Loading...")]
39 pub loading: &'static str,
40
41 #[props(default = "No results found")]
43 pub empty: &'static str,
44
45 #[props(default = "Search...")]
47 pub search_placeholder: &'static str,
48
49 #[props(default = "Previous")]
51 pub previous_button: &'static str,
52
53 #[props(default = "Next")]
55 pub next_button: &'static str,
56
57 #[props(default = "Page {current} of {total}")]
59 pub page_indicator: &'static str,
60}
61
62impl Default for TableTexts {
63 fn default() -> Self {
64 Self {
65 loading: "Loading...",
66 empty: "No results found",
67 search_placeholder: "Search...",
68 previous_button: "Previous",
69 next_button: "Next",
70 page_indicator: "Page {current} of {total}",
71 }
72 }
73}
74
75#[derive(Clone, PartialEq)]
77pub struct TableClasses {
78 pub container: &'static str,
80
81 pub table: &'static str,
83
84 pub thead: &'static str,
86
87 pub tbody: &'static str,
89
90 pub pagination: &'static str,
92
93 pub search_input: &'static str,
95
96 pub header_cell: &'static str,
98
99 pub body_cell: &'static str,
101
102 pub row: &'static str,
104
105 pub loading_row: &'static str,
107
108 pub empty_row: &'static str,
110
111 pub pagination_button: &'static str,
113}
114
115impl Default for TableClasses {
116 fn default() -> Self {
117 Self {
118 container: "table-container",
119 table: "table",
120 thead: "thead",
121 tbody: "tbody",
122 pagination: "pagination-controls",
123 search_input: "search-input",
124 header_cell: "th",
125 body_cell: "td",
126 row: "tr",
127 loading_row: "loading-row",
128 empty_row: "empty-row",
129 pagination_button: "pagination-button",
130 }
131 }
132}
133
134#[derive(PartialEq, Props, Clone)]
136pub struct TableProps {
137 #[props(default)]
139 pub data: Vec<HashMap<&'static str, String>>,
140
141 #[props(default)]
143 pub columns: Vec<Column>,
144
145 #[props(default = 10)]
147 pub page_size: usize,
148
149 #[props(default)]
151 pub loading: bool,
152
153 #[props(default = false)]
155 pub paginate: bool,
156
157 #[props(default = false)]
159 pub search: bool,
160
161 #[props(default)]
163 pub texts: TableTexts,
164
165 #[props(default)]
167 pub classes: TableClasses,
168}
169
170#[derive(PartialEq, Clone, Copy, Default)]
172pub enum SortOrder {
173 #[default]
175 Asc,
176 Desc,
178}