infoalloggi-monorepo/apps/infoalloggi/src/components/ui/table.tsx

115 lines
2.2 KiB
TypeScript
Raw Normal View History

2025-08-28 18:27:07 +02:00
import type * as React from "react";
2025-08-04 17:45:44 +02:00
2025-08-28 18:27:07 +02:00
import { cn } from "~/lib/utils";
2025-08-04 17:45:44 +02:00
function Table({ className, ...props }: React.ComponentProps<"table">) {
2025-08-28 18:27:07 +02:00
return (
<div
className="relative w-full overflow-x-auto"
2025-08-29 16:18:32 +02:00
data-slot="table-container"
2025-08-28 18:27:07 +02:00
>
<table
className={cn("w-full caption-bottom text-sm", className)}
2025-08-29 16:18:32 +02:00
data-slot="table"
2025-08-28 18:27:07 +02:00
{...props}
/>
</div>
);
2025-08-04 17:45:44 +02:00
}
function TableHeader({ className, ...props }: React.ComponentProps<"thead">) {
2025-08-28 18:27:07 +02:00
return (
<thead
className={cn("[&_tr]:border-b", className)}
2025-08-29 16:18:32 +02:00
data-slot="table-header"
2025-08-28 18:27:07 +02:00
{...props}
/>
);
2025-08-04 17:45:44 +02:00
}
function TableBody({ className, ...props }: React.ComponentProps<"tbody">) {
2025-08-28 18:27:07 +02:00
return (
<tbody
className={cn("[&_tr:last-child]:border-0", className)}
2025-08-29 16:18:32 +02:00
data-slot="table-body"
2025-08-28 18:27:07 +02:00
{...props}
/>
);
2025-08-04 17:45:44 +02:00
}
function TableFooter({ className, ...props }: React.ComponentProps<"tfoot">) {
2025-08-28 18:27:07 +02:00
return (
<tfoot
className={cn(
2025-10-10 16:18:43 +02:00
"border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",
2025-08-28 18:27:07 +02:00
className,
)}
2025-08-29 16:18:32 +02:00
data-slot="table-footer"
2025-08-28 18:27:07 +02:00
{...props}
/>
);
2025-08-04 17:45:44 +02:00
}
function TableRow({ className, ...props }: React.ComponentProps<"tr">) {
2025-08-28 18:27:07 +02:00
return (
<tr
className={cn(
2025-10-10 16:18:43 +02:00
"border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",
2025-08-28 18:27:07 +02:00
className,
)}
2025-08-29 16:18:32 +02:00
data-slot="table-row"
2025-08-28 18:27:07 +02:00
{...props}
/>
);
2025-08-04 17:45:44 +02:00
}
function TableHead({ className, ...props }: React.ComponentProps<"th">) {
2025-08-28 18:27:07 +02:00
return (
<th
className={cn(
2025-10-10 16:18:43 +02:00
"h-10 whitespace-nowrap px-2 text-left align-middle font-medium text-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
2025-08-28 18:27:07 +02:00
className,
)}
2025-08-29 16:18:32 +02:00
data-slot="table-head"
2025-08-28 18:27:07 +02:00
{...props}
/>
);
2025-08-04 17:45:44 +02:00
}
function TableCell({ className, ...props }: React.ComponentProps<"td">) {
2025-08-28 18:27:07 +02:00
return (
<td
className={cn(
2025-10-10 16:18:43 +02:00
"whitespace-nowrap p-2 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
2025-08-28 18:27:07 +02:00
className,
)}
2025-08-29 16:18:32 +02:00
data-slot="table-cell"
2025-08-28 18:27:07 +02:00
{...props}
/>
);
2025-08-04 17:45:44 +02:00
}
function TableCaption({
2025-08-28 18:27:07 +02:00
className,
...props
2025-08-04 17:45:44 +02:00
}: React.ComponentProps<"caption">) {
2025-08-28 18:27:07 +02:00
return (
<caption
2025-10-10 16:18:43 +02:00
className={cn("mt-4 text-muted-foreground text-sm", className)}
2025-08-29 16:18:32 +02:00
data-slot="table-caption"
2025-08-28 18:27:07 +02:00
{...props}
/>
);
2025-08-04 17:45:44 +02:00
}
export {
2025-08-28 18:27:07 +02:00
Table,
TableHeader,
TableBody,
TableFooter,
TableHead,
TableRow,
TableCell,
TableCaption,
};