Canvas: Text

Text draws a single line. Supports style and individual props color, fontWeight, fontSize.

color:
fontSize:
fontWeight:

Grid API

Code

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

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

const columns = [
  helper.accessor("name", {
    header: "Text",
    size: 220,
    cell: (info) => (
      <Text value={info.getValue()} color="#1a1a1a" fontSize={13} fontWeight="bold" />
    ),
  }),
];

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

Table API Code

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

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

const columns = [
  helper.accessor("name", {
    header: "Text",
    size: 220,
    cell: (info) => (
      <Text value={info.getValue()} color="#1a1a1a" fontSize={13} fontWeight="bold" />
    ),
  }),
];

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

<Table table={table} width={380} 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>;