@carbon/ibm-products 2.0.0-rc.17 → 2.0.0-rc.19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. package/css/index-full-carbon.css +140 -21
  2. package/css/index-full-carbon.css.map +1 -1
  3. package/css/index-full-carbon.min.css +3 -3
  4. package/css/index-full-carbon.min.css.map +1 -1
  5. package/css/index-without-carbon-released-only.css +413 -0
  6. package/css/index-without-carbon-released-only.css.map +1 -1
  7. package/css/index-without-carbon-released-only.min.css +1 -1
  8. package/css/index-without-carbon-released-only.min.css.map +1 -1
  9. package/css/index-without-carbon.css +140 -21
  10. package/css/index-without-carbon.css.map +1 -1
  11. package/css/index-without-carbon.min.css +3 -3
  12. package/css/index-without-carbon.min.css.map +1 -1
  13. package/css/index.css +139 -21
  14. package/css/index.css.map +1 -1
  15. package/css/index.min.css +2 -2
  16. package/css/index.min.css.map +1 -1
  17. package/es/components/Datagrid/Datagrid/Datagrid.js +4 -4
  18. package/es/components/Datagrid/Datagrid/DatagridContent.js +46 -16
  19. package/es/components/Datagrid/Datagrid/DatagridToolbar.js +3 -21
  20. package/es/components/Datagrid/Datagrid/DraggableElement.js +7 -3
  21. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +7 -2
  22. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsTearsheet.js +1 -1
  23. package/es/components/Datagrid/Datagrid/addons/Filtering/FilterFlyout.js +120 -60
  24. package/es/components/Datagrid/Datagrid/addons/Filtering/FilterPanel.js +514 -0
  25. package/es/components/Datagrid/Datagrid/addons/Filtering/FilterProvider.js +10 -2
  26. package/es/components/Datagrid/Datagrid/addons/Filtering/constants.js +9 -1
  27. package/es/components/Datagrid/Datagrid/addons/Filtering/hooks/index.js +9 -0
  28. package/es/components/Datagrid/Datagrid/addons/Filtering/hooks/useInitialStateFromFilters.js +4 -1
  29. package/es/components/Datagrid/Datagrid/addons/Filtering/hooks/useShouldDisableButtons.js +38 -0
  30. package/es/components/Datagrid/Datagrid/addons/Filtering/hooks/useSubscribeToEventEmitter.js +25 -0
  31. package/es/components/Datagrid/Datagrid/addons/Filtering/index.js +3 -1
  32. package/es/components/Datagrid/Datagrid/addons/Filtering/motion/variants.js +55 -0
  33. package/es/components/Datagrid/Datagrid/addons/Filtering/utils.js +53 -19
  34. package/es/components/Datagrid/Datagrid.stories/index.js +0 -1
  35. package/es/components/Datagrid/useFiltering.js +11 -4
  36. package/es/components/Datagrid/utils/DatagridActions.js +41 -13
  37. package/es/components/OptionsTile/OptionsTile.js +3 -3
  38. package/es/components/Tearsheet/Tearsheet.js +5 -0
  39. package/es/components/Tearsheet/TearsheetNarrow.js +5 -0
  40. package/es/components/Tearsheet/TearsheetShell.js +1 -1
  41. package/es/global/js/package-settings.js +2 -2
  42. package/lib/components/Datagrid/Datagrid/Datagrid.js +4 -4
  43. package/lib/components/Datagrid/Datagrid/DatagridContent.js +48 -15
  44. package/lib/components/Datagrid/Datagrid/DatagridToolbar.js +2 -23
  45. package/lib/components/Datagrid/Datagrid/DraggableElement.js +6 -2
  46. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +7 -2
  47. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsTearsheet.js +1 -1
  48. package/lib/components/Datagrid/Datagrid/addons/Filtering/FilterFlyout.js +113 -51
  49. package/lib/components/Datagrid/Datagrid/addons/Filtering/FilterPanel.js +538 -0
  50. package/lib/components/Datagrid/Datagrid/addons/Filtering/FilterProvider.js +9 -1
  51. package/lib/components/Datagrid/Datagrid/addons/Filtering/constants.js +15 -3
  52. package/lib/components/Datagrid/Datagrid/addons/Filtering/hooks/index.js +31 -0
  53. package/lib/components/Datagrid/Datagrid/addons/Filtering/hooks/useInitialStateFromFilters.js +5 -1
  54. package/lib/components/Datagrid/Datagrid/addons/Filtering/hooks/useShouldDisableButtons.js +50 -0
  55. package/lib/components/Datagrid/Datagrid/addons/Filtering/hooks/useSubscribeToEventEmitter.js +35 -0
  56. package/lib/components/Datagrid/Datagrid/addons/Filtering/index.js +23 -1
  57. package/lib/components/Datagrid/Datagrid/addons/Filtering/motion/variants.js +67 -0
  58. package/lib/components/Datagrid/Datagrid/addons/Filtering/utils.js +53 -18
  59. package/lib/components/Datagrid/Datagrid.stories/index.js +0 -8
  60. package/lib/components/Datagrid/useFiltering.js +11 -3
  61. package/lib/components/Datagrid/utils/DatagridActions.js +41 -11
  62. package/lib/components/OptionsTile/OptionsTile.js +2 -2
  63. package/lib/components/Tearsheet/Tearsheet.js +5 -0
  64. package/lib/components/Tearsheet/TearsheetNarrow.js +5 -0
  65. package/lib/components/Tearsheet/TearsheetShell.js +1 -1
  66. package/lib/global/js/package-settings.js +2 -2
  67. package/package.json +2 -2
  68. package/scss/components/Datagrid/styles/_datagrid.scss +16 -17
  69. package/scss/components/Datagrid/styles/_draggableElement.scss +5 -1
  70. package/scss/components/Datagrid/styles/_index.scss +1 -0
  71. package/scss/components/Datagrid/styles/addons/_FilterPanel.scss +129 -0
  72. package/scss/components/Datagrid/styles/addons/_RowSizeDropdown.scss +3 -3
  73. package/scss/components/FilterSummary/_filter-summary.scss +1 -0
  74. package/scss/components/MultiAddSelect/_multi-add-select.scss +1 -1
  75. package/scss/components/SingleAddSelect/_single-add-select.scss +1 -1
  76. package/scss/components/_index-released-only-with-carbon.scss +2 -0
  77. package/scss/components/_index-released-only.scss +2 -0
  78. package/es/components/Datagrid/Datagrid.stories/LeftPanelStory.js +0 -6
  79. package/lib/components/Datagrid/Datagrid.stories/LeftPanelStory.js +0 -13
@@ -0,0 +1,514 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
4
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
5
+
6
+ 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; }
7
+
8
+ 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; }
9
+
10
+ /**
11
+ * Copyright IBM Corp. 2022, 2023
12
+ *
13
+ * This source code is licensed under the Apache-2.0 license found in the
14
+ * LICENSE file in the root directory of this source tree.
15
+ */
16
+
17
+ /* eslint-disable react/jsx-key */
18
+ import React, { useRef, useMemo, useContext, useState, useEffect } from 'react';
19
+ import PropTypes from 'prop-types';
20
+ import { Accordion, AccordionItem, Button, Search, Checkbox, DatePicker, DatePickerInput, Dropdown, FormGroup, NumberInput, RadioButton, RadioButtonGroup, Layer } from '@carbon/react';
21
+ import { rem } from '@carbon/layout';
22
+ import { pkg } from '../../../../../settings';
23
+ import { BATCH, CHECKBOX, CLEAR_FILTERS, DATE, DROPDOWN, INSTANT, NUMBER, PANEL, RADIO } from './constants';
24
+ import cx from 'classnames';
25
+ import { motion } from 'framer-motion';
26
+ import { panelVariants, innerContainerVariants, actionSetVariants } from './motion/variants';
27
+ import { Close } from '@carbon/react/icons';
28
+ import { ActionSet } from '../../../../ActionSet';
29
+ import { FilterContext } from '.';
30
+ import { useInitialStateFromFilters, useSubscribeToEventEmitter, useShouldDisableButtons } from './hooks';
31
+ import { getInitialStateFromFilters } from './utils';
32
+ var blockClass = "".concat(pkg.prefix, "--datagrid");
33
+ var componentClass = "".concat(blockClass, "-filter-panel");
34
+ var MotionActionSet = motion(ActionSet);
35
+
36
+ var FilterPanel = function FilterPanel(_ref) {
37
+ var _cx;
38
+
39
+ var _ref$title = _ref.title,
40
+ title = _ref$title === void 0 ? 'Filter' : _ref$title,
41
+ _ref$closeIconDescrip = _ref.closeIconDescription,
42
+ closeIconDescription = _ref$closeIconDescrip === void 0 ? 'Close filter panel' : _ref$closeIconDescrip,
43
+ _ref$updateMethod = _ref.updateMethod,
44
+ updateMethod = _ref$updateMethod === void 0 ? BATCH : _ref$updateMethod,
45
+ filterSections = _ref.filterSections,
46
+ setAllFilters = _ref.setAllFilters,
47
+ _ref$onApply = _ref.onApply,
48
+ onApply = _ref$onApply === void 0 ? function () {} : _ref$onApply,
49
+ _ref$onCancel = _ref.onCancel,
50
+ onCancel = _ref$onCancel === void 0 ? function () {} : _ref$onCancel,
51
+ _ref$onPanelOpen = _ref.onPanelOpen,
52
+ onPanelOpen = _ref$onPanelOpen === void 0 ? function () {} : _ref$onPanelOpen,
53
+ _ref$onPanelClose = _ref.onPanelClose,
54
+ onPanelClose = _ref$onPanelClose === void 0 ? function () {} : _ref$onPanelClose,
55
+ _ref$showFilterSearch = _ref.showFilterSearch,
56
+ showFilterSearch = _ref$showFilterSearch === void 0 ? false : _ref$showFilterSearch,
57
+ _ref$filterPanelMinHe = _ref.filterPanelMinHeight,
58
+ filterPanelMinHeight = _ref$filterPanelMinHe === void 0 ? 600 : _ref$filterPanelMinHe,
59
+ _ref$primaryActionLab = _ref.primaryActionLabel,
60
+ primaryActionLabel = _ref$primaryActionLab === void 0 ? 'Apply' : _ref$primaryActionLab,
61
+ _ref$secondaryActionL = _ref.secondaryActionLabel,
62
+ secondaryActionLabel = _ref$secondaryActionL === void 0 ? 'Cancel' : _ref$secondaryActionL,
63
+ _ref$searchLabelText = _ref.searchLabelText,
64
+ searchLabelText = _ref$searchLabelText === void 0 ? 'Filter search' : _ref$searchLabelText,
65
+ _ref$searchPlaceholde = _ref.searchPlaceholder,
66
+ searchPlaceholder = _ref$searchPlaceholde === void 0 ? 'Find filters' : _ref$searchPlaceholde;
67
+
68
+ /** State */
69
+ var _useInitialStateFromF = useInitialStateFromFilters(filterSections, PANEL),
70
+ _useInitialStateFromF2 = _slicedToArray(_useInitialStateFromF, 2),
71
+ filtersState = _useInitialStateFromF2[0],
72
+ setFiltersState = _useInitialStateFromF2[1];
73
+
74
+ var _useState = useState([]),
75
+ _useState2 = _slicedToArray(_useState, 2),
76
+ filtersObjectArray = _useState2[0],
77
+ setFiltersObjectArray = _useState2[1];
78
+
79
+ var _useState3 = useState(false),
80
+ _useState4 = _slicedToArray(_useState3, 2),
81
+ showDividerLine = _useState4[0],
82
+ setShowDividerLine = _useState4[1];
83
+ /** Refs */
84
+
85
+
86
+ var filterPanelRef = useRef();
87
+ var filterHeadingRef = useRef();
88
+ var filterSearchRef = useRef();
89
+ var actionSetRef = useRef(); // When using batch actions we have to store the filters to then apply them later
90
+
91
+ var prevFiltersRef = useRef(JSON.stringify(filtersState));
92
+ var prevFiltersObjectArrayRef = useRef(JSON.stringify(filtersObjectArray));
93
+ /** State from hooks */
94
+
95
+ var _useShouldDisableButt = useShouldDisableButtons({
96
+ initialValue: true,
97
+ filtersState: filtersState,
98
+ prevFiltersRef: prevFiltersRef
99
+ }),
100
+ _useShouldDisableButt2 = _slicedToArray(_useShouldDisableButt, 2),
101
+ shouldDisableButtons = _useShouldDisableButt2[0],
102
+ setShouldDisableButtons = _useShouldDisableButt2[1];
103
+ /** Memos */
104
+
105
+
106
+ var showActionSet = useMemo(function () {
107
+ return updateMethod === BATCH;
108
+ }, [updateMethod]);
109
+ /** Context */
110
+
111
+ var _useContext = useContext(FilterContext),
112
+ leftPanelOpen = _useContext.leftPanelOpen,
113
+ setLeftPanelOpen = _useContext.setLeftPanelOpen;
114
+ /** Methods */
115
+
116
+
117
+ var closePanel = function closePanel() {
118
+ return setLeftPanelOpen(false);
119
+ }; // If the user decides to cancel or click outside the flyout, it reverts back to the filters that were
120
+ // there when they opened the flyout
121
+
122
+
123
+ var revertToPreviousFilters = function revertToPreviousFilters() {
124
+ setFiltersState(JSON.parse(prevFiltersRef.current));
125
+ setFiltersObjectArray(JSON.parse(prevFiltersObjectArrayRef.current));
126
+ };
127
+
128
+ var cancel = function cancel() {
129
+ // Reverting to previous filters only applies when using batch actions
130
+ if (updateMethod === BATCH) {
131
+ revertToPreviousFilters();
132
+ onCancel();
133
+ }
134
+ };
135
+
136
+ var reset = function reset() {
137
+ // Get the initial values for the filters
138
+ var initialFiltersState = getInitialStateFromFilters(filterSections, PANEL);
139
+ var initialFiltersObjectArray = []; // Set the state to the initial values
140
+
141
+ setFiltersState(initialFiltersState);
142
+ setFiltersObjectArray(initialFiltersObjectArray);
143
+ setAllFilters([]); // Update their respective refs so everything is in sync
144
+
145
+ prevFiltersRef.current = JSON.stringify(initialFiltersState);
146
+ prevFiltersObjectArrayRef.current = JSON.stringify(initialFiltersObjectArray);
147
+ };
148
+
149
+ var apply = function apply() {
150
+ setAllFilters(filtersObjectArray); // From the user
151
+
152
+ onApply(); // When the user clicks apply, the action set buttons should be disabled again
153
+
154
+ setShouldDisableButtons(true); // updates the ref so next time the flyout opens we have records of the previous filters
155
+
156
+ prevFiltersRef.current = JSON.stringify(filtersState);
157
+ prevFiltersObjectArrayRef.current = JSON.stringify(filtersObjectArray);
158
+ };
159
+
160
+ var applyFilters = function applyFilters(_ref2) {
161
+ var column = _ref2.column,
162
+ value = _ref2.value,
163
+ type = _ref2.type;
164
+
165
+ // If no end date is selected return because we need the end date to do computations
166
+ if (type === DATE && value.length > 0 && !value[1]) {
167
+ return;
168
+ }
169
+
170
+ var filtersObjectArrayCopy = _toConsumableArray(filtersObjectArray); // // check if the filter already exists in the array
171
+
172
+
173
+ var filter = filtersObjectArrayCopy.find(function (item) {
174
+ return item.id === column;
175
+ }); // // if filter exists in array then update the filter's new value
176
+
177
+ if (filter) {
178
+ filter.value = value;
179
+ } else {
180
+ filtersObjectArrayCopy.push({
181
+ id: column,
182
+ value: value,
183
+ type: type
184
+ });
185
+ } // ATTENTION: this is where you would reset or remove individual filters from the filters array
186
+
187
+
188
+ if (type === CHECKBOX) {
189
+ /**
190
+ When all checkboxes of a group are all unselected the value still exists in the filtersObjectArray
191
+ This checks if all the checkboxes are selected = false and removes it from the array
192
+ */
193
+ var index = filtersObjectArrayCopy.findIndex(function (filter) {
194
+ return filter.id === column;
195
+ }); // If all the selected state is false remove from array
196
+
197
+ var shouldRemoveFromArray = filtersObjectArrayCopy[index].value.every(function (val) {
198
+ return val.selected === false;
199
+ });
200
+
201
+ if (shouldRemoveFromArray) {
202
+ filtersObjectArrayCopy.splice(index, 1);
203
+ }
204
+ } else if (type === DATE) {
205
+ if (value.length === 0) {
206
+ /**
207
+ Checks to see if the date value is an empty array, if it is that means the user wants
208
+ to reset the date filter
209
+ */
210
+ var _index = filtersObjectArrayCopy.findIndex(function (filter) {
211
+ return filter.id === column;
212
+ }); // Remove it from the filters array since there is nothing to filter
213
+
214
+
215
+ filtersObjectArrayCopy.splice(_index, 1);
216
+ }
217
+ } else if (type === DROPDOWN || type === RADIO) {
218
+ if (value === 'Any') {
219
+ /**
220
+ Checks to see if the selected value is 'Any', that means the user wants
221
+ to reset specific filter
222
+ */
223
+ var _index2 = filtersObjectArrayCopy.findIndex(function (filter) {
224
+ return filter.id === column;
225
+ }); // Remove it from the filters array
226
+
227
+
228
+ filtersObjectArrayCopy.splice(_index2, 1);
229
+ }
230
+ }
231
+
232
+ setFiltersObjectArray(filtersObjectArrayCopy); // // Automatically apply the filters if the updateMethod is instant
233
+
234
+ if (updateMethod === INSTANT) {
235
+ setAllFilters(filtersObjectArrayCopy);
236
+ }
237
+ };
238
+ /** Render the individual filter component */
239
+
240
+
241
+ var renderFilter = function renderFilter(_ref3) {
242
+ var _filtersState$column, _filtersState$column2, _filtersState$column3, _filtersState$column4;
243
+
244
+ var type = _ref3.type,
245
+ column = _ref3.column,
246
+ components = _ref3.props;
247
+
248
+ switch (type) {
249
+ case DATE:
250
+ return /*#__PURE__*/React.createElement(Layer, null, /*#__PURE__*/React.createElement(DatePicker, _extends({}, components.DatePicker, {
251
+ onChange: function onChange(value) {
252
+ var _components$DatePicke, _components$DatePicke2;
253
+
254
+ setFiltersState(_objectSpread(_objectSpread({}, filtersState), {}, _defineProperty({}, column, {
255
+ value: value,
256
+ type: type
257
+ })));
258
+ applyFilters({
259
+ column: column,
260
+ value: value,
261
+ type: type
262
+ });
263
+ (_components$DatePicke = (_components$DatePicke2 = components.DatePicker).onChange) === null || _components$DatePicke === void 0 ? void 0 : _components$DatePicke.call(_components$DatePicke2, value);
264
+ },
265
+ value: filtersState[column].value,
266
+ datePickerType: "range"
267
+ }), /*#__PURE__*/React.createElement(DatePickerInput, _extends({
268
+ placeholder: "mm/dd/yyyy",
269
+ labelText: "Start date"
270
+ }, components.DatePickerInput.start)), /*#__PURE__*/React.createElement(DatePickerInput, _extends({
271
+ placeholder: "mm/dd/yyyy",
272
+ labelText: "End date"
273
+ }, components.DatePickerInput.end))));
274
+
275
+ case NUMBER:
276
+ return /*#__PURE__*/React.createElement(Layer, null, /*#__PURE__*/React.createElement(NumberInput, _extends({
277
+ step: 1,
278
+ allowEmpty: true,
279
+ hideSteppers: true
280
+ }, components.NumberInput, {
281
+ onChange: function onChange(event) {
282
+ var _components$NumberInp, _components$NumberInp2;
283
+
284
+ setFiltersState(_objectSpread(_objectSpread({}, filtersState), {}, _defineProperty({}, column, {
285
+ value: event.target.value,
286
+ type: type
287
+ })));
288
+ applyFilters({
289
+ column: column,
290
+ value: event.target.value,
291
+ type: type
292
+ });
293
+ (_components$NumberInp = (_components$NumberInp2 = components.NumberInput).onChange) === null || _components$NumberInp === void 0 ? void 0 : _components$NumberInp.call(_components$NumberInp2, event);
294
+ },
295
+ value: filtersState[column].value
296
+ })));
297
+
298
+ case CHECKBOX:
299
+ return /*#__PURE__*/React.createElement(FormGroup, components.FormGroup, filtersState[column].value.map(function (option) {
300
+ return /*#__PURE__*/React.createElement(Checkbox, _extends({
301
+ key: option.labelText
302
+ }, option, {
303
+ onChange: function onChange(_, _ref4) {
304
+ var _option$onChange;
305
+
306
+ var isSelected = _ref4.checked;
307
+ var checkboxCopy = filtersState[column].value;
308
+ var foundCheckbox = checkboxCopy.find(function (checkbox) {
309
+ return checkbox.value === option.value;
310
+ });
311
+ foundCheckbox.selected = isSelected;
312
+ setFiltersState(_objectSpread(_objectSpread({}, filtersState), {}, _defineProperty({}, column, {
313
+ value: checkboxCopy,
314
+ type: type
315
+ })));
316
+ applyFilters({
317
+ column: column,
318
+ value: _toConsumableArray(filtersState[column].value),
319
+ type: type
320
+ });
321
+ (_option$onChange = option.onChange) === null || _option$onChange === void 0 ? void 0 : _option$onChange.call(option, isSelected);
322
+ },
323
+ checked: option.selected
324
+ }));
325
+ }));
326
+
327
+ case RADIO:
328
+ return /*#__PURE__*/React.createElement(FormGroup, components.FormGroup, /*#__PURE__*/React.createElement(RadioButtonGroup, _extends({}, components.RadioButtonGroup, {
329
+ valueSelected: ((_filtersState$column = filtersState[column]) === null || _filtersState$column === void 0 ? void 0 : _filtersState$column.value) === '' ? 'Any' : (_filtersState$column2 = filtersState[column]) === null || _filtersState$column2 === void 0 ? void 0 : _filtersState$column2.value,
330
+ onChange: function onChange(selected) {
331
+ var _components$RadioButt, _components$RadioButt2;
332
+
333
+ setFiltersState(_objectSpread(_objectSpread({}, filtersState), {}, _defineProperty({}, column, {
334
+ value: selected,
335
+ type: type
336
+ })));
337
+ applyFilters({
338
+ column: column,
339
+ value: selected,
340
+ type: type
341
+ });
342
+ (_components$RadioButt = (_components$RadioButt2 = components.RadioButtonGroup).onChange) === null || _components$RadioButt === void 0 ? void 0 : _components$RadioButt.call(_components$RadioButt2, selected);
343
+ }
344
+ }), /*#__PURE__*/React.createElement(RadioButton, {
345
+ id: "any",
346
+ labelText: "Any",
347
+ value: "Any"
348
+ }), components.RadioButton.map(function (radio) {
349
+ var _ref5, _radio$id;
350
+
351
+ return /*#__PURE__*/React.createElement(RadioButton, _extends({
352
+ key: (_ref5 = (_radio$id = radio.id) !== null && _radio$id !== void 0 ? _radio$id : radio.labelText) !== null && _ref5 !== void 0 ? _ref5 : radio.value
353
+ }, radio));
354
+ })));
355
+
356
+ case DROPDOWN:
357
+ return /*#__PURE__*/React.createElement(Layer, null, /*#__PURE__*/React.createElement(Dropdown, _extends({}, components.Dropdown, {
358
+ selectedItem: ((_filtersState$column3 = filtersState[column]) === null || _filtersState$column3 === void 0 ? void 0 : _filtersState$column3.value) === '' ? 'Any' : (_filtersState$column4 = filtersState[column]) === null || _filtersState$column4 === void 0 ? void 0 : _filtersState$column4.value,
359
+ items: ['Any'].concat(_toConsumableArray(components.Dropdown.items)),
360
+ onChange: function onChange(_ref6) {
361
+ var _components$Dropdown$, _components$Dropdown;
362
+
363
+ var selectedItem = _ref6.selectedItem;
364
+ setFiltersState(_objectSpread(_objectSpread({}, filtersState), {}, _defineProperty({}, column, {
365
+ value: selectedItem,
366
+ type: type
367
+ })));
368
+ applyFilters({
369
+ column: column,
370
+ value: selectedItem,
371
+ type: type
372
+ });
373
+ (_components$Dropdown$ = (_components$Dropdown = components.Dropdown).onChange) === null || _components$Dropdown$ === void 0 ? void 0 : _components$Dropdown$.call(_components$Dropdown, selectedItem);
374
+ }
375
+ })));
376
+ }
377
+ };
378
+
379
+ var renderActionSet = function renderActionSet() {
380
+ return showActionSet && /*#__PURE__*/React.createElement(MotionActionSet, {
381
+ actions: [{
382
+ key: 1,
383
+ kind: 'primary',
384
+ label: primaryActionLabel,
385
+ onClick: apply,
386
+ disabled: shouldDisableButtons
387
+ }, {
388
+ key: 2,
389
+ kind: 'secondary',
390
+ label: secondaryActionLabel,
391
+ onClick: cancel,
392
+ disabled: shouldDisableButtons
393
+ }],
394
+ className: "".concat(componentClass, "__action-set"),
395
+ ref: actionSetRef,
396
+ variants: actionSetVariants
397
+ });
398
+ };
399
+
400
+ var onInnerContainerScroll = function onInnerContainerScroll(event) {
401
+ if (event.target.scrollTop > 0) {
402
+ setShowDividerLine(true);
403
+ } else {
404
+ setShowDividerLine(false);
405
+ }
406
+ };
407
+ /** Effects */
408
+
409
+
410
+ useEffect(function liftOpenStateToParent() {
411
+ if (leftPanelOpen) {
412
+ onPanelOpen(leftPanelOpen);
413
+ } else {
414
+ onPanelClose(leftPanelOpen);
415
+ }
416
+ }, [leftPanelOpen, onPanelClose, onPanelOpen]);
417
+ useEffect(function setPanelMinimumHeight() {
418
+ var _filterPanelRef$curre;
419
+
420
+ (_filterPanelRef$curre = filterPanelRef.current) === null || _filterPanelRef$curre === void 0 ? void 0 : _filterPanelRef$curre.style.setProperty('--filter-panel-min-height', rem(filterPanelMinHeight));
421
+ }, [filterPanelMinHeight]);
422
+ useSubscribeToEventEmitter(CLEAR_FILTERS, reset);
423
+
424
+ var getScrollableContainerHeight = function getScrollableContainerHeight() {
425
+ var _filterHeadingRef$cur, _filterSearchRef$curr, _actionSetRef$current;
426
+
427
+ var filterHeadingHeight = (_filterHeadingRef$cur = filterHeadingRef.current) === null || _filterHeadingRef$cur === void 0 ? void 0 : _filterHeadingRef$cur.getBoundingClientRect().height;
428
+ var filterSearchHeight = (_filterSearchRef$curr = filterSearchRef.current) === null || _filterSearchRef$curr === void 0 ? void 0 : _filterSearchRef$curr.getBoundingClientRect().height;
429
+ var actionSetHeight = (_actionSetRef$current = actionSetRef.current) === null || _actionSetRef$current === void 0 ? void 0 : _actionSetRef$current.getBoundingClientRect().height;
430
+ var height = "calc(100vh - ".concat(filterHeadingHeight, "px - ").concat(showFilterSearch ? filterSearchHeight : 0, "px - ").concat(updateMethod === BATCH ? actionSetHeight : 0, "px)");
431
+ return height;
432
+ };
433
+
434
+ return /*#__PURE__*/React.createElement(motion.div, {
435
+ ref: filterPanelRef,
436
+ className: cx(componentClass, "".concat(componentClass, "__container"), (_cx = {}, _defineProperty(_cx, "".concat(componentClass, "--open"), leftPanelOpen), _defineProperty(_cx, "".concat(componentClass, "--batch"), showActionSet), _defineProperty(_cx, "".concat(componentClass, "--instant"), !showActionSet), _cx)),
437
+ initial: false,
438
+ animate: leftPanelOpen ? 'visible' : 'hidden',
439
+ variants: panelVariants
440
+ }, /*#__PURE__*/React.createElement(motion.div, {
441
+ variants: innerContainerVariants
442
+ }, /*#__PURE__*/React.createElement("header", {
443
+ ref: filterHeadingRef,
444
+ className: cx("".concat(componentClass, "__heading"), _defineProperty({}, "".concat(componentClass, "__heading--with-divider"), showDividerLine))
445
+ }, /*#__PURE__*/React.createElement("div", {
446
+ className: "".concat(componentClass, "__title")
447
+ }, title), /*#__PURE__*/React.createElement(Button, {
448
+ hasIconOnly: true,
449
+ renderIcon: function renderIcon(props) {
450
+ return /*#__PURE__*/React.createElement(Close, _extends({
451
+ size: 16
452
+ }, props));
453
+ },
454
+ iconDescription: closeIconDescription,
455
+ kind: "ghost",
456
+ tooltipPosition: "bottom",
457
+ tooltipAlignment: "end",
458
+ onClick: closePanel
459
+ }), showFilterSearch && /*#__PURE__*/React.createElement("div", {
460
+ ref: filterSearchRef,
461
+ className: "".concat(componentClass, "__search")
462
+ }, /*#__PURE__*/React.createElement(Layer, null, /*#__PURE__*/React.createElement(Search, {
463
+ labelText: searchLabelText,
464
+ placeholder: searchPlaceholder,
465
+ size: "sm"
466
+ })))), /*#__PURE__*/React.createElement("div", {
467
+ className: "".concat(componentClass, "__inner-container"),
468
+ style: {
469
+ height: getScrollableContainerHeight()
470
+ },
471
+ onScroll: onInnerContainerScroll
472
+ }, filterSections.map(function (_ref7) {
473
+ var _ref7$categoryTitle = _ref7.categoryTitle,
474
+ categoryTitle = _ref7$categoryTitle === void 0 ? null : _ref7$categoryTitle,
475
+ _ref7$filters = _ref7.filters,
476
+ filters = _ref7$filters === void 0 ? [] : _ref7$filters,
477
+ hasAccordion = _ref7.hasAccordion;
478
+ return /*#__PURE__*/React.createElement("div", {
479
+ className: "".concat(componentClass, "__category")
480
+ }, categoryTitle && /*#__PURE__*/React.createElement("div", {
481
+ className: "".concat(componentClass, "__category-title")
482
+ }, categoryTitle), hasAccordion ? /*#__PURE__*/React.createElement(Accordion, null, filters.map(function (_ref8) {
483
+ var filterLabel = _ref8.filterLabel,
484
+ filter = _ref8.filter;
485
+ return /*#__PURE__*/React.createElement(AccordionItem, {
486
+ title: filterLabel,
487
+ key: filterLabel
488
+ }, renderFilter(filter));
489
+ })) : filters.map(function (_ref9) {
490
+ var filter = _ref9.filter;
491
+ return renderFilter(filter);
492
+ }));
493
+ })), renderActionSet()));
494
+ };
495
+
496
+ FilterPanel.propTypes = {
497
+ closeIconDescription: PropTypes.string,
498
+ filterPanelMinHeight: PropTypes.number,
499
+ filterSections: PropTypes.array,
500
+ onApply: PropTypes.func,
501
+ onCancel: PropTypes.func,
502
+ onPanelClose: PropTypes.func,
503
+ onPanelOpen: PropTypes.func,
504
+ open: PropTypes.bool,
505
+ primaryActionLabel: PropTypes.string,
506
+ searchLabelText: PropTypes.string,
507
+ searchPlaceholder: PropTypes.string,
508
+ secondaryActionLabel: PropTypes.string,
509
+ setAllFilters: PropTypes.func.isRequired,
510
+ showFilterSearch: PropTypes.bool,
511
+ title: PropTypes.string,
512
+ updateMethod: PropTypes.oneOf([BATCH, INSTANT])
513
+ };
514
+ export default FilterPanel;
@@ -6,7 +6,7 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
6
6
  * This source code is licensed under the Apache-2.0 license found in the
7
7
  * LICENSE file in the root directory of this source tree.
8
8
  */
9
- import React, { createContext } from 'react';
9
+ import React, { createContext, useState } from 'react';
10
10
  import PropTypes from 'prop-types';
11
11
  import { DATE, DROPDOWN, NUMBER, RADIO, CHECKBOX } from './constants';
12
12
  export var FilterContext = /*#__PURE__*/createContext();
@@ -69,9 +69,17 @@ export var FilterProvider = function FilterProvider(_ref2) {
69
69
  var children = _ref2.children,
70
70
  filters = _ref2.filters;
71
71
  var filterTags = prepareFiltersForTags(filters);
72
+
73
+ var _useState = useState(false),
74
+ _useState2 = _slicedToArray(_useState, 2),
75
+ leftPanelOpen = _useState2[0],
76
+ setLeftPanelOpen = _useState2[1];
77
+
72
78
  var value = {
73
79
  filterTags: filterTags,
74
- EventEmitter: EventEmitter
80
+ EventEmitter: EventEmitter,
81
+ leftPanelOpen: leftPanelOpen,
82
+ setLeftPanelOpen: setLeftPanelOpen
75
83
  };
76
84
  return /*#__PURE__*/React.createElement(FilterContext.Provider, {
77
85
  value: value
@@ -8,6 +8,10 @@
8
8
  /** Constants for update methods can either be batch or instant */
9
9
  export var BATCH = 'batch';
10
10
  export var INSTANT = 'instant';
11
+ /** Constants for filter variation */
12
+
13
+ export var FLYOUT = 'flyout';
14
+ export var PANEL = 'panel';
11
15
  /** Constants for filter type */
12
16
 
13
17
  export var DATE = 'date';
@@ -17,4 +21,8 @@ export var RADIO = 'radio';
17
21
  export var DROPDOWN = 'dropdown';
18
22
  /** Constants for event emitters */
19
23
 
20
- export var CLEAR_FILTERS = 'clearFilters';
24
+ export var CLEAR_FILTERS = 'clearFilters';
25
+ /** Constants for panel dimensions */
26
+
27
+ export var PANEL_WIDTH = 320;
28
+ export var ACTION_SET_HEIGHT = 64;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copyright IBM Corp. 2022, 2023
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ export { default as useInitialStateFromFilters } from './useInitialStateFromFilters';
8
+ export { default as useSubscribeToEventEmitter } from './useSubscribeToEventEmitter';
9
+ export { default as useShouldDisableButtons } from './useShouldDisableButtons';
@@ -8,10 +8,13 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
8
8
  * restricted by GSA ADP Schedule Contract with IBM Corp.
9
9
  */
10
10
  import { useState } from 'react';
11
+ import { FLYOUT } from '../constants';
11
12
  import { getInitialStateFromFilters } from '../utils';
12
13
 
13
14
  var useInitialStateFromFilters = function useInitialStateFromFilters(filters) {
14
- var _useState = useState(getInitialStateFromFilters(filters)),
15
+ var variation = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : FLYOUT;
16
+
17
+ var _useState = useState(getInitialStateFromFilters(filters, variation)),
15
18
  _useState2 = _slicedToArray(_useState, 2),
16
19
  state = _useState2[0],
17
20
  setState = _useState2[1];
@@ -0,0 +1,38 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+
3
+ /**
4
+ * Copyright IBM Corp. 2023, 2023
5
+ *
6
+ * This source code is licensed under the Apache-2.0 license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+
10
+ /* eslint-disable jsdoc/check-param-names */
11
+ import { useState, useEffect } from 'react';
12
+ import isEqual from 'lodash/isEqual';
13
+ /**
14
+ * Keeps track of the button disabled state
15
+ * @param {string} initialValue - the initial value if the buttons should be enabled or disabled
16
+ * @param {object} filtersState - the filter state from the filter panel or flyout
17
+ * @param {object} prevFiltersRef - reference of the prev filterState
18
+ * @returns {Array} returns a tuple of the state and setter function
19
+ */
20
+
21
+ var useShouldDisableButtons = function useShouldDisableButtons(_ref) {
22
+ var _ref$initialValue = _ref.initialValue,
23
+ initialValue = _ref$initialValue === void 0 ? true : _ref$initialValue,
24
+ filtersState = _ref.filtersState,
25
+ prevFiltersRef = _ref.prevFiltersRef;
26
+
27
+ var _useState = useState(initialValue),
28
+ _useState2 = _slicedToArray(_useState, 2),
29
+ shouldDisableButtons = _useState2[0],
30
+ setShouldDisableButtons = _useState2[1];
31
+
32
+ useEffect(function updateDisabledButtonsState() {
33
+ setShouldDisableButtons(isEqual(filtersState, JSON.parse(prevFiltersRef.current)));
34
+ }, [filtersState, prevFiltersRef]);
35
+ return [shouldDisableButtons, setShouldDisableButtons];
36
+ };
37
+
38
+ export default useShouldDisableButtons;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Copyright IBM Corp. 2022, 2023
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { useEffect, useContext } from 'react';
8
+ import { FilterContext } from '../FilterProvider';
9
+ /**
10
+ * Subscribes to the filter event emitter
11
+ * @param {string} type - the type of event to call
12
+ * @param {Function} callback - a callback to run when the event is dispatched
13
+ */
14
+
15
+ var useSubscribeToEventEmitter = function useSubscribeToEventEmitter(type, callback) {
16
+ var _useContext = useContext(FilterContext),
17
+ EventEmitter = _useContext.EventEmitter;
18
+
19
+ useEffect(function subscribeToEmitter() {
20
+ // This event is emitted from the DatagridToolbar component when clearFilters is clicked in FilterSummary
21
+ EventEmitter.subscribe(type, callback);
22
+ });
23
+ };
24
+
25
+ export default useSubscribeToEventEmitter;
@@ -4,4 +4,6 @@
4
4
  * This source code is licensed under the Apache-2.0 license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- export { default as FilterFlyout } from './FilterFlyout';
7
+ export { default as FilterFlyout } from './FilterFlyout';
8
+ export { default as FilterPanel } from './FilterPanel';
9
+ export { FilterProvider, FilterContext } from './FilterProvider';