Canvas: Color
Color draws a centered square color swatch. Supports borderRadius, borderWidth, borderColor.
borderRadius:
borderWidth:
Grid API
Event Log
Click or hover over Color cells to see events.
No events yet
#Code
import { Grid, createColumnHelper, Color } from "@ohah/react-wasm-table";
const helper = createColumnHelper<{ dept: string }>();
const colors = ["#e53935", "#1e88e5", "#43a047", "#fb8c00"];
const columns = [
helper.accessor("dept", {
header: "Color",
size: 120,
cell: (info) => {
const c = colors[info.getValue().charCodeAt(0) % colors.length]!;
return (
<Color
value={c}
borderRadius={4}
borderWidth={1}
borderColor="#333"
onClick={(e) => console.log("color clicked", c)}
/>
);
},
}),
];
<Grid data={data} columns={columns} width={280} height={460} rowHeight={40} />;#Table API Code
import {
Table,
useReactTable,
flexRender,
getCoreRowModel,
Thead,
Tbody,
Tr,
Th,
Td,
createColumnHelper,
Color,
} from "@ohah/react-wasm-table";
const helper = createColumnHelper<{ dept: string }>();
const colors = ["#e53935", "#1e88e5", "#43a047", "#fb8c00"];
const columns = [
helper.accessor("dept", {
header: "Color",
size: 120,
cell: (info) => {
const c = colors[info.getValue().charCodeAt(0) % colors.length]!;
return (
<Color
value={c}
borderRadius={4}
borderWidth={1}
borderColor="#333"
onClick={(e) => console.log("color clicked", c)}
/>
);
},
}),
];
const table = useReactTable({ data, columns, getCoreRowModel: getCoreRowModel() });
<Table table={table} width={280} 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>;