astro-better-tables

Table components for Astro MDX. TableGrid uses Row and Cell child components. Table uses RST-style nested markdown lists.

Current version: 0.1.1 --npm

Installation

$ npm install astro-better-tables

TableGrid

Use TableGrid with Row and Cell child components. Header rows go in a Row with slot="head".

import TableGrid from 'astro-better-tables/TableGrid.astro';
import Row from 'astro-better-tables/Row.astro';
import Cell from 'astro-better-tables/Cell.astro';

<TableGrid>
  <Row slot="head">
    <Cell header>Name</Cell>
    <Cell header>Type</Cell>
    <Cell header>Description</Cell>
  </Row>
  <Row>
    <Cell>href</Cell>
    <Cell>string</Cell>
    <Cell>The destination URL.</Cell>
  </Row>
  <Row>
    <Cell>title</Cell>
    <Cell>string</Cell>
    <Cell>Card heading text.</Cell>
  </Row>
</TableGrid>

Live example

PackageTypeVersion
astro-better-nav-barcomponent0.1.1
astro-better-stepscomponent0.1.0
astro-toc-smolintegration1.0.0

Multiple header rows

Two Row slot="head" entries build a two-row <thead>. Use colspan on group labels and rowspan on cells that should span both header rows. This lets you group related columns under a shared label, something impossible with standard markdown tables.

<TableGrid widths="3 1 1 1 1">
  <Row slot="head">
    <Cell header rowspan={2}>Package</Cell>
    <Cell header colspan={2} align="center">Compatibility</Cell>
    <Cell header colspan={2} align="center">Features</Cell>
  </Row>
  <Row slot="head">
    <Cell header>Min Astro</Cell>
    <Cell header>Peer deps</Cell>
    <Cell header>JS-free</Cell>
    <Cell header>Dark mode</Cell>
  </Row>
  <Row>
    <Cell>astro-better-details</Cell>
    <Cell align="center">4.0</Cell>
    <Cell>none</Cell>
    <Cell align="center">yes</Cell>
    <Cell align="center">yes</Cell>
  </Row>
  <Row>
    <Cell>astro-better-tabs</Cell>
    <Cell align="center">4.0</Cell>
    <Cell>none</Cell>
    <Cell align="center">no</Cell>
    <Cell align="center">yes</Cell>
  </Row>
  <Row>
    <Cell>astro-toc-smol</Cell>
    <Cell align="center">4.0</Cell>
    <Cell>none</Cell>
    <Cell align="center">no</Cell>
    <Cell align="center">yes</Cell>
  </Row>
  <Row>
    <Cell>astro-better-tables</Cell>
    <Cell align="center">4.0</Cell>
    <Cell>none</Cell>
    <Cell align="center">yes</Cell>
    <Cell align="center">yes</Cell>
  </Row>
</TableGrid>
PackageCompatibilityFeatures
Min AstroPeer depsJS-freeDark mode
astro-better-details4.0noneyesyes
astro-better-tabs4.0nonenoyes
astro-toc-smol4.0nonenoyes
astro-better-tables4.0noneyesyes

Rowspan in body rows

Use rowspan on a body cell to group multiple rows under a shared label. This is the classic “stub column” pattern for changelogs, reference tables, and any data where rows naturally cluster into named groups.

<TableGrid widths="1 1 3">
  <Row slot="head">
    <Cell header>Version</Cell>
    <Cell header>Type</Cell>
    <Cell header>Change</Cell>
  </Row>
  <Row>
    <Cell rowspan={3} valign="top">1.1.0</Cell>
    <Cell>feature</Cell>
    <Cell>Added `MarkdownOnly` component export</Cell>
  </Row>
  <Row>
    <Cell>fix</Cell>
    <Cell>Fixed `TableGrid` rendering empty `tbody` in MDX</Cell>
  </Row>
  <Row>
    <Cell>docs</Cell>
    <Cell>Rewrote `tables.mdx` with correct component APIs</Cell>
  </Row>
  <Row>
    <Cell rowspan={2} valign="top">1.0.0</Cell>
    <Cell>feature</Cell>
    <Cell>Initial release with `Table` and `TableGrid`</Cell>
  </Row>
  <Row>
    <Cell>docs</Cell>
    <Cell>Added README with RST list-table syntax guide</Cell>
  </Row>
</TableGrid>
VersionTypeChange
1.1.0featureAdded MarkdownOnly component export
fixFixed TableGrid rendering empty tbody in MDX
docsRewrote tables.mdx with correct component APIs
1.0.0featureInitial release with Table and TableGrid
docsAdded README with RST list-table syntax guide

TableGrid props

PropTypeDefaultDescription
widthsstringSpace-separated column width ratios, e.g. "1 2 1"
captionstringTable caption
align'left' | 'center' | 'right'Horizontal alignment of the table
widthstringCSS width of the table, e.g. "100%"
scrollbooleantrueWrap in a horizontally-scrollable container
classstringAdditional CSS classes

Row props

Row renders a <tr>. Add slot="head" to place it in <thead>.

Cell props

PropTypeDefaultDescription
headerbooleanfalseRender as <th>
colspannumberColumn span
rowspannumberRow span
alignstringtext-align value
valignstringvertical-align value
classstringAdditional CSS classes

Table

Table uses RST-style nested markdown lists. Each outer list item is a row; each inner list item is a cell. Use headerRows to specify how many leading rows become <thead> rows.

import Table from 'astro-better-tables/Table.astro';

<Table headerRows={1}>
- - Package
  - Type
  - Version
- - astro-better-nav-bar
  - component
  - 0.1.1
- - astro-better-steps
  - component
  - 0.1.0
</Table>

Table props

PropTypeDefaultDescription
headerRowsnumber0Number of leading rows to render as <thead>
stubColsnumber0Number of leading columns rendered as <th scope="row">
widthsstringSpace-separated column width ratios
colAlignstringSpace-separated text-align values per column
captionstringTable caption
align'left' | 'center' | 'right'Horizontal alignment of the table
widthstringCSS width of the table
scrollbooleantrueWrap in a horizontally-scrollable container
classstringAdditional CSS classes