@behivetech/atoms.table 0.0.0-stage → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,21 @@
1
- # Temporary Holding Version
1
+ # Table
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ TODO: Add component description.
4
+
5
+ ## Usage
6
+
7
+ ```jsx
8
+ import { Table } from "@behivetech/atoms.table";
9
+
10
+ function Example() {
11
+ const columns = [
12
+ { key: "name", title: "Name", dataIndex: "name" },
13
+ { key: "status", title: "Status", dataIndex: "status" },
14
+ ];
15
+ const data = [
16
+ { id: "1", name: "Hero banner", status: "Published" },
17
+ { id: "2", name: "Pricing table", status: "Draft" },
18
+ ];
19
+ return <Table columns={columns} data={data} rowKey={(row) => row.id} />;
20
+ }
21
+ ```
package/dist/index.cjs ADDED
@@ -0,0 +1,175 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __commonJS = (cb, mod) => function __require() {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ };
11
+ var __export = (target, all) => {
12
+ for (var name in all)
13
+ __defProp(target, name, { get: all[name], enumerable: true });
14
+ };
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from))
18
+ if (!__hasOwnProp.call(to, key) && key !== except)
19
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
+ }
21
+ return to;
22
+ };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
+ // If the importer is in node compatibility mode or this is not an ESM
25
+ // file that has been converted to a CommonJS file using a Babel-
26
+ // compatible transform (i.e. "__esModule" has not been set), then set
27
+ // "default" to the CommonJS "module.exports" for node compatibility.
28
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
+ mod
30
+ ));
31
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
+
33
+ // ../../../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js
34
+ var require_classnames = __commonJS({
35
+ "../../../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js"(exports2, module2) {
36
+ "use strict";
37
+ (function() {
38
+ "use strict";
39
+ var hasOwn = {}.hasOwnProperty;
40
+ function classNames() {
41
+ var classes = "";
42
+ for (var i = 0; i < arguments.length; i++) {
43
+ var arg = arguments[i];
44
+ if (arg) {
45
+ classes = appendClass(classes, parseValue(arg));
46
+ }
47
+ }
48
+ return classes;
49
+ }
50
+ function parseValue(arg) {
51
+ if (typeof arg === "string" || typeof arg === "number") {
52
+ return arg;
53
+ }
54
+ if (typeof arg !== "object") {
55
+ return "";
56
+ }
57
+ if (Array.isArray(arg)) {
58
+ return classNames.apply(null, arg);
59
+ }
60
+ if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes("[native code]")) {
61
+ return arg.toString();
62
+ }
63
+ var classes = "";
64
+ for (var key in arg) {
65
+ if (hasOwn.call(arg, key) && arg[key]) {
66
+ classes = appendClass(classes, key);
67
+ }
68
+ }
69
+ return classes;
70
+ }
71
+ function appendClass(value, newClass) {
72
+ if (!newClass) {
73
+ return value;
74
+ }
75
+ if (value) {
76
+ return value + " " + newClass;
77
+ }
78
+ return value + newClass;
79
+ }
80
+ if (typeof module2 !== "undefined" && module2.exports) {
81
+ classNames.default = classNames;
82
+ module2.exports = classNames;
83
+ } else if (typeof define === "function" && typeof define.amd === "object" && define.amd) {
84
+ define("classnames", [], function() {
85
+ return classNames;
86
+ });
87
+ } else {
88
+ window.classNames = classNames;
89
+ }
90
+ })();
91
+ }
92
+ });
93
+
94
+ // index.ts
95
+ var index_exports = {};
96
+ __export(index_exports, {
97
+ Table: () => Table
98
+ });
99
+ module.exports = __toCommonJS(index_exports);
100
+
101
+ // ../../../../packages/registry/class-names/dist/index.js
102
+ var import_classnames = __toESM(require_classnames(), 1);
103
+ var getClassName = ({
104
+ className,
105
+ modifiers = {},
106
+ rootClass,
107
+ styles = {}
108
+ }) => {
109
+ function getModifiers() {
110
+ const updatedModifiers = {};
111
+ const modifierKeys = Object.keys(modifiers);
112
+ if (modifierKeys.length) {
113
+ modifierKeys.forEach((modKey) => {
114
+ const classKey = `${rootClass}--${modKey}`;
115
+ const newClassName = styles[classKey] || classKey;
116
+ updatedModifiers[newClassName] = modifiers[modKey] ?? false;
117
+ });
118
+ }
119
+ return updatedModifiers;
120
+ }
121
+ function getChildClass(childClassName) {
122
+ const classKey = `${rootClass}__${childClassName}`;
123
+ return styles[classKey] || classKey;
124
+ }
125
+ function getRootStyles() {
126
+ return (0, import_classnames.default)(
127
+ className,
128
+ {
129
+ ...getModifiers()
130
+ },
131
+ styles[rootClass] || rootClass
132
+ );
133
+ }
134
+ return [getRootStyles(), getChildClass];
135
+ };
136
+
137
+ // table.module.scss
138
+ var table_module_default = {
139
+ "BHT__Table": "BHT__Table"
140
+ };
141
+
142
+ // table.tsx
143
+ var import_jsx_runtime = require("react/jsx-runtime");
144
+ var Table = ({
145
+ columns,
146
+ data,
147
+ rowKey,
148
+ className
149
+ }) => {
150
+ const [rootClass] = getClassName({
151
+ className,
152
+ rootClass: "BHT__Table",
153
+ styles: table_module_default
154
+ });
155
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("table", { className: rootClass, children: [
156
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tr", { children: columns.map((column) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", { className: column.className, children: column.title }, column.key)) }) }),
157
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tbody", { children: data.map((row) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tr", { children: columns.map((column) => {
158
+ const value = column.dataIndex ? row[column.dataIndex] : void 0;
159
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", { className: column.className, children: column.render ? column.render(value, row) : value !== void 0 ? String(value) : null }, column.key);
160
+ }) }, rowKey(row))) })
161
+ ] });
162
+ };
163
+ // Annotate the CommonJS export names for ESM import in node:
164
+ 0 && (module.exports = {
165
+ Table
166
+ });
167
+ /*! Bundled license information:
168
+
169
+ classnames/index.js:
170
+ (*!
171
+ Copyright (c) 2018 Jed Watson.
172
+ Licensed under the MIT License (MIT), see
173
+ http://jedwatson.github.io/classnames
174
+ *)
175
+ */
package/dist/index.css ADDED
@@ -0,0 +1,43 @@
1
+ /* esbuild-sass-plugin:css-chunktable.module.scss */
2
+ .BHT__Table {
3
+ width: 100%;
4
+ border-collapse: collapse;
5
+ }
6
+ .BHT__Table th {
7
+ text-align: left;
8
+ padding: var(--spacing-2, 0.5rem) var(--spacing-4, 1rem);
9
+ font-family: var(--md-sys-typescale-title-small-font, var(--font-body));
10
+ font-size: var(--md-sys-typescale-title-small-size, 0.875rem);
11
+ font-weight: var(--md-sys-typescale-title-small-weight, 500);
12
+ line-height: var(--md-sys-typescale-title-small-line-height, 1.25rem);
13
+ letter-spacing: var(--md-sys-typescale-title-small-tracking, 0.0071em);
14
+ color: var(--md-sys-color-on-surface-variant, var(--color-text-muted));
15
+ background: var(--md-sys-color-surface-container, var(--color-surface-raised));
16
+ border-bottom: 1px solid var(--md-sys-color-outline-variant, var(--color-border));
17
+ }
18
+ .BHT__Table td {
19
+ position: relative;
20
+ padding: var(--spacing-3, 0.75rem) var(--spacing-4, 1rem);
21
+ font-family: var(--md-sys-typescale-body-medium-font, var(--font-body));
22
+ font-size: var(--md-sys-typescale-body-medium-size, 0.875rem);
23
+ font-weight: var(--md-sys-typescale-body-medium-weight, 400);
24
+ line-height: var(--md-sys-typescale-body-medium-line-height, 1.25rem);
25
+ letter-spacing: var(--md-sys-typescale-body-medium-tracking, 0.0179em);
26
+ color: var(--md-sys-color-on-surface, var(--color-text-body));
27
+ border-bottom: 1px solid var(--md-sys-color-outline-variant, var(--color-border));
28
+ }
29
+ .BHT__Table td::after {
30
+ content: "";
31
+ position: absolute;
32
+ inset: 0;
33
+ background: currentColor;
34
+ opacity: 0;
35
+ pointer-events: none;
36
+ transition: opacity var(--md-sys-motion-duration-short-2, 100ms) var(--md-sys-motion-easing-standard, ease);
37
+ }
38
+ .BHT__Table tr:last-child td {
39
+ border-bottom: none;
40
+ }
41
+ .BHT__Table tr:hover td::after {
42
+ opacity: var(--md-sys-state-hover-opacity, 0.08);
43
+ }
@@ -0,0 +1,34 @@
1
+ import * as react from 'react';
2
+ import { ReactNode } from 'react';
3
+
4
+ interface TableColumn<TRow> {
5
+ /** Unique identity for this column; also used as the header cell's React key */
6
+ key: string;
7
+ /** Column header content */
8
+ title: ReactNode;
9
+ /** Reads a raw field off each row for this column, when no custom `render` is given */
10
+ dataIndex?: keyof TRow;
11
+ /** Renders a cell's content. Receives `row[dataIndex]` as `value` when `dataIndex` is set. */
12
+ render?: (value: unknown, row: TRow) => ReactNode;
13
+ /** Additional class name applied to every cell (header and body) in this column */
14
+ className?: string;
15
+ }
16
+ interface TableProps<TRow> {
17
+ /** Column definitions, rendered left to right */
18
+ columns: TableColumn<TRow>[];
19
+ /** Rows to render, in the order given — Table does not sort, paginate, or filter */
20
+ data: TRow[];
21
+ /** Returns a stable, unique key for a row, used as its React key */
22
+ rowKey: (row: TRow) => string;
23
+ /** Additional class names to merge with the component root element */
24
+ className?: string;
25
+ }
26
+ /**
27
+ * A bare data table — describe `columns` once (each with a `title` and either a
28
+ * `dataIndex` or a custom `render`), pass `data`, get a `<table>` back. No sorting,
29
+ * pagination, or empty-state handling — those are the consuming app's concern to add
30
+ * around this, not props on the component itself.
31
+ */
32
+ declare const Table: <TRow>({ columns, data, rowKey, className, }: TableProps<TRow>) => react.JSX.Element;
33
+
34
+ export { Table, type TableColumn, type TableProps };
package/dist/index.js ADDED
@@ -0,0 +1,161 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
+ // If the importer is in node compatibility mode or this is not an ESM
20
+ // file that has been converted to a CommonJS file using a Babel-
21
+ // compatible transform (i.e. "__esModule" has not been set), then set
22
+ // "default" to the CommonJS "module.exports" for node compatibility.
23
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
+ mod
25
+ ));
26
+
27
+ // ../../../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js
28
+ var require_classnames = __commonJS({
29
+ "../../../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js"(exports, module) {
30
+ "use strict";
31
+ (function() {
32
+ "use strict";
33
+ var hasOwn = {}.hasOwnProperty;
34
+ function classNames() {
35
+ var classes = "";
36
+ for (var i = 0; i < arguments.length; i++) {
37
+ var arg = arguments[i];
38
+ if (arg) {
39
+ classes = appendClass(classes, parseValue(arg));
40
+ }
41
+ }
42
+ return classes;
43
+ }
44
+ function parseValue(arg) {
45
+ if (typeof arg === "string" || typeof arg === "number") {
46
+ return arg;
47
+ }
48
+ if (typeof arg !== "object") {
49
+ return "";
50
+ }
51
+ if (Array.isArray(arg)) {
52
+ return classNames.apply(null, arg);
53
+ }
54
+ if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes("[native code]")) {
55
+ return arg.toString();
56
+ }
57
+ var classes = "";
58
+ for (var key in arg) {
59
+ if (hasOwn.call(arg, key) && arg[key]) {
60
+ classes = appendClass(classes, key);
61
+ }
62
+ }
63
+ return classes;
64
+ }
65
+ function appendClass(value, newClass) {
66
+ if (!newClass) {
67
+ return value;
68
+ }
69
+ if (value) {
70
+ return value + " " + newClass;
71
+ }
72
+ return value + newClass;
73
+ }
74
+ if (typeof module !== "undefined" && module.exports) {
75
+ classNames.default = classNames;
76
+ module.exports = classNames;
77
+ } else if (typeof define === "function" && typeof define.amd === "object" && define.amd) {
78
+ define("classnames", [], function() {
79
+ return classNames;
80
+ });
81
+ } else {
82
+ window.classNames = classNames;
83
+ }
84
+ })();
85
+ }
86
+ });
87
+
88
+ // ../../../../packages/registry/class-names/dist/index.js
89
+ var import_classnames = __toESM(require_classnames(), 1);
90
+ var getClassName = ({
91
+ className,
92
+ modifiers = {},
93
+ rootClass,
94
+ styles = {}
95
+ }) => {
96
+ function getModifiers() {
97
+ const updatedModifiers = {};
98
+ const modifierKeys = Object.keys(modifiers);
99
+ if (modifierKeys.length) {
100
+ modifierKeys.forEach((modKey) => {
101
+ const classKey = `${rootClass}--${modKey}`;
102
+ const newClassName = styles[classKey] || classKey;
103
+ updatedModifiers[newClassName] = modifiers[modKey] ?? false;
104
+ });
105
+ }
106
+ return updatedModifiers;
107
+ }
108
+ function getChildClass(childClassName) {
109
+ const classKey = `${rootClass}__${childClassName}`;
110
+ return styles[classKey] || classKey;
111
+ }
112
+ function getRootStyles() {
113
+ return (0, import_classnames.default)(
114
+ className,
115
+ {
116
+ ...getModifiers()
117
+ },
118
+ styles[rootClass] || rootClass
119
+ );
120
+ }
121
+ return [getRootStyles(), getChildClass];
122
+ };
123
+
124
+ // table.module.scss
125
+ var table_module_default = {
126
+ "BHT__Table": "BHT__Table"
127
+ };
128
+
129
+ // table.tsx
130
+ import { jsx, jsxs } from "react/jsx-runtime";
131
+ var Table = ({
132
+ columns,
133
+ data,
134
+ rowKey,
135
+ className
136
+ }) => {
137
+ const [rootClass] = getClassName({
138
+ className,
139
+ rootClass: "BHT__Table",
140
+ styles: table_module_default
141
+ });
142
+ return /* @__PURE__ */ jsxs("table", { className: rootClass, children: [
143
+ /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsx("tr", { children: columns.map((column) => /* @__PURE__ */ jsx("th", { className: column.className, children: column.title }, column.key)) }) }),
144
+ /* @__PURE__ */ jsx("tbody", { children: data.map((row) => /* @__PURE__ */ jsx("tr", { children: columns.map((column) => {
145
+ const value = column.dataIndex ? row[column.dataIndex] : void 0;
146
+ return /* @__PURE__ */ jsx("td", { className: column.className, children: column.render ? column.render(value, row) : value !== void 0 ? String(value) : null }, column.key);
147
+ }) }, rowKey(row))) })
148
+ ] });
149
+ };
150
+ export {
151
+ Table
152
+ };
153
+ /*! Bundled license information:
154
+
155
+ classnames/index.js:
156
+ (*!
157
+ Copyright (c) 2018 Jed Watson.
158
+ Licensed under the MIT License (MIT), see
159
+ http://jedwatson.github.io/classnames
160
+ *)
161
+ */
package/docs.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "$schema": "https://github.com/behivetech/bht-component-registry/docs.schema.json",
3
+ "version": 2,
4
+ "generatedAt": "2026-10-20T05:49:43.723Z",
5
+ "docs": [
6
+ {
7
+ "displayName": "Table",
8
+ "description": "A bare data table — describe `columns` once (each with a `title` and either a\n`dataIndex` or a custom `render`), pass `data`, get a `<table>` back. No sorting,\npagination, or empty-state handling — those are the consuming app's concern to add\naround this, not props on the component itself.",
9
+ "extendsNative": false,
10
+ "props": [
11
+ {
12
+ "name": "columns",
13
+ "type": "TableColumn<TRow>[]",
14
+ "required": true,
15
+ "defaultValue": null,
16
+ "description": "Column definitions, rendered left to right"
17
+ },
18
+ {
19
+ "name": "data",
20
+ "type": "TRow[]",
21
+ "required": true,
22
+ "defaultValue": null,
23
+ "description": "Rows to render, in the order given — Table does not sort, paginate, or filter"
24
+ },
25
+ {
26
+ "name": "rowKey",
27
+ "type": "(row: TRow) => string",
28
+ "required": true,
29
+ "defaultValue": null,
30
+ "description": "Returns a stable, unique key for a row, used as its React key"
31
+ },
32
+ {
33
+ "name": "className",
34
+ "type": "string",
35
+ "required": false,
36
+ "defaultValue": null,
37
+ "description": "Additional class names to merge with the component root element"
38
+ }
39
+ ]
40
+ }
41
+ ],
42
+ "functions": []
43
+ }
package/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { Table } from "./table.js";
2
+ export type { TableProps, TableColumn } from "./table.js";
package/package.json CHANGED
@@ -1,6 +1,59 @@
1
1
  {
2
2
  "name": "@behivetech/atoms.table",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.2",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "private": false,
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/index.cjs"
12
+ },
13
+ "./styles.css": "./dist/index.css"
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md",
18
+ "index.ts",
19
+ "table.tsx",
20
+ "table.module.scss",
21
+ "*.example.tsx",
22
+ "docs.json"
23
+ ],
24
+ "registry": {
25
+ "status": "stable",
26
+ "tags": []
27
+ },
28
+ "peerDependencies": {
29
+ "react": "^19.2.7",
30
+ "react-dom": "^19.2.7"
31
+ },
32
+ "devDependencies": {
33
+ "@types/react": "19.2.17",
34
+ "@types/react-dom": "19.2.3",
35
+ "eslint": "^9.39.5",
36
+ "tsup": "^8.5.1",
37
+ "typescript": "^6.0.3",
38
+ "vitest": "^4.1.10",
39
+ "@bht-component-registry/env": "0.1.0",
40
+ "@bht-component-registry/class-names": "0.0.6"
41
+ },
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "https://github.com/behivetech/bht-galaxy.git",
45
+ "directory": "registry/behivetech/atoms/table"
46
+ },
47
+ "publishConfig": {
48
+ "registry": "https://registry.npmjs.org",
49
+ "access": "public",
50
+ "provenance": true
51
+ },
52
+ "scripts": {
53
+ "build": "tsup && bht-registry-docgen",
54
+ "dev": "tsup --watch",
55
+ "lint": "eslint . --max-warnings 0",
56
+ "check-types": "tsc --noEmit",
57
+ "test": "vitest run"
58
+ }
6
59
  }
@@ -0,0 +1,49 @@
1
+ import { Table, type TableColumn } from "./table.js";
2
+
3
+ interface Invoice {
4
+ id: string;
5
+ customer: string;
6
+ amount: number;
7
+ status: "paid" | "overdue";
8
+ }
9
+
10
+ const invoices: Invoice[] = [
11
+ { id: "inv-1", customer: "Acme Co", amount: 240, status: "paid" },
12
+ { id: "inv-2", customer: "Globex", amount: 90, status: "overdue" },
13
+ { id: "inv-3", customer: "Initech", amount: 512, status: "paid" },
14
+ ];
15
+
16
+ // Simplest case — dataIndex only, no custom rendering needed.
17
+ const basicColumns: TableColumn<Invoice>[] = [
18
+ { key: "customer", title: "Customer", dataIndex: "customer" },
19
+ { key: "amount", title: "Amount", dataIndex: "amount" },
20
+ ];
21
+
22
+ export const BasicTable = () => (
23
+ <Table columns={basicColumns} data={invoices} rowKey={(row) => row.id} />
24
+ );
25
+
26
+ // render() for custom cell content — formatting a value and reacting to the row.
27
+ const richColumns: TableColumn<Invoice>[] = [
28
+ { key: "customer", title: "Customer", dataIndex: "customer" },
29
+ {
30
+ key: "amount",
31
+ title: "Amount",
32
+ dataIndex: "amount",
33
+ render: (value) => `$${value}`,
34
+ },
35
+ {
36
+ key: "status",
37
+ title: "Status",
38
+ render: (_value, row) =>
39
+ row.status === "overdue" ? "⚠️ overdue" : "✓ paid",
40
+ },
41
+ ];
42
+
43
+ export const TableWithCustomCells = () => (
44
+ <Table columns={richColumns} data={invoices} rowKey={(row) => row.id} />
45
+ );
46
+
47
+ export const EmptyTable = () => (
48
+ <Table columns={basicColumns} data={[]} rowKey={(row) => row.id} />
49
+ );
@@ -0,0 +1,60 @@
1
+ // Material Design 3 has no table spec; this follows its data-table guidance:
2
+ // title-small headers on `on-surface-variant`, body-medium cells, and
3
+ // `outline-variant` row dividers.
4
+
5
+ .BHT__Table {
6
+ width: 100%;
7
+ border-collapse: collapse;
8
+
9
+ th {
10
+ text-align: left;
11
+ padding: var(--spacing-2, 0.5rem) var(--spacing-4, 1rem);
12
+ font-family: var(--md-sys-typescale-title-small-font, var(--font-body));
13
+ font-size: var(--md-sys-typescale-title-small-size, 0.875rem);
14
+ font-weight: var(--md-sys-typescale-title-small-weight, 500);
15
+ line-height: var(--md-sys-typescale-title-small-line-height, 1.25rem);
16
+ letter-spacing: var(--md-sys-typescale-title-small-tracking, 0.0071em);
17
+ color: var(--md-sys-color-on-surface-variant, var(--color-text-muted));
18
+ background: var(
19
+ --md-sys-color-surface-container,
20
+ var(--color-surface-raised)
21
+ );
22
+ border-bottom: 1px solid
23
+ var(--md-sys-color-outline-variant, var(--color-border));
24
+ }
25
+
26
+ td {
27
+ position: relative;
28
+ padding: var(--spacing-3, 0.75rem) var(--spacing-4, 1rem);
29
+ font-family: var(--md-sys-typescale-body-medium-font, var(--font-body));
30
+ font-size: var(--md-sys-typescale-body-medium-size, 0.875rem);
31
+ font-weight: var(--md-sys-typescale-body-medium-weight, 400);
32
+ line-height: var(--md-sys-typescale-body-medium-line-height, 1.25rem);
33
+ letter-spacing: var(--md-sys-typescale-body-medium-tracking, 0.0179em);
34
+ color: var(--md-sys-color-on-surface, var(--color-text-body));
35
+ border-bottom: 1px solid
36
+ var(--md-sys-color-outline-variant, var(--color-border));
37
+
38
+ // Row hover state layer. It sits on each cell rather than the `<tr>`
39
+ // because a positioned table row is still unreliable as a containing
40
+ // block for an absolutely positioned pseudo-element.
41
+ &::after {
42
+ content: "";
43
+ position: absolute;
44
+ inset: 0;
45
+ background: currentColor;
46
+ opacity: 0;
47
+ pointer-events: none;
48
+ transition: opacity var(--md-sys-motion-duration-short-2, 100ms)
49
+ var(--md-sys-motion-easing-standard, ease);
50
+ }
51
+ }
52
+
53
+ tr:last-child td {
54
+ border-bottom: none;
55
+ }
56
+
57
+ tr:hover td::after {
58
+ opacity: var(--md-sys-state-hover-opacity, 0.08);
59
+ }
60
+ }
package/table.tsx ADDED
@@ -0,0 +1,80 @@
1
+ import { type ReactNode } from "react";
2
+ import { getClassName } from "@bht-component-registry/class-names";
3
+ import styles from "./table.module.scss";
4
+
5
+ export interface TableColumn<TRow> {
6
+ /** Unique identity for this column; also used as the header cell's React key */
7
+ key: string;
8
+ /** Column header content */
9
+ title: ReactNode;
10
+ /** Reads a raw field off each row for this column, when no custom `render` is given */
11
+ dataIndex?: keyof TRow;
12
+ /** Renders a cell's content. Receives `row[dataIndex]` as `value` when `dataIndex` is set. */
13
+ render?: (value: unknown, row: TRow) => ReactNode;
14
+ /** Additional class name applied to every cell (header and body) in this column */
15
+ className?: string;
16
+ }
17
+
18
+ export interface TableProps<TRow> {
19
+ /** Column definitions, rendered left to right */
20
+ columns: TableColumn<TRow>[];
21
+ /** Rows to render, in the order given — Table does not sort, paginate, or filter */
22
+ data: TRow[];
23
+ /** Returns a stable, unique key for a row, used as its React key */
24
+ rowKey: (row: TRow) => string;
25
+ /** Additional class names to merge with the component root element */
26
+ className?: string;
27
+ }
28
+
29
+ /**
30
+ * A bare data table — describe `columns` once (each with a `title` and either a
31
+ * `dataIndex` or a custom `render`), pass `data`, get a `<table>` back. No sorting,
32
+ * pagination, or empty-state handling — those are the consuming app's concern to add
33
+ * around this, not props on the component itself.
34
+ */
35
+ export const Table = <TRow,>({
36
+ columns,
37
+ data,
38
+ rowKey,
39
+ className,
40
+ }: TableProps<TRow>) => {
41
+ const [rootClass] = getClassName({
42
+ className,
43
+ rootClass: "BHT__Table",
44
+ styles,
45
+ });
46
+
47
+ return (
48
+ <table className={rootClass}>
49
+ <thead>
50
+ <tr>
51
+ {columns.map((column) => (
52
+ <th key={column.key} className={column.className}>
53
+ {column.title}
54
+ </th>
55
+ ))}
56
+ </tr>
57
+ </thead>
58
+ <tbody>
59
+ {data.map((row) => (
60
+ <tr key={rowKey(row)}>
61
+ {columns.map((column) => {
62
+ const value = column.dataIndex
63
+ ? row[column.dataIndex]
64
+ : undefined;
65
+ return (
66
+ <td key={column.key} className={column.className}>
67
+ {column.render
68
+ ? column.render(value, row)
69
+ : value !== undefined
70
+ ? String(value)
71
+ : null}
72
+ </td>
73
+ );
74
+ })}
75
+ </tr>
76
+ ))}
77
+ </tbody>
78
+ </table>
79
+ );
80
+ };