@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,134 @@
1
+ /*
2
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ * or more contributor license agreements. Licensed under the Elastic License
4
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
5
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
6
+ * Side Public License, v 1.
7
+ */
8
+
9
+ import React, { useMemo } from 'react';
10
+ import { useGeneratedHtmlId } from '../../../../services';
11
+ // Keep the i18n scope the same as EuiDataGridHeaderCell
12
+ /* eslint-disable local/i18n */
13
+ import { EuiI18n } from '../../../i18n';
14
+ import { EuiIcon } from '../../../icon';
15
+ import { jsx as ___EmotionJSX } from "@emotion/react";
16
+ /**
17
+ * Column sorting utility helpers
18
+ */
19
+ export var useColumnSorting = function useColumnSorting(_ref) {
20
+ var _sorting$columns;
21
+ var sorting = _ref.sorting,
22
+ id = _ref.id,
23
+ hasColumnActions = _ref.hasColumnActions;
24
+ var sortedColumn = useMemo(function () {
25
+ return sorting === null || sorting === void 0 ? void 0 : sorting.columns.find(function (col) {
26
+ return col.id === id;
27
+ });
28
+ }, [sorting, id]);
29
+ var isColumnSorted = !!sortedColumn;
30
+ var hasOnlyOneSort = (sorting === null || sorting === void 0 || (_sorting$columns = sorting.columns) === null || _sorting$columns === void 0 ? void 0 : _sorting$columns.length) === 1;
31
+
32
+ /**
33
+ * Arrow icon
34
+ */
35
+ var sortingArrow = useMemo(function () {
36
+ return isColumnSorted ? ___EmotionJSX(EuiIcon, {
37
+ type: sortedColumn.direction === 'asc' ? 'sortUp' : 'sortDown',
38
+ color: "text",
39
+ className: "euiDataGridHeaderCell__sortingArrow",
40
+ "data-test-subj": "dataGridHeaderCellSortingIcon-".concat(id)
41
+ }) : null;
42
+ }, [id, isColumnSorted, sortedColumn]);
43
+
44
+ /**
45
+ * aria-sort attribute - should only be used when a single column is being sorted
46
+ * @see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-sort
47
+ * @see https://www.w3.org/WAI/ARIA/apg/example-index/table/sortable-table.html
48
+ * @see https://github.com/w3c/aria/issues/283 for potential future multi-column usage
49
+ */
50
+ var ariaSort = isColumnSorted && hasOnlyOneSort ? sorting.columns[0].direction === 'asc' ? 'ascending' : 'descending' : undefined;
51
+
52
+ // aria-describedby ID for when aria-sort isn't sufficient
53
+ var sortingAriaId = useGeneratedHtmlId({
54
+ prefix: 'euiDataGridCellHeader',
55
+ suffix: 'sorting'
56
+ });
57
+
58
+ /**
59
+ * Sorting status - screen reader text
60
+ */
61
+ var sortingScreenReaderText = useMemo(function () {
62
+ var _sorting$columns2;
63
+ if (!isColumnSorted) return null;
64
+ if (!hasColumnActions && hasOnlyOneSort) return null; // in this scenario, the `aria-sort` attribute will be used by screen readers
65
+ return ___EmotionJSX("p", {
66
+ id: sortingAriaId,
67
+ hidden: true
68
+ }, sorting === null || sorting === void 0 || (_sorting$columns2 = sorting.columns) === null || _sorting$columns2 === void 0 ? void 0 : _sorting$columns2.map(function (_ref2, index) {
69
+ var columnId = _ref2.id,
70
+ direction = _ref2.direction;
71
+ if (hasOnlyOneSort) {
72
+ if (direction === 'asc') {
73
+ return ___EmotionJSX(EuiI18n, {
74
+ token: "euiDataGridHeaderCell.sortedByAscendingSingle",
75
+ default: "Sorted ascending",
76
+ key: index
77
+ });
78
+ } else {
79
+ return ___EmotionJSX(EuiI18n, {
80
+ token: "euiDataGridHeaderCell.sortedByDescendingSingle",
81
+ default: "Sorted descending",
82
+ key: index
83
+ });
84
+ }
85
+ } else if (index === 0) {
86
+ if (direction === 'asc') {
87
+ return ___EmotionJSX(EuiI18n, {
88
+ token: "euiDataGridHeaderCell.sortedByAscendingFirst",
89
+ default: "Sorted by {columnId}, ascending",
90
+ values: {
91
+ columnId: columnId
92
+ },
93
+ key: index
94
+ });
95
+ } else {
96
+ return ___EmotionJSX(EuiI18n, {
97
+ token: "euiDataGridHeaderCell.sortedByDescendingFirst",
98
+ default: "Sorted by {columnId}, descending",
99
+ values: {
100
+ columnId: columnId
101
+ },
102
+ key: index
103
+ });
104
+ }
105
+ } else {
106
+ if (direction === 'asc') {
107
+ return ___EmotionJSX(EuiI18n, {
108
+ token: "euiDataGridHeaderCell.sortedByAscendingMultiple",
109
+ default: ", then sorted by {columnId}, ascending",
110
+ values: {
111
+ columnId: columnId
112
+ },
113
+ key: index
114
+ });
115
+ } else {
116
+ return ___EmotionJSX(EuiI18n, {
117
+ token: "euiDataGridHeaderCell.sortedByDescendingMultiple",
118
+ default: ", then sorted by {columnId}, descending",
119
+ values: {
120
+ columnId: columnId
121
+ },
122
+ key: index
123
+ });
124
+ }
125
+ }
126
+ }), ".");
127
+ }, [isColumnSorted, hasColumnActions, hasOnlyOneSort, sorting, sortingAriaId]);
128
+ return {
129
+ sortingArrow: sortingArrow,
130
+ ariaSort: ariaSort,
131
+ sortingAriaId: sortingAriaId,
132
+ sortingScreenReaderText: sortingScreenReaderText
133
+ };
134
+ };
@@ -14,7 +14,7 @@ import { jsx as ___EmotionJSX } from "@emotion/react";
14
14
  export var EuiDataGridControlHeaderCell = /*#__PURE__*/memo(function (_ref) {
15
15
  var controlColumn = _ref.controlColumn,
16
16
  index = _ref.index,
17
- visibleColCount = _ref.visibleColCount;
17
+ isLastColumn = _ref.isLastColumn;
18
18
  var HeaderCellRender = controlColumn.headerCellRender,
19
19
  headerCellProps = controlColumn.headerCellProps,
20
20
  width = controlColumn.width,
@@ -24,7 +24,7 @@ export var EuiDataGridControlHeaderCell = /*#__PURE__*/memo(function (_ref) {
24
24
  id: id,
25
25
  index: index,
26
26
  width: width,
27
- visibleColCount: visibleColCount
27
+ isLastColumn: isLastColumn
28
28
  }), ___EmotionJSX(HeaderCellRender, null));
29
29
  });
30
30
  EuiDataGridControlHeaderCell.displayName = 'EuiDataGridControlHeaderCell';
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
4
  /*
5
5
  * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
6
6
  * or more contributor license agreements. Licensed under the Elastic License
@@ -10,17 +10,13 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
10
10
  */
11
11
 
12
12
  import classnames from 'classnames';
13
- import React, { useContext, useState, useRef, useCallback, useMemo, memo } from 'react';
14
- import { tabbable } from 'tabbable';
15
- import { keys, useGeneratedHtmlId, useEuiMemoizedStyles } from '../../../../services';
16
- import { EuiI18n, useEuiI18n } from '../../../i18n';
13
+ import React, { memo, useMemo, useRef, useState } from 'react';
14
+ import { useEuiMemoizedStyles } from '../../../../services';
17
15
  import { EuiIcon } from '../../../icon';
18
- import { EuiListGroup } from '../../../list_group';
19
- import { EuiPopover } from '../../../popover';
20
- import { EuiButtonIcon } from '../../../button';
21
- import { DataGridFocusContext } from '../../utils/focus';
22
- import { getColumnActions } from './column_actions';
23
- import { EuiDataGridColumnResizer } from './data_grid_column_resizer';
16
+ import { useHasColumnActions, ColumnActions } from './column_actions';
17
+ import { useColumnSorting } from './column_sorting';
18
+ import { ConditionalDraggableColumn } from './draggable_columns';
19
+ import { EuiDataGridColumnResizer } from './column_resizer';
24
20
  import { EuiDataGridHeaderCellWrapper } from './data_grid_header_cell_wrapper';
25
21
  import { euiDataGridHeaderCellStyles } from './data_grid_header_cell.styles';
26
22
  import { jsx as ___EmotionJSX } from "@emotion/react";
@@ -31,315 +27,99 @@ export var EuiDataGridHeaderCell = /*#__PURE__*/memo(function (_ref) {
31
27
  columnWidths = _ref.columnWidths,
32
28
  defaultColumnWidth = _ref.defaultColumnWidth,
33
29
  setColumnWidth = _ref.setColumnWidth,
34
- visibleColCount = _ref.visibleColCount,
35
30
  setVisibleColumns = _ref.setVisibleColumns,
36
31
  switchColumnPos = _ref.switchColumnPos,
32
+ isLastColumn = _ref.isLastColumn,
37
33
  sorting = _ref.sorting,
38
34
  schema = _ref.schema,
39
- schemaDetectors = _ref.schemaDetectors;
35
+ schemaDetectors = _ref.schemaDetectors,
36
+ canDragAndDropColumns = _ref.canDragAndDropColumns,
37
+ gridStyles = _ref.gridStyles;
40
38
  var id = column.id,
41
39
  display = column.display,
42
40
  displayAsText = column.displayAsText,
43
- displayHeaderCellProps = column.displayHeaderCellProps;
41
+ displayHeaderCellProps = column.displayHeaderCellProps,
42
+ actions = column.actions;
44
43
  var title = displayAsText || id;
45
44
  var children = display || displayAsText || id;
46
45
  var width = columnWidths[id] || defaultColumnWidth;
47
46
  var columnType = schema[id] ? schema[id].columnType : null;
48
- var _useContext = useContext(DataGridFocusContext),
49
- setFocusedCell = _useContext.setFocusedCell,
50
- focusFirstVisibleInteractiveCell = _useContext.focusFirstVisibleInteractiveCell;
47
+ var hasColumnActions = useHasColumnActions(actions);
48
+ var classes = classnames(_defineProperty(_defineProperty({}, "euiDataGridHeaderCell--".concat(columnType), columnType), 'euiDataGridHeaderCell--hasColumnActions', hasColumnActions), displayHeaderCellProps === null || displayHeaderCellProps === void 0 ? void 0 : displayHeaderCellProps.className);
49
+ var styles = useEuiMemoizedStyles(euiDataGridHeaderCellStyles);
50
+ var contentStyles = [styles.euiDataGridHeaderCell__content, (columnType === 'numeric' || columnType === 'currency') && styles.right];
51
51
 
52
- /*
53
- * Column actions
54
- */
55
- var _useState = useState(false),
52
+ // Props passed from <ColumnActions /> to be set on <EuiDataGridHeaderCellWrapper />
53
+ var _useState = useState({}),
56
54
  _useState2 = _slicedToArray(_useState, 2),
57
- isPopoverOpen = _useState2[0],
58
- setIsPopoverOpen = _useState2[1];
59
- var togglePopover = useCallback(function () {
60
- setIsPopoverOpen(function (isOpen) {
61
- return !isOpen;
62
- });
63
- }, []);
64
- var closePopover = useCallback(function () {
65
- return setIsPopoverOpen(false);
66
- }, []);
67
- var popoverArrowNavigationProps = usePopoverArrowNavigation();
68
- var columnActions = useMemo(function () {
69
- return getColumnActions({
70
- column: column,
71
- columns: columns,
72
- schema: schema,
73
- schemaDetectors: schemaDetectors,
74
- setVisibleColumns: setVisibleColumns,
75
- focusFirstVisibleInteractiveCell: focusFirstVisibleInteractiveCell,
76
- setIsPopoverOpen: setIsPopoverOpen,
77
- sorting: sorting,
78
- switchColumnPos: switchColumnPos,
79
- setFocusedCell: setFocusedCell,
80
- columnFocusIndex: index
81
- });
82
- }, [column, columns, schema, schemaDetectors, setVisibleColumns, focusFirstVisibleInteractiveCell, setIsPopoverOpen, sorting, switchColumnPos, setFocusedCell, index]);
83
- var showColumnActions = columnActions && columnActions.length > 0;
55
+ propsFromColumnActions = _useState2[0],
56
+ setPropsFromColumnActions = _useState2[1];
84
57
  var actionsButtonRef = useRef(null);
85
- var clickActionsButton = useCallback(function () {
86
- var _actionsButtonRef$cur;
87
- (_actionsButtonRef$cur = actionsButtonRef.current) === null || _actionsButtonRef$cur === void 0 || _actionsButtonRef$cur.click();
88
- }, []);
89
- var _useState3 = useState(false),
90
- _useState4 = _slicedToArray(_useState3, 2),
91
- isActionsButtonFocused = _useState4[0],
92
- setIsActionsButtonFocused = _useState4[1];
93
- var actionsButtonAriaLabel = useEuiI18n('euiDataGridHeaderCell.actionsButtonAriaLabel', '{title}. Click to view column header actions.', {
94
- title: title
95
- });
96
- var actionsEnterKeyInstructions = useEuiI18n('euiDataGridHeaderCell.actionsEnterKeyInstructions', "Press the Enter key to view this column's actions");
97
-
98
- /*
99
- * Column sorting
100
- */
101
- var _useSortingUtils = useSortingUtils({
58
+ var _useColumnSorting = useColumnSorting({
102
59
  sorting: sorting,
103
60
  id: id,
104
- showColumnActions: showColumnActions
61
+ hasColumnActions: hasColumnActions
105
62
  }),
106
- sortingArrow = _useSortingUtils.sortingArrow,
107
- ariaSort = _useSortingUtils.ariaSort,
108
- sortingScreenReaderText = _useSortingUtils.sortingScreenReaderText;
109
- var sortingAriaId = useGeneratedHtmlId({
110
- prefix: 'euiDataGridCellHeader',
111
- suffix: 'sorting'
112
- });
113
-
114
- /*
115
- * Rendering
116
- */
117
- var classes = classnames(_defineProperty(_defineProperty(_defineProperty({}, "euiDataGridHeaderCell--".concat(columnType), columnType), 'euiDataGridHeaderCell--hasColumnActions', showColumnActions), 'euiDataGridHeaderCell--isActionsPopoverOpen', isPopoverOpen), displayHeaderCellProps === null || displayHeaderCellProps === void 0 ? void 0 : displayHeaderCellProps.className);
118
- var styles = useEuiMemoizedStyles(euiDataGridHeaderCellStyles);
119
- var contentStyles = [styles.euiDataGridHeaderCell__content, (columnType === 'numeric' || columnType === 'currency') && styles.right];
120
- return ___EmotionJSX(EuiDataGridHeaderCellWrapper, _extends({}, displayHeaderCellProps, {
121
- className: classes,
122
- id: id,
123
- index: index,
124
- visibleColCount: visibleColCount,
125
- width: width,
126
- "aria-sort": ariaSort,
127
- hasActionsPopover: showColumnActions,
128
- openActionsPopover: clickActionsButton,
129
- "aria-label": displayAsText && "".concat(displayAsText, ", ") // ensure cell text content is read first, if available
130
- ,
131
- "aria-describedby": sortingAriaId
132
- }), function (hasFocusTrap) {
133
- return ___EmotionJSX(React.Fragment, null, column.isResizable !== false && width != null ? ___EmotionJSX(EuiDataGridColumnResizer, {
63
+ sortingArrow = _useColumnSorting.sortingArrow,
64
+ ariaSort = _useColumnSorting.ariaSort,
65
+ sortingAriaId = _useColumnSorting.sortingAriaId,
66
+ sortingScreenReaderText = _useColumnSorting.sortingScreenReaderText;
67
+ var columnResizer = useMemo(function () {
68
+ return column.isResizable !== false && width != null ? ___EmotionJSX(EuiDataGridColumnResizer, {
134
69
  columnId: id,
135
70
  columnWidth: width,
136
- setColumnWidth: setColumnWidth
137
- }) : null, ___EmotionJSX("div", {
138
- css: contentStyles,
139
- className: "euiDataGridHeaderCell__content",
140
- title: title
141
- }, children), sortingArrow, sortingScreenReaderText && ___EmotionJSX("p", {
142
- id: sortingAriaId,
143
- hidden: true
144
- }, sortingScreenReaderText), showColumnActions && ___EmotionJSX(EuiPopover, _extends({
145
- display: "block",
146
- panelPaddingSize: "none",
147
- offset: 7,
148
- anchorPosition: "downRight",
149
- css: styles.euiDataGridHeaderCell__popover,
150
- button: ___EmotionJSX(EuiButtonIcon, {
151
- iconType: "boxesVertical",
152
- iconSize: "s",
153
- color: "text",
154
- css: styles.euiDataGridHeaderCell__button,
155
- className: "euiDataGridHeaderCell__button",
156
- buttonRef: actionsButtonRef,
157
- onClick: togglePopover,
158
- onFocus: function onFocus() {
159
- return setIsActionsButtonFocused(true);
160
- },
161
- onBlur: function onBlur() {
162
- return setIsActionsButtonFocused(false);
163
- },
164
- tabIndex: 0 // Override EuiButtonIcon's conditional tabindex based on aria-hidden
165
- ,
166
- "aria-hidden": hasFocusTrap && !isActionsButtonFocused ? 'true' // prevent the actions button from being read on cell focus
167
- : undefined,
168
- "aria-label": hasFocusTrap ? actionsButtonAriaLabel : actionsEnterKeyInstructions,
169
- "data-test-subj": "dataGridHeaderCellActionButton-".concat(id)
170
- }),
171
- isOpen: isPopoverOpen,
172
- closePopover: closePopover
173
- }, popoverArrowNavigationProps), ___EmotionJSX(EuiListGroup, {
174
- listItems: columnActions,
175
- gutterSize: "none",
176
- "data-test-subj": "dataGridHeaderCellActionGroup-".concat(id)
177
- })));
71
+ setColumnWidth: setColumnWidth,
72
+ isLastColumn: isLastColumn
73
+ }) : null;
74
+ }, [column.isResizable, id, width, setColumnWidth, isLastColumn]);
75
+ return ___EmotionJSX(ConditionalDraggableColumn, {
76
+ id: id,
77
+ index: index,
78
+ canDragAndDropColumns: !!canDragAndDropColumns,
79
+ gridStyles: gridStyles,
80
+ columnResizer: columnResizer,
81
+ actionsPopoverToggle: actionsButtonRef.current
82
+ }, function (dragProps) {
83
+ return ___EmotionJSX(EuiDataGridHeaderCellWrapper, _extends({}, displayHeaderCellProps, dragProps, {
84
+ hasColumnActions: hasColumnActions
85
+ }, propsFromColumnActions, {
86
+ className: classnames(classes, propsFromColumnActions.className),
87
+ id: id,
88
+ index: index,
89
+ isLastColumn: isLastColumn,
90
+ width: width,
91
+ "aria-sort": ariaSort,
92
+ "aria-label": displayAsText && "".concat(displayAsText, ", ") // ensure cell text content is read first, if available
93
+ ,
94
+ "aria-describedby": classnames(sortingAriaId, dragProps === null || dragProps === void 0 ? void 0 : dragProps['aria-describedby']),
95
+ "data-column-moving": propsFromColumnActions['data-column-moving'] || (dragProps === null || dragProps === void 0 ? void 0 : dragProps['data-column-moving']) || undefined
96
+ }), function (hasFocusTrap) {
97
+ return ___EmotionJSX(React.Fragment, null, !canDragAndDropColumns && columnResizer, canDragAndDropColumns && ___EmotionJSX("span", {
98
+ className: "euiDataGridHeaderCell__draggableIcon"
99
+ }, ___EmotionJSX(EuiIcon, {
100
+ type: "grabOmnidirectional",
101
+ size: "s",
102
+ css: styles.euiDataGridHeaderCell__actions
103
+ })), ___EmotionJSX("div", {
104
+ css: contentStyles,
105
+ className: "euiDataGridHeaderCell__content",
106
+ title: title
107
+ }, children), sortingArrow, sortingScreenReaderText, hasColumnActions && ___EmotionJSX(ColumnActions, {
108
+ index: index,
109
+ id: id,
110
+ title: title,
111
+ column: column,
112
+ columns: columns,
113
+ schema: schema,
114
+ schemaDetectors: schemaDetectors,
115
+ setVisibleColumns: setVisibleColumns,
116
+ switchColumnPos: switchColumnPos,
117
+ sorting: sorting,
118
+ hasFocusTrap: hasFocusTrap,
119
+ setPropsFromColumnActions: setPropsFromColumnActions,
120
+ actionsButtonRef: actionsButtonRef
121
+ }));
122
+ });
178
123
  });
179
124
  });
180
- EuiDataGridHeaderCell.displayName = 'EuiDataGridHeaderCell';
181
-
182
- /**
183
- * Column sorting utility helpers
184
- */
185
- export var useSortingUtils = function useSortingUtils(_ref2) {
186
- var _sorting$columns;
187
- var sorting = _ref2.sorting,
188
- id = _ref2.id,
189
- showColumnActions = _ref2.showColumnActions;
190
- var sortedColumn = useMemo(function () {
191
- return sorting === null || sorting === void 0 ? void 0 : sorting.columns.find(function (col) {
192
- return col.id === id;
193
- });
194
- }, [sorting, id]);
195
- var isColumnSorted = !!sortedColumn;
196
- var hasOnlyOneSort = (sorting === null || sorting === void 0 || (_sorting$columns = sorting.columns) === null || _sorting$columns === void 0 ? void 0 : _sorting$columns.length) === 1;
197
-
198
- /**
199
- * Arrow icon
200
- */
201
- var sortingArrow = useMemo(function () {
202
- return isColumnSorted ? ___EmotionJSX(EuiIcon, {
203
- type: sortedColumn.direction === 'asc' ? 'sortUp' : 'sortDown',
204
- color: "text",
205
- className: "euiDataGridHeaderCell__sortingArrow",
206
- "data-test-subj": "dataGridHeaderCellSortingIcon-".concat(id)
207
- }) : null;
208
- }, [id, isColumnSorted, sortedColumn]);
209
-
210
- /**
211
- * aria-sort attribute - should only be used when a single column is being sorted
212
- * @see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-sort
213
- * @see https://www.w3.org/WAI/ARIA/apg/example-index/table/sortable-table.html
214
- * @see https://github.com/w3c/aria/issues/283 for potential future multi-column usage
215
- */
216
- var ariaSort = isColumnSorted && hasOnlyOneSort ? sorting.columns[0].direction === 'asc' ? 'ascending' : 'descending' : undefined;
217
-
218
- /**
219
- * Sorting status - screen reader text
220
- */
221
- var sortingScreenReaderText = useMemo(function () {
222
- var _sorting$columns2;
223
- if (!isColumnSorted) return null;
224
- if (!showColumnActions && hasOnlyOneSort) return null; // in this scenario, the `aria-sort` attribute will be used by screen readers
225
- return ___EmotionJSX(React.Fragment, null, sorting === null || sorting === void 0 || (_sorting$columns2 = sorting.columns) === null || _sorting$columns2 === void 0 ? void 0 : _sorting$columns2.map(function (_ref3, index) {
226
- var columnId = _ref3.id,
227
- direction = _ref3.direction;
228
- if (hasOnlyOneSort) {
229
- if (direction === 'asc') {
230
- return ___EmotionJSX(EuiI18n, {
231
- token: "euiDataGridHeaderCell.sortedByAscendingSingle",
232
- default: "Sorted ascending",
233
- key: index
234
- });
235
- } else {
236
- return ___EmotionJSX(EuiI18n, {
237
- token: "euiDataGridHeaderCell.sortedByDescendingSingle",
238
- default: "Sorted descending",
239
- key: index
240
- });
241
- }
242
- } else if (index === 0) {
243
- if (direction === 'asc') {
244
- return ___EmotionJSX(EuiI18n, {
245
- token: "euiDataGridHeaderCell.sortedByAscendingFirst",
246
- default: "Sorted by {columnId}, ascending",
247
- values: {
248
- columnId: columnId
249
- },
250
- key: index
251
- });
252
- } else {
253
- return ___EmotionJSX(EuiI18n, {
254
- token: "euiDataGridHeaderCell.sortedByDescendingFirst",
255
- default: "Sorted by {columnId}, descending",
256
- values: {
257
- columnId: columnId
258
- },
259
- key: index
260
- });
261
- }
262
- } else {
263
- if (direction === 'asc') {
264
- return ___EmotionJSX(EuiI18n, {
265
- token: "euiDataGridHeaderCell.sortedByAscendingMultiple",
266
- default: ", then sorted by {columnId}, ascending",
267
- values: {
268
- columnId: columnId
269
- },
270
- key: index
271
- });
272
- } else {
273
- return ___EmotionJSX(EuiI18n, {
274
- token: "euiDataGridHeaderCell.sortedByDescendingMultiple",
275
- default: ", then sorted by {columnId}, descending",
276
- values: {
277
- columnId: columnId
278
- },
279
- key: index
280
- });
281
- }
282
- }
283
- }), ".");
284
- }, [isColumnSorted, showColumnActions, hasOnlyOneSort, sorting]);
285
- return {
286
- sortingArrow: sortingArrow,
287
- ariaSort: ariaSort,
288
- sortingScreenReaderText: sortingScreenReaderText
289
- };
290
- };
291
-
292
- /**
293
- * Add keyboard arrow navigation to the cell actions popover
294
- * to match the UX of the rest of EuiDataGrid
295
- */
296
- export var usePopoverArrowNavigation = function usePopoverArrowNavigation() {
297
- var popoverPanelRef = useRef(null);
298
- var actionsRef = useRef(undefined);
299
- var panelRef = useCallback(function (ref) {
300
- popoverPanelRef.current = ref;
301
- actionsRef.current = ref ? tabbable(ref) : undefined;
302
- }, []);
303
- var onKeyDown = useCallback(function (e) {
304
- var _actionsRef$current;
305
- if (e.key !== keys.ARROW_DOWN && e.key !== keys.ARROW_UP) return;
306
- if (!((_actionsRef$current = actionsRef.current) !== null && _actionsRef$current !== void 0 && _actionsRef$current.length)) return;
307
- e.preventDefault();
308
- var initialState = document.activeElement === popoverPanelRef.current;
309
- var currentIndex = !initialState ? actionsRef.current.findIndex(function (el) {
310
- return document.activeElement === el;
311
- }) : -1;
312
- var lastIndex = actionsRef.current.length - 1;
313
- var indexToFocus;
314
- if (initialState) {
315
- if (e.key === keys.ARROW_DOWN) {
316
- indexToFocus = 0;
317
- } else if (e.key === keys.ARROW_UP) {
318
- indexToFocus = lastIndex;
319
- }
320
- } else {
321
- if (e.key === keys.ARROW_DOWN) {
322
- indexToFocus = currentIndex + 1;
323
- if (indexToFocus > lastIndex) {
324
- indexToFocus = 0;
325
- }
326
- } else if (e.key === keys.ARROW_UP) {
327
- indexToFocus = currentIndex - 1;
328
- if (indexToFocus < 0) {
329
- indexToFocus = lastIndex;
330
- }
331
- }
332
- }
333
- actionsRef.current[indexToFocus].focus();
334
- }, []);
335
- return {
336
- panelRef: panelRef,
337
- panelProps: {
338
- onKeyDown: onKeyDown
339
- },
340
- popoverScreenReaderText: ___EmotionJSX(EuiI18n, {
341
- token: "euiDataGridHeaderCell.actionsPopoverScreenReaderText",
342
- default: "To navigate through the list of column actions, press the Tab or Up and Down arrow keys."
343
- })
344
- };
345
- };
125
+ EuiDataGridHeaderCell.displayName = 'EuiDataGridHeaderCell';
@@ -22,6 +22,6 @@ export var euiDataGridHeaderCellStyles = function euiDataGridHeaderCellStyles(eu
22
22
  // Numeric and currency schemas are aligned to the right
23
23
  right: /*#__PURE__*/css(logicalTextAlignCSS('right'), ";;label:right;"),
24
24
  euiDataGridHeaderCell__popover: /*#__PURE__*/css(logicalCSS('margin-left', 'auto'), "line-height:0;;label:euiDataGridHeaderCell__popover;"),
25
- euiDataGridHeaderCell__button: /*#__PURE__*/css("overflow:hidden;", header.hideActions, " &{", logicalCSS('width', 0), " opacity:0;}", euiCanAnimate, "{transition:inline-size ", euiTheme.animation.fast, " ease-in,opacity ", euiTheme.animation.slow, " ease-in;transform:none!important;animation:none!important;};label:euiDataGridHeaderCell__button;")
25
+ euiDataGridHeaderCell__actions: /*#__PURE__*/css("overflow:hidden;display:flex;", header.hideActions, " &{", logicalCSS('width', 0), " opacity:0;}", euiCanAnimate, "{transition:inline-size ", euiTheme.animation.fast, " ease-in,opacity ", euiTheme.animation.slow, " ease-in;transform:none!important;animation:none!important;};label:euiDataGridHeaderCell__actions;")
26
26
  };
27
27
  };
@@ -1,7 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
4
- var _excluded = ["id", "index", "visibleColCount", "width", "className", "children", "hasActionsPopover", "openActionsPopover", "aria-label"];
4
+ var _excluded = ["id", "index", "isLastColumn", "width", "className", "children", "hasColumnActions", "isDragging", "onKeyDown", "aria-label"];
5
5
  /*
6
6
  * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
7
7
  * or more contributor license agreements. Licensed under the Elastic License
@@ -26,12 +26,13 @@ import { jsx as ___EmotionJSX } from "@emotion/react";
26
26
  export var EuiDataGridHeaderCellWrapper = function EuiDataGridHeaderCellWrapper(_ref) {
27
27
  var id = _ref.id,
28
28
  index = _ref.index,
29
- visibleColCount = _ref.visibleColCount,
29
+ isLastColumn = _ref.isLastColumn,
30
30
  width = _ref.width,
31
31
  className = _ref.className,
32
32
  children = _ref.children,
33
- hasActionsPopover = _ref.hasActionsPopover,
34
- openActionsPopover = _ref.openActionsPopover,
33
+ hasColumnActions = _ref.hasColumnActions,
34
+ isDragging = _ref.isDragging,
35
+ _onKeyDown = _ref.onKeyDown,
35
36
  ariaLabel = _ref['aria-label'],
36
37
  rest = _objectWithoutProperties(_ref, _excluded);
37
38
  var classes = classnames('euiDataGridHeaderCell', className);
@@ -52,8 +53,8 @@ export var EuiDataGridHeaderCellWrapper = function EuiDataGridHeaderCellWrapper(
52
53
  setInteractiveChildren = _useState6[1];
53
54
  useEffect(function () {
54
55
  // We're checking for interactive children outside of the default actions button
55
- setRenderFocusTrap(interactiveChildren.length > (hasActionsPopover ? 1 : 0));
56
- }, [hasActionsPopover, interactiveChildren]);
56
+ setRenderFocusTrap(interactiveChildren.length > (hasColumnActions ? 1 : 0));
57
+ }, [hasColumnActions, interactiveChildren]);
57
58
  var _useContext = useContext(DataGridFocusContext),
58
59
  setFocusedCell = _useContext.setFocusedCell,
59
60
  onFocusUpdate = _useContext.onFocusUpdate;
@@ -75,14 +76,14 @@ export var EuiDataGridHeaderCellWrapper = function EuiDataGridHeaderCellWrapper(
75
76
  }
76
77
  });
77
78
  }, [index, onFocusUpdate, headerEl]);
78
-
79
- // For cell headers with only actions, auto-open the actions popover on enter keypress
80
79
  var onKeyDown = useCallback(function (e) {
81
- if (e.key === keys.ENTER && hasActionsPopover && !renderFocusTrap && e.target === headerEl) {
82
- openActionsPopover === null || openActionsPopover === void 0 || openActionsPopover();
80
+ // Ignore keys that conflict with the focus trap being entered/exited
81
+ if (renderFocusTrap && (e.key === keys.ENTER || e.key === keys.ESCAPE)) {
82
+ return;
83
83
  }
84
- }, [hasActionsPopover, openActionsPopover, renderFocusTrap, headerEl]);
85
- var isLastColumn = index === visibleColCount - 1;
84
+ // Otherwise, continue with whatever onKeyDown is being passed
85
+ _onKeyDown === null || _onKeyDown === void 0 || _onKeyDown(e);
86
+ }, [_onKeyDown, renderFocusTrap]);
86
87
  return ___EmotionJSX("div", _extends({
87
88
  role: "columnheader",
88
89
  ref: setHeaderEl,
@@ -100,9 +101,9 @@ export var EuiDataGridHeaderCellWrapper = function EuiDataGridHeaderCellWrapper(
100
101
  } : {},
101
102
  "aria-label": renderFocusTrap ? ariaLabel : undefined
102
103
  }, rest), ___EmotionJSX(HandleInteractiveChildren, {
103
- cellEl: headerEl,
104
+ cellEl: isDragging ? null : headerEl,
105
+ renderFocusTrap: isDragging ? false : renderFocusTrap,
104
106
  updateCellFocusContext: updateCellFocusContext,
105
- renderFocusTrap: renderFocusTrap,
106
107
  onInteractiveChildrenFound: setInteractiveChildren
107
108
  }, typeof children === 'function' ? children(renderFocusTrap) : children), isLastColumn ? tabularCopyMarkers.hiddenNewline : tabularCopyMarkers.hiddenTab);
108
109
  };