@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.
- package/es/components/context_menu/context_menu_panel.js +17 -1
- package/es/components/datagrid/body/cell/data_grid_cell.js +31 -8
- package/es/components/datagrid/body/data_grid_body.js +8 -0
- package/es/components/datagrid/body/data_grid_body_custom.js +8 -1
- package/es/components/datagrid/body/data_grid_body_virtualized.js +8 -1
- package/es/components/datagrid/controls/data_grid_toolbar.styles.js +2 -2
- package/es/components/datagrid/controls/display_selector.js +277 -207
- package/es/components/datagrid/data_grid.stories.utils.js +28 -2
- package/es/components/datagrid/data_grid.styles.js +1 -1
- package/es/components/datagrid/utils/grid_height_width.js +1 -1
- package/es/components/datagrid/utils/row_heights.js +29 -13
- package/es/components/header/header.styles.js +8 -1
- package/es/services/hooks/useDeepEqual.js +18 -6
- package/eui.d.ts +38 -10
- package/i18ntokens.json +88 -106
- package/lib/components/context_menu/context_menu_panel.js +17 -1
- package/lib/components/datagrid/body/cell/data_grid_cell.js +31 -8
- package/lib/components/datagrid/body/data_grid_body.js +8 -0
- package/lib/components/datagrid/body/data_grid_body_custom.js +8 -1
- package/lib/components/datagrid/body/data_grid_body_virtualized.js +8 -1
- package/lib/components/datagrid/controls/data_grid_toolbar.styles.js +2 -2
- package/lib/components/datagrid/controls/display_selector.js +275 -204
- package/lib/components/datagrid/data_grid.stories.utils.js +28 -2
- package/lib/components/datagrid/data_grid.styles.js +1 -1
- package/lib/components/datagrid/utils/grid_height_width.js +1 -1
- package/lib/components/datagrid/utils/row_heights.js +29 -13
- package/lib/components/header/header.styles.js +8 -1
- package/lib/services/hooks/useDeepEqual.js +17 -7
- package/optimize/es/components/context_menu/context_menu_panel.js +11 -1
- package/optimize/es/components/datagrid/body/cell/data_grid_cell.js +15 -8
- package/optimize/es/components/datagrid/body/data_grid_body_custom.js +0 -1
- package/optimize/es/components/datagrid/body/data_grid_body_virtualized.js +0 -1
- package/optimize/es/components/datagrid/controls/data_grid_toolbar.styles.js +2 -2
- package/optimize/es/components/datagrid/controls/display_selector.js +277 -207
- package/optimize/es/components/datagrid/data_grid.styles.js +1 -1
- package/optimize/es/components/datagrid/utils/grid_height_width.js +1 -1
- package/optimize/es/components/datagrid/utils/row_heights.js +29 -13
- package/optimize/es/components/header/header.styles.js +8 -1
- package/optimize/es/services/hooks/useDeepEqual.js +13 -6
- package/optimize/lib/components/context_menu/context_menu_panel.js +11 -1
- package/optimize/lib/components/datagrid/body/cell/data_grid_cell.js +15 -8
- package/optimize/lib/components/datagrid/body/data_grid_body_custom.js +0 -1
- package/optimize/lib/components/datagrid/body/data_grid_body_virtualized.js +0 -1
- package/optimize/lib/components/datagrid/controls/data_grid_toolbar.styles.js +2 -2
- package/optimize/lib/components/datagrid/controls/display_selector.js +274 -204
- package/optimize/lib/components/datagrid/data_grid.styles.js +1 -1
- package/optimize/lib/components/datagrid/utils/grid_height_width.js +1 -1
- package/optimize/lib/components/datagrid/utils/row_heights.js +29 -13
- package/optimize/lib/components/header/header.styles.js +8 -1
- package/optimize/lib/services/hooks/useDeepEqual.js +12 -5
- package/package.json +1 -1
- package/test-env/components/context_menu/context_menu_panel.js +17 -1
- package/test-env/components/datagrid/body/cell/data_grid_cell.js +31 -8
- package/test-env/components/datagrid/body/data_grid_body.js +8 -0
- package/test-env/components/datagrid/body/data_grid_body_custom.js +8 -1
- package/test-env/components/datagrid/body/data_grid_body_virtualized.js +8 -1
- package/test-env/components/datagrid/controls/data_grid_toolbar.styles.js +2 -2
- package/test-env/components/datagrid/controls/display_selector.js +274 -204
- package/test-env/components/datagrid/data_grid.stories.utils.js +28 -2
- package/test-env/components/datagrid/data_grid.styles.js +1 -1
- package/test-env/components/datagrid/utils/grid_height_width.js +1 -1
- package/test-env/components/datagrid/utils/row_heights.js +29 -13
- package/test-env/components/header/header.styles.js +8 -1
- package/test-env/services/hooks/useDeepEqual.js +12 -5
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
2
2
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
4
3
|
import _typeof from "@babel/runtime/helpers/typeof";
|
|
4
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
5
5
|
var _excluded = ["onChange"],
|
|
6
6
|
_excluded2 = ["onChange"];
|
|
7
7
|
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; }
|
|
8
8
|
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; }
|
|
9
|
+
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)."; }
|
|
9
10
|
/*
|
|
10
11
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
11
12
|
* or more contributor license agreements. Licensed under the Elastic License
|
|
@@ -14,15 +15,16 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
14
15
|
* Side Public License, v 1.
|
|
15
16
|
*/
|
|
16
17
|
|
|
17
|
-
import React, { useState, useMemo, useCallback, useEffect } from 'react';
|
|
18
|
+
import React, { useState, useMemo, useCallback, useEffect, useRef } from 'react';
|
|
19
|
+
import isEqual from 'lodash/isEqual';
|
|
18
20
|
import { logicalStyle, mathWithUnits } from '../../../global_styling';
|
|
19
|
-
import { useUpdateEffect, useEuiTheme } from '../../../services';
|
|
21
|
+
import { useUpdateEffect, useDeepEqual, useEuiTheme } from '../../../services';
|
|
20
22
|
import { EuiI18n, useEuiI18n } from '../../i18n';
|
|
21
23
|
import { EuiPopover, EuiPopoverFooter } from '../../popover';
|
|
22
24
|
import { EuiButtonIcon, EuiButtonGroup, EuiButtonEmpty } from '../../button';
|
|
23
|
-
import { EuiFormRow,
|
|
25
|
+
import { EuiFormRow, EuiFieldNumber } from '../../form';
|
|
24
26
|
import { euiFormMaxWidth } from '../../form/form.styles';
|
|
25
|
-
import { EuiFlexGroup
|
|
27
|
+
import { EuiFlexGroup } from '../../flex';
|
|
26
28
|
import { EuiToolTip } from '../../tool_tip';
|
|
27
29
|
import { getNestedObjectOptions } from './data_grid_toolbar';
|
|
28
30
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
|
@@ -36,8 +38,12 @@ export var startingStyles = {
|
|
|
36
38
|
footer: 'overline',
|
|
37
39
|
stickyFooter: true
|
|
38
40
|
};
|
|
41
|
+
var emptyRowHeightsOptions = {};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Cell density
|
|
45
|
+
*/
|
|
39
46
|
|
|
40
|
-
// These are the available options. They power the gridDensity hook and also the options in the render
|
|
41
47
|
var densityOptions = ['compact', 'normal', 'expanded'];
|
|
42
48
|
var densityStyles = {
|
|
43
49
|
expanded: {
|
|
@@ -59,143 +65,274 @@ var convertGridStylesToSelection = function convertGridStylesToSelection(gridSty
|
|
|
59
65
|
if (gridStyles.fontSize === 'l' && gridStyles.cellPadding === 'l') return 'expanded';
|
|
60
66
|
return '';
|
|
61
67
|
};
|
|
68
|
+
var DensityControl = function DensityControl(_ref) {
|
|
69
|
+
var gridStyles = _ref.gridStyles,
|
|
70
|
+
onChange = _ref.onChange;
|
|
71
|
+
var getDensity = useMemo(function () {
|
|
72
|
+
return convertGridStylesToSelection(gridStyles);
|
|
73
|
+
}, [gridStyles]);
|
|
74
|
+
var setDensity = useCallback(function (density) {
|
|
75
|
+
onChange(densityStyles[density]);
|
|
76
|
+
}, [onChange]);
|
|
77
|
+
return ___EmotionJSX(EuiI18n, {
|
|
78
|
+
tokens: ['euiDisplaySelector.densityLabel', 'euiDisplaySelector.labelCompact', 'euiDisplaySelector.labelNormal', 'euiDisplaySelector.labelExpanded'],
|
|
79
|
+
defaults: ['Density', 'Compact', 'Normal', 'Expanded']
|
|
80
|
+
}, function (_ref2) {
|
|
81
|
+
var _ref3 = _slicedToArray(_ref2, 4),
|
|
82
|
+
densityLabel = _ref3[0],
|
|
83
|
+
labelCompact = _ref3[1],
|
|
84
|
+
labelNormal = _ref3[2],
|
|
85
|
+
labelExpanded = _ref3[3];
|
|
86
|
+
return ___EmotionJSX(EuiFormRow, {
|
|
87
|
+
label: densityLabel,
|
|
88
|
+
display: "columnCompressed"
|
|
89
|
+
}, ___EmotionJSX(EuiButtonGroup, {
|
|
90
|
+
legend: densityLabel,
|
|
91
|
+
buttonSize: "compressed",
|
|
92
|
+
isFullWidth: true,
|
|
93
|
+
options: [{
|
|
94
|
+
id: densityOptions[0],
|
|
95
|
+
label: labelCompact
|
|
96
|
+
}, {
|
|
97
|
+
id: densityOptions[1],
|
|
98
|
+
label: labelNormal
|
|
99
|
+
}, {
|
|
100
|
+
id: densityOptions[2],
|
|
101
|
+
label: labelExpanded
|
|
102
|
+
}],
|
|
103
|
+
onChange: setDensity,
|
|
104
|
+
idSelected: getDensity,
|
|
105
|
+
"data-test-subj": "densityButtonGroup"
|
|
106
|
+
}));
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Row heights
|
|
112
|
+
*/
|
|
62
113
|
|
|
63
|
-
|
|
64
|
-
var rowHeightButtonOptions = ['undefined', 'auto', 'lineCount'];
|
|
114
|
+
var rowHeightSelectionOptions = ['auto', 'static'];
|
|
65
115
|
var convertRowHeightsOptionsToSelection = function convertRowHeightsOptionsToSelection(rowHeightsOptions) {
|
|
66
116
|
var defaultHeight = rowHeightsOptions.defaultHeight;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
if (_typeof(defaultHeight) === 'object' && defaultHeight !== null && defaultHeight !== void 0 && defaultHeight.lineCount) {
|
|
71
|
-
return rowHeightButtonOptions[2];
|
|
72
|
-
}
|
|
117
|
+
|
|
118
|
+
// Custom pixel row height values don't have a corresponding UI element
|
|
73
119
|
if (typeof defaultHeight === 'number' || _typeof(defaultHeight) === 'object' && defaultHeight.height) {
|
|
74
120
|
return '';
|
|
75
121
|
}
|
|
76
|
-
|
|
122
|
+
if (defaultHeight === 'auto') {
|
|
123
|
+
return rowHeightSelectionOptions[0];
|
|
124
|
+
}
|
|
125
|
+
return rowHeightSelectionOptions[1];
|
|
126
|
+
};
|
|
127
|
+
var _ref7 = process.env.NODE_ENV === "production" ? {
|
|
128
|
+
name: "ueqtrq-RowHeightControl",
|
|
129
|
+
styles: "flex-shrink:0;flex-basis:66.6%;label:RowHeightControl;"
|
|
130
|
+
} : {
|
|
131
|
+
name: "ueqtrq-RowHeightControl",
|
|
132
|
+
styles: "flex-shrink:0;flex-basis:66.6%;label:RowHeightControl;",
|
|
133
|
+
toString: _EMOTION_STRINGIFIED_CSS_ERROR__
|
|
77
134
|
};
|
|
78
|
-
var
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
var
|
|
135
|
+
var RowHeightControl = function RowHeightControl(_ref4) {
|
|
136
|
+
var rowHeightsOptions = _ref4.rowHeightsOptions,
|
|
137
|
+
onChange = _ref4.onChange;
|
|
138
|
+
var autoBelowLineCount = rowHeightsOptions.autoBelowLineCount;
|
|
139
|
+
var _useState = useState(1),
|
|
82
140
|
_useState2 = _slicedToArray(_useState, 2),
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
var
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
setUserRowHeightsOptions = _useState6[1];
|
|
99
|
-
|
|
100
|
-
// Density logic
|
|
101
|
-
var setGridStyles = useCallback(function (density) {
|
|
102
|
-
setUserGridStyles(densityStyles[density]);
|
|
103
|
-
}, []);
|
|
141
|
+
lineCountInput = _useState2[0],
|
|
142
|
+
setLineCountInput = _useState2[1];
|
|
143
|
+
var setLineCountHeight = useCallback(function (event) {
|
|
144
|
+
var newLineCount = Number(event.currentTarget.value);
|
|
145
|
+
setLineCountInput(newLineCount);
|
|
146
|
+
onChange({
|
|
147
|
+
rowHeights: {},
|
|
148
|
+
// Unset all row-specific line counts
|
|
149
|
+
defaultHeight: newLineCount > 1 ? {
|
|
150
|
+
lineCount: newLineCount
|
|
151
|
+
} : undefined // lineCount: 1 is the same as undefined, and this helps correctly display the reset button
|
|
152
|
+
});
|
|
153
|
+
}, [onChange]);
|
|
154
|
+
useEffect(function () {
|
|
155
|
+
var passedLineCount = _typeof(rowHeightsOptions === null || rowHeightsOptions === void 0 ? void 0 : rowHeightsOptions.defaultHeight) === 'object' ? rowHeightsOptions.defaultHeight.lineCount : undefined;
|
|
104
156
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
157
|
+
// If lineCount updates come in from consumer changes, update the input to reflect that
|
|
158
|
+
if (passedLineCount) {
|
|
159
|
+
setLineCountInput(passedLineCount);
|
|
160
|
+
}
|
|
161
|
+
// If set back to undefined/single line height (typically from the reset button)
|
|
162
|
+
if ((rowHeightsOptions === null || rowHeightsOptions === void 0 ? void 0 : rowHeightsOptions.defaultHeight) === undefined) {
|
|
163
|
+
setLineCountInput(1);
|
|
164
|
+
}
|
|
165
|
+
}, [rowHeightsOptions === null || rowHeightsOptions === void 0 ? void 0 : rowHeightsOptions.defaultHeight]);
|
|
166
|
+
var rowHeightSelection = useMemo(function () {
|
|
167
|
+
return convertRowHeightsOptionsToSelection(rowHeightsOptions);
|
|
168
|
+
}, [rowHeightsOptions]);
|
|
110
169
|
var setRowHeight = useCallback(function (option) {
|
|
111
170
|
var rowHeightsOptions = {
|
|
112
171
|
rowHeights: {} // Unset all row-specific heights
|
|
113
172
|
};
|
|
114
|
-
if (option ===
|
|
173
|
+
if (option === rowHeightSelectionOptions[0]) {
|
|
115
174
|
rowHeightsOptions.defaultHeight = 'auto';
|
|
116
|
-
} else if (option ===
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
setLineCountInput(event.currentTarget.value);
|
|
127
|
-
var newLineCount = Number(event.currentTarget.value);
|
|
128
|
-
|
|
129
|
-
// Don't let users set a 0 or negative line count
|
|
130
|
-
if (newLineCount > 0) {
|
|
131
|
-
setUserRowHeightsOptions({
|
|
132
|
-
rowHeights: {},
|
|
133
|
-
// Unset all row-specific line counts
|
|
134
|
-
defaultHeight: {
|
|
135
|
-
lineCount: newLineCount
|
|
136
|
-
}
|
|
137
|
-
});
|
|
175
|
+
} else if (option === rowHeightSelectionOptions[1]) {
|
|
176
|
+
var lineCount = Number(lineCountInput);
|
|
177
|
+
if (lineCount > 1) {
|
|
178
|
+
rowHeightsOptions.defaultHeight = {
|
|
179
|
+
lineCount: lineCount
|
|
180
|
+
};
|
|
181
|
+
} else {
|
|
182
|
+
// lineCount: 1 is the same as single/undefined
|
|
183
|
+
rowHeightsOptions.defaultHeight = undefined;
|
|
184
|
+
}
|
|
138
185
|
}
|
|
139
|
-
|
|
186
|
+
onChange(rowHeightsOptions);
|
|
187
|
+
}, [lineCountInput, onChange]);
|
|
188
|
+
return ___EmotionJSX(EuiI18n, {
|
|
189
|
+
tokens: ['euiDisplaySelector.rowHeightLabel', 'euiDisplaySelector.labelAuto', 'euiDisplaySelector.labelStatic', 'euiDisplaySelector.labelMax'],
|
|
190
|
+
defaults: ['Lines per row', 'Auto', 'Static', 'Max']
|
|
191
|
+
}, function (_ref5) {
|
|
192
|
+
var _ref6 = _slicedToArray(_ref5, 4),
|
|
193
|
+
rowHeightLabel = _ref6[0],
|
|
194
|
+
labelAuto = _ref6[1],
|
|
195
|
+
labelStatic = _ref6[2],
|
|
196
|
+
labelMax = _ref6[3];
|
|
197
|
+
return ___EmotionJSX(EuiFormRow, {
|
|
198
|
+
label: rowHeightLabel,
|
|
199
|
+
display: "columnCompressed"
|
|
200
|
+
}, ___EmotionJSX(EuiFlexGroup, {
|
|
201
|
+
gutterSize: "s",
|
|
202
|
+
responsive: false
|
|
203
|
+
}, ___EmotionJSX(EuiButtonGroup, {
|
|
204
|
+
legend: rowHeightLabel,
|
|
205
|
+
css: _ref7,
|
|
206
|
+
buttonSize: "compressed",
|
|
207
|
+
isFullWidth: true,
|
|
208
|
+
options: [{
|
|
209
|
+
id: rowHeightSelectionOptions[0],
|
|
210
|
+
label: labelAuto
|
|
211
|
+
}, {
|
|
212
|
+
id: rowHeightSelectionOptions[1],
|
|
213
|
+
label: autoBelowLineCount ? labelMax : labelStatic
|
|
214
|
+
}],
|
|
215
|
+
onChange: setRowHeight,
|
|
216
|
+
idSelected: rowHeightSelection,
|
|
217
|
+
"data-test-subj": "rowHeightButtonGroup"
|
|
218
|
+
}), ___EmotionJSX(EuiFieldNumber, {
|
|
219
|
+
"aria-label": rowHeightLabel,
|
|
220
|
+
compressed: true,
|
|
221
|
+
min: 1,
|
|
222
|
+
max: 20,
|
|
223
|
+
disabled: rowHeightSelection !== rowHeightSelectionOptions[1],
|
|
224
|
+
value: lineCountInput,
|
|
225
|
+
onChange: setLineCountHeight,
|
|
226
|
+
"data-test-subj": "lineCountNumber"
|
|
227
|
+
})));
|
|
228
|
+
});
|
|
229
|
+
};
|
|
140
230
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}, [initialStyles, userGridStyles]);
|
|
145
|
-
var rowHeightsOptions = useMemo(function () {
|
|
146
|
-
return _objectSpread(_objectSpread({}, initialRowHeightsOptions), userRowHeightsOptions);
|
|
147
|
-
}, [initialRowHeightsOptions, userRowHeightsOptions]);
|
|
231
|
+
/**
|
|
232
|
+
* Display settings/selector popover
|
|
233
|
+
*/
|
|
148
234
|
|
|
149
|
-
|
|
150
|
-
var
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
// @ts-ignore - optional chaining operator handles types & cases that aren't lineCount
|
|
160
|
-
(rowHeightsOptions === null || rowHeightsOptions === void 0 || (_rowHeightsOptions$de = rowHeightsOptions.defaultHeight) === null || _rowHeightsOptions$de === void 0 ? void 0 : _rowHeightsOptions$de.lineCount) || defaultLineCountValue);
|
|
161
|
-
// @ts-ignore - same as above
|
|
162
|
-
}, [rowHeightsOptions === null || rowHeightsOptions === void 0 || (_rowHeightsOptions$de2 = rowHeightsOptions.defaultHeight) === null || _rowHeightsOptions$de2 === void 0 ? void 0 : _rowHeightsOptions$de2.lineCount]);
|
|
235
|
+
export var useDataGridDisplaySelector = function useDataGridDisplaySelector(showDisplaySelector, passedGridStyles) {
|
|
236
|
+
var _showDisplaySelector$;
|
|
237
|
+
var passedRowHeightsOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : emptyRowHeightsOptions;
|
|
238
|
+
/**
|
|
239
|
+
* Grid style changes
|
|
240
|
+
*/
|
|
241
|
+
var _useState3 = useState(passedGridStyles),
|
|
242
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
243
|
+
gridStyles = _useState4[0],
|
|
244
|
+
setGridStyles = _useState4[1];
|
|
163
245
|
|
|
164
|
-
//
|
|
165
|
-
|
|
166
|
-
var _useState9 = useState(false),
|
|
167
|
-
_useState10 = _slicedToArray(_useState9, 2),
|
|
168
|
-
showResetButton = _useState10[0],
|
|
169
|
-
setShowResetButton = _useState10[1];
|
|
246
|
+
// Update if consumers pass new grid style configurations
|
|
247
|
+
var stablePassedGridStyles = useDeepEqual(passedGridStyles);
|
|
170
248
|
useUpdateEffect(function () {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
249
|
+
setGridStyles(stablePassedGridStyles);
|
|
250
|
+
}, [stablePassedGridStyles]);
|
|
251
|
+
|
|
252
|
+
// Update on user display selector change
|
|
253
|
+
var onUserGridStyleChange = useCallback(function (styles) {
|
|
254
|
+
return setGridStyles(function (prevStyles) {
|
|
255
|
+
var changedStyles = _objectSpread(_objectSpread({}, prevStyles), styles);
|
|
256
|
+
var onChange = changedStyles.onChange,
|
|
257
|
+
rest = _objectWithoutProperties(changedStyles, _excluded);
|
|
258
|
+
onChange === null || onChange === void 0 || onChange(rest);
|
|
259
|
+
return changedStyles;
|
|
260
|
+
});
|
|
261
|
+
}, []);
|
|
262
|
+
var densityControl = useMemo(function () {
|
|
263
|
+
var show = getNestedObjectOptions(showDisplaySelector, 'allowDensity');
|
|
264
|
+
return show ? ___EmotionJSX(DensityControl, {
|
|
265
|
+
gridStyles: gridStyles,
|
|
266
|
+
onChange: onUserGridStyleChange
|
|
267
|
+
}) : null;
|
|
268
|
+
}, [showDisplaySelector, gridStyles, onUserGridStyleChange]);
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Row height changes
|
|
272
|
+
*/
|
|
273
|
+
var _useState5 = useState(passedRowHeightsOptions),
|
|
274
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
275
|
+
rowHeightsOptions = _useState6[0],
|
|
276
|
+
setRowHeightsOptions = _useState6[1];
|
|
277
|
+
|
|
278
|
+
// Update if consumers pass new row height configurations
|
|
279
|
+
var stablePassedRowHeights = useDeepEqual(passedRowHeightsOptions);
|
|
180
280
|
useUpdateEffect(function () {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
var hasUserChanges = Object.keys(userRowHeightsOptions).length > 0;
|
|
184
|
-
if (hasUserChanges) setShowResetButton(true);
|
|
185
|
-
}
|
|
186
|
-
var onChange = rowHeightsOptions.onChange,
|
|
187
|
-
currentRowHeightsOptions = _objectWithoutProperties(rowHeightsOptions, _excluded2);
|
|
188
|
-
initialRowHeightsOptions === null || initialRowHeightsOptions === void 0 || (_initialRowHeightsOpt = initialRowHeightsOptions.onChange) === null || _initialRowHeightsOpt === void 0 || _initialRowHeightsOpt.call(initialRowHeightsOptions, currentRowHeightsOptions);
|
|
189
|
-
}, [userRowHeightsOptions, allowResetButton]);
|
|
281
|
+
setRowHeightsOptions(stablePassedRowHeights);
|
|
282
|
+
}, [stablePassedRowHeights]);
|
|
190
283
|
|
|
191
|
-
//
|
|
284
|
+
// Update on user display selector change
|
|
285
|
+
var onUserRowHeightChange = useCallback(function (options) {
|
|
286
|
+
return setRowHeightsOptions(function (prevOptions) {
|
|
287
|
+
var changedOptions = _objectSpread(_objectSpread({}, prevOptions), options);
|
|
288
|
+
var onChange = changedOptions.onChange,
|
|
289
|
+
rest = _objectWithoutProperties(changedOptions, _excluded2);
|
|
290
|
+
onChange === null || onChange === void 0 || onChange(rest);
|
|
291
|
+
return changedOptions;
|
|
292
|
+
});
|
|
293
|
+
}, []);
|
|
294
|
+
var rowHeightControl = useMemo(function () {
|
|
295
|
+
var show = getNestedObjectOptions(showDisplaySelector, 'allowRowHeight');
|
|
296
|
+
return show ? ___EmotionJSX(RowHeightControl, {
|
|
297
|
+
rowHeightsOptions: rowHeightsOptions,
|
|
298
|
+
onChange: onUserRowHeightChange
|
|
299
|
+
}) : null;
|
|
300
|
+
}, [showDisplaySelector, rowHeightsOptions, onUserRowHeightChange]);
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Reset button
|
|
304
|
+
*/
|
|
305
|
+
var _useState7 = useState(false),
|
|
306
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
307
|
+
showResetButton = _useState8[0],
|
|
308
|
+
setShowResetButton = _useState8[1];
|
|
309
|
+
var initialGridStyles = useRef(passedGridStyles);
|
|
310
|
+
var initialRowHeightsOptions = useRef(passedRowHeightsOptions);
|
|
192
311
|
var resetToInitialState = useCallback(function () {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
setShowResetButton(false);
|
|
312
|
+
setGridStyles(initialGridStyles.current);
|
|
313
|
+
setRowHeightsOptions(initialRowHeightsOptions.current);
|
|
196
314
|
}, []);
|
|
315
|
+
useUpdateEffect(function () {
|
|
316
|
+
setShowResetButton(!isEqual(rowHeightsOptions.defaultHeight, initialRowHeightsOptions.current.defaultHeight) || gridStyles.fontSize !== initialGridStyles.current.fontSize || gridStyles.cellPadding !== initialGridStyles.current.cellPadding);
|
|
317
|
+
}, [rowHeightsOptions.defaultHeight, gridStyles.fontSize, gridStyles.cellPadding]);
|
|
318
|
+
var resetButton = useMemo(function () {
|
|
319
|
+
var allowed = getNestedObjectOptions(showDisplaySelector, 'allowResetButton');
|
|
320
|
+
if (!allowed || !showResetButton) return null;
|
|
321
|
+
return ___EmotionJSX(ResetButton, {
|
|
322
|
+
onClick: resetToInitialState
|
|
323
|
+
});
|
|
324
|
+
}, [showDisplaySelector, showResetButton, resetToInitialState]);
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Display settings popover
|
|
328
|
+
*/
|
|
329
|
+
var _useState9 = useState(false),
|
|
330
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
331
|
+
isOpen = _useState10[0],
|
|
332
|
+
setIsOpen = _useState10[1];
|
|
197
333
|
var buttonLabel = useEuiI18n('euiDisplaySelector.buttonText', 'Display options');
|
|
198
|
-
var
|
|
334
|
+
var additionalDisplaySettings = typeof showDisplaySelector === 'boolean' ? null : (_showDisplaySelector$ = showDisplaySelector === null || showDisplaySelector === void 0 ? void 0 : showDisplaySelector.additionalDisplaySettings) !== null && _showDisplaySelector$ !== void 0 ? _showDisplaySelector$ : null;
|
|
335
|
+
var customRender = typeof showDisplaySelector === 'boolean' ? undefined : showDisplaySelector === null || showDisplaySelector === void 0 ? void 0 : showDisplaySelector.customRender;
|
|
199
336
|
var euiTheme = useEuiTheme();
|
|
200
337
|
var displaySelector = useMemo(function () {
|
|
201
338
|
var paddingSize = 's';
|
|
@@ -203,7 +340,7 @@ export var useDataGridDisplaySelector = function useDataGridDisplaySelector(show
|
|
|
203
340
|
var popoverWidth = mathWithUnits([formMaxWidth, euiTheme.euiTheme.size[paddingSize]], function (x, y) {
|
|
204
341
|
return x + y * 2;
|
|
205
342
|
});
|
|
206
|
-
return
|
|
343
|
+
return densityControl || rowHeightControl || additionalDisplaySettings ? ___EmotionJSX(EuiPopover, {
|
|
207
344
|
"data-test-subj": "dataGridDisplaySelectorPopover",
|
|
208
345
|
isOpen: isOpen,
|
|
209
346
|
closePopover: function closePopover() {
|
|
@@ -228,92 +365,25 @@ export var useDataGridDisplaySelector = function useDataGridDisplaySelector(show
|
|
|
228
365
|
},
|
|
229
366
|
"aria-label": buttonLabel
|
|
230
367
|
}))
|
|
231
|
-
},
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
labelNormal = _ref2[2],
|
|
239
|
-
labelExpanded = _ref2[3];
|
|
240
|
-
return ___EmotionJSX(EuiFormRow, {
|
|
241
|
-
label: densityLabel,
|
|
242
|
-
display: "columnCompressed"
|
|
243
|
-
}, ___EmotionJSX(EuiButtonGroup, {
|
|
244
|
-
legend: densityLabel,
|
|
245
|
-
buttonSize: "compressed",
|
|
246
|
-
isFullWidth: true,
|
|
247
|
-
options: [{
|
|
248
|
-
id: densityOptions[0],
|
|
249
|
-
label: labelCompact
|
|
250
|
-
}, {
|
|
251
|
-
id: densityOptions[1],
|
|
252
|
-
label: labelNormal
|
|
253
|
-
}, {
|
|
254
|
-
id: densityOptions[2],
|
|
255
|
-
label: labelExpanded
|
|
256
|
-
}],
|
|
257
|
-
onChange: setGridStyles,
|
|
258
|
-
idSelected: gridDensity,
|
|
259
|
-
"data-test-subj": "densityButtonGroup"
|
|
260
|
-
}));
|
|
261
|
-
}), showRowHeightControls && ___EmotionJSX(EuiI18n, {
|
|
262
|
-
tokens: ['euiDisplaySelector.rowHeightLabel', 'euiDisplaySelector.labelSingle', 'euiDisplaySelector.labelAuto', 'euiDisplaySelector.labelCustom', 'euiDisplaySelector.lineCountLabel'],
|
|
263
|
-
defaults: ['Row height', 'Single', 'Auto fit', 'Custom', 'Lines per row']
|
|
264
|
-
}, function (_ref3) {
|
|
265
|
-
var _ref4 = _slicedToArray(_ref3, 5),
|
|
266
|
-
rowHeightLabel = _ref4[0],
|
|
267
|
-
labelSingle = _ref4[1],
|
|
268
|
-
labelAuto = _ref4[2],
|
|
269
|
-
labelCustom = _ref4[3],
|
|
270
|
-
lineCountLabel = _ref4[4];
|
|
271
|
-
return ___EmotionJSX(React.Fragment, null, ___EmotionJSX(EuiFormRow, {
|
|
272
|
-
label: rowHeightLabel,
|
|
273
|
-
display: "columnCompressed"
|
|
274
|
-
}, ___EmotionJSX(EuiButtonGroup, {
|
|
275
|
-
legend: rowHeightLabel,
|
|
276
|
-
buttonSize: "compressed",
|
|
277
|
-
isFullWidth: true,
|
|
278
|
-
options: [{
|
|
279
|
-
id: rowHeightButtonOptions[0],
|
|
280
|
-
label: labelSingle
|
|
281
|
-
}, {
|
|
282
|
-
id: rowHeightButtonOptions[1],
|
|
283
|
-
label: labelAuto
|
|
284
|
-
}, {
|
|
285
|
-
id: rowHeightButtonOptions[2],
|
|
286
|
-
label: labelCustom
|
|
287
|
-
}],
|
|
288
|
-
onChange: setRowHeight,
|
|
289
|
-
idSelected: rowHeightSelection,
|
|
290
|
-
"data-test-subj": "rowHeightButtonGroup"
|
|
291
|
-
})), rowHeightSelection === rowHeightButtonOptions[2] && ___EmotionJSX(EuiFormRow, {
|
|
292
|
-
label: lineCountLabel,
|
|
293
|
-
display: "columnCompressed"
|
|
294
|
-
}, ___EmotionJSX(EuiRange, {
|
|
295
|
-
compressed: true,
|
|
296
|
-
fullWidth: true,
|
|
297
|
-
showInput: true,
|
|
298
|
-
min: 1,
|
|
299
|
-
max: 20,
|
|
300
|
-
step: 1,
|
|
301
|
-
required: true,
|
|
302
|
-
value: lineCountInput,
|
|
303
|
-
onChange: setLineCountHeight,
|
|
304
|
-
"data-test-subj": "lineCountNumber"
|
|
305
|
-
})));
|
|
306
|
-
}), additionalDisplaySettings, showResetButton && ___EmotionJSX(EuiPopoverFooter, null, ___EmotionJSX(EuiFlexGroup, {
|
|
307
|
-
justifyContent: "flexEnd",
|
|
308
|
-
responsive: false
|
|
309
|
-
}, ___EmotionJSX(EuiFlexItem, {
|
|
310
|
-
grow: false
|
|
311
|
-
}, ___EmotionJSX("div", null, ___EmotionJSX(EuiButtonEmpty, {
|
|
312
|
-
flush: "both",
|
|
313
|
-
size: "xs",
|
|
314
|
-
onClick: resetToInitialState,
|
|
315
|
-
"data-test-subj": "resetDisplaySelector"
|
|
316
|
-
}, resetButtonLabel)))))) : null;
|
|
317
|
-
}, [euiTheme, additionalDisplaySettings, buttonLabel, isOpen, resetButtonLabel, showDensityControls, showResetButton, showRowHeightControls, gridDensity, rowHeightSelection, lineCountInput, setGridStyles, setRowHeight, setLineCountHeight, resetToInitialState]);
|
|
368
|
+
}, customRender ? customRender({
|
|
369
|
+
densityControl: densityControl,
|
|
370
|
+
rowHeightControl: rowHeightControl,
|
|
371
|
+
additionalDisplaySettings: additionalDisplaySettings,
|
|
372
|
+
resetButton: resetButton
|
|
373
|
+
}) : ___EmotionJSX(React.Fragment, null, densityControl, rowHeightControl, additionalDisplaySettings, resetButton)) : null;
|
|
374
|
+
}, [euiTheme, densityControl, rowHeightControl, additionalDisplaySettings, resetButton, customRender, buttonLabel, isOpen]);
|
|
318
375
|
return [displaySelector, gridStyles, rowHeightsOptions];
|
|
376
|
+
};
|
|
377
|
+
var ResetButton = function ResetButton(_ref8) {
|
|
378
|
+
var onClick = _ref8.onClick;
|
|
379
|
+
var resetButtonLabel = useEuiI18n('euiDisplaySelector.resetButtonText', 'Reset to default');
|
|
380
|
+
return ___EmotionJSX(EuiPopoverFooter, null, ___EmotionJSX(EuiFlexGroup, {
|
|
381
|
+
justifyContent: "flexEnd",
|
|
382
|
+
responsive: false
|
|
383
|
+
}, ___EmotionJSX(EuiButtonEmpty, {
|
|
384
|
+
flush: "both",
|
|
385
|
+
size: "xs",
|
|
386
|
+
onClick: onClick,
|
|
387
|
+
"data-test-subj": "resetDisplaySelector"
|
|
388
|
+
}, resetButtonLabel)));
|
|
319
389
|
};
|
|
@@ -47,7 +47,7 @@ export var euiDataGridStyles = function euiDataGridStyles(euiThemeContext) {
|
|
|
47
47
|
euiDataGrid: /*#__PURE__*/css("display:flex;flex-direction:column;align-items:stretch;", 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;"),
|
|
48
48
|
cellPadding: {
|
|
49
49
|
cellPadding: function cellPadding(size) {
|
|
50
|
-
return /*#__PURE__*/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{", logicalCSS('padding-bottom', 0), " ", logicalCSS('border-bottom', "".concat(_cellPadding[size], " solid transparent")), ";}.euiDataGridHeaderCell__button{margin-block:-", _cellPadding[size], ";};label:cellPadding;");
|
|
50
|
+
return /*#__PURE__*/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{", logicalCSS('padding-bottom', 0), " ", logicalCSS('border-bottom', "".concat(_cellPadding[size], " solid transparent")), ";}.euiDataGridHeaderCell__button{margin-block:-", _cellPadding[size], ";};label:cellPadding;");
|
|
51
51
|
},
|
|
52
52
|
get s() {
|
|
53
53
|
return /*#__PURE__*/css(this.cellPadding('s'), ";label:s;");
|
|
@@ -102,7 +102,7 @@ export var useUnconstrainedHeight = function useUnconstrainedHeight(_ref2) {
|
|
|
102
102
|
if (rowHeightOption) {
|
|
103
103
|
// this row's height is known
|
|
104
104
|
knownRowCount++;
|
|
105
|
-
knownHeight += rowHeightUtils.getCalculatedHeight(rowHeightOption, defaultRowHeight, correctRowIndex,
|
|
105
|
+
knownHeight += rowHeightUtils.getCalculatedHeight(rowHeightOption, defaultRowHeight, correctRowIndex, rowHeightsOptions);
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
|