Clawscale

HTML table

HTMLTable styles a native table element. Use it for small, static tables. For large or editable data, use the Table package.

Usage#

import { HTMLTable } from "@clawscale/react";
<HTMLTable compact striped>
  <thead>{/* header row */}</thead>
  <tbody>{/* data rows */}</tbody>
</HTMLTable>

Examples#

Basic#

Render thead and tbody as children. Right-align number columns and add the cs-numeric class: it switches to tabular figures, so digits line up.

PipelineRegionRowsErrors
ingest-ordersus-east-11,204,3310
enrich-customerseu-west-188,4123
export-ledgerus-east-114,602,1180
train-forecastap-southeast-2402,99012
import { HTMLTable } from "@clawscale/react";

const RUNS = [
  { pipeline: "ingest-orders", region: "us-east-1", rows: 1204331, errors: 0 },
  { pipeline: "enrich-customers", region: "eu-west-1", rows: 88412, errors: 3 },
  { pipeline: "export-ledger", region: "us-east-1", rows: 14602118, errors: 0 },
  { pipeline: "train-forecast", region: "ap-southeast-2", rows: 402990, errors: 12 },
];

export default function HtmlTableBasic() {
  return (
    <HTMLTable>
      <thead>
        <tr>
          <th>Pipeline</th>
          <th>Region</th>
          <th style={{ textAlign: "right" }}>Rows</th>
          <th style={{ textAlign: "right" }}>Errors</th>
        </tr>
      </thead>
      <tbody>
        {RUNS.map((run) => (
          <tr key={run.pipeline}>
            <td>{run.pipeline}</td>
            <td>{run.region}</td>
            <td className="cs-numeric" style={{ textAlign: "right" }}>
              {run.rows.toLocaleString("en-US")}
            </td>
            <td className="cs-numeric" style={{ textAlign: "right" }}>
              {run.errors}
            </td>
          </tr>
        ))}
      </tbody>
    </HTMLTable>
  );
}

Compact#

compact reduces the cell padding.

PipelineRegionRowsErrors
ingest-ordersus-east-11,204,3310
enrich-customerseu-west-188,4123
export-ledgerus-east-114,602,1180
train-forecastap-southeast-2402,99012
import { HTMLTable } from "@clawscale/react";

const RUNS = [
  { pipeline: "ingest-orders", region: "us-east-1", rows: 1204331, errors: 0 },
  { pipeline: "enrich-customers", region: "eu-west-1", rows: 88412, errors: 3 },
  { pipeline: "export-ledger", region: "us-east-1", rows: 14602118, errors: 0 },
  { pipeline: "train-forecast", region: "ap-southeast-2", rows: 402990, errors: 12 },
];

export default function HtmlTableCompact() {
  return (
    <HTMLTable compact>
      <thead>
        <tr>
          <th>Pipeline</th>
          <th>Region</th>
          <th style={{ textAlign: "right" }}>Rows</th>
          <th style={{ textAlign: "right" }}>Errors</th>
        </tr>
      </thead>
      <tbody>
        {RUNS.map((run) => (
          <tr key={run.pipeline}>
            <td>{run.pipeline}</td>
            <td>{run.region}</td>
            <td className="cs-numeric" style={{ textAlign: "right" }}>
              {run.rows.toLocaleString("en-US")}
            </td>
            <td className="cs-numeric" style={{ textAlign: "right" }}>
              {run.errors}
            </td>
          </tr>
        ))}
      </tbody>
    </HTMLTable>
  );
}

Striped#

striped shades every other row, which helps the eye follow long rows.

PipelineRegionRowsErrors
ingest-ordersus-east-11,204,3310
enrich-customerseu-west-188,4123
export-ledgerus-east-114,602,1180
train-forecastap-southeast-2402,99012
import { HTMLTable } from "@clawscale/react";

const RUNS = [
  { pipeline: "ingest-orders", region: "us-east-1", rows: 1204331, errors: 0 },
  { pipeline: "enrich-customers", region: "eu-west-1", rows: 88412, errors: 3 },
  { pipeline: "export-ledger", region: "us-east-1", rows: 14602118, errors: 0 },
  { pipeline: "train-forecast", region: "ap-southeast-2", rows: 402990, errors: 12 },
];

export default function HtmlTableStriped() {
  return (
    <HTMLTable striped>
      <thead>
        <tr>
          <th>Pipeline</th>
          <th>Region</th>
          <th style={{ textAlign: "right" }}>Rows</th>
          <th style={{ textAlign: "right" }}>Errors</th>
        </tr>
      </thead>
      <tbody>
        {RUNS.map((run) => (
          <tr key={run.pipeline}>
            <td>{run.pipeline}</td>
            <td>{run.region}</td>
            <td className="cs-numeric" style={{ textAlign: "right" }}>
              {run.rows.toLocaleString("en-US")}
            </td>
            <td className="cs-numeric" style={{ textAlign: "right" }}>
              {run.errors}
            </td>
          </tr>
        ))}
      </tbody>
    </HTMLTable>
  );
}

Bordered#

bordered adds lines between columns.

PipelineRegionRowsErrors
ingest-ordersus-east-11,204,3310
enrich-customerseu-west-188,4123
export-ledgerus-east-114,602,1180
train-forecastap-southeast-2402,99012
import { HTMLTable } from "@clawscale/react";

const RUNS = [
  { pipeline: "ingest-orders", region: "us-east-1", rows: 1204331, errors: 0 },
  { pipeline: "enrich-customers", region: "eu-west-1", rows: 88412, errors: 3 },
  { pipeline: "export-ledger", region: "us-east-1", rows: 14602118, errors: 0 },
  { pipeline: "train-forecast", region: "ap-southeast-2", rows: 402990, errors: 12 },
];

export default function HtmlTableBordered() {
  return (
    <HTMLTable bordered>
      <thead>
        <tr>
          <th>Pipeline</th>
          <th>Region</th>
          <th style={{ textAlign: "right" }}>Rows</th>
          <th style={{ textAlign: "right" }}>Errors</th>
        </tr>
      </thead>
      <tbody>
        {RUNS.map((run) => (
          <tr key={run.pipeline}>
            <td>{run.pipeline}</td>
            <td>{run.region}</td>
            <td className="cs-numeric" style={{ textAlign: "right" }}>
              {run.rows.toLocaleString("en-US")}
            </td>
            <td className="cs-numeric" style={{ textAlign: "right" }}>
              {run.errors}
            </td>
          </tr>
        ))}
      </tbody>
    </HTMLTable>
  );
}

Interactive#

interactive highlights the row under the pointer. Use it when rows respond to clicks.

PipelineRegionRowsErrors
ingest-ordersus-east-11,204,3310
enrich-customerseu-west-188,4123
export-ledgerus-east-114,602,1180
train-forecastap-southeast-2402,99012
import { HTMLTable } from "@clawscale/react";

const RUNS = [
  { pipeline: "ingest-orders", region: "us-east-1", rows: 1204331, errors: 0 },
  { pipeline: "enrich-customers", region: "eu-west-1", rows: 88412, errors: 3 },
  { pipeline: "export-ledger", region: "us-east-1", rows: 14602118, errors: 0 },
  { pipeline: "train-forecast", region: "ap-southeast-2", rows: 402990, errors: 12 },
];

export default function HtmlTableInteractive() {
  return (
    <HTMLTable interactive>
      <thead>
        <tr>
          <th>Pipeline</th>
          <th>Region</th>
          <th style={{ textAlign: "right" }}>Rows</th>
          <th style={{ textAlign: "right" }}>Errors</th>
        </tr>
      </thead>
      <tbody>
        {RUNS.map((run) => (
          <tr key={run.pipeline}>
            <td>{run.pipeline}</td>
            <td>{run.region}</td>
            <td className="cs-numeric" style={{ textAlign: "right" }}>
              {run.rows.toLocaleString("en-US")}
            </td>
            <td className="cs-numeric" style={{ textAlign: "right" }}>
              {run.errors}
            </td>
          </tr>
        ))}
      </tbody>
    </HTMLTable>
  );
}

Interactive playground#

PipelineRegionRows
ingest-ordersus-east-11,204,331
enrich-customerseu-west-188,412
export-ledgerus-east-114,602,118
train-forecastap-southeast-2402,990
Props
View source on GitHub

Props interface#

HTMLTable also accepts the HTML attributes of a table.

interface HTMLTableProps extends React.TableHTMLAttributes<HTMLTableElement>, React.RefAttributes<HTMLTableElement>@clawscale/react
PropsDescription
bordered
boolean
Enable borders between rows and cells.
compact
boolean
Use compact appearance with less padding.
interactive
boolean
Enable hover styles on rows.
striped
boolean
Use an alternate background color on odd-numbered rows.