@elastic/eui 88.0.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 (148) hide show
  1. package/dist/eui_charts_theme.js +9 -8
  2. package/dist/eui_charts_theme.js.map +1 -1
  3. package/dist/eui_theme_dark.css +11 -41
  4. package/dist/eui_theme_dark.min.css +1 -1
  5. package/dist/eui_theme_light.css +11 -41
  6. package/dist/eui_theme_light.min.css +1 -1
  7. package/es/components/accordion/accordion.js +34 -9
  8. package/es/components/accordion/accordion.styles.js +29 -9
  9. package/es/components/collapsible_nav/collapsible_nav_group/collapsible_nav_group.js +10 -2
  10. package/es/components/collapsible_nav_beta/collapsible_nav_beta.js +10 -26
  11. package/es/components/collapsible_nav_beta/collapsible_nav_beta.styles.js +10 -1
  12. package/es/components/datagrid/controls/keyboard_shortcuts.js +1 -0
  13. package/es/components/description_list/description_list.js +40 -3
  14. package/es/components/flyout/flyout.styles.js +1 -1
  15. package/es/components/header/header.js +120 -25
  16. package/es/components/header/header.styles.js +1 -1
  17. package/es/components/index.js +1 -0
  18. package/es/components/markdown_editor/markdown_format.styles.js +3 -6
  19. package/es/components/overlay_mask/overlay_mask.styles.js +1 -1
  20. package/es/components/page/page_sidebar/page_sidebar.js +2 -4
  21. package/es/components/page_template/page_template.js +4 -31
  22. package/es/components/text/text.styles.js +3 -6
  23. package/es/components/text_truncate/index.js +10 -0
  24. package/es/components/text_truncate/text_truncate.js +232 -0
  25. package/es/components/text_truncate/text_truncate.styles.js +49 -0
  26. package/es/components/text_truncate/utils.js +348 -0
  27. package/es/global_styling/functions/typography.js +8 -8
  28. package/es/global_styling/variables/typography.js +1 -1
  29. package/es/services/theme/context.js +3 -1
  30. package/es/services/theme/hooks.js +19 -1
  31. package/es/services/theme/index.js +1 -1
  32. package/es/services/theme/provider.js +37 -8
  33. package/es/themes/amsterdam/global_styling/variables/_typography.js +1 -0
  34. package/eui.d.ts +282 -24
  35. package/i18ntokens.json +112 -112
  36. package/lib/components/accordion/accordion.js +33 -8
  37. package/lib/components/accordion/accordion.styles.js +31 -10
  38. package/lib/components/collapsible_nav/collapsible_nav_group/collapsible_nav_group.js +10 -2
  39. package/lib/components/collapsible_nav_beta/collapsible_nav_beta.js +10 -26
  40. package/lib/components/collapsible_nav_beta/collapsible_nav_beta.styles.js +10 -1
  41. package/lib/components/datagrid/controls/keyboard_shortcuts.js +1 -0
  42. package/lib/components/description_list/description_list.js +39 -3
  43. package/lib/components/flyout/flyout.styles.js +1 -1
  44. package/lib/components/header/header.js +120 -23
  45. package/lib/components/header/header.styles.js +1 -1
  46. package/lib/components/index.js +11 -0
  47. package/lib/components/markdown_editor/markdown_format.styles.js +3 -6
  48. package/lib/components/overlay_mask/overlay_mask.styles.js +1 -1
  49. package/lib/components/page/page_sidebar/page_sidebar.js +2 -4
  50. package/lib/components/page_template/page_template.js +2 -29
  51. package/lib/components/text/text.styles.js +3 -6
  52. package/lib/components/text_truncate/index.js +25 -0
  53. package/lib/components/text_truncate/text_truncate.js +242 -0
  54. package/lib/components/text_truncate/text_truncate.styles.js +54 -0
  55. package/lib/components/text_truncate/utils.js +352 -0
  56. package/lib/global_styling/functions/typography.js +8 -8
  57. package/lib/global_styling/variables/typography.js +3 -3
  58. package/lib/services/theme/context.js +3 -1
  59. package/lib/services/theme/hooks.js +21 -2
  60. package/lib/services/theme/index.js +6 -0
  61. package/lib/services/theme/provider.js +62 -35
  62. package/lib/themes/amsterdam/global_styling/variables/_typography.js +1 -0
  63. package/optimize/es/components/accordion/accordion.js +19 -7
  64. package/optimize/es/components/accordion/accordion.styles.js +29 -9
  65. package/optimize/es/components/collapsible_nav_beta/collapsible_nav_beta.js +5 -26
  66. package/optimize/es/components/collapsible_nav_beta/collapsible_nav_beta.styles.js +10 -1
  67. package/optimize/es/components/datagrid/controls/keyboard_shortcuts.js +1 -0
  68. package/optimize/es/components/description_list/description_list.js +22 -2
  69. package/optimize/es/components/flyout/flyout.styles.js +1 -1
  70. package/optimize/es/components/header/header.js +75 -25
  71. package/optimize/es/components/header/header.styles.js +1 -1
  72. package/optimize/es/components/index.js +1 -0
  73. package/optimize/es/components/markdown_editor/markdown_format.styles.js +3 -6
  74. package/optimize/es/components/overlay_mask/overlay_mask.styles.js +1 -1
  75. package/optimize/es/components/page/page_sidebar/page_sidebar.js +2 -4
  76. package/optimize/es/components/page_template/page_template.js +4 -26
  77. package/optimize/es/components/text/text.styles.js +3 -6
  78. package/optimize/es/components/text_truncate/index.js +10 -0
  79. package/optimize/es/components/text_truncate/text_truncate.js +148 -0
  80. package/optimize/es/components/text_truncate/text_truncate.styles.js +49 -0
  81. package/optimize/es/components/text_truncate/utils.js +337 -0
  82. package/optimize/es/global_styling/functions/typography.js +8 -8
  83. package/optimize/es/global_styling/variables/typography.js +1 -1
  84. package/optimize/es/services/theme/context.js +3 -1
  85. package/optimize/es/services/theme/hooks.js +19 -1
  86. package/optimize/es/services/theme/index.js +1 -1
  87. package/optimize/es/services/theme/provider.js +37 -8
  88. package/optimize/es/themes/amsterdam/global_styling/variables/_typography.js +1 -0
  89. package/optimize/lib/components/accordion/accordion.js +18 -6
  90. package/optimize/lib/components/accordion/accordion.styles.js +31 -10
  91. package/optimize/lib/components/collapsible_nav_beta/collapsible_nav_beta.js +5 -26
  92. package/optimize/lib/components/collapsible_nav_beta/collapsible_nav_beta.styles.js +10 -1
  93. package/optimize/lib/components/datagrid/controls/keyboard_shortcuts.js +1 -0
  94. package/optimize/lib/components/description_list/description_list.js +22 -2
  95. package/optimize/lib/components/flyout/flyout.styles.js +1 -1
  96. package/optimize/lib/components/header/header.js +77 -24
  97. package/optimize/lib/components/header/header.styles.js +1 -1
  98. package/optimize/lib/components/index.js +11 -0
  99. package/optimize/lib/components/markdown_editor/markdown_format.styles.js +3 -6
  100. package/optimize/lib/components/overlay_mask/overlay_mask.styles.js +1 -1
  101. package/optimize/lib/components/page/page_sidebar/page_sidebar.js +2 -4
  102. package/optimize/lib/components/page_template/page_template.js +2 -24
  103. package/optimize/lib/components/text/text.styles.js +3 -6
  104. package/optimize/lib/components/text_truncate/index.js +25 -0
  105. package/optimize/lib/components/text_truncate/text_truncate.js +158 -0
  106. package/optimize/lib/components/text_truncate/text_truncate.styles.js +54 -0
  107. package/optimize/lib/components/text_truncate/utils.js +342 -0
  108. package/optimize/lib/global_styling/functions/typography.js +8 -8
  109. package/optimize/lib/global_styling/variables/typography.js +3 -3
  110. package/optimize/lib/services/theme/context.js +3 -1
  111. package/optimize/lib/services/theme/hooks.js +21 -2
  112. package/optimize/lib/services/theme/index.js +6 -0
  113. package/optimize/lib/services/theme/provider.js +62 -35
  114. package/optimize/lib/themes/amsterdam/global_styling/variables/_typography.js +1 -0
  115. package/package.json +1 -1
  116. package/src/components/datagrid/_data_grid.scss +13 -2
  117. package/src/components/datagrid/controls/_data_grid_keyboard_shortcuts.scss +1 -7
  118. package/src/components/index.scss +0 -1
  119. package/src/global_styling/mixins/_header.scss +2 -0
  120. package/test-env/components/accordion/accordion.js +28 -8
  121. package/test-env/components/accordion/accordion.styles.js +31 -10
  122. package/test-env/components/collapsible_nav/collapsible_nav_group/collapsible_nav_group.js +10 -2
  123. package/test-env/components/collapsible_nav_beta/collapsible_nav_beta.js +10 -26
  124. package/test-env/components/collapsible_nav_beta/collapsible_nav_beta.styles.js +10 -1
  125. package/test-env/components/datagrid/controls/keyboard_shortcuts.js +1 -0
  126. package/test-env/components/description_list/description_list.js +37 -3
  127. package/test-env/components/flyout/flyout.styles.js +1 -1
  128. package/test-env/components/header/header.js +113 -23
  129. package/test-env/components/header/header.styles.js +1 -1
  130. package/test-env/components/index.js +11 -0
  131. package/test-env/components/markdown_editor/markdown_format.styles.js +3 -6
  132. package/test-env/components/overlay_mask/overlay_mask.styles.js +1 -1
  133. package/test-env/components/page/page_sidebar/page_sidebar.js +2 -4
  134. package/test-env/components/page_template/page_template.js +2 -24
  135. package/test-env/components/text/text.styles.js +3 -6
  136. package/test-env/components/text_truncate/index.js +25 -0
  137. package/test-env/components/text_truncate/text_truncate.js +236 -0
  138. package/test-env/components/text_truncate/text_truncate.styles.js +54 -0
  139. package/test-env/components/text_truncate/utils.js +342 -0
  140. package/test-env/global_styling/functions/typography.js +8 -8
  141. package/test-env/global_styling/variables/typography.js +3 -3
  142. package/test-env/services/theme/context.js +3 -1
  143. package/test-env/services/theme/hooks.js +21 -2
  144. package/test-env/services/theme/index.js +6 -0
  145. package/test-env/services/theme/provider.js +62 -35
  146. package/test-env/themes/amsterdam/global_styling/variables/_typography.js +1 -0
  147. package/src/components/accordion/_accordion_form.scss +0 -40
  148. package/src/components/accordion/_index.scss +0 -1
@@ -1,6 +1,5 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
3
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
5
4
  var _excluded = ["children", "responsive", "restrictWidth", "paddingSize", "grow", "bottomBorder", "offset", "panelled", "contentBorder", "component", "mainProps", "className", "minHeight"];
6
5
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
@@ -13,14 +12,14 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
13
12
  * Side Public License, v 1.
14
13
  */
15
14
 
16
- import React, { createContext, useContext, useEffect, useState } from 'react';
15
+ import React, { createContext, useContext } from 'react';
17
16
  import classNames from 'classnames';
18
17
  import { _EuiPageOuter as EuiPageOuter } from './outer';
19
18
  import { _EuiPageInner as EuiPageInner } from './inner';
20
19
  import { _EuiPageBottomBar as EuiPageBottomBar } from './bottom_bar/page_bottom_bar';
21
20
  import { _EuiPageEmptyPrompt as EuiPageEmptyPrompt } from './empty_prompt/page_empty_prompt';
22
21
  import { EuiPageHeader, EuiPageSection, EuiPageSidebar } from '../page';
23
- import { useEuiTheme, useGeneratedHtmlId } from '../../services';
22
+ import { useGeneratedHtmlId } from '../../services';
24
23
  import { logicalStyle } from '../../global_styling';
25
24
  import { jsx as ___EmotionJSX } from "@emotion/react";
26
25
  export var TemplateContext = /*#__PURE__*/createContext({
@@ -29,14 +28,6 @@ export var TemplateContext = /*#__PURE__*/createContext({
29
28
  emptyPrompt: {},
30
29
  bottomBar: {}
31
30
  });
32
- var calculateOffset = function calculateOffset(base) {
33
- var _document$body$datase;
34
- if (typeof document === 'undefined') return 0; // SSR catch
35
-
36
- var euiHeaderFixedCounter = Number((_document$body$datase = document.body.dataset.fixedHeaders) !== null && _document$body$datase !== void 0 ? _document$body$datase : 0);
37
- return base * 3 * euiHeaderFixedCounter;
38
- };
39
-
40
31
  /**
41
32
  * Consumed via `EuiPageTemplate`,
42
33
  * it controls and propogates most of the shared props per direct child
@@ -52,7 +43,7 @@ export var _EuiPageTemplate = function _EuiPageTemplate(_ref) {
52
43
  _ref$grow = _ref.grow,
53
44
  grow = _ref$grow === void 0 ? true : _ref$grow,
54
45
  bottomBorder = _ref.bottomBorder,
55
- _offset = _ref.offset,
46
+ offset = _ref.offset,
56
47
  panelled = _ref.panelled,
57
48
  contentBorder = _ref.contentBorder,
58
49
  component = _ref.component,
@@ -61,14 +52,6 @@ export var _EuiPageTemplate = function _EuiPageTemplate(_ref) {
61
52
  _ref$minHeight = _ref.minHeight,
62
53
  minHeight = _ref$minHeight === void 0 ? '460px' : _ref$minHeight,
63
54
  rest = _objectWithoutProperties(_ref, _excluded);
64
- var _useEuiTheme = useEuiTheme(),
65
- euiTheme = _useEuiTheme.euiTheme;
66
- var _useState = useState(function () {
67
- return _offset !== null && _offset !== void 0 ? _offset : calculateOffset(euiTheme.base);
68
- }),
69
- _useState2 = _slicedToArray(_useState, 2),
70
- offset = _useState2[0],
71
- setOffset = _useState2[1];
72
55
  var templateContext = useContext(TemplateContext);
73
56
 
74
57
  // Used as a target to insert the bottom bar component
@@ -76,11 +59,6 @@ export var _EuiPageTemplate = function _EuiPageTemplate(_ref) {
76
59
  prefix: 'EuiPageTemplateInner',
77
60
  conditionalId: mainProps === null || mainProps === void 0 ? void 0 : mainProps.id
78
61
  });
79
- useEffect(function () {
80
- if (_offset === undefined) {
81
- setOffset(calculateOffset(euiTheme.base));
82
- }
83
- }, [_offset, euiTheme.base]);
84
62
 
85
63
  // Sections include page header
86
64
  var sections = [];
@@ -139,7 +117,7 @@ export var _EuiPageTemplate = function _EuiPageTemplate(_ref) {
139
117
  });
140
118
  var _minHeight = grow ? "max(".concat(minHeight, ", 100vh)") : minHeight;
141
119
  var classes = classNames('euiPageTemplate', className);
142
- var pageStyle = _objectSpread(_objectSpread(_objectSpread({}, logicalStyle('min-height', _minHeight)), logicalStyle('padding-top', offset)), rest.style);
120
+ var pageStyle = _objectSpread(_objectSpread(_objectSpread({}, logicalStyle('min-height', _minHeight)), logicalStyle('padding-top', offset !== null && offset !== void 0 ? offset : 'var(--euiFixedHeadersOffset, 0)')), rest.style);
143
121
  templateContext.header = getHeaderProps();
144
122
  templateContext.section = getSectionProps();
145
123
  templateContext.emptyPrompt = {
@@ -33,9 +33,9 @@ var euiScaleText = function euiScaleText(euiThemeContext, options) {
33
33
  fontSize = _euiFontSize.fontSize,
34
34
  lineHeight = _euiFontSize.lineHeight;
35
35
  var euiTheme = euiThemeContext.euiTheme;
36
- var measurement = options.measurement,
36
+ var unit = options.unit,
37
37
  _customScale = options.customScale;
38
- var lineHeightSize = measurement === 'em' ? "".concat(lineHeight, "em") : lineHeight;
38
+ var lineHeightSize = unit === 'em' ? "".concat(lineHeight, "em") : lineHeight;
39
39
  var headings = {
40
40
  h1: euiTitle(euiThemeContext, 'l', options),
41
41
  h2: euiTitle(euiThemeContext, 'm', options),
@@ -71,19 +71,16 @@ export var euiTextStyles = function euiTextStyles(euiThemeContext) {
71
71
  constrainedWidth: /*#__PURE__*/css(logicalCSS('max-width', euiTextConstrainedMaxWidth), ";;label:constrainedWidth;"),
72
72
  // Sizes
73
73
  m: /*#__PURE__*/css(euiScaleText(euiThemeContext, {
74
- measurement: 'rem',
75
74
  customScale: 'm'
76
75
  }), ";;label:m;"),
77
76
  s: /*#__PURE__*/css(euiScaleText(euiThemeContext, {
78
- measurement: 'rem',
79
77
  customScale: 's'
80
78
  }), ";;label:s;"),
81
79
  xs: /*#__PURE__*/css(euiScaleText(euiThemeContext, {
82
- measurement: 'rem',
83
80
  customScale: 'xs'
84
81
  }), ";;label:xs;"),
85
82
  relative: /*#__PURE__*/css(euiScaleText(euiThemeContext, {
86
- measurement: 'em'
83
+ unit: 'em'
87
84
  }), ";;label:relative;")
88
85
  };
89
86
  };
@@ -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,148 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import _extends from "@babel/runtime/helpers/extends";
3
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
4
+ var _excluded = ["width"],
5
+ _excluded2 = ["width", "children", "text", "truncation", "truncationOffset", "truncationPosition", "ellipsis", "containerRef", "measurementRenderAPI"],
6
+ _excluded3 = ["onResize"];
7
+ /*
8
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
9
+ * or more contributor license agreements. Licensed under the Elastic License
10
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
11
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
12
+ * Side Public License, v 1.
13
+ */
14
+
15
+ import React, { useState, useMemo, useCallback } from 'react';
16
+ import { useCombinedRefs } from '../../services';
17
+ import { EuiResizeObserver } from '../observer/resize_observer';
18
+ import { TruncationUtilsWithDOM, TruncationUtilsWithCanvas } from './utils';
19
+ import { euiTextTruncateStyles } from './text_truncate.styles';
20
+ import { jsx as ___EmotionJSX } from "@emotion/react";
21
+ var TRUNCATION_TYPES = ['end', 'start', 'startEnd', 'middle'];
22
+ export var EuiTextTruncate = function EuiTextTruncate(_ref) {
23
+ var width = _ref.width,
24
+ props = _objectWithoutProperties(_ref, _excluded);
25
+ return width != null ? ___EmotionJSX(EuiTextTruncateWithWidth, _extends({
26
+ width: width
27
+ }, props)) : ___EmotionJSX(EuiTextTruncateWithResizeObserver, props);
28
+ };
29
+ var EuiTextTruncateWithWidth = function EuiTextTruncateWithWidth(_ref2) {
30
+ var width = _ref2.width,
31
+ children = _ref2.children,
32
+ text = _ref2.text,
33
+ _ref2$truncation = _ref2.truncation,
34
+ _truncation = _ref2$truncation === void 0 ? 'end' : _ref2$truncation,
35
+ _ref2$truncationOffse = _ref2.truncationOffset,
36
+ _truncationOffset = _ref2$truncationOffse === void 0 ? 0 : _ref2$truncationOffse,
37
+ truncationPosition = _ref2.truncationPosition,
38
+ _ref2$ellipsis = _ref2.ellipsis,
39
+ ellipsis = _ref2$ellipsis === void 0 ? '…' : _ref2$ellipsis,
40
+ containerRef = _ref2.containerRef,
41
+ _ref2$measurementRend = _ref2.measurementRenderAPI,
42
+ measurementRenderAPI = _ref2$measurementRend === void 0 ? 'dom' : _ref2$measurementRend,
43
+ rest = _objectWithoutProperties(_ref2, _excluded2);
44
+ // Note: This needs to be a state and not a ref to trigger a rerender on mount
45
+ var _useState = useState(null),
46
+ _useState2 = _slicedToArray(_useState, 2),
47
+ containerEl = _useState2[0],
48
+ setContainerEl = _useState2[1];
49
+ var refs = useCombinedRefs([setContainerEl, containerRef]);
50
+
51
+ // Handle exceptions where we need to override the passed props
52
+ var _useMemo = useMemo(function () {
53
+ var truncation = _truncation;
54
+ var truncationOffset = 0;
55
+ if (_truncation === 'end' || _truncation === 'start') {
56
+ if (0 < _truncationOffset && _truncationOffset < text.length) {
57
+ truncationOffset = _truncationOffset;
58
+ }
59
+ } else if (_truncation === 'startEnd' && truncationPosition != null) {
60
+ if (truncationPosition <= 0) {
61
+ truncation = 'end';
62
+ } else if (truncationPosition >= text.length) {
63
+ truncation = 'start';
64
+ }
65
+ }
66
+ return {
67
+ truncation: truncation,
68
+ truncationOffset: truncationOffset
69
+ };
70
+ }, [_truncation, _truncationOffset, truncationPosition, text.length]),
71
+ truncation = _useMemo.truncation,
72
+ truncationOffset = _useMemo.truncationOffset;
73
+ var truncatedText = useMemo(function () {
74
+ var truncatedText = '';
75
+ if (!containerEl || !width) return truncatedText;
76
+ var params = {
77
+ fullText: text,
78
+ ellipsis: ellipsis,
79
+ container: containerEl,
80
+ availableWidth: width
81
+ };
82
+ var utils = measurementRenderAPI === 'canvas' ? new TruncationUtilsWithCanvas(params) : new TruncationUtilsWithDOM(params);
83
+ if (utils.checkIfTruncationIsNeeded() === false) {
84
+ truncatedText = text;
85
+ } else if (utils.checkSufficientEllipsisWidth(truncation) === false) {
86
+ truncatedText = '';
87
+ } else {
88
+ switch (truncation) {
89
+ case 'end':
90
+ truncatedText = utils.truncateEnd(truncationOffset);
91
+ break;
92
+ case 'start':
93
+ truncatedText = utils.truncateStart(truncationOffset);
94
+ break;
95
+ case 'startEnd':
96
+ if (truncationPosition == null) {
97
+ truncatedText = utils.truncateStartEndAtMiddle();
98
+ } else {
99
+ truncatedText = utils.truncateStartEndAtPosition(truncationPosition);
100
+ }
101
+ break;
102
+ case 'middle':
103
+ truncatedText = utils.truncateMiddle();
104
+ break;
105
+ }
106
+ }
107
+ if (measurementRenderAPI === 'dom') {
108
+ utils.cleanup();
109
+ }
110
+ return truncatedText;
111
+ }, [width, text, truncation, truncationOffset, truncationPosition, ellipsis, containerEl, measurementRenderAPI]);
112
+ var isTruncating = truncatedText !== text;
113
+ return ___EmotionJSX("div", _extends({
114
+ css: euiTextTruncateStyles.euiTextTruncate,
115
+ ref: refs,
116
+ title: isTruncating ? text : undefined
117
+ }, rest), isTruncating ? ___EmotionJSX(React.Fragment, null, ___EmotionJSX("span", {
118
+ css: euiTextTruncateStyles.truncatedText,
119
+ "aria-hidden": true,
120
+ "data-test-subj": "truncatedText"
121
+ }, children ? children(truncatedText) : truncatedText), ___EmotionJSX("span", {
122
+ css: euiTextTruncateStyles.fullText,
123
+ "data-test-subj": "fullText"
124
+ }, text)) : ___EmotionJSX("span", {
125
+ "data-test-subj": "fullText"
126
+ }, text));
127
+ };
128
+ var EuiTextTruncateWithResizeObserver = function EuiTextTruncateWithResizeObserver(_ref3) {
129
+ var _onResize = _ref3.onResize,
130
+ props = _objectWithoutProperties(_ref3, _excluded3);
131
+ var _useState3 = useState(0),
132
+ _useState4 = _slicedToArray(_useState3, 2),
133
+ width = _useState4[0],
134
+ setWidth = _useState4[1];
135
+ var onResize = useCallback(function (_ref4) {
136
+ var width = _ref4.width;
137
+ setWidth(width);
138
+ _onResize === null || _onResize === void 0 ? void 0 : _onResize(width);
139
+ }, [_onResize]);
140
+ return ___EmotionJSX(EuiResizeObserver, {
141
+ onResize: onResize
142
+ }, function (ref) {
143
+ return ___EmotionJSX(EuiTextTruncateWithWidth, _extends({
144
+ width: width,
145
+ containerRef: ref
146
+ }, props));
147
+ });
148
+ };
@@ -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
+ };
@@ -0,0 +1,337 @@
1
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
2
+ import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
3
+ import _inherits from "@babel/runtime/helpers/inherits";
4
+ import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5
+ import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
7
+ import _createClass from "@babel/runtime/helpers/createClass";
8
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
9
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
10
+ var _excluded = ["container"],
11
+ _excluded2 = ["font", "container"];
12
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
13
+ 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; } }
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
+ /**
22
+ * This internal shared/base class contains the actual logic for truncating text
23
+ * (as well as a few handy utilities for checking whether truncation is possible
24
+ * or even necessary).
25
+ *
26
+ * How the underlying mechanism works: the full text is rendered, and then
27
+ * characters are removed one by one until the width of the text fits within
28
+ * the specified available width.
29
+ *
30
+ * Side note: The exception to this is the `truncateStartEndAtPosition` method,
31
+ * which works by building up from an empty string / by adding characters
32
+ * instead of removing them.
33
+ */
34
+ var _TruncationUtils = /*#__PURE__*/_createClass(function _TruncationUtils(_ref) {
35
+ var _this = this;
36
+ var fullText = _ref.fullText,
37
+ ellipsis = _ref.ellipsis,
38
+ availableWidth = _ref.availableWidth;
39
+ _classCallCheck(this, _TruncationUtils);
40
+ _defineProperty(this, "fullText", void 0);
41
+ _defineProperty(this, "ellipsis", void 0);
42
+ _defineProperty(this, "availableWidth", void 0);
43
+ /**
44
+ * Early return checks
45
+ */
46
+ _defineProperty(this, "checkIfTruncationIsNeeded", function () {
47
+ _this.setTextToCheck(_this.fullText);
48
+ if (_this.availableWidth > _this.textWidth) {
49
+ return false;
50
+ }
51
+ });
52
+ _defineProperty(this, "checkSufficientEllipsisWidth", function (truncation) {
53
+ var textToCheck = truncation === 'startEnd' ? "".concat(_this.ellipsis, " ").concat(_this.ellipsis) // startEnd needs a little more space
54
+ : _this.ellipsis;
55
+ _this.setTextToCheck(textToCheck);
56
+ if (_this.textWidth >= _this.availableWidth * 0.9) {
57
+ console.error('The truncation ellipsis is larger than the available width. No text can be rendered.');
58
+ return false;
59
+ }
60
+ });
61
+ _defineProperty(this, "checkTruncationOffsetWidth", function (text) {
62
+ _this.setTextToCheck(text);
63
+ if (_this.textWidth > _this.availableWidth) {
64
+ console.error("The passed truncationOffset is too large for the available width. Truncating the offset instead.");
65
+ return false;
66
+ }
67
+ });
68
+ /**
69
+ * Truncation types logic. This is where the magic happens
70
+ */
71
+ _defineProperty(this, "truncateStart", function (truncationOffset) {
72
+ var truncatedText = _this.fullText;
73
+ var leadingText = '';
74
+ var combinedText = function combinedText() {
75
+ return "".concat(leadingText).concat(truncatedText);
76
+ };
77
+ if (truncationOffset) {
78
+ var _splitText$at = splitText(_this.fullText).at(truncationOffset);
79
+ var _splitText$at2 = _slicedToArray(_splitText$at, 2);
80
+ leadingText = _splitText$at2[0];
81
+ truncatedText = _splitText$at2[1];
82
+ var widthCheck = "".concat(leadingText).concat(_this.ellipsis);
83
+ if (_this.checkTruncationOffsetWidth(widthCheck) === false) {
84
+ truncatedText = leadingText;
85
+ leadingText = '';
86
+ }
87
+ }
88
+ leadingText += _this.ellipsis;
89
+ _this.setTextToCheck(combinedText());
90
+ while (_this.textWidth > _this.availableWidth) {
91
+ truncatedText = removeFirstCharacter(truncatedText);
92
+ _this.setTextToCheck(combinedText());
93
+ }
94
+ return combinedText();
95
+ });
96
+ _defineProperty(this, "truncateEnd", function (truncationOffset) {
97
+ var truncatedText = _this.fullText;
98
+ var trailingText = '';
99
+ var combinedText = function combinedText() {
100
+ return "".concat(truncatedText).concat(trailingText);
101
+ };
102
+ if (truncationOffset) {
103
+ var index = _this.fullText.length - truncationOffset;
104
+ var _splitText$at3 = splitText(_this.fullText).at(index);
105
+ var _splitText$at4 = _slicedToArray(_splitText$at3, 2);
106
+ truncatedText = _splitText$at4[0];
107
+ trailingText = _splitText$at4[1];
108
+ var widthCheck = "".concat(_this.ellipsis).concat(trailingText);
109
+ if (_this.checkTruncationOffsetWidth(widthCheck) === false) {
110
+ truncatedText = trailingText;
111
+ trailingText = '';
112
+ }
113
+ }
114
+ trailingText = _this.ellipsis + trailingText;
115
+ _this.setTextToCheck(combinedText());
116
+ while (_this.textWidth > _this.availableWidth) {
117
+ truncatedText = removeLastCharacter(truncatedText);
118
+ _this.setTextToCheck(combinedText());
119
+ }
120
+ return combinedText();
121
+ });
122
+ _defineProperty(this, "truncateStartEndAtPosition", function (truncationPosition) {
123
+ // If using a non-centered startEnd anchor position, we need to *build*
124
+ // the string from scratch instead of *removing* from the full text string,
125
+ // to make sure we don't go past the beginning or end of the text
126
+ var truncatedText = '';
127
+ _this.setTextToCheck(truncatedText);
128
+
129
+ // Ellipses are conditional - if the anchor is towards the beginning or end,
130
+ // it's possible they shouldn't render
131
+ var startingEllipsis = _this.ellipsis;
132
+ var endingEllipsis = _this.ellipsis;
133
+
134
+ // Split the text into two at the anchor position
135
+ var _splitText$at5 = splitText(_this.fullText).at(truncationPosition),
136
+ _splitText$at6 = _slicedToArray(_splitText$at5, 2),
137
+ firstPart = _splitText$at6[0],
138
+ secondPart = _splitText$at6[1];
139
+ var combinedText = function combinedText() {
140
+ return "".concat(startingEllipsis).concat(truncatedText).concat(endingEllipsis);
141
+ };
142
+ while (_this.textWidth <= _this.availableWidth) {
143
+ if (firstPart.length > 0) {
144
+ truncatedText = "".concat(getLastCharacter(firstPart)).concat(truncatedText);
145
+ firstPart = removeLastCharacter(firstPart);
146
+ } else {
147
+ startingEllipsis = '';
148
+ }
149
+ if (secondPart.length > 0) {
150
+ truncatedText = "".concat(truncatedText).concat(getFirstCharacter(secondPart));
151
+ secondPart = removeFirstCharacter(secondPart);
152
+ } else {
153
+ endingEllipsis = '';
154
+ }
155
+ _this.setTextToCheck(combinedText());
156
+ }
157
+
158
+ // Because this logic builds text outwards vs. removing inwards, the final
159
+ // text width ends up a little larger than the container, and we need to
160
+ // remove the last added character(s)
161
+ if (!startingEllipsis) {
162
+ truncatedText = removeLastCharacter(truncatedText);
163
+ } else if (!endingEllipsis) {
164
+ truncatedText = removeFirstCharacter(truncatedText);
165
+ } else {
166
+ truncatedText = removeFirstAndLastCharacters(truncatedText);
167
+ }
168
+ return combinedText();
169
+ });
170
+ _defineProperty(this, "truncateStartEndAtMiddle", function () {
171
+ var truncatedText = _this.fullText;
172
+ _this.setTextToCheck(truncatedText);
173
+ var combinedText = function combinedText() {
174
+ return "".concat(_this.ellipsis).concat(truncatedText).concat(_this.ellipsis);
175
+ };
176
+ while (_this.textWidth > _this.availableWidth) {
177
+ truncatedText = removeFirstAndLastCharacters(truncatedText);
178
+ _this.setTextToCheck(combinedText());
179
+ }
180
+ return combinedText();
181
+ });
182
+ _defineProperty(this, "truncateMiddle", function () {
183
+ var middlePosition = Math.floor(_this.fullText.length / 2);
184
+ var _splitText$at7 = splitText(_this.fullText).at(middlePosition),
185
+ _splitText$at8 = _slicedToArray(_splitText$at7, 2),
186
+ firstHalf = _splitText$at8[0],
187
+ secondHalf = _splitText$at8[1];
188
+ var trimfirstHalf;
189
+ var combinedText = function combinedText() {
190
+ return "".concat(firstHalf).concat(_this.ellipsis).concat(secondHalf);
191
+ };
192
+ _this.setTextToCheck(combinedText());
193
+ while (_this.textWidth > _this.availableWidth) {
194
+ trimfirstHalf = !trimfirstHalf;
195
+ if (trimfirstHalf) {
196
+ firstHalf = removeLastCharacter(firstHalf);
197
+ } else {
198
+ secondHalf = removeFirstCharacter(secondHalf);
199
+ }
200
+ _this.setTextToCheck(combinedText());
201
+ }
202
+ return combinedText();
203
+ });
204
+ this.fullText = fullText;
205
+ this.ellipsis = ellipsis;
206
+ this.availableWidth = availableWidth;
207
+ }
208
+
209
+ /**
210
+ * Internal measurement utils which will be overridden depending on the
211
+ * rendering approach used (e.g. DOM vs Canvas).
212
+ */);
213
+ /**
214
+ * Creates a temporary vanilla JS DOM element for manipulating text and
215
+ * determining text width.
216
+ *
217
+ * Requires passing in a container element to which the temporary element
218
+ * will be appended. Any CSS/font styles that need to be accounted for should
219
+ * be automatically inherited from the container.
220
+ *
221
+ * NOTE: The consumer is responsible for calling the `cleanup()` method manually
222
+ * to remove the temporary DOM node once their usage of this utility is complete.
223
+ */
224
+
225
+ export var TruncationUtilsWithDOM = /*#__PURE__*/function (_TruncationUtils2) {
226
+ _inherits(TruncationUtilsWithDOM, _TruncationUtils2);
227
+ var _super = _createSuper(TruncationUtilsWithDOM);
228
+ function TruncationUtilsWithDOM(_ref2) {
229
+ var _this2;
230
+ var container = _ref2.container,
231
+ rest = _objectWithoutProperties(_ref2, _excluded);
232
+ _classCallCheck(this, TruncationUtilsWithDOM);
233
+ _this2 = _super.call(this, rest);
234
+ _defineProperty(_assertThisInitialized(_this2), "container", void 0);
235
+ _defineProperty(_assertThisInitialized(_this2), "span", void 0);
236
+ _defineProperty(_assertThisInitialized(_this2), "setTextToCheck", function (text) {
237
+ _this2.span.textContent = text;
238
+ });
239
+ _defineProperty(_assertThisInitialized(_this2), "cleanup", function () {
240
+ _this2.container.removeChild(_this2.span);
241
+ });
242
+ _this2.container = container;
243
+ _this2.span = document.createElement('span');
244
+ _this2.span.style.position = 'absolute'; // Prevent page reflow/repaint for performance
245
+ _this2.span.style.whiteSpace = 'nowrap'; // EuiTextTruncate already sets this on the parent, but we'll set it here as well for consumers who use this util standalone
246
+ _this2.container.appendChild(_this2.span);
247
+ return _this2;
248
+ }
249
+ _createClass(TruncationUtilsWithDOM, [{
250
+ key: "textWidth",
251
+ get: function get() {
252
+ return this.span.offsetWidth;
253
+ }
254
+ }]);
255
+ return TruncationUtilsWithDOM;
256
+ }(_TruncationUtils);
257
+
258
+ /**
259
+ * Creates a temporary Canvas element for manipulating text & determining
260
+ * text width. This method is compatible with charts or other canvas-rendered
261
+ * frameworks, and requires no cleanup method.
262
+ *
263
+ * To accurately measure text, canvas rendering requires either a container to
264
+ * compute/derive font styles from, or a static font string (useful for usage
265
+ * outside the DOM). Particular care should be applied when fallback fonts are
266
+ * used, as more fallback fonts can lead to less precision.
267
+ *
268
+ * Please note that while canvas is more performant than DOM measurement, there
269
+ * are subpixel to single digit pixel differences between DOM and canvas
270
+ * measurement due to the different rendering engines used.
271
+ */
272
+ export var TruncationUtilsWithCanvas = /*#__PURE__*/function (_TruncationUtils3) {
273
+ _inherits(TruncationUtilsWithCanvas, _TruncationUtils3);
274
+ var _super2 = _createSuper(TruncationUtilsWithCanvas);
275
+ function TruncationUtilsWithCanvas(_ref3) {
276
+ var _this3;
277
+ var font = _ref3.font,
278
+ container = _ref3.container,
279
+ rest = _objectWithoutProperties(_ref3, _excluded2);
280
+ _classCallCheck(this, TruncationUtilsWithCanvas);
281
+ _this3 = _super2.call(this, rest);
282
+ _defineProperty(_assertThisInitialized(_this3), "context", void 0);
283
+ _defineProperty(_assertThisInitialized(_this3), "currentText", '');
284
+ _defineProperty(_assertThisInitialized(_this3), "computeFontFromElement", function (element) {
285
+ var computedStyles = window.getComputedStyle(element);
286
+ return ['font-style', 'font-variant', 'font-weight', 'font-size', 'font-family'].map(function (prop) {
287
+ return computedStyles.getPropertyValue(prop);
288
+ }).join(' ').trim();
289
+ });
290
+ _defineProperty(_assertThisInitialized(_this3), "setTextToCheck", function (text) {
291
+ _this3.currentText = text;
292
+ });
293
+ _this3.context = document.createElement('canvas').getContext('2d');
294
+
295
+ // Set the canvas font to ensure text width calculations are correct
296
+ if (font) {
297
+ _this3.context.font = font;
298
+ } else if (container) {
299
+ _this3.context.font = _this3.computeFontFromElement(container);
300
+ }
301
+ return _this3;
302
+ }
303
+ _createClass(TruncationUtilsWithCanvas, [{
304
+ key: "textWidth",
305
+ get: function get() {
306
+ return this.context.measureText(this.currentText).width;
307
+ }
308
+ }]);
309
+ return TruncationUtilsWithCanvas;
310
+ }(_TruncationUtils);
311
+
312
+ /**
313
+ * DRY character/substring utils
314
+ */
315
+
316
+ var removeLastCharacter = function removeLastCharacter(text) {
317
+ return text.substring(0, text.length - 1);
318
+ };
319
+ var getLastCharacter = function getLastCharacter(text) {
320
+ return text.substring(text.length - 1);
321
+ };
322
+ var removeFirstCharacter = function removeFirstCharacter(text) {
323
+ return text.substring(1);
324
+ };
325
+ var getFirstCharacter = function getFirstCharacter(text) {
326
+ return text.substring(0, 1);
327
+ };
328
+ var removeFirstAndLastCharacters = function removeFirstAndLastCharacters(text) {
329
+ return text.substring(1, text.length - 1);
330
+ };
331
+ var splitText = function splitText(text) {
332
+ return {
333
+ at: function at(index) {
334
+ return [text.substring(0, index), text.substring(index)];
335
+ }
336
+ };
337
+ };