use dioxus::prelude::*;
use std::collections::HashMap;
#[derive(PartialEq, Props, Clone, Default)]
pub struct Column {
pub id: &'static str,
pub header: &'static str,
#[props(default)]
pub sortable: bool,
#[props(default)]
pub cell: Option<Callback<String, Element>>,
#[props(default = 100)]
pub min_width: u32,
#[props(default)]
pub style: Option<&'static str>,
#[props(default)]
pub class: Option<&'static str>,
}
#[derive(PartialEq, Props, Clone)]
pub struct TableTexts {
#[props(default = "Loading...")]
pub loading: &'static str,
#[props(default = "No results found")]
pub empty: &'static str,
#[props(default = "Search...")]
pub search_placeholder: &'static str,
#[props(default = "Previous")]
pub previous_button: &'static str,
#[props(default = "Next")]
pub next_button: &'static str,
#[props(default = "Page {current} of {total}")]
pub page_indicator: &'static str,
}
impl Default for TableTexts {
fn default() -> Self {
Self {
loading: "Loading...",
empty: "No results found",
search_placeholder: "Search...",
previous_button: "Previous",
next_button: "Next",
page_indicator: "Page {current} of {total}",
}
}
}
#[derive(Clone, PartialEq)]
pub struct TableClasses {
pub container: &'static str,
pub table: &'static str,
pub thead: &'static str,
pub tbody: &'static str,
pub pagination: &'static str,
pub search_input: &'static str,
pub header_cell: &'static str,
pub body_cell: &'static str,
pub row: &'static str,
pub loading_row: &'static str,
pub empty_row: &'static str,
pub pagination_button: &'static str,
}
impl Default for TableClasses {
fn default() -> Self {
Self {
container: "table-container",
table: "table",
thead: "thead",
tbody: "tbody",
pagination: "pagination-controls",
search_input: "search-input",
header_cell: "th",
body_cell: "td",
row: "tr",
loading_row: "loading-row",
empty_row: "empty-row",
pagination_button: "pagination-button",
}
}
}
#[derive(PartialEq, Props, Clone)]
pub struct TableProps {
#[props(default)]
pub data: Vec<HashMap<&'static str, String>>,
#[props(default)]
pub columns: Vec<Column>,
#[props(default = 10)]
pub page_size: usize,
#[props(default)]
pub loading: bool,
#[props(default = false)]
pub paginate: bool,
#[props(default = false)]
pub search: bool,
#[props(default)]
pub texts: TableTexts,
#[props(default)]
pub classes: TableClasses,
}
#[derive(PartialEq, Clone, Copy, Default)]
pub enum SortOrder {
#[default]
Asc,
Desc,
}