@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
|
@@ -7,13 +7,14 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
7
7
|
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; }
|
|
8
8
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
9
9
|
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); }
|
|
10
|
+
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)."; }
|
|
11
|
+
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); }
|
|
10
12
|
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
11
13
|
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."); }
|
|
12
14
|
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; } }
|
|
13
15
|
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; }
|
|
14
16
|
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; } }
|
|
15
17
|
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
16
|
-
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); }
|
|
17
18
|
/*
|
|
18
19
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
19
20
|
* or more contributor license agreements. Licensed under the Elastic License
|
|
@@ -22,15 +23,16 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
|
|
|
22
23
|
* Side Public License, v 1.
|
|
23
24
|
*/
|
|
24
25
|
|
|
25
|
-
import React, { useState, useMemo, useCallback, useEffect } from 'react';
|
|
26
|
+
import React, { useState, useMemo, useCallback, useEffect, useRef } from 'react';
|
|
27
|
+
import isEqual from 'lodash/isEqual';
|
|
26
28
|
import { logicalStyle, mathWithUnits } from '../../../global_styling';
|
|
27
|
-
import { useUpdateEffect, useEuiTheme } from '../../../services';
|
|
29
|
+
import { useUpdateEffect, useDeepEqual, useEuiTheme } from '../../../services';
|
|
28
30
|
import { EuiI18n, useEuiI18n } from '../../i18n';
|
|
29
31
|
import { EuiPopover, EuiPopoverFooter } from '../../popover';
|
|
30
32
|
import { EuiButtonIcon, EuiButtonGroup, EuiButtonEmpty } from '../../button';
|
|
31
|
-
import { EuiFormRow,
|
|
33
|
+
import { EuiFormRow, EuiFieldNumber } from '../../form';
|
|
32
34
|
import { euiFormMaxWidth } from '../../form/form.styles';
|
|
33
|
-
import { EuiFlexGroup
|
|
35
|
+
import { EuiFlexGroup } from '../../flex';
|
|
34
36
|
import { EuiToolTip } from '../../tool_tip';
|
|
35
37
|
import { getNestedObjectOptions } from './data_grid_toolbar';
|
|
36
38
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
|
@@ -44,8 +46,12 @@ export var 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 = useMemo(function () {
|
|
80
|
+
return convertGridStylesToSelection(gridStyles);
|
|
81
|
+
}, [gridStyles]);
|
|
82
|
+
var setDensity = useCallback(function (density) {
|
|
83
|
+
onChange(densityStyles[density]);
|
|
84
|
+
}, [onChange]);
|
|
85
|
+
return ___EmotionJSX(EuiI18n, {
|
|
86
|
+
tokens: ['euiDisplaySelector.densityLabel', 'euiDisplaySelector.labelCompact', 'euiDisplaySelector.labelNormal', 'euiDisplaySelector.labelExpanded'],
|
|
87
|
+
defaults: ['Density', 'Compact', 'Normal', 'Expanded']
|
|
88
|
+
}, function (_ref2) {
|
|
89
|
+
var _ref3 = _slicedToArray(_ref2, 4),
|
|
90
|
+
densityLabel = _ref3[0],
|
|
91
|
+
labelCompact = _ref3[1],
|
|
92
|
+
labelNormal = _ref3[2],
|
|
93
|
+
labelExpanded = _ref3[3];
|
|
94
|
+
return ___EmotionJSX(EuiFormRow, {
|
|
95
|
+
label: densityLabel,
|
|
96
|
+
display: "columnCompressed"
|
|
97
|
+
}, ___EmotionJSX(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
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
if (_typeof(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' || _typeof(defaultHeight) === 'object' && defaultHeight.height) {
|
|
82
128
|
return '';
|
|
83
129
|
}
|
|
84
|
-
|
|
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
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
var
|
|
143
|
+
var RowHeightControl = function RowHeightControl(_ref4) {
|
|
144
|
+
var rowHeightsOptions = _ref4.rowHeightsOptions,
|
|
145
|
+
onChange = _ref4.onChange;
|
|
146
|
+
var autoBelowLineCount = rowHeightsOptions.autoBelowLineCount;
|
|
147
|
+
var _useState = useState(1),
|
|
90
148
|
_useState2 = _slicedToArray(_useState, 2),
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
var
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
setUserRowHeightsOptions = _useState6[1];
|
|
107
|
-
|
|
108
|
-
// Density logic
|
|
109
|
-
var setGridStyles = useCallback(function (density) {
|
|
110
|
-
setUserGridStyles(densityStyles[density]);
|
|
111
|
-
}, []);
|
|
149
|
+
lineCountInput = _useState2[0],
|
|
150
|
+
setLineCountInput = _useState2[1];
|
|
151
|
+
var setLineCountHeight = 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
|
+
useEffect(function () {
|
|
163
|
+
var passedLineCount = _typeof(rowHeightsOptions === null || rowHeightsOptions === void 0 ? void 0 : rowHeightsOptions.defaultHeight) === 'object' ? rowHeightsOptions.defaultHeight.lineCount : undefined;
|
|
112
164
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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 = useMemo(function () {
|
|
175
|
+
return convertRowHeightsOptionsToSelection(rowHeightsOptions);
|
|
176
|
+
}, [rowHeightsOptions]);
|
|
118
177
|
var setRowHeight = useCallback(function (option) {
|
|
119
178
|
var rowHeightsOptions = {
|
|
120
179
|
rowHeights: {} // Unset all row-specific heights
|
|
121
180
|
};
|
|
122
|
-
if (option ===
|
|
181
|
+
if (option === rowHeightSelectionOptions[0]) {
|
|
123
182
|
rowHeightsOptions.defaultHeight = 'auto';
|
|
124
|
-
} else if (option ===
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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 ___EmotionJSX(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 = _slicedToArray(_ref5, 4),
|
|
201
|
+
rowHeightLabel = _ref6[0],
|
|
202
|
+
labelAuto = _ref6[1],
|
|
203
|
+
labelStatic = _ref6[2],
|
|
204
|
+
labelMax = _ref6[3];
|
|
205
|
+
return ___EmotionJSX(EuiFormRow, {
|
|
206
|
+
label: rowHeightLabel,
|
|
207
|
+
display: "columnCompressed"
|
|
208
|
+
}, ___EmotionJSX(EuiFlexGroup, {
|
|
209
|
+
gutterSize: "s",
|
|
210
|
+
responsive: false
|
|
211
|
+
}, ___EmotionJSX(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
|
+
}), ___EmotionJSX(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
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}, [initialStyles, userGridStyles]);
|
|
153
|
-
var rowHeightsOptions = useMemo(function () {
|
|
154
|
-
return _objectSpread(_objectSpread({}, initialRowHeightsOptions), userRowHeightsOptions);
|
|
155
|
-
}, [initialRowHeightsOptions, userRowHeightsOptions]);
|
|
239
|
+
/**
|
|
240
|
+
* Display settings/selector popover
|
|
241
|
+
*/
|
|
156
242
|
|
|
157
|
-
|
|
158
|
-
var
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|
+
export var 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 = useState(passedGridStyles),
|
|
250
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
251
|
+
gridStyles = _useState4[0],
|
|
252
|
+
setGridStyles = _useState4[1];
|
|
171
253
|
|
|
172
|
-
//
|
|
173
|
-
|
|
174
|
-
var _useState9 = useState(false),
|
|
175
|
-
_useState10 = _slicedToArray(_useState9, 2),
|
|
176
|
-
showResetButton = _useState10[0],
|
|
177
|
-
setShowResetButton = _useState10[1];
|
|
254
|
+
// Update if consumers pass new grid style configurations
|
|
255
|
+
var stablePassedGridStyles = useDeepEqual(passedGridStyles);
|
|
178
256
|
useUpdateEffect(function () {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
257
|
+
setGridStyles(stablePassedGridStyles);
|
|
258
|
+
}, [stablePassedGridStyles]);
|
|
259
|
+
|
|
260
|
+
// Update on user display selector change
|
|
261
|
+
var onUserGridStyleChange = useCallback(function (styles) {
|
|
262
|
+
return setGridStyles(function (prevStyles) {
|
|
263
|
+
var changedStyles = _objectSpread(_objectSpread({}, prevStyles), styles);
|
|
264
|
+
var onChange = changedStyles.onChange,
|
|
265
|
+
rest = _objectWithoutProperties(changedStyles, _excluded);
|
|
266
|
+
onChange === null || onChange === void 0 || onChange(rest);
|
|
267
|
+
return changedStyles;
|
|
268
|
+
});
|
|
269
|
+
}, []);
|
|
270
|
+
var densityControl = useMemo(function () {
|
|
271
|
+
var show = getNestedObjectOptions(showDisplaySelector, 'allowDensity');
|
|
272
|
+
return show ? ___EmotionJSX(DensityControl, {
|
|
273
|
+
gridStyles: gridStyles,
|
|
274
|
+
onChange: onUserGridStyleChange
|
|
275
|
+
}) : null;
|
|
276
|
+
}, [showDisplaySelector, gridStyles, onUserGridStyleChange]);
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Row height changes
|
|
280
|
+
*/
|
|
281
|
+
var _useState5 = useState(passedRowHeightsOptions),
|
|
282
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
283
|
+
rowHeightsOptions = _useState6[0],
|
|
284
|
+
setRowHeightsOptions = _useState6[1];
|
|
285
|
+
|
|
286
|
+
// Update if consumers pass new row height configurations
|
|
287
|
+
var stablePassedRowHeights = useDeepEqual(passedRowHeightsOptions);
|
|
188
288
|
useUpdateEffect(function () {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
var hasUserChanges = Object.keys(userRowHeightsOptions).length > 0;
|
|
192
|
-
if (hasUserChanges) setShowResetButton(true);
|
|
193
|
-
}
|
|
194
|
-
var onChange = rowHeightsOptions.onChange,
|
|
195
|
-
currentRowHeightsOptions = _objectWithoutProperties(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
|
-
//
|
|
292
|
+
// Update on user display selector change
|
|
293
|
+
var onUserRowHeightChange = useCallback(function (options) {
|
|
294
|
+
return setRowHeightsOptions(function (prevOptions) {
|
|
295
|
+
var changedOptions = _objectSpread(_objectSpread({}, prevOptions), options);
|
|
296
|
+
var onChange = changedOptions.onChange,
|
|
297
|
+
rest = _objectWithoutProperties(changedOptions, _excluded2);
|
|
298
|
+
onChange === null || onChange === void 0 || onChange(rest);
|
|
299
|
+
return changedOptions;
|
|
300
|
+
});
|
|
301
|
+
}, []);
|
|
302
|
+
var rowHeightControl = useMemo(function () {
|
|
303
|
+
var show = getNestedObjectOptions(showDisplaySelector, 'allowRowHeight');
|
|
304
|
+
return show ? ___EmotionJSX(RowHeightControl, {
|
|
305
|
+
rowHeightsOptions: rowHeightsOptions,
|
|
306
|
+
onChange: onUserRowHeightChange
|
|
307
|
+
}) : null;
|
|
308
|
+
}, [showDisplaySelector, rowHeightsOptions, onUserRowHeightChange]);
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Reset button
|
|
312
|
+
*/
|
|
313
|
+
var _useState7 = useState(false),
|
|
314
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
315
|
+
showResetButton = _useState8[0],
|
|
316
|
+
setShowResetButton = _useState8[1];
|
|
317
|
+
var initialGridStyles = useRef(passedGridStyles);
|
|
318
|
+
var initialRowHeightsOptions = useRef(passedRowHeightsOptions);
|
|
200
319
|
var resetToInitialState = useCallback(function () {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
setShowResetButton(false);
|
|
320
|
+
setGridStyles(initialGridStyles.current);
|
|
321
|
+
setRowHeightsOptions(initialRowHeightsOptions.current);
|
|
204
322
|
}, []);
|
|
323
|
+
useUpdateEffect(function () {
|
|
324
|
+
setShowResetButton(!isEqual(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 = useMemo(function () {
|
|
327
|
+
var allowed = getNestedObjectOptions(showDisplaySelector, 'allowResetButton');
|
|
328
|
+
if (!allowed || !showResetButton) return null;
|
|
329
|
+
return ___EmotionJSX(ResetButton, {
|
|
330
|
+
onClick: resetToInitialState
|
|
331
|
+
});
|
|
332
|
+
}, [showDisplaySelector, showResetButton, resetToInitialState]);
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Display settings popover
|
|
336
|
+
*/
|
|
337
|
+
var _useState9 = useState(false),
|
|
338
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
339
|
+
isOpen = _useState10[0],
|
|
340
|
+
setIsOpen = _useState10[1];
|
|
205
341
|
var buttonLabel = useEuiI18n('euiDisplaySelector.buttonText', 'Display options');
|
|
206
|
-
var
|
|
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 = useEuiTheme();
|
|
208
345
|
var displaySelector = useMemo(function () {
|
|
209
346
|
var paddingSize = 's';
|
|
@@ -211,7 +348,7 @@ export var useDataGridDisplaySelector = function useDataGridDisplaySelector(show
|
|
|
211
348
|
var popoverWidth = mathWithUnits([formMaxWidth, euiTheme.euiTheme.size[paddingSize]], function (x, y) {
|
|
212
349
|
return x + y * 2;
|
|
213
350
|
});
|
|
214
|
-
return
|
|
351
|
+
return densityControl || rowHeightControl || additionalDisplaySettings ? ___EmotionJSX(EuiPopover, {
|
|
215
352
|
"data-test-subj": "dataGridDisplaySelectorPopover",
|
|
216
353
|
isOpen: isOpen,
|
|
217
354
|
closePopover: function closePopover() {
|
|
@@ -236,92 +373,25 @@ export var useDataGridDisplaySelector = function useDataGridDisplaySelector(show
|
|
|
236
373
|
},
|
|
237
374
|
"aria-label": buttonLabel
|
|
238
375
|
}))
|
|
239
|
-
},
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
labelNormal = _ref2[2],
|
|
247
|
-
labelExpanded = _ref2[3];
|
|
248
|
-
return ___EmotionJSX(EuiFormRow, {
|
|
249
|
-
label: densityLabel,
|
|
250
|
-
display: "columnCompressed"
|
|
251
|
-
}, ___EmotionJSX(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 && ___EmotionJSX(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 = _slicedToArray(_ref3, 5),
|
|
274
|
-
rowHeightLabel = _ref4[0],
|
|
275
|
-
labelSingle = _ref4[1],
|
|
276
|
-
labelAuto = _ref4[2],
|
|
277
|
-
labelCustom = _ref4[3],
|
|
278
|
-
lineCountLabel = _ref4[4];
|
|
279
|
-
return ___EmotionJSX(React.Fragment, null, ___EmotionJSX(EuiFormRow, {
|
|
280
|
-
label: rowHeightLabel,
|
|
281
|
-
display: "columnCompressed"
|
|
282
|
-
}, ___EmotionJSX(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] && ___EmotionJSX(EuiFormRow, {
|
|
300
|
-
label: lineCountLabel,
|
|
301
|
-
display: "columnCompressed"
|
|
302
|
-
}, ___EmotionJSX(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 && ___EmotionJSX(EuiPopoverFooter, null, ___EmotionJSX(EuiFlexGroup, {
|
|
315
|
-
justifyContent: "flexEnd",
|
|
316
|
-
responsive: false
|
|
317
|
-
}, ___EmotionJSX(EuiFlexItem, {
|
|
318
|
-
grow: false
|
|
319
|
-
}, ___EmotionJSX("div", null, ___EmotionJSX(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
|
+
}) : ___EmotionJSX(React.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 = useEuiI18n('euiDisplaySelector.resetButtonText', 'Reset to default');
|
|
388
|
+
return ___EmotionJSX(EuiPopoverFooter, null, ___EmotionJSX(EuiFlexGroup, {
|
|
389
|
+
justifyContent: "flexEnd",
|
|
390
|
+
responsive: false
|
|
391
|
+
}, ___EmotionJSX(EuiButtonEmpty, {
|
|
392
|
+
flush: "both",
|
|
393
|
+
size: "xs",
|
|
394
|
+
onClick: onClick,
|
|
395
|
+
"data-test-subj": "resetDisplaySelector"
|
|
396
|
+
}, resetButtonLabel)));
|
|
327
397
|
};
|
|
@@ -1059,7 +1059,12 @@ EuiDataGridToolbarPropsComponent.propTypes = {
|
|
|
1059
1059
|
/**
|
|
1060
1060
|
* Allows appending additional content to the bottom of the display settings popover
|
|
1061
1061
|
*/
|
|
1062
|
-
additionalDisplaySettings: PropTypes.node
|
|
1062
|
+
additionalDisplaySettings: PropTypes.node,
|
|
1063
|
+
/**
|
|
1064
|
+
* Allows completely custom rendering of the display selector popover via render prop.
|
|
1065
|
+
* Passes back the default controls as arguments for optional rendering.
|
|
1066
|
+
*/
|
|
1067
|
+
customRender: PropTypes.func
|
|
1063
1068
|
}).isRequired]),
|
|
1064
1069
|
/**
|
|
1065
1070
|
* Allows the ability for the user to sort rows based upon column values
|
|
@@ -1210,6 +1215,14 @@ EuiDataGridToolbarPropsComponent.propTypes = {
|
|
|
1210
1215
|
lineCount: PropTypes.number,
|
|
1211
1216
|
height: PropTypes.number
|
|
1212
1217
|
}).isRequired]),
|
|
1218
|
+
/**
|
|
1219
|
+
* Feature flag for custom `lineCount` behavior, where `lineCount` acts like a
|
|
1220
|
+
* *max* number of lines (instead of a set number of lines for all rows).
|
|
1221
|
+
*
|
|
1222
|
+
* This functionality is in beta and has performance implications;
|
|
1223
|
+
* we do not yet fully recommend/support it for heavy production usage.
|
|
1224
|
+
*/
|
|
1225
|
+
autoBelowLineCount: PropTypes.bool,
|
|
1213
1226
|
/**
|
|
1214
1227
|
* Defines the height for a specific row. It can be line count or just height.
|
|
1215
1228
|
*
|
|
@@ -1269,7 +1282,12 @@ EuiDataGridToolbarPropsComponent.propTypes = {
|
|
|
1269
1282
|
/**
|
|
1270
1283
|
* Allows appending additional content to the bottom of the display settings popover
|
|
1271
1284
|
*/
|
|
1272
|
-
additionalDisplaySettings: PropTypes.node
|
|
1285
|
+
additionalDisplaySettings: PropTypes.node,
|
|
1286
|
+
/**
|
|
1287
|
+
* Allows completely custom rendering of the display selector popover via render prop.
|
|
1288
|
+
* Passes back the default controls as arguments for optional rendering.
|
|
1289
|
+
*/
|
|
1290
|
+
customRender: PropTypes.func
|
|
1273
1291
|
}).isRequired]),
|
|
1274
1292
|
/**
|
|
1275
1293
|
* Allows the ability for the user to sort rows based upon column values
|
|
@@ -1399,6 +1417,14 @@ EuiDataGridRowHeightsPropsComponent.propTypes = {
|
|
|
1399
1417
|
lineCount: PropTypes.number,
|
|
1400
1418
|
height: PropTypes.number
|
|
1401
1419
|
}).isRequired]),
|
|
1420
|
+
/**
|
|
1421
|
+
* Feature flag for custom `lineCount` behavior, where `lineCount` acts like a
|
|
1422
|
+
* *max* number of lines (instead of a set number of lines for all rows).
|
|
1423
|
+
*
|
|
1424
|
+
* This functionality is in beta and has performance implications;
|
|
1425
|
+
* we do not yet fully recommend/support it for heavy production usage.
|
|
1426
|
+
*/
|
|
1427
|
+
autoBelowLineCount: PropTypes.bool,
|
|
1402
1428
|
/**
|
|
1403
1429
|
* Defines the height for a specific row. It can be line count or just height.
|
|
1404
1430
|
*
|
|
@@ -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;");
|
|
@@ -107,7 +107,7 @@ export var useUnconstrainedHeight = function useUnconstrainedHeight(_ref2) {
|
|
|
107
107
|
if (rowHeightOption) {
|
|
108
108
|
// this row's height is known
|
|
109
109
|
knownRowCount++;
|
|
110
|
-
knownHeight += rowHeightUtils.getCalculatedHeight(rowHeightOption, defaultRowHeight, correctRowIndex,
|
|
110
|
+
knownHeight += rowHeightUtils.getCalculatedHeight(rowHeightOption, defaultRowHeight, correctRowIndex, rowHeightsOptions);
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
|