@telus-uds/components-community.data-grid 1.0.1 → 1.2.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 +25 -2
- package/lib/cjs/DataGrid.js +59 -17
- package/lib/cjs/DataGridCell.js +23 -8
- package/lib/cjs/utility.js +41 -12
- package/lib/esm/DataGrid.js +58 -18
- package/lib/esm/DataGridCell.js +23 -8
- package/lib/esm/utility.js +38 -11
- package/package.json +4 -4
- package/src/DataGrid.jsx +76 -17
- package/src/DataGridCell.jsx +25 -3
- package/src/utility.jsx +43 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,35 @@
|
|
|
1
1
|
# Change Log - @telus-uds/components-community.data-grid
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Wed, 05 Mar 2025 00:01:06 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## 1.2.0
|
|
8
|
+
|
|
9
|
+
Wed, 05 Mar 2025 00:01:06 GMT
|
|
10
|
+
|
|
11
|
+
### Minor changes
|
|
12
|
+
|
|
13
|
+
- `DatePicker`: Enhancement to make the row checkboxes controlled by the row's data (sam.obisesan@telus.com)
|
|
14
|
+
- Bump @telus-uds/components-web to v4.2.1
|
|
15
|
+
- Bump @telus-uds/components-base to v3.3.0
|
|
16
|
+
- Bump @telus-uds/browserslist-config to v1.0.5
|
|
17
|
+
|
|
18
|
+
## 1.1.0
|
|
19
|
+
|
|
20
|
+
Fri, 14 Feb 2025 19:03:35 GMT
|
|
21
|
+
|
|
22
|
+
### Minor changes
|
|
23
|
+
|
|
24
|
+
- `DataGrid`: enhancement to make the grid header optional (mike.taylor@telus.com)
|
|
25
|
+
- Bump @telus-uds/components-web to v4.2.0
|
|
26
|
+
- Bump @telus-uds/components-base to v3.2.0
|
|
27
|
+
- Bump @telus-uds/system-theme-tokens to v4.2.0
|
|
28
|
+
- Bump @telus-uds/browserslist-config to v1.0.5
|
|
29
|
+
|
|
7
30
|
## 1.0.1
|
|
8
31
|
|
|
9
|
-
Mon, 10 Feb 2025 17:
|
|
32
|
+
Mon, 10 Feb 2025 17:36:47 GMT
|
|
10
33
|
|
|
11
34
|
### Patches
|
|
12
35
|
|
package/lib/cjs/DataGrid.js
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = exports.StyledIconContainer = void 0;
|
|
7
|
-
var _react =
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
9
|
var _componentsBase = require("@telus-uds/components-base");
|
|
10
10
|
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
@@ -17,6 +17,8 @@ var _DataGridRow = _interopRequireDefault(require("./DataGridRow"));
|
|
|
17
17
|
var _DataGridCell = _interopRequireDefault(require("./DataGridCell"));
|
|
18
18
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
19
19
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
20
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
21
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
20
22
|
const StyledIconContainer = exports.StyledIconContainer = /*#__PURE__*/_styledComponents.default.div.withConfig({
|
|
21
23
|
displayName: "DataGrid__StyledIconContainer",
|
|
22
24
|
componentId: "[object Object]__sc-1ddcmt-0"
|
|
@@ -32,7 +34,8 @@ const DataGrid = /*#__PURE__*/_react.default.forwardRef((_ref, ref) => {
|
|
|
32
34
|
tokens,
|
|
33
35
|
variant,
|
|
34
36
|
copy = 'en',
|
|
35
|
-
testID = 'data-grid'
|
|
37
|
+
testID = 'data-grid',
|
|
38
|
+
isHeaderVisible
|
|
36
39
|
} = _ref;
|
|
37
40
|
const themeTokens = (0, _componentsBase.useThemeTokens)('DataGrid', tokens, variant);
|
|
38
41
|
const getCopy = (0, _componentsBase.useCopy)({
|
|
@@ -48,17 +51,31 @@ const DataGrid = /*#__PURE__*/_react.default.forwardRef((_ref, ref) => {
|
|
|
48
51
|
const [data, setData] = _react.default.useState(groupedRows ? (0, _utility.resetRowData)([...groupedRows], true) : (0, _utility.resetRowData)([...rows]));
|
|
49
52
|
const [columnsData, setColumnsData] = _react.default.useState((0, _utility.resetColumnsData)(columns));
|
|
50
53
|
const [checkAllState, setCheckAllState] = _react.default.useState(false);
|
|
51
|
-
const
|
|
52
|
-
|
|
54
|
+
const [disableHeaderCheckbox, setDisableHeaderCheckbox] = _react.default.useState(false);
|
|
55
|
+
const [hideHeaderCheckBoxByRows, setHideHeaderCheckBoxByRows] = _react.default.useState(false);
|
|
56
|
+
(0, _react.useEffect)(() => {
|
|
57
|
+
let _isAtLeastOneRowUnselected = null;
|
|
58
|
+
let _isAtLeastOneRowEnabled = null;
|
|
59
|
+
let _hideHeaderCheckBoxByRows = null;
|
|
53
60
|
if (groupedRows) {
|
|
54
|
-
|
|
55
|
-
return (0, _utility.isAtLeastOneRowUnselected)(
|
|
61
|
+
_isAtLeastOneRowUnselected = Object.keys(data).some(el => {
|
|
62
|
+
return (0, _utility.isAtLeastOneRowUnselected)(data[el].data);
|
|
63
|
+
});
|
|
64
|
+
_isAtLeastOneRowEnabled = Object.keys(data).some(el => {
|
|
65
|
+
return (0, _utility.isAtLeastOneRowEnabled)(data[el].data);
|
|
66
|
+
});
|
|
67
|
+
_hideHeaderCheckBoxByRows = Object.keys(data).some(el => {
|
|
68
|
+
return (0, _utility.hasEveryRowHiddenItsCheckbox)(data[el].data);
|
|
56
69
|
});
|
|
57
70
|
} else {
|
|
58
|
-
|
|
71
|
+
_isAtLeastOneRowUnselected = (0, _utility.isAtLeastOneRowUnselected)(data);
|
|
72
|
+
_isAtLeastOneRowEnabled = (0, _utility.isAtLeastOneRowEnabled)(data);
|
|
73
|
+
_hideHeaderCheckBoxByRows = (0, _utility.hasEveryRowHiddenItsCheckbox)(data);
|
|
59
74
|
}
|
|
60
|
-
|
|
61
|
-
|
|
75
|
+
setCheckAllState(_isAtLeastOneRowEnabled === false ? false : !_isAtLeastOneRowUnselected);
|
|
76
|
+
setDisableHeaderCheckbox(!_isAtLeastOneRowEnabled);
|
|
77
|
+
setHideHeaderCheckBoxByRows(_hideHeaderCheckBoxByRows);
|
|
78
|
+
}, [data, groupedRows]);
|
|
62
79
|
const shouldDisplayIconColumn = (allData, _showCheckbox) => {
|
|
63
80
|
let doesOneRowHaveExpandedContent = null;
|
|
64
81
|
if (groupedRows) {
|
|
@@ -86,8 +103,11 @@ const DataGrid = /*#__PURE__*/_react.default.forwardRef((_ref, ref) => {
|
|
|
86
103
|
setData(_rows);
|
|
87
104
|
setCheckAllState(!checkAllState);
|
|
88
105
|
};
|
|
89
|
-
const toggleCheckbox = rowId => {
|
|
106
|
+
const toggleCheckbox = (rowId, row) => {
|
|
90
107
|
let _data = null;
|
|
108
|
+
if (typeof row.checkBoxProps?.onChange === 'function') {
|
|
109
|
+
row.checkBoxProps.onChange();
|
|
110
|
+
}
|
|
91
111
|
if (groupedRows) {
|
|
92
112
|
const [group, _] = rowId.split('-');
|
|
93
113
|
const id = parseInt(_, 10);
|
|
@@ -114,15 +134,18 @@ const DataGrid = /*#__PURE__*/_react.default.forwardRef((_ref, ref) => {
|
|
|
114
134
|
}
|
|
115
135
|
setData(_row);
|
|
116
136
|
};
|
|
117
|
-
const HeaderCheckBoxDisplay = showCheckbox && /*#__PURE__*/(0, _jsxRuntime.jsx)(_componentsBase.Checkbox, {
|
|
137
|
+
const HeaderCheckBoxDisplay = showCheckbox && !hideHeaderCheckBoxByRows && /*#__PURE__*/(0, _jsxRuntime.jsx)(_componentsBase.Checkbox, {
|
|
118
138
|
label: getCopy('all'),
|
|
119
|
-
checked:
|
|
139
|
+
checked: checkAllState,
|
|
140
|
+
inactive: disableHeaderCheckbox,
|
|
120
141
|
onChange: toggleSelectAll
|
|
121
142
|
});
|
|
122
|
-
const buildCheckBoxDisplay = (_showCheckbox, row, rowId) =>
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
143
|
+
const buildCheckBoxDisplay = (_showCheckbox, row, rowId) => {
|
|
144
|
+
return _showCheckbox && !row.hideCheckbox && /*#__PURE__*/(0, _jsxRuntime.jsx)(_componentsBase.Checkbox, {
|
|
145
|
+
...row.checkBoxProps,
|
|
146
|
+
onChange: () => toggleCheckbox(rowId, row)
|
|
147
|
+
});
|
|
148
|
+
};
|
|
126
149
|
const buildDisplayCaret = (row, rowId) => row.hasExpandedRow && /*#__PURE__*/(0, _jsxRuntime.jsx)(_componentsBase.IconButton, {
|
|
127
150
|
onPress: () => toggleRowExpansion(rowId),
|
|
128
151
|
icon: row.isExpandedRowOpen === true ? hideExpandedRowIcon : expandRowIcon,
|
|
@@ -153,12 +176,14 @@ const DataGrid = /*#__PURE__*/_react.default.forwardRef((_ref, ref) => {
|
|
|
153
176
|
children: [shouldDisplayIconColumn(data, _showCheckbox) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_DataGridCell.default, {
|
|
154
177
|
tokens: themeTokens,
|
|
155
178
|
isExpandedRowOpen: row.isExpandedRowOpen,
|
|
179
|
+
isHeaderVisible: isHeaderVisible,
|
|
156
180
|
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(StyledIconContainer, {
|
|
157
181
|
children: [CheckBoxDisplay, DisplayCaret]
|
|
158
182
|
})
|
|
159
183
|
}), columnsData.map(column => /*#__PURE__*/(0, _jsxRuntime.jsx)(_DataGridCell.default, {
|
|
160
184
|
tokens: themeTokens,
|
|
161
185
|
isExpandedRowOpen: row.isExpandedRowOpen,
|
|
186
|
+
isHeaderVisible: isHeaderVisible,
|
|
162
187
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_componentsBase.Typography, {
|
|
163
188
|
block: true,
|
|
164
189
|
variant: {
|
|
@@ -212,6 +237,7 @@ const DataGrid = /*#__PURE__*/_react.default.forwardRef((_ref, ref) => {
|
|
|
212
237
|
type: _utility.CELL_TYPE.SUBHEADING,
|
|
213
238
|
tokens: themeTokens,
|
|
214
239
|
columnsLength: columnsData.length,
|
|
240
|
+
isHeaderVisible: isHeaderVisible,
|
|
215
241
|
children: data[group].groupHeaderComponent || DefaultSubHeading
|
|
216
242
|
})
|
|
217
243
|
}, group);
|
|
@@ -240,11 +266,13 @@ const DataGrid = /*#__PURE__*/_react.default.forwardRef((_ref, ref) => {
|
|
|
240
266
|
type: _utility.CELL_TYPE.HEADING,
|
|
241
267
|
tokens: themeTokens,
|
|
242
268
|
isFirstCol: true,
|
|
269
|
+
isHeaderVisible: isHeaderVisible,
|
|
243
270
|
children: HeaderCheckBoxDisplay
|
|
244
271
|
}), columnsData.map(column => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_DataGridCell.default, {
|
|
245
272
|
type: _utility.CELL_TYPE.HEADING,
|
|
246
273
|
tokens: themeTokens,
|
|
247
274
|
isSortable: isSortable,
|
|
275
|
+
isHeaderVisible: isHeaderVisible,
|
|
248
276
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_componentsBase.Typography, {
|
|
249
277
|
block: true,
|
|
250
278
|
variant: {
|
|
@@ -335,6 +363,16 @@ DataGrid.propTypes = {
|
|
|
335
363
|
expandedRowChildComponent: _propTypes.default.shape({
|
|
336
364
|
component: _propTypes.default.node,
|
|
337
365
|
displayOnLoad: _propTypes.default.bool.isRequired
|
|
366
|
+
}),
|
|
367
|
+
/**
|
|
368
|
+
* Set this to true to hide checkbox for the specified row
|
|
369
|
+
*/
|
|
370
|
+
hideCheckbox: _propTypes.default.bool,
|
|
371
|
+
checkBoxProps: _propTypes.default.shape({
|
|
372
|
+
checked: _propTypes.default.bool,
|
|
373
|
+
name: _propTypes.default.string,
|
|
374
|
+
value: _propTypes.default.string.isRequired,
|
|
375
|
+
onChange: _propTypes.default.func
|
|
338
376
|
})
|
|
339
377
|
})),
|
|
340
378
|
/**
|
|
@@ -364,6 +402,10 @@ DataGrid.propTypes = {
|
|
|
364
402
|
/**
|
|
365
403
|
* Use in tests if the datagrid test cases need to find the element with the id.
|
|
366
404
|
*/
|
|
367
|
-
testID: _propTypes.default.string
|
|
405
|
+
testID: _propTypes.default.string,
|
|
406
|
+
/**
|
|
407
|
+
* Passed to the component to determine if header is displayed. Set to false to hide header of datagrid. Set to true by default
|
|
408
|
+
*/
|
|
409
|
+
isHeaderVisible: _propTypes.default.bool
|
|
368
410
|
};
|
|
369
411
|
var _default = exports.default = DataGrid;
|
package/lib/cjs/DataGridCell.js
CHANGED
|
@@ -22,31 +22,37 @@ const StyledHeaderCellDiv = /*#__PURE__*/_styledComponents.default.div.withConfi
|
|
|
22
22
|
displayName: "DataGridCell__StyledHeaderCellDiv",
|
|
23
23
|
componentId: "[object Object]__sc-6nkvhz-1"
|
|
24
24
|
})(["display:flex;align-items:center;"]);
|
|
25
|
+
const StyledHeaderCellHiddenHeader = /*#__PURE__*/_styledComponents.default.th.withConfig({
|
|
26
|
+
displayName: "DataGridCell__StyledHeaderCellHiddenHeader",
|
|
27
|
+
componentId: "[object Object]__sc-6nkvhz-2"
|
|
28
|
+
})(["", ""], props => {
|
|
29
|
+
return (0, _styledComponents.css)(["background-color:", ";border-bottom:solid ", "px ", ";padding:0px;width:", ";height:1px;"], props.headerRowBackgroundColor, props.headerBorderBottomWidth, props.cellBorderBottomColor, props.firstColWidth);
|
|
30
|
+
});
|
|
25
31
|
const StyledGroupHeaderCell = /*#__PURE__*/_styledComponents.default.td.withConfig({
|
|
26
32
|
displayName: "DataGridCell__StyledGroupHeaderCell",
|
|
27
|
-
componentId: "[object Object]__sc-6nkvhz-
|
|
33
|
+
componentId: "[object Object]__sc-6nkvhz-3"
|
|
28
34
|
})(["", ""], props => {
|
|
29
35
|
return (0, _styledComponents.css)(["background-color:", ";padding:", "px;border-top:solid ", "px ", ";text-align:", ";font-size:", "px;font-weight:normal;line-height:", "px;color:", ";font-family:", ";"], props.subHeadingBackgroundColor, props.cellPadding, props.cellBorderBottomWidth, props.cellBorderBottomColor, props.cellTextAlign, props.cellFontSize, props.cellLineHeight * props.cellFontSize, props.cellTextColor, props.cellFontFamily);
|
|
30
36
|
});
|
|
31
37
|
const StyledGroupHeaderCellDiv = /*#__PURE__*/_styledComponents.default.div.withConfig({
|
|
32
38
|
displayName: "DataGridCell__StyledGroupHeaderCellDiv",
|
|
33
|
-
componentId: "[object Object]__sc-6nkvhz-
|
|
39
|
+
componentId: "[object Object]__sc-6nkvhz-4"
|
|
34
40
|
})(["display:flex;align-items:center;justify-content:start;"]);
|
|
35
41
|
const StyledExpandedCell = /*#__PURE__*/_styledComponents.default.td.withConfig({
|
|
36
42
|
displayName: "DataGridCell__StyledExpandedCell",
|
|
37
|
-
componentId: "[object Object]__sc-6nkvhz-
|
|
43
|
+
componentId: "[object Object]__sc-6nkvhz-5"
|
|
38
44
|
})(["", ""], props => {
|
|
39
45
|
return (0, _styledComponents.css)(["padding:", "px;border-bottom:", " text-align:", ";font-size:", "px;font-weight:normal;line-height:", "px;color:", ";font-family:", ";"], props.cellPadding, props.isExpandedRowOpen ? `solid ${props.cellBorderBottomWidth}px ${props.headerBorderBottomColor};` : `solid ${props.cellBorderBottomWidth}px ${props.cellBorderBottomColor};`, props.cellTextAlign, props.cellFontSize, props.cellLineHeight * props.cellFontSize, props.cellTextColor, props.cellFontFamily);
|
|
40
46
|
});
|
|
41
47
|
const StyledExpandedCellDiv = /*#__PURE__*/_styledComponents.default.div.withConfig({
|
|
42
48
|
displayName: "DataGridCell__StyledExpandedCellDiv",
|
|
43
|
-
componentId: "[object Object]__sc-6nkvhz-
|
|
49
|
+
componentId: "[object Object]__sc-6nkvhz-6"
|
|
44
50
|
})(["", ""], props => {
|
|
45
51
|
return (0, _styledComponents.css)(["display:flex;align-items:center;justify-content:", ";padding-left:", ";"], props.expandedContentAlignment ? props.expandedContentAlignment : 'start', props.showCheckbox ? `${props.expandedContentLeftPadding}px` : `${props.expandedContentDefaultLeftPadding}px`);
|
|
46
52
|
});
|
|
47
53
|
const StyledCell = exports.StyledCell = /*#__PURE__*/_styledComponents.default.td.withConfig({
|
|
48
54
|
displayName: "DataGridCell__StyledCell",
|
|
49
|
-
componentId: "[object Object]__sc-6nkvhz-
|
|
55
|
+
componentId: "[object Object]__sc-6nkvhz-7"
|
|
50
56
|
})(["", ""], props => {
|
|
51
57
|
if (props.isExpandedRowOpen) {
|
|
52
58
|
return (0, _styledComponents.css)(["padding:", "px;text-align:", ";font-size:", "px;font-weight:normal;line-height:", "px;color:", ";font-family:", ";border-top:solid ", "px ", ";"], props.cellPadding, props.cellTextAlign, props.cellFontSize, props.cellLineHeight * props.cellFontSize, props.cellTextColor, props.cellFontFamily, props.headerBorderTopWidth, props.headerBorderTopColor);
|
|
@@ -61,16 +67,21 @@ const DataGridCell = /*#__PURE__*/_react.default.forwardRef((_ref, ref) => {
|
|
|
61
67
|
columnsLength,
|
|
62
68
|
showCheckbox = false,
|
|
63
69
|
isFirstCol = false,
|
|
64
|
-
isExpandedRowOpen = false
|
|
70
|
+
isExpandedRowOpen = false,
|
|
71
|
+
isHeaderVisible = true
|
|
65
72
|
} = _ref;
|
|
66
73
|
if (type === _utility.CELL_TYPE.HEADING) {
|
|
67
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledHeaderCell, {
|
|
74
|
+
return isHeaderVisible ? /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledHeaderCell, {
|
|
68
75
|
...tokens,
|
|
69
76
|
firstColWidth: isFirstCol ? tokens.firstColWidth : 'auto',
|
|
70
77
|
ref: ref,
|
|
71
78
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledHeaderCellDiv, {
|
|
72
79
|
children: children
|
|
73
80
|
})
|
|
81
|
+
}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledHeaderCellHiddenHeader, {
|
|
82
|
+
...tokens,
|
|
83
|
+
firstColWidth: isFirstCol ? tokens.firstColWidth : 'auto',
|
|
84
|
+
ref: ref
|
|
74
85
|
});
|
|
75
86
|
}
|
|
76
87
|
if (type === _utility.CELL_TYPE.SUBHEADING) {
|
|
@@ -133,6 +144,10 @@ DataGridCell.propTypes = {
|
|
|
133
144
|
/**
|
|
134
145
|
* isExpandedRowOpen passed to the component to determine if cell is displaying additional data
|
|
135
146
|
*/
|
|
136
|
-
isExpandedRowOpen: _propTypes.default.bool
|
|
147
|
+
isExpandedRowOpen: _propTypes.default.bool,
|
|
148
|
+
/**
|
|
149
|
+
* Passed to the component to determine if header is displayed. Set to false to hide header of datagrid. Set to true by default
|
|
150
|
+
*/
|
|
151
|
+
isHeaderVisible: _propTypes.default.bool
|
|
137
152
|
};
|
|
138
153
|
var _default = exports.default = DataGridCell;
|
package/lib/cjs/utility.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.toggleRowCheckbox = exports.toggleExpandedRow = exports.toggleAllCheckBoxes = exports.resetRowData = exports.resetColumnsData = exports.isAtLeastOneRowUnselected = exports.SORT_DIRECTION = exports.ROW_TYPE = exports.DATA_TYPE = exports.CELL_TYPE = void 0;
|
|
6
|
+
exports.toggleRowCheckbox = exports.toggleExpandedRow = exports.toggleAllCheckBoxes = exports.resetRowData = exports.resetColumnsData = exports.isAtLeastOneRowUnselected = exports.isAtLeastOneRowEnabled = exports.hasEveryRowHiddenItsCheckbox = exports.SORT_DIRECTION = exports.ROW_TYPE = exports.DATA_TYPE = exports.CELL_TYPE = void 0;
|
|
7
7
|
const ROW_TYPE = exports.ROW_TYPE = {
|
|
8
8
|
HEADING: 'heading',
|
|
9
9
|
SUBHEADING: 'subHeading',
|
|
@@ -25,20 +25,38 @@ const DATA_TYPE = exports.DATA_TYPE = {
|
|
|
25
25
|
const mappedData = array => {
|
|
26
26
|
return array.map(element => {
|
|
27
27
|
const eachRow = {
|
|
28
|
-
...element
|
|
29
|
-
isSelected: false
|
|
28
|
+
...element
|
|
30
29
|
};
|
|
31
30
|
if (eachRow.expandedRowChildComponent) {
|
|
32
31
|
eachRow.hasExpandedRow = true;
|
|
33
32
|
eachRow.isExpandedRowOpen = element.expandedRowChildComponent.displayOnLoad;
|
|
34
33
|
}
|
|
34
|
+
if (!eachRow.hideCheckbox) {
|
|
35
|
+
eachRow.hideCheckbox = false;
|
|
36
|
+
}
|
|
37
|
+
if (!eachRow.checkBoxProps) {
|
|
38
|
+
eachRow.checkBoxProps = {
|
|
39
|
+
value: `row_${eachRow.id}`,
|
|
40
|
+
inactive: false,
|
|
41
|
+
checked: false,
|
|
42
|
+
onChange: () => {}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
35
45
|
return eachRow;
|
|
36
46
|
});
|
|
37
47
|
};
|
|
38
48
|
const isAtLeastOneRowUnselected = array => {
|
|
39
|
-
return array.some(each => each.
|
|
49
|
+
return array.some(each => each.checkBoxProps?.inactive === false && each.checkBoxProps?.checked === false);
|
|
40
50
|
};
|
|
41
51
|
exports.isAtLeastOneRowUnselected = isAtLeastOneRowUnselected;
|
|
52
|
+
const isAtLeastOneRowEnabled = array => {
|
|
53
|
+
return array.some(each => each.checkBoxProps?.inactive === false);
|
|
54
|
+
};
|
|
55
|
+
exports.isAtLeastOneRowEnabled = isAtLeastOneRowEnabled;
|
|
56
|
+
const hasEveryRowHiddenItsCheckbox = array => {
|
|
57
|
+
return array.every(each => each.hideCheckbox === true);
|
|
58
|
+
};
|
|
59
|
+
exports.hasEveryRowHiddenItsCheckbox = hasEveryRowHiddenItsCheckbox;
|
|
42
60
|
const resetColumnsData = data => {
|
|
43
61
|
return data.map(element => ({
|
|
44
62
|
...element,
|
|
@@ -64,18 +82,29 @@ const resetRowData = function (data) {
|
|
|
64
82
|
exports.resetRowData = resetRowData;
|
|
65
83
|
const toggleAllCheckBoxes = (array, headerCheckBoxState) => {
|
|
66
84
|
return array.map(element => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
85
|
+
let _el = null;
|
|
86
|
+
if (element.hideCheckbox === true || element.checkBoxProps && element.checkBoxProps.inactive) {
|
|
87
|
+
_el = {
|
|
88
|
+
...element
|
|
89
|
+
};
|
|
90
|
+
} else {
|
|
91
|
+
_el = {
|
|
92
|
+
...element
|
|
93
|
+
};
|
|
94
|
+
_el.checkBoxProps.checked = !headerCheckBoxState;
|
|
95
|
+
}
|
|
96
|
+
return _el;
|
|
71
97
|
});
|
|
72
98
|
};
|
|
73
99
|
exports.toggleAllCheckBoxes = toggleAllCheckBoxes;
|
|
74
100
|
const toggleRowCheckbox = (array, rowId) => {
|
|
75
|
-
return array.map(el =>
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
101
|
+
return array.map(el => {
|
|
102
|
+
const _el = {
|
|
103
|
+
...el
|
|
104
|
+
};
|
|
105
|
+
_el.checkBoxProps.checked = el.id === rowId ? !_el.checkBoxProps.checked : _el.checkBoxProps.checked;
|
|
106
|
+
return _el;
|
|
107
|
+
});
|
|
79
108
|
};
|
|
80
109
|
exports.toggleRowCheckbox = toggleRowCheckbox;
|
|
81
110
|
const toggleExpandedRow = (array, rowId) => {
|
package/lib/esm/DataGrid.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { Typography, Checkbox, useCopy, useThemeTokens, variantProp, IconButton } from '@telus-uds/components-base';
|
|
4
4
|
import styled from 'styled-components';
|
|
5
5
|
import dictionary from './dictionary';
|
|
6
|
-
import { resetColumnsData, resetRowData, DATA_TYPE, SORT_DIRECTION, isAtLeastOneRowUnselected, toggleAllCheckBoxes, toggleExpandedRow, toggleRowCheckbox, ROW_TYPE, CELL_TYPE } from './utility';
|
|
6
|
+
import { resetColumnsData, resetRowData, DATA_TYPE, SORT_DIRECTION, isAtLeastOneRowUnselected, isAtLeastOneRowEnabled, hasEveryRowHiddenItsCheckbox, toggleAllCheckBoxes, toggleExpandedRow, toggleRowCheckbox, ROW_TYPE, CELL_TYPE } from './utility';
|
|
7
7
|
import DataGridTable from './DataGridTable';
|
|
8
8
|
import DataGridHead from './DataGridHead';
|
|
9
9
|
import DataGridBody from './DataGridBody';
|
|
@@ -25,7 +25,8 @@ const DataGrid = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
25
25
|
tokens,
|
|
26
26
|
variant,
|
|
27
27
|
copy = 'en',
|
|
28
|
-
testID = 'data-grid'
|
|
28
|
+
testID = 'data-grid',
|
|
29
|
+
isHeaderVisible
|
|
29
30
|
} = _ref;
|
|
30
31
|
const themeTokens = useThemeTokens('DataGrid', tokens, variant);
|
|
31
32
|
const getCopy = useCopy({
|
|
@@ -41,17 +42,31 @@ const DataGrid = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
41
42
|
const [data, setData] = React.useState(groupedRows ? resetRowData([...groupedRows], true) : resetRowData([...rows]));
|
|
42
43
|
const [columnsData, setColumnsData] = React.useState(resetColumnsData(columns));
|
|
43
44
|
const [checkAllState, setCheckAllState] = React.useState(false);
|
|
44
|
-
const
|
|
45
|
-
|
|
45
|
+
const [disableHeaderCheckbox, setDisableHeaderCheckbox] = React.useState(false);
|
|
46
|
+
const [hideHeaderCheckBoxByRows, setHideHeaderCheckBoxByRows] = React.useState(false);
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
let _isAtLeastOneRowUnselected = null;
|
|
49
|
+
let _isAtLeastOneRowEnabled = null;
|
|
50
|
+
let _hideHeaderCheckBoxByRows = null;
|
|
46
51
|
if (groupedRows) {
|
|
47
|
-
|
|
48
|
-
return isAtLeastOneRowUnselected(
|
|
52
|
+
_isAtLeastOneRowUnselected = Object.keys(data).some(el => {
|
|
53
|
+
return isAtLeastOneRowUnselected(data[el].data);
|
|
54
|
+
});
|
|
55
|
+
_isAtLeastOneRowEnabled = Object.keys(data).some(el => {
|
|
56
|
+
return isAtLeastOneRowEnabled(data[el].data);
|
|
57
|
+
});
|
|
58
|
+
_hideHeaderCheckBoxByRows = Object.keys(data).some(el => {
|
|
59
|
+
return hasEveryRowHiddenItsCheckbox(data[el].data);
|
|
49
60
|
});
|
|
50
61
|
} else {
|
|
51
|
-
|
|
62
|
+
_isAtLeastOneRowUnselected = isAtLeastOneRowUnselected(data);
|
|
63
|
+
_isAtLeastOneRowEnabled = isAtLeastOneRowEnabled(data);
|
|
64
|
+
_hideHeaderCheckBoxByRows = hasEveryRowHiddenItsCheckbox(data);
|
|
52
65
|
}
|
|
53
|
-
|
|
54
|
-
|
|
66
|
+
setCheckAllState(_isAtLeastOneRowEnabled === false ? false : !_isAtLeastOneRowUnselected);
|
|
67
|
+
setDisableHeaderCheckbox(!_isAtLeastOneRowEnabled);
|
|
68
|
+
setHideHeaderCheckBoxByRows(_hideHeaderCheckBoxByRows);
|
|
69
|
+
}, [data, groupedRows]);
|
|
55
70
|
const shouldDisplayIconColumn = (allData, _showCheckbox) => {
|
|
56
71
|
let doesOneRowHaveExpandedContent = null;
|
|
57
72
|
if (groupedRows) {
|
|
@@ -79,8 +94,11 @@ const DataGrid = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
79
94
|
setData(_rows);
|
|
80
95
|
setCheckAllState(!checkAllState);
|
|
81
96
|
};
|
|
82
|
-
const toggleCheckbox = rowId => {
|
|
97
|
+
const toggleCheckbox = (rowId, row) => {
|
|
83
98
|
let _data = null;
|
|
99
|
+
if (typeof row.checkBoxProps?.onChange === 'function') {
|
|
100
|
+
row.checkBoxProps.onChange();
|
|
101
|
+
}
|
|
84
102
|
if (groupedRows) {
|
|
85
103
|
const [group, _] = rowId.split('-');
|
|
86
104
|
const id = parseInt(_, 10);
|
|
@@ -107,15 +125,18 @@ const DataGrid = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
107
125
|
}
|
|
108
126
|
setData(_row);
|
|
109
127
|
};
|
|
110
|
-
const HeaderCheckBoxDisplay = showCheckbox && /*#__PURE__*/_jsx(Checkbox, {
|
|
128
|
+
const HeaderCheckBoxDisplay = showCheckbox && !hideHeaderCheckBoxByRows && /*#__PURE__*/_jsx(Checkbox, {
|
|
111
129
|
label: getCopy('all'),
|
|
112
|
-
checked:
|
|
130
|
+
checked: checkAllState,
|
|
131
|
+
inactive: disableHeaderCheckbox,
|
|
113
132
|
onChange: toggleSelectAll
|
|
114
133
|
});
|
|
115
|
-
const buildCheckBoxDisplay = (_showCheckbox, row, rowId) =>
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
134
|
+
const buildCheckBoxDisplay = (_showCheckbox, row, rowId) => {
|
|
135
|
+
return _showCheckbox && !row.hideCheckbox && /*#__PURE__*/_jsx(Checkbox, {
|
|
136
|
+
...row.checkBoxProps,
|
|
137
|
+
onChange: () => toggleCheckbox(rowId, row)
|
|
138
|
+
});
|
|
139
|
+
};
|
|
119
140
|
const buildDisplayCaret = (row, rowId) => row.hasExpandedRow && /*#__PURE__*/_jsx(IconButton, {
|
|
120
141
|
onPress: () => toggleRowExpansion(rowId),
|
|
121
142
|
icon: row.isExpandedRowOpen === true ? hideExpandedRowIcon : expandRowIcon,
|
|
@@ -146,12 +167,14 @@ const DataGrid = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
146
167
|
children: [shouldDisplayIconColumn(data, _showCheckbox) && /*#__PURE__*/_jsx(DataGridCell, {
|
|
147
168
|
tokens: themeTokens,
|
|
148
169
|
isExpandedRowOpen: row.isExpandedRowOpen,
|
|
170
|
+
isHeaderVisible: isHeaderVisible,
|
|
149
171
|
children: /*#__PURE__*/_jsxs(StyledIconContainer, {
|
|
150
172
|
children: [CheckBoxDisplay, DisplayCaret]
|
|
151
173
|
})
|
|
152
174
|
}), columnsData.map(column => /*#__PURE__*/_jsx(DataGridCell, {
|
|
153
175
|
tokens: themeTokens,
|
|
154
176
|
isExpandedRowOpen: row.isExpandedRowOpen,
|
|
177
|
+
isHeaderVisible: isHeaderVisible,
|
|
155
178
|
children: /*#__PURE__*/_jsx(Typography, {
|
|
156
179
|
block: true,
|
|
157
180
|
variant: {
|
|
@@ -205,6 +228,7 @@ const DataGrid = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
205
228
|
type: CELL_TYPE.SUBHEADING,
|
|
206
229
|
tokens: themeTokens,
|
|
207
230
|
columnsLength: columnsData.length,
|
|
231
|
+
isHeaderVisible: isHeaderVisible,
|
|
208
232
|
children: data[group].groupHeaderComponent || DefaultSubHeading
|
|
209
233
|
})
|
|
210
234
|
}, group);
|
|
@@ -233,11 +257,13 @@ const DataGrid = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
233
257
|
type: CELL_TYPE.HEADING,
|
|
234
258
|
tokens: themeTokens,
|
|
235
259
|
isFirstCol: true,
|
|
260
|
+
isHeaderVisible: isHeaderVisible,
|
|
236
261
|
children: HeaderCheckBoxDisplay
|
|
237
262
|
}), columnsData.map(column => /*#__PURE__*/_jsxs(DataGridCell, {
|
|
238
263
|
type: CELL_TYPE.HEADING,
|
|
239
264
|
tokens: themeTokens,
|
|
240
265
|
isSortable: isSortable,
|
|
266
|
+
isHeaderVisible: isHeaderVisible,
|
|
241
267
|
children: [/*#__PURE__*/_jsx(Typography, {
|
|
242
268
|
block: true,
|
|
243
269
|
variant: {
|
|
@@ -328,6 +354,16 @@ DataGrid.propTypes = {
|
|
|
328
354
|
expandedRowChildComponent: PropTypes.shape({
|
|
329
355
|
component: PropTypes.node,
|
|
330
356
|
displayOnLoad: PropTypes.bool.isRequired
|
|
357
|
+
}),
|
|
358
|
+
/**
|
|
359
|
+
* Set this to true to hide checkbox for the specified row
|
|
360
|
+
*/
|
|
361
|
+
hideCheckbox: PropTypes.bool,
|
|
362
|
+
checkBoxProps: PropTypes.shape({
|
|
363
|
+
checked: PropTypes.bool,
|
|
364
|
+
name: PropTypes.string,
|
|
365
|
+
value: PropTypes.string.isRequired,
|
|
366
|
+
onChange: PropTypes.func
|
|
331
367
|
})
|
|
332
368
|
})),
|
|
333
369
|
/**
|
|
@@ -357,6 +393,10 @@ DataGrid.propTypes = {
|
|
|
357
393
|
/**
|
|
358
394
|
* Use in tests if the datagrid test cases need to find the element with the id.
|
|
359
395
|
*/
|
|
360
|
-
testID: PropTypes.string
|
|
396
|
+
testID: PropTypes.string,
|
|
397
|
+
/**
|
|
398
|
+
* Passed to the component to determine if header is displayed. Set to false to hide header of datagrid. Set to true by default
|
|
399
|
+
*/
|
|
400
|
+
isHeaderVisible: PropTypes.bool
|
|
361
401
|
};
|
|
362
402
|
export default DataGrid;
|
package/lib/esm/DataGridCell.js
CHANGED
|
@@ -13,31 +13,37 @@ const StyledHeaderCellDiv = /*#__PURE__*/styled.div.withConfig({
|
|
|
13
13
|
displayName: "DataGridCell__StyledHeaderCellDiv",
|
|
14
14
|
componentId: "[object Object]__sc-6nkvhz-1"
|
|
15
15
|
})(["display:flex;align-items:center;"]);
|
|
16
|
+
const StyledHeaderCellHiddenHeader = /*#__PURE__*/styled.th.withConfig({
|
|
17
|
+
displayName: "DataGridCell__StyledHeaderCellHiddenHeader",
|
|
18
|
+
componentId: "[object Object]__sc-6nkvhz-2"
|
|
19
|
+
})(["", ""], props => {
|
|
20
|
+
return css(["background-color:", ";border-bottom:solid ", "px ", ";padding:0px;width:", ";height:1px;"], props.headerRowBackgroundColor, props.headerBorderBottomWidth, props.cellBorderBottomColor, props.firstColWidth);
|
|
21
|
+
});
|
|
16
22
|
const StyledGroupHeaderCell = /*#__PURE__*/styled.td.withConfig({
|
|
17
23
|
displayName: "DataGridCell__StyledGroupHeaderCell",
|
|
18
|
-
componentId: "[object Object]__sc-6nkvhz-
|
|
24
|
+
componentId: "[object Object]__sc-6nkvhz-3"
|
|
19
25
|
})(["", ""], props => {
|
|
20
26
|
return css(["background-color:", ";padding:", "px;border-top:solid ", "px ", ";text-align:", ";font-size:", "px;font-weight:normal;line-height:", "px;color:", ";font-family:", ";"], props.subHeadingBackgroundColor, props.cellPadding, props.cellBorderBottomWidth, props.cellBorderBottomColor, props.cellTextAlign, props.cellFontSize, props.cellLineHeight * props.cellFontSize, props.cellTextColor, props.cellFontFamily);
|
|
21
27
|
});
|
|
22
28
|
const StyledGroupHeaderCellDiv = /*#__PURE__*/styled.div.withConfig({
|
|
23
29
|
displayName: "DataGridCell__StyledGroupHeaderCellDiv",
|
|
24
|
-
componentId: "[object Object]__sc-6nkvhz-
|
|
30
|
+
componentId: "[object Object]__sc-6nkvhz-4"
|
|
25
31
|
})(["display:flex;align-items:center;justify-content:start;"]);
|
|
26
32
|
const StyledExpandedCell = /*#__PURE__*/styled.td.withConfig({
|
|
27
33
|
displayName: "DataGridCell__StyledExpandedCell",
|
|
28
|
-
componentId: "[object Object]__sc-6nkvhz-
|
|
34
|
+
componentId: "[object Object]__sc-6nkvhz-5"
|
|
29
35
|
})(["", ""], props => {
|
|
30
36
|
return css(["padding:", "px;border-bottom:", " text-align:", ";font-size:", "px;font-weight:normal;line-height:", "px;color:", ";font-family:", ";"], props.cellPadding, props.isExpandedRowOpen ? `solid ${props.cellBorderBottomWidth}px ${props.headerBorderBottomColor};` : `solid ${props.cellBorderBottomWidth}px ${props.cellBorderBottomColor};`, props.cellTextAlign, props.cellFontSize, props.cellLineHeight * props.cellFontSize, props.cellTextColor, props.cellFontFamily);
|
|
31
37
|
});
|
|
32
38
|
const StyledExpandedCellDiv = /*#__PURE__*/styled.div.withConfig({
|
|
33
39
|
displayName: "DataGridCell__StyledExpandedCellDiv",
|
|
34
|
-
componentId: "[object Object]__sc-6nkvhz-
|
|
40
|
+
componentId: "[object Object]__sc-6nkvhz-6"
|
|
35
41
|
})(["", ""], props => {
|
|
36
42
|
return css(["display:flex;align-items:center;justify-content:", ";padding-left:", ";"], props.expandedContentAlignment ? props.expandedContentAlignment : 'start', props.showCheckbox ? `${props.expandedContentLeftPadding}px` : `${props.expandedContentDefaultLeftPadding}px`);
|
|
37
43
|
});
|
|
38
44
|
export const StyledCell = /*#__PURE__*/styled.td.withConfig({
|
|
39
45
|
displayName: "DataGridCell__StyledCell",
|
|
40
|
-
componentId: "[object Object]__sc-6nkvhz-
|
|
46
|
+
componentId: "[object Object]__sc-6nkvhz-7"
|
|
41
47
|
})(["", ""], props => {
|
|
42
48
|
if (props.isExpandedRowOpen) {
|
|
43
49
|
return css(["padding:", "px;text-align:", ";font-size:", "px;font-weight:normal;line-height:", "px;color:", ";font-family:", ";border-top:solid ", "px ", ";"], props.cellPadding, props.cellTextAlign, props.cellFontSize, props.cellLineHeight * props.cellFontSize, props.cellTextColor, props.cellFontFamily, props.headerBorderTopWidth, props.headerBorderTopColor);
|
|
@@ -52,16 +58,21 @@ const DataGridCell = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
52
58
|
columnsLength,
|
|
53
59
|
showCheckbox = false,
|
|
54
60
|
isFirstCol = false,
|
|
55
|
-
isExpandedRowOpen = false
|
|
61
|
+
isExpandedRowOpen = false,
|
|
62
|
+
isHeaderVisible = true
|
|
56
63
|
} = _ref;
|
|
57
64
|
if (type === CELL_TYPE.HEADING) {
|
|
58
|
-
return /*#__PURE__*/_jsx(StyledHeaderCell, {
|
|
65
|
+
return isHeaderVisible ? /*#__PURE__*/_jsx(StyledHeaderCell, {
|
|
59
66
|
...tokens,
|
|
60
67
|
firstColWidth: isFirstCol ? tokens.firstColWidth : 'auto',
|
|
61
68
|
ref: ref,
|
|
62
69
|
children: /*#__PURE__*/_jsx(StyledHeaderCellDiv, {
|
|
63
70
|
children: children
|
|
64
71
|
})
|
|
72
|
+
}) : /*#__PURE__*/_jsx(StyledHeaderCellHiddenHeader, {
|
|
73
|
+
...tokens,
|
|
74
|
+
firstColWidth: isFirstCol ? tokens.firstColWidth : 'auto',
|
|
75
|
+
ref: ref
|
|
65
76
|
});
|
|
66
77
|
}
|
|
67
78
|
if (type === CELL_TYPE.SUBHEADING) {
|
|
@@ -124,6 +135,10 @@ DataGridCell.propTypes = {
|
|
|
124
135
|
/**
|
|
125
136
|
* isExpandedRowOpen passed to the component to determine if cell is displaying additional data
|
|
126
137
|
*/
|
|
127
|
-
isExpandedRowOpen: PropTypes.bool
|
|
138
|
+
isExpandedRowOpen: PropTypes.bool,
|
|
139
|
+
/**
|
|
140
|
+
* Passed to the component to determine if header is displayed. Set to false to hide header of datagrid. Set to true by default
|
|
141
|
+
*/
|
|
142
|
+
isHeaderVisible: PropTypes.bool
|
|
128
143
|
};
|
|
129
144
|
export default DataGridCell;
|
package/lib/esm/utility.js
CHANGED
|
@@ -19,18 +19,34 @@ export const DATA_TYPE = {
|
|
|
19
19
|
const mappedData = array => {
|
|
20
20
|
return array.map(element => {
|
|
21
21
|
const eachRow = {
|
|
22
|
-
...element
|
|
23
|
-
isSelected: false
|
|
22
|
+
...element
|
|
24
23
|
};
|
|
25
24
|
if (eachRow.expandedRowChildComponent) {
|
|
26
25
|
eachRow.hasExpandedRow = true;
|
|
27
26
|
eachRow.isExpandedRowOpen = element.expandedRowChildComponent.displayOnLoad;
|
|
28
27
|
}
|
|
28
|
+
if (!eachRow.hideCheckbox) {
|
|
29
|
+
eachRow.hideCheckbox = false;
|
|
30
|
+
}
|
|
31
|
+
if (!eachRow.checkBoxProps) {
|
|
32
|
+
eachRow.checkBoxProps = {
|
|
33
|
+
value: `row_${eachRow.id}`,
|
|
34
|
+
inactive: false,
|
|
35
|
+
checked: false,
|
|
36
|
+
onChange: () => {}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
29
39
|
return eachRow;
|
|
30
40
|
});
|
|
31
41
|
};
|
|
32
42
|
export const isAtLeastOneRowUnselected = array => {
|
|
33
|
-
return array.some(each => each.
|
|
43
|
+
return array.some(each => each.checkBoxProps?.inactive === false && each.checkBoxProps?.checked === false);
|
|
44
|
+
};
|
|
45
|
+
export const isAtLeastOneRowEnabled = array => {
|
|
46
|
+
return array.some(each => each.checkBoxProps?.inactive === false);
|
|
47
|
+
};
|
|
48
|
+
export const hasEveryRowHiddenItsCheckbox = array => {
|
|
49
|
+
return array.every(each => each.hideCheckbox === true);
|
|
34
50
|
};
|
|
35
51
|
export const resetColumnsData = data => {
|
|
36
52
|
return data.map(element => ({
|
|
@@ -55,17 +71,28 @@ export const resetRowData = function (data) {
|
|
|
55
71
|
};
|
|
56
72
|
export const toggleAllCheckBoxes = (array, headerCheckBoxState) => {
|
|
57
73
|
return array.map(element => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
74
|
+
let _el = null;
|
|
75
|
+
if (element.hideCheckbox === true || element.checkBoxProps && element.checkBoxProps.inactive) {
|
|
76
|
+
_el = {
|
|
77
|
+
...element
|
|
78
|
+
};
|
|
79
|
+
} else {
|
|
80
|
+
_el = {
|
|
81
|
+
...element
|
|
82
|
+
};
|
|
83
|
+
_el.checkBoxProps.checked = !headerCheckBoxState;
|
|
84
|
+
}
|
|
85
|
+
return _el;
|
|
62
86
|
});
|
|
63
87
|
};
|
|
64
88
|
export const toggleRowCheckbox = (array, rowId) => {
|
|
65
|
-
return array.map(el =>
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
89
|
+
return array.map(el => {
|
|
90
|
+
const _el = {
|
|
91
|
+
...el
|
|
92
|
+
};
|
|
93
|
+
_el.checkBoxProps.checked = el.id === rowId ? !_el.checkBoxProps.checked : _el.checkBoxProps.checked;
|
|
94
|
+
return _el;
|
|
95
|
+
});
|
|
69
96
|
};
|
|
70
97
|
export const toggleExpandedRow = (array, rowId) => {
|
|
71
98
|
return array.map(el => ({
|
package/package.json
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
],
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"prop-types": "^15.7.2",
|
|
8
|
-
"@telus-uds/components-web": "^4.1
|
|
9
|
-
"@telus-uds/components-base": "^3.
|
|
10
|
-
"@telus-uds/system-theme-tokens": "^4.
|
|
8
|
+
"@telus-uds/components-web": "^4.2.1",
|
|
9
|
+
"@telus-uds/components-base": "^3.3.0",
|
|
10
|
+
"@telus-uds/system-theme-tokens": "^4.2.0",
|
|
11
11
|
"styled-components": "6.1.13",
|
|
12
12
|
"smooth-scrollbar": "8.8.4",
|
|
13
13
|
"smooth-scrollbar-react": "2.4.1"
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"standard-engine": {
|
|
47
47
|
"skip": true
|
|
48
48
|
},
|
|
49
|
-
"version": "1.0
|
|
49
|
+
"version": "1.2.0"
|
|
50
50
|
}
|
package/src/DataGrid.jsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react'
|
|
1
|
+
import React, { useEffect } from 'react'
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
import {
|
|
4
4
|
Typography,
|
|
@@ -16,6 +16,8 @@ import {
|
|
|
16
16
|
DATA_TYPE,
|
|
17
17
|
SORT_DIRECTION,
|
|
18
18
|
isAtLeastOneRowUnselected,
|
|
19
|
+
isAtLeastOneRowEnabled,
|
|
20
|
+
hasEveryRowHiddenItsCheckbox,
|
|
19
21
|
toggleAllCheckBoxes,
|
|
20
22
|
toggleExpandedRow,
|
|
21
23
|
toggleRowCheckbox,
|
|
@@ -48,7 +50,8 @@ const DataGrid = React.forwardRef(
|
|
|
48
50
|
tokens,
|
|
49
51
|
variant,
|
|
50
52
|
copy = 'en',
|
|
51
|
-
testID = 'data-grid'
|
|
53
|
+
testID = 'data-grid',
|
|
54
|
+
isHeaderVisible
|
|
52
55
|
},
|
|
53
56
|
ref
|
|
54
57
|
) => {
|
|
@@ -60,18 +63,36 @@ const DataGrid = React.forwardRef(
|
|
|
60
63
|
)
|
|
61
64
|
const [columnsData, setColumnsData] = React.useState(resetColumnsData(columns))
|
|
62
65
|
const [checkAllState, setCheckAllState] = React.useState(false)
|
|
66
|
+
const [disableHeaderCheckbox, setDisableHeaderCheckbox] = React.useState(false)
|
|
67
|
+
const [hideHeaderCheckBoxByRows, setHideHeaderCheckBoxByRows] = React.useState(false)
|
|
68
|
+
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
let _isAtLeastOneRowUnselected = null
|
|
71
|
+
let _isAtLeastOneRowEnabled = null
|
|
72
|
+
let _hideHeaderCheckBoxByRows = null
|
|
63
73
|
|
|
64
|
-
const shouldCheckHeaderBox = (allData) => {
|
|
65
|
-
let isARowUnselectedInAllGroups = null
|
|
66
74
|
if (groupedRows) {
|
|
67
|
-
|
|
68
|
-
return isAtLeastOneRowUnselected(
|
|
75
|
+
_isAtLeastOneRowUnselected = Object.keys(data).some((el) => {
|
|
76
|
+
return isAtLeastOneRowUnselected(data[el].data)
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
_isAtLeastOneRowEnabled = Object.keys(data).some((el) => {
|
|
80
|
+
return isAtLeastOneRowEnabled(data[el].data)
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
_hideHeaderCheckBoxByRows = Object.keys(data).some((el) => {
|
|
84
|
+
return hasEveryRowHiddenItsCheckbox(data[el].data)
|
|
69
85
|
})
|
|
70
86
|
} else {
|
|
71
|
-
|
|
87
|
+
_isAtLeastOneRowUnselected = isAtLeastOneRowUnselected(data)
|
|
88
|
+
_isAtLeastOneRowEnabled = isAtLeastOneRowEnabled(data)
|
|
89
|
+
_hideHeaderCheckBoxByRows = hasEveryRowHiddenItsCheckbox(data)
|
|
72
90
|
}
|
|
73
|
-
|
|
74
|
-
|
|
91
|
+
|
|
92
|
+
setCheckAllState(_isAtLeastOneRowEnabled === false ? false : !_isAtLeastOneRowUnselected)
|
|
93
|
+
setDisableHeaderCheckbox(!_isAtLeastOneRowEnabled)
|
|
94
|
+
setHideHeaderCheckBoxByRows(_hideHeaderCheckBoxByRows)
|
|
95
|
+
}, [data, groupedRows])
|
|
75
96
|
|
|
76
97
|
const shouldDisplayIconColumn = (allData, _showCheckbox) => {
|
|
77
98
|
let doesOneRowHaveExpandedContent = null
|
|
@@ -101,8 +122,13 @@ const DataGrid = React.forwardRef(
|
|
|
101
122
|
setCheckAllState(!checkAllState)
|
|
102
123
|
}
|
|
103
124
|
|
|
104
|
-
const toggleCheckbox = (rowId) => {
|
|
125
|
+
const toggleCheckbox = (rowId, row) => {
|
|
105
126
|
let _data = null
|
|
127
|
+
|
|
128
|
+
if (typeof row.checkBoxProps?.onChange === 'function') {
|
|
129
|
+
row.checkBoxProps.onChange()
|
|
130
|
+
}
|
|
131
|
+
|
|
106
132
|
if (groupedRows) {
|
|
107
133
|
const [group, _] = rowId.split('-')
|
|
108
134
|
const id = parseInt(_, 10)
|
|
@@ -127,16 +153,23 @@ const DataGrid = React.forwardRef(
|
|
|
127
153
|
setData(_row)
|
|
128
154
|
}
|
|
129
155
|
|
|
130
|
-
const HeaderCheckBoxDisplay = showCheckbox && (
|
|
156
|
+
const HeaderCheckBoxDisplay = showCheckbox && !hideHeaderCheckBoxByRows && (
|
|
131
157
|
<Checkbox
|
|
132
158
|
label={getCopy('all')}
|
|
133
|
-
checked={
|
|
159
|
+
checked={checkAllState}
|
|
160
|
+
inactive={disableHeaderCheckbox}
|
|
134
161
|
onChange={toggleSelectAll}
|
|
135
162
|
/>
|
|
136
163
|
)
|
|
137
164
|
|
|
138
|
-
const buildCheckBoxDisplay = (_showCheckbox, row, rowId) =>
|
|
139
|
-
|
|
165
|
+
const buildCheckBoxDisplay = (_showCheckbox, row, rowId) => {
|
|
166
|
+
return (
|
|
167
|
+
_showCheckbox &&
|
|
168
|
+
!row.hideCheckbox && (
|
|
169
|
+
<Checkbox {...row.checkBoxProps} onChange={() => toggleCheckbox(rowId, row)} />
|
|
170
|
+
)
|
|
171
|
+
)
|
|
172
|
+
}
|
|
140
173
|
|
|
141
174
|
const buildDisplayCaret = (row, rowId) =>
|
|
142
175
|
row.hasExpandedRow && (
|
|
@@ -188,7 +221,11 @@ const DataGrid = React.forwardRef(
|
|
|
188
221
|
onClick={toggleRowExpansion}
|
|
189
222
|
>
|
|
190
223
|
{shouldDisplayIconColumn(data, _showCheckbox) && (
|
|
191
|
-
<DataGridCell
|
|
224
|
+
<DataGridCell
|
|
225
|
+
tokens={themeTokens}
|
|
226
|
+
isExpandedRowOpen={row.isExpandedRowOpen}
|
|
227
|
+
isHeaderVisible={isHeaderVisible}
|
|
228
|
+
>
|
|
192
229
|
<StyledIconContainer>
|
|
193
230
|
{CheckBoxDisplay}
|
|
194
231
|
{DisplayCaret}
|
|
@@ -199,6 +236,7 @@ const DataGrid = React.forwardRef(
|
|
|
199
236
|
<DataGridCell
|
|
200
237
|
tokens={themeTokens}
|
|
201
238
|
isExpandedRowOpen={row.isExpandedRowOpen}
|
|
239
|
+
isHeaderVisible={isHeaderVisible}
|
|
202
240
|
key={`${rowId}-${column.key}`}
|
|
203
241
|
>
|
|
204
242
|
<Typography
|
|
@@ -257,6 +295,7 @@ const DataGrid = React.forwardRef(
|
|
|
257
295
|
type={CELL_TYPE.SUBHEADING}
|
|
258
296
|
tokens={themeTokens}
|
|
259
297
|
columnsLength={columnsData.length}
|
|
298
|
+
isHeaderVisible={isHeaderVisible}
|
|
260
299
|
>
|
|
261
300
|
{data[group].groupHeaderComponent || DefaultSubHeading}
|
|
262
301
|
</DataGridCell>
|
|
@@ -305,7 +344,12 @@ const DataGrid = React.forwardRef(
|
|
|
305
344
|
HeaderContent = (
|
|
306
345
|
<>
|
|
307
346
|
{shouldDisplayIconColumn(data, showCheckbox) && (
|
|
308
|
-
<DataGridCell
|
|
347
|
+
<DataGridCell
|
|
348
|
+
type={CELL_TYPE.HEADING}
|
|
349
|
+
tokens={themeTokens}
|
|
350
|
+
isFirstCol={true}
|
|
351
|
+
isHeaderVisible={isHeaderVisible}
|
|
352
|
+
>
|
|
309
353
|
{HeaderCheckBoxDisplay}
|
|
310
354
|
</DataGridCell>
|
|
311
355
|
)}
|
|
@@ -316,6 +360,7 @@ const DataGrid = React.forwardRef(
|
|
|
316
360
|
key={column.key}
|
|
317
361
|
tokens={themeTokens}
|
|
318
362
|
isSortable={isSortable}
|
|
363
|
+
isHeaderVisible={isHeaderVisible}
|
|
319
364
|
>
|
|
320
365
|
<Typography
|
|
321
366
|
block
|
|
@@ -426,6 +471,16 @@ DataGrid.propTypes = {
|
|
|
426
471
|
expandedRowChildComponent: PropTypes.shape({
|
|
427
472
|
component: PropTypes.node,
|
|
428
473
|
displayOnLoad: PropTypes.bool.isRequired
|
|
474
|
+
}),
|
|
475
|
+
/**
|
|
476
|
+
* Set this to true to hide checkbox for the specified row
|
|
477
|
+
*/
|
|
478
|
+
hideCheckbox: PropTypes.bool,
|
|
479
|
+
checkBoxProps: PropTypes.shape({
|
|
480
|
+
checked: PropTypes.bool,
|
|
481
|
+
name: PropTypes.string,
|
|
482
|
+
value: PropTypes.string.isRequired,
|
|
483
|
+
onChange: PropTypes.func
|
|
429
484
|
})
|
|
430
485
|
})
|
|
431
486
|
),
|
|
@@ -457,7 +512,11 @@ DataGrid.propTypes = {
|
|
|
457
512
|
/**
|
|
458
513
|
* Use in tests if the datagrid test cases need to find the element with the id.
|
|
459
514
|
*/
|
|
460
|
-
testID: PropTypes.string
|
|
515
|
+
testID: PropTypes.string,
|
|
516
|
+
/**
|
|
517
|
+
* Passed to the component to determine if header is displayed. Set to false to hide header of datagrid. Set to true by default
|
|
518
|
+
*/
|
|
519
|
+
isHeaderVisible: PropTypes.bool
|
|
461
520
|
}
|
|
462
521
|
|
|
463
522
|
export default DataGrid
|
package/src/DataGridCell.jsx
CHANGED
|
@@ -25,6 +25,17 @@ const StyledHeaderCellDiv = styled.div`
|
|
|
25
25
|
display: flex;
|
|
26
26
|
align-items: center;
|
|
27
27
|
`
|
|
28
|
+
const StyledHeaderCellHiddenHeader = styled.th`
|
|
29
|
+
${(props) => {
|
|
30
|
+
return css`
|
|
31
|
+
background-color: ${props.headerRowBackgroundColor};
|
|
32
|
+
border-bottom: solid ${props.headerBorderBottomWidth}px ${props.cellBorderBottomColor};
|
|
33
|
+
padding: 0px;
|
|
34
|
+
width: ${props.firstColWidth};
|
|
35
|
+
height: 1px;
|
|
36
|
+
`
|
|
37
|
+
}}
|
|
38
|
+
`
|
|
28
39
|
|
|
29
40
|
const StyledGroupHeaderCell = styled.td`
|
|
30
41
|
${(props) => {
|
|
@@ -118,12 +129,13 @@ const DataGridCell = React.forwardRef(
|
|
|
118
129
|
columnsLength,
|
|
119
130
|
showCheckbox = false,
|
|
120
131
|
isFirstCol = false,
|
|
121
|
-
isExpandedRowOpen = false
|
|
132
|
+
isExpandedRowOpen = false,
|
|
133
|
+
isHeaderVisible = true
|
|
122
134
|
},
|
|
123
135
|
ref
|
|
124
136
|
) => {
|
|
125
137
|
if (type === CELL_TYPE.HEADING) {
|
|
126
|
-
return (
|
|
138
|
+
return isHeaderVisible ? (
|
|
127
139
|
<StyledHeaderCell
|
|
128
140
|
{...tokens}
|
|
129
141
|
firstColWidth={isFirstCol ? tokens.firstColWidth : 'auto'}
|
|
@@ -131,6 +143,12 @@ const DataGridCell = React.forwardRef(
|
|
|
131
143
|
>
|
|
132
144
|
<StyledHeaderCellDiv>{children}</StyledHeaderCellDiv>
|
|
133
145
|
</StyledHeaderCell>
|
|
146
|
+
) : (
|
|
147
|
+
<StyledHeaderCellHiddenHeader
|
|
148
|
+
{...tokens}
|
|
149
|
+
firstColWidth={isFirstCol ? tokens.firstColWidth : 'auto'}
|
|
150
|
+
ref={ref}
|
|
151
|
+
/>
|
|
134
152
|
)
|
|
135
153
|
}
|
|
136
154
|
if (type === CELL_TYPE.SUBHEADING) {
|
|
@@ -192,7 +210,11 @@ DataGridCell.propTypes = {
|
|
|
192
210
|
/**
|
|
193
211
|
* isExpandedRowOpen passed to the component to determine if cell is displaying additional data
|
|
194
212
|
*/
|
|
195
|
-
isExpandedRowOpen: PropTypes.bool
|
|
213
|
+
isExpandedRowOpen: PropTypes.bool,
|
|
214
|
+
/**
|
|
215
|
+
* Passed to the component to determine if header is displayed. Set to false to hide header of datagrid. Set to true by default
|
|
216
|
+
*/
|
|
217
|
+
isHeaderVisible: PropTypes.bool
|
|
196
218
|
}
|
|
197
219
|
|
|
198
220
|
export default DataGridCell
|
package/src/utility.jsx
CHANGED
|
@@ -22,17 +22,40 @@ export const DATA_TYPE = {
|
|
|
22
22
|
|
|
23
23
|
const mappedData = (array) => {
|
|
24
24
|
return array.map((element) => {
|
|
25
|
-
const eachRow = { ...element
|
|
25
|
+
const eachRow = { ...element }
|
|
26
26
|
if (eachRow.expandedRowChildComponent) {
|
|
27
27
|
eachRow.hasExpandedRow = true
|
|
28
28
|
eachRow.isExpandedRowOpen = element.expandedRowChildComponent.displayOnLoad
|
|
29
29
|
}
|
|
30
|
+
|
|
31
|
+
if (!eachRow.hideCheckbox) {
|
|
32
|
+
eachRow.hideCheckbox = false
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (!eachRow.checkBoxProps) {
|
|
36
|
+
eachRow.checkBoxProps = {
|
|
37
|
+
value: `row_${eachRow.id}`,
|
|
38
|
+
inactive: false,
|
|
39
|
+
checked: false,
|
|
40
|
+
onChange: () => {}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
30
43
|
return eachRow
|
|
31
44
|
})
|
|
32
45
|
}
|
|
33
46
|
|
|
34
47
|
export const isAtLeastOneRowUnselected = (array) => {
|
|
35
|
-
return array.some(
|
|
48
|
+
return array.some(
|
|
49
|
+
(each) => each.checkBoxProps?.inactive === false && each.checkBoxProps?.checked === false
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const isAtLeastOneRowEnabled = (array) => {
|
|
54
|
+
return array.some((each) => each.checkBoxProps?.inactive === false)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export const hasEveryRowHiddenItsCheckbox = (array) => {
|
|
58
|
+
return array.every((each) => each.hideCheckbox === true)
|
|
36
59
|
}
|
|
37
60
|
|
|
38
61
|
export const resetColumnsData = (data) => {
|
|
@@ -49,6 +72,7 @@ export const resetRowData = (data, isGrouped = false) => {
|
|
|
49
72
|
data.forEach((el) => {
|
|
50
73
|
result[el.key] = { ...el, data: mappedData(el.data) }
|
|
51
74
|
})
|
|
75
|
+
|
|
52
76
|
return result
|
|
53
77
|
}
|
|
54
78
|
|
|
@@ -57,15 +81,27 @@ export const resetRowData = (data, isGrouped = false) => {
|
|
|
57
81
|
|
|
58
82
|
export const toggleAllCheckBoxes = (array, headerCheckBoxState) => {
|
|
59
83
|
return array.map((element) => {
|
|
60
|
-
|
|
84
|
+
let _el = null
|
|
85
|
+
if (
|
|
86
|
+
element.hideCheckbox === true ||
|
|
87
|
+
(element.checkBoxProps && element.checkBoxProps.inactive)
|
|
88
|
+
) {
|
|
89
|
+
_el = { ...element }
|
|
90
|
+
} else {
|
|
91
|
+
_el = { ...element }
|
|
92
|
+
_el.checkBoxProps.checked = !headerCheckBoxState
|
|
93
|
+
}
|
|
94
|
+
return _el
|
|
61
95
|
})
|
|
62
96
|
}
|
|
63
97
|
|
|
64
98
|
export const toggleRowCheckbox = (array, rowId) => {
|
|
65
|
-
return array.map((el) =>
|
|
66
|
-
...el
|
|
67
|
-
|
|
68
|
-
|
|
99
|
+
return array.map((el) => {
|
|
100
|
+
const _el = { ...el }
|
|
101
|
+
_el.checkBoxProps.checked =
|
|
102
|
+
el.id === rowId ? !_el.checkBoxProps.checked : _el.checkBoxProps.checked
|
|
103
|
+
return _el
|
|
104
|
+
})
|
|
69
105
|
}
|
|
70
106
|
|
|
71
107
|
export const toggleExpandedRow = (array, rowId) => {
|