@spark-web/data-table 0.3.4 → 1.0.0-rc.0
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/spark-web-data-table.cjs.d.ts +2 -2
- package/dist/spark-web-data-table.cjs.js +15 -6
- package/package.json +9 -9
- package/dist/declarations/src/data-table.d.ts +0 -28
- package/dist/declarations/src/index.d.ts +0 -2
- package/dist/spark-web-data-table.cjs.dev.js +0 -183
- package/dist/spark-web-data-table.cjs.prod.js +0 -183
- package/dist/spark-web-data-table.esm.js +0 -168
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @spark-web/data-table
|
|
2
2
|
|
|
3
|
+
## 1.0.0-rc.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- rc versio
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies []:
|
|
12
|
+
- @spark-web/checkbox@2.0.0-rc.0
|
|
13
|
+
- @spark-web/spinner@2.0.0-rc.0
|
|
14
|
+
- @spark-web/theme@4.0.0-rc.0
|
|
15
|
+
- @spark-web/a11y@2.0.0-rc.0
|
|
16
|
+
- @spark-web/text@2.0.0-rc.0
|
|
17
|
+
- @spark-web/box@2.0.0-rc.0
|
|
18
|
+
- @spark-web/utils@2.0.0-rc.0
|
|
19
|
+
|
|
3
20
|
## 0.3.4
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "
|
|
2
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
1
|
+
export * from "../src/index";
|
|
2
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3Bhcmstd2ViLWRhdGEtdGFibGUuY2pzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEifQ==
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
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
|
|
2
9
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
10
|
+
// this bit of code imports the require hook and registers it
|
|
11
|
+
let unregister = require("../../../node_modules/@preconstruct/hook").___internalHook(typeof __dirname === 'undefined' ? undefined : __dirname, "../../..", "..");
|
|
12
|
+
|
|
13
|
+
// this re-exports the source file
|
|
14
|
+
module.exports = require("../src/index.ts");
|
|
15
|
+
|
|
16
|
+
unregister();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spark-web/data-table",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-rc.0",
|
|
4
4
|
"homepage": "https://github.com/brighte-labs/spark-web#readme",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -17,14 +17,14 @@
|
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@babel/runtime": "^7.25.0",
|
|
20
|
-
"@emotion/
|
|
21
|
-
"@spark-web/a11y": "^
|
|
22
|
-
"@spark-web/box": "^
|
|
23
|
-
"@spark-web/checkbox": "^
|
|
24
|
-
"@spark-web/spinner": "^
|
|
25
|
-
"@spark-web/text": "^
|
|
26
|
-
"@spark-web/theme": "^
|
|
27
|
-
"@spark-web/utils": "^
|
|
20
|
+
"@emotion/react": "^11.13.5",
|
|
21
|
+
"@spark-web/a11y": "^2.0.0-rc.0",
|
|
22
|
+
"@spark-web/box": "^2.0.0-rc.0",
|
|
23
|
+
"@spark-web/checkbox": "^2.0.0-rc.0",
|
|
24
|
+
"@spark-web/spinner": "^2.0.0-rc.0",
|
|
25
|
+
"@spark-web/text": "^2.0.0-rc.0",
|
|
26
|
+
"@spark-web/theme": "^4.0.0-rc.0",
|
|
27
|
+
"@spark-web/utils": "^2.0.0-rc.0",
|
|
28
28
|
"@tanstack/react-table": "^8.14.0",
|
|
29
29
|
"react-intersection-observer": "^9.8.2"
|
|
30
30
|
},
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { type DataAttributeMap } from '@spark-web/utils/internal';
|
|
2
|
-
import type { ColumnDef, ColumnHelper, ExpandedState, OnChangeFn, Row, Table, TableOptions } from '@tanstack/react-table';
|
|
3
|
-
import { createColumnHelper, flexRender } from '@tanstack/react-table';
|
|
4
|
-
import type { HTMLAttributes, ReactElement } from 'react';
|
|
5
|
-
/**
|
|
6
|
-
* DataTable
|
|
7
|
-
*
|
|
8
|
-
* @see https://spark.brighte.com.au/package/data-table
|
|
9
|
-
*/
|
|
10
|
-
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("react/jsx-runtime").JSX.Element;
|
|
11
|
-
declare type TableSubsetAttributes = Pick<HTMLAttributes<HTMLTableElement>, 'className'>;
|
|
12
|
-
declare type TableSubsetOptions<T> = Pick<TableOptions<T>, 'columns' | 'enableExpanding' | 'enableHiding' | 'enableMultiRowSelection' | 'state' | 'onStateChange' | 'onExpandedChange' | 'onRowSelectionChange' | 'getRowId'>;
|
|
13
|
-
declare type DataTableProps<T> = TableSubsetAttributes & TableSubsetOptions<T> & {
|
|
14
|
-
headerClassName?: string;
|
|
15
|
-
footerClassName?: string;
|
|
16
|
-
rowClassName?: (row: Row<T>, index: number) => string;
|
|
17
|
-
/** Map of data attributes. */
|
|
18
|
-
data?: DataAttributeMap;
|
|
19
|
-
items: Array<T>;
|
|
20
|
-
enableClickableRow?: boolean;
|
|
21
|
-
showBottomSpinner?: boolean;
|
|
22
|
-
expandedRowComponent?: (row: Row<T>, table?: Table<T>) => ReactElement<T>;
|
|
23
|
-
onBottomSpinnerShown?: (isInView: boolean) => void;
|
|
24
|
-
onRowClick?: (row: Row<T>) => void;
|
|
25
|
-
renderRow?: (table: Table<T>) => ReactElement<T>;
|
|
26
|
-
};
|
|
27
|
-
export { createColumnHelper, DataTable, flexRender };
|
|
28
|
-
export type { ColumnDef, ColumnHelper, DataTableProps, Row as DataTableRow, ExpandedState, OnChangeFn, };
|
|
@@ -1,183 +0,0 @@
|
|
|
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 css = require('@emotion/css');
|
|
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(box.Box, {
|
|
68
|
-
as: "thead",
|
|
69
|
-
background: "neutral",
|
|
70
|
-
className: css.cx(css.css({
|
|
71
|
-
// we use box shadow instead of bottom border
|
|
72
|
-
// to allow the border to stay in the header on scroll
|
|
73
|
-
// when the table is sticky
|
|
74
|
-
boxShadow: "inset 0 -2px 0 ".concat(theme$1.border.color.primary)
|
|
75
|
-
}, headerClassName)),
|
|
76
|
-
children: headerGroups.map(function (headerGroup) {
|
|
77
|
-
return /*#__PURE__*/jsxRuntime.jsx(box.Box, {
|
|
78
|
-
as: "tr",
|
|
79
|
-
children: headerGroup.headers.map(function (header) {
|
|
80
|
-
return /*#__PURE__*/jsxRuntime.jsx(box.Box, {
|
|
81
|
-
as: "th",
|
|
82
|
-
color: theme$1.color.foreground.muted,
|
|
83
|
-
padding: "medium",
|
|
84
|
-
className: css.css({
|
|
85
|
-
fontFamily: theme$1.typography.fontFamily.sans.name,
|
|
86
|
-
fontWeight: theme$1.typography.fontWeight.semibold,
|
|
87
|
-
textAlign: 'left',
|
|
88
|
-
textTransform: 'uppercase'
|
|
89
|
-
}),
|
|
90
|
-
children: header.isPlaceholder ? null : reactTable.flexRender(header.column.columnDef.header, header.getContext())
|
|
91
|
-
}, header.id);
|
|
92
|
-
})
|
|
93
|
-
}, headerGroup.id);
|
|
94
|
-
})
|
|
95
|
-
}) : null, /*#__PURE__*/jsxRuntime.jsxs(box.Box, {
|
|
96
|
-
as: "tbody",
|
|
97
|
-
children: [!renderRow ? table.getRowModel().rows.map(function (row) {
|
|
98
|
-
return /*#__PURE__*/jsxRuntime.jsxs(React__default["default"].Fragment, {
|
|
99
|
-
children: [/*#__PURE__*/jsxRuntime.jsx(box.Box, {
|
|
100
|
-
as: "tr",
|
|
101
|
-
className: css.css({
|
|
102
|
-
'&[data-is-selected="true"],&[data-is-expanded="true"]': {
|
|
103
|
-
background: theme$1.color.background.primaryMuted
|
|
104
|
-
},
|
|
105
|
-
':hover': {
|
|
106
|
-
background: theme$1.backgroundInteractions.neutralHover,
|
|
107
|
-
cursor: enableClickableRow ? 'pointer' : undefined
|
|
108
|
-
}
|
|
109
|
-
}, rowClassName ? rowClassName(row, row.index) : undefined),
|
|
110
|
-
onClick: function onClick() {
|
|
111
|
-
return enableClickableRow && (onRowClick ? onRowClick(row) : defaultOnRowClick(row));
|
|
112
|
-
},
|
|
113
|
-
"data-is-selected": row.getIsSelected(),
|
|
114
|
-
"data-is-expanded": row.getIsExpanded(),
|
|
115
|
-
children: row.getVisibleCells().map(function (cell) {
|
|
116
|
-
return /*#__PURE__*/jsxRuntime.jsx(box.Box, {
|
|
117
|
-
as: "td",
|
|
118
|
-
padding: "large",
|
|
119
|
-
className: css.css({
|
|
120
|
-
borderBottom: '1px',
|
|
121
|
-
borderBottomStyle: 'solid',
|
|
122
|
-
borderColor: theme$1.border.color.standard,
|
|
123
|
-
verticalAlign: 'middle',
|
|
124
|
-
textAlign: 'left'
|
|
125
|
-
}),
|
|
126
|
-
children: reactTable.flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
127
|
-
}, cell.id);
|
|
128
|
-
})
|
|
129
|
-
}), enableExpanding && row.getIsExpanded() && expandedRowComponent && expandedRowComponent(row, table)]
|
|
130
|
-
}, row.id);
|
|
131
|
-
}) : renderRow(table), showSpinner && /*#__PURE__*/jsxRuntime.jsx(reactIntersectionObserver.InView, {
|
|
132
|
-
as: "tr",
|
|
133
|
-
className: css.css({
|
|
134
|
-
columnSpan: 'all'
|
|
135
|
-
}),
|
|
136
|
-
onChange: onBottomSpinnerShown,
|
|
137
|
-
children: /*#__PURE__*/jsxRuntime.jsx(box.Box, {
|
|
138
|
-
as: "td",
|
|
139
|
-
padding: "large",
|
|
140
|
-
colSpan: headerGroups.map(function (hg) {
|
|
141
|
-
return hg.headers.length;
|
|
142
|
-
}).reduce(function (sum, len) {
|
|
143
|
-
return len + 1;
|
|
144
|
-
}, 0),
|
|
145
|
-
className: css.css({
|
|
146
|
-
textAlign: 'center',
|
|
147
|
-
verticalAlign: 'middle'
|
|
148
|
-
}),
|
|
149
|
-
children: /*#__PURE__*/jsxRuntime.jsx(spinner.Spinner, {
|
|
150
|
-
data: {
|
|
151
|
-
testId: 'data-table-spinner'
|
|
152
|
-
},
|
|
153
|
-
size: "xsmall"
|
|
154
|
-
})
|
|
155
|
-
})
|
|
156
|
-
})]
|
|
157
|
-
}), footerGroups.length > 0 ? /*#__PURE__*/jsxRuntime.jsx(box.Box, {
|
|
158
|
-
as: "tfoot",
|
|
159
|
-
className: css.cx(footerClassName),
|
|
160
|
-
children: footerGroups.map(function (footerGroup) {
|
|
161
|
-
return /*#__PURE__*/jsxRuntime.jsx(box.Box, {
|
|
162
|
-
as: "tr",
|
|
163
|
-
children: footerGroup.headers.map(function (footer) {
|
|
164
|
-
return /*#__PURE__*/jsxRuntime.jsx(box.Box, {
|
|
165
|
-
as: "td",
|
|
166
|
-
children: reactTable.flexRender(footer.column.columnDef.footer, footer.getContext())
|
|
167
|
-
}, footer.id);
|
|
168
|
-
})
|
|
169
|
-
}, footerGroup.id);
|
|
170
|
-
})
|
|
171
|
-
}) : null]
|
|
172
|
-
}));
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
Object.defineProperty(exports, 'createColumnHelper', {
|
|
176
|
-
enumerable: true,
|
|
177
|
-
get: function () { return reactTable.createColumnHelper; }
|
|
178
|
-
});
|
|
179
|
-
Object.defineProperty(exports, 'flexRender', {
|
|
180
|
-
enumerable: true,
|
|
181
|
-
get: function () { return reactTable.flexRender; }
|
|
182
|
-
});
|
|
183
|
-
exports.DataTable = DataTable;
|
|
@@ -1,183 +0,0 @@
|
|
|
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 css = require('@emotion/css');
|
|
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(box.Box, {
|
|
68
|
-
as: "thead",
|
|
69
|
-
background: "neutral",
|
|
70
|
-
className: css.cx(css.css({
|
|
71
|
-
// we use box shadow instead of bottom border
|
|
72
|
-
// to allow the border to stay in the header on scroll
|
|
73
|
-
// when the table is sticky
|
|
74
|
-
boxShadow: "inset 0 -2px 0 ".concat(theme$1.border.color.primary)
|
|
75
|
-
}, headerClassName)),
|
|
76
|
-
children: headerGroups.map(function (headerGroup) {
|
|
77
|
-
return /*#__PURE__*/jsxRuntime.jsx(box.Box, {
|
|
78
|
-
as: "tr",
|
|
79
|
-
children: headerGroup.headers.map(function (header) {
|
|
80
|
-
return /*#__PURE__*/jsxRuntime.jsx(box.Box, {
|
|
81
|
-
as: "th",
|
|
82
|
-
color: theme$1.color.foreground.muted,
|
|
83
|
-
padding: "medium",
|
|
84
|
-
className: css.css({
|
|
85
|
-
fontFamily: theme$1.typography.fontFamily.sans.name,
|
|
86
|
-
fontWeight: theme$1.typography.fontWeight.semibold,
|
|
87
|
-
textAlign: 'left',
|
|
88
|
-
textTransform: 'uppercase'
|
|
89
|
-
}),
|
|
90
|
-
children: header.isPlaceholder ? null : reactTable.flexRender(header.column.columnDef.header, header.getContext())
|
|
91
|
-
}, header.id);
|
|
92
|
-
})
|
|
93
|
-
}, headerGroup.id);
|
|
94
|
-
})
|
|
95
|
-
}) : null, /*#__PURE__*/jsxRuntime.jsxs(box.Box, {
|
|
96
|
-
as: "tbody",
|
|
97
|
-
children: [!renderRow ? table.getRowModel().rows.map(function (row) {
|
|
98
|
-
return /*#__PURE__*/jsxRuntime.jsxs(React__default["default"].Fragment, {
|
|
99
|
-
children: [/*#__PURE__*/jsxRuntime.jsx(box.Box, {
|
|
100
|
-
as: "tr",
|
|
101
|
-
className: css.css({
|
|
102
|
-
'&[data-is-selected="true"],&[data-is-expanded="true"]': {
|
|
103
|
-
background: theme$1.color.background.primaryMuted
|
|
104
|
-
},
|
|
105
|
-
':hover': {
|
|
106
|
-
background: theme$1.backgroundInteractions.neutralHover,
|
|
107
|
-
cursor: enableClickableRow ? 'pointer' : undefined
|
|
108
|
-
}
|
|
109
|
-
}, rowClassName ? rowClassName(row, row.index) : undefined),
|
|
110
|
-
onClick: function onClick() {
|
|
111
|
-
return enableClickableRow && (onRowClick ? onRowClick(row) : defaultOnRowClick(row));
|
|
112
|
-
},
|
|
113
|
-
"data-is-selected": row.getIsSelected(),
|
|
114
|
-
"data-is-expanded": row.getIsExpanded(),
|
|
115
|
-
children: row.getVisibleCells().map(function (cell) {
|
|
116
|
-
return /*#__PURE__*/jsxRuntime.jsx(box.Box, {
|
|
117
|
-
as: "td",
|
|
118
|
-
padding: "large",
|
|
119
|
-
className: css.css({
|
|
120
|
-
borderBottom: '1px',
|
|
121
|
-
borderBottomStyle: 'solid',
|
|
122
|
-
borderColor: theme$1.border.color.standard,
|
|
123
|
-
verticalAlign: 'middle',
|
|
124
|
-
textAlign: 'left'
|
|
125
|
-
}),
|
|
126
|
-
children: reactTable.flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
127
|
-
}, cell.id);
|
|
128
|
-
})
|
|
129
|
-
}), enableExpanding && row.getIsExpanded() && expandedRowComponent && expandedRowComponent(row, table)]
|
|
130
|
-
}, row.id);
|
|
131
|
-
}) : renderRow(table), showSpinner && /*#__PURE__*/jsxRuntime.jsx(reactIntersectionObserver.InView, {
|
|
132
|
-
as: "tr",
|
|
133
|
-
className: css.css({
|
|
134
|
-
columnSpan: 'all'
|
|
135
|
-
}),
|
|
136
|
-
onChange: onBottomSpinnerShown,
|
|
137
|
-
children: /*#__PURE__*/jsxRuntime.jsx(box.Box, {
|
|
138
|
-
as: "td",
|
|
139
|
-
padding: "large",
|
|
140
|
-
colSpan: headerGroups.map(function (hg) {
|
|
141
|
-
return hg.headers.length;
|
|
142
|
-
}).reduce(function (sum, len) {
|
|
143
|
-
return len + 1;
|
|
144
|
-
}, 0),
|
|
145
|
-
className: css.css({
|
|
146
|
-
textAlign: 'center',
|
|
147
|
-
verticalAlign: 'middle'
|
|
148
|
-
}),
|
|
149
|
-
children: /*#__PURE__*/jsxRuntime.jsx(spinner.Spinner, {
|
|
150
|
-
data: {
|
|
151
|
-
testId: 'data-table-spinner'
|
|
152
|
-
},
|
|
153
|
-
size: "xsmall"
|
|
154
|
-
})
|
|
155
|
-
})
|
|
156
|
-
})]
|
|
157
|
-
}), footerGroups.length > 0 ? /*#__PURE__*/jsxRuntime.jsx(box.Box, {
|
|
158
|
-
as: "tfoot",
|
|
159
|
-
className: css.cx(footerClassName),
|
|
160
|
-
children: footerGroups.map(function (footerGroup) {
|
|
161
|
-
return /*#__PURE__*/jsxRuntime.jsx(box.Box, {
|
|
162
|
-
as: "tr",
|
|
163
|
-
children: footerGroup.headers.map(function (footer) {
|
|
164
|
-
return /*#__PURE__*/jsxRuntime.jsx(box.Box, {
|
|
165
|
-
as: "td",
|
|
166
|
-
children: reactTable.flexRender(footer.column.columnDef.footer, footer.getContext())
|
|
167
|
-
}, footer.id);
|
|
168
|
-
})
|
|
169
|
-
}, footerGroup.id);
|
|
170
|
-
})
|
|
171
|
-
}) : null]
|
|
172
|
-
}));
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
Object.defineProperty(exports, 'createColumnHelper', {
|
|
176
|
-
enumerable: true,
|
|
177
|
-
get: function () { return reactTable.createColumnHelper; }
|
|
178
|
-
});
|
|
179
|
-
Object.defineProperty(exports, 'flexRender', {
|
|
180
|
-
enumerable: true,
|
|
181
|
-
get: function () { return reactTable.flexRender; }
|
|
182
|
-
});
|
|
183
|
-
exports.DataTable = DataTable;
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import _objectSpread from '@babel/runtime/helpers/esm/objectSpread2';
|
|
2
|
-
import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties';
|
|
3
|
-
import { cx, css } from '@emotion/css';
|
|
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(Box, {
|
|
61
|
-
as: "thead",
|
|
62
|
-
background: "neutral",
|
|
63
|
-
className: cx(css({
|
|
64
|
-
// we use box shadow instead of bottom border
|
|
65
|
-
// to allow the border to stay in the header on scroll
|
|
66
|
-
// when the table is sticky
|
|
67
|
-
boxShadow: "inset 0 -2px 0 ".concat(theme.border.color.primary)
|
|
68
|
-
}, headerClassName)),
|
|
69
|
-
children: headerGroups.map(function (headerGroup) {
|
|
70
|
-
return /*#__PURE__*/jsx(Box, {
|
|
71
|
-
as: "tr",
|
|
72
|
-
children: headerGroup.headers.map(function (header) {
|
|
73
|
-
return /*#__PURE__*/jsx(Box, {
|
|
74
|
-
as: "th",
|
|
75
|
-
color: theme.color.foreground.muted,
|
|
76
|
-
padding: "medium",
|
|
77
|
-
className: css({
|
|
78
|
-
fontFamily: theme.typography.fontFamily.sans.name,
|
|
79
|
-
fontWeight: theme.typography.fontWeight.semibold,
|
|
80
|
-
textAlign: 'left',
|
|
81
|
-
textTransform: 'uppercase'
|
|
82
|
-
}),
|
|
83
|
-
children: header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())
|
|
84
|
-
}, header.id);
|
|
85
|
-
})
|
|
86
|
-
}, headerGroup.id);
|
|
87
|
-
})
|
|
88
|
-
}) : null, /*#__PURE__*/jsxs(Box, {
|
|
89
|
-
as: "tbody",
|
|
90
|
-
children: [!renderRow ? table.getRowModel().rows.map(function (row) {
|
|
91
|
-
return /*#__PURE__*/jsxs(React.Fragment, {
|
|
92
|
-
children: [/*#__PURE__*/jsx(Box, {
|
|
93
|
-
as: "tr",
|
|
94
|
-
className: css({
|
|
95
|
-
'&[data-is-selected="true"],&[data-is-expanded="true"]': {
|
|
96
|
-
background: theme.color.background.primaryMuted
|
|
97
|
-
},
|
|
98
|
-
':hover': {
|
|
99
|
-
background: theme.backgroundInteractions.neutralHover,
|
|
100
|
-
cursor: enableClickableRow ? 'pointer' : undefined
|
|
101
|
-
}
|
|
102
|
-
}, rowClassName ? rowClassName(row, row.index) : undefined),
|
|
103
|
-
onClick: function onClick() {
|
|
104
|
-
return enableClickableRow && (onRowClick ? onRowClick(row) : defaultOnRowClick(row));
|
|
105
|
-
},
|
|
106
|
-
"data-is-selected": row.getIsSelected(),
|
|
107
|
-
"data-is-expanded": row.getIsExpanded(),
|
|
108
|
-
children: row.getVisibleCells().map(function (cell) {
|
|
109
|
-
return /*#__PURE__*/jsx(Box, {
|
|
110
|
-
as: "td",
|
|
111
|
-
padding: "large",
|
|
112
|
-
className: css({
|
|
113
|
-
borderBottom: '1px',
|
|
114
|
-
borderBottomStyle: 'solid',
|
|
115
|
-
borderColor: theme.border.color.standard,
|
|
116
|
-
verticalAlign: 'middle',
|
|
117
|
-
textAlign: 'left'
|
|
118
|
-
}),
|
|
119
|
-
children: flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
120
|
-
}, cell.id);
|
|
121
|
-
})
|
|
122
|
-
}), enableExpanding && row.getIsExpanded() && expandedRowComponent && expandedRowComponent(row, table)]
|
|
123
|
-
}, row.id);
|
|
124
|
-
}) : renderRow(table), showSpinner && /*#__PURE__*/jsx(InView, {
|
|
125
|
-
as: "tr",
|
|
126
|
-
className: css({
|
|
127
|
-
columnSpan: 'all'
|
|
128
|
-
}),
|
|
129
|
-
onChange: onBottomSpinnerShown,
|
|
130
|
-
children: /*#__PURE__*/jsx(Box, {
|
|
131
|
-
as: "td",
|
|
132
|
-
padding: "large",
|
|
133
|
-
colSpan: headerGroups.map(function (hg) {
|
|
134
|
-
return hg.headers.length;
|
|
135
|
-
}).reduce(function (sum, len) {
|
|
136
|
-
return len + 1;
|
|
137
|
-
}, 0),
|
|
138
|
-
className: css({
|
|
139
|
-
textAlign: 'center',
|
|
140
|
-
verticalAlign: 'middle'
|
|
141
|
-
}),
|
|
142
|
-
children: /*#__PURE__*/jsx(Spinner, {
|
|
143
|
-
data: {
|
|
144
|
-
testId: 'data-table-spinner'
|
|
145
|
-
},
|
|
146
|
-
size: "xsmall"
|
|
147
|
-
})
|
|
148
|
-
})
|
|
149
|
-
})]
|
|
150
|
-
}), footerGroups.length > 0 ? /*#__PURE__*/jsx(Box, {
|
|
151
|
-
as: "tfoot",
|
|
152
|
-
className: cx(footerClassName),
|
|
153
|
-
children: footerGroups.map(function (footerGroup) {
|
|
154
|
-
return /*#__PURE__*/jsx(Box, {
|
|
155
|
-
as: "tr",
|
|
156
|
-
children: footerGroup.headers.map(function (footer) {
|
|
157
|
-
return /*#__PURE__*/jsx(Box, {
|
|
158
|
-
as: "td",
|
|
159
|
-
children: flexRender(footer.column.columnDef.footer, footer.getContext())
|
|
160
|
-
}, footer.id);
|
|
161
|
-
})
|
|
162
|
-
}, footerGroup.id);
|
|
163
|
-
})
|
|
164
|
-
}) : null]
|
|
165
|
-
}));
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
export { DataTable };
|