@elastic/eui 88.1.0 → 88.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.
Files changed (111) hide show
  1. package/dist/eui_charts_theme.js.map +1 -1
  2. package/dist/eui_theme_dark.css +9 -36
  3. package/dist/eui_theme_dark.min.css +1 -1
  4. package/dist/eui_theme_light.css +9 -36
  5. package/dist/eui_theme_light.min.css +1 -1
  6. package/es/components/accordion/accordion.js +34 -9
  7. package/es/components/accordion/accordion.styles.js +29 -9
  8. package/es/components/collapsible_nav/collapsible_nav_group/collapsible_nav_group.js +10 -2
  9. package/es/components/collapsible_nav_beta/collapsible_nav_beta.js +2 -25
  10. package/es/components/collapsible_nav_beta/collapsible_nav_beta.styles.js +10 -1
  11. package/es/components/flyout/flyout.styles.js +1 -1
  12. package/es/components/header/header.js +120 -25
  13. package/es/components/header/header.styles.js +1 -1
  14. package/es/components/index.js +1 -0
  15. package/es/components/overlay_mask/overlay_mask.styles.js +1 -1
  16. package/es/components/page/page_sidebar/page_sidebar.js +2 -4
  17. package/es/components/page_template/page_template.js +4 -31
  18. package/es/components/text_truncate/index.js +10 -0
  19. package/es/components/text_truncate/text_truncate.js +232 -0
  20. package/es/components/text_truncate/text_truncate.styles.js +49 -0
  21. package/es/components/text_truncate/utils.js +348 -0
  22. package/es/services/theme/context.js +3 -1
  23. package/es/services/theme/hooks.js +19 -1
  24. package/es/services/theme/index.js +1 -1
  25. package/es/services/theme/provider.js +37 -8
  26. package/eui.d.ts +246 -17
  27. package/i18ntokens.json +8 -8
  28. package/lib/components/accordion/accordion.js +33 -8
  29. package/lib/components/accordion/accordion.styles.js +31 -10
  30. package/lib/components/collapsible_nav/collapsible_nav_group/collapsible_nav_group.js +10 -2
  31. package/lib/components/collapsible_nav_beta/collapsible_nav_beta.js +2 -25
  32. package/lib/components/collapsible_nav_beta/collapsible_nav_beta.styles.js +10 -1
  33. package/lib/components/flyout/flyout.styles.js +1 -1
  34. package/lib/components/header/header.js +120 -23
  35. package/lib/components/header/header.styles.js +1 -1
  36. package/lib/components/index.js +11 -0
  37. package/lib/components/overlay_mask/overlay_mask.styles.js +1 -1
  38. package/lib/components/page/page_sidebar/page_sidebar.js +2 -4
  39. package/lib/components/page_template/page_template.js +2 -29
  40. package/lib/components/text_truncate/index.js +25 -0
  41. package/lib/components/text_truncate/text_truncate.js +242 -0
  42. package/lib/components/text_truncate/text_truncate.styles.js +54 -0
  43. package/lib/components/text_truncate/utils.js +352 -0
  44. package/lib/services/theme/context.js +3 -1
  45. package/lib/services/theme/hooks.js +21 -2
  46. package/lib/services/theme/index.js +6 -0
  47. package/lib/services/theme/provider.js +62 -35
  48. package/optimize/es/components/accordion/accordion.js +19 -7
  49. package/optimize/es/components/accordion/accordion.styles.js +29 -9
  50. package/optimize/es/components/collapsible_nav_beta/collapsible_nav_beta.js +2 -25
  51. package/optimize/es/components/collapsible_nav_beta/collapsible_nav_beta.styles.js +10 -1
  52. package/optimize/es/components/flyout/flyout.styles.js +1 -1
  53. package/optimize/es/components/header/header.js +75 -25
  54. package/optimize/es/components/header/header.styles.js +1 -1
  55. package/optimize/es/components/index.js +1 -0
  56. package/optimize/es/components/overlay_mask/overlay_mask.styles.js +1 -1
  57. package/optimize/es/components/page/page_sidebar/page_sidebar.js +2 -4
  58. package/optimize/es/components/page_template/page_template.js +4 -26
  59. package/optimize/es/components/text_truncate/index.js +10 -0
  60. package/optimize/es/components/text_truncate/text_truncate.js +148 -0
  61. package/optimize/es/components/text_truncate/text_truncate.styles.js +49 -0
  62. package/optimize/es/components/text_truncate/utils.js +337 -0
  63. package/optimize/es/services/theme/context.js +3 -1
  64. package/optimize/es/services/theme/hooks.js +19 -1
  65. package/optimize/es/services/theme/index.js +1 -1
  66. package/optimize/es/services/theme/provider.js +37 -8
  67. package/optimize/lib/components/accordion/accordion.js +18 -6
  68. package/optimize/lib/components/accordion/accordion.styles.js +31 -10
  69. package/optimize/lib/components/collapsible_nav_beta/collapsible_nav_beta.js +2 -25
  70. package/optimize/lib/components/collapsible_nav_beta/collapsible_nav_beta.styles.js +10 -1
  71. package/optimize/lib/components/flyout/flyout.styles.js +1 -1
  72. package/optimize/lib/components/header/header.js +77 -24
  73. package/optimize/lib/components/header/header.styles.js +1 -1
  74. package/optimize/lib/components/index.js +11 -0
  75. package/optimize/lib/components/overlay_mask/overlay_mask.styles.js +1 -1
  76. package/optimize/lib/components/page/page_sidebar/page_sidebar.js +2 -4
  77. package/optimize/lib/components/page_template/page_template.js +2 -24
  78. package/optimize/lib/components/text_truncate/index.js +25 -0
  79. package/optimize/lib/components/text_truncate/text_truncate.js +158 -0
  80. package/optimize/lib/components/text_truncate/text_truncate.styles.js +54 -0
  81. package/optimize/lib/components/text_truncate/utils.js +342 -0
  82. package/optimize/lib/services/theme/context.js +3 -1
  83. package/optimize/lib/services/theme/hooks.js +21 -2
  84. package/optimize/lib/services/theme/index.js +6 -0
  85. package/optimize/lib/services/theme/provider.js +62 -35
  86. package/package.json +1 -1
  87. package/src/components/datagrid/_data_grid.scss +13 -2
  88. package/src/components/index.scss +0 -1
  89. package/src/global_styling/mixins/_header.scss +2 -0
  90. package/test-env/components/accordion/accordion.js +28 -8
  91. package/test-env/components/accordion/accordion.styles.js +31 -10
  92. package/test-env/components/collapsible_nav/collapsible_nav_group/collapsible_nav_group.js +10 -2
  93. package/test-env/components/collapsible_nav_beta/collapsible_nav_beta.js +2 -25
  94. package/test-env/components/collapsible_nav_beta/collapsible_nav_beta.styles.js +10 -1
  95. package/test-env/components/flyout/flyout.styles.js +1 -1
  96. package/test-env/components/header/header.js +113 -23
  97. package/test-env/components/header/header.styles.js +1 -1
  98. package/test-env/components/index.js +11 -0
  99. package/test-env/components/overlay_mask/overlay_mask.styles.js +1 -1
  100. package/test-env/components/page/page_sidebar/page_sidebar.js +2 -4
  101. package/test-env/components/page_template/page_template.js +2 -24
  102. package/test-env/components/text_truncate/index.js +25 -0
  103. package/test-env/components/text_truncate/text_truncate.js +236 -0
  104. package/test-env/components/text_truncate/text_truncate.styles.js +54 -0
  105. package/test-env/components/text_truncate/utils.js +342 -0
  106. package/test-env/services/theme/context.js +3 -1
  107. package/test-env/services/theme/hooks.js +21 -2
  108. package/test-env/services/theme/index.js +6 -0
  109. package/test-env/services/theme/provider.js +62 -35
  110. package/src/components/accordion/_accordion_form.scss +0 -40
  111. package/src/components/accordion/_index.scss +0 -1
@@ -6,12 +6,6 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
6
6
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
7
7
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
8
8
  function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
9
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
10
- 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."); }
11
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
12
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
13
- function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
14
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
15
9
  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; }
16
10
  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; }
17
11
  /*
@@ -22,7 +16,7 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
22
16
  * Side Public License, v 1.
23
17
  */
24
18
 
25
- import React, { createContext, useContext, useEffect, useState } from 'react';
19
+ import React, { createContext, useContext } from 'react';
26
20
  import PropTypes from "prop-types";
27
21
  import classNames from 'classnames';
28
22
  import { _EuiPageOuter as EuiPageOuter } from './outer';
@@ -30,7 +24,7 @@ import { _EuiPageInner as EuiPageInner } from './inner';
30
24
  import { _EuiPageBottomBar as EuiPageBottomBar } from './bottom_bar/page_bottom_bar';
31
25
  import { _EuiPageEmptyPrompt as EuiPageEmptyPrompt } from './empty_prompt/page_empty_prompt';
32
26
  import { EuiPageHeader, EuiPageSection, EuiPageSidebar } from '../page';
33
- import { useEuiTheme, useGeneratedHtmlId } from '../../services';
27
+ import { useGeneratedHtmlId } from '../../services';
34
28
  import { logicalStyle } from '../../global_styling';
35
29
  import { jsx as ___EmotionJSX } from "@emotion/react";
36
30
  export var TemplateContext = /*#__PURE__*/createContext({
@@ -39,14 +33,6 @@ export var TemplateContext = /*#__PURE__*/createContext({
39
33
  emptyPrompt: {},
40
34
  bottomBar: {}
41
35
  });
42
- var calculateOffset = function calculateOffset(base) {
43
- var _document$body$datase;
44
- if (typeof document === 'undefined') return 0; // SSR catch
45
-
46
- var euiHeaderFixedCounter = Number((_document$body$datase = document.body.dataset.fixedHeaders) !== null && _document$body$datase !== void 0 ? _document$body$datase : 0);
47
- return base * 3 * euiHeaderFixedCounter;
48
- };
49
-
50
36
  /**
51
37
  * Consumed via `EuiPageTemplate`,
52
38
  * it controls and propogates most of the shared props per direct child
@@ -62,7 +48,7 @@ export var _EuiPageTemplate = function _EuiPageTemplate(_ref) {
62
48
  _ref$grow = _ref.grow,
63
49
  grow = _ref$grow === void 0 ? true : _ref$grow,
64
50
  bottomBorder = _ref.bottomBorder,
65
- _offset = _ref.offset,
51
+ offset = _ref.offset,
66
52
  panelled = _ref.panelled,
67
53
  contentBorder = _ref.contentBorder,
68
54
  component = _ref.component,
@@ -71,14 +57,6 @@ export var _EuiPageTemplate = function _EuiPageTemplate(_ref) {
71
57
  _ref$minHeight = _ref.minHeight,
72
58
  minHeight = _ref$minHeight === void 0 ? '460px' : _ref$minHeight,
73
59
  rest = _objectWithoutProperties(_ref, _excluded);
74
- var _useEuiTheme = useEuiTheme(),
75
- euiTheme = _useEuiTheme.euiTheme;
76
- var _useState = useState(function () {
77
- return _offset !== null && _offset !== void 0 ? _offset : calculateOffset(euiTheme.base);
78
- }),
79
- _useState2 = _slicedToArray(_useState, 2),
80
- offset = _useState2[0],
81
- setOffset = _useState2[1];
82
60
  var templateContext = useContext(TemplateContext);
83
61
 
84
62
  // Used as a target to insert the bottom bar component
@@ -86,11 +64,6 @@ export var _EuiPageTemplate = function _EuiPageTemplate(_ref) {
86
64
  prefix: 'EuiPageTemplateInner',
87
65
  conditionalId: mainProps === null || mainProps === void 0 ? void 0 : mainProps.id
88
66
  });
89
- useEffect(function () {
90
- if (_offset === undefined) {
91
- setOffset(calculateOffset(euiTheme.base));
92
- }
93
- }, [_offset, euiTheme.base]);
94
67
 
95
68
  // Sections include page header
96
69
  var sections = [];
@@ -149,7 +122,7 @@ export var _EuiPageTemplate = function _EuiPageTemplate(_ref) {
149
122
  });
150
123
  var _minHeight = grow ? "max(".concat(minHeight, ", 100vh)") : minHeight;
151
124
  var classes = classNames('euiPageTemplate', className);
152
- var pageStyle = _objectSpread(_objectSpread(_objectSpread({}, logicalStyle('min-height', _minHeight)), logicalStyle('padding-top', offset)), rest.style);
125
+ var pageStyle = _objectSpread(_objectSpread(_objectSpread({}, logicalStyle('min-height', _minHeight)), logicalStyle('padding-top', offset !== null && offset !== void 0 ? offset : 'var(--euiFixedHeadersOffset, 0)')), rest.style);
153
126
  templateContext.header = getHeaderProps();
154
127
  templateContext.section = getSectionProps();
155
128
  templateContext.emptyPrompt = {
@@ -0,0 +1,10 @@
1
+ /*
2
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ * or more contributor license agreements. Licensed under the Elastic License
4
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
5
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
6
+ * Side Public License, v 1.
7
+ */
8
+
9
+ export { EuiTextTruncate } from './text_truncate';
10
+ export { TruncationUtilsWithDOM, TruncationUtilsWithCanvas } from './utils';
@@ -0,0 +1,232 @@
1
+ var _excluded = ["width"],
2
+ _excluded2 = ["width", "children", "text", "truncation", "truncationOffset", "truncationPosition", "ellipsis", "containerRef", "measurementRenderAPI"],
3
+ _excluded3 = ["onResize"];
4
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
5
+ 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."); }
6
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
7
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
8
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
9
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
10
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
11
+ 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; }
12
+ 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; }
13
+ /*
14
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
15
+ * or more contributor license agreements. Licensed under the Elastic License
16
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
17
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
18
+ * Side Public License, v 1.
19
+ */
20
+
21
+ import React, { useState, useMemo, useCallback } from 'react';
22
+ import PropTypes from "prop-types";
23
+ import { useCombinedRefs } from '../../services';
24
+ import { EuiResizeObserver } from '../observer/resize_observer';
25
+ import { TruncationUtilsWithDOM, TruncationUtilsWithCanvas } from './utils';
26
+ import { euiTextTruncateStyles } from './text_truncate.styles';
27
+ import { jsx as ___EmotionJSX } from "@emotion/react";
28
+ var TRUNCATION_TYPES = ['end', 'start', 'startEnd', 'middle'];
29
+ export var EuiTextTruncate = function EuiTextTruncate(_ref) {
30
+ var width = _ref.width,
31
+ props = _objectWithoutProperties(_ref, _excluded);
32
+ return width != null ? ___EmotionJSX(EuiTextTruncateWithWidth, _extends({
33
+ width: width
34
+ }, props)) : ___EmotionJSX(EuiTextTruncateWithResizeObserver, props);
35
+ };
36
+ EuiTextTruncate.propTypes = {
37
+ className: PropTypes.string,
38
+ "aria-label": PropTypes.string,
39
+ "data-test-subj": PropTypes.string,
40
+ css: PropTypes.any,
41
+ /**
42
+ * The full text string to truncate
43
+ */
44
+ text: PropTypes.string.isRequired,
45
+ /**
46
+ * The truncation type desired. Determines where the ellipses are placed.
47
+ */
48
+ truncation: PropTypes.any,
49
+ /**
50
+ * This prop **only** applies to the `start` and `end` truncation types.
51
+ * It allows preserving a certain number of characters of either the
52
+ * starting or ending text.
53
+ *
54
+ * If the passed offset is greater than the total text length,
55
+ * the offset will be ignored.
56
+ */
57
+ truncationOffset: PropTypes.number,
58
+ /**
59
+ * This prop **only** applies to the `startEnd` truncation type.
60
+ * It allows customizing the anchor position of the displayed text,
61
+ * which otherwise defaults to the middle of the text string.
62
+ *
63
+ * The primary use case for this prop for is search highlighting - e.g., if
64
+ * a user searches for a specific word in the text, pass the index of that
65
+ * found word to ensure it is always visible.
66
+ *
67
+ * This behavior will intelligently detect when positions are close to the start
68
+ * or end of the text, and omit leading or trailing ellipses when necessary.
69
+ * If the passed position is greater than the total text length,
70
+ * the truncation will simply default to `start` instead.
71
+ */
72
+ truncationPosition: PropTypes.number,
73
+ /**
74
+ * Defaults to the horizontal ellipsis character.
75
+ * Can be optionally configured to use other punctuation,
76
+ * e.g. spaces, brackets, hyphens, asterisks, etc.
77
+ */
78
+ ellipsis: PropTypes.string,
79
+ /**
80
+ * By default, EuiTextTruncate will render a resize observer to detect the
81
+ * available width it has. For performance reasons (e.g. multiple truncated
82
+ * text items within the same container), you may opt to pass in your own
83
+ * container width, which will skip initializing a resize observer.
84
+ */
85
+ width: PropTypes.number,
86
+ /**
87
+ * Optional callback that fires when the default resizer observer both mounts and
88
+ * registers a size change. This callback will **not** fire if `width` is passed.
89
+ */
90
+ onResize: PropTypes.func,
91
+ /**
92
+ * By default, EuiTextTruncate will calculate its truncation via DOM manipulation
93
+ * and measurement, which has the benefit of automatically inheriting font styles.
94
+ * However, if this approach proves to have a significant performance impact for your
95
+ * usage, consider using the `canvas` API instead, which is more performant.
96
+ *
97
+ * Please note that there are minute pixel to subpixel differences between the
98
+ * two options due to different rendering engines.
99
+ */
100
+ measurementRenderAPI: PropTypes.oneOf(["dom", "canvas"]),
101
+ /**
102
+ * By default, EuiTextTruncate will render the truncated string directly.
103
+ * You can optionally pass a render prop function to the component, which
104
+ * allows for more flexible text rendering, e.g. adding custom markup
105
+ * or highlighting
106
+ */
107
+ children: PropTypes.func
108
+ };
109
+ var EuiTextTruncateWithWidth = function EuiTextTruncateWithWidth(_ref2) {
110
+ var width = _ref2.width,
111
+ children = _ref2.children,
112
+ text = _ref2.text,
113
+ _ref2$truncation = _ref2.truncation,
114
+ _truncation = _ref2$truncation === void 0 ? 'end' : _ref2$truncation,
115
+ _ref2$truncationOffse = _ref2.truncationOffset,
116
+ _truncationOffset = _ref2$truncationOffse === void 0 ? 0 : _ref2$truncationOffse,
117
+ truncationPosition = _ref2.truncationPosition,
118
+ _ref2$ellipsis = _ref2.ellipsis,
119
+ ellipsis = _ref2$ellipsis === void 0 ? '…' : _ref2$ellipsis,
120
+ containerRef = _ref2.containerRef,
121
+ _ref2$measurementRend = _ref2.measurementRenderAPI,
122
+ measurementRenderAPI = _ref2$measurementRend === void 0 ? 'dom' : _ref2$measurementRend,
123
+ rest = _objectWithoutProperties(_ref2, _excluded2);
124
+ // Note: This needs to be a state and not a ref to trigger a rerender on mount
125
+ var _useState = useState(null),
126
+ _useState2 = _slicedToArray(_useState, 2),
127
+ containerEl = _useState2[0],
128
+ setContainerEl = _useState2[1];
129
+ var refs = useCombinedRefs([setContainerEl, containerRef]);
130
+
131
+ // Handle exceptions where we need to override the passed props
132
+ var _useMemo = useMemo(function () {
133
+ var truncation = _truncation;
134
+ var truncationOffset = 0;
135
+ if (_truncation === 'end' || _truncation === 'start') {
136
+ if (0 < _truncationOffset && _truncationOffset < text.length) {
137
+ truncationOffset = _truncationOffset;
138
+ }
139
+ } else if (_truncation === 'startEnd' && truncationPosition != null) {
140
+ if (truncationPosition <= 0) {
141
+ truncation = 'end';
142
+ } else if (truncationPosition >= text.length) {
143
+ truncation = 'start';
144
+ }
145
+ }
146
+ return {
147
+ truncation: truncation,
148
+ truncationOffset: truncationOffset
149
+ };
150
+ }, [_truncation, _truncationOffset, truncationPosition, text.length]),
151
+ truncation = _useMemo.truncation,
152
+ truncationOffset = _useMemo.truncationOffset;
153
+ var truncatedText = useMemo(function () {
154
+ var truncatedText = '';
155
+ if (!containerEl || !width) return truncatedText;
156
+ var params = {
157
+ fullText: text,
158
+ ellipsis: ellipsis,
159
+ container: containerEl,
160
+ availableWidth: width
161
+ };
162
+ var utils = measurementRenderAPI === 'canvas' ? new TruncationUtilsWithCanvas(params) : new TruncationUtilsWithDOM(params);
163
+ if (utils.checkIfTruncationIsNeeded() === false) {
164
+ truncatedText = text;
165
+ } else if (utils.checkSufficientEllipsisWidth(truncation) === false) {
166
+ truncatedText = '';
167
+ } else {
168
+ switch (truncation) {
169
+ case 'end':
170
+ truncatedText = utils.truncateEnd(truncationOffset);
171
+ break;
172
+ case 'start':
173
+ truncatedText = utils.truncateStart(truncationOffset);
174
+ break;
175
+ case 'startEnd':
176
+ if (truncationPosition == null) {
177
+ truncatedText = utils.truncateStartEndAtMiddle();
178
+ } else {
179
+ truncatedText = utils.truncateStartEndAtPosition(truncationPosition);
180
+ }
181
+ break;
182
+ case 'middle':
183
+ truncatedText = utils.truncateMiddle();
184
+ break;
185
+ }
186
+ }
187
+ if (measurementRenderAPI === 'dom') {
188
+ utils.cleanup();
189
+ }
190
+ return truncatedText;
191
+ }, [width, text, truncation, truncationOffset, truncationPosition, ellipsis, containerEl, measurementRenderAPI]);
192
+ var isTruncating = truncatedText !== text;
193
+ return ___EmotionJSX("div", _extends({
194
+ css: euiTextTruncateStyles.euiTextTruncate,
195
+ ref: refs,
196
+ title: isTruncating ? text : undefined
197
+ }, rest), isTruncating ? ___EmotionJSX(React.Fragment, null, ___EmotionJSX("span", {
198
+ css: euiTextTruncateStyles.truncatedText,
199
+ "aria-hidden": true,
200
+ "data-test-subj": "truncatedText"
201
+ }, children ? children(truncatedText) : truncatedText), ___EmotionJSX("span", {
202
+ css: euiTextTruncateStyles.fullText,
203
+ "data-test-subj": "fullText"
204
+ }, text)) : ___EmotionJSX("span", {
205
+ "data-test-subj": "fullText"
206
+ }, text));
207
+ };
208
+ EuiTextTruncateWithWidth.propTypes = {
209
+ width: PropTypes.number.isRequired,
210
+ containerRef: PropTypes.any
211
+ };
212
+ var EuiTextTruncateWithResizeObserver = function EuiTextTruncateWithResizeObserver(_ref3) {
213
+ var _onResize = _ref3.onResize,
214
+ props = _objectWithoutProperties(_ref3, _excluded3);
215
+ var _useState3 = useState(0),
216
+ _useState4 = _slicedToArray(_useState3, 2),
217
+ width = _useState4[0],
218
+ setWidth = _useState4[1];
219
+ var onResize = useCallback(function (_ref4) {
220
+ var width = _ref4.width;
221
+ setWidth(width);
222
+ _onResize === null || _onResize === void 0 ? void 0 : _onResize(width);
223
+ }, [_onResize]);
224
+ return ___EmotionJSX(EuiResizeObserver, {
225
+ onResize: onResize
226
+ }, function (ref) {
227
+ return ___EmotionJSX(EuiTextTruncateWithWidth, _extends({
228
+ width: width,
229
+ containerRef: ref
230
+ }, props));
231
+ });
232
+ };
@@ -0,0 +1,49 @@
1
+ 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)."; }
2
+ /*
3
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
4
+ * or more contributor license agreements. Licensed under the Elastic License
5
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
6
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
7
+ * Side Public License, v 1.
8
+ */
9
+
10
+ import { css } from '@emotion/react';
11
+ export var euiTextTruncateStyles = {
12
+ euiTextTruncate: process.env.NODE_ENV === "production" ? {
13
+ name: "7o5qnz-euiTextTruncate",
14
+ styles: "position:relative;overflow:hidden;white-space:nowrap;label:euiTextTruncate;"
15
+ } : {
16
+ name: "7o5qnz-euiTextTruncate",
17
+ styles: "position:relative;overflow:hidden;white-space:nowrap;label:euiTextTruncate;",
18
+ toString: _EMOTION_STRINGIFIED_CSS_ERROR__
19
+ },
20
+ /**
21
+ * The below CSS is a hack to get double clicking and selecting the *full* text
22
+ * instead of the truncated text (useful for copying/pasting, and mimics how
23
+ * `text-overflow: ellipsis` works).
24
+ *
25
+ * Real talk: I'm lowkey amazed it works and it wouldn't surprise me if we ran into
26
+ * cross-browser issues with this at some point. Hopefully CSS natively implements
27
+ * custom text truncation some day (https://github.com/w3c/csswg-drafts/issues/3937)
28
+ * and there'll be no need for the entire component at that point 🙏
29
+ */
30
+ // Makes the truncated text unselectable/un-clickable
31
+ truncatedText: process.env.NODE_ENV === "production" ? {
32
+ name: "1dore6v-truncatedText",
33
+ styles: "user-select:none;pointer-events:none;label:truncatedText;"
34
+ } : {
35
+ name: "1dore6v-truncatedText",
36
+ styles: "user-select:none;pointer-events:none;label:truncatedText;",
37
+ toString: _EMOTION_STRINGIFIED_CSS_ERROR__
38
+ },
39
+ // Positions the full text on top of the truncated text (so that clicking targets it)
40
+ // and gives it a color opacity of 0 so that it's not actually visible
41
+ fullText: process.env.NODE_ENV === "production" ? {
42
+ name: "1kxt4rj-fullText",
43
+ styles: "position:absolute;inset:0;overflow:hidden;color:rgba(0, 0, 0, 0);@supports (-webkit-hyphens: none){text-overflow:ellipsis;};label:fullText;"
44
+ } : {
45
+ name: "1kxt4rj-fullText",
46
+ styles: "position:absolute;inset:0;overflow:hidden;color:rgba(0, 0, 0, 0);@supports (-webkit-hyphens: none){text-overflow:ellipsis;};label:fullText;",
47
+ toString: _EMOTION_STRINGIFIED_CSS_ERROR__
48
+ }
49
+ };