Data
Table
shadcn's Table for glass: hairline rows, fill on hover and selection, muted headers, density-aware cells.
Installation
pnpm dlx shadcn@latest add https://glasscn.app/r/table.jsonOr with the namespace set up: shadcn add @glasscn/table
Parts (shadcn's API): Table, TableHeader, TableBody, TableFooter, TableRow, TableHead, TableCell, TableCaption.
No pane of its own — put it in a Card. Rows take data-state="selected" for the selected fill.
Cell padding scales with --glass-density; numbers use the theme's numerals. Align figures with className="text-right".
Source
components/glass/table.tsx
import * as React from "react"
import { cn } from "cn"
/**
* shadcn's Table on glass. It has no pane of its own — put it inside a Card:
* hairline rows, fill on hover and selection, muted small headers and the
* theme's numerals. Cell padding follows --glass-density.
*
* <Table>
* <TableHeader><TableRow><TableHead>Day</TableHead></TableRow></TableHeader>
* <TableBody><TableRow><TableCell>Monday</TableCell></TableRow></TableBody>
* </Table>
*/
function Table({ className, ...props }: React.ComponentProps<"table">) {
return (
<div data-slot="table-container" className="relative w-full overflow-x-auto">
<table data-slot="table" className={cn("w-full caption-bottom text-sm numeric-glass", className)} {...props} />
</div>
)
}
function TableHeader({ className, ...props }: React.ComponentProps<"thead">) {
return <thead data-slot="table-header" className={cn("[&_tr]:border-b [&_tr]:hover:bg-transparent", className)} {...props} />
}
function TableBody({ className, ...props }: React.ComponentProps<"tbody">) {
return <tbody data-slot="table-body" className={cn("[&_tr:last-child]:border-0", className)} {...props} />
}
function TableFooter({ className, ...props }: React.ComponentProps<"tfoot">) {
return <tfoot data-slot="table-footer" className={cn("border-t border-glass-border bg-fill font-medium [&>tr]:last:border-b-0", className)} {...props} />
}
function TableRow({ className, ...props }: React.ComponentProps<"tr">) {
return (
<tr
data-slot="table-row"
className={cn(
"border-b border-glass-border transition-colors duration-(--glass-duration) ease-glass hover:bg-fill data-[state=selected]:bg-fill data-[state=selected]:hover:bg-fill-strong",
className
)}
{...props}
/>
)
}
function TableHead({ className, ...props }: React.ComponentProps<"th">) {
return (
<th
data-slot="table-head"
className={cn(
"h-[calc(2.5rem*var(--glass-density))] px-[calc(0.75rem*var(--glass-density))] text-left align-middle text-xs font-medium whitespace-nowrap text-muted-foreground [&:has([role=checkbox])]:w-px [&:has([role=checkbox])]:pr-0",
className
)}
{...props}
/>
)
}
function TableCell({ className, ...props }: React.ComponentProps<"td">) {
return (
<td
data-slot="table-cell"
className={cn(
"px-[calc(0.75rem*var(--glass-density))] py-[calc(0.625rem*var(--glass-density))] align-middle whitespace-nowrap [&:has([role=checkbox])]:w-px [&:has([role=checkbox])]:pr-0",
className
)}
{...props}
/>
)
}
function TableCaption({ className, ...props }: React.ComponentProps<"caption">) {
return <caption data-slot="table-caption" className={cn("mt-4 text-sm text-muted-foreground", className)} {...props} />
}
export { Table, TableHeader, TableBody, TableFooter, TableHead, TableRow, TableCell, TableCaption }