DocsComponentsTemplatesThemesGitHub

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.json

Guidelines

  • Rows 56 (density="compact" 40). Right-align numbers (align: 'right').
  • Put search, filter chips and bulk actions in toolbar; put Pagination in footer.
  • Wide tables scroll horizontally inside the frame.

Props

PropTypeRequired
columnsArray<{ key: string; header: React.ReactNode; render?: (row: any) => React.ReactNode; sortable?: boolean; sortValue?: (row: any) => any; width?: number | string; align?: 'left' | 'right' | 'center' }>Yes
rowsany[]Yes
rowKeystringNo
selectablebooleanNo
selectedany[]No
onSelectionChange(ids: any[]) => voidNo
onRowClick(row: any) => voidNo
defaultSort{ key: string; dir: 'asc' | 'desc' } | nullNo
density'default' | 'compact'No
toolbarReact.ReactNodeNo
footerReact.ReactNodeNo
emptyReact.ReactNodeNo
captionstringNo
classNamestringNo
styleReact.CSSPropertiesNo

Edit this example on GitHub