@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.
- package/dist/eui_charts_theme.js +9 -8
- package/dist/eui_charts_theme.js.map +1 -1
- package/dist/eui_theme_dark.css +11 -41
- package/dist/eui_theme_dark.min.css +1 -1
- package/dist/eui_theme_light.css +11 -41
- package/dist/eui_theme_light.min.css +1 -1
- package/es/components/accordion/accordion.js +34 -9
- package/es/components/accordion/accordion.styles.js +29 -9
- package/es/components/collapsible_nav/collapsible_nav_group/collapsible_nav_group.js +10 -2
- package/es/components/collapsible_nav_beta/collapsible_nav_beta.js +10 -26
- package/es/components/collapsible_nav_beta/collapsible_nav_beta.styles.js +10 -1
- package/es/components/datagrid/controls/keyboard_shortcuts.js +1 -0
- package/es/components/description_list/description_list.js +40 -3
- package/es/components/flyout/flyout.styles.js +1 -1
- package/es/components/header/header.js +120 -25
- package/es/components/header/header.styles.js +1 -1
- package/es/components/index.js +1 -0
- package/es/components/markdown_editor/markdown_format.styles.js +3 -6
- package/es/components/overlay_mask/overlay_mask.styles.js +1 -1
- package/es/components/page/page_sidebar/page_sidebar.js +2 -4
- package/es/components/page_template/page_template.js +4 -31
- package/es/components/text/text.styles.js +3 -6
- package/es/components/text_truncate/index.js +10 -0
- package/es/components/text_truncate/text_truncate.js +232 -0
- package/es/components/text_truncate/text_truncate.styles.js +49 -0
- package/es/components/text_truncate/utils.js +348 -0
- package/es/global_styling/functions/typography.js +8 -8
- package/es/global_styling/variables/typography.js +1 -1
- package/es/services/theme/context.js +3 -1
- package/es/services/theme/hooks.js +19 -1
- package/es/services/theme/index.js +1 -1
- package/es/services/theme/provider.js +37 -8
- package/es/themes/amsterdam/global_styling/variables/_typography.js +1 -0
- package/eui.d.ts +282 -24
- package/i18ntokens.json +112 -112
- package/lib/components/accordion/accordion.js +33 -8
- package/lib/components/accordion/accordion.styles.js +31 -10
- package/lib/components/collapsible_nav/collapsible_nav_group/collapsible_nav_group.js +10 -2
- package/lib/components/collapsible_nav_beta/collapsible_nav_beta.js +10 -26
- package/lib/components/collapsible_nav_beta/collapsible_nav_beta.styles.js +10 -1
- package/lib/components/datagrid/controls/keyboard_shortcuts.js +1 -0
- package/lib/components/description_list/description_list.js +39 -3
- package/lib/components/flyout/flyout.styles.js +1 -1
- package/lib/components/header/header.js +120 -23
- package/lib/components/header/header.styles.js +1 -1
- package/lib/components/index.js +11 -0
- package/lib/components/markdown_editor/markdown_format.styles.js +3 -6
- package/lib/components/overlay_mask/overlay_mask.styles.js +1 -1
- package/lib/components/page/page_sidebar/page_sidebar.js +2 -4
- package/lib/components/page_template/page_template.js +2 -29
- package/lib/components/text/text.styles.js +3 -6
- package/lib/components/text_truncate/index.js +25 -0
- package/lib/components/text_truncate/text_truncate.js +242 -0
- package/lib/components/text_truncate/text_truncate.styles.js +54 -0
- package/lib/components/text_truncate/utils.js +352 -0
- package/lib/global_styling/functions/typography.js +8 -8
- package/lib/global_styling/variables/typography.js +3 -3
- package/lib/services/theme/context.js +3 -1
- package/lib/services/theme/hooks.js +21 -2
- package/lib/services/theme/index.js +6 -0
- package/lib/services/theme/provider.js +62 -35
- package/lib/themes/amsterdam/global_styling/variables/_typography.js +1 -0
- package/optimize/es/components/accordion/accordion.js +19 -7
- package/optimize/es/components/accordion/accordion.styles.js +29 -9
- package/optimize/es/components/collapsible_nav_beta/collapsible_nav_beta.js +5 -26
- package/optimize/es/components/collapsible_nav_beta/collapsible_nav_beta.styles.js +10 -1
- package/optimize/es/components/datagrid/controls/keyboard_shortcuts.js +1 -0
- package/optimize/es/components/description_list/description_list.js +22 -2
- package/optimize/es/components/flyout/flyout.styles.js +1 -1
- package/optimize/es/components/header/header.js +75 -25
- package/optimize/es/components/header/header.styles.js +1 -1
- package/optimize/es/components/index.js +1 -0
- package/optimize/es/components/markdown_editor/markdown_format.styles.js +3 -6
- package/optimize/es/components/overlay_mask/overlay_mask.styles.js +1 -1
- package/optimize/es/components/page/page_sidebar/page_sidebar.js +2 -4
- package/optimize/es/components/page_template/page_template.js +4 -26
- package/optimize/es/components/text/text.styles.js +3 -6
- package/optimize/es/components/text_truncate/index.js +10 -0
- package/optimize/es/components/text_truncate/text_truncate.js +148 -0
- package/optimize/es/components/text_truncate/text_truncate.styles.js +49 -0
- package/optimize/es/components/text_truncate/utils.js +337 -0
- package/optimize/es/global_styling/functions/typography.js +8 -8
- package/optimize/es/global_styling/variables/typography.js +1 -1
- package/optimize/es/services/theme/context.js +3 -1
- package/optimize/es/services/theme/hooks.js +19 -1
- package/optimize/es/services/theme/index.js +1 -1
- package/optimize/es/services/theme/provider.js +37 -8
- package/optimize/es/themes/amsterdam/global_styling/variables/_typography.js +1 -0
- package/optimize/lib/components/accordion/accordion.js +18 -6
- package/optimize/lib/components/accordion/accordion.styles.js +31 -10
- package/optimize/lib/components/collapsible_nav_beta/collapsible_nav_beta.js +5 -26
- package/optimize/lib/components/collapsible_nav_beta/collapsible_nav_beta.styles.js +10 -1
- package/optimize/lib/components/datagrid/controls/keyboard_shortcuts.js +1 -0
- package/optimize/lib/components/description_list/description_list.js +22 -2
- package/optimize/lib/components/flyout/flyout.styles.js +1 -1
- package/optimize/lib/components/header/header.js +77 -24
- package/optimize/lib/components/header/header.styles.js +1 -1
- package/optimize/lib/components/index.js +11 -0
- package/optimize/lib/components/markdown_editor/markdown_format.styles.js +3 -6
- package/optimize/lib/components/overlay_mask/overlay_mask.styles.js +1 -1
- package/optimize/lib/components/page/page_sidebar/page_sidebar.js +2 -4
- package/optimize/lib/components/page_template/page_template.js +2 -24
- package/optimize/lib/components/text/text.styles.js +3 -6
- package/optimize/lib/components/text_truncate/index.js +25 -0
- package/optimize/lib/components/text_truncate/text_truncate.js +158 -0
- package/optimize/lib/components/text_truncate/text_truncate.styles.js +54 -0
- package/optimize/lib/components/text_truncate/utils.js +342 -0
- package/optimize/lib/global_styling/functions/typography.js +8 -8
- package/optimize/lib/global_styling/variables/typography.js +3 -3
- package/optimize/lib/services/theme/context.js +3 -1
- package/optimize/lib/services/theme/hooks.js +21 -2
- package/optimize/lib/services/theme/index.js +6 -0
- package/optimize/lib/services/theme/provider.js +62 -35
- package/optimize/lib/themes/amsterdam/global_styling/variables/_typography.js +1 -0
- package/package.json +1 -1
- package/src/components/datagrid/_data_grid.scss +13 -2
- package/src/components/datagrid/controls/_data_grid_keyboard_shortcuts.scss +1 -7
- package/src/components/index.scss +0 -1
- package/src/global_styling/mixins/_header.scss +2 -0
- package/test-env/components/accordion/accordion.js +28 -8
- package/test-env/components/accordion/accordion.styles.js +31 -10
- package/test-env/components/collapsible_nav/collapsible_nav_group/collapsible_nav_group.js +10 -2
- package/test-env/components/collapsible_nav_beta/collapsible_nav_beta.js +10 -26
- package/test-env/components/collapsible_nav_beta/collapsible_nav_beta.styles.js +10 -1
- package/test-env/components/datagrid/controls/keyboard_shortcuts.js +1 -0
- package/test-env/components/description_list/description_list.js +37 -3
- package/test-env/components/flyout/flyout.styles.js +1 -1
- package/test-env/components/header/header.js +113 -23
- package/test-env/components/header/header.styles.js +1 -1
- package/test-env/components/index.js +11 -0
- package/test-env/components/markdown_editor/markdown_format.styles.js +3 -6
- package/test-env/components/overlay_mask/overlay_mask.styles.js +1 -1
- package/test-env/components/page/page_sidebar/page_sidebar.js +2 -4
- package/test-env/components/page_template/page_template.js +2 -24
- package/test-env/components/text/text.styles.js +3 -6
- package/test-env/components/text_truncate/index.js +25 -0
- package/test-env/components/text_truncate/text_truncate.js +236 -0
- package/test-env/components/text_truncate/text_truncate.styles.js +54 -0
- package/test-env/components/text_truncate/utils.js +342 -0
- package/test-env/global_styling/functions/typography.js +8 -8
- package/test-env/global_styling/variables/typography.js +3 -3
- package/test-env/services/theme/context.js +3 -1
- package/test-env/services/theme/hooks.js +21 -2
- package/test-env/services/theme/index.js +6 -0
- package/test-env/services/theme/provider.js +62 -35
- package/test-env/themes/amsterdam/global_styling/variables/_typography.js +1 -0
- package/src/components/accordion/_accordion_form.scss +0 -40
- package/src/components/accordion/_index.scss +0 -1
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.euiTextTruncateStyles = void 0;
|
|
7
|
+
var _react = require("@emotion/react");
|
|
8
|
+
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)."; } /*
|
|
9
|
+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
10
|
+
* or more contributor license agreements. Licensed under the Elastic License
|
|
11
|
+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
|
12
|
+
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
|
13
|
+
* Side Public License, v 1.
|
|
14
|
+
*/
|
|
15
|
+
var euiTextTruncateStyles = {
|
|
16
|
+
euiTextTruncate: process.env.NODE_ENV === "production" ? {
|
|
17
|
+
name: "7o5qnz-euiTextTruncate",
|
|
18
|
+
styles: "position:relative;overflow:hidden;white-space:nowrap;label:euiTextTruncate;"
|
|
19
|
+
} : {
|
|
20
|
+
name: "7o5qnz-euiTextTruncate",
|
|
21
|
+
styles: "position:relative;overflow:hidden;white-space:nowrap;label:euiTextTruncate;",
|
|
22
|
+
toString: _EMOTION_STRINGIFIED_CSS_ERROR__
|
|
23
|
+
},
|
|
24
|
+
/**
|
|
25
|
+
* The below CSS is a hack to get double clicking and selecting the *full* text
|
|
26
|
+
* instead of the truncated text (useful for copying/pasting, and mimics how
|
|
27
|
+
* `text-overflow: ellipsis` works).
|
|
28
|
+
*
|
|
29
|
+
* Real talk: I'm lowkey amazed it works and it wouldn't surprise me if we ran into
|
|
30
|
+
* cross-browser issues with this at some point. Hopefully CSS natively implements
|
|
31
|
+
* custom text truncation some day (https://github.com/w3c/csswg-drafts/issues/3937)
|
|
32
|
+
* and there'll be no need for the entire component at that point 🙏
|
|
33
|
+
*/
|
|
34
|
+
// Makes the truncated text unselectable/un-clickable
|
|
35
|
+
truncatedText: process.env.NODE_ENV === "production" ? {
|
|
36
|
+
name: "1dore6v-truncatedText",
|
|
37
|
+
styles: "user-select:none;pointer-events:none;label:truncatedText;"
|
|
38
|
+
} : {
|
|
39
|
+
name: "1dore6v-truncatedText",
|
|
40
|
+
styles: "user-select:none;pointer-events:none;label:truncatedText;",
|
|
41
|
+
toString: _EMOTION_STRINGIFIED_CSS_ERROR__
|
|
42
|
+
},
|
|
43
|
+
// Positions the full text on top of the truncated text (so that clicking targets it)
|
|
44
|
+
// and gives it a color opacity of 0 so that it's not actually visible
|
|
45
|
+
fullText: process.env.NODE_ENV === "production" ? {
|
|
46
|
+
name: "1kxt4rj-fullText",
|
|
47
|
+
styles: "position:absolute;inset:0;overflow:hidden;color:rgba(0, 0, 0, 0);@supports (-webkit-hyphens: none){text-overflow:ellipsis;};label:fullText;"
|
|
48
|
+
} : {
|
|
49
|
+
name: "1kxt4rj-fullText",
|
|
50
|
+
styles: "position:absolute;inset:0;overflow:hidden;color:rgba(0, 0, 0, 0);@supports (-webkit-hyphens: none){text-overflow:ellipsis;};label:fullText;",
|
|
51
|
+
toString: _EMOTION_STRINGIFIED_CSS_ERROR__
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
exports.euiTextTruncateStyles = euiTextTruncateStyles;
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.TruncationUtilsWithDOM = exports.TruncationUtilsWithCanvas = void 0;
|
|
8
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
9
|
+
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
10
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
11
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
12
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
13
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
14
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
15
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
16
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
17
|
+
var _excluded = ["container"],
|
|
18
|
+
_excluded2 = ["font", "container"];
|
|
19
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
20
|
+
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; } }
|
|
21
|
+
/*
|
|
22
|
+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
23
|
+
* or more contributor license agreements. Licensed under the Elastic License
|
|
24
|
+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
|
25
|
+
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
|
26
|
+
* Side Public License, v 1.
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* This internal shared/base class contains the actual logic for truncating text
|
|
30
|
+
* (as well as a few handy utilities for checking whether truncation is possible
|
|
31
|
+
* or even necessary).
|
|
32
|
+
*
|
|
33
|
+
* How the underlying mechanism works: the full text is rendered, and then
|
|
34
|
+
* characters are removed one by one until the width of the text fits within
|
|
35
|
+
* the specified available width.
|
|
36
|
+
*
|
|
37
|
+
* Side note: The exception to this is the `truncateStartEndAtPosition` method,
|
|
38
|
+
* which works by building up from an empty string / by adding characters
|
|
39
|
+
* instead of removing them.
|
|
40
|
+
*/
|
|
41
|
+
var _TruncationUtils = /*#__PURE__*/(0, _createClass2.default)(function _TruncationUtils(_ref) {
|
|
42
|
+
var _this = this;
|
|
43
|
+
var fullText = _ref.fullText,
|
|
44
|
+
ellipsis = _ref.ellipsis,
|
|
45
|
+
availableWidth = _ref.availableWidth;
|
|
46
|
+
(0, _classCallCheck2.default)(this, _TruncationUtils);
|
|
47
|
+
(0, _defineProperty2.default)(this, "fullText", void 0);
|
|
48
|
+
(0, _defineProperty2.default)(this, "ellipsis", void 0);
|
|
49
|
+
(0, _defineProperty2.default)(this, "availableWidth", void 0);
|
|
50
|
+
/**
|
|
51
|
+
* Early return checks
|
|
52
|
+
*/
|
|
53
|
+
(0, _defineProperty2.default)(this, "checkIfTruncationIsNeeded", function () {
|
|
54
|
+
_this.setTextToCheck(_this.fullText);
|
|
55
|
+
if (_this.availableWidth > _this.textWidth) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
(0, _defineProperty2.default)(this, "checkSufficientEllipsisWidth", function (truncation) {
|
|
60
|
+
var textToCheck = truncation === 'startEnd' ? "".concat(_this.ellipsis, " ").concat(_this.ellipsis) // startEnd needs a little more space
|
|
61
|
+
: _this.ellipsis;
|
|
62
|
+
_this.setTextToCheck(textToCheck);
|
|
63
|
+
if (_this.textWidth >= _this.availableWidth * 0.9) {
|
|
64
|
+
console.error('The truncation ellipsis is larger than the available width. No text can be rendered.');
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
(0, _defineProperty2.default)(this, "checkTruncationOffsetWidth", function (text) {
|
|
69
|
+
_this.setTextToCheck(text);
|
|
70
|
+
if (_this.textWidth > _this.availableWidth) {
|
|
71
|
+
console.error("The passed truncationOffset is too large for the available width. Truncating the offset instead.");
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
/**
|
|
76
|
+
* Truncation types logic. This is where the magic happens
|
|
77
|
+
*/
|
|
78
|
+
(0, _defineProperty2.default)(this, "truncateStart", function (truncationOffset) {
|
|
79
|
+
var truncatedText = _this.fullText;
|
|
80
|
+
var leadingText = '';
|
|
81
|
+
var combinedText = function combinedText() {
|
|
82
|
+
return "".concat(leadingText).concat(truncatedText);
|
|
83
|
+
};
|
|
84
|
+
if (truncationOffset) {
|
|
85
|
+
var _splitText$at = splitText(_this.fullText).at(truncationOffset);
|
|
86
|
+
var _splitText$at2 = (0, _slicedToArray2.default)(_splitText$at, 2);
|
|
87
|
+
leadingText = _splitText$at2[0];
|
|
88
|
+
truncatedText = _splitText$at2[1];
|
|
89
|
+
var widthCheck = "".concat(leadingText).concat(_this.ellipsis);
|
|
90
|
+
if (_this.checkTruncationOffsetWidth(widthCheck) === false) {
|
|
91
|
+
truncatedText = leadingText;
|
|
92
|
+
leadingText = '';
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
leadingText += _this.ellipsis;
|
|
96
|
+
_this.setTextToCheck(combinedText());
|
|
97
|
+
while (_this.textWidth > _this.availableWidth) {
|
|
98
|
+
truncatedText = removeFirstCharacter(truncatedText);
|
|
99
|
+
_this.setTextToCheck(combinedText());
|
|
100
|
+
}
|
|
101
|
+
return combinedText();
|
|
102
|
+
});
|
|
103
|
+
(0, _defineProperty2.default)(this, "truncateEnd", function (truncationOffset) {
|
|
104
|
+
var truncatedText = _this.fullText;
|
|
105
|
+
var trailingText = '';
|
|
106
|
+
var combinedText = function combinedText() {
|
|
107
|
+
return "".concat(truncatedText).concat(trailingText);
|
|
108
|
+
};
|
|
109
|
+
if (truncationOffset) {
|
|
110
|
+
var index = _this.fullText.length - truncationOffset;
|
|
111
|
+
var _splitText$at3 = splitText(_this.fullText).at(index);
|
|
112
|
+
var _splitText$at4 = (0, _slicedToArray2.default)(_splitText$at3, 2);
|
|
113
|
+
truncatedText = _splitText$at4[0];
|
|
114
|
+
trailingText = _splitText$at4[1];
|
|
115
|
+
var widthCheck = "".concat(_this.ellipsis).concat(trailingText);
|
|
116
|
+
if (_this.checkTruncationOffsetWidth(widthCheck) === false) {
|
|
117
|
+
truncatedText = trailingText;
|
|
118
|
+
trailingText = '';
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
trailingText = _this.ellipsis + trailingText;
|
|
122
|
+
_this.setTextToCheck(combinedText());
|
|
123
|
+
while (_this.textWidth > _this.availableWidth) {
|
|
124
|
+
truncatedText = removeLastCharacter(truncatedText);
|
|
125
|
+
_this.setTextToCheck(combinedText());
|
|
126
|
+
}
|
|
127
|
+
return combinedText();
|
|
128
|
+
});
|
|
129
|
+
(0, _defineProperty2.default)(this, "truncateStartEndAtPosition", function (truncationPosition) {
|
|
130
|
+
// If using a non-centered startEnd anchor position, we need to *build*
|
|
131
|
+
// the string from scratch instead of *removing* from the full text string,
|
|
132
|
+
// to make sure we don't go past the beginning or end of the text
|
|
133
|
+
var truncatedText = '';
|
|
134
|
+
_this.setTextToCheck(truncatedText);
|
|
135
|
+
|
|
136
|
+
// Ellipses are conditional - if the anchor is towards the beginning or end,
|
|
137
|
+
// it's possible they shouldn't render
|
|
138
|
+
var startingEllipsis = _this.ellipsis;
|
|
139
|
+
var endingEllipsis = _this.ellipsis;
|
|
140
|
+
|
|
141
|
+
// Split the text into two at the anchor position
|
|
142
|
+
var _splitText$at5 = splitText(_this.fullText).at(truncationPosition),
|
|
143
|
+
_splitText$at6 = (0, _slicedToArray2.default)(_splitText$at5, 2),
|
|
144
|
+
firstPart = _splitText$at6[0],
|
|
145
|
+
secondPart = _splitText$at6[1];
|
|
146
|
+
var combinedText = function combinedText() {
|
|
147
|
+
return "".concat(startingEllipsis).concat(truncatedText).concat(endingEllipsis);
|
|
148
|
+
};
|
|
149
|
+
while (_this.textWidth <= _this.availableWidth) {
|
|
150
|
+
if (firstPart.length > 0) {
|
|
151
|
+
truncatedText = "".concat(getLastCharacter(firstPart)).concat(truncatedText);
|
|
152
|
+
firstPart = removeLastCharacter(firstPart);
|
|
153
|
+
} else {
|
|
154
|
+
startingEllipsis = '';
|
|
155
|
+
}
|
|
156
|
+
if (secondPart.length > 0) {
|
|
157
|
+
truncatedText = "".concat(truncatedText).concat(getFirstCharacter(secondPart));
|
|
158
|
+
secondPart = removeFirstCharacter(secondPart);
|
|
159
|
+
} else {
|
|
160
|
+
endingEllipsis = '';
|
|
161
|
+
}
|
|
162
|
+
_this.setTextToCheck(combinedText());
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Because this logic builds text outwards vs. removing inwards, the final
|
|
166
|
+
// text width ends up a little larger than the container, and we need to
|
|
167
|
+
// remove the last added character(s)
|
|
168
|
+
if (!startingEllipsis) {
|
|
169
|
+
truncatedText = removeLastCharacter(truncatedText);
|
|
170
|
+
} else if (!endingEllipsis) {
|
|
171
|
+
truncatedText = removeFirstCharacter(truncatedText);
|
|
172
|
+
} else {
|
|
173
|
+
truncatedText = removeFirstAndLastCharacters(truncatedText);
|
|
174
|
+
}
|
|
175
|
+
return combinedText();
|
|
176
|
+
});
|
|
177
|
+
(0, _defineProperty2.default)(this, "truncateStartEndAtMiddle", function () {
|
|
178
|
+
var truncatedText = _this.fullText;
|
|
179
|
+
_this.setTextToCheck(truncatedText);
|
|
180
|
+
var combinedText = function combinedText() {
|
|
181
|
+
return "".concat(_this.ellipsis).concat(truncatedText).concat(_this.ellipsis);
|
|
182
|
+
};
|
|
183
|
+
while (_this.textWidth > _this.availableWidth) {
|
|
184
|
+
truncatedText = removeFirstAndLastCharacters(truncatedText);
|
|
185
|
+
_this.setTextToCheck(combinedText());
|
|
186
|
+
}
|
|
187
|
+
return combinedText();
|
|
188
|
+
});
|
|
189
|
+
(0, _defineProperty2.default)(this, "truncateMiddle", function () {
|
|
190
|
+
var middlePosition = Math.floor(_this.fullText.length / 2);
|
|
191
|
+
var _splitText$at7 = splitText(_this.fullText).at(middlePosition),
|
|
192
|
+
_splitText$at8 = (0, _slicedToArray2.default)(_splitText$at7, 2),
|
|
193
|
+
firstHalf = _splitText$at8[0],
|
|
194
|
+
secondHalf = _splitText$at8[1];
|
|
195
|
+
var trimfirstHalf;
|
|
196
|
+
var combinedText = function combinedText() {
|
|
197
|
+
return "".concat(firstHalf).concat(_this.ellipsis).concat(secondHalf);
|
|
198
|
+
};
|
|
199
|
+
_this.setTextToCheck(combinedText());
|
|
200
|
+
while (_this.textWidth > _this.availableWidth) {
|
|
201
|
+
trimfirstHalf = !trimfirstHalf;
|
|
202
|
+
if (trimfirstHalf) {
|
|
203
|
+
firstHalf = removeLastCharacter(firstHalf);
|
|
204
|
+
} else {
|
|
205
|
+
secondHalf = removeFirstCharacter(secondHalf);
|
|
206
|
+
}
|
|
207
|
+
_this.setTextToCheck(combinedText());
|
|
208
|
+
}
|
|
209
|
+
return combinedText();
|
|
210
|
+
});
|
|
211
|
+
this.fullText = fullText;
|
|
212
|
+
this.ellipsis = ellipsis;
|
|
213
|
+
this.availableWidth = availableWidth;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Internal measurement utils which will be overridden depending on the
|
|
218
|
+
* rendering approach used (e.g. DOM vs Canvas).
|
|
219
|
+
*/);
|
|
220
|
+
/**
|
|
221
|
+
* Creates a temporary vanilla JS DOM element for manipulating text and
|
|
222
|
+
* determining text width.
|
|
223
|
+
*
|
|
224
|
+
* Requires passing in a container element to which the temporary element
|
|
225
|
+
* will be appended. Any CSS/font styles that need to be accounted for should
|
|
226
|
+
* be automatically inherited from the container.
|
|
227
|
+
*
|
|
228
|
+
* NOTE: The consumer is responsible for calling the `cleanup()` method manually
|
|
229
|
+
* to remove the temporary DOM node once their usage of this utility is complete.
|
|
230
|
+
*/
|
|
231
|
+
var TruncationUtilsWithDOM = /*#__PURE__*/function (_TruncationUtils2) {
|
|
232
|
+
(0, _inherits2.default)(TruncationUtilsWithDOM, _TruncationUtils2);
|
|
233
|
+
var _super = _createSuper(TruncationUtilsWithDOM);
|
|
234
|
+
function TruncationUtilsWithDOM(_ref2) {
|
|
235
|
+
var _this2;
|
|
236
|
+
var container = _ref2.container,
|
|
237
|
+
rest = (0, _objectWithoutProperties2.default)(_ref2, _excluded);
|
|
238
|
+
(0, _classCallCheck2.default)(this, TruncationUtilsWithDOM);
|
|
239
|
+
_this2 = _super.call(this, rest);
|
|
240
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this2), "container", void 0);
|
|
241
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this2), "span", void 0);
|
|
242
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this2), "setTextToCheck", function (text) {
|
|
243
|
+
_this2.span.textContent = text;
|
|
244
|
+
});
|
|
245
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this2), "cleanup", function () {
|
|
246
|
+
_this2.container.removeChild(_this2.span);
|
|
247
|
+
});
|
|
248
|
+
_this2.container = container;
|
|
249
|
+
_this2.span = document.createElement('span');
|
|
250
|
+
_this2.span.style.position = 'absolute'; // Prevent page reflow/repaint for performance
|
|
251
|
+
_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
|
|
252
|
+
_this2.container.appendChild(_this2.span);
|
|
253
|
+
return _this2;
|
|
254
|
+
}
|
|
255
|
+
(0, _createClass2.default)(TruncationUtilsWithDOM, [{
|
|
256
|
+
key: "textWidth",
|
|
257
|
+
get: function get() {
|
|
258
|
+
return this.span.offsetWidth;
|
|
259
|
+
}
|
|
260
|
+
}]);
|
|
261
|
+
return TruncationUtilsWithDOM;
|
|
262
|
+
}(_TruncationUtils);
|
|
263
|
+
/**
|
|
264
|
+
* Creates a temporary Canvas element for manipulating text & determining
|
|
265
|
+
* text width. This method is compatible with charts or other canvas-rendered
|
|
266
|
+
* frameworks, and requires no cleanup method.
|
|
267
|
+
*
|
|
268
|
+
* To accurately measure text, canvas rendering requires either a container to
|
|
269
|
+
* compute/derive font styles from, or a static font string (useful for usage
|
|
270
|
+
* outside the DOM). Particular care should be applied when fallback fonts are
|
|
271
|
+
* used, as more fallback fonts can lead to less precision.
|
|
272
|
+
*
|
|
273
|
+
* Please note that while canvas is more performant than DOM measurement, there
|
|
274
|
+
* are subpixel to single digit pixel differences between DOM and canvas
|
|
275
|
+
* measurement due to the different rendering engines used.
|
|
276
|
+
*/
|
|
277
|
+
exports.TruncationUtilsWithDOM = TruncationUtilsWithDOM;
|
|
278
|
+
var TruncationUtilsWithCanvas = /*#__PURE__*/function (_TruncationUtils3) {
|
|
279
|
+
(0, _inherits2.default)(TruncationUtilsWithCanvas, _TruncationUtils3);
|
|
280
|
+
var _super2 = _createSuper(TruncationUtilsWithCanvas);
|
|
281
|
+
function TruncationUtilsWithCanvas(_ref3) {
|
|
282
|
+
var _this3;
|
|
283
|
+
var font = _ref3.font,
|
|
284
|
+
container = _ref3.container,
|
|
285
|
+
rest = (0, _objectWithoutProperties2.default)(_ref3, _excluded2);
|
|
286
|
+
(0, _classCallCheck2.default)(this, TruncationUtilsWithCanvas);
|
|
287
|
+
_this3 = _super2.call(this, rest);
|
|
288
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this3), "context", void 0);
|
|
289
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this3), "currentText", '');
|
|
290
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this3), "computeFontFromElement", function (element) {
|
|
291
|
+
var computedStyles = window.getComputedStyle(element);
|
|
292
|
+
return ['font-style', 'font-variant', 'font-weight', 'font-size', 'font-family'].map(function (prop) {
|
|
293
|
+
return computedStyles.getPropertyValue(prop);
|
|
294
|
+
}).join(' ').trim();
|
|
295
|
+
});
|
|
296
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this3), "setTextToCheck", function (text) {
|
|
297
|
+
_this3.currentText = text;
|
|
298
|
+
});
|
|
299
|
+
_this3.context = document.createElement('canvas').getContext('2d');
|
|
300
|
+
|
|
301
|
+
// Set the canvas font to ensure text width calculations are correct
|
|
302
|
+
if (font) {
|
|
303
|
+
_this3.context.font = font;
|
|
304
|
+
} else if (container) {
|
|
305
|
+
_this3.context.font = _this3.computeFontFromElement(container);
|
|
306
|
+
}
|
|
307
|
+
return _this3;
|
|
308
|
+
}
|
|
309
|
+
(0, _createClass2.default)(TruncationUtilsWithCanvas, [{
|
|
310
|
+
key: "textWidth",
|
|
311
|
+
get: function get() {
|
|
312
|
+
return this.context.measureText(this.currentText).width;
|
|
313
|
+
}
|
|
314
|
+
}]);
|
|
315
|
+
return TruncationUtilsWithCanvas;
|
|
316
|
+
}(_TruncationUtils);
|
|
317
|
+
/**
|
|
318
|
+
* DRY character/substring utils
|
|
319
|
+
*/
|
|
320
|
+
exports.TruncationUtilsWithCanvas = TruncationUtilsWithCanvas;
|
|
321
|
+
var removeLastCharacter = function removeLastCharacter(text) {
|
|
322
|
+
return text.substring(0, text.length - 1);
|
|
323
|
+
};
|
|
324
|
+
var getLastCharacter = function getLastCharacter(text) {
|
|
325
|
+
return text.substring(text.length - 1);
|
|
326
|
+
};
|
|
327
|
+
var removeFirstCharacter = function removeFirstCharacter(text) {
|
|
328
|
+
return text.substring(1);
|
|
329
|
+
};
|
|
330
|
+
var getFirstCharacter = function getFirstCharacter(text) {
|
|
331
|
+
return text.substring(0, 1);
|
|
332
|
+
};
|
|
333
|
+
var removeFirstAndLastCharacters = function removeFirstAndLastCharacters(text) {
|
|
334
|
+
return text.substring(1, text.length - 1);
|
|
335
|
+
};
|
|
336
|
+
var splitText = function splitText(text) {
|
|
337
|
+
return {
|
|
338
|
+
at: function at(index) {
|
|
339
|
+
return [text.substring(0, index), text.substring(index)];
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
};
|
|
@@ -28,16 +28,16 @@ function euiFontSizeFromScale(scale, _ref) {
|
|
|
28
28
|
var base = _ref.base,
|
|
29
29
|
font = _ref.font;
|
|
30
30
|
var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
|
|
31
|
-
_ref2$
|
|
32
|
-
|
|
31
|
+
_ref2$unit = _ref2.unit,
|
|
32
|
+
unit = _ref2$unit === void 0 ? font.defaultUnits : _ref2$unit,
|
|
33
33
|
customScale = _ref2.customScale;
|
|
34
|
-
if (
|
|
34
|
+
if (unit === 'em') {
|
|
35
35
|
return "".concat(font.scale[scale], "em");
|
|
36
36
|
}
|
|
37
37
|
var numerator = base * font.scale[scale];
|
|
38
38
|
if (customScale) numerator *= font.scale[customScale];
|
|
39
39
|
var denominator = base * font.scale[font.body.scale];
|
|
40
|
-
return
|
|
40
|
+
return unit === 'px' ? "".concat(numerator, "px") : "".concat((numerator / denominator).toFixed(4), "rem");
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
/**
|
|
@@ -56,8 +56,8 @@ function euiLineHeightFromBaseline(scale, _ref3) {
|
|
|
56
56
|
var base = _ref3.base,
|
|
57
57
|
font = _ref3.font;
|
|
58
58
|
var _ref4 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
|
|
59
|
-
_ref4$
|
|
60
|
-
|
|
59
|
+
_ref4$unit = _ref4.unit,
|
|
60
|
+
unit = _ref4$unit === void 0 ? font.defaultUnits : _ref4$unit,
|
|
61
61
|
customScale = _ref4.customScale;
|
|
62
62
|
var baseline = font.baseline,
|
|
63
63
|
lineHeightMultiplier = font.lineHeightMultiplier;
|
|
@@ -65,13 +65,13 @@ function euiLineHeightFromBaseline(scale, _ref3) {
|
|
|
65
65
|
if (customScale) numerator *= font.scale[customScale];
|
|
66
66
|
var denominator = base * font.scale[font.body.scale];
|
|
67
67
|
var _lineHeightMultiplier = numerator <= base ? lineHeightMultiplier : lineHeightMultiplier * 0.833;
|
|
68
|
-
if (
|
|
68
|
+
if (unit === 'em') {
|
|
69
69
|
// Even though the line-height via `em` cannot be determined against the pixel baseline grid;
|
|
70
70
|
// we will assume that typically larger scale font-sizes should have a shorter line-height;
|
|
71
71
|
return _lineHeightMultiplier.toFixed(4).toString();
|
|
72
72
|
}
|
|
73
73
|
var pixelValue = Math.floor(Math.round(numerator * _lineHeightMultiplier) / baseline) * baseline;
|
|
74
|
-
return
|
|
74
|
+
return unit === 'px' ? "".concat(pixelValue, "px") : "".concat((pixelValue / denominator).toFixed(4), "rem");
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
/**
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.EuiThemeFontWeights = exports.
|
|
6
|
+
exports.EuiThemeFontWeights = exports.EuiThemeFontUnits = exports.EuiThemeFontScales = void 0;
|
|
7
7
|
/*
|
|
8
8
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
9
9
|
* or more contributor license agreements. Licensed under the Elastic License
|
|
@@ -16,8 +16,8 @@ exports.EuiThemeFontWeights = exports.EuiThemeFontSizeMeasurements = exports.Eui
|
|
|
16
16
|
* Font units of measure
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
var
|
|
20
|
-
exports.
|
|
19
|
+
var EuiThemeFontUnits = ['rem', 'px', 'em'];
|
|
20
|
+
exports.EuiThemeFontUnits = EuiThemeFontUnits;
|
|
21
21
|
/*
|
|
22
22
|
* Font scale
|
|
23
23
|
*/
|
|
@@ -29,6 +29,8 @@ var EuiNestedThemeContext = /*#__PURE__*/(0, _react.createContext)({
|
|
|
29
29
|
isGlobalTheme: true,
|
|
30
30
|
hasDifferentColorFromGlobalTheme: false,
|
|
31
31
|
bodyColor: '',
|
|
32
|
-
colorClassName: ''
|
|
32
|
+
colorClassName: '',
|
|
33
|
+
setGlobalCSSVariables: function setGlobalCSSVariables() {},
|
|
34
|
+
setNearestThemeCSSVariables: function setNearestThemeCSSVariables() {}
|
|
33
35
|
});
|
|
34
36
|
exports.EuiNestedThemeContext = EuiNestedThemeContext;
|
|
@@ -5,7 +5,7 @@ var _typeof = require("@babel/runtime/helpers/typeof");
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.withEuiTheme = exports.useEuiTheme = exports.RenderWithEuiTheme = void 0;
|
|
8
|
+
exports.withEuiTheme = exports.useEuiThemeCSSVariables = exports.useEuiTheme = exports.RenderWithEuiTheme = void 0;
|
|
9
9
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
10
10
|
var _react = _interopRequireWildcard(require("react"));
|
|
11
11
|
var _context = require("./context");
|
|
@@ -75,4 +75,23 @@ var RenderWithEuiTheme = function RenderWithEuiTheme(_ref) {
|
|
|
75
75
|
var theme = useEuiTheme();
|
|
76
76
|
return children(theme);
|
|
77
77
|
};
|
|
78
|
-
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Minor syntactical sugar hook for theme CSS variables.
|
|
81
|
+
* Primarily meant for internal EUI usage.
|
|
82
|
+
*/
|
|
83
|
+
exports.RenderWithEuiTheme = RenderWithEuiTheme;
|
|
84
|
+
var useEuiThemeCSSVariables = function useEuiThemeCSSVariables() {
|
|
85
|
+
var _useContext = (0, _react.useContext)(_context.EuiNestedThemeContext),
|
|
86
|
+
setGlobalCSSVariables = _useContext.setGlobalCSSVariables,
|
|
87
|
+
globalCSSVariables = _useContext.globalCSSVariables,
|
|
88
|
+
setNearestThemeCSSVariables = _useContext.setNearestThemeCSSVariables,
|
|
89
|
+
themeCSSVariables = _useContext.themeCSSVariables;
|
|
90
|
+
return {
|
|
91
|
+
setGlobalCSSVariables: setGlobalCSSVariables,
|
|
92
|
+
globalCSSVariables: globalCSSVariables,
|
|
93
|
+
setNearestThemeCSSVariables: setNearestThemeCSSVariables,
|
|
94
|
+
themeCSSVariables: themeCSSVariables
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
exports.useEuiThemeCSSVariables = useEuiThemeCSSVariables;
|
|
@@ -123,6 +123,12 @@ Object.defineProperty(exports, "useEuiTheme", {
|
|
|
123
123
|
return _hooks.useEuiTheme;
|
|
124
124
|
}
|
|
125
125
|
});
|
|
126
|
+
Object.defineProperty(exports, "useEuiThemeCSSVariables", {
|
|
127
|
+
enumerable: true,
|
|
128
|
+
get: function get() {
|
|
129
|
+
return _hooks.useEuiThemeCSSVariables;
|
|
130
|
+
}
|
|
131
|
+
});
|
|
126
132
|
Object.defineProperty(exports, "withEuiTheme", {
|
|
127
133
|
enumerable: true,
|
|
128
134
|
get: function get() {
|