@elastic/eui 94.4.1 → 94.5.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.
@@ -23,6 +23,8 @@ import { getPosition } from '../resizable_container/helpers';
23
23
  import { EuiFlyout } from './flyout';
24
24
  import { euiFlyoutResizableButtonStyles } from './flyout_resizable.styles';
25
25
  import { jsx as ___EmotionJSX } from "@emotion/react";
26
+ // If not omitted, the correct props don't show up in the docs prop table
27
+
26
28
  export var EuiFlyoutResizable = /*#__PURE__*/forwardRef(function (_ref, ref) {
27
29
  var size = _ref.size,
28
30
  maxWidth = _ref.maxWidth,
@@ -57,9 +59,18 @@ export var EuiFlyoutResizable = /*#__PURE__*/forwardRef(function (_ref, ref) {
57
59
  setFlyoutRef = _useState6[1];
58
60
  var setRefs = useCombinedRefs([setFlyoutRef, ref]);
59
61
  useEffect(function () {
60
- setCallOnResize(false); // Don't call `onResize` for non-user width changes
61
- setFlyoutWidth(flyoutRef ? getFlyoutMinMaxWidth(flyoutRef.offsetWidth) : 0);
62
- }, [flyoutRef, getFlyoutMinMaxWidth, size]);
62
+ if (!flyoutWidth && flyoutRef) {
63
+ setCallOnResize(false); // Don't call `onResize` for non-user width changes
64
+ setFlyoutWidth(getFlyoutMinMaxWidth(flyoutRef.offsetWidth));
65
+ }
66
+ }, [flyoutWidth, flyoutRef, getFlyoutMinMaxWidth]);
67
+
68
+ // Update flyout width when consumers pass in a new `size`
69
+ useEffect(function () {
70
+ setCallOnResize(false);
71
+ // For string `size`s, resetting flyoutWidth to 0 will trigger the above useEffect's recalculation
72
+ setFlyoutWidth(typeof size === 'number' ? getFlyoutMinMaxWidth(size) : 0);
73
+ }, [size, getFlyoutMinMaxWidth]);
63
74
 
64
75
  // Initial numbers to calculate from, on resize drag start
65
76
  var initialWidth = useRef(0);
@@ -169,16 +169,21 @@ export var EuiInputPopover = function EuiInputPopover(_ref) {
169
169
  }
170
170
  closePopover();
171
171
  };
172
- window.addEventListener('scroll', closePopoverOnScroll, {
173
- passive: true,
174
- // for better performance as we won't call preventDefault
175
- capture: true // scroll events don't bubble, they must be captured instead
176
- });
177
172
 
173
+ // Kibana Cypress tests trigger a scroll event in many common situations when the options list div is appended
174
+ // to the DOM; in testing it was always within 100ms, but setting a timeout here for 500ms to be safe
175
+ var timeoutId = setTimeout(function () {
176
+ window.addEventListener('scroll', closePopoverOnScroll, {
177
+ passive: true,
178
+ // for better performance as we won't call preventDefault
179
+ capture: true // scroll events don't bubble, they must be captured instead
180
+ });
181
+ }, 500);
178
182
  return function () {
179
183
  window.removeEventListener('scroll', closePopoverOnScroll, {
180
184
  capture: true
181
185
  });
186
+ clearTimeout(timeoutId);
182
187
  };
183
188
  }
184
189
  }, [closeOnScroll, closePopover, panelEl, inputEl]);
@@ -44,18 +44,21 @@ export var useEuiTextDiff = function useEuiTextDiff(_ref) {
44
44
  var rendereredHtml = useMemo(function () {
45
45
  var html = [];
46
46
  if (textDiff) for (var i = 0; i < textDiff.length; i++) {
47
- var Element = void 0;
47
+ var _Element = void 0;
48
48
  var el = textDiff[i];
49
- if (el[0] === 1) Element = insertComponent;else if (el[0] === -1) Element = deleteComponent;else if (sameComponent) Element = sameComponent;
50
- if (Element) html.push(___EmotionJSX(Element, {
49
+ if (el[0] === 1) _Element = insertComponent;else if (el[0] === -1) _Element = deleteComponent;else if (sameComponent) _Element = sameComponent;
50
+ if (_Element) html.push(___EmotionJSX(_Element, {
51
51
  key: i
52
52
  }, el[1]));else html.push(el[1]);
53
53
  }
54
54
  return html;
55
55
  }, [textDiff, deleteComponent, insertComponent, sameComponent]); // produces diff array
56
56
 
57
- return [___EmotionJSX("span", _extends({
57
+ // specifically defining the return type here as the
58
+ // inferred type is not correct: array vs tuple
59
+ var textDiffResult = [___EmotionJSX("span", _extends({
58
60
  css: styles.euiTextDiff,
59
61
  className: classes
60
62
  }, rest), rendereredHtml), textDiff];
63
+ return textDiffResult;
61
64
  };
@@ -27,7 +27,7 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
27
27
  import React, { Component } from 'react';
28
28
  import PropTypes from "prop-types";
29
29
  import classNames from 'classnames';
30
- import { findPopoverPosition, htmlIdGenerator } from '../../services';
30
+ import { findPopoverPosition, htmlIdGenerator, keys } from '../../services';
31
31
  import { enqueueStateChange } from '../../services/react';
32
32
  import { EuiResizeObserver } from '../observer/resize_observer';
33
33
  import { EuiPortal } from '../portal';
@@ -179,6 +179,14 @@ export var EuiToolTip = /*#__PURE__*/function (_Component) {
179
179
  });
180
180
  _this.hideToolTip();
181
181
  });
182
+ _defineProperty(_assertThisInitialized(_this), "onEscapeKey", function (event) {
183
+ if (event.key === keys.ESCAPE) {
184
+ _this.setState({
185
+ hasFocus: false
186
+ }); // Allows mousing over back into the tooltip to work correctly
187
+ _this.hideToolTip();
188
+ }
189
+ });
182
190
  _defineProperty(_assertThisInitialized(_this), "onMouseOut", function (event) {
183
191
  // Prevent mousing over children from hiding the tooltip by testing for whether the mouse has
184
192
  // left the anchor for a non-child.
@@ -250,6 +258,7 @@ export var EuiToolTip = /*#__PURE__*/function (_Component) {
250
258
  ref: this.setAnchorRef,
251
259
  onBlur: this.onBlur,
252
260
  onFocus: this.onFocus,
261
+ onKeyDown: this.onEscapeKey,
253
262
  onMouseOver: this.showToolTip,
254
263
  onMouseOut: this.onMouseOut,
255
264
  id: id,
package/eui.d.ts CHANGED
@@ -6150,6 +6150,7 @@ declare module '@elastic/eui/src/components/tool_tip/tool_tip' {
6150
6150
  hideToolTip: () => void;
6151
6151
  onFocus: () => void;
6152
6152
  onBlur: () => void;
6153
+ onEscapeKey: (event: React.KeyboardEvent<HTMLSpanElement>) => void;
6153
6154
  onMouseOut: (event: ReactMouseEvent<HTMLSpanElement, MouseEvent>) => void;
6154
6155
  render(): React.JSX.Element;
6155
6156
  }
@@ -11739,14 +11740,14 @@ declare module '@elastic/eui/src/components/flyout/flyout_resizable.styles' {
11739
11740
  declare module '@elastic/eui/src/components/flyout/flyout_resizable' {
11740
11741
  import React from 'react';
11741
11742
  import { EuiFlyoutProps } from '@elastic/eui/src/components/flyout/flyout';
11742
- export type EuiFlyoutResizableProps = Omit<EuiFlyoutProps, 'maxWidth'> & {
11743
+ export type EuiFlyoutResizableProps = {
11743
11744
  maxWidth?: number;
11744
11745
  minWidth?: number;
11745
11746
  /**
11746
11747
  * Optional callback that fires on user resize with the new flyout width
11747
11748
  */
11748
11749
  onResize?: (width: number) => void;
11749
- };
11750
+ } & Omit<EuiFlyoutProps, 'maxWidth' | 'onResize'>;
11750
11751
  export const EuiFlyoutResizable: React.ForwardRefExoticComponent<Omit<EuiFlyoutResizableProps, "ref"> & React.RefAttributes<unknown>>;
11751
11752
 
11752
11753
  }
@@ -16234,7 +16235,7 @@ declare module '@elastic/eui/src/components/tabs/tabbed_content/tabbed_content'
16234
16235
  };
16235
16236
  export class EuiTabbedContent extends Component<EuiTabbedContentProps, EuiTabbedContentState> {
16236
16237
  static defaultProps: {
16237
- autoFocus: string;
16238
+ autoFocus: EuiTabbedContentProps['autoFocus'];
16238
16239
  };
16239
16240
  private readonly rootId;
16240
16241
  private readonly tabsRef;
@@ -23603,7 +23604,7 @@ declare module '@elastic/eui/src/components/text_diff/text_diff.styles' {
23603
23604
 
23604
23605
  }
23605
23606
  declare module '@elastic/eui/src/components/text_diff/text_diff' {
23606
- import React, { HTMLAttributes, ElementType } from 'react';
23607
+ import { HTMLAttributes, ElementType } from 'react';
23607
23608
  import { CommonProps } from '@elastic/eui/src/components/common';
23608
23609
  interface Props {
23609
23610
  /**
@@ -23635,7 +23636,7 @@ declare module '@elastic/eui/src/components/text_diff/text_diff' {
23635
23636
  timeout?: number;
23636
23637
  }
23637
23638
  export type EuiTextDiffProps = CommonProps & Props & HTMLAttributes<HTMLElement>;
23638
- export const useEuiTextDiff: ({ className, insertComponent, deleteComponent, sameComponent, beforeText, afterText, timeout, ...rest }: EuiTextDiffProps) => (React.JSX.Element | [0 | 1 | -1, string][])[];
23639
+ export const useEuiTextDiff: ({ className, insertComponent, deleteComponent, sameComponent, beforeText, afterText, timeout, ...rest }: EuiTextDiffProps) => [JSX.Element, [0 | 1 | -1, string][]];
23639
23640
  export {};
23640
23641
 
23641
23642
  }
@@ -31,6 +31,8 @@ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefine
31
31
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
32
32
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
33
33
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
34
+ // If not omitted, the correct props don't show up in the docs prop table
35
+
34
36
  var EuiFlyoutResizable = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
35
37
  var size = _ref.size,
36
38
  maxWidth = _ref.maxWidth,
@@ -65,9 +67,18 @@ var EuiFlyoutResizable = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref
65
67
  setFlyoutRef = _useState6[1];
66
68
  var setRefs = (0, _services.useCombinedRefs)([setFlyoutRef, ref]);
67
69
  (0, _react.useEffect)(function () {
68
- setCallOnResize(false); // Don't call `onResize` for non-user width changes
69
- setFlyoutWidth(flyoutRef ? getFlyoutMinMaxWidth(flyoutRef.offsetWidth) : 0);
70
- }, [flyoutRef, getFlyoutMinMaxWidth, size]);
70
+ if (!flyoutWidth && flyoutRef) {
71
+ setCallOnResize(false); // Don't call `onResize` for non-user width changes
72
+ setFlyoutWidth(getFlyoutMinMaxWidth(flyoutRef.offsetWidth));
73
+ }
74
+ }, [flyoutWidth, flyoutRef, getFlyoutMinMaxWidth]);
75
+
76
+ // Update flyout width when consumers pass in a new `size`
77
+ (0, _react.useEffect)(function () {
78
+ setCallOnResize(false);
79
+ // For string `size`s, resetting flyoutWidth to 0 will trigger the above useEffect's recalculation
80
+ setFlyoutWidth(typeof size === 'number' ? getFlyoutMinMaxWidth(size) : 0);
81
+ }, [size, getFlyoutMinMaxWidth]);
71
82
 
72
83
  // Initial numbers to calculate from, on resize drag start
73
84
  var initialWidth = (0, _react.useRef)(0);
@@ -177,16 +177,21 @@ var EuiInputPopover = function EuiInputPopover(_ref) {
177
177
  }
178
178
  closePopover();
179
179
  };
180
- window.addEventListener('scroll', closePopoverOnScroll, {
181
- passive: true,
182
- // for better performance as we won't call preventDefault
183
- capture: true // scroll events don't bubble, they must be captured instead
184
- });
185
180
 
181
+ // Kibana Cypress tests trigger a scroll event in many common situations when the options list div is appended
182
+ // to the DOM; in testing it was always within 100ms, but setting a timeout here for 500ms to be safe
183
+ var timeoutId = setTimeout(function () {
184
+ window.addEventListener('scroll', closePopoverOnScroll, {
185
+ passive: true,
186
+ // for better performance as we won't call preventDefault
187
+ capture: true // scroll events don't bubble, they must be captured instead
188
+ });
189
+ }, 500);
186
190
  return function () {
187
191
  window.removeEventListener('scroll', closePopoverOnScroll, {
188
192
  capture: true
189
193
  });
194
+ clearTimeout(timeoutId);
190
195
  };
191
196
  }
192
197
  }, [closeOnScroll, closePopover, panelEl, inputEl]);
@@ -53,19 +53,22 @@ var useEuiTextDiff = function useEuiTextDiff(_ref) {
53
53
  var rendereredHtml = (0, _react.useMemo)(function () {
54
54
  var html = [];
55
55
  if (textDiff) for (var i = 0; i < textDiff.length; i++) {
56
- var Element = void 0;
56
+ var _Element = void 0;
57
57
  var el = textDiff[i];
58
- if (el[0] === 1) Element = insertComponent;else if (el[0] === -1) Element = deleteComponent;else if (sameComponent) Element = sameComponent;
59
- if (Element) html.push((0, _react2.jsx)(Element, {
58
+ if (el[0] === 1) _Element = insertComponent;else if (el[0] === -1) _Element = deleteComponent;else if (sameComponent) _Element = sameComponent;
59
+ if (_Element) html.push((0, _react2.jsx)(_Element, {
60
60
  key: i
61
61
  }, el[1]));else html.push(el[1]);
62
62
  }
63
63
  return html;
64
64
  }, [textDiff, deleteComponent, insertComponent, sameComponent]); // produces diff array
65
65
 
66
- return [(0, _react2.jsx)("span", _extends({
66
+ // specifically defining the return type here as the
67
+ // inferred type is not correct: array vs tuple
68
+ var textDiffResult = [(0, _react2.jsx)("span", _extends({
67
69
  css: styles.euiTextDiff,
68
70
  className: classes
69
71
  }, rest), rendereredHtml), textDiff];
72
+ return textDiffResult;
70
73
  };
71
74
  exports.useEuiTextDiff = useEuiTextDiff;
@@ -187,6 +187,14 @@ var EuiToolTip = /*#__PURE__*/function (_Component) {
187
187
  });
188
188
  _this.hideToolTip();
189
189
  });
190
+ _defineProperty(_assertThisInitialized(_this), "onEscapeKey", function (event) {
191
+ if (event.key === _services.keys.ESCAPE) {
192
+ _this.setState({
193
+ hasFocus: false
194
+ }); // Allows mousing over back into the tooltip to work correctly
195
+ _this.hideToolTip();
196
+ }
197
+ });
190
198
  _defineProperty(_assertThisInitialized(_this), "onMouseOut", function (event) {
191
199
  // Prevent mousing over children from hiding the tooltip by testing for whether the mouse has
192
200
  // left the anchor for a non-child.
@@ -258,6 +266,7 @@ var EuiToolTip = /*#__PURE__*/function (_Component) {
258
266
  ref: this.setAnchorRef,
259
267
  onBlur: this.onBlur,
260
268
  onFocus: this.onFocus,
269
+ onKeyDown: this.onEscapeKey,
261
270
  onMouseOver: this.showToolTip,
262
271
  onMouseOut: this.onMouseOut,
263
272
  id: id,
@@ -17,6 +17,8 @@ import { getPosition } from '../resizable_container/helpers';
17
17
  import { EuiFlyout } from './flyout';
18
18
  import { euiFlyoutResizableButtonStyles } from './flyout_resizable.styles';
19
19
  import { jsx as ___EmotionJSX } from "@emotion/react";
20
+ // If not omitted, the correct props don't show up in the docs prop table
21
+
20
22
  export var EuiFlyoutResizable = /*#__PURE__*/forwardRef(function (_ref, ref) {
21
23
  var size = _ref.size,
22
24
  maxWidth = _ref.maxWidth,
@@ -51,9 +53,18 @@ export var EuiFlyoutResizable = /*#__PURE__*/forwardRef(function (_ref, ref) {
51
53
  setFlyoutRef = _useState6[1];
52
54
  var setRefs = useCombinedRefs([setFlyoutRef, ref]);
53
55
  useEffect(function () {
54
- setCallOnResize(false); // Don't call `onResize` for non-user width changes
55
- setFlyoutWidth(flyoutRef ? getFlyoutMinMaxWidth(flyoutRef.offsetWidth) : 0);
56
- }, [flyoutRef, getFlyoutMinMaxWidth, size]);
56
+ if (!flyoutWidth && flyoutRef) {
57
+ setCallOnResize(false); // Don't call `onResize` for non-user width changes
58
+ setFlyoutWidth(getFlyoutMinMaxWidth(flyoutRef.offsetWidth));
59
+ }
60
+ }, [flyoutWidth, flyoutRef, getFlyoutMinMaxWidth]);
61
+
62
+ // Update flyout width when consumers pass in a new `size`
63
+ useEffect(function () {
64
+ setCallOnResize(false);
65
+ // For string `size`s, resetting flyoutWidth to 0 will trigger the above useEffect's recalculation
66
+ setFlyoutWidth(typeof size === 'number' ? getFlyoutMinMaxWidth(size) : 0);
67
+ }, [size, getFlyoutMinMaxWidth]);
57
68
 
58
69
  // Initial numbers to calculate from, on resize drag start
59
70
  var initialWidth = useRef(0);
@@ -159,16 +159,21 @@ export var EuiInputPopover = function EuiInputPopover(_ref) {
159
159
  }
160
160
  closePopover();
161
161
  };
162
- window.addEventListener('scroll', closePopoverOnScroll, {
163
- passive: true,
164
- // for better performance as we won't call preventDefault
165
- capture: true // scroll events don't bubble, they must be captured instead
166
- });
167
162
 
163
+ // Kibana Cypress tests trigger a scroll event in many common situations when the options list div is appended
164
+ // to the DOM; in testing it was always within 100ms, but setting a timeout here for 500ms to be safe
165
+ var timeoutId = setTimeout(function () {
166
+ window.addEventListener('scroll', closePopoverOnScroll, {
167
+ passive: true,
168
+ // for better performance as we won't call preventDefault
169
+ capture: true // scroll events don't bubble, they must be captured instead
170
+ });
171
+ }, 500);
168
172
  return function () {
169
173
  window.removeEventListener('scroll', closePopoverOnScroll, {
170
174
  capture: true
171
175
  });
176
+ clearTimeout(timeoutId);
172
177
  };
173
178
  }
174
179
  }, [closeOnScroll, closePopover, panelEl, inputEl]);
@@ -43,18 +43,21 @@ export var useEuiTextDiff = function useEuiTextDiff(_ref) {
43
43
  var rendereredHtml = useMemo(function () {
44
44
  var html = [];
45
45
  if (textDiff) for (var i = 0; i < textDiff.length; i++) {
46
- var Element = void 0;
46
+ var _Element = void 0;
47
47
  var el = textDiff[i];
48
- if (el[0] === 1) Element = insertComponent;else if (el[0] === -1) Element = deleteComponent;else if (sameComponent) Element = sameComponent;
49
- if (Element) html.push(___EmotionJSX(Element, {
48
+ if (el[0] === 1) _Element = insertComponent;else if (el[0] === -1) _Element = deleteComponent;else if (sameComponent) _Element = sameComponent;
49
+ if (_Element) html.push(___EmotionJSX(_Element, {
50
50
  key: i
51
51
  }, el[1]));else html.push(el[1]);
52
52
  }
53
53
  return html;
54
54
  }, [textDiff, deleteComponent, insertComponent, sameComponent]); // produces diff array
55
55
 
56
- return [___EmotionJSX("span", _extends({
56
+ // specifically defining the return type here as the
57
+ // inferred type is not correct: array vs tuple
58
+ var textDiffResult = [___EmotionJSX("span", _extends({
57
59
  css: styles.euiTextDiff,
58
60
  className: classes
59
61
  }, rest), rendereredHtml), textDiff];
62
+ return textDiffResult;
60
63
  };
@@ -20,7 +20,7 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
20
20
 
21
21
  import React, { Component } from 'react';
22
22
  import classNames from 'classnames';
23
- import { findPopoverPosition, htmlIdGenerator } from '../../services';
23
+ import { findPopoverPosition, htmlIdGenerator, keys } from '../../services';
24
24
  import { enqueueStateChange } from '../../services/react';
25
25
  import { EuiResizeObserver } from '../observer/resize_observer';
26
26
  import { EuiPortal } from '../portal';
@@ -172,6 +172,14 @@ export var EuiToolTip = /*#__PURE__*/function (_Component) {
172
172
  });
173
173
  _this.hideToolTip();
174
174
  });
175
+ _defineProperty(_assertThisInitialized(_this), "onEscapeKey", function (event) {
176
+ if (event.key === keys.ESCAPE) {
177
+ _this.setState({
178
+ hasFocus: false
179
+ }); // Allows mousing over back into the tooltip to work correctly
180
+ _this.hideToolTip();
181
+ }
182
+ });
175
183
  _defineProperty(_assertThisInitialized(_this), "onMouseOut", function (event) {
176
184
  // Prevent mousing over children from hiding the tooltip by testing for whether the mouse has
177
185
  // left the anchor for a non-child.
@@ -243,6 +251,7 @@ export var EuiToolTip = /*#__PURE__*/function (_Component) {
243
251
  ref: this.setAnchorRef,
244
252
  onBlur: this.onBlur,
245
253
  onFocus: this.onFocus,
254
+ onKeyDown: this.onEscapeKey,
246
255
  onMouseOver: this.showToolTip,
247
256
  onMouseOut: this.onMouseOut,
248
257
  id: id,
@@ -26,6 +26,8 @@ var _excluded = ["size", "maxWidth", "minWidth", "onResize", "side", "type", "ch
26
26
  */
27
27
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
28
28
  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; }
29
+ // If not omitted, the correct props don't show up in the docs prop table
30
+
29
31
  var EuiFlyoutResizable = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
30
32
  var size = _ref.size,
31
33
  maxWidth = _ref.maxWidth,
@@ -60,9 +62,18 @@ var EuiFlyoutResizable = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref
60
62
  setFlyoutRef = _useState6[1];
61
63
  var setRefs = (0, _services.useCombinedRefs)([setFlyoutRef, ref]);
62
64
  (0, _react.useEffect)(function () {
63
- setCallOnResize(false); // Don't call `onResize` for non-user width changes
64
- setFlyoutWidth(flyoutRef ? getFlyoutMinMaxWidth(flyoutRef.offsetWidth) : 0);
65
- }, [flyoutRef, getFlyoutMinMaxWidth, size]);
65
+ if (!flyoutWidth && flyoutRef) {
66
+ setCallOnResize(false); // Don't call `onResize` for non-user width changes
67
+ setFlyoutWidth(getFlyoutMinMaxWidth(flyoutRef.offsetWidth));
68
+ }
69
+ }, [flyoutWidth, flyoutRef, getFlyoutMinMaxWidth]);
70
+
71
+ // Update flyout width when consumers pass in a new `size`
72
+ (0, _react.useEffect)(function () {
73
+ setCallOnResize(false);
74
+ // For string `size`s, resetting flyoutWidth to 0 will trigger the above useEffect's recalculation
75
+ setFlyoutWidth(typeof size === 'number' ? getFlyoutMinMaxWidth(size) : 0);
76
+ }, [size, getFlyoutMinMaxWidth]);
66
77
 
67
78
  // Initial numbers to calculate from, on resize drag start
68
79
  var initialWidth = (0, _react.useRef)(0);
@@ -168,16 +168,21 @@ var EuiInputPopover = function EuiInputPopover(_ref) {
168
168
  }
169
169
  closePopover();
170
170
  };
171
- window.addEventListener('scroll', closePopoverOnScroll, {
172
- passive: true,
173
- // for better performance as we won't call preventDefault
174
- capture: true // scroll events don't bubble, they must be captured instead
175
- });
176
171
 
172
+ // Kibana Cypress tests trigger a scroll event in many common situations when the options list div is appended
173
+ // to the DOM; in testing it was always within 100ms, but setting a timeout here for 500ms to be safe
174
+ var timeoutId = setTimeout(function () {
175
+ window.addEventListener('scroll', closePopoverOnScroll, {
176
+ passive: true,
177
+ // for better performance as we won't call preventDefault
178
+ capture: true // scroll events don't bubble, they must be captured instead
179
+ });
180
+ }, 500);
177
181
  return function () {
178
182
  window.removeEventListener('scroll', closePopoverOnScroll, {
179
183
  capture: true
180
184
  });
185
+ clearTimeout(timeoutId);
181
186
  };
182
187
  }
183
188
  }, [closeOnScroll, closePopover, panelEl, inputEl]);
@@ -52,19 +52,22 @@ var useEuiTextDiff = function useEuiTextDiff(_ref) {
52
52
  var rendereredHtml = (0, _react.useMemo)(function () {
53
53
  var html = [];
54
54
  if (textDiff) for (var i = 0; i < textDiff.length; i++) {
55
- var Element = void 0;
55
+ var _Element = void 0;
56
56
  var el = textDiff[i];
57
- if (el[0] === 1) Element = insertComponent;else if (el[0] === -1) Element = deleteComponent;else if (sameComponent) Element = sameComponent;
58
- if (Element) html.push((0, _react2.jsx)(Element, {
57
+ if (el[0] === 1) _Element = insertComponent;else if (el[0] === -1) _Element = deleteComponent;else if (sameComponent) _Element = sameComponent;
58
+ if (_Element) html.push((0, _react2.jsx)(_Element, {
59
59
  key: i
60
60
  }, el[1]));else html.push(el[1]);
61
61
  }
62
62
  return html;
63
63
  }, [textDiff, deleteComponent, insertComponent, sameComponent]); // produces diff array
64
64
 
65
- return [(0, _react2.jsx)("span", (0, _extends2.default)({
65
+ // specifically defining the return type here as the
66
+ // inferred type is not correct: array vs tuple
67
+ var textDiffResult = [(0, _react2.jsx)("span", (0, _extends2.default)({
66
68
  css: styles.euiTextDiff,
67
69
  className: classes
68
70
  }, rest), rendereredHtml), textDiff];
71
+ return textDiffResult;
69
72
  };
70
73
  exports.useEuiTextDiff = useEuiTextDiff;
@@ -181,6 +181,14 @@ var EuiToolTip = /*#__PURE__*/function (_Component) {
181
181
  });
182
182
  _this.hideToolTip();
183
183
  });
184
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onEscapeKey", function (event) {
185
+ if (event.key === _services.keys.ESCAPE) {
186
+ _this.setState({
187
+ hasFocus: false
188
+ }); // Allows mousing over back into the tooltip to work correctly
189
+ _this.hideToolTip();
190
+ }
191
+ });
184
192
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onMouseOut", function (event) {
185
193
  // Prevent mousing over children from hiding the tooltip by testing for whether the mouse has
186
194
  // left the anchor for a non-child.
@@ -252,6 +260,7 @@ var EuiToolTip = /*#__PURE__*/function (_Component) {
252
260
  ref: this.setAnchorRef,
253
261
  onBlur: this.onBlur,
254
262
  onFocus: this.onFocus,
263
+ onKeyDown: this.onEscapeKey,
255
264
  onMouseOver: this.showToolTip,
256
265
  onMouseOut: this.onMouseOut,
257
266
  id: id,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@elastic/eui",
3
3
  "description": "Elastic UI Component Library",
4
- "version": "94.4.1",
4
+ "version": "94.5.0",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "lib",
7
7
  "module": "es",
@@ -26,6 +26,8 @@ var _excluded = ["size", "maxWidth", "minWidth", "onResize", "side", "type", "ch
26
26
  */
27
27
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
28
28
  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; }
29
+ // If not omitted, the correct props don't show up in the docs prop table
30
+
29
31
  var EuiFlyoutResizable = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
30
32
  var size = _ref.size,
31
33
  maxWidth = _ref.maxWidth,
@@ -60,9 +62,18 @@ var EuiFlyoutResizable = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref
60
62
  setFlyoutRef = _useState6[1];
61
63
  var setRefs = (0, _services.useCombinedRefs)([setFlyoutRef, ref]);
62
64
  (0, _react.useEffect)(function () {
63
- setCallOnResize(false); // Don't call `onResize` for non-user width changes
64
- setFlyoutWidth(flyoutRef ? getFlyoutMinMaxWidth(flyoutRef.offsetWidth) : 0);
65
- }, [flyoutRef, getFlyoutMinMaxWidth, size]);
65
+ if (!flyoutWidth && flyoutRef) {
66
+ setCallOnResize(false); // Don't call `onResize` for non-user width changes
67
+ setFlyoutWidth(getFlyoutMinMaxWidth(flyoutRef.offsetWidth));
68
+ }
69
+ }, [flyoutWidth, flyoutRef, getFlyoutMinMaxWidth]);
70
+
71
+ // Update flyout width when consumers pass in a new `size`
72
+ (0, _react.useEffect)(function () {
73
+ setCallOnResize(false);
74
+ // For string `size`s, resetting flyoutWidth to 0 will trigger the above useEffect's recalculation
75
+ setFlyoutWidth(typeof size === 'number' ? getFlyoutMinMaxWidth(size) : 0);
76
+ }, [size, getFlyoutMinMaxWidth]);
66
77
 
67
78
  // Initial numbers to calculate from, on resize drag start
68
79
  var initialWidth = (0, _react.useRef)(0);
@@ -169,16 +169,21 @@ var EuiInputPopover = function EuiInputPopover(_ref) {
169
169
  }
170
170
  closePopover();
171
171
  };
172
- window.addEventListener('scroll', closePopoverOnScroll, {
173
- passive: true,
174
- // for better performance as we won't call preventDefault
175
- capture: true // scroll events don't bubble, they must be captured instead
176
- });
177
172
 
173
+ // Kibana Cypress tests trigger a scroll event in many common situations when the options list div is appended
174
+ // to the DOM; in testing it was always within 100ms, but setting a timeout here for 500ms to be safe
175
+ var timeoutId = setTimeout(function () {
176
+ window.addEventListener('scroll', closePopoverOnScroll, {
177
+ passive: true,
178
+ // for better performance as we won't call preventDefault
179
+ capture: true // scroll events don't bubble, they must be captured instead
180
+ });
181
+ }, 500);
178
182
  return function () {
179
183
  window.removeEventListener('scroll', closePopoverOnScroll, {
180
184
  capture: true
181
185
  });
186
+ clearTimeout(timeoutId);
182
187
  };
183
188
  }
184
189
  }, [closeOnScroll, closePopover, panelEl, inputEl]);
@@ -52,19 +52,22 @@ var useEuiTextDiff = function useEuiTextDiff(_ref) {
52
52
  var rendereredHtml = (0, _react.useMemo)(function () {
53
53
  var html = [];
54
54
  if (textDiff) for (var i = 0; i < textDiff.length; i++) {
55
- var Element = void 0;
55
+ var _Element = void 0;
56
56
  var el = textDiff[i];
57
- if (el[0] === 1) Element = insertComponent;else if (el[0] === -1) Element = deleteComponent;else if (sameComponent) Element = sameComponent;
58
- if (Element) html.push((0, _react2.jsx)(Element, {
57
+ if (el[0] === 1) _Element = insertComponent;else if (el[0] === -1) _Element = deleteComponent;else if (sameComponent) _Element = sameComponent;
58
+ if (_Element) html.push((0, _react2.jsx)(_Element, {
59
59
  key: i
60
60
  }, el[1]));else html.push(el[1]);
61
61
  }
62
62
  return html;
63
63
  }, [textDiff, deleteComponent, insertComponent, sameComponent]); // produces diff array
64
64
 
65
- return [(0, _react2.jsx)("span", (0, _extends2.default)({
65
+ // specifically defining the return type here as the
66
+ // inferred type is not correct: array vs tuple
67
+ var textDiffResult = [(0, _react2.jsx)("span", (0, _extends2.default)({
66
68
  css: styles.euiTextDiff,
67
69
  className: classes
68
70
  }, rest), rendereredHtml), textDiff];
71
+ return textDiffResult;
69
72
  };
70
73
  exports.useEuiTextDiff = useEuiTextDiff;
@@ -182,6 +182,14 @@ var EuiToolTip = /*#__PURE__*/function (_Component) {
182
182
  });
183
183
  _this.hideToolTip();
184
184
  });
185
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onEscapeKey", function (event) {
186
+ if (event.key === _services.keys.ESCAPE) {
187
+ _this.setState({
188
+ hasFocus: false
189
+ }); // Allows mousing over back into the tooltip to work correctly
190
+ _this.hideToolTip();
191
+ }
192
+ });
185
193
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onMouseOut", function (event) {
186
194
  // Prevent mousing over children from hiding the tooltip by testing for whether the mouse has
187
195
  // left the anchor for a non-child.
@@ -253,6 +261,7 @@ var EuiToolTip = /*#__PURE__*/function (_Component) {
253
261
  ref: this.setAnchorRef,
254
262
  onBlur: this.onBlur,
255
263
  onFocus: this.onFocus,
264
+ onKeyDown: this.onEscapeKey,
256
265
  onMouseOver: this.showToolTip,
257
266
  onMouseOut: this.onMouseOut,
258
267
  id: id,
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2018 HackerOne Inc and individual contributors
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,168 +0,0 @@
1
- _Forked by @elastic/eui from Hacker0x01/react-datepicker for accessibility and consolidation of services._
2
-
3
- Decision to not use a more traditional "vendor" directory approach includes redundant services, unnecessary dependencies, and a separate build pipeline. Most notably, `react-datepicker` included third-party popover and focus trap service and components that do not align with EUI interaction standards and were replaced, at parity, with EUI components.
4
-
5
- Other modifications:
6
-
7
- * Changed to `.js` naming to conform to EUI build processes
8
- * Removed files related to repository management and publishing
9
- * Adjusted `babel.rc` and `package.json` naming to avoid babel configuration conflicts
10
-
11
- ___
12
- # React Date Picker
13
-
14
- [![npm version](https://badge.fury.io/js/react-datepicker.svg)](https://badge.fury.io/js/react-datepicker)
15
- [![Build Status](https://travis-ci.org/Hacker0x01/react-datepicker.svg?branch=master)](https://travis-ci.org/Hacker0x01/react-datepicker)
16
- [![Dependency Status](https://david-dm.org/Hacker0x01/react-datepicker.svg)](https://david-dm.org/Hacker0x01/react-datepicker)
17
- [![codecov](https://codecov.io/gh/Hacker0x01/react-datepicker/branch/master/graph/badge.svg)](https://codecov.io/gh/Hacker0x01/react-datepicker)
18
- [![Downloads](http://img.shields.io/npm/dm/react-datepicker.svg)](https://npmjs.org/package/react-datepicker)
19
- [![Code Quality: Javascript](https://img.shields.io/lgtm/grade/javascript/g/Hacker0x01/react-datepicker.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Hacker0x01/react-datepicker/context:javascript)
20
- [![Total Alerts](https://img.shields.io/lgtm/alerts/g/Hacker0x01/react-datepicker.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Hacker0x01/react-datepicker/alerts)
21
-
22
- A simple and reusable Datepicker component for React ([Demo](https://reactdatepicker.com/))
23
-
24
- ![](https://cloud.githubusercontent.com/assets/1412392/5339491/c40de124-7ee1-11e4-9f07-9276e2545f27.png)
25
-
26
- ## Installation
27
-
28
- The package can be installed via NPM:
29
-
30
- ```
31
- npm install react-datepicker --save
32
- ```
33
-
34
- You’ll need to install React, PropTypes, and Moment.js separately since those dependencies aren’t included in the package. Below is a simple example of how to use the Datepicker in a React view. You will also need to require the CSS file from this package (or provide your own). The example below shows how to include the CSS from this package if your build system supports requiring CSS files (Webpack is one that does).
35
-
36
- ```js
37
- import React from "react";
38
- import DatePicker from "react-datepicker";
39
- import moment from "moment";
40
-
41
- import "react-datepicker/dist/react-datepicker.css";
42
-
43
- // CSS Modules, react-datepicker-cssmodules.css
44
- // import 'react-datepicker/dist/react-datepicker-cssmodules.css';
45
-
46
- class Example extends React.Component {
47
- constructor(props) {
48
- super(props);
49
- this.state = {
50
- startDate: moment()
51
- };
52
- this.handleChange = this.handleChange.bind(this);
53
- }
54
-
55
- handleChange(date) {
56
- this.setState({
57
- startDate: date
58
- });
59
- }
60
-
61
- render() {
62
- return (
63
- <DatePicker
64
- selected={this.state.startDate}
65
- onChange={this.handleChange}
66
- />
67
- );
68
- }
69
- }
70
- ```
71
-
72
- ## Configuration
73
-
74
- The most basic use of the DatePicker can be described with:
75
-
76
- ```js
77
- <DatePicker selected={this.state.date} onChange={this.handleChange} />
78
- ```
79
-
80
- You can use `onSelect` event handler which fires each time some calendar date has been selected
81
-
82
- ```js
83
- <DatePicker
84
- selected={this.state.date}
85
- onSelect={this.handleSelect} //when day is clicked
86
- onChange={this.handleChange} //only when value has changed
87
- />
88
- ```
89
-
90
- `onClickOutside` handler may be useful to close datepicker in `inline` mode
91
-
92
- See [here](https://github.com/Hacker0x01/react-datepicker/blob/master/docs/datepicker.md) for a full list of props that may be passed to the component. Examples are given on the [main website](https://hacker0x01.github.io/react-datepicker).
93
-
94
- ### Time picker
95
-
96
- You can also include a time picker by adding the showTimeSelect prop
97
-
98
- ```js
99
- <DatePicker
100
- selected={this.state.date}
101
- onChange={this.handleChange}
102
- showTimeSelect
103
- dateFormat="LLL"
104
- />
105
- ```
106
-
107
- Times will be displayed at 30-minute intervals by default (default configurable via timeInterval prop)
108
-
109
- More examples of how to use the time picker are given on the [main website](https://hacker0x01.github.io/react-datepicker)
110
-
111
- ### Localization
112
-
113
- The date picker relies on [moment.js internationalization](http://momentjs.com/docs/#/i18n/) to localize its display components. By default, the date picker will use the locale globally set in moment, which is English. Locales can be changed in the following ways:
114
-
115
- * **Globally** by calling `moment.locale(lang)`
116
- * **Picker-specific** by providing the `locale` prop
117
-
118
- Locales can be further configured in moment with various [customization options](http://momentjs.com/docs/#/customization/).
119
-
120
- _As of version 0.23, the `weekdays` and `weekStart` DatePicker props have been removed. Instead, they can be configured with the `weekdaysMin` and `week.dow` moment locale customization options._
121
-
122
- ## Compatibility
123
-
124
- ### React
125
-
126
- We're always trying to stay compatible with the latest version of React. We can't support all older versions of React.
127
-
128
- Latest compatible versions:
129
-
130
- * React 15.5 or newer: All above React-datepicker v.0.40.0
131
- * React 15.4.1: needs React-datepicker v0.40.0, newer won't work (due to react-onclickoutside dependencies)
132
- * React 0.14 or newer: All above React-datepicker v0.13.0
133
- * React 0.13: React-datepicker v0.13.0
134
- * pre React 0.13: React-datepicker v0.6.2
135
-
136
- ### Browser Support
137
-
138
- The date picker is compatible with the latest versions of Chrome, Firefox, and IE10+.
139
-
140
- Unfortunately, it is difficult to support legacy browsers while maintaining our ability to develop new features in the future. For IE9 support, it is known that the [classlist polyfill](https://www.npmjs.com/package/classlist-polyfill) is needed, but this may change or break at any point in the future.
141
-
142
- ## Local Development
143
-
144
- The `master` branch contains the latest version of the Datepicker component. To start your example app, you can run `yarn start`. This starts a simple webserver on http://localhost:8080.
145
-
146
- You can run `yarn test` to execute the test suite and linters. To help you develop the component we’ve set up some tests that cover the basic functionality (can be found in `/tests`). Even though we’re big fans of testing, this only covers a small piece of the component. We highly recommend you add tests when you’re adding new functionality.
147
-
148
- ### The examples
149
-
150
- The examples are hosted within the docs folder and are ran in the simple app that loads the Datepicker. To extend the examples with a new example, you can simply duplicate one of the existing examples and change the unique properties of your example.
151
-
152
- ## Accessibility
153
-
154
- ### Keyboard support
155
-
156
- * _Left_: Move to the previous day.
157
- * _Right_: Move to the next day.
158
- * _Up_: Move to the previous week.
159
- * _Down_: Move to the next week.
160
- * _PgUp_: Move to the previous month.
161
- * _PgDn_: Move to the next month.
162
- * _Home_: Move to the previous year.
163
- * _End_: Move to the next year.
164
- * _Enter/Esc/Tab_: close the calendar. (Enter & Esc calls preventDefault)
165
-
166
- ## License
167
-
168
- Copyright (c) 2018 HackerOne Inc. and individual contributors. Licensed under MIT license, see [LICENSE](LICENSE) for the full license.
@@ -1,153 +0,0 @@
1
- # JavaScript-based theming in EUI
2
-
3
- The style system to replace Sass and Sass-based design tokens in EUI.
4
-
5
- * Theme construction via a Proxy-based system with cascading and computed values
6
- * Proxy-based: allows for the theme system to reference its own values (for reuse or for computational manipulation)
7
- * Cascading: conceptually similar to Sass, where variable location and order are important
8
- * Extendable: allows for appending style variables to the EUI theme structure, scoped to a React context provider
9
- * Override-able: all theme tokens/variables can be altered by consumers
10
- * Theme consumption via React hook and HOC methods
11
- * Color mode support as first-class consideration
12
- * "Light" and "dark" mode accounting
13
- * Theme consumption is scoped to the current color mode (set in the context provider)
14
- * Style adaptaion based on a smal set of base values
15
- * Text colors are calculated with WCAG Level AA (4.5:1) in mind
16
- * Scalable typographic and spacing rhythms
17
-
18
-
19
- ## Layers of the theme system
20
-
21
- ### Unbuilt theme
22
-
23
- _See [`euiThemeDefault`](../../themes/eui/theme.ts)_
24
- An unbuilt theme is a composed object of style values or `computed` functions.
25
-
26
- #### Style values
27
-
28
- Think design tokens or CSS property values. Ready to be consumed as-is in an application environment, using some JavaScript method of applying styles (i.e., a CSS-in-JS library is not required).
29
-
30
- #### `computed` functions
31
-
32
- These properties specify that the value depends upon some other value in the theme, in the shape of:
33
-
34
- ```js
35
- computed(
36
- ([size]) => size * 2 // predicate. What to do with the dependency values,
37
- ['sizes.euiSize'], // dependency array, referencing other properties in the theme object
38
- )
39
- ```
40
-
41
- The dependency array is optional. Omitting the array gives access to the computed theme.
42
-
43
- ```js
44
- computed(
45
- (theme) => theme.sizes.euiSize * 2
46
- )
47
- ```
48
-
49
- ### Theme system (built theme)
50
-
51
- _See [`EuiThemeDefault`](../../themes/eui/theme.ts)_
52
- A built theme by way of `buildTheme`, which transforms the object containing static style values and `computed` functions into a JavaScript Proxy object with handler traps. In this state, the theme is essentially inaccessible and immutable, that is, it requires `getComputed` to correctly order and access values and dependencies, and `set()` is disabled.
53
-
54
- ### Computed theme
55
-
56
- _See [`EuiThemeContext`](../../themes/eui/context.ts)_
57
- A consumable theme object in which all `computed` function values have been computed; all values are accessible and usable in an application environment.
58
- Returned from `getComputed`, in the shape of:
59
-
60
- ```js
61
- getComputed(
62
- EuiThemeDefault, // Theme system (Proxy)
63
- {}, // Modifications object
64
- 'light' // Color mode
65
- )
66
- ```
67
-
68
- #### Modifications
69
-
70
- Because the theme system (built theme) is immutable, modifications can only be made at compute time by providing overrides and extensions for theme property values. These modifications are passed to the `EuiThemeProvider` via the `modify` prop and should match the high-level object shape of the theme.
71
-
72
- #### Color mode
73
-
74
- Think light and dark mode. A theme has built-in color mode support, using the reserved `LIGHT` and `DARK` keys as a marker:
75
-
76
- ```js
77
- colors: {
78
- LIGHT: {...}
79
- DARK : {...}
80
- }
81
- ```
82
- The reserved color mode keys can be used at any level and location in a theme.
83
- `getComputed` will only compute and return values in the specified current color mode.
84
-
85
-
86
- ## React-specific context
87
-
88
- ### EuiThemeProvider
89
-
90
- _See [`EuiThemeProvider`](../../themes/eui/provider.ts)_
91
- Umbrella provider component that holds the various top-level theme configuration option providers: theme system, color mode, modifications; as well as the primary output provider: computed theme.
92
- The actual computation for computed theme values takes place at this level, where the three inputs are known (theme system, color mode, modifications) and the output (computed theme) can be cached for consumption. Input changes are captured and the output is recomputed.
93
-
94
- ```js
95
- <EuiThemeProvider
96
- theme={DefaultEuiTheme}
97
- colorMode="light"
98
- modify={{}}
99
- />
100
- ```
101
-
102
- All three props are optional. The default values for EUI will be used in the event that no configuration is provided. Note, however that colorMode switching will require consumers to maintain that app state.
103
-
104
- ### useEuiTheme
105
-
106
- _See [`useEuiTheme`](../../themes/eui/hooks.tsx)_
107
- A custom React hook that returns the computed theme. This hook is little more than a wrapper around the `useContext` hook, accessing three of the top-level providers: computed theme, color mode, and modifications.
108
-
109
- ```js
110
- const { euiTheme, colorMode, modifications } = useEuiTheme();
111
- ```
112
-
113
- The `euiTheme` variable has TypeScript support, which will result in IDE autocomplete availability.
114
-
115
- ### WithEuiTheme
116
- A higher-order-component that wraps `useEuiTheme` for React class components.
117
-
118
-
119
- ___
120
-
121
-
122
- ## Emotion
123
-
124
- [Emotion](https://emotion.sh/docs/introduction) is the CSS-in-JS library currently selected for use in EUI. Nothing in the EUI theming system is dependent upon Emotion packages, but the Emotion ecosystem will have impacts on generated styles.
125
-
126
- ### Composition
127
-
128
- * Prefer the use of [`css` prop](https://emotion.sh/docs/css-prop) construction over [styled-component-like](https://emotion.sh/docs/styled) component construction
129
- * Babel-based build accommodation
130
-
131
- ### Testing
132
-
133
- Snapshot testing ([as currently configured](https://emotion.sh/docs/testing#writing-a-test)) will result in generic `emotion-${n}` class names with the generated style object as part of the snapshot.
134
-
135
- * This seems good for EUI, but it also affects consumers
136
- * Consumers will need to use the `@emotion/jest` snapshot serializer to avoid class name churn.
137
- * Not ideal; unsure of any other solutions
138
- * During the conversion process, the snapshot diffs will look less than ideal when using `shallow` (a single wrapper element; DOM itself is unchanged):
139
-
140
- ```diff
141
- - <div
142
- - className="euiTableRowCell__mobileHeader euiTableRowCell--hideForDesktop"
143
- + <EmotionCssPropInternal
144
- + __EMOTION_LABEL_PLEASE_DO_NOT_USE__="EuiTableRowCell"
145
- + __EMOTION_TYPE_PLEASE_DO_NOT_USE__="td"
146
- + className="euiTableRowCell"
147
- + style={
148
- + Object {
149
- + "width": undefined,
150
- + }
151
- + }
152
- >
153
- ```
@@ -1,44 +0,0 @@
1
- # Testing-related utilities
2
-
3
- EUI uses many of the utilities in this directory in its own Jest tests and, in case they are useful for consuming apps, exports them from `@elastic/eui/lib/test` (commonjs) and `@elastic/eui/es/test` (esm)
4
-
5
- ### findTestSubject
6
-
7
- Provides a quick mechanism for searching an Enzyme-mounted component tree for an element with a specific `data-test-subj` attribute.
8
-
9
- ```js
10
- // if mountedComponent contains e.g. <button data-test-subj="custom-button"/>, this would return that button
11
- const component = findTestSubject(mountedComponent, 'custom-button');
12
- ```
13
-
14
- ### startThrowingReactWarnings
15
-
16
- Patches `console.warn` and `console.error` to throw any warnings or errors, causing Jest to fail the test. This catches warnings emitted by React.
17
-
18
- ### stopThrowingReactWarnings
19
-
20
- Must be called after `startThrowingReactWarnings`, this unpatches the console and restores normal functionality.
21
-
22
- ### sleep
23
-
24
- Returns an `await`able promise that resolves after the specified duration.
25
-
26
- ```js
27
- doSomeAction();
28
- await sleep(500); // wait 500ms
29
- expect(resultOfSomeAction);
30
- ```
31
-
32
- ### takeMountedSnapshot
33
-
34
- Use this function to generate a Jest snapshot of components that have been fully rendered using Enzyme's `mount` method. Typically, a mounted component will result in a snapshot containing both React components and HTML elements. This function removes the React components, leaving only HTML elements in the snapshot.
35
-
36
- This function takes an optional configuration as a second argument, which supports one option: `hasArrayOutput`. Enable this option if the mounted component has multiple direct children, otherwise only the first is included in the snapshot.
37
-
38
- ```js
39
- expect(
40
- takeMountedSnapshot(mountedComponent, {
41
- hasArrayOutput: true,
42
- })
43
- ).toMatchSnapshot();
44
- ```