@wmcadigital/ui-table
v0.1.0-alpha.2
Published
A table is used to make information easier for users to compare and scan
Readme
@wmcadigital/ui-table
A table is used to make information easier for users to compare and scan
Usage
import { hello } from '@wmcadigital/ui-table';
This package provides a small runtime script that normalises HTML tables for consistent styling and accessibility.
## Installation
Using pnpm (monorepo/workspace):
```bash
pnpm add @wmcadigital/ui-tableUsing npm:
npm install @wmcadigital/ui-tableUsing yarn:
yarn add @wmcadigital/ui-tableWhat this package does
- Adds the
wmcads-tableclass to all<table>elements (if not already present) to enable consistent styling across the design system. - Removes inline
style,border, andwidthattributes from the table, rows and cells to avoid presentation conflicts. - Detects header-like rows (cells with
<b>/<strong>or multiple<th>cells) and converts the first logical header row into a<thead>with proper<th scope="col">cells. - For tables without an obvious header, marks them with the class
wmcads-table--without-header. - Ensures cells have
data-headerattributes (e.g.data-header="Header 1") to assist responsive or CSS-based table patterns.
Note: this is a behaviour-focused helper — it does not ship styling. Apply your design system table styles (or import the related CSS) separately.
Usage
Import and run the module in a browser environment (recommended):
import tableJS from '@wmcadigital/ui-table';
// Run after DOM is available (e.g. in your client entry)
tableJS();Or load the distributed script as an ES module in the browser:
<script type="module">
import tableJS from '/node_modules/@wmcadigital/ui-table/dist/index.esm.js';
tableJS();
</script>If you prefer to run the helper only on specific pages, call tableJS() conditionally where appropriate.
Accessibility
- The script attempts to add semantic structure (
<thead>,<th scope="col">, and rowscope="row") to improve keyboard and screen reader navigation. - Consumers should ensure the resulting headers are meaningful; the script will use visible text where possible but may fall back to generic labels like
Header Nwhen necessary. - Provide descriptive
captionor surrounding text when the table conveys complex information.
Customisation & Integration
- Styling is separate: add or import your table CSS that targets
.wmcads-tableand related modifiers. - If you need a different header-detection heuristic or want to opt-out for certain tables, call the helper selectively or fork the small runtime.
Development
Build from the repository root:
pnpm -w -r run buildSee the monorepo README.md and DOCS/ for contributing and publishing guidelines.
