# Table

<FrameworkCodeSwitcher>
  <div slot="astro">
```astro
---
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>ada@starwind.dev</TableCell>
      <TableCell>Active</TableCell>
    </TableRow>
    <TableRow>
      <TableCell>Grace Hopper</TableCell>
      <TableCell>grace@starwind.dev</TableCell>
      <TableCell>Inactive</TableCell>
    </TableRow>
  </TableBody>
  <TableFoot>
    <TableRow>
      <TableCell colspan="3">Total: 2 users</TableCell>
    </TableRow>
  </TableFoot>
</Table>
```
  </div>
  <div slot="react">
```tsx
import { Table, TableHeader, TableHead, TableBody, TableRow, TableCell, TableCaption, TableFoot } from "@/components/starwind/table";

export function Example() {
  return (
    <>
      <Table className="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>ada@starwind.dev</TableCell>
            <TableCell>Active</TableCell>
          </TableRow>
          <TableRow>
            <TableCell>Grace Hopper</TableCell>
            <TableCell>grace@starwind.dev</TableCell>
            <TableCell>Inactive</TableCell>
          </TableRow>
        </TableBody>
        <TableFoot>
          <TableRow>
            <TableCell colSpan={3}>Total: 2 users</TableCell>
          </TableRow>
        </TableFoot>
      </Table>
    </>
  );
}
```
  </div>
  <div slot="vue">
```vue
<script setup lang="ts">
import {
  Table,
  TableHeader,
  TableHead,
  TableBody,
  TableRow,
  TableCell,
  TableCaption,
  TableFoot,
} from "@/components/starwind/table";
</script>

<template>
  <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>ada@starwind.dev</TableCell>
        <TableCell>Active</TableCell>
      </TableRow>
      <TableRow>
        <TableCell>Grace Hopper</TableCell>
        <TableCell>grace@starwind.dev</TableCell>
        <TableCell>Inactive</TableCell>
      </TableRow>
    </TableBody>
    <TableFoot>
      <TableRow>
        <TableCell colspan="3">Total: 2 users</TableCell>
      </TableRow>
    </TableFoot>
  </Table>
</template>
```
  </div>
</FrameworkCodeSwitcher>

## Installation

```bash
npx starwind@latest add table --framework astro
```
</DocsTabsContent>
```bash
npx starwind@latest add table --framework react
```
</DocsTabsContent>
```bash
npx starwind@latest add table --framework vue
```
</DocsTabsContent>
</DocsTabs>

## Usage

<FrameworkCodeSwitcher>
  <div slot="astro">
```astro
---
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>ada@starwind.dev</TableCell>
      <TableCell>Active</TableCell>
    </TableRow>
    <TableRow>
      <TableCell>Grace Hopper</TableCell>
      <TableCell>grace@starwind.dev</TableCell>
      <TableCell>Inactive</TableCell>
    </TableRow>
  </TableBody>
  <TableFoot>
    <TableRow>
      <TableCell colspan="3">Total: 2 users</TableCell>
    </TableRow>
  </TableFoot>
</Table>
```
  </div>
  <div slot="react">
```tsx
import { Table, TableHeader, TableHead, TableBody, TableRow, TableCell, TableCaption, TableFoot } from "@/components/starwind/table";

export function Example() {
  return (
    <>
      <Table className="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>ada@starwind.dev</TableCell>
            <TableCell>Active</TableCell>
          </TableRow>
          <TableRow>
            <TableCell>Grace Hopper</TableCell>
            <TableCell>grace@starwind.dev</TableCell>
            <TableCell>Inactive</TableCell>
          </TableRow>
        </TableBody>
        <TableFoot>
          <TableRow>
            <TableCell colSpan={3}>Total: 2 users</TableCell>
          </TableRow>
        </TableFoot>
      </Table>
    </>
  );
}
```
  </div>
  <div slot="vue">
```vue
<script setup lang="ts">
import {
  Table,
  TableHeader,
  TableHead,
  TableBody,
  TableRow,
  TableCell,
  TableCaption,
  TableFoot,
} from "@/components/starwind/table";
</script>

<template>
  <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>ada@starwind.dev</TableCell>
        <TableCell>Active</TableCell>
      </TableRow>
      <TableRow>
        <TableCell>Grace Hopper</TableCell>
        <TableCell>grace@starwind.dev</TableCell>
        <TableCell>Inactive</TableCell>
      </TableRow>
    </TableBody>
    <TableFoot>
      <TableRow>
        <TableCell colspan="3">Total: 2 users</TableCell>
      </TableRow>
    </TableFoot>
  </Table>
</template>
```
  </div>
</FrameworkCodeSwitcher>

## Composition

Use semantic table parts in the same order as native table markup:

```text
Table
├── TableCaption
├── TableHeader
│   └── TableRow
│       └── TableHead
├── TableBody
│   └── TableRow
│       └── TableCell
└── TableFoot
    └── TableRow
        └── TableCell
```

## Dynamic Data Table Example

Render a table of recent orders using Astro frontmatter and Starwind UI Table components:

<FrameworkCodeSwitcher>
  <div slot="astro">
```astro
---
import {
  Table,
  TableBody,
  TableCaption,
  TableCell,
  TableFoot,
  TableHead,
  TableHeader,
  TableRow,
} from "@/components/starwind/table";

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>
```
  </div>
  <div slot="react">
```tsx
import { Table, TableBody, TableCaption, TableCell, TableFoot, TableHead, TableHeader, TableRow } from "@/components/starwind/table";

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" },
];

export function Example() {
  return (
    <>
      <Table>
        <TableCaption>A list of your recent orders.</TableCaption>
        <TableHeader>
          <TableRow>
            <TableHead className="w-[120px]">Order</TableHead>
            <TableHead>Status</TableHead>
            <TableHead>Customer</TableHead>
            <TableHead className="text-right">Total</TableHead>
          </TableRow>
        </TableHeader>
        <TableBody>
          {orders.map((order) => (
            <TableRow key={order.order}>
              <TableCell className="font-medium">{order.order}</TableCell>
              <TableCell>{order.status}</TableCell>
              <TableCell>{order.customer}</TableCell>
              <TableCell className="text-right">{order.total}</TableCell>
            </TableRow>
          ))}
        </TableBody>
        <TableFoot>
          <TableRow>
            <TableCell colSpan={3}>Total Orders</TableCell>
            <TableCell className="text-right">$450.00</TableCell>
          </TableRow>
        </TableFoot>
      </Table>
    </>
  );
}
```
  </div>
  <div slot="vue">
```vue
<script setup lang="ts">
import {
  Table,
  TableBody,
  TableCaption,
  TableCell,
  TableFoot,
  TableHead,
  TableHeader,
  TableRow,
} from "@/components/starwind/table";

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" },
];
</script>

<template>
  <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>
      <template v-for="order in orders" :key="order.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>
      </template>
    </TableBody>
    <TableFoot>
      <TableRow>
        <TableCell colspan="3">Total Orders</TableCell>
        <TableCell class="text-right">$450.00</TableCell>
      </TableRow>
    </TableFoot>
  </Table>
</template>
```
  </div>
</FrameworkCodeSwitcher>

## API Reference
### Table
- Inherits table attributes.

### TableHeader
- Inherits thead attributes.

### TableBody
- Inherits tbody attributes.

### TableFoot
- Inherits tfoot attributes.

### TableRow
- Inherits tr attributes.

### TableHead
- Inherits th attributes.

### TableCell
- Inherits td attributes.

### TableCaption
- Inherits caption attributes.

## Changelog

### v1.2.1

- Named the generated aggregate default export so React and Astro tooling can identify the installed component cleanly.

### v1.2.0

- Added contract-generated Astro and React implementations while preserving the component's existing public API and styling.

### v1.1.2

- Refactor tailwind variants functions into separate `variants.ts` file

### v1.1.0

- Add a `data-slot` attribute to all components to enable global styling updates, replacing the current `data-table` and similar attributes.

### v1.0.0

- Initial component release with starwind v1.6.0