dioxus_bootstrap_css/
table.rs1use dioxus::prelude::*;
2
3use crate::types::{Color, Size};
4
5#[derive(Clone, PartialEq, Props)]
26pub struct TableProps {
27 #[props(default)]
29 pub striped: bool,
30 #[props(default)]
32 pub hover: bool,
33 #[props(default)]
35 pub bordered: bool,
36 #[props(default)]
38 pub borderless: bool,
39 #[props(default)]
41 pub size: Size,
42 #[props(default)]
44 pub color: Option<Color>,
45 #[props(default)]
47 pub responsive: bool,
48 #[props(default)]
50 pub class: String,
51 pub children: Element,
53}
54
55#[component]
56pub fn Table(props: TableProps) -> Element {
57 let mut classes = vec!["table".to_string()];
58
59 if props.striped {
60 classes.push("table-striped".to_string());
61 }
62 if props.hover {
63 classes.push("table-hover".to_string());
64 }
65 if props.bordered {
66 classes.push("table-bordered".to_string());
67 }
68 if props.borderless {
69 classes.push("table-borderless".to_string());
70 }
71 if let Size::Sm = props.size {
72 classes.push("table-sm".to_string());
73 }
74 if let Some(ref c) = props.color {
75 classes.push(format!("table-{c}"));
76 }
77 if !props.class.is_empty() {
78 classes.push(props.class.clone());
79 }
80
81 let full_class = classes.join(" ");
82
83 if props.responsive {
84 rsx! {
85 div { class: "table-responsive",
86 table { class: "{full_class}", {props.children} }
87 }
88 }
89 } else {
90 rsx! {
91 table { class: "{full_class}", {props.children} }
92 }
93 }
94}