@elastic/eui 62.1.0 → 62.2.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/dist/eui_charts_theme.js +330 -330
- package/dist/eui_charts_theme.js.map +1 -1
- package/es/components/datagrid/body/data_grid_body.js +11 -1
- package/es/components/datagrid/body/data_grid_cell.js +31 -3
- package/es/components/datagrid/data_grid.js +9 -1
- package/es/components/datagrid/utils/row_heights.js +33 -4
- package/es/components/popover/wrapping_popover.js +88 -45
- package/es/components/portal/portal.js +84 -38
- package/es/test/rtl/component_helpers.js +60 -1
- package/eui.d.ts +43 -8
- package/lib/components/datagrid/body/data_grid_body.js +11 -1
- package/lib/components/datagrid/body/data_grid_cell.js +31 -3
- package/lib/components/datagrid/data_grid.js +9 -1
- package/lib/components/datagrid/utils/row_heights.js +33 -4
- package/lib/components/popover/wrapping_popover.js +85 -44
- package/lib/components/portal/portal.js +87 -39
- package/lib/test/rtl/component_helpers.js +69 -3
- package/optimize/es/components/datagrid/body/data_grid_body.js +2 -0
- package/optimize/es/components/datagrid/body/data_grid_cell.js +13 -1
- package/optimize/es/components/datagrid/utils/row_heights.js +33 -4
- package/optimize/es/components/popover/wrapping_popover.js +79 -38
- package/optimize/es/components/portal/portal.js +66 -34
- package/optimize/es/test/rtl/component_helpers.js +60 -1
- package/optimize/lib/components/datagrid/body/data_grid_body.js +2 -0
- package/optimize/lib/components/datagrid/body/data_grid_cell.js +13 -1
- package/optimize/lib/components/datagrid/utils/row_heights.js +33 -4
- package/optimize/lib/components/popover/wrapping_popover.js +78 -38
- package/optimize/lib/components/portal/portal.js +65 -44
- package/optimize/lib/test/rtl/component_helpers.js +69 -3
- package/package.json +2 -2
- package/test-env/components/datagrid/body/data_grid_body.js +11 -1
- package/test-env/components/datagrid/body/data_grid_cell.js +31 -3
- package/test-env/components/datagrid/data_grid.js +9 -1
- package/test-env/components/datagrid/utils/row_heights.js +33 -4
- package/test-env/components/observer/resize_observer/resize_observer.js +43 -126
- package/test-env/components/popover/wrapping_popover.js +78 -38
- package/test-env/components/portal/portal.js +79 -45
- package/test-env/test/rtl/component_helpers.js +69 -3
|
@@ -9,154 +9,71 @@ exports.useResizeObserver = exports.hasResizeObserver = exports.EuiResizeObserve
|
|
|
9
9
|
|
|
10
10
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
11
|
|
|
12
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
13
|
-
|
|
14
|
-
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
15
|
-
|
|
16
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
17
|
-
|
|
18
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
19
|
-
|
|
20
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
21
|
-
|
|
22
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
23
|
-
|
|
24
12
|
var _react = require("react");
|
|
25
13
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
14
|
+
/*
|
|
15
|
+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
16
|
+
* or more contributor license agreements. Licensed under the Elastic License
|
|
17
|
+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
|
18
|
+
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
|
19
|
+
* Side Public License, v 1.
|
|
20
|
+
*/
|
|
21
|
+
// Re-export `hasResizeObserver` as-is
|
|
32
22
|
var hasResizeObserver = typeof window !== 'undefined' && typeof window.ResizeObserver !== 'undefined';
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
var _super = _createSuper(EuiResizeObserver);
|
|
39
|
-
|
|
40
|
-
function EuiResizeObserver() {
|
|
41
|
-
var _this;
|
|
42
|
-
|
|
43
|
-
(0, _classCallCheck2.default)(this, EuiResizeObserver);
|
|
44
|
-
|
|
45
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
46
|
-
args[_key] = arguments[_key];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
_this = _super.call.apply(_super, [this].concat(args));
|
|
50
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "name", 'EuiResizeObserver');
|
|
51
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "state", {
|
|
52
|
-
height: 0,
|
|
53
|
-
width: 0
|
|
54
|
-
});
|
|
55
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onResize", function () {
|
|
56
|
-
// `entry.contentRect` provides incomplete `height` and `width` data.
|
|
57
|
-
// Use `getBoundingClientRect` to account for padding and border.
|
|
58
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/DOMRectReadOnly
|
|
59
|
-
if (!_this.childNode) return;
|
|
60
|
-
|
|
61
|
-
var _this$childNode$getBo = _this.childNode.getBoundingClientRect(),
|
|
62
|
-
height = _this$childNode$getBo.height,
|
|
63
|
-
width = _this$childNode$getBo.width; // Check for actual resize event
|
|
23
|
+
/**
|
|
24
|
+
* jsdom currently does not support ResizeObservers (@see https://github.com/jsdom/jsdom/issues/3368)
|
|
25
|
+
* To mimic RO init behavior (should call onResize on mount), we're providing the below testenv mocks.
|
|
26
|
+
*/
|
|
64
27
|
|
|
28
|
+
exports.hasResizeObserver = hasResizeObserver;
|
|
65
29
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
30
|
+
var EuiResizeObserver = function EuiResizeObserver(_ref) {
|
|
31
|
+
var onResize = _ref.onResize,
|
|
32
|
+
children = _ref.children;
|
|
69
33
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
34
|
+
var _useState = (0, _react.useState)(null),
|
|
35
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
36
|
+
observedElement = _useState2[0],
|
|
37
|
+
setObservedElement = _useState2[1];
|
|
74
38
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
39
|
+
(0, _react.useEffect)(function () {
|
|
40
|
+
if (observedElement) {
|
|
41
|
+
var _observedElement$getB = observedElement.getBoundingClientRect(),
|
|
42
|
+
width = _observedElement$getB.width,
|
|
43
|
+
height = _observedElement$getB.height;
|
|
44
|
+
|
|
45
|
+
onResize({
|
|
46
|
+
width: width,
|
|
47
|
+
height: height
|
|
78
48
|
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
var childNode = _this.childNode;
|
|
84
|
-
_this.observer = makeResizeObserver(childNode, _this.onResize);
|
|
85
|
-
});
|
|
86
|
-
return _this;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return EuiResizeObserver;
|
|
90
|
-
}(_observer.EuiObserver);
|
|
49
|
+
}
|
|
50
|
+
}, [observedElement, onResize]);
|
|
51
|
+
return children(setObservedElement);
|
|
52
|
+
};
|
|
91
53
|
|
|
92
54
|
exports.EuiResizeObserver = EuiResizeObserver;
|
|
93
55
|
|
|
94
|
-
var makeResizeObserver = function makeResizeObserver(node, callback) {
|
|
95
|
-
var observer;
|
|
96
|
-
|
|
97
|
-
if (hasResizeObserver) {
|
|
98
|
-
observer = new window.ResizeObserver(callback);
|
|
99
|
-
observer.observe(node);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return observer;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
56
|
var useResizeObserver = function useResizeObserver(container, dimension) {
|
|
106
|
-
var
|
|
57
|
+
var _useState3 = (0, _react.useState)({
|
|
107
58
|
width: 0,
|
|
108
59
|
height: 0
|
|
109
60
|
}),
|
|
110
|
-
|
|
111
|
-
size =
|
|
112
|
-
|
|
113
|
-
// new state (and trigger a re-render) when the new dimensions actually differ
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
var _currentDimensions = (0, _react.useRef)(size);
|
|
117
|
-
|
|
118
|
-
var setSize = (0, _react.useCallback)(function (dimensions) {
|
|
119
|
-
var doesWidthMatter = dimension !== 'height';
|
|
120
|
-
var doesHeightMatter = dimension !== 'width';
|
|
121
|
-
|
|
122
|
-
if (doesWidthMatter && _currentDimensions.current.width !== dimensions.width || doesHeightMatter && _currentDimensions.current.height !== dimensions.height) {
|
|
123
|
-
_currentDimensions.current = dimensions;
|
|
61
|
+
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
|
62
|
+
size = _useState4[0],
|
|
63
|
+
setSize = _useState4[1];
|
|
124
64
|
|
|
125
|
-
_setSize(dimensions);
|
|
126
|
-
}
|
|
127
|
-
}, [dimension]);
|
|
128
65
|
(0, _react.useEffect)(function () {
|
|
129
66
|
if (container != null) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
setSize({
|
|
134
|
-
width: boundingRect.width,
|
|
135
|
-
height: boundingRect.height
|
|
136
|
-
});
|
|
137
|
-
var observer = makeResizeObserver(container, function () {
|
|
138
|
-
// `entry.contentRect` provides incomplete `height` and `width` data.
|
|
139
|
-
// Use `getBoundingClientRect` to account for padding and border.
|
|
140
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/DOMRectReadOnly
|
|
141
|
-
var _container$getBoundin = container.getBoundingClientRect(),
|
|
142
|
-
height = _container$getBoundin.height,
|
|
143
|
-
width = _container$getBoundin.width;
|
|
67
|
+
var _container$getBoundin = container.getBoundingClientRect(),
|
|
68
|
+
width = _container$getBoundin.width,
|
|
69
|
+
height = _container$getBoundin.height;
|
|
144
70
|
|
|
145
|
-
setSize({
|
|
146
|
-
width: width,
|
|
147
|
-
height: height
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
return function () {
|
|
151
|
-
return observer && observer.disconnect();
|
|
152
|
-
};
|
|
153
|
-
} else {
|
|
154
71
|
setSize({
|
|
155
|
-
width:
|
|
156
|
-
height:
|
|
72
|
+
width: width,
|
|
73
|
+
height: height
|
|
157
74
|
});
|
|
158
75
|
}
|
|
159
|
-
}, [container,
|
|
76
|
+
}, [container, dimension]);
|
|
160
77
|
return size;
|
|
161
78
|
};
|
|
162
79
|
|
|
@@ -11,10 +11,22 @@ exports.EuiWrappingPopover = void 0;
|
|
|
11
11
|
|
|
12
12
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
13
13
|
|
|
14
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
15
|
-
|
|
16
14
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
17
15
|
|
|
16
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
17
|
+
|
|
18
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
19
|
+
|
|
20
|
+
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
21
|
+
|
|
22
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
23
|
+
|
|
24
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
25
|
+
|
|
26
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
27
|
+
|
|
28
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
29
|
+
|
|
18
30
|
var _react = _interopRequireWildcard(require("react"));
|
|
19
31
|
|
|
20
32
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
@@ -31,51 +43,79 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
31
43
|
|
|
32
44
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
33
45
|
|
|
46
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
47
|
+
|
|
48
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
49
|
+
|
|
34
50
|
/**
|
|
35
51
|
* Injects the EuiPopover next to the button via EuiPortal
|
|
36
52
|
* then the button element is moved into the popover dom.
|
|
37
53
|
* On unmount, the button is moved back to its original location.
|
|
38
54
|
*/
|
|
39
|
-
var EuiWrappingPopover = function
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
setPortal = _useState4[1];
|
|
52
|
-
|
|
53
|
-
(0, _react.useEffect)(function () {
|
|
54
|
-
if (anchor) {
|
|
55
|
-
// move the button into the popover DOM
|
|
56
|
-
anchor.insertAdjacentElement('beforebegin', button);
|
|
55
|
+
var EuiWrappingPopover = /*#__PURE__*/function (_Component) {
|
|
56
|
+
(0, _inherits2.default)(EuiWrappingPopover, _Component);
|
|
57
|
+
|
|
58
|
+
var _super = _createSuper(EuiWrappingPopover);
|
|
59
|
+
|
|
60
|
+
function EuiWrappingPopover() {
|
|
61
|
+
var _this;
|
|
62
|
+
|
|
63
|
+
(0, _classCallCheck2.default)(this, EuiWrappingPopover);
|
|
64
|
+
|
|
65
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
66
|
+
args[_key] = arguments[_key];
|
|
57
67
|
}
|
|
58
68
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
69
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
70
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "portal", null);
|
|
71
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "anchor", null);
|
|
72
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "setPortalRef", function (node) {
|
|
73
|
+
_this.portal = node;
|
|
74
|
+
});
|
|
75
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "setAnchorRef", function (node) {
|
|
76
|
+
_this.anchor = node;
|
|
77
|
+
});
|
|
78
|
+
return _this;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
(0, _createClass2.default)(EuiWrappingPopover, [{
|
|
82
|
+
key: "componentDidMount",
|
|
83
|
+
value: function componentDidMount() {
|
|
84
|
+
if (this.anchor) {
|
|
85
|
+
this.anchor.insertAdjacentElement('beforebegin', this.props.button);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}, {
|
|
89
|
+
key: "componentWillUnmount",
|
|
90
|
+
value: function componentWillUnmount() {
|
|
91
|
+
if (this.props.button.parentNode) {
|
|
92
|
+
if (this.portal) {
|
|
93
|
+
this.portal.insertAdjacentElement('beforebegin', this.props.button);
|
|
94
|
+
}
|
|
63
95
|
}
|
|
64
|
-
};
|
|
65
|
-
}, [anchor, button, portal]);
|
|
66
|
-
return (0, _react2.jsx)(_portal.EuiPortal, {
|
|
67
|
-
portalRef: setPortal,
|
|
68
|
-
insert: {
|
|
69
|
-
sibling: button,
|
|
70
|
-
position: 'after'
|
|
71
96
|
}
|
|
72
|
-
},
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
97
|
+
}, {
|
|
98
|
+
key: "render",
|
|
99
|
+
value: function render() {
|
|
100
|
+
var _this$props = this.props,
|
|
101
|
+
button = _this$props.button,
|
|
102
|
+
rest = (0, _objectWithoutProperties2.default)(_this$props, _excluded);
|
|
103
|
+
return (0, _react2.jsx)(_portal.EuiPortal, {
|
|
104
|
+
portalRef: this.setPortalRef,
|
|
105
|
+
insert: {
|
|
106
|
+
sibling: this.props.button,
|
|
107
|
+
position: 'after'
|
|
108
|
+
}
|
|
109
|
+
}, (0, _react2.jsx)(_popover.EuiPopover, (0, _extends2.default)({}, rest, {
|
|
110
|
+
button: (0, _react2.jsx)("div", {
|
|
111
|
+
ref: this.setAnchorRef,
|
|
112
|
+
className: "euiWrappingPopover__anchor"
|
|
113
|
+
})
|
|
114
|
+
})));
|
|
115
|
+
}
|
|
116
|
+
}]);
|
|
117
|
+
return EuiWrappingPopover;
|
|
118
|
+
}(_react.Component);
|
|
79
119
|
|
|
80
120
|
exports.EuiWrappingPopover = EuiWrappingPopover;
|
|
81
121
|
EuiWrappingPopover.propTypes = {
|
|
@@ -7,28 +7,32 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.insertPositions = exports.INSERT_POSITIONS = exports.EuiPortal = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
+
|
|
12
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
+
|
|
14
|
+
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
15
|
+
|
|
16
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
17
|
+
|
|
18
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
19
|
+
|
|
20
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
21
|
+
|
|
22
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
23
|
|
|
12
24
|
var _react = require("react");
|
|
13
25
|
|
|
26
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
27
|
+
|
|
14
28
|
var _reactDom = require("react-dom");
|
|
15
29
|
|
|
16
30
|
var _common = require("../common");
|
|
17
31
|
|
|
18
|
-
var
|
|
32
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
19
33
|
|
|
20
|
-
|
|
21
|
-
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
22
|
-
* or more contributor license agreements. Licensed under the Elastic License
|
|
23
|
-
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
|
24
|
-
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
|
25
|
-
* Side Public License, v 1.
|
|
26
|
-
*/
|
|
34
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
27
35
|
|
|
28
|
-
/**
|
|
29
|
-
* NOTE: We can't test this component because Enzyme doesn't support rendering
|
|
30
|
-
* into portals.
|
|
31
|
-
*/
|
|
32
36
|
var insertPositions = {
|
|
33
37
|
after: 'afterend',
|
|
34
38
|
before: 'beforebegin'
|
|
@@ -37,47 +41,77 @@ exports.insertPositions = insertPositions;
|
|
|
37
41
|
var INSERT_POSITIONS = (0, _common.keysOf)(insertPositions);
|
|
38
42
|
exports.INSERT_POSITIONS = INSERT_POSITIONS;
|
|
39
43
|
|
|
40
|
-
var EuiPortal = function
|
|
41
|
-
|
|
42
|
-
portalRef = _ref.portalRef,
|
|
43
|
-
children = _ref.children;
|
|
44
|
+
var EuiPortal = /*#__PURE__*/function (_Component) {
|
|
45
|
+
(0, _inherits2.default)(EuiPortal, _Component);
|
|
44
46
|
|
|
45
|
-
var
|
|
46
|
-
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
47
|
-
portalNode = _useState2[0],
|
|
48
|
-
setPortalNode = _useState2[1]; // pull `sibling` and `position` out of insert in case their wrapping object is recreated every render
|
|
47
|
+
var _super = _createSuper(EuiPortal);
|
|
49
48
|
|
|
49
|
+
function EuiPortal(props) {
|
|
50
|
+
var _this;
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
(0, _classCallCheck2.default)(this, EuiPortal);
|
|
53
|
+
_this = _super.call(this, props);
|
|
54
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "portalNode", null);
|
|
55
|
+
if (typeof window === 'undefined') return (0, _possibleConstructorReturn2.default)(_this); // Prevent SSR errors
|
|
54
56
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
portalNode.dataset.euiportal = 'true';
|
|
58
|
-
setPortalNode(portalNode);
|
|
57
|
+
var insert = _this.props.insert;
|
|
58
|
+
_this.portalNode = document.createElement('div');
|
|
59
|
+
_this.portalNode.dataset.euiportal = 'true';
|
|
59
60
|
|
|
60
|
-
if (
|
|
61
|
+
if (insert == null) {
|
|
61
62
|
// no insertion defined, append to body
|
|
62
|
-
document.body.appendChild(portalNode);
|
|
63
|
+
document.body.appendChild(_this.portalNode);
|
|
63
64
|
} else {
|
|
64
65
|
// inserting before or after an element
|
|
65
|
-
sibling.
|
|
66
|
+
var sibling = insert.sibling,
|
|
67
|
+
position = insert.position;
|
|
68
|
+
sibling.insertAdjacentElement(insertPositions[position], _this.portalNode);
|
|
66
69
|
}
|
|
67
70
|
|
|
68
|
-
return
|
|
69
|
-
|
|
70
|
-
|
|
71
|
+
return _this;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
(0, _createClass2.default)(EuiPortal, [{
|
|
75
|
+
key: "componentDidMount",
|
|
76
|
+
value: function componentDidMount() {
|
|
77
|
+
this.updatePortalRef(this.portalNode);
|
|
78
|
+
}
|
|
79
|
+
}, {
|
|
80
|
+
key: "componentWillUnmount",
|
|
81
|
+
value: function componentWillUnmount() {
|
|
82
|
+
var _this$portalNode;
|
|
83
|
+
|
|
84
|
+
if ((_this$portalNode = this.portalNode) !== null && _this$portalNode !== void 0 && _this$portalNode.parentNode) {
|
|
85
|
+
this.portalNode.parentNode.removeChild(this.portalNode);
|
|
71
86
|
}
|
|
72
|
-
};
|
|
73
|
-
}, [sibling, position]);
|
|
74
|
-
(0, _services.useUpdateEffect)(function () {
|
|
75
|
-
portalRef === null || portalRef === void 0 ? void 0 : portalRef(portalNode);
|
|
76
|
-
return function () {
|
|
77
|
-
portalRef === null || portalRef === void 0 ? void 0 : portalRef(null);
|
|
78
|
-
};
|
|
79
|
-
}, [portalNode, portalRef]);
|
|
80
|
-
return portalNode == null ? null : /*#__PURE__*/(0, _reactDom.createPortal)(children, portalNode);
|
|
81
|
-
};
|
|
82
87
|
|
|
83
|
-
|
|
88
|
+
this.updatePortalRef(null);
|
|
89
|
+
}
|
|
90
|
+
}, {
|
|
91
|
+
key: "updatePortalRef",
|
|
92
|
+
value: function updatePortalRef(ref) {
|
|
93
|
+
if (this.props.portalRef) {
|
|
94
|
+
this.props.portalRef(ref);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}, {
|
|
98
|
+
key: "render",
|
|
99
|
+
value: function render() {
|
|
100
|
+
return this.portalNode ? /*#__PURE__*/(0, _reactDom.createPortal)(this.props.children, this.portalNode) : null;
|
|
101
|
+
}
|
|
102
|
+
}]);
|
|
103
|
+
return EuiPortal;
|
|
104
|
+
}(_react.Component);
|
|
105
|
+
|
|
106
|
+
exports.EuiPortal = EuiPortal;
|
|
107
|
+
EuiPortal.propTypes = {
|
|
108
|
+
/**
|
|
109
|
+
* ReactNode to render as this component's content
|
|
110
|
+
*/
|
|
111
|
+
children: _propTypes.default.node.isRequired,
|
|
112
|
+
insert: _propTypes.default.shape({
|
|
113
|
+
sibling: _propTypes.default.any.isRequired,
|
|
114
|
+
position: _propTypes.default.oneOf(["before", "after"]).isRequired
|
|
115
|
+
}),
|
|
116
|
+
portalRef: _propTypes.default.func
|
|
117
|
+
};
|
|
@@ -5,12 +5,14 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.waitForEuiPopoverOpen = exports.waitForEuiPopoverClose = void 0;
|
|
8
|
+
exports.waitForEuiToolTipVisible = exports.waitForEuiToolTipHidden = exports.waitForEuiPopoverOpen = exports.waitForEuiPopoverClose = void 0;
|
|
9
9
|
|
|
10
10
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
11
|
|
|
12
12
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
13
|
|
|
14
|
+
require("@testing-library/jest-dom");
|
|
15
|
+
|
|
14
16
|
var _react = require("@testing-library/react");
|
|
15
17
|
|
|
16
18
|
/*
|
|
@@ -22,7 +24,7 @@ var _react = require("@testing-library/react");
|
|
|
22
24
|
*/
|
|
23
25
|
|
|
24
26
|
/**
|
|
25
|
-
* Ensure the EuiPopover being tested is open/closed before
|
|
27
|
+
* Ensure the EuiPopover being tested is open/closed before continuing
|
|
26
28
|
* Note: Because EuiPopover is portalled, we want to query `document`
|
|
27
29
|
* instead of the `container` returned by RTL's render()
|
|
28
30
|
*/
|
|
@@ -83,5 +85,69 @@ var waitForEuiPopoverClose = /*#__PURE__*/function () {
|
|
|
83
85
|
return _ref2.apply(this, arguments);
|
|
84
86
|
};
|
|
85
87
|
}();
|
|
88
|
+
/**
|
|
89
|
+
* Ensure the EuiToolTip being tested is open and visible before continuing
|
|
90
|
+
*/
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
exports.waitForEuiPopoverClose = waitForEuiPopoverClose;
|
|
94
|
+
|
|
95
|
+
var waitForEuiToolTipVisible = /*#__PURE__*/function () {
|
|
96
|
+
var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
|
|
97
|
+
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
98
|
+
while (1) {
|
|
99
|
+
switch (_context3.prev = _context3.next) {
|
|
100
|
+
case 0:
|
|
101
|
+
_context3.next = 2;
|
|
102
|
+
return (0, _react.waitFor)(function () {
|
|
103
|
+
var tooltip = document.querySelector('.euiToolTipPopover');
|
|
104
|
+
expect(tooltip).toBeVisible();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
case 2:
|
|
108
|
+
return _context3.abrupt("return", _context3.sent);
|
|
109
|
+
|
|
110
|
+
case 3:
|
|
111
|
+
case "end":
|
|
112
|
+
return _context3.stop();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}, _callee3);
|
|
116
|
+
}));
|
|
117
|
+
|
|
118
|
+
return function waitForEuiToolTipVisible() {
|
|
119
|
+
return _ref3.apply(this, arguments);
|
|
120
|
+
};
|
|
121
|
+
}();
|
|
122
|
+
|
|
123
|
+
exports.waitForEuiToolTipVisible = waitForEuiToolTipVisible;
|
|
124
|
+
|
|
125
|
+
var waitForEuiToolTipHidden = /*#__PURE__*/function () {
|
|
126
|
+
var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4() {
|
|
127
|
+
return _regenerator.default.wrap(function _callee4$(_context4) {
|
|
128
|
+
while (1) {
|
|
129
|
+
switch (_context4.prev = _context4.next) {
|
|
130
|
+
case 0:
|
|
131
|
+
_context4.next = 2;
|
|
132
|
+
return (0, _react.waitFor)(function () {
|
|
133
|
+
var tooltip = document.querySelector('.euiToolTipPopover');
|
|
134
|
+
expect(tooltip).toBeNull();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
case 2:
|
|
138
|
+
return _context4.abrupt("return", _context4.sent);
|
|
139
|
+
|
|
140
|
+
case 3:
|
|
141
|
+
case "end":
|
|
142
|
+
return _context4.stop();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}, _callee4);
|
|
146
|
+
}));
|
|
147
|
+
|
|
148
|
+
return function waitForEuiToolTipHidden() {
|
|
149
|
+
return _ref4.apply(this, arguments);
|
|
150
|
+
};
|
|
151
|
+
}();
|
|
86
152
|
|
|
87
|
-
exports.
|
|
153
|
+
exports.waitForEuiToolTipHidden = waitForEuiToolTipHidden;
|