@spark-web/data-table 0.0.0-snapshot-release-20260408010050
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/CHANGELOG.md +733 -0
- package/CLAUDE.md +89 -0
- package/README.md +76 -0
- package/dist/declarations/src/data-table.d.ts +30 -0
- package/dist/declarations/src/index.d.ts +2 -0
- package/dist/spark-web-data-table.cjs.d.ts +2 -0
- package/dist/spark-web-data-table.cjs.dev.js +226 -0
- package/dist/spark-web-data-table.cjs.js +7 -0
- package/dist/spark-web-data-table.cjs.prod.js +226 -0
- package/dist/spark-web-data-table.esm.js +211 -0
- package/package.json +43 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import _objectSpread from '@babel/runtime/helpers/esm/objectSpread2';
|
|
2
|
+
import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties';
|
|
3
|
+
import { css } from '@emotion/react';
|
|
4
|
+
import { Box } from '@spark-web/box';
|
|
5
|
+
import { SortAscendingIcon, SortDescendingIcon } from '@spark-web/icon';
|
|
6
|
+
import { Spinner } from '@spark-web/spinner';
|
|
7
|
+
import { useTheme } from '@spark-web/theme';
|
|
8
|
+
import { buildDataAttributes } from '@spark-web/utils/internal';
|
|
9
|
+
import { useReactTable, getCoreRowModel, flexRender } from '@tanstack/react-table';
|
|
10
|
+
export { createColumnHelper, flexRender } from '@tanstack/react-table';
|
|
11
|
+
import React from 'react';
|
|
12
|
+
import { InView } from 'react-intersection-observer';
|
|
13
|
+
import { jsxs, jsx } from '@emotion/react/jsx-runtime';
|
|
14
|
+
|
|
15
|
+
var _excluded = ["data", "items", "className", "columns", "enableExpanding", "enableHiding", "enableMultiRowSelection", "enableClickableRow", "headerClassName", "footerClassName", "showBottomSpinner", "rowClassName", "expandedRowComponent", "onBottomSpinnerShown", "onRowClick", "onRowSelectionChange", "renderRow"];
|
|
16
|
+
function getAriaSort(column) {
|
|
17
|
+
if (!column.getCanSort()) return undefined;
|
|
18
|
+
if (column.getIsSorted() === 'asc') return 'ascending';
|
|
19
|
+
if (column.getIsSorted() === 'desc') return 'descending';
|
|
20
|
+
return 'none';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* DataTable
|
|
27
|
+
*
|
|
28
|
+
* @see https://spark.brighte.com.au/package/data-table
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
function DataTable(_ref) {
|
|
32
|
+
var _tableOptions$enableS, _tableOptions$manualS;
|
|
33
|
+
var data = _ref.data,
|
|
34
|
+
items = _ref.items,
|
|
35
|
+
className = _ref.className,
|
|
36
|
+
columns = _ref.columns,
|
|
37
|
+
_ref$enableExpanding = _ref.enableExpanding,
|
|
38
|
+
enableExpanding = _ref$enableExpanding === void 0 ? false : _ref$enableExpanding,
|
|
39
|
+
_ref$enableHiding = _ref.enableHiding,
|
|
40
|
+
enableHiding = _ref$enableHiding === void 0 ? true : _ref$enableHiding,
|
|
41
|
+
_ref$enableMultiRowSe = _ref.enableMultiRowSelection,
|
|
42
|
+
enableMultiRowSelection = _ref$enableMultiRowSe === void 0 ? false : _ref$enableMultiRowSe,
|
|
43
|
+
enableClickableRow = _ref.enableClickableRow,
|
|
44
|
+
headerClassName = _ref.headerClassName,
|
|
45
|
+
footerClassName = _ref.footerClassName,
|
|
46
|
+
showSpinner = _ref.showBottomSpinner,
|
|
47
|
+
rowClassName = _ref.rowClassName,
|
|
48
|
+
expandedRowComponent = _ref.expandedRowComponent,
|
|
49
|
+
onBottomSpinnerShown = _ref.onBottomSpinnerShown,
|
|
50
|
+
onRowClick = _ref.onRowClick,
|
|
51
|
+
onRowSelectionChange = _ref.onRowSelectionChange,
|
|
52
|
+
renderRow = _ref.renderRow,
|
|
53
|
+
tableOptions = _objectWithoutProperties(_ref, _excluded);
|
|
54
|
+
var theme = useTheme();
|
|
55
|
+
var enableRowSelection = !!onRowSelectionChange;
|
|
56
|
+
var table = useReactTable(_objectSpread(_objectSpread({
|
|
57
|
+
data: items,
|
|
58
|
+
enableExpanding: enableExpanding,
|
|
59
|
+
enableMultiRowSelection: enableMultiRowSelection,
|
|
60
|
+
enableHiding: enableHiding,
|
|
61
|
+
enableRowSelection: enableRowSelection,
|
|
62
|
+
onRowSelectionChange: onRowSelectionChange,
|
|
63
|
+
columns: columns
|
|
64
|
+
}, tableOptions), {}, {
|
|
65
|
+
getCoreRowModel: getCoreRowModel(),
|
|
66
|
+
getExpandedRowModel: enableExpanding ? getCoreRowModel() : undefined,
|
|
67
|
+
enableSorting: (_tableOptions$enableS = tableOptions.enableSorting) !== null && _tableOptions$enableS !== void 0 ? _tableOptions$enableS : false,
|
|
68
|
+
manualSorting: (_tableOptions$manualS = tableOptions.manualSorting) !== null && _tableOptions$manualS !== void 0 ? _tableOptions$manualS : false
|
|
69
|
+
}));
|
|
70
|
+
var headerGroups = table.getHeaderGroups();
|
|
71
|
+
var footerGroups = table.getFooterGroups();
|
|
72
|
+
var defaultOnRowClick = function defaultOnRowClick(row) {
|
|
73
|
+
return row.toggleSelected();
|
|
74
|
+
};
|
|
75
|
+
return jsxs(Box, _objectSpread(_objectSpread({
|
|
76
|
+
as: "table"
|
|
77
|
+
}, data ? buildDataAttributes(data) : undefined), {}, {
|
|
78
|
+
css: className,
|
|
79
|
+
children: [headerGroups.length > 0 ? jsx(Box, {
|
|
80
|
+
as: "thead",
|
|
81
|
+
css: css({
|
|
82
|
+
backgroundColor: theme.color.background.surface,
|
|
83
|
+
// we use box shadow instead of bottom border
|
|
84
|
+
// to allow the border to stay in the header on scroll
|
|
85
|
+
// when the table is sticky
|
|
86
|
+
boxShadow: "inset 0 -2px 0 ".concat(theme.border.color.primaryActive)
|
|
87
|
+
}, headerClassName),
|
|
88
|
+
children: headerGroups.map(function (headerGroup) {
|
|
89
|
+
return jsx(Box, {
|
|
90
|
+
as: "tr",
|
|
91
|
+
children: headerGroup.headers.map(function (header) {
|
|
92
|
+
var _asc$desc;
|
|
93
|
+
return jsxs(Box, {
|
|
94
|
+
as: "th",
|
|
95
|
+
padding: "medium",
|
|
96
|
+
css: css(_objectSpread(_objectSpread({
|
|
97
|
+
color: theme.color.foreground.primaryActive,
|
|
98
|
+
fontFamily: theme.typography.fontFamily.sans.name,
|
|
99
|
+
fontWeight: theme.typography.fontWeight.semibold,
|
|
100
|
+
textAlign: 'left',
|
|
101
|
+
width: "".concat(header.getSize(), "px"),
|
|
102
|
+
cursor: header.column.getCanSort() ? 'pointer' : undefined,
|
|
103
|
+
userSelect: header.column.getCanSort() ? 'none' : undefined
|
|
104
|
+
}, header.column.getCanSort() ? {
|
|
105
|
+
'&:hover': {
|
|
106
|
+
backgroundColor: theme.backgroundInteractions.primaryLowHover
|
|
107
|
+
}
|
|
108
|
+
} : {}), {}, {
|
|
109
|
+
svg: {
|
|
110
|
+
marginLeft: theme.spacing.xsmall
|
|
111
|
+
}
|
|
112
|
+
})),
|
|
113
|
+
onClick: header.column.getToggleSortingHandler(),
|
|
114
|
+
"aria-sort": getAriaSort(header.column),
|
|
115
|
+
children: [header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext()), (_asc$desc = {
|
|
116
|
+
asc: jsx(SortAscendingIcon, {
|
|
117
|
+
size: "xxsmall",
|
|
118
|
+
tone: "primaryActive"
|
|
119
|
+
}),
|
|
120
|
+
desc: jsx(SortDescendingIcon, {
|
|
121
|
+
size: "xxsmall",
|
|
122
|
+
tone: "primaryActive"
|
|
123
|
+
})
|
|
124
|
+
}[header.column.getIsSorted()]) !== null && _asc$desc !== void 0 ? _asc$desc : null]
|
|
125
|
+
}, header.id);
|
|
126
|
+
})
|
|
127
|
+
}, headerGroup.id);
|
|
128
|
+
})
|
|
129
|
+
}) : null, jsxs(Box, {
|
|
130
|
+
as: "tbody",
|
|
131
|
+
children: [!renderRow ? table.getRowModel().rows.map(function (row) {
|
|
132
|
+
return jsxs(React.Fragment, {
|
|
133
|
+
children: [jsx(Box, {
|
|
134
|
+
as: "tr",
|
|
135
|
+
css: css({
|
|
136
|
+
'&[data-is-selected="true"],&[data-is-expanded="true"]': {
|
|
137
|
+
backgroundColor: theme.color.background.primarySoft
|
|
138
|
+
},
|
|
139
|
+
':hover': {
|
|
140
|
+
backgroundColor: theme.color.background.inputPressed,
|
|
141
|
+
cursor: enableClickableRow ? 'pointer' : undefined
|
|
142
|
+
}
|
|
143
|
+
}, rowClassName ? rowClassName(row, row.index) : undefined),
|
|
144
|
+
onClick: function onClick() {
|
|
145
|
+
return enableClickableRow && (onRowClick ? onRowClick(row) : defaultOnRowClick(row));
|
|
146
|
+
},
|
|
147
|
+
"data-is-selected": row.getIsSelected(),
|
|
148
|
+
"data-is-expanded": row.getIsExpanded(),
|
|
149
|
+
children: row.getVisibleCells().map(function (cell) {
|
|
150
|
+
return jsx(Box, {
|
|
151
|
+
as: "td",
|
|
152
|
+
padding: "large",
|
|
153
|
+
css: css({
|
|
154
|
+
borderBottomWidth: theme.border.width.standard,
|
|
155
|
+
borderBottomStyle: 'solid',
|
|
156
|
+
borderColor: theme.border.color.standard,
|
|
157
|
+
verticalAlign: 'middle',
|
|
158
|
+
textAlign: 'left'
|
|
159
|
+
}),
|
|
160
|
+
children: flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
161
|
+
}, cell.id);
|
|
162
|
+
})
|
|
163
|
+
}), enableExpanding && row.getIsExpanded() && expandedRowComponent && expandedRowComponent(row, table)]
|
|
164
|
+
}, row.id);
|
|
165
|
+
}) : renderRow(table), showSpinner && jsx(InView, {
|
|
166
|
+
as: "tr"
|
|
167
|
+
// @ts-ignore
|
|
168
|
+
,
|
|
169
|
+
css: css({
|
|
170
|
+
columnSpan: 'all'
|
|
171
|
+
}),
|
|
172
|
+
onChange: onBottomSpinnerShown,
|
|
173
|
+
children: jsx(Box, {
|
|
174
|
+
as: "td",
|
|
175
|
+
padding: "large",
|
|
176
|
+
colSpan: headerGroups.map(function (hg) {
|
|
177
|
+
return hg.headers.length;
|
|
178
|
+
}).reduce(function (sum, len) {
|
|
179
|
+
return len + 1;
|
|
180
|
+
}, 0),
|
|
181
|
+
css: css({
|
|
182
|
+
textAlign: 'center',
|
|
183
|
+
verticalAlign: 'middle'
|
|
184
|
+
}),
|
|
185
|
+
children: jsx(Spinner, {
|
|
186
|
+
data: {
|
|
187
|
+
testId: 'data-table-spinner'
|
|
188
|
+
},
|
|
189
|
+
size: "xsmall"
|
|
190
|
+
})
|
|
191
|
+
})
|
|
192
|
+
})]
|
|
193
|
+
}), footerGroups.length > 0 ? jsx(Box, {
|
|
194
|
+
as: "tfoot",
|
|
195
|
+
css: css(footerClassName),
|
|
196
|
+
children: footerGroups.map(function (footerGroup) {
|
|
197
|
+
return jsx(Box, {
|
|
198
|
+
as: "tr",
|
|
199
|
+
children: footerGroup.headers.map(function (footer) {
|
|
200
|
+
return jsx(Box, {
|
|
201
|
+
as: "td",
|
|
202
|
+
children: flexRender(footer.column.columnDef.footer, footer.getContext())
|
|
203
|
+
}, footer.id);
|
|
204
|
+
})
|
|
205
|
+
}, footerGroup.id);
|
|
206
|
+
})
|
|
207
|
+
}) : null]
|
|
208
|
+
}));
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export { DataTable };
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@spark-web/data-table",
|
|
3
|
+
"version": "0.0.0-snapshot-release-20260408010050",
|
|
4
|
+
"homepage": "https://github.com/brighte-labs/spark-web#readme",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/brighte-labs/spark-web.git",
|
|
8
|
+
"directory": "packages/data-table"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"main": "dist/spark-web-data-table.cjs.js",
|
|
12
|
+
"module": "dist/spark-web-data-table.esm.js",
|
|
13
|
+
"files": [
|
|
14
|
+
"CHANGELOG.md",
|
|
15
|
+
"CLAUDE.md",
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@babel/runtime": "^7.25.0",
|
|
21
|
+
"@emotion/react": "^11.14.0",
|
|
22
|
+
"@spark-web/a11y": "^5.3.0",
|
|
23
|
+
"@spark-web/box": "^6.0.0",
|
|
24
|
+
"@spark-web/checkbox": "^5.1.0",
|
|
25
|
+
"@spark-web/icon": "^5.1.0",
|
|
26
|
+
"@spark-web/spinner": "^5.1.0",
|
|
27
|
+
"@spark-web/text": "^5.3.0",
|
|
28
|
+
"@spark-web/theme": "^5.13.0",
|
|
29
|
+
"@spark-web/utils": "^5.1.0",
|
|
30
|
+
"@tanstack/react-table": "^8.14.0",
|
|
31
|
+
"react-intersection-observer": "^9.8.2"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/react": "^19.1.0",
|
|
35
|
+
"react": "^19.1.0"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"react": "^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
}
|
|
43
|
+
}
|