@elastic/eui 97.2.0 → 97.3.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 (64) hide show
  1. package/es/components/context_menu/context_menu_panel.js +17 -1
  2. package/es/components/datagrid/body/cell/data_grid_cell.js +31 -8
  3. package/es/components/datagrid/body/data_grid_body.js +8 -0
  4. package/es/components/datagrid/body/data_grid_body_custom.js +8 -1
  5. package/es/components/datagrid/body/data_grid_body_virtualized.js +8 -1
  6. package/es/components/datagrid/controls/data_grid_toolbar.styles.js +2 -2
  7. package/es/components/datagrid/controls/display_selector.js +277 -207
  8. package/es/components/datagrid/data_grid.stories.utils.js +28 -2
  9. package/es/components/datagrid/data_grid.styles.js +1 -1
  10. package/es/components/datagrid/utils/grid_height_width.js +1 -1
  11. package/es/components/datagrid/utils/row_heights.js +29 -13
  12. package/es/components/header/header.styles.js +8 -1
  13. package/es/services/hooks/useDeepEqual.js +18 -6
  14. package/eui.d.ts +38 -10
  15. package/i18ntokens.json +88 -106
  16. package/lib/components/context_menu/context_menu_panel.js +17 -1
  17. package/lib/components/datagrid/body/cell/data_grid_cell.js +31 -8
  18. package/lib/components/datagrid/body/data_grid_body.js +8 -0
  19. package/lib/components/datagrid/body/data_grid_body_custom.js +8 -1
  20. package/lib/components/datagrid/body/data_grid_body_virtualized.js +8 -1
  21. package/lib/components/datagrid/controls/data_grid_toolbar.styles.js +2 -2
  22. package/lib/components/datagrid/controls/display_selector.js +275 -204
  23. package/lib/components/datagrid/data_grid.stories.utils.js +28 -2
  24. package/lib/components/datagrid/data_grid.styles.js +1 -1
  25. package/lib/components/datagrid/utils/grid_height_width.js +1 -1
  26. package/lib/components/datagrid/utils/row_heights.js +29 -13
  27. package/lib/components/header/header.styles.js +8 -1
  28. package/lib/services/hooks/useDeepEqual.js +17 -7
  29. package/optimize/es/components/context_menu/context_menu_panel.js +11 -1
  30. package/optimize/es/components/datagrid/body/cell/data_grid_cell.js +15 -8
  31. package/optimize/es/components/datagrid/body/data_grid_body_custom.js +0 -1
  32. package/optimize/es/components/datagrid/body/data_grid_body_virtualized.js +0 -1
  33. package/optimize/es/components/datagrid/controls/data_grid_toolbar.styles.js +2 -2
  34. package/optimize/es/components/datagrid/controls/display_selector.js +277 -207
  35. package/optimize/es/components/datagrid/data_grid.styles.js +1 -1
  36. package/optimize/es/components/datagrid/utils/grid_height_width.js +1 -1
  37. package/optimize/es/components/datagrid/utils/row_heights.js +29 -13
  38. package/optimize/es/components/header/header.styles.js +8 -1
  39. package/optimize/es/services/hooks/useDeepEqual.js +13 -6
  40. package/optimize/lib/components/context_menu/context_menu_panel.js +11 -1
  41. package/optimize/lib/components/datagrid/body/cell/data_grid_cell.js +15 -8
  42. package/optimize/lib/components/datagrid/body/data_grid_body_custom.js +0 -1
  43. package/optimize/lib/components/datagrid/body/data_grid_body_virtualized.js +0 -1
  44. package/optimize/lib/components/datagrid/controls/data_grid_toolbar.styles.js +2 -2
  45. package/optimize/lib/components/datagrid/controls/display_selector.js +274 -204
  46. package/optimize/lib/components/datagrid/data_grid.styles.js +1 -1
  47. package/optimize/lib/components/datagrid/utils/grid_height_width.js +1 -1
  48. package/optimize/lib/components/datagrid/utils/row_heights.js +29 -13
  49. package/optimize/lib/components/header/header.styles.js +8 -1
  50. package/optimize/lib/services/hooks/useDeepEqual.js +12 -5
  51. package/package.json +1 -1
  52. package/test-env/components/context_menu/context_menu_panel.js +17 -1
  53. package/test-env/components/datagrid/body/cell/data_grid_cell.js +31 -8
  54. package/test-env/components/datagrid/body/data_grid_body.js +8 -0
  55. package/test-env/components/datagrid/body/data_grid_body_custom.js +8 -1
  56. package/test-env/components/datagrid/body/data_grid_body_virtualized.js +8 -1
  57. package/test-env/components/datagrid/controls/data_grid_toolbar.styles.js +2 -2
  58. package/test-env/components/datagrid/controls/display_selector.js +274 -204
  59. package/test-env/components/datagrid/data_grid.stories.utils.js +28 -2
  60. package/test-env/components/datagrid/data_grid.styles.js +1 -1
  61. package/test-env/components/datagrid/utils/grid_height_width.js +1 -1
  62. package/test-env/components/datagrid/utils/row_heights.js +29 -13
  63. package/test-env/components/header/header.styles.js +8 -1
  64. package/test-env/services/hooks/useDeepEqual.js +12 -5
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.useDataGridDisplaySelector = exports.startingStyles = void 0;
7
7
  var _react = _interopRequireWildcard(require("react"));
8
+ var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
8
9
  var _global_styling = require("../../../global_styling");
9
10
  var _services = require("../../../services");
10
11
  var _i18n = require("../../i18n");
@@ -18,6 +19,7 @@ var _data_grid_toolbar = require("./data_grid_toolbar");
18
19
  var _react2 = require("@emotion/react");
19
20
  var _excluded = ["onChange"],
20
21
  _excluded2 = ["onChange"];
22
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
21
23
  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
24
  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; }
23
25
  function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], t.indexOf(o) >= 0 || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
@@ -27,13 +29,14 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
27
29
  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; }
28
30
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
29
31
  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); }
32
+ function _EMOTION_STRINGIFIED_CSS_ERROR__() { return "You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."; }
33
+ 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); }
30
34
  function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
31
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."); }
32
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; } }
33
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; }
34
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; } }
35
- function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
36
- 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); } /*
39
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } /*
37
40
  * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
38
41
  * or more contributor license agreements. Licensed under the Elastic License
39
42
  * 2.0 and the Server Side Public License, v 1; you may not use this file except
@@ -50,8 +53,12 @@ var startingStyles = exports.startingStyles = {
50
53
  footer: 'overline',
51
54
  stickyFooter: true
52
55
  };
56
+ var emptyRowHeightsOptions = {};
57
+
58
+ /**
59
+ * Cell density
60
+ */
53
61
 
54
- // These are the available options. They power the gridDensity hook and also the options in the render
55
62
  var densityOptions = ['compact', 'normal', 'expanded'];
56
63
  var densityStyles = {
57
64
  expanded: {
@@ -73,143 +80,274 @@ var convertGridStylesToSelection = function convertGridStylesToSelection(gridSty
73
80
  if (gridStyles.fontSize === 'l' && gridStyles.cellPadding === 'l') return 'expanded';
74
81
  return '';
75
82
  };
83
+ var DensityControl = function DensityControl(_ref) {
84
+ var gridStyles = _ref.gridStyles,
85
+ onChange = _ref.onChange;
86
+ var getDensity = (0, _react.useMemo)(function () {
87
+ return convertGridStylesToSelection(gridStyles);
88
+ }, [gridStyles]);
89
+ var setDensity = (0, _react.useCallback)(function (density) {
90
+ onChange(densityStyles[density]);
91
+ }, [onChange]);
92
+ return (0, _react2.jsx)(_i18n.EuiI18n, {
93
+ tokens: ['euiDisplaySelector.densityLabel', 'euiDisplaySelector.labelCompact', 'euiDisplaySelector.labelNormal', 'euiDisplaySelector.labelExpanded'],
94
+ defaults: ['Density', 'Compact', 'Normal', 'Expanded']
95
+ }, function (_ref2) {
96
+ var _ref3 = _slicedToArray(_ref2, 4),
97
+ densityLabel = _ref3[0],
98
+ labelCompact = _ref3[1],
99
+ labelNormal = _ref3[2],
100
+ labelExpanded = _ref3[3];
101
+ return (0, _react2.jsx)(_form.EuiFormRow, {
102
+ label: densityLabel,
103
+ display: "columnCompressed"
104
+ }, (0, _react2.jsx)(_button.EuiButtonGroup, {
105
+ legend: densityLabel,
106
+ buttonSize: "compressed",
107
+ isFullWidth: true,
108
+ options: [{
109
+ id: densityOptions[0],
110
+ label: labelCompact
111
+ }, {
112
+ id: densityOptions[1],
113
+ label: labelNormal
114
+ }, {
115
+ id: densityOptions[2],
116
+ label: labelExpanded
117
+ }],
118
+ onChange: setDensity,
119
+ idSelected: getDensity,
120
+ "data-test-subj": "densityButtonGroup"
121
+ }));
122
+ });
123
+ };
76
124
 
77
- // Row height options and utilities
78
- var rowHeightButtonOptions = ['undefined', 'auto', 'lineCount'];
125
+ /**
126
+ * Row heights
127
+ */
128
+
129
+ var rowHeightSelectionOptions = ['auto', 'static'];
79
130
  var convertRowHeightsOptionsToSelection = function convertRowHeightsOptionsToSelection(rowHeightsOptions) {
80
131
  var defaultHeight = rowHeightsOptions.defaultHeight;
81
- if (defaultHeight === 'auto') {
82
- return rowHeightButtonOptions[1];
83
- }
84
- if (_typeof(defaultHeight) === 'object' && defaultHeight !== null && defaultHeight !== void 0 && defaultHeight.lineCount) {
85
- return rowHeightButtonOptions[2];
86
- }
132
+
133
+ // Custom pixel row height values don't have a corresponding UI element
87
134
  if (typeof defaultHeight === 'number' || _typeof(defaultHeight) === 'object' && defaultHeight.height) {
88
135
  return '';
89
136
  }
90
- return rowHeightButtonOptions[0];
137
+ if (defaultHeight === 'auto') {
138
+ return rowHeightSelectionOptions[0];
139
+ }
140
+ return rowHeightSelectionOptions[1];
141
+ };
142
+ var _ref7 = process.env.NODE_ENV === "production" ? {
143
+ name: "ueqtrq-RowHeightControl",
144
+ styles: "flex-shrink:0;flex-basis:66.6%;label:RowHeightControl;"
145
+ } : {
146
+ name: "ueqtrq-RowHeightControl",
147
+ styles: "flex-shrink:0;flex-basis:66.6%;label:RowHeightControl;",
148
+ toString: _EMOTION_STRINGIFIED_CSS_ERROR__
91
149
  };
92
- var defaultLineCountValue = String(2);
93
- var useDataGridDisplaySelector = exports.useDataGridDisplaySelector = function useDataGridDisplaySelector(showDisplaySelector, initialStyles, initialRowHeightsOptions) {
94
- var _showDisplaySelector$, _rowHeightsOptions$de2;
95
- var _useState = (0, _react.useState)(false),
150
+ var RowHeightControl = function RowHeightControl(_ref4) {
151
+ var rowHeightsOptions = _ref4.rowHeightsOptions,
152
+ onChange = _ref4.onChange;
153
+ var autoBelowLineCount = rowHeightsOptions.autoBelowLineCount;
154
+ var _useState = (0, _react.useState)(1),
96
155
  _useState2 = _slicedToArray(_useState, 2),
97
- isOpen = _useState2[0],
98
- setIsOpen = _useState2[1];
99
- var showDensityControls = (0, _data_grid_toolbar.getNestedObjectOptions)(showDisplaySelector, 'allowDensity');
100
- var showRowHeightControls = (0, _data_grid_toolbar.getNestedObjectOptions)(showDisplaySelector, 'allowRowHeight');
101
- var allowResetButton = (0, _data_grid_toolbar.getNestedObjectOptions)(showDisplaySelector, 'allowResetButton');
102
- var additionalDisplaySettings = typeof showDisplaySelector === 'boolean' ? null : (_showDisplaySelector$ = showDisplaySelector === null || showDisplaySelector === void 0 ? void 0 : showDisplaySelector.additionalDisplaySettings) !== null && _showDisplaySelector$ !== void 0 ? _showDisplaySelector$ : null;
103
-
104
- // Track styles specified by the user at run time
105
- var _useState3 = (0, _react.useState)({}),
106
- _useState4 = _slicedToArray(_useState3, 2),
107
- userGridStyles = _useState4[0],
108
- setUserGridStyles = _useState4[1];
109
- var _useState5 = (0, _react.useState)({}),
110
- _useState6 = _slicedToArray(_useState5, 2),
111
- userRowHeightsOptions = _useState6[0],
112
- setUserRowHeightsOptions = _useState6[1];
113
-
114
- // Density logic
115
- var setGridStyles = (0, _react.useCallback)(function (density) {
116
- setUserGridStyles(densityStyles[density]);
117
- }, []);
156
+ lineCountInput = _useState2[0],
157
+ setLineCountInput = _useState2[1];
158
+ var setLineCountHeight = (0, _react.useCallback)(function (event) {
159
+ var newLineCount = Number(event.currentTarget.value);
160
+ setLineCountInput(newLineCount);
161
+ onChange({
162
+ rowHeights: {},
163
+ // Unset all row-specific line counts
164
+ defaultHeight: newLineCount > 1 ? {
165
+ lineCount: newLineCount
166
+ } : undefined // lineCount: 1 is the same as undefined, and this helps correctly display the reset button
167
+ });
168
+ }, [onChange]);
169
+ (0, _react.useEffect)(function () {
170
+ var passedLineCount = _typeof(rowHeightsOptions === null || rowHeightsOptions === void 0 ? void 0 : rowHeightsOptions.defaultHeight) === 'object' ? rowHeightsOptions.defaultHeight.lineCount : undefined;
118
171
 
119
- // Row height logic
120
- var _useState7 = (0, _react.useState)(defaultLineCountValue),
121
- _useState8 = _slicedToArray(_useState7, 2),
122
- lineCountInput = _useState8[0],
123
- setLineCountInput = _useState8[1];
172
+ // If lineCount updates come in from consumer changes, update the input to reflect that
173
+ if (passedLineCount) {
174
+ setLineCountInput(passedLineCount);
175
+ }
176
+ // If set back to undefined/single line height (typically from the reset button)
177
+ if ((rowHeightsOptions === null || rowHeightsOptions === void 0 ? void 0 : rowHeightsOptions.defaultHeight) === undefined) {
178
+ setLineCountInput(1);
179
+ }
180
+ }, [rowHeightsOptions === null || rowHeightsOptions === void 0 ? void 0 : rowHeightsOptions.defaultHeight]);
181
+ var rowHeightSelection = (0, _react.useMemo)(function () {
182
+ return convertRowHeightsOptionsToSelection(rowHeightsOptions);
183
+ }, [rowHeightsOptions]);
124
184
  var setRowHeight = (0, _react.useCallback)(function (option) {
125
185
  var rowHeightsOptions = {
126
186
  rowHeights: {} // Unset all row-specific heights
127
187
  };
128
- if (option === 'auto') {
188
+ if (option === rowHeightSelectionOptions[0]) {
129
189
  rowHeightsOptions.defaultHeight = 'auto';
130
- } else if (option === 'lineCount') {
131
- rowHeightsOptions.defaultHeight = {
132
- lineCount: Number(lineCountInput)
133
- };
134
- } else {
135
- rowHeightsOptions.defaultHeight = undefined;
136
- }
137
- setUserRowHeightsOptions(rowHeightsOptions);
138
- }, [lineCountInput]);
139
- var setLineCountHeight = (0, _react.useCallback)(function (event) {
140
- setLineCountInput(event.currentTarget.value);
141
- var newLineCount = Number(event.currentTarget.value);
142
-
143
- // Don't let users set a 0 or negative line count
144
- if (newLineCount > 0) {
145
- setUserRowHeightsOptions({
146
- rowHeights: {},
147
- // Unset all row-specific line counts
148
- defaultHeight: {
149
- lineCount: newLineCount
150
- }
151
- });
190
+ } else if (option === rowHeightSelectionOptions[1]) {
191
+ var lineCount = Number(lineCountInput);
192
+ if (lineCount > 1) {
193
+ rowHeightsOptions.defaultHeight = {
194
+ lineCount: lineCount
195
+ };
196
+ } else {
197
+ // lineCount: 1 is the same as single/undefined
198
+ rowHeightsOptions.defaultHeight = undefined;
199
+ }
152
200
  }
153
- }, []);
201
+ onChange(rowHeightsOptions);
202
+ }, [lineCountInput, onChange]);
203
+ return (0, _react2.jsx)(_i18n.EuiI18n, {
204
+ tokens: ['euiDisplaySelector.rowHeightLabel', 'euiDisplaySelector.labelAuto', 'euiDisplaySelector.labelStatic', 'euiDisplaySelector.labelMax'],
205
+ defaults: ['Lines per row', 'Auto', 'Static', 'Max']
206
+ }, function (_ref5) {
207
+ var _ref6 = _slicedToArray(_ref5, 4),
208
+ rowHeightLabel = _ref6[0],
209
+ labelAuto = _ref6[1],
210
+ labelStatic = _ref6[2],
211
+ labelMax = _ref6[3];
212
+ return (0, _react2.jsx)(_form.EuiFormRow, {
213
+ label: rowHeightLabel,
214
+ display: "columnCompressed"
215
+ }, (0, _react2.jsx)(_flex.EuiFlexGroup, {
216
+ gutterSize: "s",
217
+ responsive: false
218
+ }, (0, _react2.jsx)(_button.EuiButtonGroup, {
219
+ legend: rowHeightLabel,
220
+ css: _ref7,
221
+ buttonSize: "compressed",
222
+ isFullWidth: true,
223
+ options: [{
224
+ id: rowHeightSelectionOptions[0],
225
+ label: labelAuto
226
+ }, {
227
+ id: rowHeightSelectionOptions[1],
228
+ label: autoBelowLineCount ? labelMax : labelStatic
229
+ }],
230
+ onChange: setRowHeight,
231
+ idSelected: rowHeightSelection,
232
+ "data-test-subj": "rowHeightButtonGroup"
233
+ }), (0, _react2.jsx)(_form.EuiFieldNumber, {
234
+ "aria-label": rowHeightLabel,
235
+ compressed: true,
236
+ min: 1,
237
+ max: 20,
238
+ disabled: rowHeightSelection !== rowHeightSelectionOptions[1],
239
+ value: lineCountInput,
240
+ onChange: setLineCountHeight,
241
+ "data-test-subj": "lineCountNumber"
242
+ })));
243
+ });
244
+ };
154
245
 
155
- // Merge the developer-specified configurations with user overrides
156
- var gridStyles = (0, _react.useMemo)(function () {
157
- return _objectSpread(_objectSpread({}, initialStyles), userGridStyles);
158
- }, [initialStyles, userGridStyles]);
159
- var rowHeightsOptions = (0, _react.useMemo)(function () {
160
- return _objectSpread(_objectSpread({}, initialRowHeightsOptions), userRowHeightsOptions);
161
- }, [initialRowHeightsOptions, userRowHeightsOptions]);
246
+ /**
247
+ * Display settings/selector popover
248
+ */
162
249
 
163
- // Set UI controls based on current configurations, on init & when either developer or user settings change
164
- var gridDensity = (0, _react.useMemo)(function () {
165
- return convertGridStylesToSelection(gridStyles);
166
- }, [gridStyles]);
167
- var rowHeightSelection = (0, _react.useMemo)(function () {
168
- return convertRowHeightsOptionsToSelection(rowHeightsOptions);
169
- }, [rowHeightsOptions]);
170
- (0, _react.useEffect)(function () {
171
- var _rowHeightsOptions$de;
172
- setLineCountInput(
173
- // @ts-ignore - optional chaining operator handles types & cases that aren't lineCount
174
- (rowHeightsOptions === null || rowHeightsOptions === void 0 || (_rowHeightsOptions$de = rowHeightsOptions.defaultHeight) === null || _rowHeightsOptions$de === void 0 ? void 0 : _rowHeightsOptions$de.lineCount) || defaultLineCountValue);
175
- // @ts-ignore - same as above
176
- }, [rowHeightsOptions === null || rowHeightsOptions === void 0 || (_rowHeightsOptions$de2 = rowHeightsOptions.defaultHeight) === null || _rowHeightsOptions$de2 === void 0 ? void 0 : _rowHeightsOptions$de2.lineCount]);
250
+ var useDataGridDisplaySelector = exports.useDataGridDisplaySelector = function useDataGridDisplaySelector(showDisplaySelector, passedGridStyles) {
251
+ var _showDisplaySelector$;
252
+ var passedRowHeightsOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : emptyRowHeightsOptions;
253
+ /**
254
+ * Grid style changes
255
+ */
256
+ var _useState3 = (0, _react.useState)(passedGridStyles),
257
+ _useState4 = _slicedToArray(_useState3, 2),
258
+ gridStyles = _useState4[0],
259
+ setGridStyles = _useState4[1];
177
260
 
178
- // Show a reset button whenever users manually change settings, and
179
- // invoke onChange callbacks (removing the callback value itself, so that only configuration values are returned)
180
- var _useState9 = (0, _react.useState)(false),
181
- _useState10 = _slicedToArray(_useState9, 2),
182
- showResetButton = _useState10[0],
183
- setShowResetButton = _useState10[1];
261
+ // Update if consumers pass new grid style configurations
262
+ var stablePassedGridStyles = (0, _services.useDeepEqual)(passedGridStyles);
184
263
  (0, _services.useUpdateEffect)(function () {
185
- var _initialStyles$onChan;
186
- if (allowResetButton) {
187
- var hasUserChanges = Object.keys(userGridStyles).length > 0;
188
- if (hasUserChanges) setShowResetButton(true);
189
- }
190
- var onChange = gridStyles.onChange,
191
- currentGridStyles = _objectWithoutProperties(gridStyles, _excluded);
192
- initialStyles === null || initialStyles === void 0 || (_initialStyles$onChan = initialStyles.onChange) === null || _initialStyles$onChan === void 0 || _initialStyles$onChan.call(initialStyles, currentGridStyles);
193
- }, [userGridStyles, allowResetButton]);
264
+ setGridStyles(stablePassedGridStyles);
265
+ }, [stablePassedGridStyles]);
266
+
267
+ // Update on user display selector change
268
+ var onUserGridStyleChange = (0, _react.useCallback)(function (styles) {
269
+ return setGridStyles(function (prevStyles) {
270
+ var changedStyles = _objectSpread(_objectSpread({}, prevStyles), styles);
271
+ var onChange = changedStyles.onChange,
272
+ rest = _objectWithoutProperties(changedStyles, _excluded);
273
+ onChange === null || onChange === void 0 || onChange(rest);
274
+ return changedStyles;
275
+ });
276
+ }, []);
277
+ var densityControl = (0, _react.useMemo)(function () {
278
+ var show = (0, _data_grid_toolbar.getNestedObjectOptions)(showDisplaySelector, 'allowDensity');
279
+ return show ? (0, _react2.jsx)(DensityControl, {
280
+ gridStyles: gridStyles,
281
+ onChange: onUserGridStyleChange
282
+ }) : null;
283
+ }, [showDisplaySelector, gridStyles, onUserGridStyleChange]);
284
+
285
+ /**
286
+ * Row height changes
287
+ */
288
+ var _useState5 = (0, _react.useState)(passedRowHeightsOptions),
289
+ _useState6 = _slicedToArray(_useState5, 2),
290
+ rowHeightsOptions = _useState6[0],
291
+ setRowHeightsOptions = _useState6[1];
292
+
293
+ // Update if consumers pass new row height configurations
294
+ var stablePassedRowHeights = (0, _services.useDeepEqual)(passedRowHeightsOptions);
194
295
  (0, _services.useUpdateEffect)(function () {
195
- var _initialRowHeightsOpt;
196
- if (allowResetButton) {
197
- var hasUserChanges = Object.keys(userRowHeightsOptions).length > 0;
198
- if (hasUserChanges) setShowResetButton(true);
199
- }
200
- var onChange = rowHeightsOptions.onChange,
201
- currentRowHeightsOptions = _objectWithoutProperties(rowHeightsOptions, _excluded2);
202
- initialRowHeightsOptions === null || initialRowHeightsOptions === void 0 || (_initialRowHeightsOpt = initialRowHeightsOptions.onChange) === null || _initialRowHeightsOpt === void 0 || _initialRowHeightsOpt.call(initialRowHeightsOptions, currentRowHeightsOptions);
203
- }, [userRowHeightsOptions, allowResetButton]);
296
+ setRowHeightsOptions(stablePassedRowHeights);
297
+ }, [stablePassedRowHeights]);
204
298
 
205
- // Allow resetting to initial developer-specified configurations
299
+ // Update on user display selector change
300
+ var onUserRowHeightChange = (0, _react.useCallback)(function (options) {
301
+ return setRowHeightsOptions(function (prevOptions) {
302
+ var changedOptions = _objectSpread(_objectSpread({}, prevOptions), options);
303
+ var onChange = changedOptions.onChange,
304
+ rest = _objectWithoutProperties(changedOptions, _excluded2);
305
+ onChange === null || onChange === void 0 || onChange(rest);
306
+ return changedOptions;
307
+ });
308
+ }, []);
309
+ var rowHeightControl = (0, _react.useMemo)(function () {
310
+ var show = (0, _data_grid_toolbar.getNestedObjectOptions)(showDisplaySelector, 'allowRowHeight');
311
+ return show ? (0, _react2.jsx)(RowHeightControl, {
312
+ rowHeightsOptions: rowHeightsOptions,
313
+ onChange: onUserRowHeightChange
314
+ }) : null;
315
+ }, [showDisplaySelector, rowHeightsOptions, onUserRowHeightChange]);
316
+
317
+ /**
318
+ * Reset button
319
+ */
320
+ var _useState7 = (0, _react.useState)(false),
321
+ _useState8 = _slicedToArray(_useState7, 2),
322
+ showResetButton = _useState8[0],
323
+ setShowResetButton = _useState8[1];
324
+ var initialGridStyles = (0, _react.useRef)(passedGridStyles);
325
+ var initialRowHeightsOptions = (0, _react.useRef)(passedRowHeightsOptions);
206
326
  var resetToInitialState = (0, _react.useCallback)(function () {
207
- setUserGridStyles({});
208
- setUserRowHeightsOptions({});
209
- setShowResetButton(false);
327
+ setGridStyles(initialGridStyles.current);
328
+ setRowHeightsOptions(initialRowHeightsOptions.current);
210
329
  }, []);
330
+ (0, _services.useUpdateEffect)(function () {
331
+ setShowResetButton(!(0, _isEqual.default)(rowHeightsOptions.defaultHeight, initialRowHeightsOptions.current.defaultHeight) || gridStyles.fontSize !== initialGridStyles.current.fontSize || gridStyles.cellPadding !== initialGridStyles.current.cellPadding);
332
+ }, [rowHeightsOptions.defaultHeight, gridStyles.fontSize, gridStyles.cellPadding]);
333
+ var resetButton = (0, _react.useMemo)(function () {
334
+ var allowed = (0, _data_grid_toolbar.getNestedObjectOptions)(showDisplaySelector, 'allowResetButton');
335
+ if (!allowed || !showResetButton) return null;
336
+ return (0, _react2.jsx)(ResetButton, {
337
+ onClick: resetToInitialState
338
+ });
339
+ }, [showDisplaySelector, showResetButton, resetToInitialState]);
340
+
341
+ /**
342
+ * Display settings popover
343
+ */
344
+ var _useState9 = (0, _react.useState)(false),
345
+ _useState10 = _slicedToArray(_useState9, 2),
346
+ isOpen = _useState10[0],
347
+ setIsOpen = _useState10[1];
211
348
  var buttonLabel = (0, _i18n.useEuiI18n)('euiDisplaySelector.buttonText', 'Display options');
212
- var resetButtonLabel = (0, _i18n.useEuiI18n)('euiDisplaySelector.resetButtonText', 'Reset to default');
349
+ var additionalDisplaySettings = typeof showDisplaySelector === 'boolean' ? null : (_showDisplaySelector$ = showDisplaySelector === null || showDisplaySelector === void 0 ? void 0 : showDisplaySelector.additionalDisplaySettings) !== null && _showDisplaySelector$ !== void 0 ? _showDisplaySelector$ : null;
350
+ var customRender = typeof showDisplaySelector === 'boolean' ? undefined : showDisplaySelector === null || showDisplaySelector === void 0 ? void 0 : showDisplaySelector.customRender;
213
351
  var euiTheme = (0, _services.useEuiTheme)();
214
352
  var displaySelector = (0, _react.useMemo)(function () {
215
353
  var paddingSize = 's';
@@ -217,7 +355,7 @@ var useDataGridDisplaySelector = exports.useDataGridDisplaySelector = function u
217
355
  var popoverWidth = (0, _global_styling.mathWithUnits)([formMaxWidth, euiTheme.euiTheme.size[paddingSize]], function (x, y) {
218
356
  return x + y * 2;
219
357
  });
220
- return showDensityControls || showRowHeightControls || additionalDisplaySettings ? (0, _react2.jsx)(_popover.EuiPopover, {
358
+ return densityControl || rowHeightControl || additionalDisplaySettings ? (0, _react2.jsx)(_popover.EuiPopover, {
221
359
  "data-test-subj": "dataGridDisplaySelectorPopover",
222
360
  isOpen: isOpen,
223
361
  closePopover: function closePopover() {
@@ -242,92 +380,25 @@ var useDataGridDisplaySelector = exports.useDataGridDisplaySelector = function u
242
380
  },
243
381
  "aria-label": buttonLabel
244
382
  }))
245
- }, showDensityControls && (0, _react2.jsx)(_i18n.EuiI18n, {
246
- tokens: ['euiDisplaySelector.densityLabel', 'euiDisplaySelector.labelCompact', 'euiDisplaySelector.labelNormal', 'euiDisplaySelector.labelExpanded'],
247
- defaults: ['Density', 'Compact', 'Normal', 'Expanded']
248
- }, function (_ref) {
249
- var _ref2 = _slicedToArray(_ref, 4),
250
- densityLabel = _ref2[0],
251
- labelCompact = _ref2[1],
252
- labelNormal = _ref2[2],
253
- labelExpanded = _ref2[3];
254
- return (0, _react2.jsx)(_form.EuiFormRow, {
255
- label: densityLabel,
256
- display: "columnCompressed"
257
- }, (0, _react2.jsx)(_button.EuiButtonGroup, {
258
- legend: densityLabel,
259
- buttonSize: "compressed",
260
- isFullWidth: true,
261
- options: [{
262
- id: densityOptions[0],
263
- label: labelCompact
264
- }, {
265
- id: densityOptions[1],
266
- label: labelNormal
267
- }, {
268
- id: densityOptions[2],
269
- label: labelExpanded
270
- }],
271
- onChange: setGridStyles,
272
- idSelected: gridDensity,
273
- "data-test-subj": "densityButtonGroup"
274
- }));
275
- }), showRowHeightControls && (0, _react2.jsx)(_i18n.EuiI18n, {
276
- tokens: ['euiDisplaySelector.rowHeightLabel', 'euiDisplaySelector.labelSingle', 'euiDisplaySelector.labelAuto', 'euiDisplaySelector.labelCustom', 'euiDisplaySelector.lineCountLabel'],
277
- defaults: ['Row height', 'Single', 'Auto fit', 'Custom', 'Lines per row']
278
- }, function (_ref3) {
279
- var _ref4 = _slicedToArray(_ref3, 5),
280
- rowHeightLabel = _ref4[0],
281
- labelSingle = _ref4[1],
282
- labelAuto = _ref4[2],
283
- labelCustom = _ref4[3],
284
- lineCountLabel = _ref4[4];
285
- return (0, _react2.jsx)(_react.default.Fragment, null, (0, _react2.jsx)(_form.EuiFormRow, {
286
- label: rowHeightLabel,
287
- display: "columnCompressed"
288
- }, (0, _react2.jsx)(_button.EuiButtonGroup, {
289
- legend: rowHeightLabel,
290
- buttonSize: "compressed",
291
- isFullWidth: true,
292
- options: [{
293
- id: rowHeightButtonOptions[0],
294
- label: labelSingle
295
- }, {
296
- id: rowHeightButtonOptions[1],
297
- label: labelAuto
298
- }, {
299
- id: rowHeightButtonOptions[2],
300
- label: labelCustom
301
- }],
302
- onChange: setRowHeight,
303
- idSelected: rowHeightSelection,
304
- "data-test-subj": "rowHeightButtonGroup"
305
- })), rowHeightSelection === rowHeightButtonOptions[2] && (0, _react2.jsx)(_form.EuiFormRow, {
306
- label: lineCountLabel,
307
- display: "columnCompressed"
308
- }, (0, _react2.jsx)(_form.EuiRange, {
309
- compressed: true,
310
- fullWidth: true,
311
- showInput: true,
312
- min: 1,
313
- max: 20,
314
- step: 1,
315
- required: true,
316
- value: lineCountInput,
317
- onChange: setLineCountHeight,
318
- "data-test-subj": "lineCountNumber"
319
- })));
320
- }), additionalDisplaySettings, showResetButton && (0, _react2.jsx)(_popover.EuiPopoverFooter, null, (0, _react2.jsx)(_flex.EuiFlexGroup, {
321
- justifyContent: "flexEnd",
322
- responsive: false
323
- }, (0, _react2.jsx)(_flex.EuiFlexItem, {
324
- grow: false
325
- }, (0, _react2.jsx)("div", null, (0, _react2.jsx)(_button.EuiButtonEmpty, {
326
- flush: "both",
327
- size: "xs",
328
- onClick: resetToInitialState,
329
- "data-test-subj": "resetDisplaySelector"
330
- }, resetButtonLabel)))))) : null;
331
- }, [euiTheme, additionalDisplaySettings, buttonLabel, isOpen, resetButtonLabel, showDensityControls, showResetButton, showRowHeightControls, gridDensity, rowHeightSelection, lineCountInput, setGridStyles, setRowHeight, setLineCountHeight, resetToInitialState]);
383
+ }, customRender ? customRender({
384
+ densityControl: densityControl,
385
+ rowHeightControl: rowHeightControl,
386
+ additionalDisplaySettings: additionalDisplaySettings,
387
+ resetButton: resetButton
388
+ }) : (0, _react2.jsx)(_react.default.Fragment, null, densityControl, rowHeightControl, additionalDisplaySettings, resetButton)) : null;
389
+ }, [euiTheme, densityControl, rowHeightControl, additionalDisplaySettings, resetButton, customRender, buttonLabel, isOpen]);
332
390
  return [displaySelector, gridStyles, rowHeightsOptions];
391
+ };
392
+ var ResetButton = function ResetButton(_ref8) {
393
+ var onClick = _ref8.onClick;
394
+ var resetButtonLabel = (0, _i18n.useEuiI18n)('euiDisplaySelector.resetButtonText', 'Reset to default');
395
+ return (0, _react2.jsx)(_popover.EuiPopoverFooter, null, (0, _react2.jsx)(_flex.EuiFlexGroup, {
396
+ justifyContent: "flexEnd",
397
+ responsive: false
398
+ }, (0, _react2.jsx)(_button.EuiButtonEmpty, {
399
+ flush: "both",
400
+ size: "xs",
401
+ onClick: onClick,
402
+ "data-test-subj": "resetDisplaySelector"
403
+ }, resetButtonLabel)));
333
404
  };
@@ -1063,7 +1063,12 @@ EuiDataGridToolbarPropsComponent.propTypes = {
1063
1063
  /**
1064
1064
  * Allows appending additional content to the bottom of the display settings popover
1065
1065
  */
1066
- additionalDisplaySettings: _propTypes.default.node
1066
+ additionalDisplaySettings: _propTypes.default.node,
1067
+ /**
1068
+ * Allows completely custom rendering of the display selector popover via render prop.
1069
+ * Passes back the default controls as arguments for optional rendering.
1070
+ */
1071
+ customRender: _propTypes.default.func
1067
1072
  }).isRequired]),
1068
1073
  /**
1069
1074
  * Allows the ability for the user to sort rows based upon column values
@@ -1214,6 +1219,14 @@ EuiDataGridToolbarPropsComponent.propTypes = {
1214
1219
  lineCount: _propTypes.default.number,
1215
1220
  height: _propTypes.default.number
1216
1221
  }).isRequired]),
1222
+ /**
1223
+ * Feature flag for custom `lineCount` behavior, where `lineCount` acts like a
1224
+ * *max* number of lines (instead of a set number of lines for all rows).
1225
+ *
1226
+ * This functionality is in beta and has performance implications;
1227
+ * we do not yet fully recommend/support it for heavy production usage.
1228
+ */
1229
+ autoBelowLineCount: _propTypes.default.bool,
1217
1230
  /**
1218
1231
  * Defines the height for a specific row. It can be line count or just height.
1219
1232
  *
@@ -1273,7 +1286,12 @@ EuiDataGridToolbarPropsComponent.propTypes = {
1273
1286
  /**
1274
1287
  * Allows appending additional content to the bottom of the display settings popover
1275
1288
  */
1276
- additionalDisplaySettings: _propTypes.default.node
1289
+ additionalDisplaySettings: _propTypes.default.node,
1290
+ /**
1291
+ * Allows completely custom rendering of the display selector popover via render prop.
1292
+ * Passes back the default controls as arguments for optional rendering.
1293
+ */
1294
+ customRender: _propTypes.default.func
1277
1295
  }).isRequired]),
1278
1296
  /**
1279
1297
  * Allows the ability for the user to sort rows based upon column values
@@ -1403,6 +1421,14 @@ EuiDataGridRowHeightsPropsComponent.propTypes = {
1403
1421
  lineCount: _propTypes.default.number,
1404
1422
  height: _propTypes.default.number
1405
1423
  }).isRequired]),
1424
+ /**
1425
+ * Feature flag for custom `lineCount` behavior, where `lineCount` acts like a
1426
+ * *max* number of lines (instead of a set number of lines for all rows).
1427
+ *
1428
+ * This functionality is in beta and has performance implications;
1429
+ * we do not yet fully recommend/support it for heavy production usage.
1430
+ */
1431
+ autoBelowLineCount: _propTypes.default.bool,
1406
1432
  /**
1407
1433
  * Defines the height for a specific row. It can be line count or just height.
1408
1434
  *
@@ -53,7 +53,7 @@ var euiDataGridStyles = exports.euiDataGridStyles = function euiDataGridStyles(e
53
53
  euiDataGrid: /*#__PURE__*/(0, _react.css)("display:flex;flex-direction:column;align-items:stretch;", (0, _global_styling.logicalCSS)('height', '100%'), " overflow:hidden;*:where(& .euiDataGridRow){background-color:", euiTheme.colors.emptyShade, ";}*:where(&.euiDataGrid--stripes .euiDataGridRow--striped){background-color:", euiTheme.colors.lightestShade, ";}*:where(&.euiDataGrid--rowHoverHighlight .euiDataGridRow:hover){background-color:", euiTheme.colors.highlight, ";};label:euiDataGrid;"),
54
54
  cellPadding: {
55
55
  cellPadding: function cellPadding(size) {
56
- return /*#__PURE__*/(0, _react.css)(".euiDataGridHeaderCell,.euiDataGridRowCell__content{padding:", _cellPadding[size], ";}/* Workaround to trim line-clamp and padding - @see https://github.com/elastic/eui/issues/7780 */.euiDataGridRowCell__content--lineCountHeight{", (0, _global_styling.logicalCSS)('padding-bottom', 0), " ", (0, _global_styling.logicalCSS)('border-bottom', "".concat(_cellPadding[size], " solid transparent")), ";}.euiDataGridHeaderCell__button{margin-block:-", _cellPadding[size], ";};label:cellPadding;");
56
+ return /*#__PURE__*/(0, _react.css)(".euiDataGridHeaderCell,.euiDataGridRowCell__content{padding:", _cellPadding[size], ";}/* Workaround to trim line-clamp and padding - @see https://github.com/elastic/eui/issues/7780 */.euiDataGridRowCell__content--lineCountHeight,.euiDataGridRowCell__content--autoBelowLineCountHeight{", (0, _global_styling.logicalCSS)('padding-bottom', 0), " ", (0, _global_styling.logicalCSS)('border-bottom', "".concat(_cellPadding[size], " solid transparent")), ";}.euiDataGridHeaderCell__button{margin-block:-", _cellPadding[size], ";};label:cellPadding;");
57
57
  },
58
58
  get s() {
59
59
  return /*#__PURE__*/(0, _react.css)(this.cellPadding('s'), ";label:s;");
@@ -111,7 +111,7 @@ var useUnconstrainedHeight = exports.useUnconstrainedHeight = function useUncons
111
111
  if (rowHeightOption) {
112
112
  // this row's height is known
113
113
  knownRowCount++;
114
- knownHeight += rowHeightUtils.getCalculatedHeight(rowHeightOption, defaultRowHeight, correctRowIndex, rowHeightUtils.isRowHeightOverride(correctRowIndex, rowHeightsOptions));
114
+ knownHeight += rowHeightUtils.getCalculatedHeight(rowHeightOption, defaultRowHeight, correctRowIndex, rowHeightsOptions);
115
115
  }
116
116
  }
117
117