@elastic/eui 109.2.0 → 110.0.0-snapshot.1764684698664
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/es/components/basic_table/in_memory_table.js +86 -233
- package/es/components/date_picker/super_date_picker/date_popover/absolute_tab.js +5 -1
- package/es/components/date_picker/super_date_picker/date_popover/relative_tab.js +5 -1
- package/es/components/date_picker/super_date_picker/date_popover/timezone_display.js +3 -1
- package/es/components/date_picker/super_date_picker/quick_select_popover/index.js +1 -0
- package/es/components/date_picker/super_date_picker/time_window_buttons.js +1 -1
- package/es/components/filter_group/filter_group.a11y.js +1 -1
- package/es/components/header/header_logo/header_logo.js +6 -1
- package/es/components/header/header_logo/header_logo.styles.js +1 -1
- package/es/components/icon/icon.styles.js +4 -4
- package/es/components/page/page.js +11 -3
- package/es/components/page/page.styles.js +1 -2
- package/es/components/page/page_header/page_header.js +11 -3
- package/es/components/page_template/outer/page_outer.js +2 -3
- package/es/components/page_template/outer/page_outer.styles.js +29 -35
- package/es/components/page_template/page_template.js +8 -2
- package/es/components/search_bar/search_bar.js +4 -4
- package/es/components/selectable/selectable.js +7 -2
- package/es/services/string/to_initials.js +26 -4
- package/eui.d.ts +38 -21
- package/lib/components/basic_table/in_memory_table.js +85 -234
- package/lib/components/date_picker/super_date_picker/date_popover/absolute_tab.js +5 -1
- package/lib/components/date_picker/super_date_picker/date_popover/relative_tab.js +5 -1
- package/lib/components/date_picker/super_date_picker/date_popover/timezone_display.js +3 -1
- package/lib/components/date_picker/super_date_picker/quick_select_popover/index.js +7 -0
- package/lib/components/date_picker/super_date_picker/time_window_buttons.js +1 -1
- package/lib/components/filter_group/filter_group.a11y.js +1 -1
- package/lib/components/header/header_logo/header_logo.js +6 -1
- package/lib/components/header/header_logo/header_logo.styles.js +1 -1
- package/lib/components/icon/icon.styles.js +4 -4
- package/lib/components/page/page.js +10 -2
- package/lib/components/page/page.styles.js +1 -2
- package/lib/components/page/page_header/page_header.js +10 -2
- package/lib/components/page_template/outer/page_outer.js +1 -2
- package/lib/components/page_template/outer/page_outer.styles.js +29 -35
- package/lib/components/page_template/page_template.js +8 -2
- package/lib/components/search_bar/search_bar.js +4 -4
- package/lib/components/selectable/selectable.js +7 -2
- package/lib/services/string/to_initials.js +26 -4
- package/optimize/es/components/basic_table/in_memory_table.js +73 -46
- package/optimize/es/components/date_picker/super_date_picker/date_popover/absolute_tab.js +5 -1
- package/optimize/es/components/date_picker/super_date_picker/date_popover/relative_tab.js +5 -1
- package/optimize/es/components/date_picker/super_date_picker/date_popover/timezone_display.js +3 -1
- package/optimize/es/components/date_picker/super_date_picker/quick_select_popover/index.js +1 -0
- package/optimize/es/components/date_picker/super_date_picker/time_window_buttons.js +1 -1
- package/optimize/es/components/filter_group/filter_group.a11y.js +1 -1
- package/optimize/es/components/header/header_logo/header_logo.js +6 -1
- package/optimize/es/components/header/header_logo/header_logo.styles.js +1 -1
- package/optimize/es/components/icon/icon.styles.js +4 -4
- package/optimize/es/components/page/page.js +6 -3
- package/optimize/es/components/page/page.styles.js +1 -2
- package/optimize/es/components/page/page_header/page_header.js +6 -3
- package/optimize/es/components/page_template/outer/page_outer.js +2 -3
- package/optimize/es/components/page_template/outer/page_outer.styles.js +29 -35
- package/optimize/es/components/page_template/page_template.js +2 -1
- package/optimize/es/components/selectable/selectable.js +7 -2
- package/optimize/es/services/string/to_initials.js +26 -4
- package/optimize/lib/components/basic_table/in_memory_table.js +72 -47
- package/optimize/lib/components/date_picker/super_date_picker/date_popover/absolute_tab.js +5 -1
- package/optimize/lib/components/date_picker/super_date_picker/date_popover/relative_tab.js +5 -1
- package/optimize/lib/components/date_picker/super_date_picker/date_popover/timezone_display.js +3 -1
- package/optimize/lib/components/date_picker/super_date_picker/quick_select_popover/index.js +7 -0
- package/optimize/lib/components/date_picker/super_date_picker/time_window_buttons.js +1 -1
- package/optimize/lib/components/filter_group/filter_group.a11y.js +1 -1
- package/optimize/lib/components/header/header_logo/header_logo.js +6 -1
- package/optimize/lib/components/header/header_logo/header_logo.styles.js +1 -1
- package/optimize/lib/components/icon/icon.styles.js +4 -4
- package/optimize/lib/components/page/page.js +5 -2
- package/optimize/lib/components/page/page.styles.js +1 -2
- package/optimize/lib/components/page/page_header/page_header.js +5 -2
- package/optimize/lib/components/page_template/outer/page_outer.js +1 -2
- package/optimize/lib/components/page_template/outer/page_outer.styles.js +29 -35
- package/optimize/lib/components/page_template/page_template.js +2 -1
- package/optimize/lib/components/selectable/selectable.js +7 -2
- package/optimize/lib/services/string/to_initials.js +26 -4
- package/package.json +3 -2
- package/test-env/components/basic_table/in_memory_table.js +85 -234
- package/test-env/components/date_picker/super_date_picker/date_popover/absolute_tab.js +5 -1
- package/test-env/components/date_picker/super_date_picker/date_popover/relative_tab.js +5 -1
- package/test-env/components/date_picker/super_date_picker/date_popover/timezone_display.js +3 -1
- package/test-env/components/date_picker/super_date_picker/quick_select_popover/index.js +7 -0
- package/test-env/components/date_picker/super_date_picker/time_window_buttons.js +1 -1
- package/test-env/components/filter_group/filter_group.a11y.js +1 -1
- package/test-env/components/header/header_logo/header_logo.js +6 -1
- package/test-env/components/header/header_logo/header_logo.styles.js +1 -1
- package/test-env/components/icon/icon.styles.js +4 -4
- package/test-env/components/page/page.js +10 -2
- package/test-env/components/page/page.styles.js +1 -2
- package/test-env/components/page/page_header/page_header.js +10 -2
- package/test-env/components/page_template/outer/page_outer.js +1 -2
- package/test-env/components/page_template/outer/page_outer.styles.js +29 -35
- package/test-env/components/page_template/page_template.js +8 -2
- package/test-env/components/search_bar/search_bar.js +4 -4
- package/test-env/components/selectable/selectable.js +7 -2
- package/test-env/services/string/to_initials.js +26 -4
|
@@ -15,7 +15,7 @@ var _global_styling = require("../../global_styling");
|
|
|
15
15
|
var _page = require("./page.styles");
|
|
16
16
|
var _services = require("../../services");
|
|
17
17
|
var _react2 = require("@emotion/react");
|
|
18
|
-
var _excluded = ["children", "restrictWidth", "className", "paddingSize", "grow", "direction"];
|
|
18
|
+
var _excluded = ["children", "restrictWidth", "className", "paddingSize", "grow", "direction", "color"];
|
|
19
19
|
/*
|
|
20
20
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
21
21
|
* or more contributor license agreements. Licensed under the Elastic License
|
|
@@ -34,13 +34,16 @@ var EuiPage = exports.EuiPage = function EuiPage(_ref) {
|
|
|
34
34
|
grow = _ref$grow === void 0 ? true : _ref$grow,
|
|
35
35
|
_ref$direction = _ref.direction,
|
|
36
36
|
direction = _ref$direction === void 0 ? 'row' : _ref$direction,
|
|
37
|
+
_ref$color = _ref.color,
|
|
38
|
+
color = _ref$color === void 0 ? 'transparent' : _ref$color,
|
|
37
39
|
rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
|
|
38
40
|
// Set max-width as a style prop
|
|
39
41
|
var widthStyles = (0, _restrict_width.setStyleForRestrictedPageWidth)(restrictWidth, rest === null || rest === void 0 ? void 0 : rest.style);
|
|
40
42
|
var euiTheme = (0, _services.useEuiTheme)();
|
|
41
43
|
var styles = (0, _page.euiPageStyles)(euiTheme);
|
|
42
44
|
var padding = (0, _global_styling.useEuiPaddingCSS)()[paddingSize];
|
|
43
|
-
var
|
|
45
|
+
var backgroundColor = (0, _global_styling.useEuiBackgroundColorCSS)()[color];
|
|
46
|
+
var stylesCSS = [styles.euiPage, styles[direction], backgroundColor, grow && styles.grow, padding, restrictWidth && styles.restrictWidth];
|
|
44
47
|
var classes = (0, _classnames.default)('euiPage', className);
|
|
45
48
|
return (0, _react2.jsx)("div", (0, _extends2.default)({
|
|
46
49
|
css: stylesCSS,
|
|
@@ -65,6 +68,11 @@ EuiPage.propTypes = {
|
|
|
65
68
|
* Flip to `column` when not including a sidebar.
|
|
66
69
|
*/
|
|
67
70
|
direction: _propTypes.default.oneOf(["row", "column"]),
|
|
71
|
+
/**
|
|
72
|
+
* Defines the page background color.
|
|
73
|
+
* @default 'transparent'
|
|
74
|
+
*/
|
|
75
|
+
color: _propTypes.default.oneOf(["plain", "transparent"]),
|
|
68
76
|
className: _propTypes.default.string,
|
|
69
77
|
"aria-label": _propTypes.default.string,
|
|
70
78
|
"data-test-subj": _propTypes.default.string,
|
|
@@ -30,9 +30,8 @@ var _ref2 = process.env.NODE_ENV === "production" ? {
|
|
|
30
30
|
toString: _EMOTION_STRINGIFIED_CSS_ERROR__
|
|
31
31
|
};
|
|
32
32
|
var euiPageStyles = exports.euiPageStyles = function euiPageStyles(euiThemeContext) {
|
|
33
|
-
var euiTheme = euiThemeContext.euiTheme;
|
|
34
33
|
return {
|
|
35
|
-
euiPage: /*#__PURE__*/(0, _react.css)("display:flex;
|
|
34
|
+
euiPage: /*#__PURE__*/(0, _react.css)("display:flex;flex-shrink:0;", (0, _global_styling.logicalCSS)('max-width', '100%'), ";;label:euiPage;"),
|
|
36
35
|
// Grow
|
|
37
36
|
grow: _ref2,
|
|
38
37
|
// Direction
|
|
@@ -15,7 +15,7 @@ var _global_styling = require("../../../global_styling");
|
|
|
15
15
|
var _page_header_content = require("./page_header_content");
|
|
16
16
|
var _page_header = require("./page_header.styles");
|
|
17
17
|
var _react2 = require("@emotion/react");
|
|
18
|
-
var _excluded = ["className", "restrictWidth", "paddingSize", "bottomBorder", "alignItems", "responsive", "children", "pageTitle", "pageTitleProps", "iconType", "iconProps", "tabs", "tabsProps", "breadcrumbs", "breadcrumbProps", "description", "rightSideItems", "rightSideGroupProps"];
|
|
18
|
+
var _excluded = ["className", "restrictWidth", "paddingSize", "bottomBorder", "color", "alignItems", "responsive", "children", "pageTitle", "pageTitleProps", "iconType", "iconProps", "tabs", "tabsProps", "breadcrumbs", "breadcrumbProps", "description", "rightSideItems", "rightSideGroupProps"];
|
|
19
19
|
/*
|
|
20
20
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
21
21
|
* or more contributor license agreements. Licensed under the Elastic License
|
|
@@ -30,6 +30,8 @@ var EuiPageHeader = exports.EuiPageHeader = function EuiPageHeader(_ref) {
|
|
|
30
30
|
_ref$paddingSize = _ref.paddingSize,
|
|
31
31
|
paddingSize = _ref$paddingSize === void 0 ? 'none' : _ref$paddingSize,
|
|
32
32
|
bottomBorder = _ref.bottomBorder,
|
|
33
|
+
_ref$color = _ref.color,
|
|
34
|
+
color = _ref$color === void 0 ? 'transparent' : _ref$color,
|
|
33
35
|
alignItems = _ref.alignItems,
|
|
34
36
|
_ref$responsive = _ref.responsive,
|
|
35
37
|
responsive = _ref$responsive === void 0 ? true : _ref$responsive,
|
|
@@ -49,7 +51,8 @@ var EuiPageHeader = exports.EuiPageHeader = function EuiPageHeader(_ref) {
|
|
|
49
51
|
var useTheme = (0, _services.useEuiTheme)();
|
|
50
52
|
var styles = (0, _page_header.euiPageHeaderStyles)(useTheme);
|
|
51
53
|
var inlinePadding = (0, _global_styling.useEuiPaddingCSS)('horizontal');
|
|
52
|
-
var
|
|
54
|
+
var backgroundColor = (0, _global_styling.useEuiBackgroundColorCSS)()[color];
|
|
55
|
+
var cssStyles = [styles.euiPageHeader, inlinePadding[paddingSize], bottomBorder === 'extended' && styles.border, backgroundColor];
|
|
53
56
|
var classes = (0, _classnames.default)('euiPageHeader', className);
|
|
54
57
|
var contentProps = {
|
|
55
58
|
restrictWidth: restrictWidth,
|
|
@@ -81,6 +84,11 @@ EuiPageHeader.propTypes = {
|
|
|
81
84
|
* Adjust the overall padding.
|
|
82
85
|
*/
|
|
83
86
|
paddingSize: _propTypes.default.any,
|
|
87
|
+
/**
|
|
88
|
+
* Define the header background color
|
|
89
|
+
* @default 'transparent'
|
|
90
|
+
*/
|
|
91
|
+
color: _propTypes.default.oneOf(["plain", "transparent"]),
|
|
84
92
|
className: _propTypes.default.string,
|
|
85
93
|
"aria-label": _propTypes.default.string,
|
|
86
94
|
"data-test-subj": _propTypes.default.string,
|
|
@@ -30,8 +30,7 @@ var _EuiPageOuter = exports._EuiPageOuter = function _EuiPageOuter(_ref) {
|
|
|
30
30
|
_ref$responsive = _ref.responsive,
|
|
31
31
|
responsive = _ref$responsive === void 0 ? ['xs', 's'] : _ref$responsive,
|
|
32
32
|
rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
|
|
33
|
-
var
|
|
34
|
-
var styles = (0, _page_outer.euiPageOuterStyles)(themeContext);
|
|
33
|
+
var styles = _page_outer.euiPageOuterStyles;
|
|
35
34
|
var isResponding = (0, _services.useIsWithinBreakpoints)(responsive);
|
|
36
35
|
var cssStyles = [styles.euiPageOuter, styles[isResponding ? 'column' : direction], grow && styles.grow];
|
|
37
36
|
return (0, _react2.jsx)("div", (0, _extends2.default)({
|
|
@@ -13,39 +13,33 @@ function _EMOTION_STRINGIFIED_CSS_ERROR__() { return "You have tried to stringif
|
|
|
13
13
|
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
|
14
14
|
* Side Public License, v 1.
|
|
15
15
|
*/
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
// Grow
|
|
46
|
-
grow: _ref3,
|
|
47
|
-
// Direction
|
|
48
|
-
column: _ref2,
|
|
49
|
-
row: _ref
|
|
50
|
-
};
|
|
16
|
+
var euiPageOuterStyles = exports.euiPageOuterStyles = {
|
|
17
|
+
euiPageOuter: /*#__PURE__*/(0, _react.css)("display:flex;flex-shrink:0;", (0, _global_styling.logicalCSS)('max-width', '100%' // Ensures Firefox doesn't expand width beyond bounds
|
|
18
|
+
), ";;label:euiPageOuter;"),
|
|
19
|
+
// Grow
|
|
20
|
+
grow: process.env.NODE_ENV === "production" ? {
|
|
21
|
+
name: "122lw0e-grow",
|
|
22
|
+
styles: "flex-grow:1;label:grow;"
|
|
23
|
+
} : {
|
|
24
|
+
name: "122lw0e-grow",
|
|
25
|
+
styles: "flex-grow:1;label:grow;",
|
|
26
|
+
toString: _EMOTION_STRINGIFIED_CSS_ERROR__
|
|
27
|
+
},
|
|
28
|
+
// Direction
|
|
29
|
+
column: process.env.NODE_ENV === "production" ? {
|
|
30
|
+
name: "ll8kmq-column",
|
|
31
|
+
styles: "flex-direction:column;label:column;"
|
|
32
|
+
} : {
|
|
33
|
+
name: "ll8kmq-column",
|
|
34
|
+
styles: "flex-direction:column;label:column;",
|
|
35
|
+
toString: _EMOTION_STRINGIFIED_CSS_ERROR__
|
|
36
|
+
},
|
|
37
|
+
row: process.env.NODE_ENV === "production" ? {
|
|
38
|
+
name: "15mvjmo-row",
|
|
39
|
+
styles: "flex-direction:row;label:row;"
|
|
40
|
+
} : {
|
|
41
|
+
name: "15mvjmo-row",
|
|
42
|
+
styles: "flex-direction:row;label:row;",
|
|
43
|
+
toString: _EMOTION_STRINGIFIED_CSS_ERROR__
|
|
44
|
+
}
|
|
51
45
|
};
|
|
@@ -108,7 +108,8 @@ var _EuiPageTemplate = exports._EuiPageTemplate = function _EuiPageTemplate(_ref
|
|
|
108
108
|
header: {
|
|
109
109
|
restrictWidth: restrictWidth,
|
|
110
110
|
paddingSize: paddingSize,
|
|
111
|
-
bottomBorder: headerBottomBorder
|
|
111
|
+
bottomBorder: headerBottomBorder,
|
|
112
|
+
color: panelled === false ? 'transparent' : 'plain'
|
|
112
113
|
},
|
|
113
114
|
section: {
|
|
114
115
|
restrictWidth: restrictWidth,
|
|
@@ -165,7 +166,7 @@ _EuiPageTemplate.propTypes = {
|
|
|
165
166
|
"data-test-subj": _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.string]),
|
|
166
167
|
css: _propTypes.default.oneOfType([_propTypes.default.any, _propTypes.default.any]),
|
|
167
168
|
/**
|
|
168
|
-
* Adds a
|
|
169
|
+
* Adds a background and shadow to define the area.
|
|
169
170
|
*/
|
|
170
171
|
panelled: _propTypes.default.bool,
|
|
171
172
|
/**
|
|
@@ -313,6 +314,11 @@ _EuiPageHeader.propTypes = {
|
|
|
313
314
|
* Adjust the overall padding.
|
|
314
315
|
*/
|
|
315
316
|
paddingSize: _propTypes.default.any,
|
|
317
|
+
/**
|
|
318
|
+
* Define the header background color
|
|
319
|
+
* @default 'transparent'
|
|
320
|
+
*/
|
|
321
|
+
color: _propTypes.default.oneOf(["plain", "transparent"]),
|
|
316
322
|
className: _propTypes.default.string,
|
|
317
323
|
"aria-label": _propTypes.default.string,
|
|
318
324
|
"data-test-subj": _propTypes.default.string,
|
|
@@ -255,15 +255,15 @@ var EuiSearchBar = exports.EuiSearchBar = /*#__PURE__*/function (_Component) {
|
|
|
255
255
|
EuiSearchBar.propTypes = {
|
|
256
256
|
onChange: _propTypes.default.func,
|
|
257
257
|
/**
|
|
258
|
-
The initial query the bar will hold when first mounted
|
|
258
|
+
* The initial query the bar will hold when first mounted
|
|
259
259
|
*/
|
|
260
260
|
defaultQuery: _propTypes.default.oneOfType([_propTypes.default.any.isRequired, _propTypes.default.string.isRequired]),
|
|
261
261
|
/**
|
|
262
|
-
If you wish to use the search bar as a controlled component, continuously pass the query via this prop.
|
|
262
|
+
* If you wish to use the search bar as a controlled component, continuously pass the query via this prop.
|
|
263
263
|
*/
|
|
264
264
|
query: _propTypes.default.oneOfType([_propTypes.default.any.isRequired, _propTypes.default.string.isRequired]),
|
|
265
265
|
/**
|
|
266
|
-
Configures the search box. Set `placeholder` to change the placeholder text in the box and `incremental` to support incremental (as you type) search.
|
|
266
|
+
* Configures the search box. Set `placeholder` to change the placeholder text in the box and `incremental` to support incremental (as you type) search.
|
|
267
267
|
*/
|
|
268
268
|
box: _propTypes.default.shape({
|
|
269
269
|
name: _propTypes.default.string,
|
|
@@ -323,7 +323,7 @@ EuiSearchBar.propTypes = {
|
|
|
323
323
|
}).isRequired, _propTypes.default.bool.isRequired])
|
|
324
324
|
}),
|
|
325
325
|
/**
|
|
326
|
-
An array of search filters. See {@link SearchFilterConfig}.
|
|
326
|
+
* An array of search filters. See {@link SearchFilterConfig}.
|
|
327
327
|
*/
|
|
328
328
|
filters: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.shape({
|
|
329
329
|
type: _propTypes.default.oneOf(["is"]).isRequired,
|
|
@@ -85,6 +85,12 @@ var EuiSelectable = exports.EuiSelectable = /*#__PURE__*/function (_Component) {
|
|
|
85
85
|
_this.preventOnFocus = false;
|
|
86
86
|
return;
|
|
87
87
|
}
|
|
88
|
+
if (event && _this.props.searchable && event.target === _this.inputRef) {
|
|
89
|
+
_this.setState({
|
|
90
|
+
isFocused: true
|
|
91
|
+
});
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
88
94
|
if (!_this.state.visibleOptions.length || _this.state.activeOptionIndex != null) {
|
|
89
95
|
return;
|
|
90
96
|
}
|
|
@@ -460,8 +466,7 @@ var EuiSelectable = exports.EuiSelectable = /*#__PURE__*/function (_Component) {
|
|
|
460
466
|
onChange: _this2.onSearchChange,
|
|
461
467
|
listId: _this2.optionsListRef.current ? _this2.listId : undefined // Only pass the listId if it exists on the page
|
|
462
468
|
,
|
|
463
|
-
"aria-activedescendant": _this2.makeOptionId(activeOptionIndex)
|
|
464
|
-
,
|
|
469
|
+
"aria-activedescendant": activeOptionIndex != null ? _this2.makeOptionId(activeOptionIndex) : undefined,
|
|
465
470
|
placeholder: placeholderName,
|
|
466
471
|
isPreFiltered: !!isPreFiltered,
|
|
467
472
|
optionMatcher: optionMatcher,
|
|
@@ -13,6 +13,8 @@ exports.toInitials = toInitials;
|
|
|
13
13
|
* Side Public License, v 1.
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
+
var MAX_INITIALS = exports.MAX_INITIALS = 2;
|
|
17
|
+
|
|
16
18
|
/**
|
|
17
19
|
* This function calculates the initials/acronym for a given name.
|
|
18
20
|
* It defaults to only 2 characters and will take the first character (of each word).
|
|
@@ -24,11 +26,20 @@ exports.toInitials = toInitials;
|
|
|
24
26
|
* @param {string} name The full name of the item to turn into initials
|
|
25
27
|
* @param {number} initialsLength (Optional) How many characters to show (max 2 allowed)
|
|
26
28
|
* @param {string} initials (Optional) Custom initials (max 2 characters)
|
|
27
|
-
* @returns {string} True if the color is dark, false otherwise.
|
|
28
29
|
*/
|
|
29
|
-
|
|
30
|
-
var MAX_INITIALS = exports.MAX_INITIALS = 2;
|
|
31
30
|
function toInitials(name, initialsLength, initials) {
|
|
31
|
+
// If `initials` provided, check if it's a single emoji
|
|
32
|
+
// in order to support complex, "multi-character" ones
|
|
33
|
+
if (initials && typeof Intl !== 'undefined' && 'Segmenter' in Intl) {
|
|
34
|
+
var segmenter = new Intl.Segmenter('en', {
|
|
35
|
+
granularity: 'grapheme'
|
|
36
|
+
});
|
|
37
|
+
var segments = Array.from(segmenter.segment(initials));
|
|
38
|
+
if (segments.length === 1 && isEmoji(segments[0].segment)) {
|
|
39
|
+
return segments[0].segment;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
32
43
|
// Calculate the number of initials to show, maxing out at MAX_INITIALS
|
|
33
44
|
var calculatedInitialsLength = initials ? initials.split('').length : name.split(' ').length;
|
|
34
45
|
calculatedInitialsLength = calculatedInitialsLength > MAX_INITIALS ? MAX_INITIALS : calculatedInitialsLength;
|
|
@@ -51,5 +62,16 @@ function toInitials(name, initialsLength, initials) {
|
|
|
51
62
|
calculatedInitials = name.substring(0, calculatedInitialsLength);
|
|
52
63
|
}
|
|
53
64
|
}
|
|
54
|
-
return calculatedInitials;
|
|
65
|
+
return calculatedInitials || '';
|
|
66
|
+
}
|
|
67
|
+
function isEmoji(str) {
|
|
68
|
+
/**
|
|
69
|
+
* The \p escape sequence allows matching a character based on its Unicode properties
|
|
70
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Unicode_character_class_escape
|
|
71
|
+
* @see https://www.unicode.org/Public/UCD/latest/ucd/emoji/emoji-data.txt
|
|
72
|
+
* @see https://www.unicode.org/reports/tr51/#Definitions
|
|
73
|
+
* @see https://util.unicode.org/UnicodeJsps/character.jsp?a=1F440&B1=Show
|
|
74
|
+
*/
|
|
75
|
+
var emojiRegex = /(?:[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u2388\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2605\u2607-\u2612\u2614-\u2685\u2690-\u2705\u2708-\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763-\u2767\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC00-\uDCFF\uDD0D-\uDD0F\uDD2F\uDD6C-\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDAD-\uDDFF\uDE01-\uDE0F\uDE1A\uDE2F\uDE32-\uDE3A\uDE3C-\uDE3F\uDE49-\uDFFF]|\uD83D[\uDC00-\uDD3D\uDD46-\uDE4F\uDE80-\uDEFF\uDF74-\uDF7F\uDFD5-\uDFFF]|\uD83E[\uDC0C-\uDC0F\uDC48-\uDC4F\uDC5A-\uDC5F\uDC88-\uDC8F\uDCAE-\uDCFF\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDEFF]|\uD83F[\uDC00-\uDFFD])/;
|
|
76
|
+
return emojiRegex.test(str);
|
|
55
77
|
}
|