@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,352 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.TruncationUtilsWithDOM = exports.TruncationUtilsWithCanvas = void 0;
|
|
7
|
+
var _excluded = ["container"],
|
|
8
|
+
_excluded2 = ["font", "container"];
|
|
9
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
10
|
+
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; }
|
|
11
|
+
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; }
|
|
12
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
13
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
14
|
+
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); }; }
|
|
15
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
16
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
17
|
+
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; } }
|
|
18
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
19
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
20
|
+
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."); }
|
|
21
|
+
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); }
|
|
22
|
+
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; }
|
|
23
|
+
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; } }
|
|
24
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
25
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
26
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
27
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
28
|
+
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; }
|
|
29
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
30
|
+
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); }
|
|
31
|
+
/*
|
|
32
|
+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
33
|
+
* or more contributor license agreements. Licensed under the Elastic License
|
|
34
|
+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
|
35
|
+
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
|
36
|
+
* Side Public License, v 1.
|
|
37
|
+
*/
|
|
38
|
+
/**
|
|
39
|
+
* This internal shared/base class contains the actual logic for truncating text
|
|
40
|
+
* (as well as a few handy utilities for checking whether truncation is possible
|
|
41
|
+
* or even necessary).
|
|
42
|
+
*
|
|
43
|
+
* How the underlying mechanism works: the full text is rendered, and then
|
|
44
|
+
* characters are removed one by one until the width of the text fits within
|
|
45
|
+
* the specified available width.
|
|
46
|
+
*
|
|
47
|
+
* Side note: The exception to this is the `truncateStartEndAtPosition` method,
|
|
48
|
+
* which works by building up from an empty string / by adding characters
|
|
49
|
+
* instead of removing them.
|
|
50
|
+
*/
|
|
51
|
+
var _TruncationUtils = /*#__PURE__*/_createClass(function _TruncationUtils(_ref) {
|
|
52
|
+
var _this = this;
|
|
53
|
+
var fullText = _ref.fullText,
|
|
54
|
+
ellipsis = _ref.ellipsis,
|
|
55
|
+
availableWidth = _ref.availableWidth;
|
|
56
|
+
_classCallCheck(this, _TruncationUtils);
|
|
57
|
+
_defineProperty(this, "fullText", void 0);
|
|
58
|
+
_defineProperty(this, "ellipsis", void 0);
|
|
59
|
+
_defineProperty(this, "availableWidth", void 0);
|
|
60
|
+
/**
|
|
61
|
+
* Early return checks
|
|
62
|
+
*/
|
|
63
|
+
_defineProperty(this, "checkIfTruncationIsNeeded", function () {
|
|
64
|
+
_this.setTextToCheck(_this.fullText);
|
|
65
|
+
if (_this.availableWidth > _this.textWidth) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
_defineProperty(this, "checkSufficientEllipsisWidth", function (truncation) {
|
|
70
|
+
var textToCheck = truncation === 'startEnd' ? "".concat(_this.ellipsis, " ").concat(_this.ellipsis) // startEnd needs a little more space
|
|
71
|
+
: _this.ellipsis;
|
|
72
|
+
_this.setTextToCheck(textToCheck);
|
|
73
|
+
if (_this.textWidth >= _this.availableWidth * 0.9) {
|
|
74
|
+
console.error('The truncation ellipsis is larger than the available width. No text can be rendered.');
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
_defineProperty(this, "checkTruncationOffsetWidth", function (text) {
|
|
79
|
+
_this.setTextToCheck(text);
|
|
80
|
+
if (_this.textWidth > _this.availableWidth) {
|
|
81
|
+
console.error("The passed truncationOffset is too large for the available width. Truncating the offset instead.");
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
/**
|
|
86
|
+
* Truncation types logic. This is where the magic happens
|
|
87
|
+
*/
|
|
88
|
+
_defineProperty(this, "truncateStart", function (truncationOffset) {
|
|
89
|
+
var truncatedText = _this.fullText;
|
|
90
|
+
var leadingText = '';
|
|
91
|
+
var combinedText = function combinedText() {
|
|
92
|
+
return "".concat(leadingText).concat(truncatedText);
|
|
93
|
+
};
|
|
94
|
+
if (truncationOffset) {
|
|
95
|
+
var _splitText$at = splitText(_this.fullText).at(truncationOffset);
|
|
96
|
+
var _splitText$at2 = _slicedToArray(_splitText$at, 2);
|
|
97
|
+
leadingText = _splitText$at2[0];
|
|
98
|
+
truncatedText = _splitText$at2[1];
|
|
99
|
+
var widthCheck = "".concat(leadingText).concat(_this.ellipsis);
|
|
100
|
+
if (_this.checkTruncationOffsetWidth(widthCheck) === false) {
|
|
101
|
+
truncatedText = leadingText;
|
|
102
|
+
leadingText = '';
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
leadingText += _this.ellipsis;
|
|
106
|
+
_this.setTextToCheck(combinedText());
|
|
107
|
+
while (_this.textWidth > _this.availableWidth) {
|
|
108
|
+
truncatedText = removeFirstCharacter(truncatedText);
|
|
109
|
+
_this.setTextToCheck(combinedText());
|
|
110
|
+
}
|
|
111
|
+
return combinedText();
|
|
112
|
+
});
|
|
113
|
+
_defineProperty(this, "truncateEnd", function (truncationOffset) {
|
|
114
|
+
var truncatedText = _this.fullText;
|
|
115
|
+
var trailingText = '';
|
|
116
|
+
var combinedText = function combinedText() {
|
|
117
|
+
return "".concat(truncatedText).concat(trailingText);
|
|
118
|
+
};
|
|
119
|
+
if (truncationOffset) {
|
|
120
|
+
var index = _this.fullText.length - truncationOffset;
|
|
121
|
+
var _splitText$at3 = splitText(_this.fullText).at(index);
|
|
122
|
+
var _splitText$at4 = _slicedToArray(_splitText$at3, 2);
|
|
123
|
+
truncatedText = _splitText$at4[0];
|
|
124
|
+
trailingText = _splitText$at4[1];
|
|
125
|
+
var widthCheck = "".concat(_this.ellipsis).concat(trailingText);
|
|
126
|
+
if (_this.checkTruncationOffsetWidth(widthCheck) === false) {
|
|
127
|
+
truncatedText = trailingText;
|
|
128
|
+
trailingText = '';
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
trailingText = _this.ellipsis + trailingText;
|
|
132
|
+
_this.setTextToCheck(combinedText());
|
|
133
|
+
while (_this.textWidth > _this.availableWidth) {
|
|
134
|
+
truncatedText = removeLastCharacter(truncatedText);
|
|
135
|
+
_this.setTextToCheck(combinedText());
|
|
136
|
+
}
|
|
137
|
+
return combinedText();
|
|
138
|
+
});
|
|
139
|
+
_defineProperty(this, "truncateStartEndAtPosition", function (truncationPosition) {
|
|
140
|
+
// If using a non-centered startEnd anchor position, we need to *build*
|
|
141
|
+
// the string from scratch instead of *removing* from the full text string,
|
|
142
|
+
// to make sure we don't go past the beginning or end of the text
|
|
143
|
+
var truncatedText = '';
|
|
144
|
+
_this.setTextToCheck(truncatedText);
|
|
145
|
+
|
|
146
|
+
// Ellipses are conditional - if the anchor is towards the beginning or end,
|
|
147
|
+
// it's possible they shouldn't render
|
|
148
|
+
var startingEllipsis = _this.ellipsis;
|
|
149
|
+
var endingEllipsis = _this.ellipsis;
|
|
150
|
+
|
|
151
|
+
// Split the text into two at the anchor position
|
|
152
|
+
var _splitText$at5 = splitText(_this.fullText).at(truncationPosition),
|
|
153
|
+
_splitText$at6 = _slicedToArray(_splitText$at5, 2),
|
|
154
|
+
firstPart = _splitText$at6[0],
|
|
155
|
+
secondPart = _splitText$at6[1];
|
|
156
|
+
var combinedText = function combinedText() {
|
|
157
|
+
return "".concat(startingEllipsis).concat(truncatedText).concat(endingEllipsis);
|
|
158
|
+
};
|
|
159
|
+
while (_this.textWidth <= _this.availableWidth) {
|
|
160
|
+
if (firstPart.length > 0) {
|
|
161
|
+
truncatedText = "".concat(getLastCharacter(firstPart)).concat(truncatedText);
|
|
162
|
+
firstPart = removeLastCharacter(firstPart);
|
|
163
|
+
} else {
|
|
164
|
+
startingEllipsis = '';
|
|
165
|
+
}
|
|
166
|
+
if (secondPart.length > 0) {
|
|
167
|
+
truncatedText = "".concat(truncatedText).concat(getFirstCharacter(secondPart));
|
|
168
|
+
secondPart = removeFirstCharacter(secondPart);
|
|
169
|
+
} else {
|
|
170
|
+
endingEllipsis = '';
|
|
171
|
+
}
|
|
172
|
+
_this.setTextToCheck(combinedText());
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Because this logic builds text outwards vs. removing inwards, the final
|
|
176
|
+
// text width ends up a little larger than the container, and we need to
|
|
177
|
+
// remove the last added character(s)
|
|
178
|
+
if (!startingEllipsis) {
|
|
179
|
+
truncatedText = removeLastCharacter(truncatedText);
|
|
180
|
+
} else if (!endingEllipsis) {
|
|
181
|
+
truncatedText = removeFirstCharacter(truncatedText);
|
|
182
|
+
} else {
|
|
183
|
+
truncatedText = removeFirstAndLastCharacters(truncatedText);
|
|
184
|
+
}
|
|
185
|
+
return combinedText();
|
|
186
|
+
});
|
|
187
|
+
_defineProperty(this, "truncateStartEndAtMiddle", function () {
|
|
188
|
+
var truncatedText = _this.fullText;
|
|
189
|
+
_this.setTextToCheck(truncatedText);
|
|
190
|
+
var combinedText = function combinedText() {
|
|
191
|
+
return "".concat(_this.ellipsis).concat(truncatedText).concat(_this.ellipsis);
|
|
192
|
+
};
|
|
193
|
+
while (_this.textWidth > _this.availableWidth) {
|
|
194
|
+
truncatedText = removeFirstAndLastCharacters(truncatedText);
|
|
195
|
+
_this.setTextToCheck(combinedText());
|
|
196
|
+
}
|
|
197
|
+
return combinedText();
|
|
198
|
+
});
|
|
199
|
+
_defineProperty(this, "truncateMiddle", function () {
|
|
200
|
+
var middlePosition = Math.floor(_this.fullText.length / 2);
|
|
201
|
+
var _splitText$at7 = splitText(_this.fullText).at(middlePosition),
|
|
202
|
+
_splitText$at8 = _slicedToArray(_splitText$at7, 2),
|
|
203
|
+
firstHalf = _splitText$at8[0],
|
|
204
|
+
secondHalf = _splitText$at8[1];
|
|
205
|
+
var trimfirstHalf;
|
|
206
|
+
var combinedText = function combinedText() {
|
|
207
|
+
return "".concat(firstHalf).concat(_this.ellipsis).concat(secondHalf);
|
|
208
|
+
};
|
|
209
|
+
_this.setTextToCheck(combinedText());
|
|
210
|
+
while (_this.textWidth > _this.availableWidth) {
|
|
211
|
+
trimfirstHalf = !trimfirstHalf;
|
|
212
|
+
if (trimfirstHalf) {
|
|
213
|
+
firstHalf = removeLastCharacter(firstHalf);
|
|
214
|
+
} else {
|
|
215
|
+
secondHalf = removeFirstCharacter(secondHalf);
|
|
216
|
+
}
|
|
217
|
+
_this.setTextToCheck(combinedText());
|
|
218
|
+
}
|
|
219
|
+
return combinedText();
|
|
220
|
+
});
|
|
221
|
+
this.fullText = fullText;
|
|
222
|
+
this.ellipsis = ellipsis;
|
|
223
|
+
this.availableWidth = availableWidth;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Internal measurement utils which will be overridden depending on the
|
|
228
|
+
* rendering approach used (e.g. DOM vs Canvas).
|
|
229
|
+
*/);
|
|
230
|
+
/**
|
|
231
|
+
* Creates a temporary vanilla JS DOM element for manipulating text and
|
|
232
|
+
* determining text width.
|
|
233
|
+
*
|
|
234
|
+
* Requires passing in a container element to which the temporary element
|
|
235
|
+
* will be appended. Any CSS/font styles that need to be accounted for should
|
|
236
|
+
* be automatically inherited from the container.
|
|
237
|
+
*
|
|
238
|
+
* NOTE: The consumer is responsible for calling the `cleanup()` method manually
|
|
239
|
+
* to remove the temporary DOM node once their usage of this utility is complete.
|
|
240
|
+
*/
|
|
241
|
+
var TruncationUtilsWithDOM = /*#__PURE__*/function (_TruncationUtils2) {
|
|
242
|
+
_inherits(TruncationUtilsWithDOM, _TruncationUtils2);
|
|
243
|
+
var _super = _createSuper(TruncationUtilsWithDOM);
|
|
244
|
+
function TruncationUtilsWithDOM(_ref2) {
|
|
245
|
+
var _this2;
|
|
246
|
+
var container = _ref2.container,
|
|
247
|
+
rest = _objectWithoutProperties(_ref2, _excluded);
|
|
248
|
+
_classCallCheck(this, TruncationUtilsWithDOM);
|
|
249
|
+
_this2 = _super.call(this, rest);
|
|
250
|
+
_defineProperty(_assertThisInitialized(_this2), "container", void 0);
|
|
251
|
+
_defineProperty(_assertThisInitialized(_this2), "span", void 0);
|
|
252
|
+
_defineProperty(_assertThisInitialized(_this2), "setTextToCheck", function (text) {
|
|
253
|
+
_this2.span.textContent = text;
|
|
254
|
+
});
|
|
255
|
+
_defineProperty(_assertThisInitialized(_this2), "cleanup", function () {
|
|
256
|
+
_this2.container.removeChild(_this2.span);
|
|
257
|
+
});
|
|
258
|
+
_this2.container = container;
|
|
259
|
+
_this2.span = document.createElement('span');
|
|
260
|
+
_this2.span.style.position = 'absolute'; // Prevent page reflow/repaint for performance
|
|
261
|
+
_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
|
|
262
|
+
_this2.container.appendChild(_this2.span);
|
|
263
|
+
return _this2;
|
|
264
|
+
}
|
|
265
|
+
_createClass(TruncationUtilsWithDOM, [{
|
|
266
|
+
key: "textWidth",
|
|
267
|
+
get: function get() {
|
|
268
|
+
return this.span.offsetWidth;
|
|
269
|
+
}
|
|
270
|
+
}]);
|
|
271
|
+
return TruncationUtilsWithDOM;
|
|
272
|
+
}(_TruncationUtils);
|
|
273
|
+
/**
|
|
274
|
+
* Creates a temporary Canvas element for manipulating text & determining
|
|
275
|
+
* text width. This method is compatible with charts or other canvas-rendered
|
|
276
|
+
* frameworks, and requires no cleanup method.
|
|
277
|
+
*
|
|
278
|
+
* To accurately measure text, canvas rendering requires either a container to
|
|
279
|
+
* compute/derive font styles from, or a static font string (useful for usage
|
|
280
|
+
* outside the DOM). Particular care should be applied when fallback fonts are
|
|
281
|
+
* used, as more fallback fonts can lead to less precision.
|
|
282
|
+
*
|
|
283
|
+
* Please note that while canvas is more performant than DOM measurement, there
|
|
284
|
+
* are subpixel to single digit pixel differences between DOM and canvas
|
|
285
|
+
* measurement due to the different rendering engines used.
|
|
286
|
+
*/
|
|
287
|
+
exports.TruncationUtilsWithDOM = TruncationUtilsWithDOM;
|
|
288
|
+
var TruncationUtilsWithCanvas = /*#__PURE__*/function (_TruncationUtils3) {
|
|
289
|
+
_inherits(TruncationUtilsWithCanvas, _TruncationUtils3);
|
|
290
|
+
var _super2 = _createSuper(TruncationUtilsWithCanvas);
|
|
291
|
+
function TruncationUtilsWithCanvas(_ref3) {
|
|
292
|
+
var _this3;
|
|
293
|
+
var font = _ref3.font,
|
|
294
|
+
container = _ref3.container,
|
|
295
|
+
rest = _objectWithoutProperties(_ref3, _excluded2);
|
|
296
|
+
_classCallCheck(this, TruncationUtilsWithCanvas);
|
|
297
|
+
_this3 = _super2.call(this, rest);
|
|
298
|
+
_defineProperty(_assertThisInitialized(_this3), "context", void 0);
|
|
299
|
+
_defineProperty(_assertThisInitialized(_this3), "currentText", '');
|
|
300
|
+
_defineProperty(_assertThisInitialized(_this3), "computeFontFromElement", function (element) {
|
|
301
|
+
var computedStyles = window.getComputedStyle(element);
|
|
302
|
+
return ['font-style', 'font-variant', 'font-weight', 'font-size', 'font-family'].map(function (prop) {
|
|
303
|
+
return computedStyles.getPropertyValue(prop);
|
|
304
|
+
}).join(' ').trim();
|
|
305
|
+
});
|
|
306
|
+
_defineProperty(_assertThisInitialized(_this3), "setTextToCheck", function (text) {
|
|
307
|
+
_this3.currentText = text;
|
|
308
|
+
});
|
|
309
|
+
_this3.context = document.createElement('canvas').getContext('2d');
|
|
310
|
+
|
|
311
|
+
// Set the canvas font to ensure text width calculations are correct
|
|
312
|
+
if (font) {
|
|
313
|
+
_this3.context.font = font;
|
|
314
|
+
} else if (container) {
|
|
315
|
+
_this3.context.font = _this3.computeFontFromElement(container);
|
|
316
|
+
}
|
|
317
|
+
return _this3;
|
|
318
|
+
}
|
|
319
|
+
_createClass(TruncationUtilsWithCanvas, [{
|
|
320
|
+
key: "textWidth",
|
|
321
|
+
get: function get() {
|
|
322
|
+
return this.context.measureText(this.currentText).width;
|
|
323
|
+
}
|
|
324
|
+
}]);
|
|
325
|
+
return TruncationUtilsWithCanvas;
|
|
326
|
+
}(_TruncationUtils);
|
|
327
|
+
/**
|
|
328
|
+
* DRY character/substring utils
|
|
329
|
+
*/
|
|
330
|
+
exports.TruncationUtilsWithCanvas = TruncationUtilsWithCanvas;
|
|
331
|
+
var removeLastCharacter = function removeLastCharacter(text) {
|
|
332
|
+
return text.substring(0, text.length - 1);
|
|
333
|
+
};
|
|
334
|
+
var getLastCharacter = function getLastCharacter(text) {
|
|
335
|
+
return text.substring(text.length - 1);
|
|
336
|
+
};
|
|
337
|
+
var removeFirstCharacter = function removeFirstCharacter(text) {
|
|
338
|
+
return text.substring(1);
|
|
339
|
+
};
|
|
340
|
+
var getFirstCharacter = function getFirstCharacter(text) {
|
|
341
|
+
return text.substring(0, 1);
|
|
342
|
+
};
|
|
343
|
+
var removeFirstAndLastCharacters = function removeFirstAndLastCharacters(text) {
|
|
344
|
+
return text.substring(1, text.length - 1);
|
|
345
|
+
};
|
|
346
|
+
var splitText = function splitText(text) {
|
|
347
|
+
return {
|
|
348
|
+
at: function at(index) {
|
|
349
|
+
return [text.substring(0, index), text.substring(index)];
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
};
|
|
@@ -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;
|
|
@@ -4,7 +4,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.withEuiTheme = exports.useEuiTheme = exports.RenderWithEuiTheme = void 0;
|
|
7
|
+
exports.withEuiTheme = exports.useEuiThemeCSSVariables = exports.useEuiTheme = exports.RenderWithEuiTheme = void 0;
|
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
var _context = require("./context");
|
|
10
10
|
var _warning = require("./warning");
|
|
@@ -72,4 +72,23 @@ var RenderWithEuiTheme = function RenderWithEuiTheme(_ref) {
|
|
|
72
72
|
var theme = useEuiTheme();
|
|
73
73
|
return children(theme);
|
|
74
74
|
};
|
|
75
|
-
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Minor syntactical sugar hook for theme CSS variables.
|
|
78
|
+
* Primarily meant for internal EUI usage.
|
|
79
|
+
*/
|
|
80
|
+
exports.RenderWithEuiTheme = RenderWithEuiTheme;
|
|
81
|
+
var useEuiThemeCSSVariables = function useEuiThemeCSSVariables() {
|
|
82
|
+
var _useContext = (0, _react.useContext)(_context.EuiNestedThemeContext),
|
|
83
|
+
setGlobalCSSVariables = _useContext.setGlobalCSSVariables,
|
|
84
|
+
globalCSSVariables = _useContext.globalCSSVariables,
|
|
85
|
+
setNearestThemeCSSVariables = _useContext.setNearestThemeCSSVariables,
|
|
86
|
+
themeCSSVariables = _useContext.themeCSSVariables;
|
|
87
|
+
return {
|
|
88
|
+
setGlobalCSSVariables: setGlobalCSSVariables,
|
|
89
|
+
globalCSSVariables: globalCSSVariables,
|
|
90
|
+
setNearestThemeCSSVariables: setNearestThemeCSSVariables,
|
|
91
|
+
themeCSSVariables: themeCSSVariables
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
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() {
|
|
@@ -5,14 +5,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.EuiThemeProvider = void 0;
|
|
8
|
-
var _react =
|
|
8
|
+
var _react = require("@emotion/react");
|
|
9
|
+
var _react2 = _interopRequireWildcard(require("react"));
|
|
9
10
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
10
|
-
var
|
|
11
|
+
var _css2 = require("@emotion/css");
|
|
11
12
|
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
|
|
13
|
+
var _emotion = require("../emotion");
|
|
12
14
|
var _context = require("./context");
|
|
13
|
-
var
|
|
15
|
+
var _emotion2 = require("./emotion");
|
|
14
16
|
var _utils = require("./utils");
|
|
15
|
-
var _react2 = require("@emotion/react");
|
|
16
17
|
var _excluded = ["cloneElement", "className"];
|
|
17
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
19
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
@@ -43,35 +44,37 @@ var EuiThemeProvider = function EuiThemeProvider(_ref) {
|
|
|
43
44
|
_modifications = _ref.modify,
|
|
44
45
|
children = _ref.children,
|
|
45
46
|
wrapperProps = _ref.wrapperProps;
|
|
46
|
-
var _useContext = (0,
|
|
47
|
+
var _useContext = (0, _react2.useContext)(_context.EuiNestedThemeContext),
|
|
47
48
|
isGlobalTheme = _useContext.isGlobalTheme,
|
|
48
|
-
bodyColor = _useContext.bodyColor
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
var
|
|
52
|
-
var
|
|
53
|
-
var
|
|
49
|
+
bodyColor = _useContext.bodyColor,
|
|
50
|
+
globalCSSVariables = _useContext.globalCSSVariables,
|
|
51
|
+
setGlobalCSSVariables = _useContext.setGlobalCSSVariables;
|
|
52
|
+
var parentSystem = (0, _react2.useContext)(_context.EuiSystemContext);
|
|
53
|
+
var parentModifications = (0, _react2.useContext)(_context.EuiModificationsContext);
|
|
54
|
+
var parentColorMode = (0, _react2.useContext)(_context.EuiColorModeContext);
|
|
55
|
+
var parentTheme = (0, _react2.useContext)(_context.EuiThemeContext);
|
|
56
|
+
var _useState = (0, _react2.useState)(_system || parentSystem),
|
|
54
57
|
_useState2 = _slicedToArray(_useState, 2),
|
|
55
58
|
system = _useState2[0],
|
|
56
59
|
setSystem = _useState2[1];
|
|
57
|
-
var prevSystemKey = (0,
|
|
58
|
-
var _useState3 = (0,
|
|
60
|
+
var prevSystemKey = (0, _react2.useRef)(system.key);
|
|
61
|
+
var _useState3 = (0, _react2.useState)((0, _utils.mergeDeep)(parentModifications, _modifications)),
|
|
59
62
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
60
63
|
modifications = _useState4[0],
|
|
61
64
|
setModifications = _useState4[1];
|
|
62
|
-
var prevModifications = (0,
|
|
63
|
-
var _useState5 = (0,
|
|
65
|
+
var prevModifications = (0, _react2.useRef)(modifications);
|
|
66
|
+
var _useState5 = (0, _react2.useState)((0, _utils.getColorMode)(_colorMode, parentColorMode)),
|
|
64
67
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
65
68
|
colorMode = _useState6[0],
|
|
66
69
|
setColorMode = _useState6[1];
|
|
67
|
-
var prevColorMode = (0,
|
|
68
|
-
var isParentTheme = (0,
|
|
69
|
-
var _useState7 = (0,
|
|
70
|
+
var prevColorMode = (0, _react2.useRef)(colorMode);
|
|
71
|
+
var isParentTheme = (0, _react2.useRef)(prevSystemKey.current === parentSystem.key && colorMode === parentColorMode && (0, _isEqual.default)(parentModifications, modifications));
|
|
72
|
+
var _useState7 = (0, _react2.useState)(isParentTheme.current && Object.keys(parentTheme).length ? _objectSpread({}, parentTheme) // Intentionally create a new object to break referential equality
|
|
70
73
|
: (0, _utils.getComputed)(system, (0, _utils.buildTheme)(modifications, "_".concat(system.key)), colorMode)),
|
|
71
74
|
_useState8 = _slicedToArray(_useState7, 2),
|
|
72
75
|
theme = _useState8[0],
|
|
73
76
|
setTheme = _useState8[1];
|
|
74
|
-
(0,
|
|
77
|
+
(0, _react2.useEffect)(function () {
|
|
75
78
|
var newSystem = _system || parentSystem;
|
|
76
79
|
if (prevSystemKey.current !== newSystem.key) {
|
|
77
80
|
setSystem(newSystem);
|
|
@@ -79,7 +82,7 @@ var EuiThemeProvider = function EuiThemeProvider(_ref) {
|
|
|
79
82
|
isParentTheme.current = false;
|
|
80
83
|
}
|
|
81
84
|
}, [_system, parentSystem]);
|
|
82
|
-
(0,
|
|
85
|
+
(0, _react2.useEffect)(function () {
|
|
83
86
|
var newModifications = (0, _utils.mergeDeep)(parentModifications, _modifications);
|
|
84
87
|
if (!(0, _isEqual.default)(prevModifications.current, newModifications)) {
|
|
85
88
|
setModifications(newModifications);
|
|
@@ -87,7 +90,7 @@ var EuiThemeProvider = function EuiThemeProvider(_ref) {
|
|
|
87
90
|
isParentTheme.current = false;
|
|
88
91
|
}
|
|
89
92
|
}, [_modifications, parentModifications]);
|
|
90
|
-
(0,
|
|
93
|
+
(0, _react2.useEffect)(function () {
|
|
91
94
|
var newColorMode = (0, _utils.getColorMode)(_colorMode, parentColorMode);
|
|
92
95
|
if (!(0, _isEqual.default)(newColorMode, prevColorMode.current)) {
|
|
93
96
|
setColorMode(newColorMode);
|
|
@@ -95,21 +98,34 @@ var EuiThemeProvider = function EuiThemeProvider(_ref) {
|
|
|
95
98
|
isParentTheme.current = false;
|
|
96
99
|
}
|
|
97
100
|
}, [_colorMode, parentColorMode]);
|
|
98
|
-
(0,
|
|
101
|
+
(0, _react2.useEffect)(function () {
|
|
99
102
|
if (!isParentTheme.current) {
|
|
100
103
|
setTheme((0, _utils.getComputed)(system, (0, _utils.buildTheme)(modifications, "_".concat(system.key)), colorMode));
|
|
101
104
|
}
|
|
102
105
|
}, [colorMode, system, modifications]);
|
|
103
|
-
var
|
|
106
|
+
var _useState9 = (0, _react2.useState)(),
|
|
107
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
108
|
+
themeCSSVariables = _useState10[0],
|
|
109
|
+
_setThemeCSSVariables = _useState10[1];
|
|
110
|
+
var setThemeCSSVariables = (0, _react2.useCallback)(function (variables) {
|
|
111
|
+
return _setThemeCSSVariables(function (previous) {
|
|
112
|
+
return _objectSpread(_objectSpread({}, previous), variables);
|
|
113
|
+
});
|
|
114
|
+
}, []);
|
|
115
|
+
var nestedThemeContext = (0, _react2.useMemo)(function () {
|
|
104
116
|
return {
|
|
105
117
|
isGlobalTheme: false,
|
|
106
118
|
// The theme that determines the global body styles
|
|
107
119
|
bodyColor: isGlobalTheme ? theme.colors.text : bodyColor,
|
|
108
120
|
hasDifferentColorFromGlobalTheme: isGlobalTheme ? false : bodyColor !== theme.colors.text,
|
|
109
|
-
colorClassName: /*#__PURE__*/(0,
|
|
121
|
+
colorClassName: /*#__PURE__*/(0, _css2.css)("label:euiColorMode-", _colorMode, ";color:", theme.colors.text, ";;label:colorClassName;"),
|
|
122
|
+
setGlobalCSSVariables: isGlobalTheme ? setThemeCSSVariables : setGlobalCSSVariables,
|
|
123
|
+
globalCSSVariables: isGlobalTheme ? themeCSSVariables : globalCSSVariables,
|
|
124
|
+
setNearestThemeCSSVariables: setThemeCSSVariables,
|
|
125
|
+
themeCSSVariables: themeCSSVariables
|
|
110
126
|
};
|
|
111
|
-
}, [theme, isGlobalTheme, bodyColor, _colorMode]);
|
|
112
|
-
var renderedChildren = (0,
|
|
127
|
+
}, [theme, isGlobalTheme, bodyColor, _colorMode, setGlobalCSSVariables, globalCSSVariables, setThemeCSSVariables, themeCSSVariables]);
|
|
128
|
+
var renderedChildren = (0, _react2.useMemo)(function () {
|
|
113
129
|
if (isGlobalTheme) {
|
|
114
130
|
return children; // No wrapper
|
|
115
131
|
}
|
|
@@ -121,26 +137,37 @@ var EuiThemeProvider = function EuiThemeProvider(_ref) {
|
|
|
121
137
|
var props = _objectSpread(_objectSpread({}, rest), {}, {
|
|
122
138
|
className: (0, _classnames.default)(className, nestedThemeContext.colorClassName)
|
|
123
139
|
});
|
|
140
|
+
// Condition avoids rendering an empty Emotion selector if no
|
|
141
|
+
// theme-specific CSS variables have been set by child components
|
|
142
|
+
if (themeCSSVariables) {
|
|
143
|
+
props.css = _objectSpread({
|
|
144
|
+
label: 'euiCSSVariables'
|
|
145
|
+
}, themeCSSVariables);
|
|
146
|
+
}
|
|
124
147
|
if (cloneElement) {
|
|
125
|
-
return
|
|
148
|
+
return (0, _emotion.cloneElementWithCss)(children, _objectSpread(_objectSpread({}, props), {}, {
|
|
126
149
|
className: (0, _classnames.default)(children.props.className, props.className)
|
|
127
150
|
}));
|
|
128
151
|
} else {
|
|
129
|
-
return (0,
|
|
152
|
+
return (0, _react.jsx)("span", _extends({}, props, {
|
|
130
153
|
className: (0, _classnames.default)('euiThemeProvider', props.className)
|
|
131
154
|
}), children);
|
|
132
155
|
}
|
|
133
|
-
}, [isGlobalTheme, nestedThemeContext, wrapperProps, children]);
|
|
134
|
-
return (0,
|
|
156
|
+
}, [isGlobalTheme, themeCSSVariables, nestedThemeContext, wrapperProps, children]);
|
|
157
|
+
return (0, _react.jsx)(_react2.default.Fragment, null, isGlobalTheme && themeCSSVariables && (0, _react.jsx)(_react.Global, {
|
|
158
|
+
styles: /*#__PURE__*/(0, _react.css)({
|
|
159
|
+
':root': themeCSSVariables
|
|
160
|
+
}, ";label:EuiThemeProvider;")
|
|
161
|
+
}), (0, _react.jsx)(_context.EuiColorModeContext.Provider, {
|
|
135
162
|
value: colorMode
|
|
136
|
-
}, (0,
|
|
163
|
+
}, (0, _react.jsx)(_context.EuiSystemContext.Provider, {
|
|
137
164
|
value: system
|
|
138
|
-
}, (0,
|
|
165
|
+
}, (0, _react.jsx)(_context.EuiModificationsContext.Provider, {
|
|
139
166
|
value: modifications
|
|
140
|
-
}, (0,
|
|
167
|
+
}, (0, _react.jsx)(_context.EuiThemeContext.Provider, {
|
|
141
168
|
value: theme
|
|
142
|
-
}, (0,
|
|
169
|
+
}, (0, _react.jsx)(_context.EuiNestedThemeContext.Provider, {
|
|
143
170
|
value: nestedThemeContext
|
|
144
|
-
}, (0,
|
|
171
|
+
}, (0, _react.jsx)(_emotion2.EuiEmotionThemeProvider, null, renderedChildren)))))));
|
|
145
172
|
};
|
|
146
173
|
exports.EuiThemeProvider = EuiThemeProvider;
|