@molecule/app-admin-table-react 1.0.0 → 1.0.1
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 +213 -0
- package/package.json +14 -8
package/README.md
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
3
|
+
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
|
+
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
|
+
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
+
Generated: 2026-08-04T01:49:53.453Z
|
|
7
|
+
-->
|
|
8
|
+
|
|
9
|
+
# @molecule/app-admin-table-react
|
|
10
|
+
|
|
11
|
+
> **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
|
|
12
|
+
> It is written to be read by coding agents as much as by people, and is generated from this
|
|
13
|
+
> package's source — edit `src/index.ts` JSDoc, not this file.
|
|
14
|
+
|
|
15
|
+
`@molecule/app-admin-table-react` — generic admin-style data table.
|
|
16
|
+
Define columns, optionally enable row-click navigation, bulk-select
|
|
17
|
+
checkboxes, and a row-actions kebab menu; supply a pagination footer
|
|
18
|
+
via the `footer` slot.
|
|
19
|
+
|
|
20
|
+
Generalised from the AdminProductsTable / AdminOrdersTable shapes in
|
|
21
|
+
the online-store flagship — the table itself is the reusable
|
|
22
|
+
primitive; product-specific cells (sale price, stock badges) stay in
|
|
23
|
+
the consumer.
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
import { AdminTable, type AdminTableColumn } from '@molecule/app-admin-table-react'
|
|
29
|
+
|
|
30
|
+
const columns: AdminTableColumn<Product>[] = [
|
|
31
|
+
{ id: 'name', header: 'Product', render: (p) => <Product p={p} /> },
|
|
32
|
+
{ id: 'price', header: 'Price', render: (p) => `$${(p.price / 100).toFixed(2)}`, align: 'right' },
|
|
33
|
+
{ id: 'stock', header: 'Stock', render: (p) => <StockBadge stock={p.stock} /> },
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
<AdminTable
|
|
37
|
+
rows={products}
|
|
38
|
+
columns={columns}
|
|
39
|
+
rowKey={(p) => p.id}
|
|
40
|
+
loading={loading}
|
|
41
|
+
onRowClick={(p) => navigate(`/product/${p.id}`)}
|
|
42
|
+
bulkSelect
|
|
43
|
+
rowActions={[
|
|
44
|
+
{ label: 'Edit', hrefFor: (p) => `/product/${p.id}`, onSelect: () => {} },
|
|
45
|
+
{ label: 'Delete', destructive: true, onSelect: (p) => http.delete(`/api/products/${p.id}`) },
|
|
46
|
+
]}
|
|
47
|
+
footer={pagination}
|
|
48
|
+
/>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Type
|
|
52
|
+
|
|
53
|
+
`feature`
|
|
54
|
+
|
|
55
|
+
## Installation
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
npm install @molecule/app-admin-table-react @molecule/app-react @molecule/app-ui @molecule/app-ui-react react
|
|
59
|
+
npm install -D @types/react
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## API
|
|
63
|
+
|
|
64
|
+
### Interfaces
|
|
65
|
+
|
|
66
|
+
#### `AdminTableColumn`
|
|
67
|
+
|
|
68
|
+
A column definition. Drives header rendering + per-row cell rendering.
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
interface AdminTableColumn<T> {
|
|
72
|
+
/** Stable identifier (also used as React key). */
|
|
73
|
+
id: string
|
|
74
|
+
/** Column header (rendered in `<th>`). */
|
|
75
|
+
header: ReactNode
|
|
76
|
+
/** Cell renderer for one row. */
|
|
77
|
+
render: (row: T) => ReactNode
|
|
78
|
+
/** Optional alignment override; defaults to left. */
|
|
79
|
+
align?: 'left' | 'right' | 'center'
|
|
80
|
+
/** Optional class string appended to the `<td>` (resolve via `getClassMap()` — e.g. `cm.textRight` — rather than raw utilities). */
|
|
81
|
+
className?: string
|
|
82
|
+
/** Optional class string appended to the `<th>` (resolve via `getClassMap()` rather than raw utilities). */
|
|
83
|
+
headerClassName?: string
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
#### `AdminTableProps`
|
|
88
|
+
|
|
89
|
+
Props for {@link AdminTable}.
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
interface AdminTableProps<T> {
|
|
93
|
+
rows: T[]
|
|
94
|
+
columns: AdminTableColumn<T>[]
|
|
95
|
+
rowKey: (row: T) => string
|
|
96
|
+
loading?: boolean
|
|
97
|
+
skeletonRowCount?: number
|
|
98
|
+
/** Click handler for whole-row navigation. */
|
|
99
|
+
onRowClick?: (row: T) => void
|
|
100
|
+
/** When set, renders a leading checkbox column and tracks selection. */
|
|
101
|
+
bulkSelect?: boolean
|
|
102
|
+
/**
|
|
103
|
+
* Selected row keys. Honored ONLY when `onSelectedIdsChange` is also
|
|
104
|
+
* provided (controlled mode); otherwise selection state is internal.
|
|
105
|
+
*/
|
|
106
|
+
selectedIds?: string[]
|
|
107
|
+
/** Selection-change handler — providing it switches selection to controlled mode. */
|
|
108
|
+
onSelectedIdsChange?: (ids: string[]) => void
|
|
109
|
+
/** Kebab menu items. When set, a trailing right-aligned actions column is rendered. */
|
|
110
|
+
rowActions?: AdminTableRowAction<T>[]
|
|
111
|
+
rowActionsAriaLabel?: (row: T) => string
|
|
112
|
+
/** Slot rendered below the table (typically a `<Pagination>` row). */
|
|
113
|
+
footer?: ReactNode
|
|
114
|
+
className?: string
|
|
115
|
+
/** Optional `data-mol-id` to attach to the rendered `<tbody>` for tests/AI. */
|
|
116
|
+
tbodyDataMolId?: string
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
#### `AdminTableRowAction`
|
|
121
|
+
|
|
122
|
+
One entry in the row-action kebab menu.
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
interface AdminTableRowAction<T> {
|
|
126
|
+
/** Label rendered in the menu (post-i18n). */
|
|
127
|
+
label: ReactNode
|
|
128
|
+
/** Called when the action is selected. */
|
|
129
|
+
onSelect: (row: T) => void | Promise<void>
|
|
130
|
+
/** Optional `data-mol-id` for tests/automation. */
|
|
131
|
+
dataMolIdFor?: (row: T) => string
|
|
132
|
+
/** Marks the action visually as destructive (red). */
|
|
133
|
+
destructive?: boolean
|
|
134
|
+
/** Optional href for non-click actions (rendered as a link). */
|
|
135
|
+
hrefFor?: (row: T) => string
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
#### `AdminTableRowActionsProps`
|
|
140
|
+
|
|
141
|
+
Props for {@link AdminTableRowActions}.
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
interface AdminTableRowActionsProps<T> {
|
|
145
|
+
row: T
|
|
146
|
+
actions: AdminTableRowAction<T>[]
|
|
147
|
+
ariaLabel: string
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Functions
|
|
152
|
+
|
|
153
|
+
#### `AdminTable(props)`
|
|
154
|
+
|
|
155
|
+
Admin-style data table.
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
function AdminTable({
|
|
159
|
+
rows,
|
|
160
|
+
columns,
|
|
161
|
+
rowKey,
|
|
162
|
+
loading,
|
|
163
|
+
skeletonRowCount = 8,
|
|
164
|
+
onRowClick,
|
|
165
|
+
bulkSelect,
|
|
166
|
+
selectedIds = [],
|
|
167
|
+
onSelectedIdsChange,
|
|
168
|
+
rowActions,
|
|
169
|
+
rowActionsAriaLabel,
|
|
170
|
+
footer,
|
|
171
|
+
className,
|
|
172
|
+
tbodyDataMolId,
|
|
173
|
+
}: AdminTableProps<T>): JSX.Element
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
#### `AdminTableRowActions(props)`
|
|
177
|
+
|
|
178
|
+
Three-dots row actions menu.
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
function AdminTableRowActions({
|
|
182
|
+
row,
|
|
183
|
+
actions,
|
|
184
|
+
ariaLabel,
|
|
185
|
+
}: AdminTableRowActionsProps<T>): JSX.Element
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## Injection Notes
|
|
189
|
+
|
|
190
|
+
### Requirements
|
|
191
|
+
|
|
192
|
+
Peer dependencies:
|
|
193
|
+
|
|
194
|
+
- `@molecule/app-react` ^1.0.1
|
|
195
|
+
- `@molecule/app-ui` ^1.0.1
|
|
196
|
+
- `@molecule/app-ui-react` ^1.0.1
|
|
197
|
+
- `react` ^18.0.0 || ^19.0.0
|
|
198
|
+
|
|
199
|
+
### Runtime Dependencies
|
|
200
|
+
|
|
201
|
+
- `@molecule/app-react`
|
|
202
|
+
- `@molecule/app-ui`
|
|
203
|
+
- `@molecule/app-ui-react`
|
|
204
|
+
- `react`
|
|
205
|
+
|
|
206
|
+
- Requires the Material Symbols Outlined font (row-actions kebab icon) —
|
|
207
|
+
load it via an `@molecule/app-fonts-*` bond or a font link.
|
|
208
|
+
- Styling resolves entirely through the ClassMap bond (`getClassMap()` /
|
|
209
|
+
`cm.*`): surfaces, borders, text, and hover all use theme tokens, so the
|
|
210
|
+
table renders correctly in both light and dark themes with no per-app
|
|
211
|
+
restyling.
|
|
212
|
+
- `selectedIds` is honored only together with `onSelectedIdsChange`
|
|
213
|
+
(controlled selection); omit both for internal selection state.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/app-admin-table-react",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Admin-style data table: column-defs, row click navigation, bulk-select, row-action kebab menu, loading skeleton, pagination slot. Generalised from AdminProductsTable / AdminOrdersTable in the online-store flagship.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
"files": [
|
|
20
|
-
"dist"
|
|
20
|
+
"dist",
|
|
21
|
+
"README.md"
|
|
21
22
|
],
|
|
22
23
|
"keywords": [
|
|
23
24
|
"molecule",
|
|
@@ -27,16 +28,21 @@
|
|
|
27
28
|
"react"
|
|
28
29
|
],
|
|
29
30
|
"license": "Apache-2.0",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "https://github.com/molecule-dev/molecule.git",
|
|
34
|
+
"directory": "packages/app/features/admin-table-react"
|
|
35
|
+
},
|
|
30
36
|
"peerDependencies": {
|
|
31
|
-
"@molecule/app-react": "^1.0.
|
|
32
|
-
"@molecule/app-ui": "^1.0.
|
|
33
|
-
"@molecule/app-ui-react": "^1.0.
|
|
37
|
+
"@molecule/app-react": "^1.0.1",
|
|
38
|
+
"@molecule/app-ui": "^1.0.1",
|
|
39
|
+
"@molecule/app-ui-react": "^1.0.1",
|
|
34
40
|
"react": "^18.0.0 || ^19.0.0"
|
|
35
41
|
},
|
|
36
42
|
"devDependencies": {
|
|
37
|
-
"@molecule/app-react": "1.0.
|
|
38
|
-
"@molecule/app-ui": "1.0.
|
|
39
|
-
"@molecule/app-ui-react": "1.0.
|
|
43
|
+
"@molecule/app-react": "1.0.1",
|
|
44
|
+
"@molecule/app-ui": "1.0.1",
|
|
45
|
+
"@molecule/app-ui-react": "1.0.1",
|
|
40
46
|
"@types/node": "26.1.2",
|
|
41
47
|
"@types/react": "19.2.17",
|
|
42
48
|
"react": "19.2.8",
|