Table for Astro
Semantic Astro table parts for records and comparisons.
Installation
bunx --bun shadcn@latest add @gnostic/tablenpx shadcn@latest add @gnostic/tablepnpm dlx shadcn@latest add @gnostic/tableCopy the files
src/components/ui/table/index.tssrc/components/ui/table/table-body.astrosrc/components/ui/table/table-caption.astrosrc/components/ui/table/table-cell.astrosrc/components/ui/table/table-footer.astrosrc/components/ui/table/table-head.astrosrc/components/ui/table/table-header.astrosrc/components/ui/table/table-row.astrosrc/components/ui/table/table.astro
Usage
import {
Table,
TableBody,
TableCaption,
TableCell,
TableFooter,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table"
<Table>
<TableCaption>A list of your invoices.</TableCaption>
<TableHeader>
<TableRow>
<TableHead>Invoice</TableHead>
<TableHead>Status</TableHead>
<TableHead>Amount</TableHead>
</TableRow>
</TableHeader>
<TableBody>
<TableRow>
<TableCell>INV-001</TableCell>
<TableCell>Paid</TableCell>
<TableCell>$250.00</TableCell>
</TableRow>
</TableBody>
</Table>
Composition
Arrange the parts as shown for a Table:
Table
├── TableCaption
├── TableHeader
│ └── TableRow
│ ├── TableHead
│ ├── TableHead
│ └── TableHead
├── TableBody
│ └── TableRow
│ ├── TableCell
│ ├── TableCell
│ └── TableCell
└── TableFooter
Notes
- Keep table structure semantic: headers in
TableHeader, rows inTableBody, and summary data inTableFooterwhen needed. - Right-align numeric columns so values are easier to scan.
- Wrap large tables in a container with horizontal overflow when the content may exceed the available width.
Sizes and states
API Reference
Read the installed source for the complete prop types.
When to use Table
Compose TableHeader, TableBody, rows, and cells from your data. Use header cells for column or row names and a caption when it helps identify the data. The wrapper allows horizontal overflow.
Keyboard and behavior
Native table markup preserves the relationship between headers and cells. The component does not add sorting, filtering, row selection, or pagination. Implement those as labelled controls and keep their state clear.
Theme and layout
Use variant="card" for the card table treatment or the default for a page table. Check long cells and narrow-screen overflow. Avoid hiding essential columns only to fit a small screen.