@carbon/ibm-products 1.59.1 → 1.61.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. package/css/index-full-carbon.css +99 -45
  2. package/css/index-full-carbon.css.map +1 -1
  3. package/css/index-full-carbon.min.css +4 -4
  4. package/css/index-full-carbon.min.css.map +1 -1
  5. package/css/index-without-carbon-released-only.css +9 -3
  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 +89 -30
  10. package/css/index-without-carbon.css.map +1 -1
  11. package/css/index-without-carbon.min.css +2 -2
  12. package/css/index-without-carbon.min.css.map +1 -1
  13. package/css/index.css +89 -45
  14. package/css/index.css.map +1 -1
  15. package/css/index.min.css +3 -3
  16. package/css/index.min.css.map +1 -1
  17. package/es/components/Datagrid/Datagrid/Datagrid.js +2 -1
  18. package/es/components/Datagrid/Datagrid/DatagridContent.js +10 -2
  19. package/es/components/Datagrid/Datagrid/DatagridEmptyBody.js +4 -4
  20. package/es/components/Datagrid/Datagrid/DatagridHeaderRow.js +2 -2
  21. package/es/components/Datagrid/Datagrid/DatagridSelectAll.js +13 -1
  22. package/es/components/Datagrid/Datagrid/DatagridToolbar.js +3 -15
  23. package/es/components/Datagrid/Datagrid/DraggableElement.js +32 -135
  24. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +14 -38
  25. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsTearsheet.js +1 -0
  26. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/DraggableItemsList.js +134 -45
  27. package/es/components/Datagrid/Datagrid/addons/Filtering/FilterPanel.js +7 -6
  28. package/es/components/Datagrid/Datagrid/addons/Filtering/FilterProvider.js +104 -18
  29. package/es/components/Datagrid/Datagrid/addons/Filtering/constants.js +1 -0
  30. package/es/components/Datagrid/Datagrid/addons/Filtering/hooks/useFilters.js +37 -4
  31. package/es/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditButton/InlineEditButton.js +6 -12
  32. package/es/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditCell/InlineEditCell.js +0 -5
  33. package/es/components/Datagrid/Datagrid/addons/RowSize/RowSizeDropdown.js +17 -5
  34. package/es/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.js +4 -3
  35. package/es/components/Datagrid/useFiltering.js +4 -1
  36. package/es/components/Datagrid/useInlineEdit.js +1 -6
  37. package/es/components/Datagrid/useNestedRowExpander.js +22 -9
  38. package/es/components/Datagrid/useRowExpander.js +22 -9
  39. package/es/components/Datagrid/useSortableColumns.js +5 -4
  40. package/es/components/Datagrid/utils/getArgTypes.js +12 -0
  41. package/es/components/EmptyStates/EmptyState.js +1 -1
  42. package/es/components/EmptyStates/ErrorEmptyState/ErrorEmptyState.js +1 -1
  43. package/es/components/EmptyStates/NoDataEmptyState/NoDataEmptyState.js +1 -1
  44. package/es/components/EmptyStates/NoTagsEmptyState/NoTagsEmptyState.js +1 -1
  45. package/es/components/EmptyStates/NotFoundEmptyState/NotFoundEmptyState.js +1 -1
  46. package/es/components/EmptyStates/NotificationsEmptyState/NotificationsEmptyState.js +1 -1
  47. package/es/components/EmptyStates/UnauthorizedEmptyState/UnauthorizedEmptyState.js +1 -1
  48. package/es/components/EmptyStates/assets/ErrorIllustration.js +6 -11
  49. package/es/components/EmptyStates/assets/NoDataIllustration.js +6 -11
  50. package/es/components/EmptyStates/assets/NoTagsIllustration.js +6 -12
  51. package/es/components/EmptyStates/assets/NotFoundIllustration.js +6 -12
  52. package/es/components/EmptyStates/assets/NotificationsIllustration.js +6 -12
  53. package/es/components/EmptyStates/assets/UnauthorizedIllustration.js +6 -12
  54. package/es/components/FilterSummary/FilterSummary.js +15 -5
  55. package/es/components/TagSet/TagSet.js +14 -10
  56. package/es/components/TagSet/TagSetOverflow.js +16 -5
  57. package/es/global/js/hooks/useWindowScroll.js +5 -0
  58. package/es/global/js/utils/getNodeTextContent.js +51 -0
  59. package/lib/components/Datagrid/Datagrid/Datagrid.js +2 -1
  60. package/lib/components/Datagrid/Datagrid/DatagridContent.js +9 -1
  61. package/lib/components/Datagrid/Datagrid/DatagridEmptyBody.js +3 -3
  62. package/lib/components/Datagrid/Datagrid/DatagridHeaderRow.js +2 -2
  63. package/lib/components/Datagrid/Datagrid/DatagridSelectAll.js +13 -1
  64. package/lib/components/Datagrid/Datagrid/DatagridToolbar.js +3 -15
  65. package/lib/components/Datagrid/Datagrid/DraggableElement.js +34 -140
  66. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +17 -38
  67. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsTearsheet.js +1 -0
  68. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/DraggableItemsList.js +134 -52
  69. package/lib/components/Datagrid/Datagrid/addons/Filtering/FilterPanel.js +7 -6
  70. package/lib/components/Datagrid/Datagrid/addons/Filtering/FilterProvider.js +104 -24
  71. package/lib/components/Datagrid/Datagrid/addons/Filtering/constants.js +4 -2
  72. package/lib/components/Datagrid/Datagrid/addons/Filtering/hooks/useFilters.js +36 -3
  73. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditButton/InlineEditButton.js +6 -12
  74. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditCell/InlineEditCell.js +0 -5
  75. package/lib/components/Datagrid/Datagrid/addons/RowSize/RowSizeDropdown.js +15 -3
  76. package/lib/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.js +7 -3
  77. package/lib/components/Datagrid/useFiltering.js +4 -1
  78. package/lib/components/Datagrid/useInlineEdit.js +1 -6
  79. package/lib/components/Datagrid/useNestedRowExpander.js +24 -9
  80. package/lib/components/Datagrid/useRowExpander.js +24 -9
  81. package/lib/components/Datagrid/useSortableColumns.js +5 -4
  82. package/lib/components/Datagrid/utils/getArgTypes.js +12 -0
  83. package/lib/components/EmptyStates/EmptyState.js +1 -1
  84. package/lib/components/EmptyStates/ErrorEmptyState/ErrorEmptyState.js +1 -1
  85. package/lib/components/EmptyStates/NoDataEmptyState/NoDataEmptyState.js +1 -1
  86. package/lib/components/EmptyStates/NoTagsEmptyState/NoTagsEmptyState.js +1 -1
  87. package/lib/components/EmptyStates/NotFoundEmptyState/NotFoundEmptyState.js +1 -1
  88. package/lib/components/EmptyStates/NotificationsEmptyState/NotificationsEmptyState.js +1 -1
  89. package/lib/components/EmptyStates/UnauthorizedEmptyState/UnauthorizedEmptyState.js +1 -1
  90. package/lib/components/EmptyStates/assets/ErrorIllustration.js +6 -11
  91. package/lib/components/EmptyStates/assets/NoDataIllustration.js +6 -11
  92. package/lib/components/EmptyStates/assets/NoTagsIllustration.js +6 -12
  93. package/lib/components/EmptyStates/assets/NotFoundIllustration.js +6 -12
  94. package/lib/components/EmptyStates/assets/NotificationsIllustration.js +6 -12
  95. package/lib/components/EmptyStates/assets/UnauthorizedIllustration.js +6 -12
  96. package/lib/components/FilterSummary/FilterSummary.js +15 -12
  97. package/lib/components/TagSet/TagSet.js +13 -9
  98. package/lib/components/TagSet/TagSetOverflow.js +16 -5
  99. package/lib/global/js/hooks/useWindowScroll.js +6 -0
  100. package/lib/global/js/utils/getNodeTextContent.js +59 -0
  101. package/package.json +8 -7
  102. package/scss/components/Datagrid/_datagrid.scss +2 -1
  103. package/scss/components/Datagrid/styles/_draggableElement.scss +44 -20
  104. package/scss/components/Datagrid/styles/_useInlineEdit.scss +7 -11
  105. package/scss/components/Datagrid/styles/addons/_CustomizeColumnsTearsheet.scss +0 -1
  106. package/scss/components/Datagrid/styles/addons/_RowSizeDropdown.scss +42 -1
  107. package/scss/components/TagSet/_tag-set.scss +13 -3
  108. package/es/components/Datagrid/utils/getColTitle.js +0 -25
  109. package/lib/components/Datagrid/utils/getColTitle.js +0 -32
@@ -24,7 +24,9 @@ import { useMultipleKeyTracking } from '../../DataSpreadsheet/hooks';
24
24
  import FilterPanel from './addons/Filtering/FilterPanel';
25
25
  import { FilterSummary } from '../../FilterSummary';
26
26
  import { FilterContext } from './addons/Filtering';
27
- import { CLEAR_FILTERS } from './addons/Filtering/constants';
27
+ import { CLEAR_FILTERS, CLEAR_SINGLE_FILTER } from './addons/Filtering/constants';
28
+ import { useSubscribeToEventEmitter } from './addons/Filtering/hooks';
29
+ import { clearSingleFilter } from './addons/Filtering/FilterProvider';
28
30
  var TableContainer = DataTable.TableContainer,
29
31
  Table = DataTable.Table;
30
32
  var blockClass = "".concat(pkg.prefix, "--datagrid");
@@ -62,6 +64,7 @@ export var DatagridContent = function DatagridContent(_ref) {
62
64
  DatagridActions = datagridState.DatagridActions,
63
65
  totalColumnsWidth = datagridState.totalColumnsWidth,
64
66
  gridRef = datagridState.gridRef,
67
+ setAllFilters = datagridState.setAllFilters,
65
68
  state = datagridState.state,
66
69
  page = datagridState.page,
67
70
  rows = datagridState.rows;
@@ -127,13 +130,18 @@ export var DatagridContent = function DatagridContent(_ref) {
127
130
  gridElement.style.setProperty("--".concat(blockClass, "--grid-header-height"), px((tableHeader === null || tableHeader === void 0 ? void 0 : tableHeader.clientHeight) || 0));
128
131
  }
129
132
  }, [withInlineEdit, tableId, totalColumnsWidth, datagridState, gridActive]);
133
+ useSubscribeToEventEmitter(CLEAR_SINGLE_FILTER, function (id) {
134
+ return clearSingleFilter(id, setAllFilters, state);
135
+ });
130
136
  var renderFilterSummary = function renderFilterSummary() {
131
137
  return state.filters.length > 0 && /*#__PURE__*/React.createElement(FilterSummary, {
132
138
  className: "".concat(blockClass, "__filter-summary"),
133
139
  filters: filterTags,
134
140
  clearFilters: function clearFilters() {
135
141
  return EventEmitter.dispatch(CLEAR_FILTERS);
136
- }
142
+ },
143
+ renderLabel: filterProps.renderLabel,
144
+ overflowType: "tag"
137
145
  });
138
146
  };
139
147
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(TableContainer, {
@@ -9,7 +9,7 @@ import _extends from "@babel/runtime/helpers/extends";
9
9
  import React from 'react';
10
10
  import { pkg } from '../../../settings';
11
11
  import { DataTable } from 'carbon-components-react';
12
- import { NoDataEmptyState, ErrorEmptyState, NotFoundEmptyState } from '../../EmptyStates';
12
+ import { NoDataEmptyState, ErrorEmptyState, NotFoundEmptyState, EmptyState } from '../../EmptyStates';
13
13
  var blockClass = "".concat(pkg.prefix, "--datagrid");
14
14
  var TableBody = DataTable.TableBody,
15
15
  TableRow = DataTable.TableRow,
@@ -33,13 +33,13 @@ var DatagridEmptyBody = function DatagridEmptyBody(datagridState) {
33
33
  action: emptyStateAction,
34
34
  link: emptyStateLink
35
35
  };
36
+ var validEmptyStates = ['error', 'noData', 'notFound'];
36
37
  return /*#__PURE__*/React.createElement(TableBody, _extends({}, getTableBodyProps({
37
38
  role: false
38
39
  }), {
39
40
  className: "".concat(blockClass, "__empty-state-body")
40
41
  }), /*#__PURE__*/React.createElement(TableRow, null, /*#__PURE__*/React.createElement(TableCell, {
41
- colSpan: headers.length,
42
- className: "".concat(blockClass, "__empty-state-cell")
43
- }, emptyStateType === 'error' && /*#__PURE__*/React.createElement(ErrorEmptyState, emptyStateProps), emptyStateType === 'noData' && /*#__PURE__*/React.createElement(NoDataEmptyState, emptyStateProps), emptyStateType === 'notFound' && /*#__PURE__*/React.createElement(NotFoundEmptyState, emptyStateProps))));
42
+ colSpan: headers.length
43
+ }, validEmptyStates.includes(emptyStateType) ? /*#__PURE__*/React.createElement(React.Fragment, null, emptyStateType === 'error' && /*#__PURE__*/React.createElement(ErrorEmptyState, emptyStateProps), emptyStateType === 'noData' && /*#__PURE__*/React.createElement(NoDataEmptyState, emptyStateProps), emptyStateType === 'notFound' && /*#__PURE__*/React.createElement(NotFoundEmptyState, emptyStateProps)) : /*#__PURE__*/React.createElement(EmptyState, emptyStateProps))));
44
44
  };
45
45
  export default DatagridEmptyBody;
@@ -16,11 +16,11 @@ import { px } from '@carbon/layout';
16
16
  import { selectionColumnId } from '../common-column-ids';
17
17
  import { pkg } from '../../../settings';
18
18
  import { handleColumnResizeEndEvent, handleColumnResizeStartEvent, handleColumnResizingEvent } from './addons/stateReducer';
19
- import getColTitle from '../utils/getColTitle';
19
+ import { getNodeTextContent } from '../../../global/js/utils/getNodeTextContent';
20
20
  var blockClass = "".concat(pkg.prefix, "--datagrid");
21
21
  var getAccessibilityProps = function getAccessibilityProps(header) {
22
22
  var props = {};
23
- var title = getColTitle(header);
23
+ var title = getNodeTextContent(header.Header);
24
24
  if (title) {
25
25
  props.title = title;
26
26
  } else {
@@ -50,11 +50,23 @@ var SelectAll = function SelectAll(datagridState) {
50
50
  var _getProps = getProps(),
51
51
  onChange = _getProps.onChange,
52
52
  selectProps = _objectWithoutProperties(_getProps, _excluded);
53
+ var _ref = selectProps || {},
54
+ indeterminate = _ref.indeterminate;
55
+ var handleSelectAllChange = function handleSelectAllChange(event) {
56
+ if (indeterminate) {
57
+ return onChange === null || onChange === void 0 ? void 0 : onChange({
58
+ target: {
59
+ checked: false
60
+ }
61
+ });
62
+ }
63
+ return onChange === null || onChange === void 0 ? void 0 : onChange(event);
64
+ };
53
65
  return /*#__PURE__*/React.createElement("div", {
54
66
  className: cx("".concat(blockClass, "__head-select-all"), "".concat(blockClass, "__checkbox-cell"), _defineProperty({}, "".concat(blockClass, "__checkbox-cell-sticky-left"), isFirstColumnStickyLeft && windowSize > 671))
55
67
  }, /*#__PURE__*/React.createElement(TableSelectAll, _extends({}, selectProps, {
56
68
  name: "".concat(tableId, "-select-all-checkbox-name"),
57
- onSelect: onChange,
69
+ onSelect: handleSelectAllChange,
58
70
  disabled: isFetching || selectProps.disabled,
59
71
  id: "".concat(tableId, "-select-all-checkbox-id")
60
72
  })));
@@ -1,7 +1,7 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
  /**
4
- * Copyright IBM Corp. 2022, 2022
4
+ * Copyright IBM Corp. 2022, 2023
5
5
  *
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.
@@ -70,20 +70,8 @@ var DatagridBatchActionsToolbar = function DatagridBatchActionsToolbar(datagridS
70
70
  menuOptionsClass: "".concat(blockClass, "__button-menu-options"),
71
71
  flipped: true
72
72
  }, toolbarBatchActions && toolbarBatchActions.map(function (batchAction, index) {
73
- if (index < 2) {
74
- if (displayAllInMenu) {
75
- return /*#__PURE__*/React.createElement(ButtonMenuItem, {
76
- key: "".concat(batchAction.label, "-").concat(index),
77
- itemText: batchAction.label,
78
- onClick: function onClick() {
79
- batchAction.onClick();
80
- if (batchAction.type === 'select_all') {
81
- toggleAllRowsSelected(true);
82
- }
83
- }
84
- });
85
- }
86
- return null;
73
+ if (index < 2 && !displayAllInMenu) {
74
+ return;
87
75
  }
88
76
  return /*#__PURE__*/React.createElement(ButtonMenuItem, {
89
77
  key: "".concat(batchAction.label, "-").concat(index),
@@ -1,5 +1,5 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
1
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
  // @flow
4
4
  /*
5
5
  * Licensed Materials - Property of IBM
@@ -8,166 +8,63 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
8
8
  * US Government Users Restricted Rights - Use, duplication or disclosure
9
9
  * restricted by GSA ADP Schedule Contract with IBM Corp.
10
10
  */
11
- import * as React from 'react';
11
+ import React from 'react';
12
12
  import PropTypes from 'prop-types';
13
13
  import { Draggable16, Locked16 } from '@carbon/icons-react';
14
- import { useDrag, useDrop } from 'react-dnd';
15
14
  import cx from 'classnames';
16
15
  import { pkg } from '../../../settings';
17
- var useEffect = React.useEffect,
18
- useRef = React.useRef,
19
- useState = React.useState;
16
+ import { CSS } from '@dnd-kit/utilities';
17
+ import { useSortable } from '@dnd-kit/sortable';
20
18
  var blockClass = "".concat(pkg.prefix, "--datagrid");
21
- var DRAG_TYPE = "".concat(blockClass, "__shared-ui-draggable-element");
22
19
  var DraggableElement = function DraggableElement(_ref) {
23
20
  var _cx;
24
21
  var id = _ref.id,
25
- index = _ref.index,
26
- listData = _ref.listData,
27
22
  children = _ref.children,
28
- type = _ref.type,
23
+ classList = _ref.classList,
29
24
  disabled = _ref.disabled,
30
25
  ariaLabel = _ref.ariaLabel,
31
- onGrab = _ref.onGrab,
32
- onArrowKeyDown = _ref.onArrowKeyDown,
33
- isFocused = _ref.isFocused,
34
26
  isSticky = _ref.isSticky,
35
- moveElement = _ref.moveElement,
36
- selected = _ref.selected,
37
- _ref$positionLabel = _ref.positionLabel,
38
- positionLabel = _ref$positionLabel === void 0 ? 'Current position {index} of {total}' : _ref$positionLabel,
39
- _ref$grabbedLabel = _ref.grabbedLabel,
40
- grabbedLabel = _ref$grabbedLabel === void 0 ? '{itemName} grabbed.' : _ref$grabbedLabel,
41
- _ref$droppedLabel = _ref.droppedLabel,
42
- droppedLabel = _ref$droppedLabel === void 0 ? '{itemName} dropped.' : _ref$droppedLabel;
43
- var ref = useRef();
44
- var _useDrop = useDrop({
45
- accept: DRAG_TYPE + type,
46
- collect: function collect(monitor) {
47
- return {
48
- isOver: !!monitor.isOver()
49
- };
50
- },
51
- drop: function drop(item) {
52
- moveElement(item.index, index);
53
- },
54
- canDrop: function canDrop() {
55
- return !disabled;
56
- },
57
- hover: function hover(item) {
58
- var dragIndex = item.index;
59
- var hoverIndex = index;
60
- // Don't replace items with themselves
61
- if (dragIndex === hoverIndex || disabled) {
62
- return;
63
- }
64
- moveElement(dragIndex, hoverIndex);
65
- // Time to actually perform the action
66
- // Note: we're mutating the monitor item here!
67
- // Generally it's better to avoid mutations,
68
- // but it's good here for the sake of performance
69
- // to avoid expensive index searches.
70
- // eslint-disable-next-line no-param-reassign
71
- item.index = hoverIndex;
72
- }
27
+ selected = _ref.selected;
28
+ var _useSortable = useSortable({
29
+ id: id
73
30
  }),
74
- _useDrop2 = _slicedToArray(_useDrop, 2),
75
- isOver = _useDrop2[0].isOver,
76
- drop = _useDrop2[1];
77
- var _useDrag = useDrag({
78
- type: DRAG_TYPE + type,
79
- item: {
80
- id: id,
81
- index: index
82
- },
83
- canDrag: function canDrag() {
84
- return !disabled;
85
- },
86
- collect: function collect(monitor) {
87
- return {
88
- isDragging: monitor.isDragging()
89
- };
90
- }
91
- }),
92
- _useDrag2 = _slicedToArray(_useDrag, 3),
93
- isDragging = _useDrag2[0].isDragging,
94
- drag = _useDrag2[1],
95
- preview = _useDrag2[2];
96
- useEffect(function () {
97
- if (isFocused && ref && ref.current) {
98
- ref.current.focus();
99
- }
100
- }, [isFocused]);
101
- var _useState = useState(false),
102
- _useState2 = _slicedToArray(_useState, 2),
103
- isGrabbed = _useState2[0],
104
- setIsGrabbed = _useState2[1];
105
- var _useState3 = useState(isFocused),
106
- _useState4 = _slicedToArray(_useState3, 2),
107
- isFocusedOnItem = _useState4[0],
108
- setIsFocusedOnItem = _useState4[1];
109
- drop(ref);
31
+ attributes = _useSortable.attributes,
32
+ isDragging = _useSortable.isDragging,
33
+ listeners = _useSortable.listeners,
34
+ setNodeRef = _useSortable.setNodeRef,
35
+ transform = _useSortable.transform,
36
+ transition = _useSortable.transition;
110
37
  var content = /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
111
38
  className: cx({
112
39
  disabled: disabled
113
40
  }, "".concat(blockClass, "__draggable-handleStyle"))
114
41
  }, isSticky ? /*#__PURE__*/React.createElement(Locked16, null) : /*#__PURE__*/React.createElement(Draggable16, null)), children);
115
- return /*#__PURE__*/React.createElement("li", {
116
- className: cx((_cx = {}, _defineProperty(_cx, "".concat(blockClass, "__draggable-handleHolder-isOver"), isOver && !disabled), _defineProperty(_cx, "".concat(blockClass, "__draggable-handleHolder-grabbed"), isGrabbed), _defineProperty(_cx, "".concat(blockClass, "__draggable-handleHolder-selected"), selected), _defineProperty(_cx, "".concat(blockClass, "__draggable-handleHolder--sticky"), isSticky), _defineProperty(_cx, "".concat(blockClass, "__draggable-handleHolder"), !selected), _cx)),
117
- ref: ref,
118
- "aria-selected": isFocused,
119
- role: "option",
120
- tabIndex: isFocused ? 0 : -1,
121
- onKeyPress: function onKeyPress(e) {
122
- if (e.key === ' ' && e.target === e.currentTarget && !disabled) {
123
- var positionText = positionLabel.replace('{index}', index + 1).replace('{total}', listData.length);
124
- var grabAriaText = (isGrabbed ? droppedLabel : grabbedLabel).replace('{itemName}', ariaLabel);
125
- onGrab(grabAriaText + positionText);
126
- setIsGrabbed(!isGrabbed);
127
- e.preventDefault();
128
- }
129
- },
130
- onKeyDown: function onKeyDown(e) {
131
- if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
132
- onArrowKeyDown(e, isGrabbed, index);
133
- }
134
- },
135
- onBlur: function onBlur(e) {
136
- // handle when focus move to inner elements
137
- setIsFocusedOnItem(e.currentTarget === e.target);
138
- },
139
- onFocus: function onFocus(e) {
140
- // handle when focus move to li element
141
- setIsFocusedOnItem(e.currentTarget === e.target);
142
- }
143
- }, /*#__PURE__*/React.createElement("span", {
42
+ var style = {
43
+ transform: CSS.Transform.toString(transform),
44
+ transition: transition
45
+ };
46
+ return /*#__PURE__*/React.createElement("li", _extends({
47
+ className: cx(classList, "".concat(blockClass, "__draggable-handleHolder"), (_cx = {}, _defineProperty(_cx, "".concat(blockClass, "__draggable-handleHolder--selected"), selected), _defineProperty(_cx, "".concat(blockClass, "__draggable-handleHolder--sticky"), isSticky), _defineProperty(_cx, "".concat(blockClass, "__draggable-handleHolder--dragging"), isDragging), _cx)),
48
+ id: id,
49
+ ref: setNodeRef,
50
+ style: style
51
+ }, attributes, listeners, {
52
+ disabled: disabled,
53
+ "aria-selected": selected,
54
+ role: "option"
55
+ }), /*#__PURE__*/React.createElement("span", {
144
56
  className: "".concat(blockClass, "__shared-ui--assistive-text")
145
- }, ariaLabel), isDragging && !isOver ? /*#__PURE__*/React.createElement("div", {
146
- ref: preview,
147
- className: "".concat(blockClass, "__draggable-handleHolder-droppable ").concat(blockClass, "__draggable-handleHolder-droppable--origin")
148
- }, content) : /*#__PURE__*/React.createElement("div", {
149
- ref: drag,
150
- "aria-hidden": isFocused && isFocusedOnItem // if focus on li, hide the children from aria
151
- ,
57
+ }, ariaLabel), /*#__PURE__*/React.createElement("div", {
152
58
  className: cx(_defineProperty({}, "".concat(blockClass, "__draggable-handleStyle"), !disabled), ["".concat(blockClass, "__draggable-handleHolder-droppable")])
153
- }, (!isOver || disabled) && content));
59
+ }, content));
154
60
  };
155
61
  DraggableElement.propTypes = {
156
62
  ariaLabel: PropTypes.string.isRequired,
157
63
  children: PropTypes.element.isRequired,
64
+ classList: PropTypes.string,
158
65
  disabled: PropTypes.bool,
159
- droppedLabel: PropTypes.string,
160
- grabbedLabel: PropTypes.string,
161
66
  id: PropTypes.string.isRequired,
162
- index: PropTypes.number.isRequired,
163
- isFocused: PropTypes.bool.isRequired,
164
67
  isSticky: PropTypes.bool,
165
- listData: PropTypes.array.isRequired,
166
- moveElement: PropTypes.func.isRequired,
167
- onArrowKeyDown: PropTypes.func.isRequired,
168
- onGrab: PropTypes.func.isRequired,
169
- positionLabel: PropTypes.string,
170
- selected: PropTypes.bool,
171
- type: PropTypes.string.isRequired
68
+ selected: PropTypes.bool
172
69
  };
173
70
  export default DraggableElement;
@@ -1,32 +1,21 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
  /**
4
- * Copyright IBM Corp. 2022, 2022
4
+ * Copyright IBM Corp. 2022, 2023
5
5
  *
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
9
 
10
- import React from 'react';
10
+ import React, { useRef } from 'react';
11
11
  import PropTypes from 'prop-types';
12
- import { DndProvider } from 'react-dnd';
13
- import { HTML5Backend } from 'react-dnd-html5-backend';
14
12
  import { Checkbox } from 'carbon-components-react';
15
13
  import update from 'immutability-helper';
16
14
  import { pkg } from '../../../../../settings';
17
15
  import classNames from 'classnames';
18
16
  import { DraggableItemsList } from './DraggableItemsList';
17
+ import uuidv4 from '../../../../../global/js/utils/uuidv4';
19
18
  var blockClass = "".concat(pkg.prefix, "--datagrid");
20
- var getNextIndex = function getNextIndex(array, currentIndex, key) {
21
- var newIndex = -1;
22
- if (key === 'ArrowUp') {
23
- newIndex = currentIndex - 1 >= 0 ? currentIndex - 1 : array.length - 1;
24
- }
25
- if (key === 'ArrowDown') {
26
- newIndex = currentIndex + 1 < array.length ? currentIndex + 1 : 0;
27
- }
28
- return newIndex;
29
- };
30
19
  var Columns = function Columns(_ref) {
31
20
  var getVisibleColumnsCount = _ref.getVisibleColumnsCount,
32
21
  filterString = _ref.filterString,
@@ -36,36 +25,26 @@ var Columns = function Columns(_ref) {
36
25
  assistiveTextInstructionsLabel = _ref.assistiveTextInstructionsLabel,
37
26
  assistiveTextDisabledInstructionsLabel = _ref.assistiveTextDisabledInstructionsLabel,
38
27
  selectAllLabel = _ref.selectAllLabel;
28
+ var listId = useRef(uuidv4()); // keep id between renders
29
+ var listRef = useRef(null);
39
30
  var _React$useState = React.useState(''),
40
31
  _React$useState2 = _slicedToArray(_React$useState, 2),
41
32
  ariaRegionText = _React$useState2[0],
42
33
  setAriaRegionText = _React$useState2[1];
43
- var _React$useState3 = React.useState(-1),
44
- _React$useState4 = _slicedToArray(_React$useState3, 2),
45
- focusIndex = _React$useState4[0],
46
- setFocusIndex = _React$useState4[1];
47
- var moveElement = React.useCallback(function (dragIndex, hoverIndex) {
48
- var dragCard = columns[dragIndex];
34
+ // after a drag/drop action set the columns
35
+ var moveElement = React.useCallback(function (from, to) {
36
+ var fromCol = columns[from];
49
37
  setColumnsObject(update(columns, {
50
- $splice: [[dragIndex, 1], [hoverIndex, 0, dragCard]]
38
+ $splice: [[from, 1], [to, 0, fromCol]]
51
39
  }));
52
40
  }, [columns, setColumnsObject]);
53
41
  return /*#__PURE__*/React.createElement("div", {
54
- className: "".concat(blockClass, "__customize-columns-column-list")
55
- }, /*#__PURE__*/React.createElement(DndProvider, {
56
- backend: HTML5Backend
42
+ className: "".concat(blockClass, "__customize-columns-column-list"),
43
+ ref: listRef
57
44
  }, /*#__PURE__*/React.createElement("ol", {
58
45
  className: "".concat(blockClass, "__customize-columns-column-list--focus"),
59
46
  role: "listbox",
60
47
  "aria-describedby": "".concat(blockClass, "__customize-columns--instructions"),
61
- onKeyDown: function onKeyDown(e) {
62
- var nextIndex = getNextIndex(columns, focusIndex, e.key);
63
- if (nextIndex >= 0) {
64
- setFocusIndex(nextIndex);
65
- e.preventDefault();
66
- e.stopPropagation();
67
- }
68
- },
69
48
  tabIndex: 0
70
49
  }, /*#__PURE__*/React.createElement("span", {
71
50
  "aria-live": "assertive",
@@ -87,16 +66,13 @@ var Columns = function Columns(_ref) {
87
66
  id: "".concat(blockClass, "__customization-column-select-all"),
88
67
  labelText: selectAllLabel
89
68
  })), /*#__PURE__*/React.createElement(DraggableItemsList, {
69
+ id: listId.current,
90
70
  columns: columns,
91
71
  filterString: filterString,
92
- focusIndex: focusIndex,
93
- getNextIndex: getNextIndex,
94
72
  moveElement: moveElement,
95
- onSelectColumn: onSelectColumn,
96
73
  setAriaRegionText: setAriaRegionText,
97
- setColumnsObject: setColumnsObject,
98
- setFocusIndex: setFocusIndex
99
- }))));
74
+ onSelectColumn: onSelectColumn
75
+ })));
100
76
  };
101
77
  Columns.propTypes = {
102
78
  assistiveTextDisabledInstructionsLabel: PropTypes.string,
@@ -75,6 +75,7 @@ var CustomizeColumnsTearsheet = function CustomizeColumnsTearsheet(_ref) {
75
75
  isDirty = _useState10[0],
76
76
  setIsDirty = _useState10[1];
77
77
  var onRequestClose = function onRequestClose() {
78
+ setColumnObjects(columnDefinitions);
78
79
  setIsTearsheetOpen(false);
79
80
  };
80
81
  var onRequestSubmit = function onRequestSubmit() {