Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Shadcn Table for React and Tailwind

A responsive table component.

A list of users in your workspace.
NameEmailRoleStatus
Alice Johnson[email protected]Adminactive
Bruno Silva[email protected]Editorinvited
Clara Mendes[email protected]Viewerinactive
David Park[email protected]Editoractive

Installation

bunx --bun shadcn@latest add https://kit.dev/r/table.json

Usage

import { Badge, type BadgeVariant } from "@/components/ui/badge";
import {
  Table,
  TableBody,
  TableCaption,
  TableCell,
  TableHead,
  TableHeader,
  TableRow,
} from "@/components/ui/table";
const TableDemo = () => (
  <Table className="mx-auto w-full max-w-xl">
    <TableCaption>A list of users in your workspace.</TableCaption>
    <TableHeader>
      <TableRow>
        <TableHead>Name</TableHead>
        <TableHead>Email</TableHead>
        <TableHead>Role</TableHead>
        <TableHead className="text-center">Status</TableHead>
      </TableRow>
    </TableHeader>
    <TableBody>
      {users.map((user) => (
        <TableRow key={user.id}>
          <TableCell>{user.name}</TableCell>
          <TableCell>{user.email}</TableCell>
          <TableCell>{user.role}</TableCell>
          <TableCell className="text-center">
            <Badge className="capitalize" variant={statusVariants[user.status]}>
              {user.status}
            </Badge>
          </TableCell>
        </TableRow>
      ))}
    </TableBody>
  </Table>
);

const statusVariants: Record<string, BadgeVariant> = {
  active: "success",
  invited: "info",
  inactive: "destructive",
};

const users = [
  {
    id: "1",
    name: "Alice Johnson",
    email: "[email protected]",
    role: "Admin",
    status: "active",
  },
  {
    id: "2",
    name: "Bruno Silva",
    email: "[email protected]",
    role: "Editor",
    status: "invited",
  },
  {
    id: "3",
    name: "Clara Mendes",
    email: "[email protected]",
    role: "Viewer",
    status: "inactive",
  },
  {
    id: "4",
    name: "David Park",
    email: "[email protected]",
    role: "Editor",
    status: "active",
  },
];

Demos

Action Bar

Actions

Context Menu

Not Hoverable

Striped

API Reference

Table

table

PropType
AttributeType

TableHeader

thead

PropType
AttributeType

TableBody

tbody

PropType
AttributeType

TableFooter

tfoot

PropType
AttributeType

TableRow

tr

PropType
AttributeType

TableHead

th

PropType
AttributeType

TableCell

td

PropType
AttributeType

TableCaption

caption

PropType
AttributeType