@carbon/ibm-products 1.11.2 → 1.14.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +0 -3
- package/css/components/Datagrid/styles/addons/CustomizeColumnsModal.css +47 -0
- package/css/components/Datagrid/styles/addons/CustomizeColumnsModal.css.map +1 -0
- package/css/components/Datagrid/styles/addons/RowSizeDropdown.css +20 -0
- package/css/components/Datagrid/styles/addons/RowSizeDropdown.css.map +1 -0
- package/css/components/Datagrid/styles/datagrid.css +264 -0
- package/css/components/Datagrid/styles/datagrid.css.map +1 -0
- package/css/components/Datagrid/styles/index.css +509 -0
- package/css/components/Datagrid/styles/index.css.map +1 -0
- package/css/components/Datagrid/styles/useActionsColumn.css +23 -0
- package/css/components/Datagrid/styles/useActionsColumn.css.map +1 -0
- package/css/components/Datagrid/styles/useColumnRightAlign.css +28 -0
- package/css/components/Datagrid/styles/useColumnRightAlign.css.map +1 -0
- package/css/components/Datagrid/styles/useNestedRows.css +15 -0
- package/css/components/Datagrid/styles/useNestedRows.css.map +1 -0
- package/css/components/Datagrid/styles/useNestedTable.css +25 -0
- package/css/components/Datagrid/styles/useNestedTable.css.map +1 -0
- package/css/components/Datagrid/styles/useSelectAllToggle.css +28 -0
- package/css/components/Datagrid/styles/useSelectAllToggle.css.map +1 -0
- package/css/components/Datagrid/styles/useSortableColumns.css +50 -0
- package/css/components/Datagrid/styles/useSortableColumns.css.map +1 -0
- package/css/components/Datagrid/styles/useStickyColumn.css +35 -0
- package/css/components/Datagrid/styles/useStickyColumn.css.map +1 -0
- package/css/index-full-carbon.css +2019 -376
- package/css/index-full-carbon.css.map +1 -1
- package/css/index-full-carbon.min.css +6 -6
- package/css/index-full-carbon.min.css.map +1 -1
- package/css/index-without-carbon-released-only.css +18 -6
- package/css/index-without-carbon-released-only.css.map +1 -1
- package/css/index-without-carbon-released-only.min.css +2 -2
- package/css/index-without-carbon-released-only.min.css.map +1 -1
- package/css/index-without-carbon.css +679 -19
- package/css/index-without-carbon.css.map +1 -1
- package/css/index-without-carbon.min.css +5 -5
- package/css/index-without-carbon.min.css.map +1 -1
- package/css/index.css +679 -19
- package/css/index.css.map +1 -1
- package/css/index.min.css +6 -6
- package/css/index.min.css.map +1 -1
- package/es/components/ActionBar/ActionBar.js +3 -1
- package/es/components/ActionBar/ActionBarOverflowItems.js +5 -3
- package/es/components/AddSelect/AddSelect.js +133 -30
- package/es/components/AddSelect/AddSelectColumn.js +0 -1
- package/es/components/AddSelect/AddSelectFilter.js +129 -0
- package/es/components/AddSelect/AddSelectList.js +59 -13
- package/es/components/AddSelect/AddSelectSidebar.js +15 -5
- package/es/components/AddSelect/add-select-utils.js +30 -0
- package/es/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +2 -0
- package/es/components/DataSpreadsheet/DataSpreadsheet.js +262 -164
- package/es/components/DataSpreadsheet/DataSpreadsheetBody.js +191 -51
- package/es/components/DataSpreadsheet/DataSpreadsheetHeader.js +65 -13
- package/es/components/DataSpreadsheet/hooks/index.js +10 -0
- package/es/components/DataSpreadsheet/hooks/useMultipleKeyTracking.js +111 -0
- package/es/components/DataSpreadsheet/hooks/useResetSpreadsheetFocus.js +2 -4
- package/es/components/DataSpreadsheet/hooks/useSpreadsheetOutsideClick.js +6 -6
- package/es/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +3 -1
- package/es/components/DataSpreadsheet/utils/handleMultipleKeys.js +80 -6
- package/es/components/Datagrid/Datagrid/Datagrid.js +70 -0
- package/es/components/Datagrid/Datagrid/DatagridBody.js +36 -0
- package/es/components/Datagrid/Datagrid/DatagridEmptyBody.js +19 -0
- package/es/components/Datagrid/Datagrid/DatagridExpandedRow.js +26 -0
- package/es/components/Datagrid/Datagrid/DatagridHead.js +31 -0
- package/es/components/Datagrid/Datagrid/DatagridHeaderRow.js +57 -0
- package/es/components/Datagrid/Datagrid/DatagridRefBody.js +37 -0
- package/es/components/Datagrid/Datagrid/DatagridRow.js +50 -0
- package/es/components/Datagrid/Datagrid/DatagridSelectAll.js +50 -0
- package/es/components/Datagrid/Datagrid/DatagridSelectAllWithToggle.js +122 -0
- package/es/components/Datagrid/Datagrid/DatagridSimpleBody.js +36 -0
- package/es/components/Datagrid/Datagrid/DatagridToolbar.js +22 -0
- package/es/components/Datagrid/Datagrid/DatagridVirtualBody.js +87 -0
- package/es/components/Datagrid/Datagrid/DraggableElement.js +188 -0
- package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/Actions.js +78 -0
- package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/ButtonWrapper.js +51 -0
- package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +140 -0
- package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsModal.js +157 -0
- package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/ModalWrapper.js +62 -0
- package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/common.js +13 -0
- package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/index.js +9 -0
- package/es/components/Datagrid/Datagrid/addons/RowSize/RowSizeDropdown.js +62 -0
- package/es/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.js +139 -0
- package/es/components/Datagrid/Datagrid/addons/RowSize/index.js +8 -0
- package/es/components/Datagrid/Datagrid/index.js +8 -0
- package/es/components/Datagrid/Datagrid.stories/CustomizeColumnStory.js +6 -0
- package/es/components/Datagrid/Datagrid.stories/LeftPanelStory.js +6 -0
- package/es/components/Datagrid/Datagrid.stories/RowSizeDropdownStory.js +6 -0
- package/es/components/Datagrid/Datagrid.stories/SelectAllWithToggleStory.js +6 -0
- package/es/components/Datagrid/Datagrid.stories/StickyActionsColumnStory.js +92 -0
- package/es/components/Datagrid/Datagrid.stories/common.js +199 -0
- package/es/components/Datagrid/Datagrid.stories/index.js +5 -0
- package/es/components/Datagrid/common-column-ids.js +8 -0
- package/es/components/Datagrid/index.js +22 -0
- package/es/components/Datagrid/useActionsColumn.js +86 -0
- package/es/components/Datagrid/useColumnRightAlign.js +52 -0
- package/es/components/Datagrid/useCustomizeColumns.js +45 -0
- package/es/components/Datagrid/useDatagrid.js +44 -0
- package/es/components/Datagrid/useDefaultStringRenderer.js +48 -0
- package/es/components/Datagrid/useDisableSelectRows.js +84 -0
- package/es/components/Datagrid/useExpandedRow.js +52 -0
- package/es/components/Datagrid/useFlexResize.js +51 -0
- package/es/components/Datagrid/useFloatingScroll.js +88 -0
- package/es/components/Datagrid/useInfiniteScroll.js +54 -0
- package/es/components/Datagrid/useNestedRows.js +53 -0
- package/es/components/Datagrid/useOnRowClick.js +37 -0
- package/es/components/Datagrid/useParentDimensions.js +65 -0
- package/es/components/Datagrid/useResizeTable.js +40 -0
- package/es/components/Datagrid/useRowExpander.js +34 -0
- package/es/components/Datagrid/useRowIsMouseOver.js +61 -0
- package/es/components/Datagrid/useRowRenderer.js +30 -0
- package/es/components/Datagrid/useRowSize.js +56 -0
- package/es/components/Datagrid/useSelectAllToggle.js +74 -0
- package/es/components/Datagrid/useSelectRows.js +107 -0
- package/es/components/Datagrid/useSkeletonRows.js +32 -0
- package/es/components/Datagrid/useSortableColumns.js +110 -0
- package/es/components/Datagrid/useStickyColumn.js +183 -0
- package/es/components/HTTPErrors/assets/HTTPErrorSvg403.js +2 -3
- package/es/components/HTTPErrors/assets/HTTPErrorSvg404.js +2 -3
- package/es/components/HTTPErrors/assets/HTTPErrorSvgOther.js +2 -3
- package/es/components/ImportModal/ImportModal.js +2 -2
- package/es/components/TagSet/TagSet.js +12 -3
- package/es/components/UserProfileImage/UserProfileImage.js +38 -10
- package/es/components/index.js +2 -1
- package/es/global/js/package-settings.js +2 -1
- package/lib/components/ActionBar/ActionBar.js +3 -1
- package/lib/components/ActionBar/ActionBarOverflowItems.js +5 -3
- package/lib/components/AddSelect/AddSelect.js +132 -28
- package/lib/components/AddSelect/AddSelectColumn.js +0 -1
- package/lib/components/AddSelect/AddSelectFilter.js +147 -0
- package/lib/components/AddSelect/AddSelectList.js +61 -12
- package/lib/components/AddSelect/AddSelectSidebar.js +15 -11
- package/lib/components/AddSelect/add-select-utils.js +35 -2
- package/lib/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +2 -0
- package/lib/components/DataSpreadsheet/DataSpreadsheet.js +267 -168
- package/lib/components/DataSpreadsheet/DataSpreadsheetBody.js +191 -57
- package/lib/components/DataSpreadsheet/DataSpreadsheetHeader.js +67 -18
- package/lib/components/DataSpreadsheet/hooks/index.js +37 -0
- package/lib/components/DataSpreadsheet/hooks/useMultipleKeyTracking.js +123 -0
- package/lib/components/DataSpreadsheet/hooks/useResetSpreadsheetFocus.js +2 -4
- package/lib/components/DataSpreadsheet/hooks/useSpreadsheetOutsideClick.js +6 -5
- package/lib/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +3 -1
- package/lib/components/DataSpreadsheet/utils/handleMultipleKeys.js +83 -7
- package/lib/components/Datagrid/Datagrid/Datagrid.js +86 -0
- package/lib/components/Datagrid/Datagrid/DatagridBody.js +50 -0
- package/lib/components/Datagrid/Datagrid/DatagridEmptyBody.js +31 -0
- package/lib/components/Datagrid/Datagrid/DatagridExpandedRow.js +38 -0
- package/lib/components/Datagrid/Datagrid/DatagridHead.js +43 -0
- package/lib/components/Datagrid/Datagrid/DatagridHeaderRow.js +73 -0
- package/lib/components/Datagrid/Datagrid/DatagridRefBody.js +44 -0
- package/lib/components/Datagrid/Datagrid/DatagridRow.js +56 -0
- package/lib/components/Datagrid/Datagrid/DatagridSelectAll.js +55 -0
- package/lib/components/Datagrid/Datagrid/DatagridSelectAllWithToggle.js +139 -0
- package/lib/components/Datagrid/Datagrid/DatagridSimpleBody.js +44 -0
- package/lib/components/Datagrid/Datagrid/DatagridToolbar.js +35 -0
- package/lib/components/Datagrid/Datagrid/DatagridVirtualBody.js +101 -0
- package/lib/components/Datagrid/Datagrid/DraggableElement.js +210 -0
- package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/Actions.js +92 -0
- package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/ButtonWrapper.js +65 -0
- package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +166 -0
- package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsModal.js +173 -0
- package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/ModalWrapper.js +73 -0
- package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/common.js +25 -0
- package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/index.js +23 -0
- package/lib/components/Datagrid/Datagrid/addons/RowSize/RowSizeDropdown.js +80 -0
- package/lib/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.js +160 -0
- package/lib/components/Datagrid/Datagrid/addons/RowSize/index.js +15 -0
- package/lib/components/Datagrid/Datagrid/index.js +15 -0
- package/lib/components/Datagrid/Datagrid.stories/CustomizeColumnStory.js +13 -0
- package/lib/components/Datagrid/Datagrid.stories/LeftPanelStory.js +13 -0
- package/lib/components/Datagrid/Datagrid.stories/RowSizeDropdownStory.js +13 -0
- package/lib/components/Datagrid/Datagrid.stories/SelectAllWithToggleStory.js +13 -0
- package/lib/components/Datagrid/Datagrid.stories/StickyActionsColumnStory.js +112 -0
- package/lib/components/Datagrid/Datagrid.stories/common.js +215 -0
- package/lib/components/Datagrid/Datagrid.stories/index.js +47 -0
- package/lib/components/Datagrid/common-column-ids.js +16 -0
- package/lib/components/Datagrid/index.js +127 -0
- package/lib/components/Datagrid/useActionsColumn.js +94 -0
- package/lib/components/Datagrid/useColumnRightAlign.js +59 -0
- package/lib/components/Datagrid/useCustomizeColumns.js +55 -0
- package/lib/components/Datagrid/useDatagrid.js +58 -0
- package/lib/components/Datagrid/useDefaultStringRenderer.js +54 -0
- package/lib/components/Datagrid/useDisableSelectRows.js +92 -0
- package/lib/components/Datagrid/useExpandedRow.js +58 -0
- package/lib/components/Datagrid/useFlexResize.js +61 -0
- package/lib/components/Datagrid/useFloatingScroll.js +101 -0
- package/lib/components/Datagrid/useInfiniteScroll.js +67 -0
- package/lib/components/Datagrid/useNestedRows.js +65 -0
- package/lib/components/Datagrid/useOnRowClick.js +45 -0
- package/lib/components/Datagrid/useParentDimensions.js +75 -0
- package/lib/components/Datagrid/useResizeTable.js +48 -0
- package/lib/components/Datagrid/useRowExpander.js +45 -0
- package/lib/components/Datagrid/useRowIsMouseOver.js +66 -0
- package/lib/components/Datagrid/useRowRenderer.js +40 -0
- package/lib/components/Datagrid/useRowSize.js +67 -0
- package/lib/components/Datagrid/useSelectAllToggle.js +88 -0
- package/lib/components/Datagrid/useSelectRows.js +119 -0
- package/lib/components/Datagrid/useSkeletonRows.js +42 -0
- package/lib/components/Datagrid/useSortableColumns.js +117 -0
- package/lib/components/Datagrid/useStickyColumn.js +190 -0
- package/lib/components/HTTPErrors/assets/HTTPErrorSvg403.js +2 -3
- package/lib/components/HTTPErrors/assets/HTTPErrorSvg404.js +2 -3
- package/lib/components/HTTPErrors/assets/HTTPErrorSvgOther.js +2 -3
- package/lib/components/ImportModal/ImportModal.js +1 -1
- package/lib/components/TagSet/TagSet.js +12 -3
- package/lib/components/UserProfileImage/UserProfileImage.js +38 -10
- package/lib/components/index.js +9 -1
- package/lib/global/js/package-settings.js +2 -1
- package/package.json +19 -15
- package/scss/components/AboutModal/_about-modal.scss +2 -2
- package/scss/components/ActionSet/_action-set.scss +3 -1
- package/scss/components/AddSelect/_add-select.scss +87 -3
- package/scss/components/CreateModal/_create-modal.scss +7 -5
- package/scss/components/CreateModal/_storybook-styles.scss +8 -7
- package/scss/components/DataSpreadsheet/_data-spreadsheet.scss +70 -10
- package/scss/components/Datagrid/_datagrid.scss +66 -0
- package/scss/components/Datagrid/_index.scss +8 -0
- package/scss/components/Datagrid/_storybook-styles.scss +26 -0
- package/scss/components/Datagrid/styles/_variables.scss +9 -0
- package/scss/components/Datagrid/styles/addons/CustomizeColumnsModal.scss +48 -0
- package/scss/components/Datagrid/styles/addons/RowSizeDropdown.scss +23 -0
- package/scss/components/Datagrid/styles/datagrid.scss +318 -0
- package/scss/components/Datagrid/styles/index.scss +17 -0
- package/scss/components/Datagrid/styles/useActionsColumn.scss +24 -0
- package/scss/components/Datagrid/styles/useColumnRightAlign.scss +29 -0
- package/scss/components/Datagrid/styles/useNestedRows.scss +17 -0
- package/scss/components/Datagrid/styles/useNestedTable.scss +28 -0
- package/scss/components/Datagrid/styles/useSelectAllToggle.scss +28 -0
- package/scss/components/Datagrid/styles/useSortableColumns.scss +55 -0
- package/scss/components/Datagrid/styles/useStickyColumn.scss +38 -0
- package/scss/components/ExportModal/_export-modal.scss +3 -3
- package/scss/components/HTTPErrors/_http-errors.scss +16 -16
- package/scss/components/InlineEdit/_inline-edit.scss +0 -1
- package/scss/components/ModifiedTabs/_modified-tabs.scss +0 -10
- package/scss/components/NotificationsPanel/_notifications-panel.scss +3 -3
- package/scss/components/OptionsTile/_options-tile.scss +0 -1
- package/scss/components/PageHeader/_page-header.scss +4 -0
- package/scss/components/RemoveModal/_remove-modal.scss +3 -3
- package/scss/components/TagSet/_tag-set.scss +2 -1
- package/scss/components/Tearsheet/_tearsheet.scss +5 -2
- package/scss/components/_index.scss +1 -0
@@ -0,0 +1,84 @@
|
|
1
|
+
/*
|
2
|
+
* Licensed Materials - Property of IBM
|
3
|
+
* 5724-Q36
|
4
|
+
* (c) Copyright IBM Corp. 2020
|
5
|
+
* US Government Users Restricted Rights - Use, duplication or disclosure
|
6
|
+
* restricted by GSA ADP Schedule Contract with IBM Corp.
|
7
|
+
*/
|
8
|
+
var useDisableSelectRows = function useDisableSelectRows(hooks) {
|
9
|
+
updateSelectAll(hooks);
|
10
|
+
updatePageSelectAll(hooks);
|
11
|
+
|
12
|
+
var getRowProps = function getRowProps(props, _ref) {
|
13
|
+
var row = _ref.row,
|
14
|
+
instance = _ref.instance;
|
15
|
+
return [props, {
|
16
|
+
selectDisabled: instance.shouldDisableSelectRow && instance.shouldDisableSelectRow(row)
|
17
|
+
}];
|
18
|
+
};
|
19
|
+
|
20
|
+
hooks.getRowProps.push(getRowProps);
|
21
|
+
};
|
22
|
+
|
23
|
+
var updateSelectAll = function updateSelectAll(hooks) {
|
24
|
+
var getToggleAllRowsSelectedProps = function getToggleAllRowsSelectedProps(props, _ref2) {
|
25
|
+
var instance = _ref2.instance;
|
26
|
+
var selectableRows = instance.rows.filter(function (row) {
|
27
|
+
return !(instance.shouldDisableSelectRow && instance.shouldDisableSelectRow(row));
|
28
|
+
});
|
29
|
+
var isAllRowsSelected = selectableRows.length > 0 && selectableRows.every(function (_ref3) {
|
30
|
+
var id = _ref3.id;
|
31
|
+
return instance.state.selectedRowIds[id];
|
32
|
+
});
|
33
|
+
return [props, {
|
34
|
+
onChange: function onChange(e) {
|
35
|
+
selectableRows.forEach(function (row) {
|
36
|
+
return row.toggleRowSelected(e.target.checked);
|
37
|
+
});
|
38
|
+
},
|
39
|
+
style: {
|
40
|
+
cursor: 'pointer'
|
41
|
+
},
|
42
|
+
checked: isAllRowsSelected,
|
43
|
+
disabled: instance.disableSelectAll,
|
44
|
+
title: 'Toggle All Rows Selected',
|
45
|
+
indeterminate: Boolean(!isAllRowsSelected && Object.keys(instance.state.selectedRowIds).length)
|
46
|
+
}];
|
47
|
+
};
|
48
|
+
|
49
|
+
hooks.getToggleAllRowsSelectedProps.push(getToggleAllRowsSelectedProps);
|
50
|
+
};
|
51
|
+
|
52
|
+
var updatePageSelectAll = function updatePageSelectAll(hooks) {
|
53
|
+
var getToggleAllPageRowsSelectedProps = function getToggleAllPageRowsSelectedProps(props, _ref4) {
|
54
|
+
var instance = _ref4.instance;
|
55
|
+
var selectableRows = instance.page.filter(function (row) {
|
56
|
+
return !(instance.shouldDisableSelectRow && instance.shouldDisableSelectRow(row));
|
57
|
+
});
|
58
|
+
var isAllRowsSelected = selectableRows.length > 0 && selectableRows.every(function (_ref5) {
|
59
|
+
var id = _ref5.id;
|
60
|
+
return instance.state.selectedRowIds[id];
|
61
|
+
});
|
62
|
+
return [props, {
|
63
|
+
onChange: function onChange(e) {
|
64
|
+
selectableRows.forEach(function (row) {
|
65
|
+
return row.toggleRowSelected(e.target.checked);
|
66
|
+
});
|
67
|
+
},
|
68
|
+
style: {
|
69
|
+
cursor: 'pointer'
|
70
|
+
},
|
71
|
+
checked: isAllRowsSelected,
|
72
|
+
disabled: instance.disableSelectAll,
|
73
|
+
title: 'Toggle All Rows Selected',
|
74
|
+
indeterminate: Boolean(!isAllRowsSelected && instance.page.some(function (_ref6) {
|
75
|
+
var id = _ref6.id;
|
76
|
+
return instance.state.selectedRowIds[id];
|
77
|
+
}))
|
78
|
+
}];
|
79
|
+
};
|
80
|
+
|
81
|
+
hooks.getToggleAllPageRowsSelectedProps.push(getToggleAllPageRowsSelectedProps);
|
82
|
+
};
|
83
|
+
|
84
|
+
export default useDisableSelectRows;
|
@@ -0,0 +1,52 @@
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
3
|
+
|
4
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
5
|
+
|
6
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
7
|
+
|
8
|
+
/*
|
9
|
+
* Licensed Materials - Property of IBM
|
10
|
+
* 5724-Q36
|
11
|
+
* (c) Copyright IBM Corp. 2020
|
12
|
+
* US Government Users Restricted Rights - Use, duplication or disclosure
|
13
|
+
* restricted by GSA ADP Schedule Contract with IBM Corp.
|
14
|
+
*/
|
15
|
+
import { useState } from 'react';
|
16
|
+
import DatagridExpandedRow from './Datagrid/DatagridExpandedRow';
|
17
|
+
import useRowExpander from './useRowExpander';
|
18
|
+
|
19
|
+
var useExpandedRow = function useExpandedRow(hooks) {
|
20
|
+
useRowExpander(hooks);
|
21
|
+
|
22
|
+
var useInstance = function useInstance(instance) {
|
23
|
+
var rows = instance.rows,
|
24
|
+
expandedContentHeight = instance.expandedContentHeight,
|
25
|
+
ExpandedRowContentComponent = instance.ExpandedRowContentComponent;
|
26
|
+
|
27
|
+
var _useState = useState({}),
|
28
|
+
_useState2 = _slicedToArray(_useState, 2),
|
29
|
+
expandedRowsHeight = _useState2[0],
|
30
|
+
setExpandedRowsHeight = _useState2[1];
|
31
|
+
|
32
|
+
var setExpandedRowHeight = function setExpandedRowHeight(rowIndex, height) {
|
33
|
+
return setExpandedRowsHeight(_objectSpread(_objectSpread({}, expandedRowsHeight), {}, _defineProperty({}, rowIndex, height)));
|
34
|
+
};
|
35
|
+
|
36
|
+
var rowsWithExpand = rows.map(function (row) {
|
37
|
+
return _objectSpread(_objectSpread({}, row), {}, {
|
38
|
+
canExpand: row.original && !row.original.notExpandable,
|
39
|
+
expandedContentHeight: expandedRowsHeight[row.index] || expandedContentHeight,
|
40
|
+
RowRenderer: DatagridExpandedRow(row.RowRenderer, ExpandedRowContentComponent)
|
41
|
+
});
|
42
|
+
});
|
43
|
+
Object.assign(instance, {
|
44
|
+
rows: rowsWithExpand,
|
45
|
+
setExpandedRowHeight: setExpandedRowHeight
|
46
|
+
});
|
47
|
+
};
|
48
|
+
|
49
|
+
hooks.useInstance.push(useInstance);
|
50
|
+
};
|
51
|
+
|
52
|
+
export default useExpandedRow;
|
@@ -0,0 +1,51 @@
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
2
|
+
|
3
|
+
/*
|
4
|
+
* Licensed Materials - Property of IBM
|
5
|
+
* 5724-Q36
|
6
|
+
* (c) Copyright IBM Corp. 2020
|
7
|
+
* US Government Users Restricted Rights - Use, duplication or disclosure
|
8
|
+
* restricted by GSA ADP Schedule Contract with IBM Corp.
|
9
|
+
*/
|
10
|
+
var useFlexResize = function useFlexResize(hooks) {
|
11
|
+
var spacerColumn = {
|
12
|
+
id: 'spacer',
|
13
|
+
width: 0,
|
14
|
+
disableSortBy: true,
|
15
|
+
disableResizing: true
|
16
|
+
};
|
17
|
+
hooks.visibleColumns.push(function (columns) {
|
18
|
+
return [].concat(_toConsumableArray(columns), [spacerColumn]);
|
19
|
+
});
|
20
|
+
|
21
|
+
var changeProps = function changeProps(props, data) {
|
22
|
+
var column = data.column;
|
23
|
+
|
24
|
+
if (!column && data.cell) {
|
25
|
+
column = data.cell.column;
|
26
|
+
}
|
27
|
+
|
28
|
+
if (column.id === spacerColumn.id) {
|
29
|
+
return [props, {
|
30
|
+
style: {
|
31
|
+
flex: '1 1 0'
|
32
|
+
}
|
33
|
+
}];
|
34
|
+
}
|
35
|
+
|
36
|
+
return [props, {
|
37
|
+
style: {
|
38
|
+
flex: '0 0 auto'
|
39
|
+
}
|
40
|
+
}];
|
41
|
+
};
|
42
|
+
|
43
|
+
hooks.getHeaderProps.push(function (props, data) {
|
44
|
+
return changeProps(props, data);
|
45
|
+
});
|
46
|
+
hooks.getCellProps.push(function (props, data) {
|
47
|
+
return changeProps(props, data);
|
48
|
+
});
|
49
|
+
};
|
50
|
+
|
51
|
+
export default useFlexResize;
|
@@ -0,0 +1,88 @@
|
|
1
|
+
/*
|
2
|
+
* Licensed Materials - Property of IBM
|
3
|
+
* 5724-Q36
|
4
|
+
* (c) Copyright IBM Corp. 2021
|
5
|
+
* US Government Users Restricted Rights - Use, duplication or disclosure
|
6
|
+
* restricted by GSA ADP Schedule Contract with IBM Corp.
|
7
|
+
*/
|
8
|
+
import { useEffect } from 'react';
|
9
|
+
import cx from 'classnames';
|
10
|
+
import { pkg } from '../../settings';
|
11
|
+
var blockClass = "".concat(pkg.prefix, "--datagrid");
|
12
|
+
|
13
|
+
var useFloatingScroll = function useFloatingScroll(hooks) {
|
14
|
+
var useInstance = function useInstance(instance) {
|
15
|
+
var tableId = instance.tableId,
|
16
|
+
withVirtualScroll = instance.withVirtualScroll,
|
17
|
+
ExpandedRowContentComponent = instance.ExpandedRowContentComponent;
|
18
|
+
useEffect(function () {
|
19
|
+
// Floating scroll doesn't work with expanded rows and virtual scroll
|
20
|
+
if (withVirtualScroll || ExpandedRowContentComponent) {
|
21
|
+
return;
|
22
|
+
}
|
23
|
+
|
24
|
+
var datagrid = document.getElementById(tableId); // eslint-disable-next-line no-unused-expressions
|
25
|
+
|
26
|
+
datagrid === null || datagrid === void 0 ? void 0 : datagrid.classList.add("".concat(blockClass, "__sticky"));
|
27
|
+
}, [ExpandedRowContentComponent, tableId, withVirtualScroll]);
|
28
|
+
};
|
29
|
+
|
30
|
+
var useAddStickyClass = function useAddStickyClass(instance) {
|
31
|
+
var withVirtualScroll = instance.withVirtualScroll,
|
32
|
+
ExpandedRowContentComponent = instance.ExpandedRowContentComponent; // Floating scroll doesn't work with expanded rows and virtual scroll
|
33
|
+
|
34
|
+
if (withVirtualScroll || ExpandedRowContentComponent) {
|
35
|
+
return;
|
36
|
+
}
|
37
|
+
|
38
|
+
var addStickyClass = function addStickyClass(props) {
|
39
|
+
return [props, {
|
40
|
+
className: cx(props.className, "".concat(blockClass, "__sticky"))
|
41
|
+
}];
|
42
|
+
};
|
43
|
+
|
44
|
+
hooks.getTableProps.push(addStickyClass);
|
45
|
+
hooks.getTableBodyProps.push(addStickyClass);
|
46
|
+
hooks.getHeaderGroupProps.push(addStickyClass);
|
47
|
+
};
|
48
|
+
|
49
|
+
var useAddScrollListener = function useAddScrollListener(instance) {
|
50
|
+
var withVirtualScroll = instance.withVirtualScroll,
|
51
|
+
ExpandedRowContentComponent = instance.ExpandedRowContentComponent,
|
52
|
+
tableId = instance.tableId; // Floating scroll doesn't work with expanded rows and virtual scroll
|
53
|
+
|
54
|
+
if (withVirtualScroll || ExpandedRowContentComponent) {
|
55
|
+
return;
|
56
|
+
}
|
57
|
+
|
58
|
+
var memoHead;
|
59
|
+
|
60
|
+
var addOnScroll = function addOnScroll(props) {
|
61
|
+
return [props, {
|
62
|
+
onScroll: function onScroll(e) {
|
63
|
+
var simpleThead;
|
64
|
+
|
65
|
+
if (memoHead) {
|
66
|
+
simpleThead = memoHead;
|
67
|
+
} else {
|
68
|
+
var datagrid = document.getElementById(tableId);
|
69
|
+
simpleThead = datagrid === null || datagrid === void 0 ? void 0 : datagrid.querySelector(".".concat(blockClass, "__table-simple thead > div"));
|
70
|
+
memoHead = simpleThead;
|
71
|
+
}
|
72
|
+
|
73
|
+
if (simpleThead) {
|
74
|
+
simpleThead.scrollLeft = e.target.scrollLeft;
|
75
|
+
}
|
76
|
+
}
|
77
|
+
}];
|
78
|
+
};
|
79
|
+
|
80
|
+
hooks.getTableBodyProps.push(addOnScroll);
|
81
|
+
};
|
82
|
+
|
83
|
+
hooks.useInstance.push(useAddStickyClass);
|
84
|
+
hooks.useInstance.push(useAddScrollListener);
|
85
|
+
hooks.useInstance.push(useInstance);
|
86
|
+
};
|
87
|
+
|
88
|
+
export default useFloatingScroll;
|
@@ -0,0 +1,54 @@
|
|
1
|
+
/*
|
2
|
+
* Licensed Materials - Property of IBM
|
3
|
+
* 5724-Q36
|
4
|
+
* (c) Copyright IBM Corp. 2020
|
5
|
+
* US Government Users Restricted Rights - Use, duplication or disclosure
|
6
|
+
* restricted by GSA ADP Schedule Contract with IBM Corp.
|
7
|
+
*/
|
8
|
+
import { useCallback } from 'react';
|
9
|
+
import debounce from 'lodash/debounce';
|
10
|
+
import useParentDimensions from './useParentDimensions';
|
11
|
+
import useResizeTable from './useResizeTable';
|
12
|
+
|
13
|
+
var useInfiniteScroll = function useInfiniteScroll(hooks) {
|
14
|
+
useParentDimensions(hooks);
|
15
|
+
useResizeTable(hooks);
|
16
|
+
|
17
|
+
var useInstance = function useInstance(instance) {
|
18
|
+
var isFetching = instance.isFetching,
|
19
|
+
tableHeight = instance.tableHeight,
|
20
|
+
innerListRef = instance.innerListRef,
|
21
|
+
fetchMoreData = instance.fetchMoreData;
|
22
|
+
var loadMoreThreshold = 200;
|
23
|
+
|
24
|
+
var emptyFetchData = function emptyFetchData() {}; // eslint-disable-next-line react-hooks/exhaustive-deps
|
25
|
+
|
26
|
+
|
27
|
+
var fetchMore = useCallback(debounce(fetchMoreData || emptyFetchData, 3000, {
|
28
|
+
leading: true,
|
29
|
+
trailing: false
|
30
|
+
}), [fetchMoreData]);
|
31
|
+
|
32
|
+
var onScroll = function onScroll(_ref) {
|
33
|
+
var scrollDirection = _ref.scrollDirection,
|
34
|
+
scrollOffset = _ref.scrollOffset;
|
35
|
+
|
36
|
+
if (innerListRef && innerListRef.current) {
|
37
|
+
if (!isFetching && scrollDirection === 'forward' && scrollOffset + tableHeight >= innerListRef.current.clientHeight - loadMoreThreshold) {
|
38
|
+
if (fetchMoreData) {
|
39
|
+
fetchMore();
|
40
|
+
}
|
41
|
+
}
|
42
|
+
}
|
43
|
+
};
|
44
|
+
|
45
|
+
Object.assign(instance, {
|
46
|
+
onScroll: onScroll,
|
47
|
+
withVirtualScroll: true
|
48
|
+
});
|
49
|
+
};
|
50
|
+
|
51
|
+
hooks.useInstance.push(useInstance);
|
52
|
+
};
|
53
|
+
|
54
|
+
export default useInfiniteScroll;
|
@@ -0,0 +1,53 @@
|
|
1
|
+
/*
|
2
|
+
* Licensed Materials - Property of IBM
|
3
|
+
* 5724-Q36
|
4
|
+
* (c) Copyright IBM Corp. 2020
|
5
|
+
* US Government Users Restricted Rights - Use, duplication or disclosure
|
6
|
+
* restricted by GSA ADP Schedule Contract with IBM Corp.
|
7
|
+
*/
|
8
|
+
import useRowExpander from './useRowExpander';
|
9
|
+
import { pkg } from '../../settings';
|
10
|
+
var blockClass = "".concat(pkg.prefix, "--datagrid");
|
11
|
+
|
12
|
+
var useNestedRows = function useNestedRows(hooks) {
|
13
|
+
useRowExpander(hooks);
|
14
|
+
var marginLeft = 32;
|
15
|
+
|
16
|
+
var getRowProps = function getRowProps(props, _ref) {
|
17
|
+
var row = _ref.row;
|
18
|
+
return [props, {
|
19
|
+
className: row.depth > 0 ? "".concat(blockClass, "__carbon-nested-row") : ''
|
20
|
+
}];
|
21
|
+
};
|
22
|
+
|
23
|
+
var getRowStyles = function getRowStyles(props, _ref2) {
|
24
|
+
var row = _ref2.row;
|
25
|
+
return [props, {
|
26
|
+
style: {
|
27
|
+
marginLeft: "".concat(row.depth > 0 ? marginLeft : 0, "px"),
|
28
|
+
paddingLeft: "".concat(row.depth > 1 ? marginLeft * (row.depth - 1) : 0, "px"),
|
29
|
+
maxWidth: "calc(100% - ".concat(marginLeft * row.depth, "px)")
|
30
|
+
}
|
31
|
+
}];
|
32
|
+
};
|
33
|
+
|
34
|
+
var getCellProps = function getCellProps(props, _ref3) {
|
35
|
+
var cell = _ref3.cell,
|
36
|
+
instance = _ref3.instance;
|
37
|
+
// reduce the "first cell"s width to compensate added (left) margin
|
38
|
+
var isFirstCell = instance.columns.findIndex(function (c) {
|
39
|
+
return c.id === cell.column.id;
|
40
|
+
}) === 0;
|
41
|
+
return [props, {
|
42
|
+
style: {
|
43
|
+
marginRight: isFirstCell ? "-".concat(marginLeft * cell.row.depth, "px") : ''
|
44
|
+
}
|
45
|
+
}];
|
46
|
+
};
|
47
|
+
|
48
|
+
hooks.getRowProps.push(getRowProps);
|
49
|
+
hooks.getRowProps.push(getRowStyles);
|
50
|
+
hooks.getCellProps.push(getCellProps);
|
51
|
+
};
|
52
|
+
|
53
|
+
export default useNestedRows;
|
@@ -0,0 +1,37 @@
|
|
1
|
+
/*
|
2
|
+
* Licensed Materials - Property of IBM
|
3
|
+
* 5724-Q36
|
4
|
+
* (c) Copyright IBM Corp. 2020
|
5
|
+
* US Government Users Restricted Rights - Use, duplication or disclosure
|
6
|
+
* restricted by GSA ADP Schedule Contract with IBM Corp.
|
7
|
+
*/
|
8
|
+
var useOnRowClick = function useOnRowClick(hooks) {
|
9
|
+
var useInstance = function useInstance(instance) {
|
10
|
+
var onRowClick = instance.onRowClick;
|
11
|
+
|
12
|
+
var getRowProps = function getRowProps(props, datagridState) {
|
13
|
+
var isFetching = datagridState.isFetching,
|
14
|
+
row = datagridState.row;
|
15
|
+
|
16
|
+
var onClick = function onClick() {
|
17
|
+
if (!isFetching && onRowClick) {
|
18
|
+
onRowClick(row);
|
19
|
+
}
|
20
|
+
};
|
21
|
+
|
22
|
+
return [props, {
|
23
|
+
onClick: onClick
|
24
|
+
}, {
|
25
|
+
style: {
|
26
|
+
cursor: 'pointer'
|
27
|
+
}
|
28
|
+
}];
|
29
|
+
};
|
30
|
+
|
31
|
+
hooks.getRowProps.push(getRowProps);
|
32
|
+
};
|
33
|
+
|
34
|
+
hooks.useInstance.push(useInstance);
|
35
|
+
};
|
36
|
+
|
37
|
+
export default useOnRowClick;
|
@@ -0,0 +1,65 @@
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
2
|
+
|
3
|
+
/*
|
4
|
+
* Licensed Materials - Property of IBM
|
5
|
+
* 5724-Q36
|
6
|
+
* (c) Copyright IBM Corp. 2020
|
7
|
+
* US Government Users Restricted Rights - Use, duplication or disclosure
|
8
|
+
* restricted by GSA ADP Schedule Contract with IBM Corp.
|
9
|
+
*/
|
10
|
+
import { useRef, useState } from 'react';
|
11
|
+
|
12
|
+
var useParentDimensions = function useParentDimensions(hooks) {
|
13
|
+
var rootRef = useRef();
|
14
|
+
var headRef = useRef();
|
15
|
+
var innerListRef = useRef();
|
16
|
+
var listRef = useRef();
|
17
|
+
|
18
|
+
var _useState = useState(),
|
19
|
+
_useState2 = _slicedToArray(_useState, 2),
|
20
|
+
tableHeight = _useState2[0],
|
21
|
+
setTableHeight = _useState2[1];
|
22
|
+
|
23
|
+
var useInstance = function useInstance(instance) {
|
24
|
+
var DatagridActions = instance.DatagridActions,
|
25
|
+
DatagridBatchActions = instance.DatagridBatchActions,
|
26
|
+
totalColumnsWidth = instance.totalColumnsWidth,
|
27
|
+
DatagridPagination = instance.DatagridPagination;
|
28
|
+
|
29
|
+
var handleResize = function handleResize() {
|
30
|
+
var parent = rootRef && rootRef.current && rootRef.current.parentElement;
|
31
|
+
|
32
|
+
if (!parent) {
|
33
|
+
return;
|
34
|
+
}
|
35
|
+
|
36
|
+
var parentHeight = parent.clientHeight;
|
37
|
+
var parentWidth = parent.clientWidth;
|
38
|
+
var headHeight = headRef && headRef.current && headRef.current.clientHeight;
|
39
|
+
var parentStyles = window.getComputedStyle(parent);
|
40
|
+
var parentMarginBottom = parseFloat(parentStyles.getPropertyValue('margin-bottom'));
|
41
|
+
var parentPaddingBottom = parseFloat(parentStyles.getPropertyValue('padding-bottom'));
|
42
|
+
var parentMarginTop = parseFloat(parentStyles.getPropertyValue('margin-top'));
|
43
|
+
var parentPaddingTop = parseFloat(parentStyles.getPropertyValue('padding-top'));
|
44
|
+
var datagridActionsHeight = DatagridActions || DatagridBatchActions ? 48 : 0;
|
45
|
+
var datagridPaginationHeight = DatagridPagination ? 48 : 0;
|
46
|
+
var hasHorizontalScrollbar = parentWidth < totalColumnsWidth;
|
47
|
+
var horizontalScrollbarHolder = hasHorizontalScrollbar ? 16 : 0;
|
48
|
+
var newHeight = parentHeight - headHeight - parentMarginBottom - parentPaddingBottom - parentMarginTop - parentPaddingTop - datagridActionsHeight - datagridPaginationHeight - horizontalScrollbarHolder;
|
49
|
+
setTableHeight(newHeight);
|
50
|
+
};
|
51
|
+
|
52
|
+
Object.assign(instance, {
|
53
|
+
tableHeight: tableHeight,
|
54
|
+
rootRef: rootRef,
|
55
|
+
headRef: headRef,
|
56
|
+
innerListRef: innerListRef,
|
57
|
+
handleResize: handleResize,
|
58
|
+
listRef: listRef
|
59
|
+
});
|
60
|
+
};
|
61
|
+
|
62
|
+
hooks.useInstance.push(useInstance);
|
63
|
+
};
|
64
|
+
|
65
|
+
export default useParentDimensions;
|
@@ -0,0 +1,40 @@
|
|
1
|
+
/*
|
2
|
+
* Licensed Materials - Property of IBM
|
3
|
+
* 5724-Q36
|
4
|
+
* (c) Copyright IBM Corp. 2020
|
5
|
+
* US Government Users Restricted Rights - Use, duplication or disclosure
|
6
|
+
* restricted by GSA ADP Schedule Contract with IBM Corp.
|
7
|
+
*/
|
8
|
+
import { useLayoutEffect } from 'react';
|
9
|
+
|
10
|
+
var useResizeTable = function useResizeTable(hooks) {
|
11
|
+
var useInstanceBeforeDimensions = function useInstanceBeforeDimensions(instance) {
|
12
|
+
var rootRef = instance.rootRef,
|
13
|
+
handleResize = instance.handleResize;
|
14
|
+
var parent = rootRef && rootRef.current && rootRef.current.parentElement;
|
15
|
+
useLayoutEffect(function () {
|
16
|
+
if (!parent) {
|
17
|
+
return function () {};
|
18
|
+
}
|
19
|
+
|
20
|
+
handleResize();
|
21
|
+
|
22
|
+
if (typeof ResizeObserver === 'function') {
|
23
|
+
var resizeObserver = new ResizeObserver(function () {
|
24
|
+
handleResize();
|
25
|
+
});
|
26
|
+
resizeObserver.observe(parent);
|
27
|
+
return function () {
|
28
|
+
resizeObserver.disconnect(parent);
|
29
|
+
resizeObserver = null;
|
30
|
+
};
|
31
|
+
}
|
32
|
+
|
33
|
+
return console.error(' Could not resize table, no support for ResizeObserver');
|
34
|
+
}, [handleResize, parent]);
|
35
|
+
};
|
36
|
+
|
37
|
+
hooks.useInstanceBeforeDimensions.push(useInstanceBeforeDimensions);
|
38
|
+
};
|
39
|
+
|
40
|
+
export default useResizeTable;
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
2
|
+
|
3
|
+
/* eslint-disable react/prop-types */
|
4
|
+
|
5
|
+
/*
|
6
|
+
* Licensed Materials - Property of IBM
|
7
|
+
* 5724-Q36
|
8
|
+
* (c) Copyright IBM Corp. 2020
|
9
|
+
* US Government Users Restricted Rights - Use, duplication or disclosure
|
10
|
+
* restricted by GSA ADP Schedule Contract with IBM Corp.
|
11
|
+
*/
|
12
|
+
import React from 'react';
|
13
|
+
import { ChevronDown16, ChevronUp16 } from '@carbon/icons-react';
|
14
|
+
|
15
|
+
var useRowExpander = function useRowExpander(hooks) {
|
16
|
+
var visibleColumns = function visibleColumns(columns) {
|
17
|
+
var expanderColumn = {
|
18
|
+
id: 'expander',
|
19
|
+
Cell: function Cell(_ref) {
|
20
|
+
var row = _ref.row;
|
21
|
+
return row.canExpand && /*#__PURE__*/React.createElement("span", row.getToggleRowExpandedProps(), row.isExpanded ? /*#__PURE__*/React.createElement(ChevronUp16, null) : /*#__PURE__*/React.createElement(ChevronDown16, null));
|
22
|
+
},
|
23
|
+
width: 32,
|
24
|
+
disableResizing: true,
|
25
|
+
disableSortBy: true,
|
26
|
+
Header: ''
|
27
|
+
};
|
28
|
+
return [expanderColumn].concat(_toConsumableArray(columns));
|
29
|
+
};
|
30
|
+
|
31
|
+
hooks.visibleColumns.push(visibleColumns);
|
32
|
+
};
|
33
|
+
|
34
|
+
export default useRowExpander;
|
@@ -0,0 +1,61 @@
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
3
|
+
|
4
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
5
|
+
|
6
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
7
|
+
|
8
|
+
/*
|
9
|
+
* Licensed Materials - Property of IBM
|
10
|
+
* 5724-Q36
|
11
|
+
* (c) Copyright IBM Corp. 2020
|
12
|
+
* US Government Users Restricted Rights - Use, duplication or disclosure
|
13
|
+
* restricted by GSA ADP Schedule Contract with IBM Corp.
|
14
|
+
*/
|
15
|
+
import { useState, useCallback } from 'react';
|
16
|
+
import debounce from 'lodash/debounce';
|
17
|
+
|
18
|
+
var useRowIsMouseOver = function useRowIsMouseOver(hooks) {
|
19
|
+
var useInstance = function useInstance(instance) {
|
20
|
+
var _useState = useState(),
|
21
|
+
_useState2 = _slicedToArray(_useState, 2),
|
22
|
+
mouseOverRowIndex = _useState2[0],
|
23
|
+
setMouseOverRowIndex = _useState2[1];
|
24
|
+
|
25
|
+
var onMouseChange = useDebounce(function (datagridState) {
|
26
|
+
var row = datagridState.row;
|
27
|
+
setMouseOverRowIndex(row.index);
|
28
|
+
}, 100);
|
29
|
+
|
30
|
+
var getRowProps = function getRowProps(props, datagridState) {
|
31
|
+
var onMouseOver = function onMouseOver() {
|
32
|
+
return onMouseChange(datagridState);
|
33
|
+
};
|
34
|
+
|
35
|
+
return [props, {
|
36
|
+
onMouseOver: onMouseOver
|
37
|
+
}];
|
38
|
+
};
|
39
|
+
|
40
|
+
var rows = instance.rows;
|
41
|
+
var rowsWithMouseOver = rows.map(function (row) {
|
42
|
+
return _objectSpread(_objectSpread({}, row), {}, {
|
43
|
+
isMouseOver: row.index === mouseOverRowIndex
|
44
|
+
});
|
45
|
+
});
|
46
|
+
Object.assign(instance, {
|
47
|
+
rows: rowsWithMouseOver
|
48
|
+
});
|
49
|
+
hooks.getRowProps.push(getRowProps);
|
50
|
+
};
|
51
|
+
|
52
|
+
hooks.useInstance.push(useInstance);
|
53
|
+
};
|
54
|
+
|
55
|
+
var useDebounce = function useDebounce(fn, wait) {
|
56
|
+
return (// eslint-disable-next-line react-hooks/exhaustive-deps
|
57
|
+
useCallback(debounce(fn, wait), [])
|
58
|
+
);
|
59
|
+
};
|
60
|
+
|
61
|
+
export default useRowIsMouseOver;
|
@@ -0,0 +1,30 @@
|
|
1
|
+
/*
|
2
|
+
* Licensed Materials - Property of IBM
|
3
|
+
* 5724-Q36
|
4
|
+
* (c) Copyright IBM Corp. 2020
|
5
|
+
* US Government Users Restricted Rights - Use, duplication or disclosure
|
6
|
+
* restricted by GSA ADP Schedule Contract with IBM Corp.
|
7
|
+
*/
|
8
|
+
import DatagridRow from './Datagrid/DatagridRow';
|
9
|
+
|
10
|
+
var useRowRenderer = function useRowRenderer(hooks) {
|
11
|
+
var useInstance = function useInstance(instance) {
|
12
|
+
var rows = instance.rows;
|
13
|
+
|
14
|
+
var addRowRenderer = function addRowRenderer(row) {
|
15
|
+
return Object.assign(row, {
|
16
|
+
RowRenderer: DatagridRow,
|
17
|
+
subRows: (row.subRows || []).map(addRowRenderer)
|
18
|
+
});
|
19
|
+
};
|
20
|
+
|
21
|
+
var rowsWithRenderer = rows.map(addRowRenderer);
|
22
|
+
Object.assign(instance, {
|
23
|
+
rows: rowsWithRenderer
|
24
|
+
});
|
25
|
+
};
|
26
|
+
|
27
|
+
hooks.useInstance.push(useInstance);
|
28
|
+
};
|
29
|
+
|
30
|
+
export default useRowRenderer;
|