@elastic/eui 97.0.0-backport.0 → 97.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/es/components/datagrid/body/cell/data_grid_cell.styles.js +4 -2
  2. package/es/components/datagrid/body/cell/focus_utils.js +14 -4
  3. package/es/components/datagrid/body/data_grid_body.js +2 -1
  4. package/es/components/datagrid/body/data_grid_body_custom.js +5 -2
  5. package/es/components/datagrid/body/data_grid_body_virtualized.js +8 -4
  6. package/es/components/datagrid/body/header/column_actions.js +262 -27
  7. package/es/components/datagrid/body/header/{data_grid_column_resizer.js → column_resizer.js} +10 -4
  8. package/es/components/datagrid/body/header/{data_grid_column_resizer.styles.js → column_resizer.styles.js} +6 -1
  9. package/es/components/datagrid/body/header/column_sorting.js +134 -0
  10. package/es/components/datagrid/body/header/data_grid_control_header_cell.js +3 -3
  11. package/es/components/datagrid/body/header/data_grid_header_cell.js +86 -305
  12. package/es/components/datagrid/body/header/data_grid_header_cell.styles.js +1 -1
  13. package/es/components/datagrid/body/header/data_grid_header_cell_wrapper.js +19 -17
  14. package/es/components/datagrid/body/header/data_grid_header_cell_wrapper.styles.js +1 -2
  15. package/es/components/datagrid/body/header/data_grid_header_row.js +25 -10
  16. package/es/components/datagrid/body/header/draggable_columns.js +301 -0
  17. package/es/components/datagrid/body/header/draggable_columns.styles.js +38 -0
  18. package/es/components/datagrid/data_grid.js +2 -1
  19. package/es/components/datagrid/data_grid.stories.utils.js +9 -6
  20. package/es/components/datagrid/utils/col_widths.js +17 -13
  21. package/es/components/datagrid/utils/focus.js +2 -2
  22. package/es/components/datagrid/utils/scrolling.js +13 -10
  23. package/es/components/drag_and_drop/draggable.js +13 -5
  24. package/es/components/header/header.styles.js +6 -12
  25. package/es/components/page_template/inner/page_inner.styles.js +3 -4
  26. package/es/components/tabs/tab.js +1 -1
  27. package/eui.d.ts +406 -311
  28. package/i18ntokens.json +123 -123
  29. package/lib/components/datagrid/body/cell/data_grid_cell.styles.js +4 -2
  30. package/lib/components/datagrid/body/cell/focus_utils.js +14 -4
  31. package/lib/components/datagrid/body/data_grid_body.js +2 -1
  32. package/lib/components/datagrid/body/data_grid_body_custom.js +5 -2
  33. package/lib/components/datagrid/body/data_grid_body_virtualized.js +8 -4
  34. package/lib/components/datagrid/body/header/column_actions.js +265 -29
  35. package/lib/components/datagrid/body/header/{data_grid_column_resizer.js → column_resizer.js} +11 -5
  36. package/{optimize/lib/components/datagrid/body/header/data_grid_column_resizer.styles.js → lib/components/datagrid/body/header/column_resizer.styles.js} +6 -1
  37. package/lib/components/datagrid/body/header/column_sorting.js +144 -0
  38. package/lib/components/datagrid/body/header/data_grid_control_header_cell.js +3 -3
  39. package/lib/components/datagrid/body/header/data_grid_header_cell.js +86 -305
  40. package/lib/components/datagrid/body/header/data_grid_header_cell.styles.js +1 -1
  41. package/lib/components/datagrid/body/header/data_grid_header_cell_wrapper.js +19 -17
  42. package/lib/components/datagrid/body/header/data_grid_header_cell_wrapper.styles.js +1 -2
  43. package/lib/components/datagrid/body/header/data_grid_header_row.js +24 -9
  44. package/lib/components/datagrid/body/header/draggable_columns.js +308 -0
  45. package/lib/components/datagrid/body/header/draggable_columns.styles.js +42 -0
  46. package/lib/components/datagrid/data_grid.js +2 -1
  47. package/lib/components/datagrid/data_grid.stories.utils.js +9 -6
  48. package/lib/components/datagrid/utils/col_widths.js +17 -13
  49. package/lib/components/datagrid/utils/focus.js +2 -2
  50. package/lib/components/datagrid/utils/scrolling.js +13 -10
  51. package/lib/components/drag_and_drop/draggable.js +13 -5
  52. package/lib/components/header/header.styles.js +6 -12
  53. package/lib/components/page_template/inner/page_inner.styles.js +3 -4
  54. package/lib/components/tabs/tab.js +1 -1
  55. package/optimize/es/components/datagrid/body/cell/data_grid_cell.styles.js +4 -2
  56. package/optimize/es/components/datagrid/body/cell/focus_utils.js +13 -4
  57. package/optimize/es/components/datagrid/body/data_grid_body_custom.js +3 -1
  58. package/optimize/es/components/datagrid/body/data_grid_body_virtualized.js +6 -3
  59. package/optimize/es/components/datagrid/body/header/column_actions.js +250 -26
  60. package/optimize/es/components/datagrid/body/header/{data_grid_column_resizer.js → column_resizer.js} +8 -3
  61. package/optimize/es/components/datagrid/body/header/{data_grid_column_resizer.styles.js → column_resizer.styles.js} +6 -1
  62. package/optimize/es/components/datagrid/body/header/column_sorting.js +134 -0
  63. package/optimize/es/components/datagrid/body/header/data_grid_control_header_cell.js +2 -2
  64. package/optimize/es/components/datagrid/body/header/data_grid_header_cell.js +82 -302
  65. package/optimize/es/components/datagrid/body/header/data_grid_header_cell.styles.js +1 -1
  66. package/optimize/es/components/datagrid/body/header/data_grid_header_cell_wrapper.js +15 -14
  67. package/optimize/es/components/datagrid/body/header/data_grid_header_cell_wrapper.styles.js +1 -2
  68. package/optimize/es/components/datagrid/body/header/data_grid_header_row.js +25 -10
  69. package/optimize/es/components/datagrid/body/header/draggable_columns.js +223 -0
  70. package/optimize/es/components/datagrid/body/header/draggable_columns.styles.js +38 -0
  71. package/optimize/es/components/datagrid/data_grid.js +2 -1
  72. package/optimize/es/components/datagrid/data_grid.stories.utils.js +7 -5
  73. package/optimize/es/components/datagrid/utils/col_widths.js +17 -13
  74. package/optimize/es/components/datagrid/utils/focus.js +2 -2
  75. package/optimize/es/components/datagrid/utils/scrolling.js +13 -10
  76. package/optimize/es/components/drag_and_drop/draggable.js +8 -3
  77. package/optimize/es/components/header/header.styles.js +6 -12
  78. package/optimize/es/components/page_template/inner/page_inner.styles.js +3 -4
  79. package/optimize/es/components/tabs/tab.js +1 -1
  80. package/optimize/lib/components/datagrid/body/cell/data_grid_cell.styles.js +4 -2
  81. package/optimize/lib/components/datagrid/body/cell/focus_utils.js +13 -4
  82. package/optimize/lib/components/datagrid/body/data_grid_body_custom.js +3 -1
  83. package/optimize/lib/components/datagrid/body/data_grid_body_virtualized.js +6 -3
  84. package/optimize/lib/components/datagrid/body/header/column_actions.js +253 -27
  85. package/optimize/lib/components/datagrid/body/header/{data_grid_column_resizer.js → column_resizer.js} +9 -4
  86. package/{test-env/components/datagrid/body/header/data_grid_column_resizer.styles.js → optimize/lib/components/datagrid/body/header/column_resizer.styles.js} +6 -1
  87. package/optimize/lib/components/datagrid/body/header/column_sorting.js +144 -0
  88. package/optimize/lib/components/datagrid/body/header/data_grid_control_header_cell.js +2 -2
  89. package/optimize/lib/components/datagrid/body/header/data_grid_header_cell.js +80 -300
  90. package/optimize/lib/components/datagrid/body/header/data_grid_header_cell.styles.js +1 -1
  91. package/optimize/lib/components/datagrid/body/header/data_grid_header_cell_wrapper.js +15 -14
  92. package/optimize/lib/components/datagrid/body/header/data_grid_header_cell_wrapper.styles.js +1 -2
  93. package/optimize/lib/components/datagrid/body/header/data_grid_header_row.js +24 -9
  94. package/optimize/lib/components/datagrid/body/header/draggable_columns.js +231 -0
  95. package/optimize/lib/components/datagrid/body/header/draggable_columns.styles.js +43 -0
  96. package/optimize/lib/components/datagrid/data_grid.js +2 -1
  97. package/optimize/lib/components/datagrid/data_grid.stories.utils.js +7 -5
  98. package/optimize/lib/components/datagrid/utils/col_widths.js +17 -13
  99. package/optimize/lib/components/datagrid/utils/focus.js +2 -2
  100. package/optimize/lib/components/datagrid/utils/scrolling.js +13 -10
  101. package/optimize/lib/components/drag_and_drop/draggable.js +8 -3
  102. package/optimize/lib/components/header/header.styles.js +6 -12
  103. package/optimize/lib/components/page_template/inner/page_inner.styles.js +3 -4
  104. package/optimize/lib/components/tabs/tab.js +1 -1
  105. package/package.json +2 -3
  106. package/test-env/components/datagrid/body/cell/data_grid_cell.styles.js +4 -2
  107. package/test-env/components/datagrid/body/cell/focus_utils.js +13 -4
  108. package/test-env/components/datagrid/body/data_grid_body.js +2 -1
  109. package/test-env/components/datagrid/body/data_grid_body_custom.js +5 -2
  110. package/test-env/components/datagrid/body/data_grid_body_virtualized.js +8 -4
  111. package/test-env/components/datagrid/body/header/column_actions.js +261 -27
  112. package/test-env/components/datagrid/body/header/{data_grid_column_resizer.js → column_resizer.js} +11 -5
  113. package/{lib/components/datagrid/body/header/data_grid_column_resizer.styles.js → test-env/components/datagrid/body/header/column_resizer.styles.js} +6 -1
  114. package/test-env/components/datagrid/body/header/column_sorting.js +144 -0
  115. package/test-env/components/datagrid/body/header/data_grid_control_header_cell.js +3 -3
  116. package/test-env/components/datagrid/body/header/data_grid_header_cell.js +82 -301
  117. package/test-env/components/datagrid/body/header/data_grid_header_cell.styles.js +1 -1
  118. package/test-env/components/datagrid/body/header/data_grid_header_cell_wrapper.js +19 -17
  119. package/test-env/components/datagrid/body/header/data_grid_header_cell_wrapper.styles.js +1 -2
  120. package/test-env/components/datagrid/body/header/data_grid_header_row.js +24 -9
  121. package/test-env/components/datagrid/body/header/draggable_columns.js +305 -0
  122. package/test-env/components/datagrid/body/header/draggable_columns.styles.js +43 -0
  123. package/test-env/components/datagrid/data_grid.js +2 -1
  124. package/test-env/components/datagrid/data_grid.stories.utils.js +9 -6
  125. package/test-env/components/datagrid/utils/col_widths.js +17 -13
  126. package/test-env/components/datagrid/utils/focus.js +2 -2
  127. package/test-env/components/datagrid/utils/scrolling.js +13 -10
  128. package/test-env/components/drag_and_drop/draggable.js +13 -5
  129. package/test-env/components/header/header.styles.js +6 -12
  130. package/test-env/components/page_template/inner/page_inner.styles.js +3 -4
  131. package/test-env/components/tabs/tab.js +1 -1
@@ -0,0 +1,308 @@
1
+ "use strict";
2
+
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.DroppableColumns = exports.DraggableColumn = exports.DragOverlay = exports.ConditionalDroppableColumns = exports.ConditionalDraggableColumn = void 0;
8
+ var _react = _interopRequireWildcard(require("react"));
9
+ var _propTypes = _interopRequireDefault(require("prop-types"));
10
+ var _services = require("../../../../services");
11
+ var _drag_and_drop = require("../../../drag_and_drop");
12
+ var _portal = require("../../../portal");
13
+ var _focus = require("../../utils/focus");
14
+ var _data_grid = require("../../data_grid.styles");
15
+ var _draggable_columns = require("./draggable_columns.styles");
16
+ var _react2 = require("@emotion/react");
17
+ var _excluded = ["role", "tabIndex"],
18
+ _excluded2 = ["canDragAndDropColumns", "children"],
19
+ _excluded3 = ["canDragAndDropColumns", "children"];
20
+ /*
21
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
22
+ * or more contributor license agreements. Licensed under the Elastic License
23
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
24
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
25
+ * Side Public License, v 1.
26
+ */
27
+ /**
28
+ * Parent context + EuiDroppable wrapper
29
+ */
30
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
31
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
32
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
33
+ function _EMOTION_STRINGIFIED_CSS_ERROR__() { return "You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."; }
34
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
35
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
36
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
37
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
38
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
39
+ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], t.indexOf(o) >= 0 || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
40
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
41
+ var DroppableColumns = exports.DroppableColumns = /*#__PURE__*/(0, _react.memo)(function (_ref) {
42
+ var columns = _ref.columns,
43
+ switchColumnPos = _ref.switchColumnPos,
44
+ indexOffset = _ref.indexOffset,
45
+ children = _ref.children;
46
+ var styles = (0, _services.useEuiMemoizedStyles)(_draggable_columns.euiDataGridDraggableHeaderStyles);
47
+ var droppableId = (0, _services.useGeneratedHtmlId)({
48
+ prefix: 'euiDataGridHeaderDroppable'
49
+ });
50
+ var _useContext = (0, _react.useContext)(_focus.DataGridFocusContext),
51
+ setFocusedCell = _useContext.setFocusedCell;
52
+ var handleOnDragEnd = (0, _react.useCallback)(function (_ref2) {
53
+ var source = _ref2.source,
54
+ destination = _ref2.destination;
55
+ if (!source) return;
56
+ if (destination && destination.index !== source.index) {
57
+ var sourceColumn = columns[source.index - indexOffset];
58
+ var destinationColumn = columns[destination.index - indexOffset];
59
+ if (sourceColumn && destinationColumn) {
60
+ switchColumnPos(sourceColumn.id, destinationColumn.id);
61
+ }
62
+ }
63
+ // Force focus the cell to prevent the datagrid body from become unfocusable, including on drag cancel
64
+ setTimeout(function () {
65
+ var cellToFocus = destination ? destination.index : source.index;
66
+ setFocusedCell([cellToFocus, -1], true);
67
+ });
68
+ }, [columns, indexOffset, switchColumnPos, setFocusedCell]);
69
+ return (0, _react2.jsx)(_drag_and_drop.EuiDragDropContext, {
70
+ onDragEnd: handleOnDragEnd
71
+ }, (0, _react2.jsx)(_drag_and_drop.EuiDroppable, {
72
+ droppableId: droppableId,
73
+ direction: "horizontal",
74
+ ignoreContainerClipping: true,
75
+ css: styles.euiDataGridHeaderDroppable,
76
+ "data-test-subj": "euiDataGridHeaderDroppable"
77
+ }, children));
78
+ });
79
+ DroppableColumns.propTypes = {
80
+ indexOffset: _propTypes.default.number.isRequired,
81
+ children: _propTypes.default.oneOfType([_propTypes.default.element.isRequired, _propTypes.default.arrayOf(_propTypes.default.element.isRequired).isRequired, _propTypes.default.any.isRequired]).isRequired
82
+ };
83
+ DroppableColumns.displayName = 'DroppableColumns';
84
+
85
+ /**
86
+ * Individual EuiDraggable columns
87
+ */
88
+ var DraggableColumn = exports.DraggableColumn = /*#__PURE__*/(0, _react.memo)(function (_ref3) {
89
+ var id = _ref3.id,
90
+ index = _ref3.index,
91
+ gridStyles = _ref3.gridStyles,
92
+ columnResizer = _ref3.columnResizer,
93
+ actionsPopoverToggle = _ref3.actionsPopoverToggle,
94
+ children = _ref3.children;
95
+ var dataGridStyles = (0, _services.useEuiMemoizedStyles)(_data_grid.euiDataGridStyles);
96
+ var styles = (0, _services.useEuiMemoizedStyles)(_draggable_columns.euiDataGridDraggableHeaderStyles);
97
+ // Manually re-apply background and border overrides, since
98
+ // the droppable zone sets its own and confuses :first-of-type CSS
99
+ var reapplyCellStyles = [styles[gridStyles.header], index !== 0 && styles.noLeadingBorder];
100
+
101
+ // Draggable prevents the cell from receiving focus on click.
102
+ // We manually ensure focus is set on cell mouseDown which
103
+ // also includes setting focus before dragging
104
+ var _useContext2 = (0, _react.useContext)(_focus.DataGridFocusContext),
105
+ setFocusedCell = _useContext2.setFocusedCell;
106
+ var handleOnMouseDown = (0, _react.useCallback)(function (e) {
107
+ var openFocusTrap = document.querySelector('[data-focus-lock-disabled="false"]');
108
+ if (!!openFocusTrap &&
109
+ // If a focus trap is open somewhere on the page
110
+ !openFocusTrap.contains(e.target) &&
111
+ // & the focus trap doesn't belong to this header
112
+ e.target !== actionsPopoverToggle // & we're not closing the actions popover toggle
113
+ ) {
114
+ // Trick the focus trap lib into registering an outside click -
115
+ // the drag/drop lib otherwise otherwise prevents the event 💀
116
+ document.dispatchEvent(new MouseEvent('mousedown'));
117
+ }
118
+ setTimeout(function () {
119
+ setFocusedCell([index, -1], true);
120
+ });
121
+ }, [setFocusedCell, index, actionsPopoverToggle]);
122
+
123
+ // Prevent any other keypresses when dragging
124
+ var isDraggingRef = (0, _react.useRef)(false);
125
+ var handleOnKeydown = (0, _react.useCallback)(function (e) {
126
+ if (isDraggingRef.current) {
127
+ e.preventDefault();
128
+ e.stopPropagation();
129
+ return false;
130
+ }
131
+ }, []);
132
+
133
+ // UX polish: add a slight animation frame delay to the dragging ref end
134
+ // which prevents re-running the hover animation of column header actions
135
+ var updateDraggingRef = (0, _react.useCallback)(function (isDragging) {
136
+ // Only update if the state has changed from before
137
+ if (isDragging !== isDraggingRef.current) {
138
+ if (!isDragging) {
139
+ requestAnimationFrame(function () {
140
+ isDraggingRef.current = false;
141
+ });
142
+ } else {
143
+ isDraggingRef.current = true;
144
+ }
145
+ }
146
+ }, []);
147
+ return (0, _react2.jsx)("div", {
148
+ css: styles.euiDataGridHeaderCellDraggableWrapper,
149
+ onMouseDown: handleOnMouseDown,
150
+ onKeyDownCapture: handleOnKeydown
151
+ }, columnResizer, (0, _react2.jsx)(_drag_and_drop.EuiDraggable, {
152
+ draggableId: id,
153
+ className: "euiDataGridHeaderCellDraggable",
154
+ css: styles.euiDataGridHeaderCellDraggable,
155
+ index: index,
156
+ customDragHandle: "custom",
157
+ hasInteractiveChildren: true,
158
+ usePortal: true
159
+ }, function (_ref4, _ref5) {
160
+ var dragHandleProps = _ref4.dragHandleProps;
161
+ var isDragging = _ref5.isDragging,
162
+ mode = _ref5.mode;
163
+ updateDraggingRef(isDragging);
164
+ var _ref6 = dragHandleProps !== null && dragHandleProps !== void 0 ? dragHandleProps : {},
165
+ role = _ref6.role,
166
+ tabIndex = _ref6.tabIndex,
167
+ restDragHandleProps = _objectWithoutProperties(_ref6, _excluded);
168
+ var passedProps = _objectSpread(_objectSpread({}, restDragHandleProps), {}, {
169
+ css: reapplyCellStyles,
170
+ 'data-column-moving': isDraggingRef.current || undefined,
171
+ isDragging: isDragging
172
+ });
173
+
174
+ // since the cloned content is in a portal outside the datagrid
175
+ // we need to re-add styles to the cell as the scoped styles
176
+ // from the wrapper don't apply
177
+ var draggingStyles = [styles.euiDataGridHeaderCellDraggable,
178
+ // ensure height is maintained while dragging
179
+ dataGridStyles.cellPadding[gridStyles.cellPadding], dataGridStyles.fontSize[gridStyles.fontSize], dataGridStyles.borders[gridStyles.border], mode === 'SNAP' && styles.isKeyboardDragging];
180
+ return isDragging ? (0, _react2.jsx)("div", {
181
+ css: draggingStyles
182
+ }, (0, _react2.jsx)(DragOverlay, {
183
+ isDragging: true,
184
+ cursor: "grabbing"
185
+ }), children(passedProps)) : children(passedProps);
186
+ }));
187
+ });
188
+ DraggableColumn.propTypes = {
189
+ id: _propTypes.default.string.isRequired,
190
+ index: _propTypes.default.number.isRequired,
191
+ gridStyles: _propTypes.default.shape({
192
+ /**
193
+ * Size of fonts used within the row and column cells
194
+ * @default m
195
+ */
196
+ fontSize: _propTypes.default.oneOf(["s", "m", "l"]),
197
+ /**
198
+ * Defines the padding with the row and column cells
199
+ * @default m
200
+ */
201
+ cellPadding: _propTypes.default.oneOf(["s", "m", "l"]),
202
+ /**
203
+ * Border used for the row and column cells
204
+ * @default all
205
+ */
206
+ border: _propTypes.default.oneOf(["all", "horizontal", "none"]),
207
+ /**
208
+ * If set to true, rows will alternate zebra striping for clarity
209
+ * @default false
210
+ */
211
+ stripes: _propTypes.default.bool,
212
+ /**
213
+ * Visual style for the column headers. Recommendation is to use the `underline` style in times when #EuiDataGrid `toolbarVisibility` is set to `false`.
214
+ * @default shade
215
+ */
216
+ header: _propTypes.default.oneOf(["shade", "underline"]),
217
+ /**
218
+ * Visual style for the column footers.
219
+ * @default overline
220
+ */
221
+ footer: _propTypes.default.oneOf(["shade", "overline", "striped"]),
222
+ /**
223
+ * If set to true, the footer row will be sticky
224
+ * @default true
225
+ */
226
+ stickyFooter: _propTypes.default.bool,
227
+ /**
228
+ * Will define what visual style to show on row hover
229
+ * @default hover
230
+ */
231
+ rowHover: _propTypes.default.oneOf(["highlight", "none"]),
232
+ /**
233
+ * Optionally pass custom classes to highlight or customize certain rows
234
+ */
235
+ rowClasses: _propTypes.default.shape({}),
236
+ /**
237
+ * Optional callback returning the current `gridStyle` config when changes occur from user input (e.g. toolbar display controls).
238
+ * Can be used for, e.g. storing user `gridStyle` in a local storage object.
239
+ */
240
+ onChange: _propTypes.default.func
241
+ }).isRequired,
242
+ columnResizer: _propTypes.default.node,
243
+ actionsPopoverToggle: _propTypes.default.oneOfType([_propTypes.default.any.isRequired, _propTypes.default.oneOf([null])]),
244
+ children: _propTypes.default.func.isRequired
245
+ };
246
+ DraggableColumn.displayName = 'DraggableColumn';
247
+
248
+ /**
249
+ * Components for conditionally rendering drag/drop wrappers
250
+ * Allows us to conditionally call hooks while not instantiating a bunch
251
+ * of extra state/etc., since draggable columns isn't yet(?) a default
252
+ */
253
+
254
+ var ConditionalDroppableColumns = exports.ConditionalDroppableColumns = /*#__PURE__*/(0, _react.memo)(function (_ref7) {
255
+ var canDragAndDropColumns = _ref7.canDragAndDropColumns,
256
+ children = _ref7.children,
257
+ rest = _objectWithoutProperties(_ref7, _excluded2);
258
+ return canDragAndDropColumns ? (0, _react2.jsx)(DroppableColumns, rest, children) : (0, _react2.jsx)(_react.default.Fragment, null, children);
259
+ });
260
+ ConditionalDroppableColumns.propTypes = {
261
+ canDragAndDropColumns: _propTypes.default.bool.isRequired
262
+ };
263
+ ConditionalDroppableColumns.displayName = 'ConditionalDroppableColumns';
264
+ var ConditionalDraggableColumn = exports.ConditionalDraggableColumn = /*#__PURE__*/(0, _react.memo)(function (_ref8) {
265
+ var canDragAndDropColumns = _ref8.canDragAndDropColumns,
266
+ children = _ref8.children,
267
+ rest = _objectWithoutProperties(_ref8, _excluded3);
268
+ return canDragAndDropColumns ? (0, _react2.jsx)(DraggableColumn, rest, children) : (0, _react2.jsx)(_react.default.Fragment, null, children());
269
+ });
270
+ ConditionalDraggableColumn.propTypes = {
271
+ canDragAndDropColumns: _propTypes.default.bool.isRequired
272
+ };
273
+ ConditionalDraggableColumn.displayName = 'ConditionalDraggableColumn';
274
+
275
+ /**
276
+ * Creates an invisible overlay that prevents hover interactions/transitions
277
+ * on other elements that the dragged element is dragged over, and also maintains
278
+ * the intended drag cursor over any location.
279
+ *
280
+ * TODO: If this is useful elsewhere, consider moving it to `src/services`
281
+ */
282
+ var _ref10 = process.env.NODE_ENV === "production" ? {
283
+ name: "q8wbl-DragOverlay",
284
+ styles: "position:fixed;inset:0;label:DragOverlay;"
285
+ } : {
286
+ name: "q8wbl-DragOverlay",
287
+ styles: "position:fixed;inset:0;label:DragOverlay;",
288
+ toString: _EMOTION_STRINGIFIED_CSS_ERROR__
289
+ };
290
+ var DragOverlay = exports.DragOverlay = /*#__PURE__*/(0, _react.memo)(function (_ref9) {
291
+ var isDragging = _ref9.isDragging,
292
+ cursor = _ref9.cursor,
293
+ _ref9$zIndex = _ref9.zIndex,
294
+ zIndex = _ref9$zIndex === void 0 ? 9999 : _ref9$zIndex;
295
+ return isDragging ? (0, _react2.jsx)(_portal.EuiPortal, null, (0, _react2.jsx)("div", {
296
+ css: _ref10,
297
+ style: {
298
+ cursor: cursor,
299
+ zIndex: zIndex
300
+ }
301
+ })) : null;
302
+ });
303
+ DragOverlay.propTypes = {
304
+ isDragging: _propTypes.default.bool,
305
+ cursor: _propTypes.default.any,
306
+ zIndex: _propTypes.default.any
307
+ };
308
+ DragOverlay.displayName = 'DragOverlay';
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.euiDataGridDraggableHeaderStyles = void 0;
7
+ var _react = require("@emotion/react");
8
+ var _global_styling = require("../../../../global_styling");
9
+ var _templateObject;
10
+ function _taggedTemplateLiteral(e, t) { return t || (t = e.slice(0)), Object.freeze(Object.defineProperties(e, { raw: { value: Object.freeze(t) } })); }
11
+ function _EMOTION_STRINGIFIED_CSS_ERROR__() { return "You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."; } /*
12
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
13
+ * or more contributor license agreements. Licensed under the Elastic License
14
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
15
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
16
+ * Side Public License, v 1.
17
+ */
18
+ var _ref = process.env.NODE_ENV === "production" ? {
19
+ name: "pfqu74-euiDataGridHeaderDroppable",
20
+ styles: "display:flex;label:euiDataGridHeaderDroppable;"
21
+ } : {
22
+ name: "pfqu74-euiDataGridHeaderDroppable",
23
+ styles: "display:flex;label:euiDataGridHeaderDroppable;",
24
+ toString: _EMOTION_STRINGIFIED_CSS_ERROR__
25
+ };
26
+ var euiDataGridDraggableHeaderStyles = exports.euiDataGridDraggableHeaderStyles = function euiDataGridDraggableHeaderStyles(_ref2) {
27
+ var euiTheme = _ref2.euiTheme;
28
+ return {
29
+ euiDataGridHeaderDroppable: _ref,
30
+ // The resizer must be positioned outside the draggable component to ensure both work independently
31
+ euiDataGridHeaderCellDraggableWrapper: /*#__PURE__*/(0, _react.css)("position:relative;.euiDataGridColumnResizer::after{", (0, _global_styling.logicalCSS)('margin-left', "-".concat(euiTheme.border.width.thick)), ";};label:euiDataGridHeaderCellDraggableWrapper;"),
32
+ // override internal styling from @hello-pangea/dnd to ensure positioning
33
+ euiDataGridHeaderCellDraggable: /*#__PURE__*/(0, _react.css)("display:flex;", (0, _global_styling.logicalCSS)('height', '100%'), ";;label:euiDataGridHeaderCellDraggable;"),
34
+ // Add more visual affordance to keyboard drags (raises cell slightly to show green droppable bg)
35
+ // Using animation as transition doesn't seem to work (a tale as old as EuiDataGrid...)
36
+ isKeyboardDragging: /*#__PURE__*/(0, _react.css)("animation-name:", (0, _react.keyframes)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n from { transform: translateY(0); }\n to { transform: translateY(-", "); }\n "])), euiTheme.size.s), ";animation-iteration-count:1;animation-fill-mode:forwards;", _global_styling.euiCanAnimate, "{animation-duration:", euiTheme.animation.fast, ";};label:isKeyboardDragging;"),
37
+ // Ensure correct cell background colors on drag
38
+ underline: /*#__PURE__*/(0, _react.css)("background-color:", euiTheme.colors.emptyShade, ";;label:underline;"),
39
+ shade: /*#__PURE__*/(0, _react.css)("background-color:", euiTheme.colors.lightestShade, ";;label:shade;"),
40
+ noLeadingBorder: /*#__PURE__*/(0, _react.css)((0, _global_styling.logicalCSS)('border-left', 'none !important'), ";;label:noLeadingBorder;")
41
+ };
42
+ };
@@ -410,7 +410,8 @@ var EuiDataGrid = exports.EuiDataGrid = /*#__PURE__*/(0, _react.memo)( /*#__PURE
410
410
  gridRef: gridRef,
411
411
  gridItemsRendered: gridItemsRendered,
412
412
  wrapperRef: contentRef,
413
- renderCustomGridBody: renderCustomGridBody
413
+ renderCustomGridBody: renderCustomGridBody,
414
+ canDragAndDropColumns: columnVisibility.canDragAndDropColumns
414
415
  }))), showPagination && props['aria-labelledby'] && (0, _react2.jsx)("p", {
415
416
  id: ariaLabelledById,
416
417
  hidden: true
@@ -122,9 +122,6 @@ var columns = [{
122
122
  "aria-label": "Send email to ".concat(value)
123
123
  }, "Send email");
124
124
  }]
125
- }, {
126
- id: 'location',
127
- displayAsText: 'Location'
128
125
  }, {
129
126
  id: 'account',
130
127
  displayAsText: 'Account',
@@ -159,6 +156,9 @@ var columns = [{
159
156
  "aria-label": "Send money to ".concat(value)
160
157
  }, "Send money");
161
158
  }]
159
+ }, {
160
+ id: 'location',
161
+ displayAsText: 'Location'
162
162
  }, {
163
163
  id: 'date',
164
164
  displayAsText: 'Date',
@@ -239,7 +239,8 @@ var defaultStorybookArgs = exports.defaultStorybookArgs = {
239
239
  // setup for easier testing/QA
240
240
  columnVisibility: {
241
241
  visibleColumns: ['name', 'email', 'account', 'location', 'date', 'amount', 'phone', 'version'],
242
- setVisibleColumns: function setVisibleColumns() {}
242
+ setVisibleColumns: function setVisibleColumns() {},
243
+ canDragAndDropColumns: false
243
244
  },
244
245
  inMemory: {
245
246
  level: 'sorting'
@@ -350,7 +351,8 @@ var StatefulDataGrid = exports.StatefulDataGrid = function StatefulDataGrid(prop
350
351
  return (0, _react2.jsx)(_data_grid.EuiDataGrid, _extends({}, rest, {
351
352
  columnVisibility: {
352
353
  visibleColumns: visibleColumns,
353
- setVisibleColumns: setVisibleColumns
354
+ setVisibleColumns: setVisibleColumns,
355
+ canDragAndDropColumns: columnVisibility.canDragAndDropColumns
354
356
  },
355
357
  sorting: {
356
358
  columns: sortingColumns,
@@ -859,7 +861,8 @@ EuiDataGridToolbarPropsComponent.propTypes = {
859
861
  /**
860
862
  * A callback for when a column's visibility or order is modified by the user.
861
863
  */
862
- setVisibleColumns: _propTypes.default.func.isRequired
864
+ setVisibleColumns: _propTypes.default.func.isRequired,
865
+ /** Enables reordering grid columns on drag and drop via the headers cells */canDragAndDropColumns: _propTypes.default.bool
863
866
  }).isRequired,
864
867
  /**
865
868
  * An array of custom #EuiDataGridSchemaDetector objects. You can inject custom schemas to the grid to define the classnames applied.
@@ -61,31 +61,35 @@ var useColumnWidths = exports.useColumnWidths = function useColumnWidths(_ref) {
61
61
  trailingControlColumns = _ref.trailingControlColumns,
62
62
  defaultColumnWidth = _ref.defaultColumnWidth,
63
63
  onColumnResize = _ref.onColumnResize;
64
- var computeColumnWidths = (0, _react.useCallback)(function () {
65
- return columns.filter(doesColumnHaveAnInitialWidth).reduce(function (initialWidths, column) {
66
- return _objectSpread(_objectSpread({}, initialWidths), {}, _defineProperty({}, column.id, column.initialWidth));
67
- }, {});
64
+ var getInitialWidths = (0, _react.useCallback)(function (prevColumnWidths) {
65
+ var columnWidths = _objectSpread({}, prevColumnWidths);
66
+ columns.filter(doesColumnHaveAnInitialWidth).forEach(function (_ref2) {
67
+ var id = _ref2.id,
68
+ initialWidth = _ref2.initialWidth;
69
+ if (columnWidths[id] == null) {
70
+ columnWidths[id] = initialWidth;
71
+ }
72
+ });
73
+ return columnWidths;
68
74
  }, [columns]);
69
75
 
70
76
  // Passes initializer function for performance, so computing only runs once on init
71
77
  // @see https://react.dev/reference/react/useState#examples-initializer
72
- var _useState = (0, _react.useState)(computeColumnWidths),
78
+ var _useState = (0, _react.useState)(getInitialWidths),
73
79
  _useState2 = _slicedToArray(_useState, 2),
74
80
  columnWidths = _useState2[0],
75
81
  setColumnWidths = _useState2[1];
76
82
  (0, _services.useUpdateEffect)(function () {
77
- setColumnWidths(computeColumnWidths());
78
- }, [computeColumnWidths]);
83
+ setColumnWidths(getInitialWidths);
84
+ }, [columns]);
79
85
  var setColumnWidth = (0, _react.useCallback)(function (columnId, width) {
80
86
  setColumnWidths(function (prevColumnWidths) {
81
87
  return _objectSpread(_objectSpread({}, prevColumnWidths), {}, _defineProperty({}, columnId, width));
82
88
  });
83
- if (onColumnResize) {
84
- onColumnResize({
85
- columnId: columnId,
86
- width: width
87
- });
88
- }
89
+ onColumnResize === null || onColumnResize === void 0 || onColumnResize({
90
+ columnId: columnId,
91
+ width: width
92
+ });
89
93
  }, [onColumnResize]);
90
94
 
91
95
  // Used by react-window to determine actual column widths
@@ -51,11 +51,11 @@ var useFocus = exports.useFocus = function useFocus() {
51
51
  _useState4 = _slicedToArray(_useState3, 2),
52
52
  focusedCell = _useState4[0],
53
53
  _setFocusedCell = _useState4[1];
54
- var setFocusedCell = (0, _react.useCallback)(function (nextFocusedCell) {
54
+ var setFocusedCell = (0, _react.useCallback)(function (nextFocusedCell, forceUpdate) {
55
55
  _setFocusedCell(function (prevFocusedCell) {
56
56
  // If the x/y coordinates remained the same, don't update. This keeps the focusedCell
57
57
  // reference stable, and allows it to be used in places that need reference equality.
58
- if (nextFocusedCell[0] === (prevFocusedCell === null || prevFocusedCell === void 0 ? void 0 : prevFocusedCell[0]) && nextFocusedCell[1] === (prevFocusedCell === null || prevFocusedCell === void 0 ? void 0 : prevFocusedCell[1])) {
58
+ if (!forceUpdate && nextFocusedCell[0] === (prevFocusedCell === null || prevFocusedCell === void 0 ? void 0 : prevFocusedCell[0]) && nextFocusedCell[1] === (prevFocusedCell === null || prevFocusedCell === void 0 ? void 0 : prevFocusedCell[1])) {
59
59
  return prevFocusedCell;
60
60
  } else {
61
61
  setIsFocusedCellInView(true); // scrolling.ts ensures focused cells are fully in view
@@ -69,7 +69,8 @@ var useScrollCellIntoView = exports.useScrollCellIntoView = function useScrollCe
69
69
  headerRowHeight = _ref.headerRowHeight,
70
70
  footerRowHeight = _ref.footerRowHeight,
71
71
  visibleRowCount = _ref.visibleRowCount,
72
- hasStickyFooter = _ref.hasStickyFooter;
72
+ hasStickyFooter = _ref.hasStickyFooter,
73
+ canDragAndDropColumns = _ref.canDragAndDropColumns;
73
74
  var scrollCellIntoView = (0, _react.useCallback)(
74
75
  /*#__PURE__*/
75
76
  // Note: in order for this UX to work correctly with react-window's APIs,
@@ -78,7 +79,7 @@ var useScrollCellIntoView = exports.useScrollCellIntoView = function useScrollCe
78
79
  function () {
79
80
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref2) {
80
81
  var _adjustedScrollLeft;
81
- var rowIndex, colIndex, getCell, cell, cellIsInView, _outerGridRef$current, scrollTop, scrollLeft, adjustedScrollTop, adjustedScrollLeft, cellRightPos, rightScrollBound, rightWidthOutOfView, cellLeftPos, leftScrollBound, leftWidthOutOfView, isStickyHeader, isStickyFooter, _adjustedScrollTop, parentRow, cellBottomPos, bottomScrollBound, bottomHeightOutOfView, cellTopPos, topScrollBound, topHeightOutOfView, _adjustedScrollLeft2, _adjustedScrollTop2;
82
+ var rowIndex, colIndex, getCell, cell, cellIsInView, isStickyHeader, isStickyFooter, isDraggableHeader, isDraggableHeaderCell, _outerGridRef$current, scrollTop, scrollLeft, adjustedScrollTop, adjustedScrollLeft, cellLeftPos, cellRightPos, rightScrollBound, rightWidthOutOfView, leftScrollBound, leftWidthOutOfView, _adjustedScrollTop, parentRow, cellBottomPos, bottomScrollBound, bottomHeightOutOfView, cellTopPos, topScrollBound, topHeightOutOfView, _adjustedScrollLeft2, _adjustedScrollTop2;
82
83
  return _regeneratorRuntime().wrap(function _callee$(_context) {
83
84
  while (1) switch (_context.prev = _context.next) {
84
85
  case 0:
@@ -125,7 +126,10 @@ var useScrollCellIntoView = exports.useScrollCellIntoView = function useScrollCe
125
126
  return _context.abrupt("return");
126
127
  case 15:
127
128
  // If for some reason we can't find a valid cell, short-circuit
128
- // We now manually adjust scroll positioning around the cell to ensure it's
129
+ isStickyHeader = rowIndex === -1;
130
+ isStickyFooter = hasStickyFooter && rowIndex === visibleRowCount;
131
+ isDraggableHeader = canDragAndDropColumns && isStickyHeader;
132
+ isDraggableHeaderCell = isDraggableHeader && cell.offsetLeft === 0 && colIndex !== 0; // We now manually adjust scroll positioning around the cell to ensure it's
129
133
  // fully in view on all sides. A couple of notes on this:
130
134
  // 1. We're avoiding relying on react-window's scrollToItem for this because it also
131
135
  // does not account for sticky items (see https://github.com/bvaughn/react-window/issues/586)
@@ -134,8 +138,10 @@ var useScrollCellIntoView = exports.useScrollCellIntoView = function useScrollCe
134
138
  // halfway there, but doesn't guarantee the *full* cell in view, or account for
135
139
  // sticky positioned rows or OS scrollbars, hence these workarounds
136
140
  _outerGridRef$current = outerGridRef.current, scrollTop = _outerGridRef$current.scrollTop, scrollLeft = _outerGridRef$current.scrollLeft;
137
- // Check if the cell's right side is outside the current scrolling bounds
138
- cellRightPos = cell.offsetLeft + cell.offsetWidth;
141
+ // Draggable header columns are nested within EuiDraggables,
142
+ // and their offsetLeft needs to go up a wrapper as a result
143
+ cellLeftPos = isDraggableHeaderCell ? cell.offsetParent.offsetLeft : cell.offsetLeft; // Check if the cell's right side is outside the current scrolling bounds
144
+ cellRightPos = cellLeftPos + cell.offsetWidth;
139
145
  rightScrollBound = scrollLeft + outerGridRef.current.clientWidth; // Note: We specifically want clientWidth and not offsetWidth here to account for scrollbars
140
146
  rightWidthOutOfView = cellRightPos - rightScrollBound;
141
147
  if (rightWidthOutOfView > 0) {
@@ -143,7 +149,6 @@ var useScrollCellIntoView = exports.useScrollCellIntoView = function useScrollCe
143
149
  }
144
150
 
145
151
  // Check if the cell's left side is outside the current scrolling bounds
146
- cellLeftPos = cell.offsetLeft;
147
152
  leftScrollBound = (_adjustedScrollLeft = adjustedScrollLeft) !== null && _adjustedScrollLeft !== void 0 ? _adjustedScrollLeft : scrollLeft;
148
153
  leftWidthOutOfView = leftScrollBound - cellLeftPos;
149
154
  if (leftWidthOutOfView > 0) {
@@ -154,8 +159,6 @@ var useScrollCellIntoView = exports.useScrollCellIntoView = function useScrollCe
154
159
 
155
160
  // Skip top/bottom scroll adjustments for sticky headers & footers
156
161
  // since they should always be in view vertically
157
- isStickyHeader = rowIndex === -1;
158
- isStickyFooter = hasStickyFooter && rowIndex === visibleRowCount;
159
162
  if (!isStickyHeader && !isStickyFooter) {
160
163
  parentRow = cell.parentNode; // Check if the cell's bottom side is outside the current scrolling bounds
161
164
  cellBottomPos = parentRow.offsetTop + cell.offsetHeight;
@@ -185,7 +188,7 @@ var useScrollCellIntoView = exports.useScrollCellIntoView = function useScrollCe
185
188
  scrollTop: (_adjustedScrollTop2 = adjustedScrollTop) !== null && _adjustedScrollTop2 !== void 0 ? _adjustedScrollTop2 : scrollTop
186
189
  });
187
190
  }
188
- case 28:
191
+ case 30:
189
192
  case "end":
190
193
  return _context.stop();
191
194
  }
@@ -194,7 +197,7 @@ var useScrollCellIntoView = exports.useScrollCellIntoView = function useScrollCe
194
197
  return function (_x) {
195
198
  return _ref3.apply(this, arguments);
196
199
  };
197
- }(), [gridRef, outerGridRef, hasGridScrolling, headerRowHeight, footerRowHeight, visibleRowCount, hasStickyFooter]);
200
+ }(), [gridRef, outerGridRef, hasGridScrolling, headerRowHeight, footerRowHeight, visibleRowCount, hasStickyFooter, canDragAndDropColumns]);
198
201
  return {
199
202
  scrollCellIntoView: scrollCellIntoView
200
203
  };
@@ -58,6 +58,7 @@ var EuiDraggable = exports.EuiDraggable = function EuiDraggable(_ref) {
58
58
  cloneItems = _useContext.cloneItems;
59
59
  var euiTheme = (0, _services.useEuiTheme)();
60
60
  var styles = (0, _draggable.euiDraggableStyles)(euiTheme);
61
+ var hasCustomDragHandle = customDragHandle !== false;
61
62
  return (0, _react2.jsx)(_dnd.Draggable, _extends({
62
63
  draggableId: draggableId,
63
64
  index: index,
@@ -65,13 +66,14 @@ var EuiDraggable = exports.EuiDraggable = function EuiDraggable(_ref) {
65
66
  }, rest), function (provided, snapshot, rubric) {
66
67
  var _provided$dragHandleP, _provided$dragHandleP2;
67
68
  var isDragging = snapshot.isDragging;
69
+ var isFullyCustomDragHandle = customDragHandle === 'custom';
68
70
  var cssStyles = [styles.euiDraggable, cloneItems && !isDragging && styles.hasClone, isDragging && styles.isDragging, isRemovable && styles.isRemovable, styles.spacing[spacing]];
69
71
  var classes = (0, _classnames.default)('euiDraggable', className);
70
72
  var childClasses = (0, _classnames.default)('euiDraggable__item', {
71
73
  'euiDraggable__item-isDisabled': isDragDisabled
72
74
  });
73
75
  var DraggableElement = typeof children === 'function' ? children(provided, snapshot, rubric) : children;
74
- var content = (0, _react2.jsx)(_react.default.Fragment, null, (0, _react2.jsx)("div", _extends({}, provided.draggableProps, !customDragHandle ? provided.dragHandleProps : {}, {
76
+ var content = (0, _react2.jsx)(_react.default.Fragment, null, (0, _react2.jsx)("div", _extends({}, provided.draggableProps, !hasCustomDragHandle ? provided.dragHandleProps : {}, {
75
77
  ref: provided.innerRef,
76
78
  "data-test-subj": dataTestSubj,
77
79
  className: classes,
@@ -81,11 +83,14 @@ var EuiDraggable = exports.EuiDraggable = function EuiDraggable(_ref) {
81
83
  // interactive element. Screen readers will cue users that this is a container
82
84
  // and has one or more elements inside that are part of a related group.
83
85
  ,
84
- role: hasInteractiveChildren ? 'group' : (_provided$dragHandleP = provided.dragHandleProps) === null || _provided$dragHandleP === void 0 ? void 0 : _provided$dragHandleP.role
86
+ role: isFullyCustomDragHandle ? undefined // prevent wrapper role from removing semantics of the children
87
+ : hasInteractiveChildren ? 'group' : (_provided$dragHandleP = provided.dragHandleProps) === null || _provided$dragHandleP === void 0 ? void 0 : _provided$dragHandleP.role
85
88
  // If the container includes an interactive element, we remove the tabindex=0
86
89
  // because [role="group"] does not permit or warrant a tab stop
90
+ // additionally we remove the tabindex when the child is a fully custom handle
91
+ // that has its own tabindex and handle props
87
92
  ,
88
- tabIndex: hasInteractiveChildren ? undefined : (_provided$dragHandleP2 = provided.dragHandleProps) === null || _provided$dragHandleP2 === void 0 ? void 0 : _provided$dragHandleP2.tabIndex
93
+ tabIndex: hasInteractiveChildren || isFullyCustomDragHandle ? undefined : (_provided$dragHandleP2 = provided.dragHandleProps) === null || _provided$dragHandleP2 === void 0 ? void 0 : _provided$dragHandleP2.tabIndex
89
94
  }), (0, _services.cloneElementWithCss)(DraggableElement, {
90
95
  className: (0, _classnames.default)(DraggableElement.props.className, childClasses),
91
96
  css: [_draggable.euiDraggableItemStyles.euiDraggable__item, isDragDisabled && _draggable.euiDraggableItemStyles.disabled]
@@ -103,9 +108,12 @@ EuiDraggable.propTypes = {
103
108
  children: _propTypes.default.oneOfType([_propTypes.default.element.isRequired, _propTypes.default.any.isRequired]).isRequired,
104
109
  className: _propTypes.default.string,
105
110
  /**
106
- * Whether the `children` will provide and set up its own drag handle
111
+ * Whether the `children` will provide and set up its own drag handle.
112
+ * The `custom` value additionally removes the `role` from the draggable container.
113
+ * Use this if the `children` element is focusable and should keep its
114
+ * semantic role for accessibility purposes.
107
115
  */
108
- customDragHandle: _propTypes.default.bool,
116
+ customDragHandle: _propTypes.default.oneOfType([_propTypes.default.bool.isRequired, _propTypes.default.oneOf(["custom"])]),
109
117
  /**
110
118
  * Whether the container has interactive children and should have `role="group"` instead of `"button"`.
111
119
  * Setting this flag ensures your drag & drop container is keyboard and screen reader accessible.