Table
Data table: toolbar slot, sortable columns, row selection, custom cells, empty state, footer.
Code
import * as React from 'react';
import { Avatar, Badge, Button, Chip, Pagination, SearchField, Table } from '@fruit-labs/design';
export default function Demo() {
return (function () {
const tone = {
Active: 'success',
Review: 'warning',
Blocked: 'danger',
Draft: 'neutral',
};
const rows = [
{
id: 1,
name: 'Website refresh',
owner: 'Ada Lovelace',
status: 'Active',
progress: 72,
},
{
id: 2,
name: 'Mobile onboarding',
owner: 'Marco Kim',
status: 'Review',
progress: 90,
},
{
id: 3,
name: 'Billing migration',
owner: 'Jia Song',
status: 'Blocked',
progress: 35,
},
{
id: 4,
name: 'Help center',
owner: 'Rosa Torres',
status: 'Draft',
progress: 10,
},
];
return (
<Table
caption="Projects"
selectable
rows={rows}
toolbar={
<>
<SearchField
placeholder="Search projects"
style={{
width: 240,
}}
/>
<Chip variant="dashed" icon="plus">
Status
</Chip>
<span
style={{
flex: 1,
}}
/>
<Button icon="plus">New project</Button>
</>
}
columns={[
{
key: 'name',
header: 'Project',
sortable: true,
render: (r) => <b>{r.name}</b>,
},
{
key: 'owner',
header: 'Owner',
render: (r) => (
<span
style={{
display: 'inline-flex',
gap: 10,
alignItems: 'center',
}}
>
<Avatar name={r.owner} size={26} />
{r.owner}
</span>
),
},
{
key: 'status',
header: 'Status',
render: (r) => (
<Badge tone={tone[r.status]} dot>
{r.status}
</Badge>
),
},
{
key: 'progress',
header: 'Progress',
sortable: true,
align: 'right',
render: (r) => r.progress + '%',
},
]}
footer={
<>
<span>Showing 1–4 of 28</span>
<Pagination pageCount={7} label="Projects pages" />
</>
}
/>
);
})();
}Selectable and sortable
import { Table } from '@fruit-labs/design';
export default function Example() {
return (
<div style={{ display: 'flex', flexDirection: 'column', gap: 12, maxWidth: 560 }}>
<Table
caption="Team"
selectable
rowKey="id"
columns={[{ key: 'name', header: 'Name', sortable: true }, { key: 'role', header: 'Role' }]}
rows={[{ id: 1, name: 'Ada', role: 'Owner' }, { id: 2, name: 'Marco', role: 'Editor' }]}
/>
</div>
);
}Install
From npm:
npm install @fruit-labs/design
import { Table } from '@fruit-labs/design';Or copy the TypeScript source into your project:
npx shadcn@latest add https://design.fruitlabs.online/r/table.jsonGuidelines
- Rows 56 (
density="compact"40). Right-align numbers (align: 'right'). - Put search, filter chips and bulk actions in
toolbar; put Pagination infooter. - Wide tables scroll horizontally inside the frame.
Props
| Prop | Type | Required |
|---|---|---|
columns | Array<{ key: string; header: React.ReactNode; render?: (row: any) => React.ReactNode; sortable?: boolean; sortValue?: (row: any) => any; width?: number | string; align?: 'left' | 'right' | 'center' }> | Yes |
rows | any[] | Yes |
rowKey | string | No |
selectable | boolean | No |
selected | any[] | No |
onSelectionChange | (ids: any[]) => void | No |
onRowClick | (row: any) => void | No |
defaultSort | { key: string; dir: 'asc' | 'desc' } | null | No |
density | 'default' | 'compact' | No |
toolbar | React.ReactNode | No |
footer | React.ReactNode | No |
empty | React.ReactNode | No |
caption | string | No |
className | string | No |
style | React.CSSProperties | No |