Canvas: Chip

Chip draws a filled pill with optional close button. Supports color, backgroundColor, borderRadius, closable.

Preset:
closable:

Grid API

Event Log

Click, double-click, or hover over Chip cells to see events.

No events yet

Code

import { Grid, createColumnHelper, Chip } from "@ohah/react-wasm-table";

const helper = createColumnHelper<{ dept: string }>();

const columns = [
  helper.accessor("dept", {
    header: "Chip",
    size: 200,
    cell: (info) => (
      <Chip
        value={info.getValue()}
        color="#fff"
        backgroundColor="#1976d2"
        closable
        onClick={(e) => console.log("chip clicked", info.getValue())}
      />
    ),
  }),
];

<Grid data={data} columns={columns} width={360} height={460} rowHeight={40} />;

Table API Code

import {
  Table,
  useReactTable,
  flexRender,
  getCoreRowModel,
  Thead,
  Tbody,
  Tr,
  Th,
  Td,
  createColumnHelper,
  Chip,
} from "@ohah/react-wasm-table";

const helper = createColumnHelper<{ dept: string }>();

const columns = [
  helper.accessor("dept", {
    header: "Chip",
    size: 200,
    cell: (info) => (
      <Chip
        value={info.getValue()}
        color="#fff"
        backgroundColor="#1976d2"
        closable
        onClick={(e) => console.log("chip clicked", info.getValue())}
      />
    ),
  }),
];

const table = useReactTable({ data, columns, getCoreRowModel: getCoreRowModel() });

<Table table={table} width={360} height={460} rowHeight={40}>
  <Thead>
    {table.getHeaderGroups().map((hg) => (
      <Tr key={hg.id}>
        {hg.headers.map((h) => (
          <Th key={h.id} colSpan={h.colSpan}>
            {h.isPlaceholder ? null : flexRender(h.column.columnDef.header, h.getContext())}
          </Th>
        ))}
      </Tr>
    ))}
  </Thead>
  <Tbody>
    {table.getRowModel().rows.map((row) => (
      <Tr key={row.id}>
        {row.getVisibleCells().map((cell) => (
          <Td key={cell.id}>{flexRender(cell.column.columnDef.cell, cell.getContext())}</Td>
        ))}
      </Tr>
    ))}
  </Tbody>
</Table>;