@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.
- package/es/components/datagrid/body/cell/data_grid_cell.styles.js +4 -2
- package/es/components/datagrid/body/cell/focus_utils.js +14 -4
- package/es/components/datagrid/body/data_grid_body.js +2 -1
- package/es/components/datagrid/body/data_grid_body_custom.js +5 -2
- package/es/components/datagrid/body/data_grid_body_virtualized.js +8 -4
- package/es/components/datagrid/body/header/column_actions.js +262 -27
- package/es/components/datagrid/body/header/{data_grid_column_resizer.js → column_resizer.js} +10 -4
- package/es/components/datagrid/body/header/{data_grid_column_resizer.styles.js → column_resizer.styles.js} +6 -1
- package/es/components/datagrid/body/header/column_sorting.js +134 -0
- package/es/components/datagrid/body/header/data_grid_control_header_cell.js +3 -3
- package/es/components/datagrid/body/header/data_grid_header_cell.js +86 -305
- package/es/components/datagrid/body/header/data_grid_header_cell.styles.js +1 -1
- package/es/components/datagrid/body/header/data_grid_header_cell_wrapper.js +19 -17
- package/es/components/datagrid/body/header/data_grid_header_cell_wrapper.styles.js +1 -2
- package/es/components/datagrid/body/header/data_grid_header_row.js +25 -10
- package/es/components/datagrid/body/header/draggable_columns.js +301 -0
- package/es/components/datagrid/body/header/draggable_columns.styles.js +38 -0
- package/es/components/datagrid/data_grid.js +2 -1
- package/es/components/datagrid/data_grid.stories.utils.js +9 -6
- package/es/components/datagrid/utils/col_widths.js +17 -13
- package/es/components/datagrid/utils/focus.js +2 -2
- package/es/components/datagrid/utils/scrolling.js +13 -10
- package/es/components/drag_and_drop/draggable.js +13 -5
- package/es/components/header/header.styles.js +6 -12
- package/es/components/page_template/inner/page_inner.styles.js +3 -4
- package/es/components/tabs/tab.js +1 -1
- package/eui.d.ts +406 -311
- package/i18ntokens.json +123 -123
- package/lib/components/datagrid/body/cell/data_grid_cell.styles.js +4 -2
- package/lib/components/datagrid/body/cell/focus_utils.js +14 -4
- package/lib/components/datagrid/body/data_grid_body.js +2 -1
- package/lib/components/datagrid/body/data_grid_body_custom.js +5 -2
- package/lib/components/datagrid/body/data_grid_body_virtualized.js +8 -4
- package/lib/components/datagrid/body/header/column_actions.js +265 -29
- package/lib/components/datagrid/body/header/{data_grid_column_resizer.js → column_resizer.js} +11 -5
- package/{optimize/lib/components/datagrid/body/header/data_grid_column_resizer.styles.js → lib/components/datagrid/body/header/column_resizer.styles.js} +6 -1
- package/lib/components/datagrid/body/header/column_sorting.js +144 -0
- package/lib/components/datagrid/body/header/data_grid_control_header_cell.js +3 -3
- package/lib/components/datagrid/body/header/data_grid_header_cell.js +86 -305
- package/lib/components/datagrid/body/header/data_grid_header_cell.styles.js +1 -1
- package/lib/components/datagrid/body/header/data_grid_header_cell_wrapper.js +19 -17
- package/lib/components/datagrid/body/header/data_grid_header_cell_wrapper.styles.js +1 -2
- package/lib/components/datagrid/body/header/data_grid_header_row.js +24 -9
- package/lib/components/datagrid/body/header/draggable_columns.js +308 -0
- package/lib/components/datagrid/body/header/draggable_columns.styles.js +42 -0
- package/lib/components/datagrid/data_grid.js +2 -1
- package/lib/components/datagrid/data_grid.stories.utils.js +9 -6
- package/lib/components/datagrid/utils/col_widths.js +17 -13
- package/lib/components/datagrid/utils/focus.js +2 -2
- package/lib/components/datagrid/utils/scrolling.js +13 -10
- package/lib/components/drag_and_drop/draggable.js +13 -5
- package/lib/components/header/header.styles.js +6 -12
- package/lib/components/page_template/inner/page_inner.styles.js +3 -4
- package/lib/components/tabs/tab.js +1 -1
- package/optimize/es/components/datagrid/body/cell/data_grid_cell.styles.js +4 -2
- package/optimize/es/components/datagrid/body/cell/focus_utils.js +13 -4
- package/optimize/es/components/datagrid/body/data_grid_body_custom.js +3 -1
- package/optimize/es/components/datagrid/body/data_grid_body_virtualized.js +6 -3
- package/optimize/es/components/datagrid/body/header/column_actions.js +250 -26
- package/optimize/es/components/datagrid/body/header/{data_grid_column_resizer.js → column_resizer.js} +8 -3
- package/optimize/es/components/datagrid/body/header/{data_grid_column_resizer.styles.js → column_resizer.styles.js} +6 -1
- package/optimize/es/components/datagrid/body/header/column_sorting.js +134 -0
- package/optimize/es/components/datagrid/body/header/data_grid_control_header_cell.js +2 -2
- package/optimize/es/components/datagrid/body/header/data_grid_header_cell.js +82 -302
- package/optimize/es/components/datagrid/body/header/data_grid_header_cell.styles.js +1 -1
- package/optimize/es/components/datagrid/body/header/data_grid_header_cell_wrapper.js +15 -14
- package/optimize/es/components/datagrid/body/header/data_grid_header_cell_wrapper.styles.js +1 -2
- package/optimize/es/components/datagrid/body/header/data_grid_header_row.js +25 -10
- package/optimize/es/components/datagrid/body/header/draggable_columns.js +223 -0
- package/optimize/es/components/datagrid/body/header/draggable_columns.styles.js +38 -0
- package/optimize/es/components/datagrid/data_grid.js +2 -1
- package/optimize/es/components/datagrid/data_grid.stories.utils.js +7 -5
- package/optimize/es/components/datagrid/utils/col_widths.js +17 -13
- package/optimize/es/components/datagrid/utils/focus.js +2 -2
- package/optimize/es/components/datagrid/utils/scrolling.js +13 -10
- package/optimize/es/components/drag_and_drop/draggable.js +8 -3
- package/optimize/es/components/header/header.styles.js +6 -12
- package/optimize/es/components/page_template/inner/page_inner.styles.js +3 -4
- package/optimize/es/components/tabs/tab.js +1 -1
- package/optimize/lib/components/datagrid/body/cell/data_grid_cell.styles.js +4 -2
- package/optimize/lib/components/datagrid/body/cell/focus_utils.js +13 -4
- package/optimize/lib/components/datagrid/body/data_grid_body_custom.js +3 -1
- package/optimize/lib/components/datagrid/body/data_grid_body_virtualized.js +6 -3
- package/optimize/lib/components/datagrid/body/header/column_actions.js +253 -27
- package/optimize/lib/components/datagrid/body/header/{data_grid_column_resizer.js → column_resizer.js} +9 -4
- 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
- package/optimize/lib/components/datagrid/body/header/column_sorting.js +144 -0
- package/optimize/lib/components/datagrid/body/header/data_grid_control_header_cell.js +2 -2
- package/optimize/lib/components/datagrid/body/header/data_grid_header_cell.js +80 -300
- package/optimize/lib/components/datagrid/body/header/data_grid_header_cell.styles.js +1 -1
- package/optimize/lib/components/datagrid/body/header/data_grid_header_cell_wrapper.js +15 -14
- package/optimize/lib/components/datagrid/body/header/data_grid_header_cell_wrapper.styles.js +1 -2
- package/optimize/lib/components/datagrid/body/header/data_grid_header_row.js +24 -9
- package/optimize/lib/components/datagrid/body/header/draggable_columns.js +231 -0
- package/optimize/lib/components/datagrid/body/header/draggable_columns.styles.js +43 -0
- package/optimize/lib/components/datagrid/data_grid.js +2 -1
- package/optimize/lib/components/datagrid/data_grid.stories.utils.js +7 -5
- package/optimize/lib/components/datagrid/utils/col_widths.js +17 -13
- package/optimize/lib/components/datagrid/utils/focus.js +2 -2
- package/optimize/lib/components/datagrid/utils/scrolling.js +13 -10
- package/optimize/lib/components/drag_and_drop/draggable.js +8 -3
- package/optimize/lib/components/header/header.styles.js +6 -12
- package/optimize/lib/components/page_template/inner/page_inner.styles.js +3 -4
- package/optimize/lib/components/tabs/tab.js +1 -1
- package/package.json +2 -3
- package/test-env/components/datagrid/body/cell/data_grid_cell.styles.js +4 -2
- package/test-env/components/datagrid/body/cell/focus_utils.js +13 -4
- package/test-env/components/datagrid/body/data_grid_body.js +2 -1
- package/test-env/components/datagrid/body/data_grid_body_custom.js +5 -2
- package/test-env/components/datagrid/body/data_grid_body_virtualized.js +8 -4
- package/test-env/components/datagrid/body/header/column_actions.js +261 -27
- package/test-env/components/datagrid/body/header/{data_grid_column_resizer.js → column_resizer.js} +11 -5
- package/{lib/components/datagrid/body/header/data_grid_column_resizer.styles.js → test-env/components/datagrid/body/header/column_resizer.styles.js} +6 -1
- package/test-env/components/datagrid/body/header/column_sorting.js +144 -0
- package/test-env/components/datagrid/body/header/data_grid_control_header_cell.js +3 -3
- package/test-env/components/datagrid/body/header/data_grid_header_cell.js +82 -301
- package/test-env/components/datagrid/body/header/data_grid_header_cell.styles.js +1 -1
- package/test-env/components/datagrid/body/header/data_grid_header_cell_wrapper.js +19 -17
- package/test-env/components/datagrid/body/header/data_grid_header_cell_wrapper.styles.js +1 -2
- package/test-env/components/datagrid/body/header/data_grid_header_row.js +24 -9
- package/test-env/components/datagrid/body/header/draggable_columns.js +305 -0
- package/test-env/components/datagrid/body/header/draggable_columns.styles.js +43 -0
- package/test-env/components/datagrid/data_grid.js +2 -1
- package/test-env/components/datagrid/data_grid.stories.utils.js +9 -6
- package/test-env/components/datagrid/utils/col_widths.js +17 -13
- package/test-env/components/datagrid/utils/focus.js +2 -2
- package/test-env/components/datagrid/utils/scrolling.js +13 -10
- package/test-env/components/drag_and_drop/draggable.js +13 -5
- package/test-env/components/header/header.styles.js +6 -12
- package/test-env/components/page_template/inner/page_inner.styles.js +3 -4
- package/test-env/components/tabs/tab.js +1 -1
|
@@ -3,13 +3,23 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.isColumnActionEnabled = exports.getSortColumnActions = exports.getHideColumnAction = exports.getColumnActions = exports.getColumnActionConfig = void 0;
|
|
7
|
-
var _react =
|
|
6
|
+
exports.usePopoverArrowNavigation = exports.useHasColumnActions = exports.isColumnActionEnabled = exports.getSortColumnActions = exports.getHideColumnAction = exports.getColumnActions = exports.getColumnActionConfig = exports.ColumnActions = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
var _tabbable = require("tabbable");
|
|
10
|
+
var _services = require("../../../../services");
|
|
8
11
|
var _i18n = require("../../../i18n");
|
|
12
|
+
var _popover = require("../../../popover");
|
|
13
|
+
var _list_group = require("../../../list_group");
|
|
14
|
+
var _button = require("../../../button");
|
|
15
|
+
var _focus = require("../../utils/focus");
|
|
9
16
|
var _data_grid_schema = require("../../utils/data_grid_schema");
|
|
10
17
|
var _column_sorting_draggable = require("../../controls/column_sorting_draggable");
|
|
18
|
+
var _data_grid_header_cell = require("./data_grid_header_cell.styles");
|
|
11
19
|
var _react2 = require("@emotion/react");
|
|
12
20
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
21
|
+
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); }
|
|
22
|
+
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; }
|
|
13
23
|
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); }
|
|
14
24
|
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; }
|
|
15
25
|
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; }
|
|
@@ -18,29 +28,243 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
18
28
|
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); }
|
|
19
29
|
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
20
30
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
21
|
-
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; } }
|
|
22
31
|
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
23
32
|
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
24
|
-
function
|
|
33
|
+
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); }
|
|
34
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
35
|
+
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."); }
|
|
36
|
+
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; } }
|
|
37
|
+
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; }
|
|
38
|
+
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; } }
|
|
39
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } /*
|
|
25
40
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
26
41
|
* or more contributor license agreements. Licensed under the Elastic License
|
|
27
42
|
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
|
28
43
|
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
|
29
44
|
* Side Public License, v 1.
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
45
|
+
*/ // Keep the i18n scope the same as EuiDataGridHeaderCell
|
|
46
|
+
/* eslint-disable local/i18n */
|
|
47
|
+
var useHasColumnActions = exports.useHasColumnActions = function useHasColumnActions(columnActions) {
|
|
48
|
+
return (0, _react.useMemo)(function () {
|
|
49
|
+
// By default, all column actions are enabled
|
|
50
|
+
if (columnActions === undefined) return true;
|
|
51
|
+
if (columnActions === false) return false;
|
|
52
|
+
if (columnActions.additional && columnActions.additional.length) return true;
|
|
53
|
+
// Check if all (currently 5) default column actions have been manually disabled
|
|
54
|
+
var disabledActions = Object.values(columnActions).filter(function (action) {
|
|
55
|
+
return action === false;
|
|
56
|
+
});
|
|
57
|
+
return disabledActions.length < 5;
|
|
58
|
+
}, [columnActions]);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// Props to pass back to EuiDataGridHeaderCell and set on EuiDataGridHeaderCellWrapper
|
|
62
|
+
|
|
63
|
+
var ColumnActions = exports.ColumnActions = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
64
|
+
var index = _ref.index,
|
|
65
|
+
id = _ref.id,
|
|
66
|
+
title = _ref.title,
|
|
67
|
+
column = _ref.column,
|
|
34
68
|
columns = _ref.columns,
|
|
35
69
|
schema = _ref.schema,
|
|
36
70
|
schemaDetectors = _ref.schemaDetectors,
|
|
37
71
|
setVisibleColumns = _ref.setVisibleColumns,
|
|
38
|
-
focusFirstVisibleInteractiveCell = _ref.focusFirstVisibleInteractiveCell,
|
|
39
|
-
setIsPopoverOpen = _ref.setIsPopoverOpen,
|
|
40
|
-
sorting = _ref.sorting,
|
|
41
72
|
switchColumnPos = _ref.switchColumnPos,
|
|
42
|
-
|
|
43
|
-
|
|
73
|
+
sorting = _ref.sorting,
|
|
74
|
+
hasFocusTrap = _ref.hasFocusTrap,
|
|
75
|
+
setPropsFromColumnActions = _ref.setPropsFromColumnActions,
|
|
76
|
+
actionsButtonRef = _ref.actionsButtonRef;
|
|
77
|
+
/**
|
|
78
|
+
* Popover logic and accessibility
|
|
79
|
+
*/
|
|
80
|
+
var _useState = (0, _react.useState)(false),
|
|
81
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
82
|
+
isPopoverOpen = _useState2[0],
|
|
83
|
+
setIsPopoverOpen = _useState2[1];
|
|
84
|
+
var togglePopover = (0, _react.useCallback)(function () {
|
|
85
|
+
setIsPopoverOpen(function (isOpen) {
|
|
86
|
+
return !isOpen;
|
|
87
|
+
});
|
|
88
|
+
}, []);
|
|
89
|
+
var closePopover = (0, _react.useCallback)(function () {
|
|
90
|
+
setIsPopoverOpen(false);
|
|
91
|
+
}, []);
|
|
92
|
+
var _useState3 = (0, _react.useState)(false),
|
|
93
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
94
|
+
isActionsButtonFocused = _useState4[0],
|
|
95
|
+
setIsActionsButtonFocused = _useState4[1];
|
|
96
|
+
var onFocus = (0, _react.useCallback)(function () {
|
|
97
|
+
return setIsActionsButtonFocused(true);
|
|
98
|
+
}, []);
|
|
99
|
+
var onBlur = (0, _react.useCallback)(function () {
|
|
100
|
+
return setIsActionsButtonFocused(false);
|
|
101
|
+
}, []);
|
|
102
|
+
var actionsButtonAriaLabel = (0, _i18n.useEuiI18n)('euiDataGridHeaderCell.actionsButtonAriaLabel', '{title}. Click to view column header actions.', {
|
|
103
|
+
title: title
|
|
104
|
+
});
|
|
105
|
+
var actionsEnterKeyInstructions = (0, _i18n.useEuiI18n)('euiDataGridHeaderCell.actionsEnterKeyInstructions', "Press the Enter key to view this column's actions");
|
|
106
|
+
var openActionsPopoverOnEnter = (0, _react.useCallback)(function (e) {
|
|
107
|
+
if (e.key === _services.keys.ENTER) {
|
|
108
|
+
setIsPopoverOpen(true);
|
|
109
|
+
}
|
|
110
|
+
}, []);
|
|
111
|
+
var popoverArrowNavigationProps = usePopoverArrowNavigation();
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Props to set on parent EuiDataGridHeaderCell
|
|
115
|
+
*/
|
|
116
|
+
var _useState5 = (0, _react.useState)(false),
|
|
117
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
118
|
+
isColumnMoving = _useState6[0],
|
|
119
|
+
setIsColumnMoving = _useState6[1];
|
|
120
|
+
(0, _react.useEffect)(function () {
|
|
121
|
+
setPropsFromColumnActions({
|
|
122
|
+
className: isPopoverOpen ? 'euiDataGridHeaderCell--isActionsPopoverOpen' : '',
|
|
123
|
+
onKeyDown: openActionsPopoverOnEnter,
|
|
124
|
+
'data-column-moving': isColumnMoving || undefined
|
|
125
|
+
});
|
|
126
|
+
}, [setPropsFromColumnActions, isPopoverOpen, openActionsPopoverOnEnter, isColumnMoving]);
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Get column actions as an array of EuiListGroup items
|
|
130
|
+
*/
|
|
131
|
+
var _useContext = (0, _react.useContext)(_focus.DataGridFocusContext),
|
|
132
|
+
setFocusedCell = _useContext.setFocusedCell,
|
|
133
|
+
focusFirstVisibleInteractiveCell = _useContext.focusFirstVisibleInteractiveCell;
|
|
134
|
+
var columnActions = (0, _react.useMemo)(function () {
|
|
135
|
+
return getColumnActions({
|
|
136
|
+
column: column,
|
|
137
|
+
columns: columns,
|
|
138
|
+
schema: schema,
|
|
139
|
+
schemaDetectors: schemaDetectors,
|
|
140
|
+
setVisibleColumns: setVisibleColumns,
|
|
141
|
+
focusFirstVisibleInteractiveCell: focusFirstVisibleInteractiveCell,
|
|
142
|
+
sorting: sorting,
|
|
143
|
+
switchColumnPos: switchColumnPos,
|
|
144
|
+
setIsPopoverOpen: setIsPopoverOpen,
|
|
145
|
+
setIsColumnMoving: setIsColumnMoving,
|
|
146
|
+
setFocusedCell: setFocusedCell,
|
|
147
|
+
columnFocusIndex: index
|
|
148
|
+
});
|
|
149
|
+
}, [column, columns, schema, schemaDetectors, setVisibleColumns, focusFirstVisibleInteractiveCell, sorting, switchColumnPos, setFocusedCell, index]);
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Rendering
|
|
153
|
+
*/
|
|
154
|
+
var styles = (0, _services.useEuiMemoizedStyles)(_data_grid_header_cell.euiDataGridHeaderCellStyles);
|
|
155
|
+
return (0, _react2.jsx)(_popover.EuiPopover, _extends({
|
|
156
|
+
display: "block",
|
|
157
|
+
panelPaddingSize: "none",
|
|
158
|
+
offset: 7,
|
|
159
|
+
anchorPosition: "downRight",
|
|
160
|
+
css: styles.euiDataGridHeaderCell__popover,
|
|
161
|
+
button: (0, _react2.jsx)(_button.EuiButtonIcon, {
|
|
162
|
+
iconType: "boxesVertical",
|
|
163
|
+
iconSize: "s",
|
|
164
|
+
color: "text",
|
|
165
|
+
css: styles.euiDataGridHeaderCell__actions,
|
|
166
|
+
className: "euiDataGridHeaderCell__button",
|
|
167
|
+
onClick: togglePopover,
|
|
168
|
+
buttonRef: actionsButtonRef,
|
|
169
|
+
onFocus: onFocus,
|
|
170
|
+
onBlur: onBlur,
|
|
171
|
+
tabIndex: 0 // Override EuiButtonIcon's conditional tabindex based on aria-hidden
|
|
172
|
+
,
|
|
173
|
+
"aria-hidden": hasFocusTrap && !isActionsButtonFocused ? 'true' // prevent the actions button from being read on cell focus
|
|
174
|
+
: undefined,
|
|
175
|
+
"aria-label": hasFocusTrap ? actionsButtonAriaLabel : actionsEnterKeyInstructions,
|
|
176
|
+
"data-test-subj": "dataGridHeaderCellActionButton-".concat(id)
|
|
177
|
+
}),
|
|
178
|
+
isOpen: isPopoverOpen,
|
|
179
|
+
closePopover: closePopover
|
|
180
|
+
}, popoverArrowNavigationProps), (0, _react2.jsx)(_list_group.EuiListGroup, {
|
|
181
|
+
listItems: columnActions,
|
|
182
|
+
gutterSize: "none",
|
|
183
|
+
"data-test-subj": "dataGridHeaderCellActionGroup-".concat(id)
|
|
184
|
+
}));
|
|
185
|
+
});
|
|
186
|
+
ColumnActions.propTypes = {
|
|
187
|
+
id: _propTypes.default.string.isRequired,
|
|
188
|
+
title: _propTypes.default.string.isRequired,
|
|
189
|
+
hasFocusTrap: _propTypes.default.bool.isRequired,
|
|
190
|
+
setPropsFromColumnActions: _propTypes.default.func.isRequired,
|
|
191
|
+
actionsButtonRef: _propTypes.default.any.isRequired
|
|
192
|
+
};
|
|
193
|
+
ColumnActions.displayName = 'EuiDataGridHeaderCellColumnActions';
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Add keyboard arrow navigation to the cell actions popover
|
|
197
|
+
* to match the UX of the rest of EuiDataGrid
|
|
198
|
+
*/
|
|
199
|
+
var usePopoverArrowNavigation = exports.usePopoverArrowNavigation = function usePopoverArrowNavigation() {
|
|
200
|
+
var popoverPanelRef = (0, _react.useRef)(null);
|
|
201
|
+
var actionsRef = (0, _react.useRef)(undefined);
|
|
202
|
+
var panelRef = (0, _react.useCallback)(function (ref) {
|
|
203
|
+
popoverPanelRef.current = ref;
|
|
204
|
+
actionsRef.current = ref ? (0, _tabbable.tabbable)(ref) : undefined;
|
|
205
|
+
}, []);
|
|
206
|
+
var onKeyDown = (0, _react.useCallback)(function (e) {
|
|
207
|
+
var _actionsRef$current;
|
|
208
|
+
if (e.key !== _services.keys.ARROW_DOWN && e.key !== _services.keys.ARROW_UP) return;
|
|
209
|
+
if (!((_actionsRef$current = actionsRef.current) !== null && _actionsRef$current !== void 0 && _actionsRef$current.length)) return;
|
|
210
|
+
e.preventDefault();
|
|
211
|
+
var initialState = document.activeElement === popoverPanelRef.current;
|
|
212
|
+
var currentIndex = !initialState ? actionsRef.current.findIndex(function (el) {
|
|
213
|
+
return document.activeElement === el;
|
|
214
|
+
}) : -1;
|
|
215
|
+
var lastIndex = actionsRef.current.length - 1;
|
|
216
|
+
var indexToFocus;
|
|
217
|
+
if (initialState) {
|
|
218
|
+
if (e.key === _services.keys.ARROW_DOWN) {
|
|
219
|
+
indexToFocus = 0;
|
|
220
|
+
} else if (e.key === _services.keys.ARROW_UP) {
|
|
221
|
+
indexToFocus = lastIndex;
|
|
222
|
+
}
|
|
223
|
+
} else {
|
|
224
|
+
if (e.key === _services.keys.ARROW_DOWN) {
|
|
225
|
+
indexToFocus = currentIndex + 1;
|
|
226
|
+
if (indexToFocus > lastIndex) {
|
|
227
|
+
indexToFocus = 0;
|
|
228
|
+
}
|
|
229
|
+
} else if (e.key === _services.keys.ARROW_UP) {
|
|
230
|
+
indexToFocus = currentIndex - 1;
|
|
231
|
+
if (indexToFocus < 0) {
|
|
232
|
+
indexToFocus = lastIndex;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
actionsRef.current[indexToFocus].focus();
|
|
237
|
+
}, []);
|
|
238
|
+
return {
|
|
239
|
+
panelRef: panelRef,
|
|
240
|
+
panelProps: {
|
|
241
|
+
onKeyDown: onKeyDown
|
|
242
|
+
},
|
|
243
|
+
popoverScreenReaderText: (0, _react2.jsx)(_i18n.EuiI18n, {
|
|
244
|
+
token: "euiDataGridHeaderCell.actionsPopoverScreenReaderText",
|
|
245
|
+
default: "To navigate through the list of column actions, press the Tab or Up and Down arrow keys."
|
|
246
|
+
})
|
|
247
|
+
};
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Logic for returning an array of actions/items to pass to EuiListGroup
|
|
252
|
+
*/
|
|
253
|
+
|
|
254
|
+
var getColumnActions = exports.getColumnActions = function getColumnActions(_ref2) {
|
|
255
|
+
var _column$actions;
|
|
256
|
+
var column = _ref2.column,
|
|
257
|
+
columns = _ref2.columns,
|
|
258
|
+
schema = _ref2.schema,
|
|
259
|
+
schemaDetectors = _ref2.schemaDetectors,
|
|
260
|
+
setVisibleColumns = _ref2.setVisibleColumns,
|
|
261
|
+
focusFirstVisibleInteractiveCell = _ref2.focusFirstVisibleInteractiveCell,
|
|
262
|
+
setIsPopoverOpen = _ref2.setIsPopoverOpen,
|
|
263
|
+
sorting = _ref2.sorting,
|
|
264
|
+
switchColumnPos = _ref2.switchColumnPos,
|
|
265
|
+
setIsColumnMoving = _ref2.setIsColumnMoving,
|
|
266
|
+
setFocusedCell = _ref2.setFocusedCell,
|
|
267
|
+
columnFocusIndex = _ref2.columnFocusIndex;
|
|
44
268
|
if (column.actions === false) {
|
|
45
269
|
return [];
|
|
46
270
|
}
|
|
@@ -58,6 +282,7 @@ var getColumnActions = exports.getColumnActions = function getColumnActions(_ref
|
|
|
58
282
|
column: column,
|
|
59
283
|
columns: columns,
|
|
60
284
|
switchColumnPos: switchColumnPos,
|
|
285
|
+
setIsColumnMoving: setIsColumnMoving,
|
|
61
286
|
setFocusedCell: setFocusedCell,
|
|
62
287
|
columnFocusIndex: columnFocusIndex
|
|
63
288
|
})), _toConsumableArray(((_column$actions = column.actions) === null || _column$actions === void 0 ? void 0 : _column$actions.additional) || []));
|
|
@@ -79,11 +304,11 @@ var getColumnActions = exports.getColumnActions = function getColumnActions(_ref
|
|
|
79
304
|
* Hide column action
|
|
80
305
|
*/
|
|
81
306
|
|
|
82
|
-
var getHideColumnAction = exports.getHideColumnAction = function getHideColumnAction(
|
|
83
|
-
var column =
|
|
84
|
-
columns =
|
|
85
|
-
setVisibleColumns =
|
|
86
|
-
focusFirstVisibleInteractiveCell =
|
|
307
|
+
var getHideColumnAction = exports.getHideColumnAction = function getHideColumnAction(_ref3) {
|
|
308
|
+
var column = _ref3.column,
|
|
309
|
+
columns = _ref3.columns,
|
|
310
|
+
setVisibleColumns = _ref3.setVisibleColumns,
|
|
311
|
+
focusFirstVisibleInteractiveCell = _ref3.focusFirstVisibleInteractiveCell;
|
|
87
312
|
var items = [];
|
|
88
313
|
var onClickHideColumn = function onClickHideColumn() {
|
|
89
314
|
setVisibleColumns(columns.filter(function (col) {
|
|
@@ -114,16 +339,25 @@ var getHideColumnAction = exports.getHideColumnAction = function getHideColumnAc
|
|
|
114
339
|
* Move column actions
|
|
115
340
|
*/
|
|
116
341
|
|
|
117
|
-
var getMoveColumnActions = function getMoveColumnActions(
|
|
118
|
-
var column =
|
|
119
|
-
columns =
|
|
120
|
-
switchColumnPos =
|
|
121
|
-
|
|
122
|
-
|
|
342
|
+
var getMoveColumnActions = function getMoveColumnActions(_ref4) {
|
|
343
|
+
var column = _ref4.column,
|
|
344
|
+
columns = _ref4.columns,
|
|
345
|
+
switchColumnPos = _ref4.switchColumnPos,
|
|
346
|
+
setIsColumnMoving = _ref4.setIsColumnMoving,
|
|
347
|
+
setFocusedCell = _ref4.setFocusedCell,
|
|
348
|
+
columnFocusIndex = _ref4.columnFocusIndex;
|
|
123
349
|
var items = [];
|
|
124
350
|
var colIdx = columns.findIndex(function (col) {
|
|
125
351
|
return col.id === column.id;
|
|
126
352
|
});
|
|
353
|
+
|
|
354
|
+
// UX polish: prevent the column actions hover animation from flashing after column move
|
|
355
|
+
var handleAnimationFlash = function handleAnimationFlash() {
|
|
356
|
+
setIsColumnMoving(true);
|
|
357
|
+
requestAnimationFrame(function () {
|
|
358
|
+
return setIsColumnMoving(false);
|
|
359
|
+
});
|
|
360
|
+
};
|
|
127
361
|
var moveFocus = function moveFocus(direction) {
|
|
128
362
|
var newIndex = direction === 'left' ? -1 : 1;
|
|
129
363
|
// Wait a beat to move focus, otherwise the EuiPopover's EuiFocusTrap's
|
|
@@ -137,6 +371,7 @@ var getMoveColumnActions = function getMoveColumnActions(_ref3) {
|
|
|
137
371
|
var targetCol = columns[colIdx - 1];
|
|
138
372
|
if (targetCol) {
|
|
139
373
|
switchColumnPos(column.id, targetCol.id);
|
|
374
|
+
handleAnimationFlash();
|
|
140
375
|
moveFocus('left');
|
|
141
376
|
}
|
|
142
377
|
};
|
|
@@ -158,6 +393,7 @@ var getMoveColumnActions = function getMoveColumnActions(_ref3) {
|
|
|
158
393
|
var targetCol = columns[colIdx + 1];
|
|
159
394
|
if (targetCol) {
|
|
160
395
|
switchColumnPos(column.id, targetCol.id);
|
|
396
|
+
handleAnimationFlash();
|
|
161
397
|
moveFocus('right');
|
|
162
398
|
}
|
|
163
399
|
};
|
|
@@ -181,11 +417,11 @@ var getMoveColumnActions = function getMoveColumnActions(_ref3) {
|
|
|
181
417
|
* Sort column actions
|
|
182
418
|
*/
|
|
183
419
|
|
|
184
|
-
var getSortColumnActions = exports.getSortColumnActions = function getSortColumnActions(
|
|
185
|
-
var column =
|
|
186
|
-
sorting =
|
|
187
|
-
schema =
|
|
188
|
-
schemaDetectors =
|
|
420
|
+
var getSortColumnActions = exports.getSortColumnActions = function getSortColumnActions(_ref5) {
|
|
421
|
+
var column = _ref5.column,
|
|
422
|
+
sorting = _ref5.sorting,
|
|
423
|
+
schema = _ref5.schema,
|
|
424
|
+
schemaDetectors = _ref5.schemaDetectors;
|
|
189
425
|
if (!sorting) return [];
|
|
190
426
|
var items = [];
|
|
191
427
|
var sortingIdx = sorting.columns.findIndex(function (col) {
|
package/lib/components/datagrid/body/header/{data_grid_column_resizer.js → column_resizer.js}
RENAMED
|
@@ -8,7 +8,8 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
8
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
9
|
var _services = require("../../../../services");
|
|
10
10
|
var _global_styling = require("../../../../global_styling");
|
|
11
|
-
var
|
|
11
|
+
var _draggable_columns = require("./draggable_columns");
|
|
12
|
+
var _column_resizer = require("./column_resizer.styles");
|
|
12
13
|
var _react2 = require("@emotion/react");
|
|
13
14
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
15
|
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); }
|
|
@@ -88,16 +89,20 @@ var EuiDataGridColumnResizer = exports.EuiDataGridColumnResizer = /*#__PURE__*/f
|
|
|
88
89
|
value: function render() {
|
|
89
90
|
var _this2 = this;
|
|
90
91
|
var offset = this.state.offset;
|
|
92
|
+
var isLastColumn = this.props.isLastColumn;
|
|
91
93
|
return (0, _react2.jsx)(_services.RenderWithEuiStylesMemoizer, null, function (stylesMemoizer) {
|
|
92
|
-
var styles = stylesMemoizer(
|
|
93
|
-
var cssStyles = [styles.euiDataGridColumnResizer, offset && styles.isDragging];
|
|
94
|
+
var styles = stylesMemoizer(_column_resizer.euiDataGridColumnResizerStyles);
|
|
95
|
+
var cssStyles = [styles.euiDataGridColumnResizer, isLastColumn && styles.isLastColumn, offset && styles.isDragging];
|
|
94
96
|
return (0, _react2.jsx)("div", {
|
|
95
97
|
css: cssStyles,
|
|
96
98
|
className: "euiDataGridColumnResizer",
|
|
97
99
|
"data-test-subj": "dataGridColumnResizer",
|
|
98
100
|
style: offset ? (0, _global_styling.logicalStyle)('margin-right', "".concat(-offset, "px")) : undefined,
|
|
99
101
|
onMouseDown: _this2.onMouseDown
|
|
100
|
-
})
|
|
102
|
+
}, (0, _react2.jsx)(_draggable_columns.DragOverlay, {
|
|
103
|
+
isDragging: !!offset,
|
|
104
|
+
cursor: "ew-resize"
|
|
105
|
+
}));
|
|
101
106
|
});
|
|
102
107
|
}
|
|
103
108
|
}]);
|
|
@@ -105,5 +110,6 @@ var EuiDataGridColumnResizer = exports.EuiDataGridColumnResizer = /*#__PURE__*/f
|
|
|
105
110
|
EuiDataGridColumnResizer.propTypes = {
|
|
106
111
|
columnId: _propTypes.default.string.isRequired,
|
|
107
112
|
columnWidth: _propTypes.default.number.isRequired,
|
|
108
|
-
setColumnWidth: _propTypes.default.func.isRequired
|
|
113
|
+
setColumnWidth: _propTypes.default.func.isRequired,
|
|
114
|
+
isLastColumn: _propTypes.default.bool.isRequired
|
|
109
115
|
};
|
|
@@ -33,7 +33,12 @@ var euiDataGridColumnResizerStyles = exports.euiDataGridColumnResizerStyles = fu
|
|
|
33
33
|
}); // Odd number because it straddles a border
|
|
34
34
|
var indicatorOffset = "-".concat(euiTheme.border.width.thin);
|
|
35
35
|
return {
|
|
36
|
-
euiDataGridColumnResizer: /*#__PURE__*/(0, _react.css)("z-index:2;position:absolute;", (0, _global_styling.logicalCSS)('vertical', 0), " ", (0, _global_styling.logicalCSS)('right', positionOffset), " cursor:ew-resize;opacity:0;&:hover,&:active{opacity:1;}&::after{content:'';position:absolute;", (0, _global_styling.logicalCSS)('vertical', 0), " ", (0, _global_styling.logicalCSS)('left', positionOffset), " ", (0, _global_styling.logicalCSS)('margin-left', indicatorOffset), " ", (0, _global_styling.logicalCSS)('width', indicatorWidth), " background-color:", euiTheme.colors.primary, ";}
|
|
36
|
+
euiDataGridColumnResizer: /*#__PURE__*/(0, _react.css)("z-index:2;position:absolute;", (0, _global_styling.logicalCSS)('vertical', 0), " ", (0, _global_styling.logicalCSS)('right', positionOffset), " cursor:ew-resize;opacity:0;&:hover,&:active{opacity:1;}&::after{content:'';position:absolute;", (0, _global_styling.logicalCSS)('vertical', 0), " ", (0, _global_styling.logicalCSS)('left', positionOffset), " ", (0, _global_styling.logicalCSS)('margin-left', indicatorOffset), " ", (0, _global_styling.logicalCSS)('width', indicatorWidth), " background-color:", euiTheme.colors.primary, ";};label:euiDataGridColumnResizer;"),
|
|
37
|
+
/* Because the resizer sits in the negative space to the right of the column,
|
|
38
|
+
* it can cause the full grid to be a few pixels longer than it actually is.
|
|
39
|
+
* So for the last cell, we don't use negative positioning and the borders from
|
|
40
|
+
* the cell will match the container. */
|
|
41
|
+
isLastColumn: /*#__PURE__*/(0, _react.css)((0, _global_styling.logicalCSS)('right', 0), " ", (0, _global_styling.logicalCSS)('width', euiTheme.size.s), " &::after{", (0, _global_styling.logicalCSS)('left', 'auto'), " ", (0, _global_styling.logicalCSS)('right', 0), ";};label:isLastColumn;"),
|
|
37
42
|
isDragging: _ref
|
|
38
43
|
};
|
|
39
44
|
};
|
|
@@ -0,0 +1,144 @@
|
|
|
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.useColumnSorting = void 0;
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
var _services = require("../../../../services");
|
|
10
|
+
var _i18n = require("../../../i18n");
|
|
11
|
+
var _icon = require("../../../icon");
|
|
12
|
+
var _react2 = require("@emotion/react");
|
|
13
|
+
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); }
|
|
14
|
+
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; }
|
|
15
|
+
/*
|
|
16
|
+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
17
|
+
* or more contributor license agreements. Licensed under the Elastic License
|
|
18
|
+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
|
19
|
+
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
|
20
|
+
* Side Public License, v 1.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
// Keep the i18n scope the same as EuiDataGridHeaderCell
|
|
24
|
+
/* eslint-disable local/i18n */
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Column sorting utility helpers
|
|
28
|
+
*/
|
|
29
|
+
var useColumnSorting = exports.useColumnSorting = function useColumnSorting(_ref) {
|
|
30
|
+
var _sorting$columns;
|
|
31
|
+
var sorting = _ref.sorting,
|
|
32
|
+
id = _ref.id,
|
|
33
|
+
hasColumnActions = _ref.hasColumnActions;
|
|
34
|
+
var sortedColumn = (0, _react.useMemo)(function () {
|
|
35
|
+
return sorting === null || sorting === void 0 ? void 0 : sorting.columns.find(function (col) {
|
|
36
|
+
return col.id === id;
|
|
37
|
+
});
|
|
38
|
+
}, [sorting, id]);
|
|
39
|
+
var isColumnSorted = !!sortedColumn;
|
|
40
|
+
var hasOnlyOneSort = (sorting === null || sorting === void 0 || (_sorting$columns = sorting.columns) === null || _sorting$columns === void 0 ? void 0 : _sorting$columns.length) === 1;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Arrow icon
|
|
44
|
+
*/
|
|
45
|
+
var sortingArrow = (0, _react.useMemo)(function () {
|
|
46
|
+
return isColumnSorted ? (0, _react2.jsx)(_icon.EuiIcon, {
|
|
47
|
+
type: sortedColumn.direction === 'asc' ? 'sortUp' : 'sortDown',
|
|
48
|
+
color: "text",
|
|
49
|
+
className: "euiDataGridHeaderCell__sortingArrow",
|
|
50
|
+
"data-test-subj": "dataGridHeaderCellSortingIcon-".concat(id)
|
|
51
|
+
}) : null;
|
|
52
|
+
}, [id, isColumnSorted, sortedColumn]);
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* aria-sort attribute - should only be used when a single column is being sorted
|
|
56
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-sort
|
|
57
|
+
* @see https://www.w3.org/WAI/ARIA/apg/example-index/table/sortable-table.html
|
|
58
|
+
* @see https://github.com/w3c/aria/issues/283 for potential future multi-column usage
|
|
59
|
+
*/
|
|
60
|
+
var ariaSort = isColumnSorted && hasOnlyOneSort ? sorting.columns[0].direction === 'asc' ? 'ascending' : 'descending' : undefined;
|
|
61
|
+
|
|
62
|
+
// aria-describedby ID for when aria-sort isn't sufficient
|
|
63
|
+
var sortingAriaId = (0, _services.useGeneratedHtmlId)({
|
|
64
|
+
prefix: 'euiDataGridCellHeader',
|
|
65
|
+
suffix: 'sorting'
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Sorting status - screen reader text
|
|
70
|
+
*/
|
|
71
|
+
var sortingScreenReaderText = (0, _react.useMemo)(function () {
|
|
72
|
+
var _sorting$columns2;
|
|
73
|
+
if (!isColumnSorted) return null;
|
|
74
|
+
if (!hasColumnActions && hasOnlyOneSort) return null; // in this scenario, the `aria-sort` attribute will be used by screen readers
|
|
75
|
+
return (0, _react2.jsx)("p", {
|
|
76
|
+
id: sortingAriaId,
|
|
77
|
+
hidden: true
|
|
78
|
+
}, sorting === null || sorting === void 0 || (_sorting$columns2 = sorting.columns) === null || _sorting$columns2 === void 0 ? void 0 : _sorting$columns2.map(function (_ref2, index) {
|
|
79
|
+
var columnId = _ref2.id,
|
|
80
|
+
direction = _ref2.direction;
|
|
81
|
+
if (hasOnlyOneSort) {
|
|
82
|
+
if (direction === 'asc') {
|
|
83
|
+
return (0, _react2.jsx)(_i18n.EuiI18n, {
|
|
84
|
+
token: "euiDataGridHeaderCell.sortedByAscendingSingle",
|
|
85
|
+
default: "Sorted ascending",
|
|
86
|
+
key: index
|
|
87
|
+
});
|
|
88
|
+
} else {
|
|
89
|
+
return (0, _react2.jsx)(_i18n.EuiI18n, {
|
|
90
|
+
token: "euiDataGridHeaderCell.sortedByDescendingSingle",
|
|
91
|
+
default: "Sorted descending",
|
|
92
|
+
key: index
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
} else if (index === 0) {
|
|
96
|
+
if (direction === 'asc') {
|
|
97
|
+
return (0, _react2.jsx)(_i18n.EuiI18n, {
|
|
98
|
+
token: "euiDataGridHeaderCell.sortedByAscendingFirst",
|
|
99
|
+
default: "Sorted by {columnId}, ascending",
|
|
100
|
+
values: {
|
|
101
|
+
columnId: columnId
|
|
102
|
+
},
|
|
103
|
+
key: index
|
|
104
|
+
});
|
|
105
|
+
} else {
|
|
106
|
+
return (0, _react2.jsx)(_i18n.EuiI18n, {
|
|
107
|
+
token: "euiDataGridHeaderCell.sortedByDescendingFirst",
|
|
108
|
+
default: "Sorted by {columnId}, descending",
|
|
109
|
+
values: {
|
|
110
|
+
columnId: columnId
|
|
111
|
+
},
|
|
112
|
+
key: index
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
} else {
|
|
116
|
+
if (direction === 'asc') {
|
|
117
|
+
return (0, _react2.jsx)(_i18n.EuiI18n, {
|
|
118
|
+
token: "euiDataGridHeaderCell.sortedByAscendingMultiple",
|
|
119
|
+
default: ", then sorted by {columnId}, ascending",
|
|
120
|
+
values: {
|
|
121
|
+
columnId: columnId
|
|
122
|
+
},
|
|
123
|
+
key: index
|
|
124
|
+
});
|
|
125
|
+
} else {
|
|
126
|
+
return (0, _react2.jsx)(_i18n.EuiI18n, {
|
|
127
|
+
token: "euiDataGridHeaderCell.sortedByDescendingMultiple",
|
|
128
|
+
default: ", then sorted by {columnId}, descending",
|
|
129
|
+
values: {
|
|
130
|
+
columnId: columnId
|
|
131
|
+
},
|
|
132
|
+
key: index
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}), ".");
|
|
137
|
+
}, [isColumnSorted, hasColumnActions, hasOnlyOneSort, sorting, sortingAriaId]);
|
|
138
|
+
return {
|
|
139
|
+
sortingArrow: sortingArrow,
|
|
140
|
+
ariaSort: ariaSort,
|
|
141
|
+
sortingAriaId: sortingAriaId,
|
|
142
|
+
sortingScreenReaderText: sortingScreenReaderText
|
|
143
|
+
};
|
|
144
|
+
};
|
|
@@ -23,7 +23,7 @@ function _extends() { return _extends = Object.assign ? Object.assign.bind() : f
|
|
|
23
23
|
var EuiDataGridControlHeaderCell = exports.EuiDataGridControlHeaderCell = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
24
24
|
var controlColumn = _ref.controlColumn,
|
|
25
25
|
index = _ref.index,
|
|
26
|
-
|
|
26
|
+
isLastColumn = _ref.isLastColumn;
|
|
27
27
|
var HeaderCellRender = controlColumn.headerCellRender,
|
|
28
28
|
headerCellProps = controlColumn.headerCellProps,
|
|
29
29
|
width = controlColumn.width,
|
|
@@ -33,12 +33,12 @@ var EuiDataGridControlHeaderCell = exports.EuiDataGridControlHeaderCell = /*#__P
|
|
|
33
33
|
id: id,
|
|
34
34
|
index: index,
|
|
35
35
|
width: width,
|
|
36
|
-
|
|
36
|
+
isLastColumn: isLastColumn
|
|
37
37
|
}), (0, _react2.jsx)(HeaderCellRender, null));
|
|
38
38
|
});
|
|
39
39
|
EuiDataGridControlHeaderCell.propTypes = {
|
|
40
40
|
index: _propTypes.default.number.isRequired,
|
|
41
|
-
|
|
41
|
+
isLastColumn: _propTypes.default.bool.isRequired,
|
|
42
42
|
controlColumn: _propTypes.default.shape({
|
|
43
43
|
/**
|
|
44
44
|
* Used as the React `key` when rendering content
|