Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
import { useState } from "react";
import type { Meta, StoryObj } from "@storybook/react-vite";
import {
BoxIcon as ProjectIcon,
ChevronDownIcon,
CopyIcon,
EditIcon,
MoreHorizontalIcon,
TrashIcon
} from "lucide-react";
import {
Badge,
Button,
Checkbox,
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
IconButton,
Pagination,
RowLink
} from "@app/components/v3/generic";
import { cn } from "../../utils";
import {
Table,
TableAttachedFooter,
TableBody,
TableCaption,
TableCell,
TableFooter,
TableHead,
TableHeader,
TableRow,
TableSkeletonRows,
type TableSortDirection,
TableVirtualBody
} from "./Table";
type Identity = {
name: string;
role: string;
managedBy?: { scope: "org" | "namespace"; name: string };
};
const identities: Identity[] = [
{
name: "machine-one",
role: "Admin",
managedBy: { scope: "org", name: "infisical" }
},
{
name: "machine-two",
role: "Viewer",
managedBy: { scope: "namespace", name: "engineering" }
},
{ name: "machine-three", role: "Member" },
{
name: "machine-four",
role: "Admin",
managedBy: { scope: "namespace", name: "dev-ops" }
},
{
name: "machine-five",
role: "Viewer",
managedBy: { scope: "org", name: "infisical" }
},
{ name: "machine-six", role: "Member" }
];
/**
* `Table` is the v3 data-table primitive — native `<table>` markup wrapped in a
* bordered, scrollable container. Compose it from `Table` (root) → `TableHeader`
* (with one `TableRow` of `TableHead`s) → `TableBody` (with one `TableRow` of
* `TableCell`s per data row), plus optional `TableFooter` for summary rows and
* `TableCaption` for an accessible description.
*
* **Always render a `Table` inside a `Card`, `Dialog`, or `Sheet`.** Tables sit
* on a chrome surface, never bare on the page background — that's how a
* settings section, a modal flow, or a slide-over panel reads as a contained
* unit. (The stories below render the table on its own purely so the component
* is the focus.)
*
* **For the empty case, use the `Empty` component above the table** (set
* `className="border"` to activate its dashed frame). Don't render an empty
* `Table` with a "No rows" cell — `Empty` is the v3-sanctioned empty state with
* icon, title, description, and call-to-action slots.
*
* Reach for `Table` for tabular data with a known schema — members, identities,
* audit logs, secret diffs, integration runs. For long lists with no grid
* structure, a `<ul>` of `Item`s is usually a better fit.
*
* Useful per-cell flags:
* - **`sticky`** on `TableHeader` pins the header while scrolling a table
* with a height-constrained container (`containerClassName="max-h-40"`).
* - **`isTruncatable`** on `TableHead` / `TableCell` clips long content with
* ellipsis instead of letting the column blow out the row width.
* - **`isWrappable`** on `TableCell` wraps long text (descriptions, paths,
* error messages) onto more lines within a bounded column width
* (`max-w-md`, overridable through `className`). Set it on every cell of
* the column.
* - **`isTopAligned`** on `TableCell` aligns content to the top of the row
* instead of the middle, for rows whose cells can grow to different heights
* (editable multi-line values, inline validation errors). Set it on every
* cell of the row so their first lines stay level.
*
* While rows load, render `TableSkeletonRows` inside `TableBody` with the
* table's column count (and an optional `rows` count, default 3) instead of
* hand-rolling skeleton cells.
* - **`data-state="selected"`** on a `TableRow` paints the selected highlight
* for row-checkbox patterns.
* - **`onSortChange`** on `TableHead` renders an accessible, full-cell sort button.
* Control it with `sortDirection`; each activation cycles none → ascending →
* descending → none.
*
* For datasets that don't fit on a single screen, pair the `Table` with the
* `Pagination` component as a sibling below it — see *Example: With
* Pagination*.
*
* Anchor the table on the start edge. Extra column width grows toward the end
* and scrolls inside the bordered container; do not center the table so it
* grows both ways. Stories use `layout: "padded"` for that reason.
*/
const meta = {
title: "Generic/Table",
component: Table,
parameters: {
layout: "padded"
},
tags: ["autodocs"],
decorators: [
(Story) => (
<div className="ms-0 w-full max-w-3xl min-w-0">
<Story />
</div>
)
]
} satisfies Meta<typeof Table>;
export default meta;
type Story = StoryObj<typeof meta>;
export const Default: Story = {
name: "Anatomy: Default",
parameters: {
docs: {
description: {
story:
"The baseline — `Table` wraps a `TableHeader` (one row of `TableHead`s) and a `TableBody` (one `TableRow` per data row). The bordered container and horizontal scroll behavior are built in, so a bare table is already a finished surface."
}
}
},
render: () => (
<Table>
<TableHeader>
<TableRow>
<TableHead>Name</TableHead>
<TableHead>Role</TableHead>
<TableHead>Status</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{identities.slice(0, 4).map((id) => (
<TableRow key={id.name}>
<TableCell className="font-medium">{id.name}</TableCell>
<TableCell>{id.role}</TableCell>
<TableCell>
<Badge variant="success">Active</Badge>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
)
};
export const StickyHeader: Story = {
name: "Example: Sticky Header",
parameters: {
docs: {
description: {
story:
"Set `sticky` on `TableHeader` and constrain the table container height with `containerClassName`. The header stays visible while the rows scroll; by default, headers are not sticky."
}
}
},
render: () => (
<Table containerClassName="max-h-40">
<TableHeader sticky>
<TableRow>
<TableHead>Name</TableHead>
<TableHead>Role</TableHead>
<TableHead>Status</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{identities.map((id) => (
<TableRow key={id.name}>
<TableCell className="font-medium">{id.name}</TableCell>
<TableCell>{id.role}</TableCell>
<TableCell>
<Badge variant="success">Active</Badge>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
)
};
const virtualizedRows = Array.from({ length: 10000 }, (_, i) => ({
key: `SECRET_KEY_${String(i + 1).padStart(5, "0")}`,
value: `value-${i + 1}`
}));
export const Virtualized: Story = {
name: "Example: Virtualized Rows",
parameters: {
docs: {
description: {
story:
"Use `TableVirtualBody` in place of `TableBody` when a table can render thousands of rows. Only the rows in view are mounted. Constrain the container height with `containerClassName`, and spread the `rowProps` from the render function onto each `TableRow` so rows of varying height are measured. Give columns fixed widths (`table-fixed`, or fixed or truncated cell widths) so they don't resize as rows mount while scrolling."
}
}
},
render: () => (
<Table className="w-full table-fixed" containerClassName="max-h-80 overflow-y-auto">
<TableHeader sticky>
<TableRow>
<TableHead>Key</TableHead>
<TableHead>Value</TableHead>
</TableRow>
</TableHeader>
<TableVirtualBody count={virtualizedRows.length}>
{(index, rowProps) => {
const row = virtualizedRows[index];
return (
<TableRow key={row.key} {...rowProps}>
<TableCell className="font-mono text-xs">{row.key}</TableCell>
<TableCell className="font-mono text-xs">{row.value}</TableCell>
</TableRow>
);
}}
</TableVirtualBody>
</Table>
)
};
export const WithCaption: Story = {
name: "Anatomy: With Caption",
parameters: {
docs: {
description: {
story:
"`TableCaption` renders a screen-reader-accessible description below the table. Use it whenever the table needs context that isn't carried by the column headers — what the rows represent, the time window, the filter that produced them."
}
}
},
render: () => (
<Table>
<TableCaption>Identities created in the last 30 days.</TableCaption>
<TableHeader>
<TableRow>
<TableHead>Name</TableHead>
<TableHead>Role</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{identities.slice(0, 3).map((id) => (
<TableRow key={id.name}>
<TableCell className="font-medium">{id.name}</TableCell>
<TableCell>{id.role}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
)
};
export const WithFooter: Story = {
name: "Anatomy: With Footer",
parameters: {
docs: {
description: {
story:
"`TableFooter` renders a summary row (totals, counts, aggregates) below the body, separated by its own top border. Use a single `TableRow` inside; `colSpan` whatever cells you want to merge for the summary label."
}
}
},
render: () => (
<Table>
<TableHeader>
<TableRow>
<TableHead>Project</TableHead>
<TableHead>Active secrets</TableHead>
<TableHead className="text-right">Reads (30d)</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{[
{ name: "infra", secrets: 142, reads: 18430 },
{ name: "api", secrets: 87, reads: 9622 },
{ name: "frontend", secrets: 24, reads: 3014 }
].map((p) => (
<TableRow key={p.name}>
<TableCell className="font-medium">{p.name}</TableCell>
<TableCell>{p.secrets}</TableCell>
<TableCell className="text-right">{p.reads.toLocaleString()}</TableCell>
</TableRow>
))}
</TableBody>
<TableFooter>
<TableRow>
<TableCell className="font-medium">Total</TableCell>
<TableCell>253</TableCell>
<TableCell className="text-right">31,066</TableCell>
</TableRow>
</TableFooter>
</Table>
)
};
function AttachedFooterRender() {
const [hasMore, setHasMore] = useState(true);
const [isLoading, setIsLoading] = useState(false);
return (
<div>
<Table hasAttachedFooter>
<TableHeader>
<TableRow>
<TableHead>Event</TableHead>
<TableHead>Timestamp</TableHead>
</TableRow>
</TableHeader>
<TableBody>
<TableRow>
<TableCell>Secret read</TableCell>
<TableCell>Today</TableCell>
</TableRow>
</TableBody>
</Table>
<TableAttachedFooter>
{hasMore ? (
<Button
variant="ghost"
size="lg"
isFullWidth
isPending={isLoading}
onClick={() => {
setIsLoading(true);
window.setTimeout(() => {
setIsLoading(false);
setHasMore(false);
}, 1000);
}}
>
Load More
</Button>
) : (
<span className="text-xs text-muted">End of logs</span>
)}
</TableAttachedFooter>
</div>
);
}
export const WithAttachedFooter: Story = {
name: "Example: With Attached Footer",
parameters: {
docs: {
description: {
story:
"Use `TableAttachedFooter` as a sibling after `Table` for a full-width load-more action or a completion message. Set `hasAttachedFooter` on `Table` to join their borders; unlike `TableFooter`, this action stays outside the table's horizontal scroll area."
}
}
},
render: () => <AttachedFooterRender />
};
export const WithSelection: Story = {
name: "Example: With Selection",
parameters: {
docs: {
description: {
story:
'Set `data-state="selected"` on a `TableRow` to paint the selected highlight — the same hover background, but persistent. Combine with a leading `Checkbox` cell for a row-selection pattern (bulk edit, bulk delete).'
}
}
},
render: () => (
<Table>
<TableHeader>
<TableRow>
<TableHead className="w-10" />
<TableHead>Name</TableHead>
<TableHead>Role</TableHead>
<TableHead>Managed by</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{identities.slice(0, 4).map((id, i) => (
<TableRow key={id.name} data-state={i === 1 ? "selected" : undefined}>
<TableCell>
<Checkbox isChecked={i === 1} aria-label={`Select ${id.name}`} />
</TableCell>
<TableCell className="font-medium">{id.name}</TableCell>
<TableCell>{id.role}</TableCell>
<TableCell>{id.managedBy?.name ?? "—"}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
)
};
type SortableColumn = "managedBy" | "name" | "role";
const SortableHeadersExample = () => {
const [sort, setSort] = useState<{
column: SortableColumn;
direction: Exclude<TableSortDirection, "none">;
} | null>(null);
const getSortDirection = (column: SortableColumn): TableSortDirection =>
sort?.column === column ? sort.direction : "none";
const handleSortChange = (column: SortableColumn, direction: TableSortDirection) => {
setSort(direction === "none" ? null : { column, direction });
};
const getSortIconClassName = (column: SortableColumn) => {
const direction = getSortDirection(column);
return cn(
"transition-transform",
direction === "descending" && "rotate-180",
direction === "none" && "opacity-30"
);
};
const sortedIdentities = identities.slice(0, 4);
if (sort) {
sortedIdentities.sort((a, b) => {
const getValue = (identity: Identity) => {
if (sort.column === "managedBy") return identity.managedBy?.name ?? "";
return identity[sort.column];
};
const comparison = getValue(a).localeCompare(getValue(b));
return sort.direction === "ascending" ? comparison : -comparison;
});
}
return (
<Table>
<TableHeader>
<TableRow>
<TableHead
sortDirection={getSortDirection("name")}
onSortChange={(direction) => handleSortChange("name", direction)}
>
Name
<ChevronDownIcon className={getSortIconClassName("name")} />
</TableHead>
<TableHead
sortDirection={getSortDirection("role")}
onSortChange={(direction) => handleSortChange("role", direction)}
>
Role
<ChevronDownIcon className={getSortIconClassName("role")} />
</TableHead>
<TableHead
sortDirection={getSortDirection("managedBy")}
onSortChange={(direction) => handleSortChange("managedBy", direction)}
>
Managed by
<ChevronDownIcon className={getSortIconClassName("managedBy")} />
</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{sortedIdentities.map((id) => (
<TableRow key={id.name}>
<TableCell className="font-medium">{id.name}</TableCell>
<TableCell>{id.role}</TableCell>
<TableCell>{id.managedBy?.name ?? "—"}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
);
};
export const SortableHeaders: Story = {
name: "Example: Sortable Headers",
parameters: {
docs: {
description: {
story:
"Pass `onSortChange` to render a keyboard-operable, full-cell sort button. Control it with `sortDirection`; each activation cycles from none to ascending, descending, and back to none."
}
}
},
render: () => <SortableHeadersExample />
};
export const TruncatedCells: Story = {
name: "Example: Truncated Cells",
parameters: {
docs: {
description: {
story:
"Pass `isTruncatable` to `TableHead` and `TableCell` for any column that can carry long, single-line content (descriptions, paths, signatures). The column collapses to whatever space the row gives it, with the overflow clipped behind an ellipsis. Pair with the cell's `title` attribute so the full value is hover-discoverable."
}
}
},
render: () => (
<Table>
<TableHeader>
<TableRow>
<TableHead className="w-32">Identity</TableHead>
<TableHead isTruncatable>Description</TableHead>
<TableHead className="w-28">Role</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{[
{
name: "machine-one",
description:
"Long-running CI worker in the infrastructure project, used by automation jobs that publish release artefacts to internal mirrors.",
role: "Admin"
},
{
name: "machine-two",
description:
"Service identity for the engineering namespace's secret rotation job; rotates every Sunday at 02:00 UTC.",
role: "Viewer"
},
{
name: "machine-three",
description: "Standby identity reserved for incident response — do not delete.",
role: "Member"
}
].map((id) => (
<TableRow key={id.name}>
<TableCell className="font-medium">{id.name}</TableCell>
<TableCell isTruncatable title={id.description}>
{id.description}
</TableCell>
<TableCell>{id.role}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
)
};
export const WrappedCells: Story = {
name: "Example: Wrapped Cells",
parameters: {
docs: {
description: {
story:
"Pass `isWrappable` to every `TableCell` of a column whose full text must stay readable, such as descriptions, paths, or error messages. The text wraps within a bounded width (`max-w-md`, overridable through `className`) and long unbroken values break where they need to. Other columns keep the default single-line layout."
}
}
},
render: () => (
<Table>
<TableHeader>
<TableRow>
<TableHead>Scan</TableHead>
<TableHead>Status</TableHead>
<TableHead>Error</TableHead>
<TableHead>Started</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{[
{
id: "scan-1",
status: "Failed",
error:
"Could not clone repository: the GitHub App installation lacks read access to the contents of this repository.",
started: "Oct 12, 2026 09:14"
},
{
id: "scan-2",
status: "Failed",
error:
"File too large to scan: /services/payments/fixtures/generated/large-transaction-export-2026-10-01.json",
started: "Oct 11, 2026 22:40"
},
{ id: "scan-3", status: "Completed", error: "None", started: "Oct 11, 2026 08:02" }
].map((scan) => (
<TableRow key={scan.id}>
<TableCell className="font-medium">{scan.id}</TableCell>
<TableCell>{scan.status}</TableCell>
<TableCell isWrappable>{scan.error}</TableCell>
<TableCell>{scan.started}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
)
};
export const LoadingRows: Story = {
name: "Example: Loading Rows",
parameters: {
docs: {
description: {
story:
"While the first page of data loads, render `TableSkeletonRows` inside `TableBody` with the number of columns in the header. `rows` defaults to 3."
}
}
},
render: () => (
<Table>
<TableHeader>
<TableRow>
<TableHead>Name</TableHead>
<TableHead>Role</TableHead>
<TableHead>Managed By</TableHead>
<TableHead variant="action" />
</TableRow>
</TableHeader>
<TableBody>
<TableSkeletonRows columns={4} />
</TableBody>
</Table>
)
};
export const WithActions: Story = {
name: "Example: With Actions",
parameters: {
docs: {
description: {
story:
"Trailing `DropdownMenu` triggered by an `IconButton` is the canonical row-action pattern. Mark the empty header and each trailing action cell with `variant=action`; the shared table primitives preserve flexible column sizing and align the controls to the trailing edge."
}
}
},
render: () => (
<Table>
<TableHeader>
<TableRow>
<TableHead>Name</TableHead>
<TableHead>Role</TableHead>
<TableHead variant="action" />
</TableRow>
</TableHeader>
<TableBody>
{identities.slice(0, 4).map((id) => (
<TableRow key={id.name}>
<TableCell className="font-medium">{id.name}</TableCell>
<TableCell>{id.role}</TableCell>
<TableCell variant="action">
<DropdownMenu>
<DropdownMenuTrigger asChild>
<IconButton variant="ghost" size="xs" aria-label={`${id.name} actions`}>
<MoreHorizontalIcon />
</IconButton>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-36">
<DropdownMenuItem>
<CopyIcon />
Copy ID
</DropdownMenuItem>
<DropdownMenuItem>
<EditIcon />
Edit identity
</DropdownMenuItem>
<DropdownMenuItem variant="danger">
<TrashIcon />
Delete identity
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
)
};
export const LinkedRows: Story = {
name: "Example: Linked Rows",
parameters: {
docs: {
description: {
story:
"For rows that open a detail page, set `linked` on the row and render a `RowLink` in its main cell. The link's overlay covers the row, so a plain click, cmd/ctrl+click, middle-click and right-click \"Open link in new tab\" all work. Buttons, inputs, selects, checkboxes, other links, tooltip triggers and `variant=action` cells are lifted above the overlay automatically; mark any other control (a badge used as a tooltip anchor) with `data-row-interactive`. `RowLink disabled` renders plain text for rows the user cannot open (the last row here); leave `linked` off for that row too. To keep a whole cell clickable for its own controls, including the padding around them, put `data-row-interactive` on the cell. `Card` takes the same `linked` prop, and `CommandItemLink` covers `CommandItem` rows. Never navigate from a row's `onClick`."
}
}
},
render: () => (
<Table>
<TableHeader>
<TableRow>
<TableHead>Name</TableHead>
<TableHead>Role</TableHead>
<TableHead variant="action" />
</TableRow>
</TableHeader>
<TableBody>
{identities.slice(0, 4).map((id, index) => (
<TableRow key={id.name} linked={index !== 3}>
<TableCell isTruncatable>
<RowLink to="." disabled={index === 3}>
{id.name}
</RowLink>
</TableCell>
<TableCell>{id.role}</TableCell>
<TableCell variant="action">
<DropdownMenu>
<DropdownMenuTrigger asChild>
<IconButton variant="ghost" size="xs" aria-label={`${id.name} actions`}>
<MoreHorizontalIcon />
</IconButton>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-36">
<DropdownMenuItem>
<CopyIcon />
Copy ID
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
)
};
function PaginationRender() {
const [page, setPage] = useState(1);
const [perPage, setPerPage] = useState(10);
const TOTAL = 142;
const start = (page - 1) * perPage;
const rowCount = Math.min(perPage, TOTAL - start);
const roleFor = (idx: number) => {
if (idx % 5 === 0) return "Admin";
if (idx % 3 === 0) return "Viewer";
return "Member";
};
const rows = Array.from({ length: rowCount }, (_, i) => {
const idx = start + i + 1;
return { name: `machine-${String(idx).padStart(3, "0")}`, role: roleFor(idx) };
});
return (
<>
<Table>
<TableHeader>
<TableRow>
<TableHead className="w-1/2">Name</TableHead>
<TableHead>Role</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{rows.map((row) => (
<TableRow key={row.name}>
<TableCell className="font-medium">{row.name}</TableCell>
<TableCell>{row.role}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
<Pagination
count={TOTAL}
page={page}
perPage={perPage}
onChangePage={setPage}
onChangePerPage={(next) => {
setPerPage(next);
setPage(1);
}}
/>
</>
);
}
export const WithPagination: Story = {
name: "Example: With Pagination",
parameters: {
docs: {
description: {
story:
"Render `Pagination` as a sibling directly below the `Table`. The component handles the page / per-page controls and emits `onChangePage` / `onChangePerPage` — you supply the `count` of total rows and slice the dataset before rendering. This is the canonical pattern for any list that doesn't fit on a single screen."
}
}
},
render: () => <PaginationRender />
};
export const KitchenSink: Story = {
name: "Example: Kitchen Sink",
parameters: {
docs: {
description: {
story:
"A realistic identities table — a status `Badge`, a managed-by `Badge` with a `ProjectIcon`, and per-row actions in a trailing `DropdownMenu`. The composition you reach for on most management screens."
}
}
},
render: () => (
<Table>
<TableHeader>
<TableRow>
<TableHead className="w-1/3">Name</TableHead>
<TableHead className="w-1/3">Role</TableHead>
<TableHead className="w-1/3">Managed By</TableHead>
<TableHead variant="action" />
</TableRow>
</TableHeader>
<TableBody>
{identities.map((id) => (
<TableRow key={id.name}>
<TableCell className="font-medium">{id.name}</TableCell>
<TableCell>{id.role}</TableCell>
<TableCell>
<Badge variant="project">
<ProjectIcon />
Project
</Badge>
</TableCell>
<TableCell variant="action">
<DropdownMenu>
<DropdownMenuTrigger asChild>
<IconButton variant="ghost" size="xs" aria-label={`${id.name} actions`}>
<MoreHorizontalIcon />
</IconButton>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-36">
<DropdownMenuItem>
<CopyIcon />
Copy ID
</DropdownMenuItem>
<DropdownMenuItem>
<EditIcon />
Edit Identity
</DropdownMenuItem>
<DropdownMenuItem variant="danger">
<TrashIcon />
Delete Identity
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
)
};