@elastic/eui 97.0.0 → 97.2.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 (161) 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 +4 -6
  21. package/es/components/datagrid/utils/focus.js +2 -2
  22. package/es/components/datagrid/utils/scrolling.js +13 -10
  23. package/es/components/date_picker/super_date_picker/date_popover/absolute_tab.js +8 -2
  24. package/es/components/date_picker/super_date_picker/date_popover/date_popover_button.js +8 -2
  25. package/es/components/date_picker/super_date_picker/date_popover/date_popover_content.js +8 -2
  26. package/es/components/date_picker/super_date_picker/super_date_picker.js +27 -5
  27. package/es/components/drag_and_drop/draggable.js +13 -5
  28. package/es/components/header/header.styles.js +6 -12
  29. package/es/components/header/header_links/header_links.js +1 -1
  30. package/es/components/header/header_links/header_links.styles.js +1 -0
  31. package/es/components/page_template/inner/page_inner.styles.js +3 -4
  32. package/es/components/tabs/tab.js +1 -1
  33. package/eui.d.ts +417 -307
  34. package/i18ntokens.json +175 -175
  35. package/lib/components/datagrid/body/cell/data_grid_cell.styles.js +4 -2
  36. package/lib/components/datagrid/body/cell/focus_utils.js +14 -4
  37. package/lib/components/datagrid/body/data_grid_body.js +2 -1
  38. package/lib/components/datagrid/body/data_grid_body_custom.js +5 -2
  39. package/lib/components/datagrid/body/data_grid_body_virtualized.js +8 -4
  40. package/lib/components/datagrid/body/header/column_actions.js +265 -29
  41. package/lib/components/datagrid/body/header/{data_grid_column_resizer.js → column_resizer.js} +11 -5
  42. package/{optimize/lib/components/datagrid/body/header/data_grid_column_resizer.styles.js → lib/components/datagrid/body/header/column_resizer.styles.js} +6 -1
  43. package/lib/components/datagrid/body/header/column_sorting.js +144 -0
  44. package/lib/components/datagrid/body/header/data_grid_control_header_cell.js +3 -3
  45. package/lib/components/datagrid/body/header/data_grid_header_cell.js +86 -305
  46. package/lib/components/datagrid/body/header/data_grid_header_cell.styles.js +1 -1
  47. package/lib/components/datagrid/body/header/data_grid_header_cell_wrapper.js +19 -17
  48. package/lib/components/datagrid/body/header/data_grid_header_cell_wrapper.styles.js +1 -2
  49. package/lib/components/datagrid/body/header/data_grid_header_row.js +24 -9
  50. package/lib/components/datagrid/body/header/draggable_columns.js +308 -0
  51. package/lib/components/datagrid/body/header/draggable_columns.styles.js +42 -0
  52. package/lib/components/datagrid/data_grid.js +2 -1
  53. package/lib/components/datagrid/data_grid.stories.utils.js +9 -6
  54. package/lib/components/datagrid/utils/col_widths.js +4 -6
  55. package/lib/components/datagrid/utils/focus.js +2 -2
  56. package/lib/components/datagrid/utils/scrolling.js +13 -10
  57. package/lib/components/date_picker/super_date_picker/date_popover/absolute_tab.js +8 -2
  58. package/lib/components/date_picker/super_date_picker/date_popover/date_popover_button.js +8 -2
  59. package/lib/components/date_picker/super_date_picker/date_popover/date_popover_content.js +8 -2
  60. package/lib/components/date_picker/super_date_picker/super_date_picker.js +27 -5
  61. package/lib/components/drag_and_drop/draggable.js +13 -5
  62. package/lib/components/header/header.styles.js +6 -12
  63. package/lib/components/header/header_links/header_links.js +1 -1
  64. package/lib/components/header/header_links/header_links.styles.js +1 -0
  65. package/lib/components/page_template/inner/page_inner.styles.js +3 -4
  66. package/lib/components/tabs/tab.js +1 -1
  67. package/optimize/es/components/datagrid/body/cell/data_grid_cell.styles.js +4 -2
  68. package/optimize/es/components/datagrid/body/cell/focus_utils.js +13 -4
  69. package/optimize/es/components/datagrid/body/data_grid_body_custom.js +3 -1
  70. package/optimize/es/components/datagrid/body/data_grid_body_virtualized.js +6 -3
  71. package/optimize/es/components/datagrid/body/header/column_actions.js +250 -26
  72. package/optimize/es/components/datagrid/body/header/{data_grid_column_resizer.js → column_resizer.js} +8 -3
  73. package/optimize/es/components/datagrid/body/header/{data_grid_column_resizer.styles.js → column_resizer.styles.js} +6 -1
  74. package/optimize/es/components/datagrid/body/header/column_sorting.js +134 -0
  75. package/optimize/es/components/datagrid/body/header/data_grid_control_header_cell.js +2 -2
  76. package/optimize/es/components/datagrid/body/header/data_grid_header_cell.js +82 -302
  77. package/optimize/es/components/datagrid/body/header/data_grid_header_cell.styles.js +1 -1
  78. package/optimize/es/components/datagrid/body/header/data_grid_header_cell_wrapper.js +15 -14
  79. package/optimize/es/components/datagrid/body/header/data_grid_header_cell_wrapper.styles.js +1 -2
  80. package/optimize/es/components/datagrid/body/header/data_grid_header_row.js +25 -10
  81. package/optimize/es/components/datagrid/body/header/draggable_columns.js +223 -0
  82. package/optimize/es/components/datagrid/body/header/draggable_columns.styles.js +38 -0
  83. package/optimize/es/components/datagrid/data_grid.js +2 -1
  84. package/optimize/es/components/datagrid/data_grid.stories.utils.js +7 -5
  85. package/optimize/es/components/datagrid/utils/col_widths.js +4 -6
  86. package/optimize/es/components/datagrid/utils/focus.js +2 -2
  87. package/optimize/es/components/datagrid/utils/scrolling.js +13 -10
  88. package/optimize/es/components/date_picker/super_date_picker/date_popover/absolute_tab.js +5 -1
  89. package/optimize/es/components/date_picker/super_date_picker/date_popover/date_popover_button.js +6 -2
  90. package/optimize/es/components/date_picker/super_date_picker/date_popover/date_popover_content.js +6 -2
  91. package/optimize/es/components/date_picker/super_date_picker/super_date_picker.js +11 -5
  92. package/optimize/es/components/drag_and_drop/draggable.js +8 -3
  93. package/optimize/es/components/header/header.styles.js +6 -12
  94. package/optimize/es/components/header/header_links/header_links.js +1 -1
  95. package/optimize/es/components/header/header_links/header_links.styles.js +1 -0
  96. package/optimize/es/components/page_template/inner/page_inner.styles.js +3 -4
  97. package/optimize/es/components/tabs/tab.js +1 -1
  98. package/optimize/lib/components/datagrid/body/cell/data_grid_cell.styles.js +4 -2
  99. package/optimize/lib/components/datagrid/body/cell/focus_utils.js +13 -4
  100. package/optimize/lib/components/datagrid/body/data_grid_body_custom.js +3 -1
  101. package/optimize/lib/components/datagrid/body/data_grid_body_virtualized.js +6 -3
  102. package/optimize/lib/components/datagrid/body/header/column_actions.js +253 -27
  103. package/optimize/lib/components/datagrid/body/header/{data_grid_column_resizer.js → column_resizer.js} +9 -4
  104. 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
  105. package/optimize/lib/components/datagrid/body/header/column_sorting.js +144 -0
  106. package/optimize/lib/components/datagrid/body/header/data_grid_control_header_cell.js +2 -2
  107. package/optimize/lib/components/datagrid/body/header/data_grid_header_cell.js +80 -300
  108. package/optimize/lib/components/datagrid/body/header/data_grid_header_cell.styles.js +1 -1
  109. package/optimize/lib/components/datagrid/body/header/data_grid_header_cell_wrapper.js +15 -14
  110. package/optimize/lib/components/datagrid/body/header/data_grid_header_cell_wrapper.styles.js +1 -2
  111. package/optimize/lib/components/datagrid/body/header/data_grid_header_row.js +24 -9
  112. package/optimize/lib/components/datagrid/body/header/draggable_columns.js +231 -0
  113. package/optimize/lib/components/datagrid/body/header/draggable_columns.styles.js +43 -0
  114. package/optimize/lib/components/datagrid/data_grid.js +2 -1
  115. package/optimize/lib/components/datagrid/data_grid.stories.utils.js +7 -5
  116. package/optimize/lib/components/datagrid/utils/col_widths.js +4 -6
  117. package/optimize/lib/components/datagrid/utils/focus.js +2 -2
  118. package/optimize/lib/components/datagrid/utils/scrolling.js +13 -10
  119. package/optimize/lib/components/date_picker/super_date_picker/date_popover/absolute_tab.js +5 -1
  120. package/optimize/lib/components/date_picker/super_date_picker/date_popover/date_popover_button.js +6 -2
  121. package/optimize/lib/components/date_picker/super_date_picker/date_popover/date_popover_content.js +6 -2
  122. package/optimize/lib/components/date_picker/super_date_picker/super_date_picker.js +11 -5
  123. package/optimize/lib/components/drag_and_drop/draggable.js +8 -3
  124. package/optimize/lib/components/header/header.styles.js +6 -12
  125. package/optimize/lib/components/header/header_links/header_links.js +1 -1
  126. package/optimize/lib/components/header/header_links/header_links.styles.js +1 -0
  127. package/optimize/lib/components/page_template/inner/page_inner.styles.js +3 -4
  128. package/optimize/lib/components/tabs/tab.js +1 -1
  129. package/package.json +1 -1
  130. package/test-env/components/datagrid/body/cell/data_grid_cell.styles.js +4 -2
  131. package/test-env/components/datagrid/body/cell/focus_utils.js +13 -4
  132. package/test-env/components/datagrid/body/data_grid_body.js +2 -1
  133. package/test-env/components/datagrid/body/data_grid_body_custom.js +5 -2
  134. package/test-env/components/datagrid/body/data_grid_body_virtualized.js +8 -4
  135. package/test-env/components/datagrid/body/header/column_actions.js +261 -27
  136. package/test-env/components/datagrid/body/header/{data_grid_column_resizer.js → column_resizer.js} +11 -5
  137. package/{lib/components/datagrid/body/header/data_grid_column_resizer.styles.js → test-env/components/datagrid/body/header/column_resizer.styles.js} +6 -1
  138. package/test-env/components/datagrid/body/header/column_sorting.js +144 -0
  139. package/test-env/components/datagrid/body/header/data_grid_control_header_cell.js +3 -3
  140. package/test-env/components/datagrid/body/header/data_grid_header_cell.js +82 -301
  141. package/test-env/components/datagrid/body/header/data_grid_header_cell.styles.js +1 -1
  142. package/test-env/components/datagrid/body/header/data_grid_header_cell_wrapper.js +19 -17
  143. package/test-env/components/datagrid/body/header/data_grid_header_cell_wrapper.styles.js +1 -2
  144. package/test-env/components/datagrid/body/header/data_grid_header_row.js +24 -9
  145. package/test-env/components/datagrid/body/header/draggable_columns.js +305 -0
  146. package/test-env/components/datagrid/body/header/draggable_columns.styles.js +43 -0
  147. package/test-env/components/datagrid/data_grid.js +2 -1
  148. package/test-env/components/datagrid/data_grid.stories.utils.js +9 -6
  149. package/test-env/components/datagrid/utils/col_widths.js +4 -6
  150. package/test-env/components/datagrid/utils/focus.js +2 -2
  151. package/test-env/components/datagrid/utils/scrolling.js +13 -10
  152. package/test-env/components/date_picker/super_date_picker/date_popover/absolute_tab.js +8 -2
  153. package/test-env/components/date_picker/super_date_picker/date_popover/date_popover_button.js +8 -2
  154. package/test-env/components/date_picker/super_date_picker/date_popover/date_popover_content.js +8 -2
  155. package/test-env/components/date_picker/super_date_picker/super_date_picker.js +27 -5
  156. package/test-env/components/drag_and_drop/draggable.js +13 -5
  157. package/test-env/components/header/header.styles.js +6 -12
  158. package/test-env/components/header/header_links/header_links.js +1 -1
  159. package/test-env/components/header/header_links/header_links.styles.js +1 -0
  160. package/test-env/components/page_template/inner/page_inner.styles.js +3 -4
  161. 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
+ };
@@ -15,7 +15,7 @@ import { jsx as ___EmotionJSX } from "@emotion/react";
15
15
  export var EuiDataGridControlHeaderCell = /*#__PURE__*/memo(function (_ref) {
16
16
  var controlColumn = _ref.controlColumn,
17
17
  index = _ref.index,
18
- visibleColCount = _ref.visibleColCount;
18
+ isLastColumn = _ref.isLastColumn;
19
19
  var HeaderCellRender = controlColumn.headerCellRender,
20
20
  headerCellProps = controlColumn.headerCellProps,
21
21
  width = controlColumn.width,
@@ -25,12 +25,12 @@ export var EuiDataGridControlHeaderCell = /*#__PURE__*/memo(function (_ref) {
25
25
  id: id,
26
26
  index: index,
27
27
  width: width,
28
- visibleColCount: visibleColCount
28
+ isLastColumn: isLastColumn
29
29
  }), ___EmotionJSX(HeaderCellRender, null));
30
30
  });
31
31
  EuiDataGridControlHeaderCell.propTypes = {
32
32
  index: PropTypes.number.isRequired,
33
- visibleColCount: PropTypes.number.isRequired,
33
+ isLastColumn: PropTypes.bool.isRequired,
34
34
  controlColumn: PropTypes.shape({
35
35
  /**
36
36
  * Used as the React `key` when rendering content
@@ -1,14 +1,14 @@
1
1
  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); }
2
2
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
3
- 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; }
4
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
5
- 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); }
6
3
  function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
7
4
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
8
5
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
9
6
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
10
7
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
11
8
  function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
9
+ 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; }
10
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
11
+ 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); }
12
12
  /*
13
13
  * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
14
14
  * or more contributor license agreements. Licensed under the Elastic License
@@ -19,17 +19,13 @@ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
19
19
 
20
20
  import classnames from 'classnames';
21
21
  import PropTypes from "prop-types";
22
- import React, { useContext, useState, useRef, useCallback, useMemo, memo } from 'react';
23
- import { tabbable } from 'tabbable';
24
- import { keys, useGeneratedHtmlId, useEuiMemoizedStyles } from '../../../../services';
25
- import { EuiI18n, useEuiI18n } from '../../../i18n';
22
+ import React, { memo, useMemo, useRef, useState } from 'react';
23
+ import { useEuiMemoizedStyles } from '../../../../services';
26
24
  import { EuiIcon } from '../../../icon';
27
- import { EuiListGroup } from '../../../list_group';
28
- import { EuiPopover } from '../../../popover';
29
- import { EuiButtonIcon } from '../../../button';
30
- import { DataGridFocusContext } from '../../utils/focus';
31
- import { getColumnActions } from './column_actions';
32
- import { EuiDataGridColumnResizer } from './data_grid_column_resizer';
25
+ import { useHasColumnActions, ColumnActions } from './column_actions';
26
+ import { useColumnSorting } from './column_sorting';
27
+ import { ConditionalDraggableColumn } from './draggable_columns';
28
+ import { EuiDataGridColumnResizer } from './column_resizer';
33
29
  import { EuiDataGridHeaderCellWrapper } from './data_grid_header_cell_wrapper';
34
30
  import { euiDataGridHeaderCellStyles } from './data_grid_header_cell.styles';
35
31
  import { jsx as ___EmotionJSX } from "@emotion/react";
@@ -40,153 +36,103 @@ export var EuiDataGridHeaderCell = /*#__PURE__*/memo(function (_ref) {
40
36
  columnWidths = _ref.columnWidths,
41
37
  defaultColumnWidth = _ref.defaultColumnWidth,
42
38
  setColumnWidth = _ref.setColumnWidth,
43
- visibleColCount = _ref.visibleColCount,
44
39
  setVisibleColumns = _ref.setVisibleColumns,
45
40
  switchColumnPos = _ref.switchColumnPos,
41
+ isLastColumn = _ref.isLastColumn,
46
42
  sorting = _ref.sorting,
47
43
  schema = _ref.schema,
48
- schemaDetectors = _ref.schemaDetectors;
44
+ schemaDetectors = _ref.schemaDetectors,
45
+ canDragAndDropColumns = _ref.canDragAndDropColumns,
46
+ gridStyles = _ref.gridStyles;
49
47
  var id = column.id,
50
48
  display = column.display,
51
49
  displayAsText = column.displayAsText,
52
- displayHeaderCellProps = column.displayHeaderCellProps;
50
+ displayHeaderCellProps = column.displayHeaderCellProps,
51
+ actions = column.actions;
53
52
  var title = displayAsText || id;
54
53
  var children = display || displayAsText || id;
55
54
  var width = columnWidths[id] || defaultColumnWidth;
56
55
  var columnType = schema[id] ? schema[id].columnType : null;
57
- var _useContext = useContext(DataGridFocusContext),
58
- setFocusedCell = _useContext.setFocusedCell,
59
- focusFirstVisibleInteractiveCell = _useContext.focusFirstVisibleInteractiveCell;
56
+ var hasColumnActions = useHasColumnActions(actions);
57
+ var classes = classnames(_defineProperty(_defineProperty({}, "euiDataGridHeaderCell--".concat(columnType), columnType), 'euiDataGridHeaderCell--hasColumnActions', hasColumnActions), displayHeaderCellProps === null || displayHeaderCellProps === void 0 ? void 0 : displayHeaderCellProps.className);
58
+ var styles = useEuiMemoizedStyles(euiDataGridHeaderCellStyles);
59
+ var contentStyles = [styles.euiDataGridHeaderCell__content, (columnType === 'numeric' || columnType === 'currency') && styles.right];
60
60
 
61
- /*
62
- * Column actions
63
- */
64
- var _useState = useState(false),
61
+ // Props passed from <ColumnActions /> to be set on <EuiDataGridHeaderCellWrapper />
62
+ var _useState = useState({}),
65
63
  _useState2 = _slicedToArray(_useState, 2),
66
- isPopoverOpen = _useState2[0],
67
- setIsPopoverOpen = _useState2[1];
68
- var togglePopover = useCallback(function () {
69
- setIsPopoverOpen(function (isOpen) {
70
- return !isOpen;
71
- });
72
- }, []);
73
- var closePopover = useCallback(function () {
74
- return setIsPopoverOpen(false);
75
- }, []);
76
- var popoverArrowNavigationProps = usePopoverArrowNavigation();
77
- var columnActions = useMemo(function () {
78
- return getColumnActions({
79
- column: column,
80
- columns: columns,
81
- schema: schema,
82
- schemaDetectors: schemaDetectors,
83
- setVisibleColumns: setVisibleColumns,
84
- focusFirstVisibleInteractiveCell: focusFirstVisibleInteractiveCell,
85
- setIsPopoverOpen: setIsPopoverOpen,
86
- sorting: sorting,
87
- switchColumnPos: switchColumnPos,
88
- setFocusedCell: setFocusedCell,
89
- columnFocusIndex: index
90
- });
91
- }, [column, columns, schema, schemaDetectors, setVisibleColumns, focusFirstVisibleInteractiveCell, setIsPopoverOpen, sorting, switchColumnPos, setFocusedCell, index]);
92
- var showColumnActions = columnActions && columnActions.length > 0;
64
+ propsFromColumnActions = _useState2[0],
65
+ setPropsFromColumnActions = _useState2[1];
93
66
  var actionsButtonRef = useRef(null);
94
- var clickActionsButton = useCallback(function () {
95
- var _actionsButtonRef$cur;
96
- (_actionsButtonRef$cur = actionsButtonRef.current) === null || _actionsButtonRef$cur === void 0 || _actionsButtonRef$cur.click();
97
- }, []);
98
- var _useState3 = useState(false),
99
- _useState4 = _slicedToArray(_useState3, 2),
100
- isActionsButtonFocused = _useState4[0],
101
- setIsActionsButtonFocused = _useState4[1];
102
- var actionsButtonAriaLabel = useEuiI18n('euiDataGridHeaderCell.actionsButtonAriaLabel', '{title}. Click to view column header actions.', {
103
- title: title
104
- });
105
- var actionsEnterKeyInstructions = useEuiI18n('euiDataGridHeaderCell.actionsEnterKeyInstructions', "Press the Enter key to view this column's actions");
106
-
107
- /*
108
- * Column sorting
109
- */
110
- var _useSortingUtils = useSortingUtils({
67
+ var _useColumnSorting = useColumnSorting({
111
68
  sorting: sorting,
112
69
  id: id,
113
- showColumnActions: showColumnActions
70
+ hasColumnActions: hasColumnActions
114
71
  }),
115
- sortingArrow = _useSortingUtils.sortingArrow,
116
- ariaSort = _useSortingUtils.ariaSort,
117
- sortingScreenReaderText = _useSortingUtils.sortingScreenReaderText;
118
- var sortingAriaId = useGeneratedHtmlId({
119
- prefix: 'euiDataGridCellHeader',
120
- suffix: 'sorting'
121
- });
122
-
123
- /*
124
- * Rendering
125
- */
126
- 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);
127
- var styles = useEuiMemoizedStyles(euiDataGridHeaderCellStyles);
128
- var contentStyles = [styles.euiDataGridHeaderCell__content, (columnType === 'numeric' || columnType === 'currency') && styles.right];
129
- return ___EmotionJSX(EuiDataGridHeaderCellWrapper, _extends({}, displayHeaderCellProps, {
130
- className: classes,
131
- id: id,
132
- index: index,
133
- visibleColCount: visibleColCount,
134
- width: width,
135
- "aria-sort": ariaSort,
136
- hasActionsPopover: showColumnActions,
137
- openActionsPopover: clickActionsButton,
138
- "aria-label": displayAsText && "".concat(displayAsText, ", ") // ensure cell text content is read first, if available
139
- ,
140
- "aria-describedby": sortingAriaId
141
- }), function (hasFocusTrap) {
142
- return ___EmotionJSX(React.Fragment, null, column.isResizable !== false && width != null ? ___EmotionJSX(EuiDataGridColumnResizer, {
72
+ sortingArrow = _useColumnSorting.sortingArrow,
73
+ ariaSort = _useColumnSorting.ariaSort,
74
+ sortingAriaId = _useColumnSorting.sortingAriaId,
75
+ sortingScreenReaderText = _useColumnSorting.sortingScreenReaderText;
76
+ var columnResizer = useMemo(function () {
77
+ return column.isResizable !== false && width != null ? ___EmotionJSX(EuiDataGridColumnResizer, {
143
78
  columnId: id,
144
79
  columnWidth: width,
145
- setColumnWidth: setColumnWidth
146
- }) : null, ___EmotionJSX("div", {
147
- css: contentStyles,
148
- className: "euiDataGridHeaderCell__content",
149
- title: title
150
- }, children), sortingArrow, sortingScreenReaderText && ___EmotionJSX("p", {
151
- id: sortingAriaId,
152
- hidden: true
153
- }, sortingScreenReaderText), showColumnActions && ___EmotionJSX(EuiPopover, _extends({
154
- display: "block",
155
- panelPaddingSize: "none",
156
- offset: 7,
157
- anchorPosition: "downRight",
158
- css: styles.euiDataGridHeaderCell__popover,
159
- button: ___EmotionJSX(EuiButtonIcon, {
160
- iconType: "boxesVertical",
161
- iconSize: "s",
162
- color: "text",
163
- css: styles.euiDataGridHeaderCell__button,
164
- className: "euiDataGridHeaderCell__button",
165
- buttonRef: actionsButtonRef,
166
- onClick: togglePopover,
167
- onFocus: function onFocus() {
168
- return setIsActionsButtonFocused(true);
169
- },
170
- onBlur: function onBlur() {
171
- return setIsActionsButtonFocused(false);
172
- },
173
- tabIndex: 0 // Override EuiButtonIcon's conditional tabindex based on aria-hidden
174
- ,
175
- "aria-hidden": hasFocusTrap && !isActionsButtonFocused ? 'true' // prevent the actions button from being read on cell focus
176
- : undefined,
177
- "aria-label": hasFocusTrap ? actionsButtonAriaLabel : actionsEnterKeyInstructions,
178
- "data-test-subj": "dataGridHeaderCellActionButton-".concat(id)
179
- }),
180
- isOpen: isPopoverOpen,
181
- closePopover: closePopover
182
- }, popoverArrowNavigationProps), ___EmotionJSX(EuiListGroup, {
183
- listItems: columnActions,
184
- gutterSize: "none",
185
- "data-test-subj": "dataGridHeaderCellActionGroup-".concat(id)
186
- })));
80
+ setColumnWidth: setColumnWidth,
81
+ isLastColumn: isLastColumn
82
+ }) : null;
83
+ }, [column.isResizable, id, width, setColumnWidth, isLastColumn]);
84
+ return ___EmotionJSX(ConditionalDraggableColumn, {
85
+ id: id,
86
+ index: index,
87
+ canDragAndDropColumns: !!canDragAndDropColumns,
88
+ gridStyles: gridStyles,
89
+ columnResizer: columnResizer,
90
+ actionsPopoverToggle: actionsButtonRef.current
91
+ }, function (dragProps) {
92
+ return ___EmotionJSX(EuiDataGridHeaderCellWrapper, _extends({}, displayHeaderCellProps, dragProps, {
93
+ hasColumnActions: hasColumnActions
94
+ }, propsFromColumnActions, {
95
+ className: classnames(classes, propsFromColumnActions.className),
96
+ id: id,
97
+ index: index,
98
+ isLastColumn: isLastColumn,
99
+ width: width,
100
+ "aria-sort": ariaSort,
101
+ "aria-label": displayAsText && "".concat(displayAsText, ", ") // ensure cell text content is read first, if available
102
+ ,
103
+ "aria-describedby": classnames(sortingAriaId, dragProps === null || dragProps === void 0 ? void 0 : dragProps['aria-describedby']),
104
+ "data-column-moving": propsFromColumnActions['data-column-moving'] || (dragProps === null || dragProps === void 0 ? void 0 : dragProps['data-column-moving']) || undefined
105
+ }), function (hasFocusTrap) {
106
+ return ___EmotionJSX(React.Fragment, null, !canDragAndDropColumns && columnResizer, canDragAndDropColumns && ___EmotionJSX("span", {
107
+ className: "euiDataGridHeaderCell__draggableIcon"
108
+ }, ___EmotionJSX(EuiIcon, {
109
+ type: "grabOmnidirectional",
110
+ size: "s",
111
+ css: styles.euiDataGridHeaderCell__actions
112
+ })), ___EmotionJSX("div", {
113
+ css: contentStyles,
114
+ className: "euiDataGridHeaderCell__content",
115
+ title: title
116
+ }, children), sortingArrow, sortingScreenReaderText, hasColumnActions && ___EmotionJSX(ColumnActions, {
117
+ index: index,
118
+ id: id,
119
+ title: title,
120
+ column: column,
121
+ columns: columns,
122
+ schema: schema,
123
+ schemaDetectors: schemaDetectors,
124
+ setVisibleColumns: setVisibleColumns,
125
+ switchColumnPos: switchColumnPos,
126
+ sorting: sorting,
127
+ hasFocusTrap: hasFocusTrap,
128
+ setPropsFromColumnActions: setPropsFromColumnActions,
129
+ actionsButtonRef: actionsButtonRef
130
+ }));
131
+ });
187
132
  });
188
133
  });
189
134
  EuiDataGridHeaderCell.propTypes = {
135
+ index: PropTypes.number.isRequired,
190
136
  column: PropTypes.shape({
191
137
  /**
192
138
  * The unique identifier for this column
@@ -583,171 +529,6 @@ EuiDataGridHeaderCell.propTypes = {
583
529
  */
584
530
  visibleCellActions: PropTypes.number
585
531
  }).isRequired,
586
- index: PropTypes.number.isRequired
532
+ isLastColumn: PropTypes.bool.isRequired
587
533
  };
588
- EuiDataGridHeaderCell.displayName = 'EuiDataGridHeaderCell';
589
-
590
- /**
591
- * Column sorting utility helpers
592
- */
593
- export var useSortingUtils = function useSortingUtils(_ref2) {
594
- var _sorting$columns;
595
- var sorting = _ref2.sorting,
596
- id = _ref2.id,
597
- showColumnActions = _ref2.showColumnActions;
598
- var sortedColumn = useMemo(function () {
599
- return sorting === null || sorting === void 0 ? void 0 : sorting.columns.find(function (col) {
600
- return col.id === id;
601
- });
602
- }, [sorting, id]);
603
- var isColumnSorted = !!sortedColumn;
604
- var hasOnlyOneSort = (sorting === null || sorting === void 0 || (_sorting$columns = sorting.columns) === null || _sorting$columns === void 0 ? void 0 : _sorting$columns.length) === 1;
605
-
606
- /**
607
- * Arrow icon
608
- */
609
- var sortingArrow = useMemo(function () {
610
- return isColumnSorted ? ___EmotionJSX(EuiIcon, {
611
- type: sortedColumn.direction === 'asc' ? 'sortUp' : 'sortDown',
612
- color: "text",
613
- className: "euiDataGridHeaderCell__sortingArrow",
614
- "data-test-subj": "dataGridHeaderCellSortingIcon-".concat(id)
615
- }) : null;
616
- }, [id, isColumnSorted, sortedColumn]);
617
-
618
- /**
619
- * aria-sort attribute - should only be used when a single column is being sorted
620
- * @see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-sort
621
- * @see https://www.w3.org/WAI/ARIA/apg/example-index/table/sortable-table.html
622
- * @see https://github.com/w3c/aria/issues/283 for potential future multi-column usage
623
- */
624
- var ariaSort = isColumnSorted && hasOnlyOneSort ? sorting.columns[0].direction === 'asc' ? 'ascending' : 'descending' : undefined;
625
-
626
- /**
627
- * Sorting status - screen reader text
628
- */
629
- var sortingScreenReaderText = useMemo(function () {
630
- var _sorting$columns2;
631
- if (!isColumnSorted) return null;
632
- if (!showColumnActions && hasOnlyOneSort) return null; // in this scenario, the `aria-sort` attribute will be used by screen readers
633
- 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) {
634
- var columnId = _ref3.id,
635
- direction = _ref3.direction;
636
- if (hasOnlyOneSort) {
637
- if (direction === 'asc') {
638
- return ___EmotionJSX(EuiI18n, {
639
- token: "euiDataGridHeaderCell.sortedByAscendingSingle",
640
- default: "Sorted ascending",
641
- key: index
642
- });
643
- } else {
644
- return ___EmotionJSX(EuiI18n, {
645
- token: "euiDataGridHeaderCell.sortedByDescendingSingle",
646
- default: "Sorted descending",
647
- key: index
648
- });
649
- }
650
- } else if (index === 0) {
651
- if (direction === 'asc') {
652
- return ___EmotionJSX(EuiI18n, {
653
- token: "euiDataGridHeaderCell.sortedByAscendingFirst",
654
- default: "Sorted by {columnId}, ascending",
655
- values: {
656
- columnId: columnId
657
- },
658
- key: index
659
- });
660
- } else {
661
- return ___EmotionJSX(EuiI18n, {
662
- token: "euiDataGridHeaderCell.sortedByDescendingFirst",
663
- default: "Sorted by {columnId}, descending",
664
- values: {
665
- columnId: columnId
666
- },
667
- key: index
668
- });
669
- }
670
- } else {
671
- if (direction === 'asc') {
672
- return ___EmotionJSX(EuiI18n, {
673
- token: "euiDataGridHeaderCell.sortedByAscendingMultiple",
674
- default: ", then sorted by {columnId}, ascending",
675
- values: {
676
- columnId: columnId
677
- },
678
- key: index
679
- });
680
- } else {
681
- return ___EmotionJSX(EuiI18n, {
682
- token: "euiDataGridHeaderCell.sortedByDescendingMultiple",
683
- default: ", then sorted by {columnId}, descending",
684
- values: {
685
- columnId: columnId
686
- },
687
- key: index
688
- });
689
- }
690
- }
691
- }), ".");
692
- }, [isColumnSorted, showColumnActions, hasOnlyOneSort, sorting]);
693
- return {
694
- sortingArrow: sortingArrow,
695
- ariaSort: ariaSort,
696
- sortingScreenReaderText: sortingScreenReaderText
697
- };
698
- };
699
-
700
- /**
701
- * Add keyboard arrow navigation to the cell actions popover
702
- * to match the UX of the rest of EuiDataGrid
703
- */
704
- export var usePopoverArrowNavigation = function usePopoverArrowNavigation() {
705
- var popoverPanelRef = useRef(null);
706
- var actionsRef = useRef(undefined);
707
- var panelRef = useCallback(function (ref) {
708
- popoverPanelRef.current = ref;
709
- actionsRef.current = ref ? tabbable(ref) : undefined;
710
- }, []);
711
- var onKeyDown = useCallback(function (e) {
712
- var _actionsRef$current;
713
- if (e.key !== keys.ARROW_DOWN && e.key !== keys.ARROW_UP) return;
714
- if (!((_actionsRef$current = actionsRef.current) !== null && _actionsRef$current !== void 0 && _actionsRef$current.length)) return;
715
- e.preventDefault();
716
- var initialState = document.activeElement === popoverPanelRef.current;
717
- var currentIndex = !initialState ? actionsRef.current.findIndex(function (el) {
718
- return document.activeElement === el;
719
- }) : -1;
720
- var lastIndex = actionsRef.current.length - 1;
721
- var indexToFocus;
722
- if (initialState) {
723
- if (e.key === keys.ARROW_DOWN) {
724
- indexToFocus = 0;
725
- } else if (e.key === keys.ARROW_UP) {
726
- indexToFocus = lastIndex;
727
- }
728
- } else {
729
- if (e.key === keys.ARROW_DOWN) {
730
- indexToFocus = currentIndex + 1;
731
- if (indexToFocus > lastIndex) {
732
- indexToFocus = 0;
733
- }
734
- } else if (e.key === keys.ARROW_UP) {
735
- indexToFocus = currentIndex - 1;
736
- if (indexToFocus < 0) {
737
- indexToFocus = lastIndex;
738
- }
739
- }
740
- }
741
- actionsRef.current[indexToFocus].focus();
742
- }, []);
743
- return {
744
- panelRef: panelRef,
745
- panelProps: {
746
- onKeyDown: onKeyDown
747
- },
748
- popoverScreenReaderText: ___EmotionJSX(EuiI18n, {
749
- token: "euiDataGridHeaderCell.actionsPopoverScreenReaderText",
750
- default: "To navigate through the list of column actions, press the Tab or Up and Down arrow keys."
751
- })
752
- };
753
- };
534
+ 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
  };