@carbon/ibm-products 1.13.0 → 1.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (198) hide show
  1. package/css/components/Datagrid/styles/addons/CustomizeColumnsModal.css +47 -0
  2. package/css/components/Datagrid/styles/addons/CustomizeColumnsModal.css.map +1 -0
  3. package/css/components/Datagrid/styles/addons/RowSizeDropdown.css +20 -0
  4. package/css/components/Datagrid/styles/addons/RowSizeDropdown.css.map +1 -0
  5. package/css/components/Datagrid/styles/datagrid.css +264 -0
  6. package/css/components/Datagrid/styles/datagrid.css.map +1 -0
  7. package/css/components/Datagrid/styles/index.css +509 -0
  8. package/css/components/Datagrid/styles/index.css.map +1 -0
  9. package/css/components/Datagrid/styles/useActionsColumn.css +23 -0
  10. package/css/components/Datagrid/styles/useActionsColumn.css.map +1 -0
  11. package/css/components/Datagrid/styles/useColumnRightAlign.css +28 -0
  12. package/css/components/Datagrid/styles/useColumnRightAlign.css.map +1 -0
  13. package/css/components/Datagrid/styles/useNestedRows.css +15 -0
  14. package/css/components/Datagrid/styles/useNestedRows.css.map +1 -0
  15. package/css/components/Datagrid/styles/useNestedTable.css +25 -0
  16. package/css/components/Datagrid/styles/useNestedTable.css.map +1 -0
  17. package/css/components/Datagrid/styles/useSelectAllToggle.css +28 -0
  18. package/css/components/Datagrid/styles/useSelectAllToggle.css.map +1 -0
  19. package/css/components/Datagrid/styles/useSortableColumns.css +50 -0
  20. package/css/components/Datagrid/styles/useSortableColumns.css.map +1 -0
  21. package/css/components/Datagrid/styles/useStickyColumn.css +35 -0
  22. package/css/components/Datagrid/styles/useStickyColumn.css.map +1 -0
  23. package/css/index-full-carbon.css +570 -3
  24. package/css/index-full-carbon.css.map +1 -1
  25. package/css/index-full-carbon.min.css +2 -2
  26. package/css/index-full-carbon.min.css.map +1 -1
  27. package/css/index-without-carbon-released-only.css +3 -0
  28. package/css/index-without-carbon-released-only.css.map +1 -1
  29. package/css/index-without-carbon-released-only.min.css +1 -1
  30. package/css/index-without-carbon-released-only.min.css.map +1 -1
  31. package/css/index-without-carbon.css +570 -3
  32. package/css/index-without-carbon.css.map +1 -1
  33. package/css/index-without-carbon.min.css +2 -2
  34. package/css/index-without-carbon.min.css.map +1 -1
  35. package/css/index.css +570 -3
  36. package/css/index.css.map +1 -1
  37. package/css/index.min.css +2 -2
  38. package/css/index.min.css.map +1 -1
  39. package/es/components/AddSelect/AddSelect.js +76 -24
  40. package/es/components/AddSelect/AddSelectFilter.js +129 -0
  41. package/es/components/AddSelect/add-select-utils.js +30 -0
  42. package/es/components/DataSpreadsheet/DataSpreadsheet.js +77 -53
  43. package/es/components/DataSpreadsheet/DataSpreadsheetBody.js +22 -9
  44. package/es/components/DataSpreadsheet/DataSpreadsheetHeader.js +15 -11
  45. package/es/components/DataSpreadsheet/hooks/index.js +10 -0
  46. package/es/components/DataSpreadsheet/hooks/useMultipleKeyTracking.js +111 -0
  47. package/es/components/DataSpreadsheet/hooks/useResetSpreadsheetFocus.js +2 -4
  48. package/es/components/DataSpreadsheet/hooks/useSpreadsheetOutsideClick.js +1 -3
  49. package/es/components/DataSpreadsheet/utils/handleMultipleKeys.js +80 -6
  50. package/es/components/Datagrid/Datagrid/Datagrid.js +70 -0
  51. package/es/components/Datagrid/Datagrid/DatagridBody.js +36 -0
  52. package/es/components/Datagrid/Datagrid/DatagridEmptyBody.js +19 -0
  53. package/es/components/Datagrid/Datagrid/DatagridExpandedRow.js +26 -0
  54. package/es/components/Datagrid/Datagrid/DatagridHead.js +31 -0
  55. package/es/components/Datagrid/Datagrid/DatagridHeaderRow.js +57 -0
  56. package/es/components/Datagrid/Datagrid/DatagridRefBody.js +37 -0
  57. package/es/components/Datagrid/Datagrid/DatagridRow.js +50 -0
  58. package/es/components/Datagrid/Datagrid/DatagridSelectAll.js +50 -0
  59. package/es/components/Datagrid/Datagrid/DatagridSelectAllWithToggle.js +122 -0
  60. package/es/components/Datagrid/Datagrid/DatagridSimpleBody.js +36 -0
  61. package/es/components/Datagrid/Datagrid/DatagridToolbar.js +22 -0
  62. package/es/components/Datagrid/Datagrid/DatagridVirtualBody.js +87 -0
  63. package/es/components/Datagrid/Datagrid/DraggableElement.js +188 -0
  64. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/Actions.js +78 -0
  65. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/ButtonWrapper.js +51 -0
  66. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +140 -0
  67. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsModal.js +157 -0
  68. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/ModalWrapper.js +62 -0
  69. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/common.js +13 -0
  70. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/index.js +9 -0
  71. package/es/components/Datagrid/Datagrid/addons/RowSize/RowSizeDropdown.js +62 -0
  72. package/es/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.js +139 -0
  73. package/es/components/Datagrid/Datagrid/addons/RowSize/index.js +8 -0
  74. package/es/components/Datagrid/Datagrid/index.js +8 -0
  75. package/es/components/Datagrid/Datagrid.stories/CustomizeColumnStory.js +6 -0
  76. package/es/components/Datagrid/Datagrid.stories/LeftPanelStory.js +6 -0
  77. package/es/components/Datagrid/Datagrid.stories/RowSizeDropdownStory.js +6 -0
  78. package/es/components/Datagrid/Datagrid.stories/SelectAllWithToggleStory.js +6 -0
  79. package/es/components/Datagrid/Datagrid.stories/StickyActionsColumnStory.js +92 -0
  80. package/es/components/Datagrid/Datagrid.stories/common.js +199 -0
  81. package/es/components/Datagrid/Datagrid.stories/index.js +5 -0
  82. package/es/components/Datagrid/common-column-ids.js +8 -0
  83. package/es/components/Datagrid/index.js +22 -0
  84. package/es/components/Datagrid/useActionsColumn.js +86 -0
  85. package/es/components/Datagrid/useColumnRightAlign.js +52 -0
  86. package/es/components/Datagrid/useCustomizeColumns.js +45 -0
  87. package/es/components/Datagrid/useDatagrid.js +44 -0
  88. package/es/components/Datagrid/useDefaultStringRenderer.js +48 -0
  89. package/es/components/Datagrid/useDisableSelectRows.js +84 -0
  90. package/es/components/Datagrid/useExpandedRow.js +52 -0
  91. package/es/components/Datagrid/useFlexResize.js +51 -0
  92. package/es/components/Datagrid/useFloatingScroll.js +88 -0
  93. package/es/components/Datagrid/useInfiniteScroll.js +54 -0
  94. package/es/components/Datagrid/useNestedRows.js +53 -0
  95. package/es/components/Datagrid/useOnRowClick.js +37 -0
  96. package/es/components/Datagrid/useParentDimensions.js +65 -0
  97. package/es/components/Datagrid/useResizeTable.js +40 -0
  98. package/es/components/Datagrid/useRowExpander.js +34 -0
  99. package/es/components/Datagrid/useRowIsMouseOver.js +61 -0
  100. package/es/components/Datagrid/useRowRenderer.js +30 -0
  101. package/es/components/Datagrid/useRowSize.js +56 -0
  102. package/es/components/Datagrid/useSelectAllToggle.js +74 -0
  103. package/es/components/Datagrid/useSelectRows.js +107 -0
  104. package/es/components/Datagrid/useSkeletonRows.js +32 -0
  105. package/es/components/Datagrid/useSortableColumns.js +110 -0
  106. package/es/components/Datagrid/useStickyColumn.js +183 -0
  107. package/es/components/index.js +2 -1
  108. package/es/global/js/package-settings.js +2 -1
  109. package/lib/components/AddSelect/AddSelect.js +75 -22
  110. package/lib/components/AddSelect/AddSelectFilter.js +147 -0
  111. package/lib/components/AddSelect/add-select-utils.js +35 -2
  112. package/lib/components/DataSpreadsheet/DataSpreadsheet.js +79 -56
  113. package/lib/components/DataSpreadsheet/DataSpreadsheetBody.js +22 -15
  114. package/lib/components/DataSpreadsheet/DataSpreadsheetHeader.js +15 -11
  115. package/lib/components/DataSpreadsheet/hooks/index.js +37 -0
  116. package/lib/components/DataSpreadsheet/hooks/useMultipleKeyTracking.js +123 -0
  117. package/lib/components/DataSpreadsheet/hooks/useResetSpreadsheetFocus.js +2 -4
  118. package/lib/components/DataSpreadsheet/hooks/useSpreadsheetOutsideClick.js +1 -3
  119. package/lib/components/DataSpreadsheet/utils/handleMultipleKeys.js +83 -7
  120. package/lib/components/Datagrid/Datagrid/Datagrid.js +86 -0
  121. package/lib/components/Datagrid/Datagrid/DatagridBody.js +50 -0
  122. package/lib/components/Datagrid/Datagrid/DatagridEmptyBody.js +31 -0
  123. package/lib/components/Datagrid/Datagrid/DatagridExpandedRow.js +38 -0
  124. package/lib/components/Datagrid/Datagrid/DatagridHead.js +43 -0
  125. package/lib/components/Datagrid/Datagrid/DatagridHeaderRow.js +73 -0
  126. package/lib/components/Datagrid/Datagrid/DatagridRefBody.js +44 -0
  127. package/lib/components/Datagrid/Datagrid/DatagridRow.js +56 -0
  128. package/lib/components/Datagrid/Datagrid/DatagridSelectAll.js +55 -0
  129. package/lib/components/Datagrid/Datagrid/DatagridSelectAllWithToggle.js +139 -0
  130. package/lib/components/Datagrid/Datagrid/DatagridSimpleBody.js +44 -0
  131. package/lib/components/Datagrid/Datagrid/DatagridToolbar.js +35 -0
  132. package/lib/components/Datagrid/Datagrid/DatagridVirtualBody.js +101 -0
  133. package/lib/components/Datagrid/Datagrid/DraggableElement.js +210 -0
  134. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/Actions.js +92 -0
  135. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/ButtonWrapper.js +65 -0
  136. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +166 -0
  137. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsModal.js +173 -0
  138. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/ModalWrapper.js +73 -0
  139. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/common.js +25 -0
  140. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/index.js +23 -0
  141. package/lib/components/Datagrid/Datagrid/addons/RowSize/RowSizeDropdown.js +80 -0
  142. package/lib/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.js +160 -0
  143. package/lib/components/Datagrid/Datagrid/addons/RowSize/index.js +15 -0
  144. package/lib/components/Datagrid/Datagrid/index.js +15 -0
  145. package/lib/components/Datagrid/Datagrid.stories/CustomizeColumnStory.js +13 -0
  146. package/lib/components/Datagrid/Datagrid.stories/LeftPanelStory.js +13 -0
  147. package/lib/components/Datagrid/Datagrid.stories/RowSizeDropdownStory.js +13 -0
  148. package/lib/components/Datagrid/Datagrid.stories/SelectAllWithToggleStory.js +13 -0
  149. package/lib/components/Datagrid/Datagrid.stories/StickyActionsColumnStory.js +112 -0
  150. package/lib/components/Datagrid/Datagrid.stories/common.js +215 -0
  151. package/lib/components/Datagrid/Datagrid.stories/index.js +47 -0
  152. package/lib/components/Datagrid/common-column-ids.js +16 -0
  153. package/lib/components/Datagrid/index.js +127 -0
  154. package/lib/components/Datagrid/useActionsColumn.js +94 -0
  155. package/lib/components/Datagrid/useColumnRightAlign.js +59 -0
  156. package/lib/components/Datagrid/useCustomizeColumns.js +55 -0
  157. package/lib/components/Datagrid/useDatagrid.js +58 -0
  158. package/lib/components/Datagrid/useDefaultStringRenderer.js +54 -0
  159. package/lib/components/Datagrid/useDisableSelectRows.js +92 -0
  160. package/lib/components/Datagrid/useExpandedRow.js +58 -0
  161. package/lib/components/Datagrid/useFlexResize.js +61 -0
  162. package/lib/components/Datagrid/useFloatingScroll.js +101 -0
  163. package/lib/components/Datagrid/useInfiniteScroll.js +67 -0
  164. package/lib/components/Datagrid/useNestedRows.js +65 -0
  165. package/lib/components/Datagrid/useOnRowClick.js +45 -0
  166. package/lib/components/Datagrid/useParentDimensions.js +75 -0
  167. package/lib/components/Datagrid/useResizeTable.js +48 -0
  168. package/lib/components/Datagrid/useRowExpander.js +45 -0
  169. package/lib/components/Datagrid/useRowIsMouseOver.js +66 -0
  170. package/lib/components/Datagrid/useRowRenderer.js +40 -0
  171. package/lib/components/Datagrid/useRowSize.js +67 -0
  172. package/lib/components/Datagrid/useSelectAllToggle.js +88 -0
  173. package/lib/components/Datagrid/useSelectRows.js +119 -0
  174. package/lib/components/Datagrid/useSkeletonRows.js +42 -0
  175. package/lib/components/Datagrid/useSortableColumns.js +117 -0
  176. package/lib/components/Datagrid/useStickyColumn.js +190 -0
  177. package/lib/components/index.js +9 -1
  178. package/lib/global/js/package-settings.js +2 -1
  179. package/package.json +6 -2
  180. package/scss/components/AddSelect/_add-select.scss +37 -0
  181. package/scss/components/DataSpreadsheet/_data-spreadsheet.scss +13 -3
  182. package/scss/components/Datagrid/_datagrid.scss +66 -0
  183. package/scss/components/Datagrid/_index.scss +8 -0
  184. package/scss/components/Datagrid/_storybook-styles.scss +26 -0
  185. package/scss/components/Datagrid/styles/_variables.scss +9 -0
  186. package/scss/components/Datagrid/styles/addons/CustomizeColumnsModal.scss +48 -0
  187. package/scss/components/Datagrid/styles/addons/RowSizeDropdown.scss +23 -0
  188. package/scss/components/Datagrid/styles/datagrid.scss +318 -0
  189. package/scss/components/Datagrid/styles/index.scss +17 -0
  190. package/scss/components/Datagrid/styles/useActionsColumn.scss +24 -0
  191. package/scss/components/Datagrid/styles/useColumnRightAlign.scss +29 -0
  192. package/scss/components/Datagrid/styles/useNestedRows.scss +17 -0
  193. package/scss/components/Datagrid/styles/useNestedTable.scss +28 -0
  194. package/scss/components/Datagrid/styles/useSelectAllToggle.scss +28 -0
  195. package/scss/components/Datagrid/styles/useSortableColumns.scss +55 -0
  196. package/scss/components/Datagrid/styles/useStickyColumn.scss +38 -0
  197. package/scss/components/Tearsheet/_tearsheet.scss +4 -0
  198. package/scss/components/_index.scss +1 -0
@@ -0,0 +1,140 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ // @flow
3
+
4
+ /*
5
+ * Licensed Materials - Property of IBM
6
+ * 5724-Q36
7
+ * (c) Copyright IBM Corp. 2021
8
+ * US Government Users Restricted Rights - Use, duplication or disclosure
9
+ * restricted by GSA ADP Schedule Contract with IBM Corp.
10
+ */
11
+ import * as React from 'react';
12
+ import PropTypes from 'prop-types';
13
+ import { DndProvider } from 'react-dnd';
14
+ import { HTML5Backend } from 'react-dnd-html5-backend';
15
+ import { Checkbox } from 'carbon-components-react';
16
+ import update from 'immutability-helper';
17
+ import { pkg } from '../../../../../settings';
18
+ import DraggableElement from '../../DraggableElement';
19
+ import { isColumnVisible } from './common';
20
+ var blockClass = "".concat(pkg.prefix, "--datagrid");
21
+
22
+ var getNextIndex = function getNextIndex(array, currentIndex, key) {
23
+ var newIndex = -1;
24
+
25
+ if (key === 'ArrowUp') {
26
+ newIndex = currentIndex - 1 >= 0 ? currentIndex - 1 : array.length - 1;
27
+ }
28
+
29
+ if (key === 'ArrowDown') {
30
+ newIndex = currentIndex + 1 < array.length ? currentIndex + 1 : 0;
31
+ }
32
+
33
+ return newIndex;
34
+ };
35
+
36
+ var Columns = function Columns(_ref) {
37
+ var filterString = _ref.filterString,
38
+ columns = _ref.columns,
39
+ setColumnsObject = _ref.setColumnsObject,
40
+ onSelectColumn = _ref.onSelectColumn,
41
+ _ref$instructionsLabe = _ref.instructionsLabel,
42
+ instructionsLabel = _ref$instructionsLabe === void 0 ? 'Press space bar to toggle drag drop mode, use arrow keys to move selected elements.' : _ref$instructionsLabe,
43
+ _ref$disabledInstruct = _ref.disabledInstructionsLabel,
44
+ disabledInstructionsLabel = _ref$disabledInstruct === void 0 ? 'Reordering columns are disabled because they are filtered currently.' : _ref$disabledInstruct;
45
+
46
+ var _React$useState = React.useState(''),
47
+ _React$useState2 = _slicedToArray(_React$useState, 2),
48
+ ariaRegionText = _React$useState2[0],
49
+ setAriaRegionText = _React$useState2[1];
50
+
51
+ var _React$useState3 = React.useState(-1),
52
+ _React$useState4 = _slicedToArray(_React$useState3, 2),
53
+ focusIndex = _React$useState4[0],
54
+ setFocusIndex = _React$useState4[1];
55
+
56
+ var moveElement = React.useCallback(function (dragIndex, hoverIndex) {
57
+ var dragCard = columns[dragIndex];
58
+ setColumnsObject(update(columns, {
59
+ $splice: [[dragIndex, 1], [hoverIndex, 0, dragCard]]
60
+ }));
61
+ }, [columns, setColumnsObject]);
62
+ return /*#__PURE__*/React.createElement("div", {
63
+ className: "".concat(blockClass, "__customize-columns-column-list")
64
+ }, /*#__PURE__*/React.createElement(DndProvider, {
65
+ backend: HTML5Backend
66
+ }, /*#__PURE__*/React.createElement("ol", {
67
+ className: "".concat(blockClass, "__customize-columns-column-list--focus"),
68
+ role: "listbox",
69
+ "aria-describedby": "".concat(blockClass, "__customize-columns--instructions"),
70
+ onKeyDown: function onKeyDown(e) {
71
+ var nextIndex = getNextIndex(columns, focusIndex, e.key);
72
+
73
+ if (nextIndex >= 0) {
74
+ setFocusIndex(nextIndex);
75
+ e.preventDefault();
76
+ e.stopPropagation();
77
+ }
78
+ },
79
+ tabIndex: 0,
80
+ onFocus: function onFocus(e) {
81
+ if (e.target === e.currentTarget) {
82
+ setFocusIndex(0);
83
+ }
84
+ }
85
+ }, /*#__PURE__*/React.createElement("span", {
86
+ "aria-live": "assertive",
87
+ className: "".concat(blockClass, "__shared-ui--assistive-text")
88
+ }, ariaRegionText), /*#__PURE__*/React.createElement("span", {
89
+ id: "".concat(blockClass, "__customize-columns--instructions"),
90
+ className: "".concat(blockClass, "__shared-ui--assistive-text")
91
+ }, filterString.length === 0 ? instructionsLabel : disabledInstructionsLabel), columns.filter(function (colDef) {
92
+ return filterString.length === 0 || colDef.Header.props.title.toLowerCase().includes(filterString);
93
+ }).map(function (colDef, i) {
94
+ return /*#__PURE__*/React.createElement(DraggableElement, {
95
+ key: colDef.id,
96
+ index: i,
97
+ listData: columns,
98
+ setListData: setColumnsObject,
99
+ id: "dnd-datagrid-columns-".concat(colDef.id),
100
+ type: "column-customization",
101
+ disabled: filterString.length > 0,
102
+ ariaLabel: colDef.Header.props.title,
103
+ onGrab: setAriaRegionText,
104
+ isFocused: focusIndex === i,
105
+ moveElement: moveElement,
106
+ onArrowKeyDown: function onArrowKeyDown(e, isGrabbed, currentIndex) {
107
+ if (isGrabbed) {
108
+ var nextIndex = getNextIndex(columns, currentIndex, e.key);
109
+ e.preventDefault();
110
+ e.stopPropagation();
111
+
112
+ if (nextIndex >= 0) {
113
+ setFocusIndex(nextIndex);
114
+ moveElement(currentIndex, nextIndex);
115
+ e.target.scrollIntoView({
116
+ block: 'center'
117
+ });
118
+ }
119
+ }
120
+ }
121
+ }, /*#__PURE__*/React.createElement(Checkbox, {
122
+ wrapperClassName: "".concat(blockClass, "__customize-columns-checkbox"),
123
+ checked: isColumnVisible(colDef),
124
+ onChange: onSelectColumn.bind(null, colDef),
125
+ id: "".concat(blockClass, "__customization-column-").concat(colDef.id),
126
+ labelText: colDef.Header.props.title,
127
+ title: colDef.Header.props.title
128
+ }));
129
+ }))));
130
+ };
131
+
132
+ Columns.propTypes = {
133
+ columns: PropTypes.array.isRequired,
134
+ disabledInstructionsLabel: PropTypes.string,
135
+ filterString: PropTypes.string.isRequired,
136
+ instructionsLabel: PropTypes.string,
137
+ onSelectColumn: PropTypes.func.isRequired,
138
+ setColumnsObject: PropTypes.func.isRequired
139
+ };
140
+ export default Columns;
@@ -0,0 +1,157 @@
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. 2021
12
+ * US Government Users Restricted Rights - Use, duplication or disclosure
13
+ * restricted by GSA ADP Schedule Contract with IBM Corp.
14
+ */
15
+ // @flow
16
+ import React, { useState } from 'react';
17
+ import PropTypes from 'prop-types';
18
+ import { Modal } from 'carbon-components-react';
19
+ import { isColumnVisible } from './common';
20
+ import Columns from './Columns';
21
+ import Actions from './Actions';
22
+ import { pkg } from '../../../../../settings';
23
+ var blockClass = "".concat(pkg.prefix, "--datagrid");
24
+
25
+ var CustomizeColumnsModal = function CustomizeColumnsModal(_ref) {
26
+ var isOpen = _ref.isOpen,
27
+ setIsModalOpen = _ref.setIsModalOpen,
28
+ onSaveColumnPrefs = _ref.onSaveColumnPrefs,
29
+ columnDefinitions = _ref.columnDefinitions,
30
+ originalColumnDefinitions = _ref.originalColumnDefinitions,
31
+ _ref$customizeModalHe = _ref.customizeModalHeadingLabel,
32
+ customizeModalHeadingLabel = _ref$customizeModalHe === void 0 ? 'Customize display' : _ref$customizeModalHe,
33
+ _ref$primaryButtonTex = _ref.primaryButtonTextLabel,
34
+ primaryButtonTextLabel = _ref$primaryButtonTex === void 0 ? 'Save' : _ref$primaryButtonTex,
35
+ _ref$secondaryButtonT = _ref.secondaryButtonTextLabel,
36
+ secondaryButtonTextLabel = _ref$secondaryButtonT === void 0 ? 'Cancel' : _ref$secondaryButtonT,
37
+ _ref$instructionsLabe = _ref.instructionsLabel,
38
+ instructionsLabel = _ref$instructionsLabe === void 0 ? 'Deselect columns to hide them. Click and drag the white box to reorder the columns. These specifications will be saved and persist if you leave and return to the data table.' : _ref$instructionsLabe;
39
+
40
+ var _useState = useState(''),
41
+ _useState2 = _slicedToArray(_useState, 2),
42
+ searchText = _useState2[0],
43
+ setSearchText = _useState2[1];
44
+
45
+ var _useState3 = useState(columnDefinitions // hide the columns without Header, e.g the sticky actions, spacer
46
+ .filter(function (colDef) {
47
+ return !!colDef.Header.props;
48
+ }) // only sort the hidden column to the end when modal reopen
49
+ .sort(function (defA, defB) {
50
+ var isVisibleA = isColumnVisible(defA);
51
+ var isVisibleB = isColumnVisible(defB);
52
+
53
+ if (isVisibleA && !isVisibleB) {
54
+ return -1;
55
+ }
56
+
57
+ if (!isVisibleA && isVisibleB) {
58
+ return 1;
59
+ }
60
+
61
+ return 0;
62
+ })),
63
+ _useState4 = _slicedToArray(_useState3, 2),
64
+ columnObjects = _useState4[0],
65
+ _setColumnsObject = _useState4[1];
66
+
67
+ var _useState5 = useState(false),
68
+ _useState6 = _slicedToArray(_useState5, 2),
69
+ isDirty = _useState6[0],
70
+ setIsDirty = _useState6[1];
71
+
72
+ var onRequestClose = function onRequestClose() {
73
+ setIsModalOpen(false);
74
+ };
75
+
76
+ var onRequestSubmit = function onRequestSubmit() {
77
+ setIsModalOpen(false);
78
+ var updatedColumns = columnObjects.map(function (colDef) {
79
+ return {
80
+ id: colDef.id,
81
+ isVisible: colDef.isVisible
82
+ };
83
+ });
84
+ onSaveColumnPrefs(updatedColumns);
85
+ };
86
+
87
+ var onCheckboxCheck = function onCheckboxCheck(col, value) {
88
+ var changedDefinitions = columnObjects.map(function (definition) {
89
+ if (definition.id === col.id) {
90
+ return _objectSpread(_objectSpread({}, definition), {}, {
91
+ isVisible: value
92
+ });
93
+ }
94
+
95
+ return definition;
96
+ });
97
+
98
+ _setColumnsObject(changedDefinitions);
99
+
100
+ setDirty();
101
+ };
102
+
103
+ var setDirty = function setDirty() {
104
+ if (!isDirty) {
105
+ setIsDirty(true);
106
+ }
107
+ };
108
+
109
+ var string = searchText.trim().toLowerCase();
110
+ return /*#__PURE__*/React.createElement(Modal, {
111
+ className: "".concat(blockClass, "__customize-columns-modal"),
112
+ open: isOpen,
113
+ modalHeading: customizeModalHeadingLabel,
114
+ primaryButtonText: primaryButtonTextLabel,
115
+ secondaryButtonText: secondaryButtonTextLabel,
116
+ selectorPrimaryFocus: ".".concat(blockClass, "__customize-columns-column-list--focus"),
117
+ primaryButtonDisabled: !isDirty,
118
+ onRequestClose: onRequestClose,
119
+ onRequestSubmit: onRequestSubmit,
120
+ size: "sm",
121
+ hasForm: true
122
+ }, /*#__PURE__*/React.createElement("div", {
123
+ className: "".concat(blockClass, "__customize-columns-instructions")
124
+ }, instructionsLabel), /*#__PURE__*/React.createElement(Actions, {
125
+ columns: columnObjects,
126
+ originalColumnDefinitions: originalColumnDefinitions,
127
+ searchText: searchText,
128
+ setColumnsObject: function setColumnsObject(cols) {
129
+ _setColumnsObject(cols);
130
+
131
+ setDirty();
132
+ },
133
+ setSearchText: setSearchText
134
+ }), isOpen && /*#__PURE__*/React.createElement(Columns, {
135
+ columns: columnObjects,
136
+ filterString: string,
137
+ onSelectColumn: onCheckboxCheck,
138
+ setColumnsObject: function setColumnsObject(cols) {
139
+ _setColumnsObject(cols);
140
+
141
+ setDirty();
142
+ }
143
+ }));
144
+ };
145
+
146
+ CustomizeColumnsModal.propTypes = {
147
+ columnDefinitions: PropTypes.array.isRequired,
148
+ customizeModalHeadingLabel: PropTypes.string,
149
+ instructionsLabel: PropTypes.string,
150
+ isOpen: PropTypes.bool.isRequired,
151
+ onSaveColumnPrefs: PropTypes.func.isRequired,
152
+ originalColumnDefinitions: PropTypes.array.isRequired,
153
+ primaryButtonTextLabel: PropTypes.string,
154
+ secondaryButtonTextLabel: PropTypes.string,
155
+ setIsModalOpen: PropTypes.func.isRequired
156
+ };
157
+ export default CustomizeColumnsModal;
@@ -0,0 +1,62 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
+ var _excluded = ["onSaveColumnPrefs", "isModalOpen", "setIsModalOpen"];
4
+ // @flow
5
+
6
+ /*
7
+ * Licensed Materials - Property of IBM
8
+ * 5724-Q36
9
+ * (c) Copyright IBM Corp. 2021
10
+ * US Government Users Restricted Rights - Use, duplication or disclosure
11
+ * restricted by GSA ADP Schedule Contract with IBM Corp.
12
+ */
13
+ import * as React from 'react';
14
+ import PropTypes from 'prop-types';
15
+ import CustomizeColumnsModal from './CustomizeColumnsModal';
16
+
17
+ var ModalWrapper = function ModalWrapper(_ref) {
18
+ var instance = _ref.instance;
19
+
20
+ var _instance$customizeCo = instance.customizeColumnsProps,
21
+ _onSaveColumnPrefs = _instance$customizeCo.onSaveColumnPrefs,
22
+ isModalOpen = _instance$customizeCo.isModalOpen,
23
+ setIsModalOpen = _instance$customizeCo.setIsModalOpen,
24
+ rest = _objectWithoutProperties(_instance$customizeCo, _excluded);
25
+
26
+ if (isModalOpen) {
27
+ return /*#__PURE__*/React.createElement(CustomizeColumnsModal, _extends({}, rest, {
28
+ isOpen: isModalOpen,
29
+ setIsModalOpen: setIsModalOpen,
30
+ columnDefinitions: instance.allColumns,
31
+ originalColumnDefinitions: instance.columns,
32
+ onSaveColumnPrefs: function onSaveColumnPrefs(updatedColDefs) {
33
+ var hiddenIds = updatedColDefs.filter(function (colDef) {
34
+ return !colDef.isVisible;
35
+ }).map(function (colDef) {
36
+ return colDef.id;
37
+ });
38
+ instance.setHiddenColumns(hiddenIds);
39
+
40
+ if (typeof instance.setColumnOrder === 'function') {
41
+ instance.setColumnOrder(updatedColDefs.map(function (colDef) {
42
+ return colDef.id;
43
+ }));
44
+ } else {
45
+ // eslint-disable-next-line no-console
46
+ console.warn("Column order can not be updated. Did you forget to add 'useColumnOrder' in 'useDatagrid'");
47
+ }
48
+
49
+ if (typeof _onSaveColumnPrefs === 'function') {
50
+ _onSaveColumnPrefs(updatedColDefs);
51
+ }
52
+ }
53
+ }));
54
+ }
55
+
56
+ return null;
57
+ };
58
+
59
+ ModalWrapper.propTypes = {
60
+ instance: PropTypes.object.isRequired
61
+ };
62
+ export default ModalWrapper;
@@ -0,0 +1,13 @@
1
+ // @flow
2
+
3
+ /*
4
+ * Licensed Materials - Property of IBM
5
+ * 5724-Q36
6
+ * (c) Copyright IBM Corp. 2021
7
+ * US Government Users Restricted Rights - Use, duplication or disclosure
8
+ * restricted by GSA ADP Schedule Contract with IBM Corp.
9
+ */
10
+ import isBoolean from 'lodash/isBoolean';
11
+ export var isColumnVisible = function isColumnVisible(colDef) {
12
+ return isBoolean(colDef.isVisible) ? colDef.isVisible : true;
13
+ };
@@ -0,0 +1,9 @@
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
+ export { default as CustomizeColumnsModalWrapper } from './ModalWrapper';
9
+ export { default as ToggleButtonWrapper } from './ButtonWrapper';
@@ -0,0 +1,62 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
5
+ var _excluded = ["buttonLabel"];
6
+ // @flow
7
+
8
+ /*
9
+ * Licensed Materials - Property of IBM
10
+ * 5724-Q36
11
+ * (c) Copyright IBM Corp. 2021
12
+ * US Government Users Restricted Rights - Use, duplication or disclosure
13
+ * restricted by GSA ADP Schedule Contract with IBM Corp.
14
+ */
15
+ import * as React from 'react';
16
+ import PropTypes from 'prop-types';
17
+ import { Settings16 } from '@carbon/icons-react';
18
+ import { Button } from 'carbon-components-react';
19
+ import cx from 'classnames';
20
+ import RowSizeRadioGroup from './RowSizeRadioGroup';
21
+ import { pkg } from '../../../../../settings';
22
+ var blockClass = "".concat(pkg.prefix, "--datagrid");
23
+
24
+ var RowSizeDropdown = function RowSizeDropdown(_ref) {
25
+ var _ref$buttonLabel = _ref.buttonLabel,
26
+ buttonLabel = _ref$buttonLabel === void 0 ? 'Row height' : _ref$buttonLabel,
27
+ props = _objectWithoutProperties(_ref, _excluded);
28
+
29
+ var buttonRef = React.useRef({});
30
+
31
+ var _React$useState = React.useState(false),
32
+ _React$useState2 = _slicedToArray(_React$useState, 2),
33
+ isOpen = _React$useState2[0],
34
+ setIsOpen = _React$useState2[1];
35
+
36
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, {
37
+ hasIconOnly: true,
38
+ ref: buttonRef,
39
+ kind: "ghost",
40
+ tooltipPosition: "left",
41
+ renderIcon: Settings16,
42
+ onClick: function onClick() {
43
+ return setIsOpen(!isOpen);
44
+ },
45
+ iconDescription: buttonLabel,
46
+ className: cx(_defineProperty({}, "".concat(blockClass, "__row-size-button--open"), isOpen))
47
+ }), isOpen && /*#__PURE__*/React.createElement(RowSizeRadioGroup, _extends({}, props, {
48
+ buttonRef: buttonRef,
49
+ hideRadioGroup: function hideRadioGroup() {
50
+ setIsOpen(false);
51
+ }
52
+ })));
53
+ };
54
+
55
+ RowSizeDropdown.propTypes = {
56
+ buttonLabel: PropTypes.string,
57
+ datagridName: PropTypes.string.isRequired,
58
+ light: PropTypes.bool.isRequired,
59
+ onChange: PropTypes.func.isRequired,
60
+ selectedOption: PropTypes.string.isRequired
61
+ };
62
+ export default RowSizeDropdown;
@@ -0,0 +1,139 @@
1
+ /* eslint-disable react/default-props-match-prop-types */
2
+ // @flow
3
+
4
+ /*
5
+ * Licensed Materials - Property of IBM
6
+ * 5724-Q36
7
+ * (c) Copyright IBM Corp. 2021
8
+ * US Government Users Restricted Rights - Use, duplication or disclosure
9
+ * restricted by GSA ADP Schedule Contract with IBM Corp.
10
+ */
11
+ import React, { useEffect } from 'react';
12
+ import PropTypes from 'prop-types';
13
+ import { RadioButtonGroup, RadioButton } from 'carbon-components-react';
14
+ import isArray from 'lodash/isArray';
15
+ import { pkg } from '../../../../../settings';
16
+ var blockClass = "".concat(pkg.prefix, "--datagrid");
17
+
18
+ var RowSizeRadioGroup = function RowSizeRadioGroup(_ref) {
19
+ var rowSizes = _ref.rowSizes,
20
+ selectedOption = _ref.selectedOption,
21
+ datagridName = _ref.datagridName,
22
+ buttonRef = _ref.buttonRef,
23
+ onChange = _ref.onChange,
24
+ hideRadioGroup = _ref.hideRadioGroup,
25
+ _ref$legendText = _ref.legendText,
26
+ legendText = _ref$legendText === void 0 ? 'Row height' : _ref$legendText,
27
+ _ref$rowSizeLabels = _ref.rowSizeLabels,
28
+ rowSizeLabels = _ref$rowSizeLabels === void 0 ? {
29
+ xl: 'Extra large',
30
+ lg: 'Large (default)',
31
+ md: 'Medium',
32
+ sm: 'Small',
33
+ xs: 'Extra small'
34
+ } : _ref$rowSizeLabels;
35
+
36
+ var _getDropdownPosition = getDropdownPosition(buttonRef.current),
37
+ top = _getDropdownPosition.top,
38
+ right = _getDropdownPosition.right;
39
+
40
+ useEffect(function () {
41
+ window.addEventListener('click', hideRadioGroup);
42
+ return function () {
43
+ window.removeEventListener('click', hideRadioGroup);
44
+ };
45
+ }, [hideRadioGroup]);
46
+ return /*#__PURE__*/React.createElement("div", {
47
+ className: "".concat(blockClass, "__row-size-dropdown"),
48
+ style: {
49
+ top: top,
50
+ right: right
51
+ },
52
+ role: "presentation",
53
+ onClick: function onClick(e) {
54
+ e.stopPropagation();
55
+ }
56
+ }, /*#__PURE__*/React.createElement(RadioButtonGroup, {
57
+ legendText: legendText,
58
+ name: "row-height-group",
59
+ orientation: "vertical",
60
+ defaultSelected: getBackwardCompatibleRowSize(selectedOption),
61
+ onChange: onChange
62
+ }, rowSizes && isArray(rowSizes) && rowSizes.map(function (option) {
63
+ var labelText;
64
+
65
+ try {
66
+ labelText = option.labelText || rowSizeLabels[option.value];
67
+ } catch (e) {
68
+ labelText = option.value;
69
+ }
70
+
71
+ return /*#__PURE__*/React.createElement(RadioButton, {
72
+ key: option.value,
73
+ labelText: labelText,
74
+ value: option.value,
75
+ id: "".concat(datagridName || 'datagrid', "--row-density--").concat(option.value)
76
+ });
77
+ })));
78
+ };
79
+
80
+ var getBackwardCompatibleRowSize = function getBackwardCompatibleRowSize(rowSize) {
81
+ // TODO: deprecate this function in next major release (v8) on carbon-components-react
82
+ var rowSizeMap = {
83
+ tall: 'xl',
84
+ normal: 'lg',
85
+ short: 'sm',
86
+ compact: 'xs' // md is a new value
87
+
88
+ };
89
+ return rowSizeMap[rowSize] || rowSize;
90
+ };
91
+
92
+ var getDropdownPosition = function getDropdownPosition(buttonEle) {
93
+ var parent = buttonEle.parentElement;
94
+
95
+ if (parent instanceof HTMLElement) {
96
+ var top = buttonEle.offsetTop + buttonEle.offsetHeight;
97
+ var right = parent.offsetWidth - parent.offsetLeft - (buttonEle.offsetLeft + buttonEle.offsetWidth);
98
+ return {
99
+ top: top,
100
+ right: right
101
+ };
102
+ }
103
+
104
+ return {
105
+ top: 0,
106
+ right: 0
107
+ };
108
+ };
109
+
110
+ RowSizeRadioGroup.defaultProps = {
111
+ rowSizes: [{
112
+ value: 'xl' // 64
113
+
114
+ }, {
115
+ value: 'lg' // 48
116
+
117
+ }, {
118
+ value: 'md' // 40
119
+
120
+ }, {
121
+ value: 'sm' // 32
122
+
123
+ }, {
124
+ value: 'xs' // 24
125
+
126
+ }],
127
+ selectedOption: 'lg'
128
+ };
129
+ RowSizeRadioGroup.propTypes = {
130
+ buttonRef: PropTypes.any.isRequired,
131
+ datagridName: PropTypes.string.isRequired,
132
+ hideRadioGroup: PropTypes.func.isRequired,
133
+ legendText: PropTypes.string,
134
+ onChange: PropTypes.func.isRequired,
135
+ rowSizeLabels: PropTypes.object,
136
+ rowSizes: PropTypes.array.isRequired,
137
+ selectedOption: PropTypes.string.isRequired
138
+ };
139
+ export default RowSizeRadioGroup;
@@ -0,0 +1,8 @@
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
+ export { default as RowSizeDropdown } from './RowSizeDropdown';
@@ -0,0 +1,8 @@
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
+ export { default } from './Datagrid';
@@ -0,0 +1,6 @@
1
+ var notes = "\n # Customizing columns\n Customizing columns allows user to reorder and hide certain columns of the datagrid. Consuming component can use the provided callback to save/update according to their persistent strategy.\n\n ## Documentation:\n\n - (required) Add following plugins to `useDatagrid` hook\n - `useCustomizeColumns`\n - `useColumnOrder`\n - (required) Implement `options.DatagridActions` component\n - this component will have props: `datagridState`\n - render `datagridState.CustomizeColumnsButton` component wherever makes sense.\n - `CustomizeColumnsButton` props can be overridden. Available props: [carbon-components-react doc](https://react.carbondesignsystem.com/?path=/docs/components-button--default)\n - (optional) Preserve and apply the user preference\n - `options.initialState.hiddenColumns: Array<ColumnId: String>`\n - Array of column ids that will be hidden after initial render\n - [react-table doc](https://react-table.tanstack.com/docs/api/useTable#table-options)\n - `options.initialState.columnOrder: Array<ColumnId: String>`\n - Order of the columns. Any column ids not in this array will be ordered by their position in the `options.columns`\n - [react-table doc](https://react-table.tanstack.com/docs/api/useColumnOrder#table-options)\n - `options.customizeColumnsProps.onSaveColumnPrefs`\n - type: `Function(Columns: Array<{ColumnId: String, isVisible: Boolean}>) => void`\n - It's a callback function when 'Save' button clicked on the modal. It allows consumer to preserve the updated column preference. This output can also be used to compute the `hiddenColumns` and `columnOrder`\n - (optional) Reset to default\n - There is a reset to default button on the modal. It will use the `options.columns` as the default. If there are columns should be hidden by default, denote them with property: `isVisible: false` (undefined will be treated as `true`)\n\n code snippet:\n\n ```js\n const columns = React.useMemo(() => defaultHeader, []);\n const [data] = useState(makeData(10));\n const DatagridActions = (datagridState) => (\n <TableToolbarContent>\n <TableToolbarSearch ... />\n <Button ... />\n <datagridState.CustomizeColumnsButton />\n </TableToolbarContent>\n )\n const datagridState = useDatagrid(\n {\n columns,\n data,\n initialState: {\n hiddenColumns: ['age'],\n columnOrder: [],\n },\n customizeColumnsProps: {\n onSaveColumnPrefs: (newColDefs) => {\n console.log(newColDefs);\n },\n },\n DatagridActions,\n },\n useCustomizeColumns,\n useColumnOrder,\n );\n\n return (\n <Wrapper>\n <IntlProvider locale=\"en\">\n <Datagrid {...datagridState} />\n <div>\n Hidden column ids: \n <pre>{JSON.stringify(datagridState.state.hiddenColumns, null, 2)}</pre>\n </div>\n </IntlProvider>\n </Wrapper>\n );\n ```\n";
2
+ export var story = {
3
+ parameters: {
4
+ notes: notes
5
+ }
6
+ };
@@ -0,0 +1,6 @@
1
+ var notes = "\n# Access left side panel in data grid\nAllow users to access left panel in datagrid.\n\n## Documentation:\n\n- (required) Implement `options.leftPanel` which has the following props\n - `options.leftPanel.isOpen` value is toggled by the Button onClick from DatagridActions\n - render `options.leftPanel.panelContent` inside the panel container of data grid when isOpen is true\n\ncode snippet:\n\n```js\nconst columns = React.useMemo(() => defaultHeader, []);\n const [data] = useState(makeData(10));\n const [isPanelOpen, setIsPanelOpen] = useState(false);\n const DatagridActions = (datagridState) => (\n <TableToolbarContent>\n <Button onClick={() => { setIsPanelOpen(!isPanelOpen); }}>Click to toggle left panel</Button>\n <TableToolbarSearch ... />\n <Button ... />\n <datagridState.CustomizeColumnsButton />\n </TableToolbarContent>\n )\n const datagridState = useDatagrid(\n {\n columns,\n data,\n leftPanel: {\n isOpen: isPanelOpen,\n panelContent: <div>Panel content will go here along with any button interactions</div>,\n },\n initialState: {\n hiddenColumns: ['age'],\n columnOrder: [],\n },\n customizeColumnsProps: {\n onSaveColumnPrefs: (newColDefs) => {\n console.log(newColDefs);\n },\n },\n DatagridActions,\n },\n );\n\nreturn (\n <Wrapper>\n <IntlProvider locale=\"en\">\n <Datagrid {...datagridState} />\n </IntlProvider>\n </Wrapper>\n);\n```\n";
2
+ export var story = {
3
+ parameters: {
4
+ notes: notes
5
+ }
6
+ };
@@ -0,0 +1,6 @@
1
+ var notes = "\n# Changing row size (height/density)\nAllow users to adjust the data density on datagrid.\n\n## Documentation:\n\n- (optional) Define initial row size by `datagridOptions.rowSize`.\n - Default value is `md`.\n - Supported values are `xl`, `lg`, `md`, `sm`, `xs` same as size prop on carbon component react `DataTable`.\n- (optional) Provide list of allowed sizes use `datagridOptions.rowSizes`\n - Default list is\n ```\n [{ value: 'lg'}, { value: 'md'}, {value: 'sm'}, {value: 'xs'}]\n ```\n - Provide `labelText` in each option if not satisfied with the default labels.\n- (optional) Use `RowSizeDropdown` component to change row size:\n - (required) Implement `datagridOptions.DatagridActions` component\n - The component will have props: `datagridState`\n - Render `datagridState.RowSizeDropdown` component in `datagridOptions.DatagridActions`.\n - Pass `datagridState.rowSizeDropdownProps` as props\n - No extra logic is needed.\n - (optional) Preserve row size, use `datagridOptions.onRowSizeChange`\n - type: `Function(rowSize: String) => void`\n - It's a callback function when different row size option is selected on the dropdown.\n- (optional) Use other component to change row size:\n - Wire the variable controlled by the component with `datagridOptions.rowSize = variable`\n- (optional) Render different content in the cell on different `rowSize`\n - `Cell` renderer of each column will receive `datagridState` which will contain `rowSize`. Render different content based on this value.\n\ncode snippet:\n\n```js\nconst columns = React.useMemo(() => [ ...defaultHeader.slice(0, 3),\n {\n Header: 'Different cell content',\n id: 'rowSizeDemo-cell',\n disableSortBy: true,\n Cell: ({ rowSize }) => rowSize,\n }\n], []);\nconst [data] = useState(makeData(10));\nconst DatagridActions = (datagridState) => (\n <TableToolbarContent>\n <TableToolbarSearch ... />\n <Button ... />\n <datagridState.RowSizeDropdown {...datagridState.rowSizeDropdownProps} />\n </TableToolbarContent>\n)\nconst datagridState = useDatagrid(\n {\n columns,\n data,\n rowSize: 'xs',\n rowSizes: [\n {\n value: 'lg',\n labelText: 'Super tall row',\n },\n {\n value: 'md',\n },\n {\n value: 'xs',\n labelText: 'Teeny tiny row',\n },\n ],\n onRowSizeChange: (rowSize) => {\n console.log(rowSize);\n },\n DatagridActions,\n },\n);\n\nreturn (\n <Wrapper>\n <IntlProvider locale=\"en\">\n <Datagrid {...datagridState} />\n </IntlProvider>\n </Wrapper>\n);\n```\n";
2
+ export var story = {
3
+ parameters: {
4
+ notes: notes
5
+ }
6
+ };
@@ -0,0 +1,6 @@
1
+ var notes = "\n# Select all toggle\nUse this feature will allow user to toggle the select all checkbox behavior between selecting all rows **on current page** vs **across all pages**\n<br/>\nIt's using [react-table API](https://react-table.tanstack.com/docs/api/useRowSelect#instance-properties) to select all rows.\n\n## Terminology\n- Pagination\n - **UI side pagination**: all rows are loaded to browser, but only display subset of them.\n - **Server side pagination**: subset of rows are loaded to browser, going to another page requires another network call\n- Selection mode\n - **all rows**: selects all rows across pages.\n - **all page rows**: selects all rows on the current page.\n\n## Compatibility with other plugin hooks and options\n- It has to be used with `useSelectRows` hook.\n- Select all toggle will not be enabled if `options.DatagridPagination` is not defined (select all is the same without pagination)\n- Compatible with `options.DatagridBatchActions`\n- Obviously it will not work when select-all is hidden by `options.hideSelectAll`.\n- Not compatible with `useInfiniteScroll`. Pull request welcome!\n\n## Sample usage:\n- (required) `useSelectRows` - enable row selections with select all on header\n- (required) `useSelectAllToggle` - enable select all toggle.\n- (optional) config the label on toggle menu:\n - (optional) `options.selectAllToggle.labels.allRows` for label that selects all rows across all pages\n - (optional) `options.selectAllToggle.labels.allPageRows` for label that selects all rows on current page\n- (optional) `options.selectAllToggle.onSelectAllRows`\n - type: `Function(areAllRowsSelected: Boolean) => void`\n - callback when `instance.isAllRowsSelected` value changes. Check out doc: [instance property](https://react-table.tanstack.com/docs/api/useRowSelect#instance-properties)\n - `true`: when selection mode is **all rows** and user selects all via toggle dropdown 'Select all' or toggle 'on' on the select all checkbox.\n - useful when grid is server side paginated (only a subset of rows are loaded in UI)\n\n```js\nconst columns = React.useMemo(() => defaultHeader, []);\n const [data] = useState(makeData(100));\n const datagridState = useDatagrid(\n {\n columns,\n data,\n initialState: {\n pageSize: 10,\n pageSizes: [5,10,25,50]\n },\n selectAllToggle: {\n labels: {\n allRows: \"Select all randomly generated rows\",\n },\n onSelectAllRows: (areAllSelected) => console.log('are all selected: ', areAllSelected),\n },\n DatagridPagination,\n DatagridActions,\n DatagridBatchActions,\n },\n useSelectRows,\n useSelectAllToggle,\n );\n\n return (\n <Wrapper>\n <Datagrid {...datagridState} />\n </Wrapper>\n);\n```\n\n";
2
+ export var story = {
3
+ parameters: {
4
+ notes: notes
5
+ }
6
+ };