Table
Name | Status | |
---|---|---|
Ada Lovelace | [email protected] | Active |
Grace Hopper | [email protected] | Inactive |
Total: 2 users |
---import { Table, TableHeader, TableHead, TableBody, TableRow, TableCell, TableCaption, TableFoot } from "@/components/starwind/table";---
<Table class="max-w-md mx-auto"> <TableCaption>Example of a simple table</TableCaption> <TableHeader> <TableRow> <TableHead>Name</TableHead> <TableHead>Email</TableHead> <TableHead>Status</TableHead> </TableRow> </TableHeader> <TableBody> <TableRow> <TableCell>Ada Lovelace</TableCell> <TableCell>Active</TableCell> </TableRow> <TableRow> <TableCell>Grace Hopper</TableCell> <TableCell>Inactive</TableCell> </TableRow> </TableBody> <TableFoot> <TableRow> <TableCell colSpan="3">Total: 2 users</TableCell> </TableRow> </TableFoot></Table>
Installation
pnpx starwind@latest add table
npx starwind@latest add table
yarn dlx starwind@latest add table
Usage
Dynamic Data Table Example
Render a table of recent orders using Astro frontmatter and Starwind UI Table components:
Order | Status | Customer | Total |
---|---|---|---|
ORD1001 | Shipped | Alice Smith | $120.00 |
ORD1002 | Processing | Bob Johnson | $80.00 |
ORD1003 | Delivered | Charlie Rose | $200.00 |
ORD1004 | Cancelled | Dana Lee | $50.00 |
Total Orders | $450.00 |
---const orders = [ { order: "ORD1001", status: "Shipped", total: "$120.00", customer: "Alice Smith" }, { order: "ORD1002", status: "Processing", total: "$80.00", customer: "Bob Johnson" }, { order: "ORD1003", status: "Delivered", total: "$200.00", customer: "Charlie Rose" }, { order: "ORD1004", status: "Cancelled", total: "$50.00", customer: "Dana Lee" },];---<Table> <TableCaption>A list of your recent orders.</TableCaption> <TableHeader> <TableRow> <TableHead class="w-[120px]">Order</TableHead> <TableHead>Status</TableHead> <TableHead>Customer</TableHead> <TableHead class="text-right">Total</TableHead> </TableRow> </TableHeader> <TableBody> {orders.map(order => ( <TableRow> <TableCell class="font-medium">{order.order}</TableCell> <TableCell>{order.status}</TableCell> <TableCell>{order.customer}</TableCell> <TableCell class="text-right">{order.total}</TableCell> </TableRow> ))} </TableBody> <TableFoot> <TableRow> <TableCell colSpan="3">Total Orders</TableCell> <TableCell class="text-right">$450.00</TableCell> </TableRow> </TableFoot></Table>
API Reference
Table
The root table component. Renders a <table>
inside a scrollable <div>
. Accepts all standard HTML <table>
attributes and a class
prop for Tailwind styling.
TableHeader
Wraps <thead>
. Use to group header rows.
TableHead
Wraps <th>
. Use for column headers. Has role="columnheader"
and appropriate styles.
TableBody
Wraps <tbody>
. Use for the main data rows.
TableRow
Wraps <tr>
. Use for each row. Has role="row"
and hover/selected states.
TableCell
Wraps <td>
. Use for data cells.
TableCaption
Wraps <caption>
. Use for table captions. Useful for accessibility.
TableFoot
Wraps <tfoot>
. Use for table footers or summary rows.
Changelog
v1.0.0
- Initial component release with starwind v1.6.0