@spark-web/data-table 1.0.0-rc.0 → 1.0.0-rc.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/CHANGELOG.md +17 -0
- package/dist/declarations/src/data-table.d.ts +29 -0
- package/dist/declarations/src/index.d.ts +2 -0
- package/dist/spark-web-data-table.cjs.d.ts +2 -2
- package/dist/spark-web-data-table.cjs.dev.js +196 -0
- package/dist/spark-web-data-table.cjs.js +6 -15
- package/dist/spark-web-data-table.cjs.prod.js +196 -0
- package/dist/spark-web-data-table.esm.js +181 -0
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @spark-web/data-table
|
|
2
2
|
|
|
3
|
+
## 1.0.0-rc.1
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- rc
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies []:
|
|
12
|
+
- @spark-web/checkbox@2.0.0-rc.1
|
|
13
|
+
- @spark-web/spinner@2.0.0-rc.1
|
|
14
|
+
- @spark-web/theme@4.0.0-rc.1
|
|
15
|
+
- @spark-web/utils@2.0.0-rc.1
|
|
16
|
+
- @spark-web/a11y@2.0.0-rc.1
|
|
17
|
+
- @spark-web/text@2.0.0-rc.1
|
|
18
|
+
- @spark-web/box@2.0.0-rc.1
|
|
19
|
+
|
|
3
20
|
## 1.0.0-rc.0
|
|
4
21
|
|
|
5
22
|
### Major Changes
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { SerializedStyles } from '@emotion/react';
|
|
2
|
+
import { type DataAttributeMap } from '@spark-web/utils/internal';
|
|
3
|
+
import type { ColumnDef, ColumnHelper, ExpandedState, OnChangeFn, Row, Table, TableOptions } from '@tanstack/react-table';
|
|
4
|
+
import { createColumnHelper, flexRender } from '@tanstack/react-table';
|
|
5
|
+
import type { HTMLAttributes, ReactElement } from 'react';
|
|
6
|
+
/**
|
|
7
|
+
* DataTable
|
|
8
|
+
*
|
|
9
|
+
* @see https://spark.brighte.com.au/package/data-table
|
|
10
|
+
*/
|
|
11
|
+
declare function DataTable<T>({ data, items, className, columns, enableExpanding, enableHiding, enableMultiRowSelection, enableClickableRow, headerClassName, footerClassName, showBottomSpinner: showSpinner, rowClassName, expandedRowComponent, onBottomSpinnerShown, onRowClick, onRowSelectionChange, renderRow, ...tableOptions }: DataTableProps<T>): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
12
|
+
declare type TableSubsetAttributes = Pick<HTMLAttributes<HTMLTableElement>, 'className'>;
|
|
13
|
+
declare type TableSubsetOptions<T> = Pick<TableOptions<T>, 'columns' | 'enableExpanding' | 'enableHiding' | 'enableMultiRowSelection' | 'state' | 'onStateChange' | 'onExpandedChange' | 'onRowSelectionChange' | 'getRowId'>;
|
|
14
|
+
declare type DataTableProps<T> = TableSubsetAttributes & TableSubsetOptions<T> & {
|
|
15
|
+
headerClassName?: SerializedStyles;
|
|
16
|
+
footerClassName?: string;
|
|
17
|
+
rowClassName?: (row: Row<T>, index: number) => SerializedStyles;
|
|
18
|
+
/** Map of data attributes. */
|
|
19
|
+
data?: DataAttributeMap;
|
|
20
|
+
items: Array<T>;
|
|
21
|
+
enableClickableRow?: boolean;
|
|
22
|
+
showBottomSpinner?: boolean;
|
|
23
|
+
expandedRowComponent?: (row: Row<T>, table?: Table<T>) => ReactElement<T>;
|
|
24
|
+
onBottomSpinnerShown?: (isInView: boolean) => void;
|
|
25
|
+
onRowClick?: (row: Row<T>) => void;
|
|
26
|
+
renderRow?: (table: Table<T>) => ReactElement<T>;
|
|
27
|
+
};
|
|
28
|
+
export { createColumnHelper, DataTable, flexRender };
|
|
29
|
+
export type { ColumnDef, ColumnHelper, DataTableProps, Row as DataTableRow, ExpandedState, OnChangeFn, };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "
|
|
2
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
1
|
+
export * from "./declarations/src/index";
|
|
2
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3Bhcmstd2ViLWRhdGEtdGFibGUuY2pzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuL2RlY2xhcmF0aW9ucy9zcmMvaW5kZXguZC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSJ9
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
6
|
+
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
7
|
+
var react = require('@emotion/react');
|
|
8
|
+
var box = require('@spark-web/box');
|
|
9
|
+
var spinner = require('@spark-web/spinner');
|
|
10
|
+
var theme = require('@spark-web/theme');
|
|
11
|
+
var internal = require('@spark-web/utils/internal');
|
|
12
|
+
var reactTable = require('@tanstack/react-table');
|
|
13
|
+
var React = require('react');
|
|
14
|
+
var reactIntersectionObserver = require('react-intersection-observer');
|
|
15
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
16
|
+
|
|
17
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
18
|
+
|
|
19
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
20
|
+
|
|
21
|
+
var _excluded = ["data", "items", "className", "columns", "enableExpanding", "enableHiding", "enableMultiRowSelection", "enableClickableRow", "headerClassName", "footerClassName", "showBottomSpinner", "rowClassName", "expandedRowComponent", "onBottomSpinnerShown", "onRowClick", "onRowSelectionChange", "renderRow"];
|
|
22
|
+
function DataTable(_ref) {
|
|
23
|
+
var data = _ref.data,
|
|
24
|
+
items = _ref.items,
|
|
25
|
+
className = _ref.className,
|
|
26
|
+
columns = _ref.columns,
|
|
27
|
+
_ref$enableExpanding = _ref.enableExpanding,
|
|
28
|
+
enableExpanding = _ref$enableExpanding === void 0 ? false : _ref$enableExpanding,
|
|
29
|
+
_ref$enableHiding = _ref.enableHiding,
|
|
30
|
+
enableHiding = _ref$enableHiding === void 0 ? true : _ref$enableHiding,
|
|
31
|
+
_ref$enableMultiRowSe = _ref.enableMultiRowSelection,
|
|
32
|
+
enableMultiRowSelection = _ref$enableMultiRowSe === void 0 ? false : _ref$enableMultiRowSe,
|
|
33
|
+
enableClickableRow = _ref.enableClickableRow,
|
|
34
|
+
headerClassName = _ref.headerClassName,
|
|
35
|
+
footerClassName = _ref.footerClassName,
|
|
36
|
+
showSpinner = _ref.showBottomSpinner,
|
|
37
|
+
rowClassName = _ref.rowClassName,
|
|
38
|
+
expandedRowComponent = _ref.expandedRowComponent,
|
|
39
|
+
onBottomSpinnerShown = _ref.onBottomSpinnerShown,
|
|
40
|
+
onRowClick = _ref.onRowClick,
|
|
41
|
+
onRowSelectionChange = _ref.onRowSelectionChange,
|
|
42
|
+
renderRow = _ref.renderRow,
|
|
43
|
+
tableOptions = _objectWithoutProperties(_ref, _excluded);
|
|
44
|
+
var theme$1 = theme.useTheme();
|
|
45
|
+
var enableRowSelection = !!onRowSelectionChange;
|
|
46
|
+
var table = reactTable.useReactTable(_objectSpread(_objectSpread({
|
|
47
|
+
data: items,
|
|
48
|
+
enableExpanding: enableExpanding,
|
|
49
|
+
enableMultiRowSelection: enableMultiRowSelection,
|
|
50
|
+
enableHiding: enableHiding,
|
|
51
|
+
enableRowSelection: enableRowSelection,
|
|
52
|
+
onRowSelectionChange: onRowSelectionChange,
|
|
53
|
+
columns: columns
|
|
54
|
+
}, tableOptions), {}, {
|
|
55
|
+
getCoreRowModel: reactTable.getCoreRowModel(),
|
|
56
|
+
getExpandedRowModel: enableExpanding ? reactTable.getCoreRowModel() : undefined
|
|
57
|
+
}));
|
|
58
|
+
var headerGroups = table.getHeaderGroups();
|
|
59
|
+
var footerGroups = table.getFooterGroups();
|
|
60
|
+
var defaultOnRowClick = function defaultOnRowClick(row) {
|
|
61
|
+
return row.toggleSelected();
|
|
62
|
+
};
|
|
63
|
+
return /*#__PURE__*/jsxRuntime.jsxs(box.Box, _objectSpread(_objectSpread({
|
|
64
|
+
as: "table"
|
|
65
|
+
}, data ? internal.buildDataAttributes(data) : undefined), {}, {
|
|
66
|
+
className: className,
|
|
67
|
+
children: [headerGroups.length > 0 ? /*#__PURE__*/jsxRuntime.jsx(react.ClassNames, {
|
|
68
|
+
children: function children(_ref2) {
|
|
69
|
+
var css = _ref2.css,
|
|
70
|
+
cx = _ref2.cx;
|
|
71
|
+
return /*#__PURE__*/jsxRuntime.jsx(box.Box, {
|
|
72
|
+
as: "thead",
|
|
73
|
+
background: "neutral",
|
|
74
|
+
className: cx(css({
|
|
75
|
+
// we use box shadow instead of bottom border
|
|
76
|
+
// to allow the border to stay in the header on scroll
|
|
77
|
+
// when the table is sticky
|
|
78
|
+
boxShadow: "inset 0 -2px 0 ".concat(theme$1.border.color.primary)
|
|
79
|
+
}, headerClassName)),
|
|
80
|
+
children: headerGroups.map(function (headerGroup) {
|
|
81
|
+
return /*#__PURE__*/jsxRuntime.jsx(box.Box, {
|
|
82
|
+
as: "tr",
|
|
83
|
+
children: headerGroup.headers.map(function (header) {
|
|
84
|
+
return /*#__PURE__*/jsxRuntime.jsx(box.Box, {
|
|
85
|
+
as: "th",
|
|
86
|
+
color: theme$1.color.foreground.muted,
|
|
87
|
+
padding: "medium",
|
|
88
|
+
css: css({
|
|
89
|
+
fontFamily: theme$1.typography.fontFamily.sans.name,
|
|
90
|
+
fontWeight: theme$1.typography.fontWeight.semibold,
|
|
91
|
+
textAlign: 'left',
|
|
92
|
+
textTransform: 'uppercase'
|
|
93
|
+
}),
|
|
94
|
+
children: header.isPlaceholder ? null : reactTable.flexRender(header.column.columnDef.header, header.getContext())
|
|
95
|
+
}, header.id);
|
|
96
|
+
})
|
|
97
|
+
}, headerGroup.id);
|
|
98
|
+
})
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}) : null, /*#__PURE__*/jsxRuntime.jsxs(box.Box, {
|
|
102
|
+
as: "tbody",
|
|
103
|
+
children: [!renderRow ? table.getRowModel().rows.map(function (row) {
|
|
104
|
+
return /*#__PURE__*/jsxRuntime.jsxs(React__default["default"].Fragment, {
|
|
105
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(box.Box, {
|
|
106
|
+
as: "tr",
|
|
107
|
+
css: react.css({
|
|
108
|
+
'&[data-is-selected="true"],&[data-is-expanded="true"]': {
|
|
109
|
+
background: theme$1.color.background.primaryMuted
|
|
110
|
+
},
|
|
111
|
+
':hover': {
|
|
112
|
+
background: theme$1.backgroundInteractions.neutralHover,
|
|
113
|
+
cursor: enableClickableRow ? 'pointer' : undefined
|
|
114
|
+
}
|
|
115
|
+
}, rowClassName ? rowClassName(row, row.index) : undefined),
|
|
116
|
+
onClick: function onClick() {
|
|
117
|
+
return enableClickableRow && (onRowClick ? onRowClick(row) : defaultOnRowClick(row));
|
|
118
|
+
},
|
|
119
|
+
"data-is-selected": row.getIsSelected(),
|
|
120
|
+
"data-is-expanded": row.getIsExpanded(),
|
|
121
|
+
children: row.getVisibleCells().map(function (cell) {
|
|
122
|
+
return /*#__PURE__*/jsxRuntime.jsx(box.Box, {
|
|
123
|
+
as: "td",
|
|
124
|
+
padding: "large",
|
|
125
|
+
css: react.css({
|
|
126
|
+
borderBottom: '1px',
|
|
127
|
+
borderBottomStyle: 'solid',
|
|
128
|
+
borderColor: theme$1.border.color.standard,
|
|
129
|
+
verticalAlign: 'middle',
|
|
130
|
+
textAlign: 'left'
|
|
131
|
+
}),
|
|
132
|
+
children: reactTable.flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
133
|
+
}, cell.id);
|
|
134
|
+
})
|
|
135
|
+
}), enableExpanding && row.getIsExpanded() && expandedRowComponent && expandedRowComponent(row, table)]
|
|
136
|
+
}, row.id);
|
|
137
|
+
}) : renderRow(table), showSpinner && /*#__PURE__*/jsxRuntime.jsx(reactIntersectionObserver.InView, {
|
|
138
|
+
as: "tr"
|
|
139
|
+
// @ts-ignore
|
|
140
|
+
,
|
|
141
|
+
className: react.css({
|
|
142
|
+
columnSpan: 'all'
|
|
143
|
+
}),
|
|
144
|
+
onChange: onBottomSpinnerShown,
|
|
145
|
+
children: /*#__PURE__*/jsxRuntime.jsx(box.Box, {
|
|
146
|
+
as: "td",
|
|
147
|
+
padding: "large",
|
|
148
|
+
colSpan: headerGroups.map(function (hg) {
|
|
149
|
+
return hg.headers.length;
|
|
150
|
+
}).reduce(function (sum, len) {
|
|
151
|
+
return len + 1;
|
|
152
|
+
}, 0),
|
|
153
|
+
css: react.css({
|
|
154
|
+
textAlign: 'center',
|
|
155
|
+
verticalAlign: 'middle'
|
|
156
|
+
}),
|
|
157
|
+
children: /*#__PURE__*/jsxRuntime.jsx(spinner.Spinner, {
|
|
158
|
+
data: {
|
|
159
|
+
testId: 'data-table-spinner'
|
|
160
|
+
},
|
|
161
|
+
size: "xsmall"
|
|
162
|
+
})
|
|
163
|
+
})
|
|
164
|
+
})]
|
|
165
|
+
}), footerGroups.length > 0 ? /*#__PURE__*/jsxRuntime.jsx(react.ClassNames, {
|
|
166
|
+
children: function children(_ref3) {
|
|
167
|
+
var cx = _ref3.cx;
|
|
168
|
+
return /*#__PURE__*/jsxRuntime.jsx(box.Box, {
|
|
169
|
+
as: "tfoot",
|
|
170
|
+
className: cx(footerClassName),
|
|
171
|
+
children: footerGroups.map(function (footerGroup) {
|
|
172
|
+
return /*#__PURE__*/jsxRuntime.jsx(box.Box, {
|
|
173
|
+
as: "tr",
|
|
174
|
+
children: footerGroup.headers.map(function (footer) {
|
|
175
|
+
return /*#__PURE__*/jsxRuntime.jsx(box.Box, {
|
|
176
|
+
as: "td",
|
|
177
|
+
children: reactTable.flexRender(footer.column.columnDef.footer, footer.getContext())
|
|
178
|
+
}, footer.id);
|
|
179
|
+
})
|
|
180
|
+
}, footerGroup.id);
|
|
181
|
+
})
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}) : null]
|
|
185
|
+
}));
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
Object.defineProperty(exports, 'createColumnHelper', {
|
|
189
|
+
enumerable: true,
|
|
190
|
+
get: function () { return reactTable.createColumnHelper; }
|
|
191
|
+
});
|
|
192
|
+
Object.defineProperty(exports, 'flexRender', {
|
|
193
|
+
enumerable: true,
|
|
194
|
+
get: function () { return reactTable.flexRender; }
|
|
195
|
+
});
|
|
196
|
+
exports.DataTable = DataTable;
|
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
// this file might look strange and you might be wondering what it's for
|
|
3
|
-
// it's lets you import your source files by importing this entrypoint
|
|
4
|
-
// as you would import it if it was built with preconstruct build
|
|
5
|
-
// this file is slightly different to some others though
|
|
6
|
-
// it has a require hook which compiles your code with Babel
|
|
7
|
-
// this means that you don't have to set up @babel/register or anything like that
|
|
8
|
-
// but you can still require this module and it'll be compiled
|
|
1
|
+
'use strict';
|
|
9
2
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
unregister();
|
|
3
|
+
if (process.env.NODE_ENV === "production") {
|
|
4
|
+
module.exports = require("./spark-web-data-table.cjs.prod.js");
|
|
5
|
+
} else {
|
|
6
|
+
module.exports = require("./spark-web-data-table.cjs.dev.js");
|
|
7
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
6
|
+
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
7
|
+
var react = require('@emotion/react');
|
|
8
|
+
var box = require('@spark-web/box');
|
|
9
|
+
var spinner = require('@spark-web/spinner');
|
|
10
|
+
var theme = require('@spark-web/theme');
|
|
11
|
+
var internal = require('@spark-web/utils/internal');
|
|
12
|
+
var reactTable = require('@tanstack/react-table');
|
|
13
|
+
var React = require('react');
|
|
14
|
+
var reactIntersectionObserver = require('react-intersection-observer');
|
|
15
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
16
|
+
|
|
17
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
18
|
+
|
|
19
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
20
|
+
|
|
21
|
+
var _excluded = ["data", "items", "className", "columns", "enableExpanding", "enableHiding", "enableMultiRowSelection", "enableClickableRow", "headerClassName", "footerClassName", "showBottomSpinner", "rowClassName", "expandedRowComponent", "onBottomSpinnerShown", "onRowClick", "onRowSelectionChange", "renderRow"];
|
|
22
|
+
function DataTable(_ref) {
|
|
23
|
+
var data = _ref.data,
|
|
24
|
+
items = _ref.items,
|
|
25
|
+
className = _ref.className,
|
|
26
|
+
columns = _ref.columns,
|
|
27
|
+
_ref$enableExpanding = _ref.enableExpanding,
|
|
28
|
+
enableExpanding = _ref$enableExpanding === void 0 ? false : _ref$enableExpanding,
|
|
29
|
+
_ref$enableHiding = _ref.enableHiding,
|
|
30
|
+
enableHiding = _ref$enableHiding === void 0 ? true : _ref$enableHiding,
|
|
31
|
+
_ref$enableMultiRowSe = _ref.enableMultiRowSelection,
|
|
32
|
+
enableMultiRowSelection = _ref$enableMultiRowSe === void 0 ? false : _ref$enableMultiRowSe,
|
|
33
|
+
enableClickableRow = _ref.enableClickableRow,
|
|
34
|
+
headerClassName = _ref.headerClassName,
|
|
35
|
+
footerClassName = _ref.footerClassName,
|
|
36
|
+
showSpinner = _ref.showBottomSpinner,
|
|
37
|
+
rowClassName = _ref.rowClassName,
|
|
38
|
+
expandedRowComponent = _ref.expandedRowComponent,
|
|
39
|
+
onBottomSpinnerShown = _ref.onBottomSpinnerShown,
|
|
40
|
+
onRowClick = _ref.onRowClick,
|
|
41
|
+
onRowSelectionChange = _ref.onRowSelectionChange,
|
|
42
|
+
renderRow = _ref.renderRow,
|
|
43
|
+
tableOptions = _objectWithoutProperties(_ref, _excluded);
|
|
44
|
+
var theme$1 = theme.useTheme();
|
|
45
|
+
var enableRowSelection = !!onRowSelectionChange;
|
|
46
|
+
var table = reactTable.useReactTable(_objectSpread(_objectSpread({
|
|
47
|
+
data: items,
|
|
48
|
+
enableExpanding: enableExpanding,
|
|
49
|
+
enableMultiRowSelection: enableMultiRowSelection,
|
|
50
|
+
enableHiding: enableHiding,
|
|
51
|
+
enableRowSelection: enableRowSelection,
|
|
52
|
+
onRowSelectionChange: onRowSelectionChange,
|
|
53
|
+
columns: columns
|
|
54
|
+
}, tableOptions), {}, {
|
|
55
|
+
getCoreRowModel: reactTable.getCoreRowModel(),
|
|
56
|
+
getExpandedRowModel: enableExpanding ? reactTable.getCoreRowModel() : undefined
|
|
57
|
+
}));
|
|
58
|
+
var headerGroups = table.getHeaderGroups();
|
|
59
|
+
var footerGroups = table.getFooterGroups();
|
|
60
|
+
var defaultOnRowClick = function defaultOnRowClick(row) {
|
|
61
|
+
return row.toggleSelected();
|
|
62
|
+
};
|
|
63
|
+
return /*#__PURE__*/jsxRuntime.jsxs(box.Box, _objectSpread(_objectSpread({
|
|
64
|
+
as: "table"
|
|
65
|
+
}, data ? internal.buildDataAttributes(data) : undefined), {}, {
|
|
66
|
+
className: className,
|
|
67
|
+
children: [headerGroups.length > 0 ? /*#__PURE__*/jsxRuntime.jsx(react.ClassNames, {
|
|
68
|
+
children: function children(_ref2) {
|
|
69
|
+
var css = _ref2.css,
|
|
70
|
+
cx = _ref2.cx;
|
|
71
|
+
return /*#__PURE__*/jsxRuntime.jsx(box.Box, {
|
|
72
|
+
as: "thead",
|
|
73
|
+
background: "neutral",
|
|
74
|
+
className: cx(css({
|
|
75
|
+
// we use box shadow instead of bottom border
|
|
76
|
+
// to allow the border to stay in the header on scroll
|
|
77
|
+
// when the table is sticky
|
|
78
|
+
boxShadow: "inset 0 -2px 0 ".concat(theme$1.border.color.primary)
|
|
79
|
+
}, headerClassName)),
|
|
80
|
+
children: headerGroups.map(function (headerGroup) {
|
|
81
|
+
return /*#__PURE__*/jsxRuntime.jsx(box.Box, {
|
|
82
|
+
as: "tr",
|
|
83
|
+
children: headerGroup.headers.map(function (header) {
|
|
84
|
+
return /*#__PURE__*/jsxRuntime.jsx(box.Box, {
|
|
85
|
+
as: "th",
|
|
86
|
+
color: theme$1.color.foreground.muted,
|
|
87
|
+
padding: "medium",
|
|
88
|
+
css: css({
|
|
89
|
+
fontFamily: theme$1.typography.fontFamily.sans.name,
|
|
90
|
+
fontWeight: theme$1.typography.fontWeight.semibold,
|
|
91
|
+
textAlign: 'left',
|
|
92
|
+
textTransform: 'uppercase'
|
|
93
|
+
}),
|
|
94
|
+
children: header.isPlaceholder ? null : reactTable.flexRender(header.column.columnDef.header, header.getContext())
|
|
95
|
+
}, header.id);
|
|
96
|
+
})
|
|
97
|
+
}, headerGroup.id);
|
|
98
|
+
})
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}) : null, /*#__PURE__*/jsxRuntime.jsxs(box.Box, {
|
|
102
|
+
as: "tbody",
|
|
103
|
+
children: [!renderRow ? table.getRowModel().rows.map(function (row) {
|
|
104
|
+
return /*#__PURE__*/jsxRuntime.jsxs(React__default["default"].Fragment, {
|
|
105
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(box.Box, {
|
|
106
|
+
as: "tr",
|
|
107
|
+
css: react.css({
|
|
108
|
+
'&[data-is-selected="true"],&[data-is-expanded="true"]': {
|
|
109
|
+
background: theme$1.color.background.primaryMuted
|
|
110
|
+
},
|
|
111
|
+
':hover': {
|
|
112
|
+
background: theme$1.backgroundInteractions.neutralHover,
|
|
113
|
+
cursor: enableClickableRow ? 'pointer' : undefined
|
|
114
|
+
}
|
|
115
|
+
}, rowClassName ? rowClassName(row, row.index) : undefined),
|
|
116
|
+
onClick: function onClick() {
|
|
117
|
+
return enableClickableRow && (onRowClick ? onRowClick(row) : defaultOnRowClick(row));
|
|
118
|
+
},
|
|
119
|
+
"data-is-selected": row.getIsSelected(),
|
|
120
|
+
"data-is-expanded": row.getIsExpanded(),
|
|
121
|
+
children: row.getVisibleCells().map(function (cell) {
|
|
122
|
+
return /*#__PURE__*/jsxRuntime.jsx(box.Box, {
|
|
123
|
+
as: "td",
|
|
124
|
+
padding: "large",
|
|
125
|
+
css: react.css({
|
|
126
|
+
borderBottom: '1px',
|
|
127
|
+
borderBottomStyle: 'solid',
|
|
128
|
+
borderColor: theme$1.border.color.standard,
|
|
129
|
+
verticalAlign: 'middle',
|
|
130
|
+
textAlign: 'left'
|
|
131
|
+
}),
|
|
132
|
+
children: reactTable.flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
133
|
+
}, cell.id);
|
|
134
|
+
})
|
|
135
|
+
}), enableExpanding && row.getIsExpanded() && expandedRowComponent && expandedRowComponent(row, table)]
|
|
136
|
+
}, row.id);
|
|
137
|
+
}) : renderRow(table), showSpinner && /*#__PURE__*/jsxRuntime.jsx(reactIntersectionObserver.InView, {
|
|
138
|
+
as: "tr"
|
|
139
|
+
// @ts-ignore
|
|
140
|
+
,
|
|
141
|
+
className: react.css({
|
|
142
|
+
columnSpan: 'all'
|
|
143
|
+
}),
|
|
144
|
+
onChange: onBottomSpinnerShown,
|
|
145
|
+
children: /*#__PURE__*/jsxRuntime.jsx(box.Box, {
|
|
146
|
+
as: "td",
|
|
147
|
+
padding: "large",
|
|
148
|
+
colSpan: headerGroups.map(function (hg) {
|
|
149
|
+
return hg.headers.length;
|
|
150
|
+
}).reduce(function (sum, len) {
|
|
151
|
+
return len + 1;
|
|
152
|
+
}, 0),
|
|
153
|
+
css: react.css({
|
|
154
|
+
textAlign: 'center',
|
|
155
|
+
verticalAlign: 'middle'
|
|
156
|
+
}),
|
|
157
|
+
children: /*#__PURE__*/jsxRuntime.jsx(spinner.Spinner, {
|
|
158
|
+
data: {
|
|
159
|
+
testId: 'data-table-spinner'
|
|
160
|
+
},
|
|
161
|
+
size: "xsmall"
|
|
162
|
+
})
|
|
163
|
+
})
|
|
164
|
+
})]
|
|
165
|
+
}), footerGroups.length > 0 ? /*#__PURE__*/jsxRuntime.jsx(react.ClassNames, {
|
|
166
|
+
children: function children(_ref3) {
|
|
167
|
+
var cx = _ref3.cx;
|
|
168
|
+
return /*#__PURE__*/jsxRuntime.jsx(box.Box, {
|
|
169
|
+
as: "tfoot",
|
|
170
|
+
className: cx(footerClassName),
|
|
171
|
+
children: footerGroups.map(function (footerGroup) {
|
|
172
|
+
return /*#__PURE__*/jsxRuntime.jsx(box.Box, {
|
|
173
|
+
as: "tr",
|
|
174
|
+
children: footerGroup.headers.map(function (footer) {
|
|
175
|
+
return /*#__PURE__*/jsxRuntime.jsx(box.Box, {
|
|
176
|
+
as: "td",
|
|
177
|
+
children: reactTable.flexRender(footer.column.columnDef.footer, footer.getContext())
|
|
178
|
+
}, footer.id);
|
|
179
|
+
})
|
|
180
|
+
}, footerGroup.id);
|
|
181
|
+
})
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}) : null]
|
|
185
|
+
}));
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
Object.defineProperty(exports, 'createColumnHelper', {
|
|
189
|
+
enumerable: true,
|
|
190
|
+
get: function () { return reactTable.createColumnHelper; }
|
|
191
|
+
});
|
|
192
|
+
Object.defineProperty(exports, 'flexRender', {
|
|
193
|
+
enumerable: true,
|
|
194
|
+
get: function () { return reactTable.flexRender; }
|
|
195
|
+
});
|
|
196
|
+
exports.DataTable = DataTable;
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import _objectSpread from '@babel/runtime/helpers/esm/objectSpread2';
|
|
2
|
+
import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties';
|
|
3
|
+
import { ClassNames, css } from '@emotion/react';
|
|
4
|
+
import { Box } from '@spark-web/box';
|
|
5
|
+
import { Spinner } from '@spark-web/spinner';
|
|
6
|
+
import { useTheme } from '@spark-web/theme';
|
|
7
|
+
import { buildDataAttributes } from '@spark-web/utils/internal';
|
|
8
|
+
import { useReactTable, getCoreRowModel, flexRender } from '@tanstack/react-table';
|
|
9
|
+
export { createColumnHelper, flexRender } from '@tanstack/react-table';
|
|
10
|
+
import React from 'react';
|
|
11
|
+
import { InView } from 'react-intersection-observer';
|
|
12
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
13
|
+
|
|
14
|
+
var _excluded = ["data", "items", "className", "columns", "enableExpanding", "enableHiding", "enableMultiRowSelection", "enableClickableRow", "headerClassName", "footerClassName", "showBottomSpinner", "rowClassName", "expandedRowComponent", "onBottomSpinnerShown", "onRowClick", "onRowSelectionChange", "renderRow"];
|
|
15
|
+
function DataTable(_ref) {
|
|
16
|
+
var data = _ref.data,
|
|
17
|
+
items = _ref.items,
|
|
18
|
+
className = _ref.className,
|
|
19
|
+
columns = _ref.columns,
|
|
20
|
+
_ref$enableExpanding = _ref.enableExpanding,
|
|
21
|
+
enableExpanding = _ref$enableExpanding === void 0 ? false : _ref$enableExpanding,
|
|
22
|
+
_ref$enableHiding = _ref.enableHiding,
|
|
23
|
+
enableHiding = _ref$enableHiding === void 0 ? true : _ref$enableHiding,
|
|
24
|
+
_ref$enableMultiRowSe = _ref.enableMultiRowSelection,
|
|
25
|
+
enableMultiRowSelection = _ref$enableMultiRowSe === void 0 ? false : _ref$enableMultiRowSe,
|
|
26
|
+
enableClickableRow = _ref.enableClickableRow,
|
|
27
|
+
headerClassName = _ref.headerClassName,
|
|
28
|
+
footerClassName = _ref.footerClassName,
|
|
29
|
+
showSpinner = _ref.showBottomSpinner,
|
|
30
|
+
rowClassName = _ref.rowClassName,
|
|
31
|
+
expandedRowComponent = _ref.expandedRowComponent,
|
|
32
|
+
onBottomSpinnerShown = _ref.onBottomSpinnerShown,
|
|
33
|
+
onRowClick = _ref.onRowClick,
|
|
34
|
+
onRowSelectionChange = _ref.onRowSelectionChange,
|
|
35
|
+
renderRow = _ref.renderRow,
|
|
36
|
+
tableOptions = _objectWithoutProperties(_ref, _excluded);
|
|
37
|
+
var theme = useTheme();
|
|
38
|
+
var enableRowSelection = !!onRowSelectionChange;
|
|
39
|
+
var table = useReactTable(_objectSpread(_objectSpread({
|
|
40
|
+
data: items,
|
|
41
|
+
enableExpanding: enableExpanding,
|
|
42
|
+
enableMultiRowSelection: enableMultiRowSelection,
|
|
43
|
+
enableHiding: enableHiding,
|
|
44
|
+
enableRowSelection: enableRowSelection,
|
|
45
|
+
onRowSelectionChange: onRowSelectionChange,
|
|
46
|
+
columns: columns
|
|
47
|
+
}, tableOptions), {}, {
|
|
48
|
+
getCoreRowModel: getCoreRowModel(),
|
|
49
|
+
getExpandedRowModel: enableExpanding ? getCoreRowModel() : undefined
|
|
50
|
+
}));
|
|
51
|
+
var headerGroups = table.getHeaderGroups();
|
|
52
|
+
var footerGroups = table.getFooterGroups();
|
|
53
|
+
var defaultOnRowClick = function defaultOnRowClick(row) {
|
|
54
|
+
return row.toggleSelected();
|
|
55
|
+
};
|
|
56
|
+
return /*#__PURE__*/jsxs(Box, _objectSpread(_objectSpread({
|
|
57
|
+
as: "table"
|
|
58
|
+
}, data ? buildDataAttributes(data) : undefined), {}, {
|
|
59
|
+
className: className,
|
|
60
|
+
children: [headerGroups.length > 0 ? /*#__PURE__*/jsx(ClassNames, {
|
|
61
|
+
children: function children(_ref2) {
|
|
62
|
+
var css = _ref2.css,
|
|
63
|
+
cx = _ref2.cx;
|
|
64
|
+
return /*#__PURE__*/jsx(Box, {
|
|
65
|
+
as: "thead",
|
|
66
|
+
background: "neutral",
|
|
67
|
+
className: cx(css({
|
|
68
|
+
// we use box shadow instead of bottom border
|
|
69
|
+
// to allow the border to stay in the header on scroll
|
|
70
|
+
// when the table is sticky
|
|
71
|
+
boxShadow: "inset 0 -2px 0 ".concat(theme.border.color.primary)
|
|
72
|
+
}, headerClassName)),
|
|
73
|
+
children: headerGroups.map(function (headerGroup) {
|
|
74
|
+
return /*#__PURE__*/jsx(Box, {
|
|
75
|
+
as: "tr",
|
|
76
|
+
children: headerGroup.headers.map(function (header) {
|
|
77
|
+
return /*#__PURE__*/jsx(Box, {
|
|
78
|
+
as: "th",
|
|
79
|
+
color: theme.color.foreground.muted,
|
|
80
|
+
padding: "medium",
|
|
81
|
+
css: css({
|
|
82
|
+
fontFamily: theme.typography.fontFamily.sans.name,
|
|
83
|
+
fontWeight: theme.typography.fontWeight.semibold,
|
|
84
|
+
textAlign: 'left',
|
|
85
|
+
textTransform: 'uppercase'
|
|
86
|
+
}),
|
|
87
|
+
children: header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())
|
|
88
|
+
}, header.id);
|
|
89
|
+
})
|
|
90
|
+
}, headerGroup.id);
|
|
91
|
+
})
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}) : null, /*#__PURE__*/jsxs(Box, {
|
|
95
|
+
as: "tbody",
|
|
96
|
+
children: [!renderRow ? table.getRowModel().rows.map(function (row) {
|
|
97
|
+
return /*#__PURE__*/jsxs(React.Fragment, {
|
|
98
|
+
children: [/*#__PURE__*/jsx(Box, {
|
|
99
|
+
as: "tr",
|
|
100
|
+
css: css({
|
|
101
|
+
'&[data-is-selected="true"],&[data-is-expanded="true"]': {
|
|
102
|
+
background: theme.color.background.primaryMuted
|
|
103
|
+
},
|
|
104
|
+
':hover': {
|
|
105
|
+
background: theme.backgroundInteractions.neutralHover,
|
|
106
|
+
cursor: enableClickableRow ? 'pointer' : undefined
|
|
107
|
+
}
|
|
108
|
+
}, rowClassName ? rowClassName(row, row.index) : undefined),
|
|
109
|
+
onClick: function onClick() {
|
|
110
|
+
return enableClickableRow && (onRowClick ? onRowClick(row) : defaultOnRowClick(row));
|
|
111
|
+
},
|
|
112
|
+
"data-is-selected": row.getIsSelected(),
|
|
113
|
+
"data-is-expanded": row.getIsExpanded(),
|
|
114
|
+
children: row.getVisibleCells().map(function (cell) {
|
|
115
|
+
return /*#__PURE__*/jsx(Box, {
|
|
116
|
+
as: "td",
|
|
117
|
+
padding: "large",
|
|
118
|
+
css: css({
|
|
119
|
+
borderBottom: '1px',
|
|
120
|
+
borderBottomStyle: 'solid',
|
|
121
|
+
borderColor: theme.border.color.standard,
|
|
122
|
+
verticalAlign: 'middle',
|
|
123
|
+
textAlign: 'left'
|
|
124
|
+
}),
|
|
125
|
+
children: flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
126
|
+
}, cell.id);
|
|
127
|
+
})
|
|
128
|
+
}), enableExpanding && row.getIsExpanded() && expandedRowComponent && expandedRowComponent(row, table)]
|
|
129
|
+
}, row.id);
|
|
130
|
+
}) : renderRow(table), showSpinner && /*#__PURE__*/jsx(InView, {
|
|
131
|
+
as: "tr"
|
|
132
|
+
// @ts-ignore
|
|
133
|
+
,
|
|
134
|
+
className: css({
|
|
135
|
+
columnSpan: 'all'
|
|
136
|
+
}),
|
|
137
|
+
onChange: onBottomSpinnerShown,
|
|
138
|
+
children: /*#__PURE__*/jsx(Box, {
|
|
139
|
+
as: "td",
|
|
140
|
+
padding: "large",
|
|
141
|
+
colSpan: headerGroups.map(function (hg) {
|
|
142
|
+
return hg.headers.length;
|
|
143
|
+
}).reduce(function (sum, len) {
|
|
144
|
+
return len + 1;
|
|
145
|
+
}, 0),
|
|
146
|
+
css: css({
|
|
147
|
+
textAlign: 'center',
|
|
148
|
+
verticalAlign: 'middle'
|
|
149
|
+
}),
|
|
150
|
+
children: /*#__PURE__*/jsx(Spinner, {
|
|
151
|
+
data: {
|
|
152
|
+
testId: 'data-table-spinner'
|
|
153
|
+
},
|
|
154
|
+
size: "xsmall"
|
|
155
|
+
})
|
|
156
|
+
})
|
|
157
|
+
})]
|
|
158
|
+
}), footerGroups.length > 0 ? /*#__PURE__*/jsx(ClassNames, {
|
|
159
|
+
children: function children(_ref3) {
|
|
160
|
+
var cx = _ref3.cx;
|
|
161
|
+
return /*#__PURE__*/jsx(Box, {
|
|
162
|
+
as: "tfoot",
|
|
163
|
+
className: cx(footerClassName),
|
|
164
|
+
children: footerGroups.map(function (footerGroup) {
|
|
165
|
+
return /*#__PURE__*/jsx(Box, {
|
|
166
|
+
as: "tr",
|
|
167
|
+
children: footerGroup.headers.map(function (footer) {
|
|
168
|
+
return /*#__PURE__*/jsx(Box, {
|
|
169
|
+
as: "td",
|
|
170
|
+
children: flexRender(footer.column.columnDef.footer, footer.getContext())
|
|
171
|
+
}, footer.id);
|
|
172
|
+
})
|
|
173
|
+
}, footerGroup.id);
|
|
174
|
+
})
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}) : null]
|
|
178
|
+
}));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export { DataTable };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spark-web/data-table",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.1",
|
|
4
4
|
"homepage": "https://github.com/brighte-labs/spark-web#readme",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -18,13 +18,13 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@babel/runtime": "^7.25.0",
|
|
20
20
|
"@emotion/react": "^11.13.5",
|
|
21
|
-
"@spark-web/a11y": "^2.0.0-rc.
|
|
22
|
-
"@spark-web/box": "^2.0.0-rc.
|
|
23
|
-
"@spark-web/checkbox": "^2.0.0-rc.
|
|
24
|
-
"@spark-web/spinner": "^2.0.0-rc.
|
|
25
|
-
"@spark-web/text": "^2.0.0-rc.
|
|
26
|
-
"@spark-web/theme": "^4.0.0-rc.
|
|
27
|
-
"@spark-web/utils": "^2.0.0-rc.
|
|
21
|
+
"@spark-web/a11y": "^2.0.0-rc.1",
|
|
22
|
+
"@spark-web/box": "^2.0.0-rc.1",
|
|
23
|
+
"@spark-web/checkbox": "^2.0.0-rc.1",
|
|
24
|
+
"@spark-web/spinner": "^2.0.0-rc.1",
|
|
25
|
+
"@spark-web/text": "^2.0.0-rc.1",
|
|
26
|
+
"@spark-web/theme": "^4.0.0-rc.1",
|
|
27
|
+
"@spark-web/utils": "^2.0.0-rc.1",
|
|
28
28
|
"@tanstack/react-table": "^8.14.0",
|
|
29
29
|
"react-intersection-observer": "^9.8.2"
|
|
30
30
|
},
|