39 lines
1.5 KiB
TypeScript
39 lines
1.5 KiB
TypeScript
import type { ReactNode } from 'react';
|
|
|
|
interface TableProps {
|
|
headers: ReactNode;
|
|
body: ReactNode;
|
|
footer?: ReactNode;
|
|
/** Extra classes on the `<table>` (e.g. `table-fixed` for equal columns). */
|
|
className?: string;
|
|
}
|
|
|
|
/** Column header cell styling shared by every data table. */
|
|
export const TABLE_HEADER_CELL_CLASS =
|
|
'text-xs font-medium text-text-muted uppercase tracking-wider';
|
|
|
|
/** Shared data table — logical alignment (`text-start` / `text-end`) for LTR and RTL. */
|
|
export function Table({ headers, body, footer, className = '' }: TableProps) {
|
|
return (
|
|
<div className="surface-card overflow-hidden">
|
|
<div className="overflow-x-auto">
|
|
<table
|
|
className={`data-table w-full min-w-[36rem] border-collapse [&_th]:px-3 sm:[&_th]:px-6 [&_th]:py-3 [&_th]:text-start [&_td]:px-3 sm:[&_td]:px-6 [&_td]:py-1.5 [&_td]:text-start [&_th.text-center]:text-center [&_td.text-center]:text-center [&_th.text-end]:text-end [&_td.text-end]:text-end ${className}`.trim()}
|
|
>
|
|
<thead className="bg-background-secondary/70 border-b border-border">
|
|
{headers}
|
|
</thead>
|
|
<tbody className="divide-y divide-border/60">
|
|
{body}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
{footer && (
|
|
<div className="px-3 sm:px-6 py-3 border-t border-border/60 flex flex-col gap-2 sm:flex-row sm:justify-between sm:items-center bg-background-secondary/70">
|
|
{footer}
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|