Canvas: Badge
Badge draws a pill/chip. Supports style and individual props color, backgroundColor, borderRadius.
Preset:
borderRadius:
Grid API
#Code
import { Grid, createColumnHelper, Badge } from "@ohah/react-wasm-table";
const helper = createColumnHelper<{ dept: string }>();
const columns = [
helper.accessor("dept", {
header: "Badge",
size: 200,
cell: (info) => (
<Badge value={info.getValue()} color="#2e7d32" backgroundColor="#e8f5e9" borderRadius={6} />
),
}),
];
<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,
Badge,
} from "@ohah/react-wasm-table";
const helper = createColumnHelper<{ dept: string }>();
const columns = [
helper.accessor("dept", {
header: "Badge",
size: 200,
cell: (info) => (
<Badge value={info.getValue()} color="#2e7d32" backgroundColor="#e8f5e9" borderRadius={6} />
),
}),
];
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>;