use dioxus::prelude::*;
use crate::types::{Color, Size};
#[derive(Clone, PartialEq, Props)]
pub struct TableProps {
#[props(default)]
pub striped: bool,
#[props(default)]
pub striped_columns: bool,
#[props(default)]
pub hover: bool,
#[props(default)]
pub bordered: bool,
#[props(default)]
pub borderless: bool,
#[props(default)]
pub size: Size,
#[props(default)]
pub color: Option<Color>,
#[props(default)]
pub responsive: bool,
#[props(default)]
pub caption: String,
#[props(default)]
pub caption_top: bool,
#[props(default)]
pub class: String,
#[props(extends = GlobalAttributes)]
attributes: Vec<Attribute>,
pub children: Element,
}
#[component]
pub fn Table(props: TableProps) -> Element {
let mut classes = vec!["table".to_string()];
if props.striped {
classes.push("table-striped".to_string());
}
if props.striped_columns {
classes.push("table-striped-columns".to_string());
}
if props.caption_top {
classes.push("caption-top".to_string());
}
if props.hover {
classes.push("table-hover".to_string());
}
if props.bordered {
classes.push("table-bordered".to_string());
}
if props.borderless {
classes.push("table-borderless".to_string());
}
if let Size::Sm = props.size {
classes.push("table-sm".to_string());
}
if let Some(ref c) = props.color {
classes.push(format!("table-{c}"));
}
if !props.class.is_empty() {
classes.push(props.class.clone());
}
let full_class = classes.join(" ");
let caption = props.caption.clone();
if props.responsive {
rsx! {
div { class: "table-responsive",
table { class: "{full_class}",
..props.attributes,
if !caption.is_empty() {
caption { "{caption}" }
}
{props.children}
}
}
}
} else {
rsx! {
table { class: "{full_class}",
..props.attributes,
if !caption.is_empty() {
caption { "{caption}" }
}
{props.children}
}
}
}
}