@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
@@ -8,9 +8,10 @@ Object.defineProperty(exports, "__esModule", {
8
8
  exports.useDataGridDisplaySelector = exports.startingStyles = void 0;
9
9
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
10
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
12
11
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
12
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
13
13
  var _react = _interopRequireWildcard(require("react"));
14
+ var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
14
15
  var _global_styling = require("../../../global_styling");
15
16
  var _services = require("../../../services");
16
17
  var _i18n = require("../../i18n");
@@ -27,7 +28,8 @@ var _excluded = ["onChange"],
27
28
  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); }
28
29
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof3(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; }
29
30
  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; }
30
- 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) { (0, _defineProperty2.default)(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; } /*
31
+ 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) { (0, _defineProperty2.default)(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; }
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)."; } /*
31
33
  * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
32
34
  * or more contributor license agreements. Licensed under the Elastic License
33
35
  * 2.0 and the Server Side Public License, v 1; you may not use this file except
@@ -44,8 +46,12 @@ var startingStyles = exports.startingStyles = {
44
46
  footer: 'overline',
45
47
  stickyFooter: true
46
48
  };
49
+ var emptyRowHeightsOptions = {};
50
+
51
+ /**
52
+ * Cell density
53
+ */
47
54
 
48
- // These are the available options. They power the gridDensity hook and also the options in the render
49
55
  var densityOptions = ['compact', 'normal', 'expanded'];
50
56
  var densityStyles = {
51
57
  expanded: {
@@ -67,143 +73,274 @@ var convertGridStylesToSelection = function convertGridStylesToSelection(gridSty
67
73
  if (gridStyles.fontSize === 'l' && gridStyles.cellPadding === 'l') return 'expanded';
68
74
  return '';
69
75
  };
76
+ var DensityControl = function DensityControl(_ref) {
77
+ var gridStyles = _ref.gridStyles,
78
+ onChange = _ref.onChange;
79
+ var getDensity = (0, _react.useMemo)(function () {
80
+ return convertGridStylesToSelection(gridStyles);
81
+ }, [gridStyles]);
82
+ var setDensity = (0, _react.useCallback)(function (density) {
83
+ onChange(densityStyles[density]);
84
+ }, [onChange]);
85
+ return (0, _react2.jsx)(_i18n.EuiI18n, {
86
+ tokens: ['euiDisplaySelector.densityLabel', 'euiDisplaySelector.labelCompact', 'euiDisplaySelector.labelNormal', 'euiDisplaySelector.labelExpanded'],
87
+ defaults: ['Density', 'Compact', 'Normal', 'Expanded']
88
+ }, function (_ref2) {
89
+ var _ref3 = (0, _slicedToArray2.default)(_ref2, 4),
90
+ densityLabel = _ref3[0],
91
+ labelCompact = _ref3[1],
92
+ labelNormal = _ref3[2],
93
+ labelExpanded = _ref3[3];
94
+ return (0, _react2.jsx)(_form.EuiFormRow, {
95
+ label: densityLabel,
96
+ display: "columnCompressed"
97
+ }, (0, _react2.jsx)(_button.EuiButtonGroup, {
98
+ legend: densityLabel,
99
+ buttonSize: "compressed",
100
+ isFullWidth: true,
101
+ options: [{
102
+ id: densityOptions[0],
103
+ label: labelCompact
104
+ }, {
105
+ id: densityOptions[1],
106
+ label: labelNormal
107
+ }, {
108
+ id: densityOptions[2],
109
+ label: labelExpanded
110
+ }],
111
+ onChange: setDensity,
112
+ idSelected: getDensity,
113
+ "data-test-subj": "densityButtonGroup"
114
+ }));
115
+ });
116
+ };
117
+
118
+ /**
119
+ * Row heights
120
+ */
70
121
 
71
- // Row height options and utilities
72
- var rowHeightButtonOptions = ['undefined', 'auto', 'lineCount'];
122
+ var rowHeightSelectionOptions = ['auto', 'static'];
73
123
  var convertRowHeightsOptionsToSelection = function convertRowHeightsOptionsToSelection(rowHeightsOptions) {
74
124
  var defaultHeight = rowHeightsOptions.defaultHeight;
75
- if (defaultHeight === 'auto') {
76
- return rowHeightButtonOptions[1];
77
- }
78
- if ((0, _typeof2.default)(defaultHeight) === 'object' && defaultHeight !== null && defaultHeight !== void 0 && defaultHeight.lineCount) {
79
- return rowHeightButtonOptions[2];
80
- }
125
+
126
+ // Custom pixel row height values don't have a corresponding UI element
81
127
  if (typeof defaultHeight === 'number' || (0, _typeof2.default)(defaultHeight) === 'object' && defaultHeight.height) {
82
128
  return '';
83
129
  }
84
- return rowHeightButtonOptions[0];
130
+ if (defaultHeight === 'auto') {
131
+ return rowHeightSelectionOptions[0];
132
+ }
133
+ return rowHeightSelectionOptions[1];
134
+ };
135
+ var _ref7 = process.env.NODE_ENV === "production" ? {
136
+ name: "ueqtrq-RowHeightControl",
137
+ styles: "flex-shrink:0;flex-basis:66.6%;label:RowHeightControl;"
138
+ } : {
139
+ name: "ueqtrq-RowHeightControl",
140
+ styles: "flex-shrink:0;flex-basis:66.6%;label:RowHeightControl;",
141
+ toString: _EMOTION_STRINGIFIED_CSS_ERROR__
85
142
  };
86
- var defaultLineCountValue = String(2);
87
- var useDataGridDisplaySelector = exports.useDataGridDisplaySelector = function useDataGridDisplaySelector(showDisplaySelector, initialStyles, initialRowHeightsOptions) {
88
- var _showDisplaySelector$, _rowHeightsOptions$de2;
89
- var _useState = (0, _react.useState)(false),
143
+ var RowHeightControl = function RowHeightControl(_ref4) {
144
+ var rowHeightsOptions = _ref4.rowHeightsOptions,
145
+ onChange = _ref4.onChange;
146
+ var autoBelowLineCount = rowHeightsOptions.autoBelowLineCount;
147
+ var _useState = (0, _react.useState)(1),
90
148
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
91
- isOpen = _useState2[0],
92
- setIsOpen = _useState2[1];
93
- var showDensityControls = (0, _data_grid_toolbar.getNestedObjectOptions)(showDisplaySelector, 'allowDensity');
94
- var showRowHeightControls = (0, _data_grid_toolbar.getNestedObjectOptions)(showDisplaySelector, 'allowRowHeight');
95
- var allowResetButton = (0, _data_grid_toolbar.getNestedObjectOptions)(showDisplaySelector, 'allowResetButton');
96
- var additionalDisplaySettings = typeof showDisplaySelector === 'boolean' ? null : (_showDisplaySelector$ = showDisplaySelector === null || showDisplaySelector === void 0 ? void 0 : showDisplaySelector.additionalDisplaySettings) !== null && _showDisplaySelector$ !== void 0 ? _showDisplaySelector$ : null;
97
-
98
- // Track styles specified by the user at run time
99
- var _useState3 = (0, _react.useState)({}),
100
- _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
101
- userGridStyles = _useState4[0],
102
- setUserGridStyles = _useState4[1];
103
- var _useState5 = (0, _react.useState)({}),
104
- _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
105
- userRowHeightsOptions = _useState6[0],
106
- setUserRowHeightsOptions = _useState6[1];
107
-
108
- // Density logic
109
- var setGridStyles = (0, _react.useCallback)(function (density) {
110
- setUserGridStyles(densityStyles[density]);
111
- }, []);
149
+ lineCountInput = _useState2[0],
150
+ setLineCountInput = _useState2[1];
151
+ var setLineCountHeight = (0, _react.useCallback)(function (event) {
152
+ var newLineCount = Number(event.currentTarget.value);
153
+ setLineCountInput(newLineCount);
154
+ onChange({
155
+ rowHeights: {},
156
+ // Unset all row-specific line counts
157
+ defaultHeight: newLineCount > 1 ? {
158
+ lineCount: newLineCount
159
+ } : undefined // lineCount: 1 is the same as undefined, and this helps correctly display the reset button
160
+ });
161
+ }, [onChange]);
162
+ (0, _react.useEffect)(function () {
163
+ var passedLineCount = (0, _typeof2.default)(rowHeightsOptions === null || rowHeightsOptions === void 0 ? void 0 : rowHeightsOptions.defaultHeight) === 'object' ? rowHeightsOptions.defaultHeight.lineCount : undefined;
112
164
 
113
- // Row height logic
114
- var _useState7 = (0, _react.useState)(defaultLineCountValue),
115
- _useState8 = (0, _slicedToArray2.default)(_useState7, 2),
116
- lineCountInput = _useState8[0],
117
- setLineCountInput = _useState8[1];
165
+ // If lineCount updates come in from consumer changes, update the input to reflect that
166
+ if (passedLineCount) {
167
+ setLineCountInput(passedLineCount);
168
+ }
169
+ // If set back to undefined/single line height (typically from the reset button)
170
+ if ((rowHeightsOptions === null || rowHeightsOptions === void 0 ? void 0 : rowHeightsOptions.defaultHeight) === undefined) {
171
+ setLineCountInput(1);
172
+ }
173
+ }, [rowHeightsOptions === null || rowHeightsOptions === void 0 ? void 0 : rowHeightsOptions.defaultHeight]);
174
+ var rowHeightSelection = (0, _react.useMemo)(function () {
175
+ return convertRowHeightsOptionsToSelection(rowHeightsOptions);
176
+ }, [rowHeightsOptions]);
118
177
  var setRowHeight = (0, _react.useCallback)(function (option) {
119
178
  var rowHeightsOptions = {
120
179
  rowHeights: {} // Unset all row-specific heights
121
180
  };
122
- if (option === 'auto') {
181
+ if (option === rowHeightSelectionOptions[0]) {
123
182
  rowHeightsOptions.defaultHeight = 'auto';
124
- } else if (option === 'lineCount') {
125
- rowHeightsOptions.defaultHeight = {
126
- lineCount: Number(lineCountInput)
127
- };
128
- } else {
129
- rowHeightsOptions.defaultHeight = undefined;
130
- }
131
- setUserRowHeightsOptions(rowHeightsOptions);
132
- }, [lineCountInput]);
133
- var setLineCountHeight = (0, _react.useCallback)(function (event) {
134
- setLineCountInput(event.currentTarget.value);
135
- var newLineCount = Number(event.currentTarget.value);
136
-
137
- // Don't let users set a 0 or negative line count
138
- if (newLineCount > 0) {
139
- setUserRowHeightsOptions({
140
- rowHeights: {},
141
- // Unset all row-specific line counts
142
- defaultHeight: {
143
- lineCount: newLineCount
144
- }
145
- });
183
+ } else if (option === rowHeightSelectionOptions[1]) {
184
+ var lineCount = Number(lineCountInput);
185
+ if (lineCount > 1) {
186
+ rowHeightsOptions.defaultHeight = {
187
+ lineCount: lineCount
188
+ };
189
+ } else {
190
+ // lineCount: 1 is the same as single/undefined
191
+ rowHeightsOptions.defaultHeight = undefined;
192
+ }
146
193
  }
147
- }, []);
194
+ onChange(rowHeightsOptions);
195
+ }, [lineCountInput, onChange]);
196
+ return (0, _react2.jsx)(_i18n.EuiI18n, {
197
+ tokens: ['euiDisplaySelector.rowHeightLabel', 'euiDisplaySelector.labelAuto', 'euiDisplaySelector.labelStatic', 'euiDisplaySelector.labelMax'],
198
+ defaults: ['Lines per row', 'Auto', 'Static', 'Max']
199
+ }, function (_ref5) {
200
+ var _ref6 = (0, _slicedToArray2.default)(_ref5, 4),
201
+ rowHeightLabel = _ref6[0],
202
+ labelAuto = _ref6[1],
203
+ labelStatic = _ref6[2],
204
+ labelMax = _ref6[3];
205
+ return (0, _react2.jsx)(_form.EuiFormRow, {
206
+ label: rowHeightLabel,
207
+ display: "columnCompressed"
208
+ }, (0, _react2.jsx)(_flex.EuiFlexGroup, {
209
+ gutterSize: "s",
210
+ responsive: false
211
+ }, (0, _react2.jsx)(_button.EuiButtonGroup, {
212
+ legend: rowHeightLabel,
213
+ css: _ref7,
214
+ buttonSize: "compressed",
215
+ isFullWidth: true,
216
+ options: [{
217
+ id: rowHeightSelectionOptions[0],
218
+ label: labelAuto
219
+ }, {
220
+ id: rowHeightSelectionOptions[1],
221
+ label: autoBelowLineCount ? labelMax : labelStatic
222
+ }],
223
+ onChange: setRowHeight,
224
+ idSelected: rowHeightSelection,
225
+ "data-test-subj": "rowHeightButtonGroup"
226
+ }), (0, _react2.jsx)(_form.EuiFieldNumber, {
227
+ "aria-label": rowHeightLabel,
228
+ compressed: true,
229
+ min: 1,
230
+ max: 20,
231
+ disabled: rowHeightSelection !== rowHeightSelectionOptions[1],
232
+ value: lineCountInput,
233
+ onChange: setLineCountHeight,
234
+ "data-test-subj": "lineCountNumber"
235
+ })));
236
+ });
237
+ };
148
238
 
149
- // Merge the developer-specified configurations with user overrides
150
- var gridStyles = (0, _react.useMemo)(function () {
151
- return _objectSpread(_objectSpread({}, initialStyles), userGridStyles);
152
- }, [initialStyles, userGridStyles]);
153
- var rowHeightsOptions = (0, _react.useMemo)(function () {
154
- return _objectSpread(_objectSpread({}, initialRowHeightsOptions), userRowHeightsOptions);
155
- }, [initialRowHeightsOptions, userRowHeightsOptions]);
239
+ /**
240
+ * Display settings/selector popover
241
+ */
156
242
 
157
- // Set UI controls based on current configurations, on init & when either developer or user settings change
158
- var gridDensity = (0, _react.useMemo)(function () {
159
- return convertGridStylesToSelection(gridStyles);
160
- }, [gridStyles]);
161
- var rowHeightSelection = (0, _react.useMemo)(function () {
162
- return convertRowHeightsOptionsToSelection(rowHeightsOptions);
163
- }, [rowHeightsOptions]);
164
- (0, _react.useEffect)(function () {
165
- var _rowHeightsOptions$de;
166
- setLineCountInput(
167
- // @ts-ignore - optional chaining operator handles types & cases that aren't lineCount
168
- (rowHeightsOptions === null || rowHeightsOptions === void 0 || (_rowHeightsOptions$de = rowHeightsOptions.defaultHeight) === null || _rowHeightsOptions$de === void 0 ? void 0 : _rowHeightsOptions$de.lineCount) || defaultLineCountValue);
169
- // @ts-ignore - same as above
170
- }, [rowHeightsOptions === null || rowHeightsOptions === void 0 || (_rowHeightsOptions$de2 = rowHeightsOptions.defaultHeight) === null || _rowHeightsOptions$de2 === void 0 ? void 0 : _rowHeightsOptions$de2.lineCount]);
243
+ var useDataGridDisplaySelector = exports.useDataGridDisplaySelector = function useDataGridDisplaySelector(showDisplaySelector, passedGridStyles) {
244
+ var _showDisplaySelector$;
245
+ var passedRowHeightsOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : emptyRowHeightsOptions;
246
+ /**
247
+ * Grid style changes
248
+ */
249
+ var _useState3 = (0, _react.useState)(passedGridStyles),
250
+ _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
251
+ gridStyles = _useState4[0],
252
+ setGridStyles = _useState4[1];
171
253
 
172
- // Show a reset button whenever users manually change settings, and
173
- // invoke onChange callbacks (removing the callback value itself, so that only configuration values are returned)
174
- var _useState9 = (0, _react.useState)(false),
175
- _useState10 = (0, _slicedToArray2.default)(_useState9, 2),
176
- showResetButton = _useState10[0],
177
- setShowResetButton = _useState10[1];
254
+ // Update if consumers pass new grid style configurations
255
+ var stablePassedGridStyles = (0, _services.useDeepEqual)(passedGridStyles);
178
256
  (0, _services.useUpdateEffect)(function () {
179
- var _initialStyles$onChan;
180
- if (allowResetButton) {
181
- var hasUserChanges = Object.keys(userGridStyles).length > 0;
182
- if (hasUserChanges) setShowResetButton(true);
183
- }
184
- var onChange = gridStyles.onChange,
185
- currentGridStyles = (0, _objectWithoutProperties2.default)(gridStyles, _excluded);
186
- initialStyles === null || initialStyles === void 0 || (_initialStyles$onChan = initialStyles.onChange) === null || _initialStyles$onChan === void 0 || _initialStyles$onChan.call(initialStyles, currentGridStyles);
187
- }, [userGridStyles, allowResetButton]);
257
+ setGridStyles(stablePassedGridStyles);
258
+ }, [stablePassedGridStyles]);
259
+
260
+ // Update on user display selector change
261
+ var onUserGridStyleChange = (0, _react.useCallback)(function (styles) {
262
+ return setGridStyles(function (prevStyles) {
263
+ var changedStyles = _objectSpread(_objectSpread({}, prevStyles), styles);
264
+ var onChange = changedStyles.onChange,
265
+ rest = (0, _objectWithoutProperties2.default)(changedStyles, _excluded);
266
+ onChange === null || onChange === void 0 || onChange(rest);
267
+ return changedStyles;
268
+ });
269
+ }, []);
270
+ var densityControl = (0, _react.useMemo)(function () {
271
+ var show = (0, _data_grid_toolbar.getNestedObjectOptions)(showDisplaySelector, 'allowDensity');
272
+ return show ? (0, _react2.jsx)(DensityControl, {
273
+ gridStyles: gridStyles,
274
+ onChange: onUserGridStyleChange
275
+ }) : null;
276
+ }, [showDisplaySelector, gridStyles, onUserGridStyleChange]);
277
+
278
+ /**
279
+ * Row height changes
280
+ */
281
+ var _useState5 = (0, _react.useState)(passedRowHeightsOptions),
282
+ _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
283
+ rowHeightsOptions = _useState6[0],
284
+ setRowHeightsOptions = _useState6[1];
285
+
286
+ // Update if consumers pass new row height configurations
287
+ var stablePassedRowHeights = (0, _services.useDeepEqual)(passedRowHeightsOptions);
188
288
  (0, _services.useUpdateEffect)(function () {
189
- var _initialRowHeightsOpt;
190
- if (allowResetButton) {
191
- var hasUserChanges = Object.keys(userRowHeightsOptions).length > 0;
192
- if (hasUserChanges) setShowResetButton(true);
193
- }
194
- var onChange = rowHeightsOptions.onChange,
195
- currentRowHeightsOptions = (0, _objectWithoutProperties2.default)(rowHeightsOptions, _excluded2);
196
- initialRowHeightsOptions === null || initialRowHeightsOptions === void 0 || (_initialRowHeightsOpt = initialRowHeightsOptions.onChange) === null || _initialRowHeightsOpt === void 0 || _initialRowHeightsOpt.call(initialRowHeightsOptions, currentRowHeightsOptions);
197
- }, [userRowHeightsOptions, allowResetButton]);
289
+ setRowHeightsOptions(stablePassedRowHeights);
290
+ }, [stablePassedRowHeights]);
198
291
 
199
- // Allow resetting to initial developer-specified configurations
292
+ // Update on user display selector change
293
+ var onUserRowHeightChange = (0, _react.useCallback)(function (options) {
294
+ return setRowHeightsOptions(function (prevOptions) {
295
+ var changedOptions = _objectSpread(_objectSpread({}, prevOptions), options);
296
+ var onChange = changedOptions.onChange,
297
+ rest = (0, _objectWithoutProperties2.default)(changedOptions, _excluded2);
298
+ onChange === null || onChange === void 0 || onChange(rest);
299
+ return changedOptions;
300
+ });
301
+ }, []);
302
+ var rowHeightControl = (0, _react.useMemo)(function () {
303
+ var show = (0, _data_grid_toolbar.getNestedObjectOptions)(showDisplaySelector, 'allowRowHeight');
304
+ return show ? (0, _react2.jsx)(RowHeightControl, {
305
+ rowHeightsOptions: rowHeightsOptions,
306
+ onChange: onUserRowHeightChange
307
+ }) : null;
308
+ }, [showDisplaySelector, rowHeightsOptions, onUserRowHeightChange]);
309
+
310
+ /**
311
+ * Reset button
312
+ */
313
+ var _useState7 = (0, _react.useState)(false),
314
+ _useState8 = (0, _slicedToArray2.default)(_useState7, 2),
315
+ showResetButton = _useState8[0],
316
+ setShowResetButton = _useState8[1];
317
+ var initialGridStyles = (0, _react.useRef)(passedGridStyles);
318
+ var initialRowHeightsOptions = (0, _react.useRef)(passedRowHeightsOptions);
200
319
  var resetToInitialState = (0, _react.useCallback)(function () {
201
- setUserGridStyles({});
202
- setUserRowHeightsOptions({});
203
- setShowResetButton(false);
320
+ setGridStyles(initialGridStyles.current);
321
+ setRowHeightsOptions(initialRowHeightsOptions.current);
204
322
  }, []);
323
+ (0, _services.useUpdateEffect)(function () {
324
+ setShowResetButton(!(0, _isEqual.default)(rowHeightsOptions.defaultHeight, initialRowHeightsOptions.current.defaultHeight) || gridStyles.fontSize !== initialGridStyles.current.fontSize || gridStyles.cellPadding !== initialGridStyles.current.cellPadding);
325
+ }, [rowHeightsOptions.defaultHeight, gridStyles.fontSize, gridStyles.cellPadding]);
326
+ var resetButton = (0, _react.useMemo)(function () {
327
+ var allowed = (0, _data_grid_toolbar.getNestedObjectOptions)(showDisplaySelector, 'allowResetButton');
328
+ if (!allowed || !showResetButton) return null;
329
+ return (0, _react2.jsx)(ResetButton, {
330
+ onClick: resetToInitialState
331
+ });
332
+ }, [showDisplaySelector, showResetButton, resetToInitialState]);
333
+
334
+ /**
335
+ * Display settings popover
336
+ */
337
+ var _useState9 = (0, _react.useState)(false),
338
+ _useState10 = (0, _slicedToArray2.default)(_useState9, 2),
339
+ isOpen = _useState10[0],
340
+ setIsOpen = _useState10[1];
205
341
  var buttonLabel = (0, _i18n.useEuiI18n)('euiDisplaySelector.buttonText', 'Display options');
206
- var resetButtonLabel = (0, _i18n.useEuiI18n)('euiDisplaySelector.resetButtonText', 'Reset to default');
342
+ var additionalDisplaySettings = typeof showDisplaySelector === 'boolean' ? null : (_showDisplaySelector$ = showDisplaySelector === null || showDisplaySelector === void 0 ? void 0 : showDisplaySelector.additionalDisplaySettings) !== null && _showDisplaySelector$ !== void 0 ? _showDisplaySelector$ : null;
343
+ var customRender = typeof showDisplaySelector === 'boolean' ? undefined : showDisplaySelector === null || showDisplaySelector === void 0 ? void 0 : showDisplaySelector.customRender;
207
344
  var euiTheme = (0, _services.useEuiTheme)();
208
345
  var displaySelector = (0, _react.useMemo)(function () {
209
346
  var paddingSize = 's';
@@ -211,7 +348,7 @@ var useDataGridDisplaySelector = exports.useDataGridDisplaySelector = function u
211
348
  var popoverWidth = (0, _global_styling.mathWithUnits)([formMaxWidth, euiTheme.euiTheme.size[paddingSize]], function (x, y) {
212
349
  return x + y * 2;
213
350
  });
214
- return showDensityControls || showRowHeightControls || additionalDisplaySettings ? (0, _react2.jsx)(_popover.EuiPopover, {
351
+ return densityControl || rowHeightControl || additionalDisplaySettings ? (0, _react2.jsx)(_popover.EuiPopover, {
215
352
  "data-test-subj": "dataGridDisplaySelectorPopover",
216
353
  isOpen: isOpen,
217
354
  closePopover: function closePopover() {
@@ -236,92 +373,25 @@ var useDataGridDisplaySelector = exports.useDataGridDisplaySelector = function u
236
373
  },
237
374
  "aria-label": buttonLabel
238
375
  }))
239
- }, showDensityControls && (0, _react2.jsx)(_i18n.EuiI18n, {
240
- tokens: ['euiDisplaySelector.densityLabel', 'euiDisplaySelector.labelCompact', 'euiDisplaySelector.labelNormal', 'euiDisplaySelector.labelExpanded'],
241
- defaults: ['Density', 'Compact', 'Normal', 'Expanded']
242
- }, function (_ref) {
243
- var _ref2 = (0, _slicedToArray2.default)(_ref, 4),
244
- densityLabel = _ref2[0],
245
- labelCompact = _ref2[1],
246
- labelNormal = _ref2[2],
247
- labelExpanded = _ref2[3];
248
- return (0, _react2.jsx)(_form.EuiFormRow, {
249
- label: densityLabel,
250
- display: "columnCompressed"
251
- }, (0, _react2.jsx)(_button.EuiButtonGroup, {
252
- legend: densityLabel,
253
- buttonSize: "compressed",
254
- isFullWidth: true,
255
- options: [{
256
- id: densityOptions[0],
257
- label: labelCompact
258
- }, {
259
- id: densityOptions[1],
260
- label: labelNormal
261
- }, {
262
- id: densityOptions[2],
263
- label: labelExpanded
264
- }],
265
- onChange: setGridStyles,
266
- idSelected: gridDensity,
267
- "data-test-subj": "densityButtonGroup"
268
- }));
269
- }), showRowHeightControls && (0, _react2.jsx)(_i18n.EuiI18n, {
270
- tokens: ['euiDisplaySelector.rowHeightLabel', 'euiDisplaySelector.labelSingle', 'euiDisplaySelector.labelAuto', 'euiDisplaySelector.labelCustom', 'euiDisplaySelector.lineCountLabel'],
271
- defaults: ['Row height', 'Single', 'Auto fit', 'Custom', 'Lines per row']
272
- }, function (_ref3) {
273
- var _ref4 = (0, _slicedToArray2.default)(_ref3, 5),
274
- rowHeightLabel = _ref4[0],
275
- labelSingle = _ref4[1],
276
- labelAuto = _ref4[2],
277
- labelCustom = _ref4[3],
278
- lineCountLabel = _ref4[4];
279
- return (0, _react2.jsx)(_react.default.Fragment, null, (0, _react2.jsx)(_form.EuiFormRow, {
280
- label: rowHeightLabel,
281
- display: "columnCompressed"
282
- }, (0, _react2.jsx)(_button.EuiButtonGroup, {
283
- legend: rowHeightLabel,
284
- buttonSize: "compressed",
285
- isFullWidth: true,
286
- options: [{
287
- id: rowHeightButtonOptions[0],
288
- label: labelSingle
289
- }, {
290
- id: rowHeightButtonOptions[1],
291
- label: labelAuto
292
- }, {
293
- id: rowHeightButtonOptions[2],
294
- label: labelCustom
295
- }],
296
- onChange: setRowHeight,
297
- idSelected: rowHeightSelection,
298
- "data-test-subj": "rowHeightButtonGroup"
299
- })), rowHeightSelection === rowHeightButtonOptions[2] && (0, _react2.jsx)(_form.EuiFormRow, {
300
- label: lineCountLabel,
301
- display: "columnCompressed"
302
- }, (0, _react2.jsx)(_form.EuiRange, {
303
- compressed: true,
304
- fullWidth: true,
305
- showInput: true,
306
- min: 1,
307
- max: 20,
308
- step: 1,
309
- required: true,
310
- value: lineCountInput,
311
- onChange: setLineCountHeight,
312
- "data-test-subj": "lineCountNumber"
313
- })));
314
- }), additionalDisplaySettings, showResetButton && (0, _react2.jsx)(_popover.EuiPopoverFooter, null, (0, _react2.jsx)(_flex.EuiFlexGroup, {
315
- justifyContent: "flexEnd",
316
- responsive: false
317
- }, (0, _react2.jsx)(_flex.EuiFlexItem, {
318
- grow: false
319
- }, (0, _react2.jsx)("div", null, (0, _react2.jsx)(_button.EuiButtonEmpty, {
320
- flush: "both",
321
- size: "xs",
322
- onClick: resetToInitialState,
323
- "data-test-subj": "resetDisplaySelector"
324
- }, resetButtonLabel)))))) : null;
325
- }, [euiTheme, additionalDisplaySettings, buttonLabel, isOpen, resetButtonLabel, showDensityControls, showResetButton, showRowHeightControls, gridDensity, rowHeightSelection, lineCountInput, setGridStyles, setRowHeight, setLineCountHeight, resetToInitialState]);
376
+ }, customRender ? customRender({
377
+ densityControl: densityControl,
378
+ rowHeightControl: rowHeightControl,
379
+ additionalDisplaySettings: additionalDisplaySettings,
380
+ resetButton: resetButton
381
+ }) : (0, _react2.jsx)(_react.default.Fragment, null, densityControl, rowHeightControl, additionalDisplaySettings, resetButton)) : null;
382
+ }, [euiTheme, densityControl, rowHeightControl, additionalDisplaySettings, resetButton, customRender, buttonLabel, isOpen]);
326
383
  return [displaySelector, gridStyles, rowHeightsOptions];
384
+ };
385
+ var ResetButton = function ResetButton(_ref8) {
386
+ var onClick = _ref8.onClick;
387
+ var resetButtonLabel = (0, _i18n.useEuiI18n)('euiDisplaySelector.resetButtonText', 'Reset to default');
388
+ return (0, _react2.jsx)(_popover.EuiPopoverFooter, null, (0, _react2.jsx)(_flex.EuiFlexGroup, {
389
+ justifyContent: "flexEnd",
390
+ responsive: false
391
+ }, (0, _react2.jsx)(_button.EuiButtonEmpty, {
392
+ flush: "both",
393
+ size: "xs",
394
+ onClick: onClick,
395
+ "data-test-subj": "resetDisplaySelector"
396
+ }, resetButtonLabel)));
327
397
  };
@@ -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;");
@@ -109,7 +109,7 @@ var useUnconstrainedHeight = exports.useUnconstrainedHeight = function useUncons
109
109
  if (rowHeightOption) {
110
110
  // this row's height is known
111
111
  knownRowCount++;
112
- knownHeight += rowHeightUtils.getCalculatedHeight(rowHeightOption, defaultRowHeight, correctRowIndex, rowHeightUtils.isRowHeightOverride(correctRowIndex, rowHeightsOptions));
112
+ knownHeight += rowHeightUtils.getCalculatedHeight(rowHeightOption, defaultRowHeight, correctRowIndex, rowHeightsOptions);
113
113
  }
114
114
  }
115
115