2026-07-08 15:02:03 +08:00
|
|
|
import * as React from "react";
|
|
|
|
|
import { cn } from "@/lib/utils";
|
|
|
|
|
|
|
|
|
|
/** 统一表格外观:外层 Card 内使用 */
|
2026-07-11 23:19:59 +08:00
|
|
|
export function Table({
|
|
|
|
|
className,
|
|
|
|
|
striped,
|
|
|
|
|
bordered,
|
|
|
|
|
...props
|
|
|
|
|
}: React.TableHTMLAttributes<HTMLTableElement> & {
|
|
|
|
|
striped?: boolean;
|
|
|
|
|
bordered?: boolean;
|
|
|
|
|
}) {
|
2026-07-08 15:02:03 +08:00
|
|
|
return (
|
|
|
|
|
<div className="w-full overflow-x-auto">
|
2026-07-11 23:19:59 +08:00
|
|
|
<table
|
|
|
|
|
className={cn(
|
|
|
|
|
"w-full text-sm",
|
|
|
|
|
bordered &&
|
|
|
|
|
"border border-[var(--color-border)] [&_tr]:divide-x [&_tr]:divide-[var(--color-border)]",
|
|
|
|
|
striped && "[&_tbody_tr:nth-child(even)]:bg-[var(--color-muted)]/50",
|
|
|
|
|
className
|
|
|
|
|
)}
|
|
|
|
|
{...props}
|
|
|
|
|
/>
|
2026-07-08 15:02:03 +08:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function THead(props: React.HTMLAttributes<HTMLTableSectionElement>) {
|
|
|
|
|
return (
|
|
|
|
|
<thead
|
|
|
|
|
className="bg-[var(--color-muted)] text-left text-xs uppercase tracking-wide text-[var(--color-muted-foreground)]"
|
|
|
|
|
{...props}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function TR({ className, ...props }: React.HTMLAttributes<HTMLTableRowElement>) {
|
|
|
|
|
return (
|
|
|
|
|
<tr
|
|
|
|
|
className={cn("border-b last:border-0 hover:bg-[var(--color-muted)]/60", className)}
|
|
|
|
|
{...props}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function TH({ className, ...props }: React.ThHTMLAttributes<HTMLTableCellElement>) {
|
|
|
|
|
return <th className={cn("px-4 py-3 font-medium", className)} {...props} />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function TD({ className, ...props }: React.TdHTMLAttributes<HTMLTableCellElement>) {
|
|
|
|
|
return <td className={cn("px-4 py-3 align-middle", className)} {...props} />;
|
|
|
|
|
}
|