@widergy/energy-ui 3.161.0 → 3.162.1
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/CHANGELOG.md +25 -2
- package/dist/components/UTBanner/README.md +41 -8
- package/dist/components/UTBanner/constants.js +36 -0
- package/dist/components/UTBanner/index.js +118 -15
- package/dist/components/UTBanner/stories/UTBanner.stories.js +164 -0
- package/dist/components/UTBanner/styles.module.scss +149 -5
- package/dist/components/UTBanner/types.js +20 -0
- package/dist/components/UTBanner/utils.js +148 -0
- package/dist/components/UTGraph/index.js +1 -1
- package/dist/components/UTHeader/index.js +3 -2
- package/dist/components/UTIcon/components/FlagsIcons/flagsComponents/index.js +61 -0
- package/dist/components/UTIcon/theme.js +5 -3
- package/dist/constants/testIds.js +2 -0
- package/dist/esm/components/UTBanner/README.md +41 -8
- package/dist/esm/components/UTBanner/constants.js +30 -0
- package/dist/esm/components/UTBanner/index.js +120 -16
- package/dist/esm/components/UTBanner/stories/UTBanner.stories.js +157 -0
- package/dist/esm/components/UTBanner/styles.module.scss +149 -5
- package/dist/esm/components/UTBanner/types.js +14 -0
- package/dist/esm/components/UTBanner/utils.js +137 -0
- package/dist/esm/components/UTGraph/index.js +2 -2
- package/dist/esm/components/UTHeader/index.js +3 -2
- package/dist/esm/components/UTIcon/components/FlagsIcons/flagsComponents/index.js +54 -0
- package/dist/esm/components/UTIcon/theme.js +4 -2
- package/dist/esm/constants/testIds.js +2 -0
- package/dist/esm/index.js +2 -1
- package/dist/esm/utils/hooks/useCSSVariables/constants.js +13 -0
- package/dist/index.js +7 -0
- package/dist/utils/hooks/useCSSVariables/constants.js +13 -0
- package/package.json +1 -1
- package/dist/components/UTBanner/theme.js +0 -18
- package/dist/esm/components/UTBanner/theme.js +0 -11
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getSecondaryLabelColorTheme = exports.getLabelStyles = exports.getLabelColorTheme = exports.getDefaultIconTheme = exports.getDefaultIconSize = exports.getDefaultButtonColorTheme = void 0;
|
|
7
|
+
var _constants = require("./constants");
|
|
8
|
+
/**
|
|
9
|
+
* Returns the default UTIcon colorTheme and shade for the banner icon based on the
|
|
10
|
+
* banner's colorTheme and variant. Matches the mobile implementation.
|
|
11
|
+
* @param {string} colorTheme - Banner color theme.
|
|
12
|
+
* @param {string} variant - Banner variant ('light' | 'dark').
|
|
13
|
+
* @returns {{ colorTheme: string, shade: string }}
|
|
14
|
+
*/
|
|
15
|
+
const getDefaultIconTheme = (colorTheme, variant) => {
|
|
16
|
+
var _COLOR_THEMES$ERROR$C;
|
|
17
|
+
if (variant === _constants.VARIANTS.DARK) {
|
|
18
|
+
return colorTheme === _constants.COLOR_THEMES.NEGATIVE ? {
|
|
19
|
+
colorTheme: 'dark',
|
|
20
|
+
shade: '05'
|
|
21
|
+
} : {
|
|
22
|
+
colorTheme: 'light',
|
|
23
|
+
shade: '01'
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return (_COLOR_THEMES$ERROR$C = {
|
|
27
|
+
[_constants.COLOR_THEMES.ERROR]: {
|
|
28
|
+
colorTheme: 'error',
|
|
29
|
+
shade: '04'
|
|
30
|
+
},
|
|
31
|
+
[_constants.COLOR_THEMES.GRAY]: {
|
|
32
|
+
colorTheme: 'accent',
|
|
33
|
+
shade: '04'
|
|
34
|
+
},
|
|
35
|
+
[_constants.COLOR_THEMES.INFORMATION]: {
|
|
36
|
+
colorTheme: 'information',
|
|
37
|
+
shade: '04'
|
|
38
|
+
},
|
|
39
|
+
[_constants.COLOR_THEMES.NEGATIVE]: {
|
|
40
|
+
colorTheme: 'light',
|
|
41
|
+
shade: '01'
|
|
42
|
+
},
|
|
43
|
+
[_constants.COLOR_THEMES.PRIMARY]: {
|
|
44
|
+
colorTheme: 'accent',
|
|
45
|
+
shade: '04'
|
|
46
|
+
},
|
|
47
|
+
[_constants.COLOR_THEMES.SUCCESS]: {
|
|
48
|
+
colorTheme: 'success',
|
|
49
|
+
shade: '04'
|
|
50
|
+
},
|
|
51
|
+
[_constants.COLOR_THEMES.WARNING]: {
|
|
52
|
+
colorTheme: 'warning',
|
|
53
|
+
shade: '04'
|
|
54
|
+
},
|
|
55
|
+
[_constants.COLOR_THEMES.WHITE]: {
|
|
56
|
+
colorTheme: 'accent',
|
|
57
|
+
shade: '04'
|
|
58
|
+
}
|
|
59
|
+
}[colorTheme]) !== null && _COLOR_THEMES$ERROR$C !== void 0 ? _COLOR_THEMES$ERROR$C : {
|
|
60
|
+
colorTheme: 'accent',
|
|
61
|
+
shade: '04'
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Returns the default icon size in pixels based on the banner size.
|
|
67
|
+
* @param {string} size - One of SIZES values.
|
|
68
|
+
* @returns {number}
|
|
69
|
+
*/
|
|
70
|
+
exports.getDefaultIconTheme = getDefaultIconTheme;
|
|
71
|
+
const getDefaultIconSize = size => size === _constants.SIZES.LARGE ? 24 : 20;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Returns the default colorTheme for buttons and the close button based on the
|
|
75
|
+
* banner variant. Dark variant uses 'negative'; light variant uses standard colors.
|
|
76
|
+
* @param {string} variant - Banner variant ('light' | 'dark').
|
|
77
|
+
* @returns {{ button: string, onClose: string, secondaryButton: string }}
|
|
78
|
+
*/
|
|
79
|
+
exports.getDefaultIconSize = getDefaultIconSize;
|
|
80
|
+
const getDefaultButtonColorTheme = variant => {
|
|
81
|
+
const isDark = variant === _constants.VARIANTS.DARK;
|
|
82
|
+
return {
|
|
83
|
+
button: isDark ? 'negative' : 'secondary',
|
|
84
|
+
onClose: isDark ? 'negative' : 'gray',
|
|
85
|
+
secondaryButton: isDark ? 'negative' : 'secondary'
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Returns the UTLabel variant and weight for the main text (children) based on
|
|
91
|
+
* the banner size.
|
|
92
|
+
* @param {string} size - One of SIZES values.
|
|
93
|
+
* @returns {{ variant: string, weight: string }}
|
|
94
|
+
*/
|
|
95
|
+
exports.getDefaultButtonColorTheme = getDefaultButtonColorTheme;
|
|
96
|
+
const getLabelStyles = size => {
|
|
97
|
+
var _SIZES$LARGE$SIZES$ME;
|
|
98
|
+
return (_SIZES$LARGE$SIZES$ME = {
|
|
99
|
+
[_constants.SIZES.LARGE]: {
|
|
100
|
+
titleVariant: 'title3',
|
|
101
|
+
descriptionVariant: 'body'
|
|
102
|
+
},
|
|
103
|
+
[_constants.SIZES.MEDIUM]: {
|
|
104
|
+
titleVariant: 'subtitle1',
|
|
105
|
+
descriptionVariant: 'small'
|
|
106
|
+
},
|
|
107
|
+
[_constants.SIZES.SMALL]: {
|
|
108
|
+
titleVariant: 'small',
|
|
109
|
+
descriptionVariant: 'small'
|
|
110
|
+
}
|
|
111
|
+
}[size]) !== null && _SIZES$LARGE$SIZES$ME !== void 0 ? _SIZES$LARGE$SIZES$ME : {
|
|
112
|
+
titleVariant: 'small',
|
|
113
|
+
descriptionVariant: 'small'
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Returns the UTLabel colorTheme for the banner's main text content based on the
|
|
119
|
+
* banner's colorTheme and variant. Negative+light and any dark variant use light
|
|
120
|
+
* (white) text; all other combinations use dark text.
|
|
121
|
+
* @param {string} colorTheme - Banner color theme.
|
|
122
|
+
* @param {string} variant - Banner variant ('light' | 'dark').
|
|
123
|
+
* @returns {string} UTLabel colorTheme value.
|
|
124
|
+
*/
|
|
125
|
+
exports.getLabelStyles = getLabelStyles;
|
|
126
|
+
const getLabelColorTheme = (colorTheme, variant) => {
|
|
127
|
+
if (colorTheme === _constants.COLOR_THEMES.NEGATIVE) {
|
|
128
|
+
return variant === _constants.VARIANTS.LIGHT ? 'light' : 'dark';
|
|
129
|
+
}
|
|
130
|
+
return variant === _constants.VARIANTS.LIGHT ? 'dark' : 'light';
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Returns the UTLabel colorTheme for the banner's secondary text content based on the
|
|
135
|
+
* banner's colorTheme and variant. Negative+light and any dark variant use light
|
|
136
|
+
* (white) text; all other combinations use gray text.
|
|
137
|
+
* @param {string} colorTheme - Banner color theme.
|
|
138
|
+
* @param {string} variant - Banner variant ('light' | 'gray').
|
|
139
|
+
* @returns {string} UTLabel colorTheme value.
|
|
140
|
+
*/
|
|
141
|
+
exports.getLabelColorTheme = getLabelColorTheme;
|
|
142
|
+
const getSecondaryLabelColorTheme = (colorTheme, variant) => {
|
|
143
|
+
if (colorTheme === _constants.COLOR_THEMES.NEGATIVE) {
|
|
144
|
+
return variant === _constants.VARIANTS.LIGHT ? 'light' : 'gray';
|
|
145
|
+
}
|
|
146
|
+
return variant === _constants.VARIANTS.LIGHT ? 'gray' : 'light';
|
|
147
|
+
};
|
|
148
|
+
exports.getSecondaryLabelColorTheme = getSecondaryLabelColorTheme;
|
|
@@ -176,7 +176,7 @@ const UTGraph = _ref => {
|
|
|
176
176
|
crossAxisLeft,
|
|
177
177
|
crossAxisRight
|
|
178
178
|
} = _ref2;
|
|
179
|
-
return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement(_Bars.default, {
|
|
179
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_Bars.default, {
|
|
180
180
|
crossAxisLeft: crossAxisLeft,
|
|
181
181
|
crossAxisRight: crossAxisRight,
|
|
182
182
|
dataset: dataset,
|
|
@@ -154,8 +154,9 @@ const UTHeader = _ref => {
|
|
|
154
154
|
height: BANNER_ICON_SIZE,
|
|
155
155
|
width: BANNER_ICON_SIZE
|
|
156
156
|
},
|
|
157
|
-
Icon: banner.Icon
|
|
158
|
-
|
|
157
|
+
Icon: banner.Icon,
|
|
158
|
+
title: banner.text
|
|
159
|
+
})));
|
|
159
160
|
};
|
|
160
161
|
UTHeader.propTypes = {
|
|
161
162
|
actions: (0, _propTypes.arrayOf)(_propTypes.object),
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
8
|
+
const flagComponentMap = {
|
|
9
|
+
AG: () => Promise.resolve().then(() => _interopRequireWildcard(require('./AG'))),
|
|
10
|
+
AI: () => Promise.resolve().then(() => _interopRequireWildcard(require('./AI'))),
|
|
11
|
+
AR: () => Promise.resolve().then(() => _interopRequireWildcard(require('./AR'))),
|
|
12
|
+
AW: () => Promise.resolve().then(() => _interopRequireWildcard(require('./AW'))),
|
|
13
|
+
BB: () => Promise.resolve().then(() => _interopRequireWildcard(require('./BB'))),
|
|
14
|
+
BL: () => Promise.resolve().then(() => _interopRequireWildcard(require('./BL'))),
|
|
15
|
+
BM: () => Promise.resolve().then(() => _interopRequireWildcard(require('./BM'))),
|
|
16
|
+
BO: () => Promise.resolve().then(() => _interopRequireWildcard(require('./BO'))),
|
|
17
|
+
BR: () => Promise.resolve().then(() => _interopRequireWildcard(require('./BR'))),
|
|
18
|
+
BS: () => Promise.resolve().then(() => _interopRequireWildcard(require('./BS'))),
|
|
19
|
+
BZ: () => Promise.resolve().then(() => _interopRequireWildcard(require('./BZ'))),
|
|
20
|
+
CA: () => Promise.resolve().then(() => _interopRequireWildcard(require('./CA'))),
|
|
21
|
+
CL: () => Promise.resolve().then(() => _interopRequireWildcard(require('./CL'))),
|
|
22
|
+
CO: () => Promise.resolve().then(() => _interopRequireWildcard(require('./CO'))),
|
|
23
|
+
CR: () => Promise.resolve().then(() => _interopRequireWildcard(require('./CR'))),
|
|
24
|
+
CU: () => Promise.resolve().then(() => _interopRequireWildcard(require('./CU'))),
|
|
25
|
+
CW: () => Promise.resolve().then(() => _interopRequireWildcard(require('./CW'))),
|
|
26
|
+
DM: () => Promise.resolve().then(() => _interopRequireWildcard(require('./DM'))),
|
|
27
|
+
DO: () => Promise.resolve().then(() => _interopRequireWildcard(require('./DO'))),
|
|
28
|
+
EC: () => Promise.resolve().then(() => _interopRequireWildcard(require('./EC'))),
|
|
29
|
+
ES: () => Promise.resolve().then(() => _interopRequireWildcard(require('./ES'))),
|
|
30
|
+
GD: () => Promise.resolve().then(() => _interopRequireWildcard(require('./GD'))),
|
|
31
|
+
GF: () => Promise.resolve().then(() => _interopRequireWildcard(require('./GF'))),
|
|
32
|
+
GL: () => Promise.resolve().then(() => _interopRequireWildcard(require('./GL'))),
|
|
33
|
+
GP: () => Promise.resolve().then(() => _interopRequireWildcard(require('./GP'))),
|
|
34
|
+
GT: () => Promise.resolve().then(() => _interopRequireWildcard(require('./GT'))),
|
|
35
|
+
GY: () => Promise.resolve().then(() => _interopRequireWildcard(require('./GY'))),
|
|
36
|
+
HN: () => Promise.resolve().then(() => _interopRequireWildcard(require('./HN'))),
|
|
37
|
+
HT: () => Promise.resolve().then(() => _interopRequireWildcard(require('./HT'))),
|
|
38
|
+
JM: () => Promise.resolve().then(() => _interopRequireWildcard(require('./JM'))),
|
|
39
|
+
LC: () => Promise.resolve().then(() => _interopRequireWildcard(require('./LC'))),
|
|
40
|
+
MF: () => Promise.resolve().then(() => _interopRequireWildcard(require('./MF'))),
|
|
41
|
+
MQ: () => Promise.resolve().then(() => _interopRequireWildcard(require('./MQ'))),
|
|
42
|
+
MS: () => Promise.resolve().then(() => _interopRequireWildcard(require('./MS'))),
|
|
43
|
+
MX: () => Promise.resolve().then(() => _interopRequireWildcard(require('./MX'))),
|
|
44
|
+
NI: () => Promise.resolve().then(() => _interopRequireWildcard(require('./NI'))),
|
|
45
|
+
PA: () => Promise.resolve().then(() => _interopRequireWildcard(require('./PA'))),
|
|
46
|
+
PE: () => Promise.resolve().then(() => _interopRequireWildcard(require('./PE'))),
|
|
47
|
+
PM: () => Promise.resolve().then(() => _interopRequireWildcard(require('./PM'))),
|
|
48
|
+
PR: () => Promise.resolve().then(() => _interopRequireWildcard(require('./PR'))),
|
|
49
|
+
PY: () => Promise.resolve().then(() => _interopRequireWildcard(require('./PY'))),
|
|
50
|
+
SR: () => Promise.resolve().then(() => _interopRequireWildcard(require('./SR'))),
|
|
51
|
+
SV: () => Promise.resolve().then(() => _interopRequireWildcard(require('./SV'))),
|
|
52
|
+
TC: () => Promise.resolve().then(() => _interopRequireWildcard(require('./TC'))),
|
|
53
|
+
TT: () => Promise.resolve().then(() => _interopRequireWildcard(require('./TT'))),
|
|
54
|
+
US: () => Promise.resolve().then(() => _interopRequireWildcard(require('./US'))),
|
|
55
|
+
UY: () => Promise.resolve().then(() => _interopRequireWildcard(require('./UY'))),
|
|
56
|
+
VC: () => Promise.resolve().then(() => _interopRequireWildcard(require('./VC'))),
|
|
57
|
+
VE: () => Promise.resolve().then(() => _interopRequireWildcard(require('./VE'))),
|
|
58
|
+
VG: () => Promise.resolve().then(() => _interopRequireWildcard(require('./VG'))),
|
|
59
|
+
VI: () => Promise.resolve().then(() => _interopRequireWildcard(require('./VI')))
|
|
60
|
+
};
|
|
61
|
+
var _default = exports.default = flagComponentMap;
|
|
@@ -10,8 +10,9 @@ var _componentUtils = require("../../utils/componentUtils");
|
|
|
10
10
|
var _countries = _interopRequireDefault(require("../../constants/countries"));
|
|
11
11
|
var _constants = require("./constants");
|
|
12
12
|
var _stylesModule = _interopRequireDefault(require("./styles.module.scss"));
|
|
13
|
-
|
|
13
|
+
var _flagsComponents = _interopRequireDefault(require("./components/FlagsIcons/flagsComponents"));
|
|
14
14
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
15
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
16
|
const FLAG_CODES = new Set(_countries.default.map(_ref => {
|
|
16
17
|
let {
|
|
17
18
|
code
|
|
@@ -20,8 +21,9 @@ const FLAG_CODES = new Set(_countries.default.map(_ref => {
|
|
|
20
21
|
}));
|
|
21
22
|
const flagComponentCache = {};
|
|
22
23
|
const getFlagComponent = code => {
|
|
23
|
-
if (!flagComponentCache
|
|
24
|
-
|
|
24
|
+
if (!(code in flagComponentCache)) {
|
|
25
|
+
const loader = _flagsComponents.default[code];
|
|
26
|
+
flagComponentCache[code] = loader ? /*#__PURE__*/_react.default.lazy(loader) : null;
|
|
25
27
|
}
|
|
26
28
|
return flagComponentCache[code];
|
|
27
29
|
};
|
|
@@ -53,6 +53,7 @@ const ID_CONSTANTS = exports.ID_CONSTANTS = {
|
|
|
53
53
|
PINNED: 'pinned',
|
|
54
54
|
POPPER: 'popper',
|
|
55
55
|
SEARCH_BUTTON: 'searchButton',
|
|
56
|
+
SECONDARY_ACTION: 'secondaryAction',
|
|
56
57
|
SEARCH_BUTTON_TOOLTIP: 'searchButtonTooltip',
|
|
57
58
|
SEARCH_FIELD: 'searchField',
|
|
58
59
|
SELECTION_COMPONENT: 'selectionComponent',
|
|
@@ -60,6 +61,7 @@ const ID_CONSTANTS = exports.ID_CONSTANTS = {
|
|
|
60
61
|
SIDEBAR_BUTTON: 'sidebarButton',
|
|
61
62
|
STATUS_MESSAGE: 'statusMessage',
|
|
62
63
|
TABLE: 'table',
|
|
64
|
+
TERTIARY_ACTION: 'tertiaryAction',
|
|
63
65
|
TABLE_ROW: 'tableRow',
|
|
64
66
|
TITLE: 'title',
|
|
65
67
|
USER_FILTER: 'userFilter',
|
|
@@ -2,14 +2,47 @@
|
|
|
2
2
|
|
|
3
3
|
### Description
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Displays a banner with contextual information. Supports multiple color themes, sizes, icon/button placement, and optional close action.
|
|
6
6
|
|
|
7
7
|
## Props
|
|
8
8
|
|
|
9
|
-
| Name
|
|
10
|
-
|
|
|
11
|
-
|
|
|
12
|
-
|
|
|
13
|
-
|
|
|
14
|
-
|
|
|
15
|
-
|
|
|
9
|
+
| Name | Type | Default | Description |
|
|
10
|
+
| ----------------- | --------------------------------------------------------------------------------- | -------------- | --------------------------------------------------------------------------- |
|
|
11
|
+
| button | object (UTButton props) | | Primary action button. All UTButton props are accepted. |
|
|
12
|
+
| buttonPlacement | `'horizontal'` \| `'vertical'` | `'horizontal'` | Alignment between the text group and the buttons group. |
|
|
13
|
+
| category | string | | Optional category label shown above the main text (xsmall, uppercase, gray). |
|
|
14
|
+
| children | node | | Main text content rendered inside the banner. |
|
|
15
|
+
| classes | object of string | | Classes returned by UTBanner's own [theme](./theme.js) `retrieveStyle`. |
|
|
16
|
+
| classNames | object of string | | Additional classes merged with the themed classes. |
|
|
17
|
+
| colorTheme | `'error'` \| `'gray'` \| `'information'` \| `'negative'` \| `'primary'` \| `'success'` \| `'warning'` \| `'white'` | `'gray'` | Color theme that determines the banner background. |
|
|
18
|
+
| helpText | string | | Optional secondary text shown below the main content (small, gray). |
|
|
19
|
+
| Icon | element type | | Icon component rendered at the start of the banner. |
|
|
20
|
+
| iconPlacement | `'horizontal'` \| `'vertical'` | `'horizontal'` | Alignment between the icon and the text group. |
|
|
21
|
+
| iconProps | object | | Props passed to the `Icon` component. |
|
|
22
|
+
| onClose | func | | If provided, renders a close button (gray, small, IconX) at the end. |
|
|
23
|
+
| secondaryButton | object (UTButton props) | | Secondary action button. Renders as `variant="text"` by default. |
|
|
24
|
+
| size | `'small'` \| `'medium'` \| `'large'` | `'medium'` | Controls padding, gap, and icon size. |
|
|
25
|
+
| variant | `'light'` \| `'dark'` | `'light'` | Light or dark tint of the color theme. |
|
|
26
|
+
|
|
27
|
+
## Usage examples
|
|
28
|
+
|
|
29
|
+
```jsx
|
|
30
|
+
// Basic
|
|
31
|
+
<UTBanner>Your account has been updated.</UTBanner>
|
|
32
|
+
|
|
33
|
+
// With color theme and close
|
|
34
|
+
<UTBanner colorTheme="success" onClose={() => dismiss()}>
|
|
35
|
+
Your changes were saved successfully.
|
|
36
|
+
</UTBanner>
|
|
37
|
+
|
|
38
|
+
// With category, helpText and actions
|
|
39
|
+
<UTBanner
|
|
40
|
+
category="Alert"
|
|
41
|
+
colorTheme="warning"
|
|
42
|
+
helpText="Contact support if the issue persists."
|
|
43
|
+
button={{ children: 'Retry', onClick: handleRetry }}
|
|
44
|
+
secondaryButton={{ children: 'Dismiss', onClick: handleDismiss }}
|
|
45
|
+
>
|
|
46
|
+
Something went wrong while loading your data.
|
|
47
|
+
</UTBanner>
|
|
48
|
+
```
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export const SIZES = {
|
|
2
|
+
SMALL: 'small',
|
|
3
|
+
MEDIUM: 'medium',
|
|
4
|
+
LARGE: 'large'
|
|
5
|
+
};
|
|
6
|
+
export const COLOR_THEMES = {
|
|
7
|
+
ERROR: 'error',
|
|
8
|
+
GRAY: 'gray',
|
|
9
|
+
INFORMATION: 'information',
|
|
10
|
+
NEGATIVE: 'negative',
|
|
11
|
+
PRIMARY: 'primary',
|
|
12
|
+
SUCCESS: 'success',
|
|
13
|
+
WARNING: 'warning',
|
|
14
|
+
WHITE: 'white'
|
|
15
|
+
};
|
|
16
|
+
export const VARIANTS = {
|
|
17
|
+
DARK: 'dark',
|
|
18
|
+
LIGHT: 'light'
|
|
19
|
+
};
|
|
20
|
+
export const PLACEMENTS = {
|
|
21
|
+
HORIZONTAL: 'horizontal',
|
|
22
|
+
VERTICAL: 'vertical'
|
|
23
|
+
};
|
|
24
|
+
export const DEFAULT_PROPS = {
|
|
25
|
+
buttonPlacement: PLACEMENTS.HORIZONTAL,
|
|
26
|
+
colorTheme: COLOR_THEMES.GRAY,
|
|
27
|
+
iconPlacement: PLACEMENTS.HORIZONTAL,
|
|
28
|
+
size: SIZES.MEDIUM,
|
|
29
|
+
variant: VARIANTS.LIGHT
|
|
30
|
+
};
|
|
@@ -1,29 +1,133 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
1
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { elementType, func, object, objectOf, oneOf, oneOfType, string } from 'prop-types';
|
|
4
|
+
import UTButton from '../UTButton';
|
|
5
|
+
import UTIcon from '../UTIcon';
|
|
3
6
|
import UTLabel from '../UTLabel';
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
7
|
+
import { capitalize, isUTIcon } from '../../utils/componentUtils';
|
|
8
|
+
import { mergeMultipleClassNames } from '../../utils/classesUtils';
|
|
9
|
+
import { ID_CONSTANTS } from '../../constants/testIds';
|
|
6
10
|
import styles from './styles.module.scss';
|
|
7
|
-
import {
|
|
11
|
+
import { buttonType } from './types';
|
|
12
|
+
import { getDefaultButtonColorTheme, getDefaultIconSize, getDefaultIconTheme, getLabelColorTheme, getLabelStyles, getSecondaryLabelColorTheme } from './utils';
|
|
13
|
+
import { COLOR_THEMES, DEFAULT_PROPS, PLACEMENTS, SIZES, VARIANTS } from './constants';
|
|
8
14
|
const UTBanner = _ref => {
|
|
9
15
|
let {
|
|
10
|
-
|
|
16
|
+
button,
|
|
17
|
+
buttonPlacement = DEFAULT_PROPS.buttonPlacement,
|
|
18
|
+
category,
|
|
11
19
|
classNames,
|
|
12
|
-
|
|
20
|
+
colorTheme = DEFAULT_PROPS.colorTheme,
|
|
21
|
+
dataTestId,
|
|
22
|
+
description,
|
|
23
|
+
helpText,
|
|
24
|
+
Icon,
|
|
25
|
+
iconPlacement = DEFAULT_PROPS.iconPlacement,
|
|
13
26
|
iconProps,
|
|
14
|
-
|
|
27
|
+
onClose,
|
|
28
|
+
secondaryButton,
|
|
29
|
+
size = DEFAULT_PROPS.size,
|
|
30
|
+
title,
|
|
31
|
+
variant = DEFAULT_PROPS.variant
|
|
15
32
|
} = _ref;
|
|
16
|
-
const
|
|
33
|
+
const isVerticalButton = buttonPlacement === PLACEMENTS.VERTICAL;
|
|
34
|
+
const isVerticalIcon = iconPlacement === PLACEMENTS.VERTICAL;
|
|
35
|
+
const labelColorTheme = getLabelColorTheme(colorTheme, variant);
|
|
36
|
+
const secondaryLabelColorTheme = getSecondaryLabelColorTheme(colorTheme, variant);
|
|
37
|
+
const {
|
|
38
|
+
titleVariant,
|
|
39
|
+
descriptionVariant
|
|
40
|
+
} = getLabelStyles(size);
|
|
41
|
+
const iconTheme = getDefaultIconTheme(colorTheme, variant);
|
|
42
|
+
const iconSize = getDefaultIconSize(size);
|
|
43
|
+
const buttonColorTheme = getDefaultButtonColorTheme(variant);
|
|
44
|
+
const gapClass = styles["gap".concat(capitalize(size))];
|
|
45
|
+
const paddingClass = styles["padding".concat(capitalize(size))];
|
|
46
|
+
const colorClass = styles["".concat(colorTheme).concat(capitalize(variant))];
|
|
47
|
+
const dynamicClasses = {
|
|
48
|
+
bannerContainer: [colorClass, paddingClass, gapClass].filter(Boolean).join(' '),
|
|
49
|
+
contentContainer: [isVerticalButton ? styles.contentVertical : styles.contentHorizontal, gapClass].filter(Boolean).join(' '),
|
|
50
|
+
iconTextContainer: [isVerticalIcon ? styles.iconVertical : styles.iconHorizontal, !isVerticalButton ? styles.iconFlex : ''].filter(Boolean).join(' '),
|
|
51
|
+
textContainer: !isVerticalIcon ? styles.textFlex : '',
|
|
52
|
+
buttonsContainer: isVerticalButton ? styles.buttonsVertical : ''
|
|
53
|
+
};
|
|
54
|
+
const normalizedClassNames = classNames ? {
|
|
55
|
+
...classNames,
|
|
56
|
+
bannerContainer: classNames.infoContainer
|
|
57
|
+
} : undefined;
|
|
58
|
+
const classes = mergeMultipleClassNames(styles, dynamicClasses, normalizedClassNames);
|
|
17
59
|
return /*#__PURE__*/React.createElement("div", {
|
|
18
|
-
className:
|
|
19
|
-
|
|
60
|
+
className: classes.bannerContainer,
|
|
61
|
+
"data-testid": dataTestId
|
|
62
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
63
|
+
className: classes.contentContainer
|
|
64
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
65
|
+
className: classes.iconTextContainer
|
|
66
|
+
}, !!Icon && isUTIcon(Icon) ? /*#__PURE__*/React.createElement(UTIcon, _extends({
|
|
67
|
+
colorTheme: iconTheme.colorTheme,
|
|
68
|
+
dataTestId: dataTestId ? "".concat(dataTestId, ".").concat(ID_CONSTANTS.ICON) : undefined,
|
|
69
|
+
name: Icon,
|
|
70
|
+
shade: iconTheme.shade,
|
|
71
|
+
size: iconSize
|
|
72
|
+
}, iconProps)) : !!Icon && /*#__PURE__*/React.createElement(Icon, _extends({}, iconProps, {
|
|
73
|
+
"data-testId": dataTestId ? "".concat(dataTestId, ".").concat(ID_CONSTANTS.ICON) : undefined
|
|
74
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
75
|
+
className: classes.textContainer
|
|
76
|
+
}, !!category && /*#__PURE__*/React.createElement(UTLabel, {
|
|
77
|
+
className: styles.uppercase,
|
|
78
|
+
colorTheme: secondaryLabelColorTheme,
|
|
79
|
+
dataTestId: dataTestId ? "".concat(dataTestId, ".category.").concat(ID_CONSTANTS.LABEL) : undefined,
|
|
80
|
+
variant: "xsmall",
|
|
81
|
+
weight: "medium"
|
|
82
|
+
}, category), !!title && /*#__PURE__*/React.createElement(UTLabel, {
|
|
83
|
+
colorTheme: labelColorTheme,
|
|
84
|
+
dataTestId: dataTestId ? "".concat(dataTestId, ".").concat(ID_CONSTANTS.TITLE, ".").concat(ID_CONSTANTS.LABEL) : undefined,
|
|
85
|
+
variant: titleVariant,
|
|
86
|
+
weight: "medium"
|
|
87
|
+
}, title), !!description && /*#__PURE__*/React.createElement(UTLabel, {
|
|
88
|
+
colorTheme: labelColorTheme,
|
|
89
|
+
dataTestId: dataTestId ? "".concat(dataTestId, ".").concat(ID_CONSTANTS.DESCRIPTION, ".").concat(ID_CONSTANTS.LABEL) : undefined,
|
|
90
|
+
variant: descriptionVariant
|
|
91
|
+
}, description), !!helpText && /*#__PURE__*/React.createElement(UTLabel, {
|
|
92
|
+
colorTheme: secondaryLabelColorTheme,
|
|
93
|
+
dataTestId: dataTestId ? "".concat(dataTestId, ".").concat(ID_CONSTANTS.HELP_TEXT, ".").concat(ID_CONSTANTS.LABEL) : undefined,
|
|
20
94
|
variant: "small"
|
|
21
|
-
},
|
|
95
|
+
}, helpText))), !!(button || secondaryButton) && /*#__PURE__*/React.createElement("div", {
|
|
96
|
+
className: classes.buttonsContainer
|
|
97
|
+
}, !!button && /*#__PURE__*/React.createElement(UTButton, _extends({
|
|
98
|
+
colorTheme: buttonColorTheme.button
|
|
99
|
+
}, button, {
|
|
100
|
+
dataTestId: dataTestId ? "".concat(dataTestId, ".button.").concat(ID_CONSTANTS.SECONDARY_ACTION) : undefined
|
|
101
|
+
}), button.title), !!secondaryButton && /*#__PURE__*/React.createElement(UTButton, _extends({
|
|
102
|
+
colorTheme: buttonColorTheme.secondaryButton,
|
|
103
|
+
variant: "text"
|
|
104
|
+
}, secondaryButton, {
|
|
105
|
+
dataTestId: dataTestId ? "".concat(dataTestId, ".secondaryButton.").concat(ID_CONSTANTS.TERTIARY_ACTION) : undefined
|
|
106
|
+
}), secondaryButton.title))), !!onClose && /*#__PURE__*/React.createElement(UTButton, {
|
|
107
|
+
colorTheme: buttonColorTheme.onClose,
|
|
108
|
+
dataTestId: dataTestId ? "".concat(dataTestId, ".close") : undefined,
|
|
109
|
+
Icon: "IconX",
|
|
110
|
+
onClick: onClose,
|
|
111
|
+
size: "small",
|
|
112
|
+
variant: "text"
|
|
113
|
+
}));
|
|
22
114
|
};
|
|
23
115
|
UTBanner.propTypes = {
|
|
24
|
-
|
|
116
|
+
button: buttonType,
|
|
117
|
+
buttonPlacement: oneOf(Object.values(PLACEMENTS)),
|
|
118
|
+
category: string,
|
|
25
119
|
classNames: objectOf(string),
|
|
26
|
-
|
|
27
|
-
|
|
120
|
+
colorTheme: oneOf(Object.values(COLOR_THEMES)),
|
|
121
|
+
dataTestId: string,
|
|
122
|
+
description: string,
|
|
123
|
+
helpText: string,
|
|
124
|
+
Icon: oneOfType([elementType, string]),
|
|
125
|
+
iconPlacement: oneOf(Object.values(PLACEMENTS)),
|
|
126
|
+
iconProps: object,
|
|
127
|
+
onClose: func,
|
|
128
|
+
secondaryButton: buttonType,
|
|
129
|
+
size: oneOf(Object.values(SIZES)),
|
|
130
|
+
title: string,
|
|
131
|
+
variant: oneOf(Object.values(VARIANTS))
|
|
28
132
|
};
|
|
29
|
-
export default
|
|
133
|
+
export default UTBanner;
|