use topcoat::{
Result,
view::{Attributes, Child, View, class, component, view},
};
#[component]
pub async fn table(
#[default] mut attrs: Attributes,
#[default] child: Child<'_>,
) -> Result<impl View> {
Ok(view! {
<div data-slot="table" class="w-full overflow-x-auto">
<table
class=(class!(
"w-full caption-bottom border-collapse border-border text-sm",
"[:not(:first-child)>&]:border-t [:not(:last-child)>&]:border-b",
attrs.remove("class"),
))
(attrs)
>
(child)
</table>
</div>
})
}
#[component]
pub async fn table_header(
#[default] mut attrs: Attributes,
#[default] child: Child<'_>,
) -> Result<impl View> {
Ok(view! {
<thead
class=(class!("bg-foreground/5 [&_tr]:border-b", attrs.remove("class")))
(attrs)
>
(child)
</thead>
})
}
#[component]
pub async fn table_body(
#[default] mut attrs: Attributes,
#[default] child: Child<'_>,
) -> Result<impl View> {
Ok(view! {
<tbody
class=(class!("[&_tr:last-child]:border-0", attrs.remove("class")))
(attrs)
>
(child)
</tbody>
})
}
#[component]
pub async fn table_footer(
#[default] mut attrs: Attributes,
#[default] child: Child<'_>,
) -> Result<impl View> {
Ok(view! {
<tfoot
class=(class!(
"border-t border-border bg-foreground/5 font-medium [&>tr]:last:border-b-0",
attrs.remove("class"),
))
(attrs)
>
(child)
</tfoot>
})
}
#[component]
pub async fn table_row(
#[default] mut attrs: Attributes,
#[default] child: Child<'_>,
) -> Result<impl View> {
Ok(view! {
<tr
class=(class!(
"border-b border-border transition-colors hover:bg-foreground/5",
attrs.remove("class"),
))
(attrs)
>
(child)
</tr>
})
}
#[component]
pub async fn table_head(
#[default] mut attrs: Attributes,
#[default] child: Child<'_>,
) -> Result<impl View> {
Ok(view! {
<th
class=(class!(
"p-3 text-left align-middle font-medium whitespace-nowrap",
"text-muted-foreground first:pl-6 last:pr-6",
attrs.remove("class"),
))
(attrs)
>
(child)
</th>
})
}
#[component]
pub async fn table_cell(
#[default] mut attrs: Attributes,
#[default] child: Child<'_>,
) -> Result<impl View> {
Ok(view! {
<td
class=(class!(
"p-3 align-middle whitespace-nowrap first:pl-6 last:pr-6",
attrs.remove("class"),
))
(attrs)
>
(child)
</td>
})
}
#[component]
pub async fn table_caption(
#[default] mut attrs: Attributes,
#[default] child: Child<'_>,
) -> Result<impl View> {
Ok(view! {
<caption
class=(class!("mt-4 text-sm text-muted-foreground", attrs.remove("class")))
(attrs)
>
(child)
</caption>
})
}