Table
A structured data display component with rows and columns.
<script lang="ts">
import {
Badge,
Table,
TableBody,
TableCaption,
TableCell,
TableFooter,
TableHead,
TableHeader,
TableRow,
} from "coss-svelte";
const projects = [
{
budget: "$12,500",
dot: "bg-emerald-500",
name: "Website Redesign",
status: "Paid",
team: "Frontend Team",
},
{
budget: "$8,750",
dot: "bg-muted-foreground/64",
name: "Mobile App",
status: "Unpaid",
team: "Mobile Team",
},
{
budget: "$5,200",
dot: "bg-amber-500",
name: "API Integration",
status: "Pending",
team: "Backend Team",
},
{
budget: "$3,800",
dot: "bg-emerald-500",
name: "Database Migration",
status: "Paid",
team: "DevOps Team",
},
{
budget: "$7,200",
dot: "bg-emerald-500",
name: "User Dashboard",
status: "Paid",
team: "UX Team",
},
{
budget: "$2,100",
dot: "bg-red-500",
name: "Security Audit",
status: "Failed",
team: "Security Team",
},
];
</script>
<Table>
<TableCaption>A list of current projects.</TableCaption>
<TableHeader>
<TableRow>
<TableHead>Project</TableHead>
<TableHead>Status</TableHead>
<TableHead>Team</TableHead>
<TableHead class="text-right">Budget</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{#each projects as project (project.name)}
<TableRow>
<TableCell class="font-medium">{project.name}</TableCell>
<TableCell>
<Badge variant="outline">
<span aria-hidden="true" class={`size-1.5 rounded-full ${project.dot}`}></span>
{project.status}
</Badge>
</TableCell>
<TableCell>{project.team}</TableCell>
<TableCell class="text-right">{project.budget}</TableCell>
</TableRow>
{/each}
</TableBody>
<TableFooter>
<TableRow>
<TableCell colspan={3}>Total Budget</TableCell>
<TableCell class="text-right">$39,550</TableCell>
</TableRow>
</TableFooter>
</Table>
Installation
Install the component package, shared coss-svelte theme, and Bits UI peer.
npm install coss-svelte @coss-svelte/theme bits-uiUsage
Import the Svelte component exports directly from the package.
import { Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow } from "coss-svelte";Anatomy
- Table
- TableBody
- TableCaption
- TableCell
- TableFooter
- TableHead
- TableHeader
- TableRow
API Reference
Table
A structured data display component with rows and columns.
children : Snippet<[]>Inherits from Svelte <div> attributes.
TableBody
Groups the main rows or body content.
children : Snippet<[]>Inherits from Svelte component attributes.
TableCaption
Provides a caption for the parent component.
children : Snippet<[]>Inherits from Svelte component attributes.
TableCell
Renders one cell within the parent component.
children : Snippet<[]>Inherits from Svelte component attributes.
TableHead
Renders a header cell for a table.
| Prop | Type | Default | Description |
|---|---|---|---|
scope | Scope | "col" | Scope attribute forwarded to the table header cell. |
children : Snippet<[]>Inherits from Svelte <th> attributes.
TableHeader
Groups heading content for the parent component.
children : Snippet<[]>Inherits from Svelte component attributes.
TableRow
Renders one row inside the parent table.
children : Snippet<[]>Inherits from Svelte component attributes.
Implementation Details
- Status
- Stable
- Foundation
- native
- Category
- Content & Display
- Particles
- 8