Files
liandong-crm/src/components/ui/table.tsx
T

55 lines
1.5 KiB
TypeScript
Raw Normal View History

import * as React from "react";
import { cn } from "@/lib/utils";
/** 统一表格外观:外层 Card 内使用 */
export function Table({
className,
striped,
bordered,
...props
}: React.TableHTMLAttributes<HTMLTableElement> & {
striped?: boolean;
bordered?: boolean;
}) {
return (
<div className="w-full overflow-x-auto">
<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}
/>
</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} />;
}