tablo_ui/components/primitives/
table.rs1use topcoat::{
3 Result,
4 view::{Attributes, Child, View, class, component, view},
5};
6
7#[component]
35pub async fn table(
36 #[default] mut attrs: Attributes,
37 #[default] child: Child<'_>,
38) -> Result<impl View> {
39 Ok(view! {
40 <div data-slot="table" class="w-full overflow-x-auto">
41 <table
43 class=(class!(
44 "w-full caption-bottom border-collapse border-border text-sm",
45 "[:not(:first-child)>&]:border-t [:not(:last-child)>&]:border-b",
46 attrs.remove("class"),
47 ))
48 (attrs)
49 >
50 (child)
51 </table>
52 </div>
53 })
54}
55
56#[component]
58pub async fn table_header(
59 #[default] mut attrs: Attributes,
60 #[default] child: Child<'_>,
61) -> Result<impl View> {
62 Ok(view! {
63 <thead
64 class=(class!("bg-foreground/5 [&_tr]:border-b", attrs.remove("class")))
65 (attrs)
66 >
67 (child)
68 </thead>
69 })
70}
71
72#[component]
74pub async fn table_body(
75 #[default] mut attrs: Attributes,
76 #[default] child: Child<'_>,
77) -> Result<impl View> {
78 Ok(view! {
79 <tbody
80 class=(class!("[&_tr:last-child]:border-0", attrs.remove("class")))
81 (attrs)
82 >
83 (child)
84 </tbody>
85 })
86}
87
88#[component]
90pub async fn table_footer(
91 #[default] mut attrs: Attributes,
92 #[default] child: Child<'_>,
93) -> Result<impl View> {
94 Ok(view! {
95 <tfoot
96 class=(class!(
97 "border-t border-border bg-foreground/5 font-medium [&>tr]:last:border-b-0",
98 attrs.remove("class"),
99 ))
100 (attrs)
101 >
102 (child)
103 </tfoot>
104 })
105}
106
107#[component]
109pub async fn table_row(
110 #[default] mut attrs: Attributes,
111 #[default] child: Child<'_>,
112) -> Result<impl View> {
113 Ok(view! {
114 <tr
115 class=(class!(
116 "border-b border-border transition-colors hover:bg-foreground/5",
117 attrs.remove("class"),
118 ))
119 (attrs)
120 >
121 (child)
122 </tr>
123 })
124}
125
126#[component]
128pub async fn table_head(
129 #[default] mut attrs: Attributes,
130 #[default] child: Child<'_>,
131) -> Result<impl View> {
132 Ok(view! {
133 <th
134 class=(class!(
135 "p-3 text-left align-middle font-medium whitespace-nowrap",
136 "text-muted-foreground first:pl-6 last:pr-6",
137 attrs.remove("class"),
138 ))
139 (attrs)
140 >
141 (child)
142 </th>
143 })
144}
145
146#[component]
148pub async fn table_cell(
149 #[default] mut attrs: Attributes,
150 #[default] child: Child<'_>,
151) -> Result<impl View> {
152 Ok(view! {
153 <td
154 class=(class!(
155 "p-3 align-middle whitespace-nowrap first:pl-6 last:pr-6",
156 attrs.remove("class"),
157 ))
158 (attrs)
159 >
160 (child)
161 </td>
162 })
163}
164
165#[component]
167pub async fn table_caption(
168 #[default] mut attrs: Attributes,
169 #[default] child: Child<'_>,
170) -> Result<impl View> {
171 Ok(view! {
172 <caption
173 class=(class!("mt-4 text-sm text-muted-foreground", attrs.remove("class")))
174 (attrs)
175 >
176 (child)
177 </caption>
178 })
179}