@dxc-technology/halstack-react 0.0.0-509f1eb → 0.0.0-51152f3
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/HalstackContext.d.ts +16 -14
- package/action-icon/ActionIcon.d.ts +2 -2
- package/action-icon/ActionIcon.js +8 -4
- package/action-icon/ActionIcon.stories.tsx +41 -0
- package/action-icon/ActionIcon.test.js +64 -0
- package/badge/Badge.d.ts +1 -1
- package/badge/Badge.js +140 -29
- package/badge/Badge.stories.tsx +210 -0
- package/badge/Badge.test.js +30 -0
- package/badge/types.d.ts +52 -3
- package/button/Button.test.js +3 -1
- package/common/coreTokens.js +2 -2
- package/common/variables.d.ts +16 -14
- package/common/variables.js +22 -20
- package/container/Container.js +1 -1
- package/dropdown/Dropdown.js +9 -7
- package/footer/Footer.d.ts +1 -1
- package/footer/Footer.js +25 -12
- package/footer/Footer.stories.tsx +19 -0
- package/footer/Icons.d.ts +1 -0
- package/footer/Icons.js +65 -1
- package/footer/types.d.ts +6 -0
- package/layout/ApplicationLayout.d.ts +1 -1
- package/main.d.ts +3 -2
- package/main.js +8 -1
- package/nav-tabs/NavTabs.js +1 -1
- package/nav-tabs/NavTabs.stories.tsx +6 -4
- package/nav-tabs/NavTabs.test.js +3 -2
- package/nav-tabs/Tab.js +5 -4
- package/number-input/NumberInput.js +21 -2
- package/number-input/NumberInput.test.js +165 -6
- package/package.json +1 -1
- package/resultset-table/ResultsetTable.d.ts +4 -1
- package/resultset-table/ResultsetTable.js +14 -6
- package/resultset-table/ResultsetTable.stories.tsx +86 -5
- package/resultset-table/ResultsetTable.test.js +66 -0
- package/resultset-table/types.d.ts +6 -0
- package/status-light/StatusLight.d.ts +4 -0
- package/status-light/StatusLight.js +51 -0
- package/status-light/StatusLight.stories.tsx +74 -0
- package/status-light/StatusLight.test.js +25 -0
- package/status-light/types.d.ts +17 -0
- package/status-light/types.js +5 -0
- package/table/ActionsCell.d.ts +4 -0
- package/table/ActionsCell.js +55 -0
- package/table/DropdownTheme.js +58 -0
- package/table/Table.d.ts +4 -1
- package/table/Table.js +22 -5
- package/table/Table.stories.tsx +261 -2
- package/table/Table.test.js +92 -0
- package/table/types.d.ts +39 -0
- package/tabs/Tab.js +7 -4
- package/tabs/Tabs.stories.tsx +1 -1
- package/text-input/TextInput.js +28 -35
- package/text-input/TextInput.test.js +96 -79
- package/useTheme.d.ts +16 -14
- package/utils/FocusLock.js +3 -0
package/HalstackContext.d.ts
CHANGED
|
@@ -284,8 +284,14 @@ declare const HalstackContext: React.Context<DeepPartial<{
|
|
|
284
284
|
buttonPaddingBottom: string;
|
|
285
285
|
buttonPaddingLeft: string;
|
|
286
286
|
buttonPaddingRight: string;
|
|
287
|
+
buttonHeight: string;
|
|
288
|
+
buttonBorderRadius: string;
|
|
289
|
+
buttonBorderStyle: string;
|
|
290
|
+
buttonBorderThickness: string;
|
|
291
|
+
buttonBorderColor: string;
|
|
287
292
|
disabledColor: string;
|
|
288
293
|
disabledButtonBackgroundColor: string;
|
|
294
|
+
disabledButtonBorderColor: string;
|
|
289
295
|
disabledBorderColor: string;
|
|
290
296
|
optionBackgroundColor: string;
|
|
291
297
|
hoverOptionBackgroundColor: string;
|
|
@@ -867,6 +873,16 @@ declare const HalstackContext: React.Context<DeepPartial<{
|
|
|
867
873
|
scrollBarThumbColor: string;
|
|
868
874
|
scrollBarTrackColor: string;
|
|
869
875
|
sortIconColor: string;
|
|
876
|
+
actionIconColor: string;
|
|
877
|
+
disabledActionIconColor: string;
|
|
878
|
+
hoverActionIconColor: string;
|
|
879
|
+
focusActionIconColor: string;
|
|
880
|
+
activeActionIconColor: string;
|
|
881
|
+
actionBackgroundColor: string;
|
|
882
|
+
disabledActionBackgroundColor: string;
|
|
883
|
+
hoverActionBackgroundColor: string;
|
|
884
|
+
focusActionBorderColor: string;
|
|
885
|
+
activeActionBackgroundColor: string;
|
|
870
886
|
};
|
|
871
887
|
tabs: {
|
|
872
888
|
fontFamily: string;
|
|
@@ -885,7 +901,6 @@ declare const HalstackContext: React.Context<DeepPartial<{
|
|
|
885
901
|
disabledFontColor: string;
|
|
886
902
|
disabledIconColor: string;
|
|
887
903
|
disabledFontStyle: string;
|
|
888
|
-
disabledBadgeBackgroundColor: string;
|
|
889
904
|
hoverBackgroundColor: string;
|
|
890
905
|
pressedBackgroundColor: string;
|
|
891
906
|
pressedFontWeight: string;
|
|
@@ -893,19 +908,6 @@ declare const HalstackContext: React.Context<DeepPartial<{
|
|
|
893
908
|
dividerThickness: string;
|
|
894
909
|
focusOutline: string;
|
|
895
910
|
scrollButtonsWidth: string;
|
|
896
|
-
badgeBackgroundColor: string;
|
|
897
|
-
badgeFontFamily: string;
|
|
898
|
-
badgeFontSize: string;
|
|
899
|
-
badgeFontStyle: string;
|
|
900
|
-
badgeFontWeight: string;
|
|
901
|
-
badgeFontColor: string;
|
|
902
|
-
badgeLetterSpacing: string;
|
|
903
|
-
badgeWidth: string;
|
|
904
|
-
badgeHeight: string;
|
|
905
|
-
badgeRadius: string;
|
|
906
|
-
badgeWidthWithNotificationNumber: string;
|
|
907
|
-
badgeHeightWithNotificationNumber: string;
|
|
908
|
-
badgeRadiusWithNotificationNumber: string;
|
|
909
911
|
};
|
|
910
912
|
tag: {
|
|
911
913
|
fontFamily: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import
|
|
3
|
-
declare const DxcActionIcon: React.ForwardRefExoticComponent<
|
|
2
|
+
import ActionIconPropsTypes from "./types";
|
|
3
|
+
declare const DxcActionIcon: React.ForwardRefExoticComponent<ActionIconPropsTypes & React.RefAttributes<HTMLButtonElement>>;
|
|
4
4
|
export default DxcActionIcon;
|
|
@@ -8,6 +8,7 @@ exports["default"] = void 0;
|
|
|
8
8
|
var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
|
|
9
9
|
var _react = _interopRequireDefault(require("react"));
|
|
10
10
|
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
11
|
+
var _coreTokens = _interopRequireDefault(require("../common/coreTokens"));
|
|
11
12
|
var _templateObject;
|
|
12
13
|
var DxcActionIcon = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
13
14
|
var _ref$disabled = _ref.disabled,
|
|
@@ -31,13 +32,16 @@ var DxcActionIcon = /*#__PURE__*/_react["default"].forwardRef(function (_ref, re
|
|
|
31
32
|
src: icon
|
|
32
33
|
}) : icon);
|
|
33
34
|
});
|
|
34
|
-
var ActionIcon = _styledComponents["default"].button(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n align-items: center;\n justify-content: center;\n flex-shrink: 0;\n border: none;\n border-radius: 2px;\n width: 24px;\n height: 24px;\n padding:
|
|
35
|
+
var ActionIcon = _styledComponents["default"].button(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n align-items: center;\n justify-content: center;\n flex-shrink: 0;\n border: none;\n border-radius: 2px;\n width: 24px;\n height: 24px;\n padding: 0px;\n ", "\n\n box-shadow: 0 0 0 2px transparent;\n background-color: ", ";\n color: ", ";\n\n ", "\n\n img, svg {\n width: 16px;\n height: 16px;\n }\n"])), function (props) {
|
|
35
36
|
return props.disabled ? "cursor: not-allowed;" : "cursor: pointer;";
|
|
36
37
|
}, function (props) {
|
|
37
|
-
|
|
38
|
+
var _props$theme$disabled, _props$theme$actionBa;
|
|
39
|
+
return props.disabled ? (_props$theme$disabled = props.theme.disabledActionBackgroundColor) !== null && _props$theme$disabled !== void 0 ? _props$theme$disabled : _coreTokens["default"].color_transparent : (_props$theme$actionBa = props.theme.actionBackgroundColor) !== null && _props$theme$actionBa !== void 0 ? _props$theme$actionBa : _coreTokens["default"].color_transparent;
|
|
38
40
|
}, function (props) {
|
|
39
|
-
|
|
41
|
+
var _props$theme$disabled2, _props$theme$actionIc;
|
|
42
|
+
return props.disabled ? (_props$theme$disabled2 = props.theme.disabledActionIconColor) !== null && _props$theme$disabled2 !== void 0 ? _props$theme$disabled2 : _coreTokens["default"].color_grey_500 : (_props$theme$actionIc = props.theme.actionIconColor) !== null && _props$theme$actionIc !== void 0 ? _props$theme$actionIc : _coreTokens["default"].color_black;
|
|
40
43
|
}, function (props) {
|
|
41
|
-
|
|
44
|
+
var _props$theme$focusAct, _props$theme$focusAct2, _props$theme$hoverAct, _props$theme$hoverAct2, _props$theme$activeAc, _props$theme$activeAc2;
|
|
45
|
+
return !props.disabled && "\n &:focus,\n &:focus-visible {\n outline: none;\n box-shadow: 0 0 0 2px ".concat((_props$theme$focusAct = props.theme.focusActionBorderColor) !== null && _props$theme$focusAct !== void 0 ? _props$theme$focusAct : _coreTokens["default"].color_blue_600, ";\n color: ").concat((_props$theme$focusAct2 = props.theme.focusActionIconColor) !== null && _props$theme$focusAct2 !== void 0 ? _props$theme$focusAct2 : _coreTokens["default"].color_black, ";\n }\n &:hover {\n background-color: ").concat((_props$theme$hoverAct = props.theme.hoverActionBackgroundColor) !== null && _props$theme$hoverAct !== void 0 ? _props$theme$hoverAct : _coreTokens["default"].color_grey_100, ";\n color: ").concat((_props$theme$hoverAct2 = props.theme.hoverActionIconColor) !== null && _props$theme$hoverAct2 !== void 0 ? _props$theme$hoverAct2 : _coreTokens["default"].color_black, ";\n }\n &:active {\n background-color: ").concat((_props$theme$activeAc = props.theme.activeActionBackgroundColor) !== null && _props$theme$activeAc !== void 0 ? _props$theme$activeAc : _coreTokens["default"].color_grey_300, ";\n color: ").concat((_props$theme$activeAc2 = props.theme.activeActionIconColor) !== null && _props$theme$activeAc2 !== void 0 ? _props$theme$activeAc2 : _coreTokens["default"].color_black, ";\n }\n ");
|
|
42
46
|
});
|
|
43
47
|
var _default = exports["default"] = DxcActionIcon;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import Title from "../../.storybook/components/Title";
|
|
3
|
+
import ExampleContainer from "../../.storybook/components/ExampleContainer";
|
|
4
|
+
import DxcActionIcon from "./ActionIcon";
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
title: "Action Icon ",
|
|
8
|
+
component: DxcActionIcon,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const iconSVG = (
|
|
12
|
+
<svg width="24px" height="24px" viewBox="0 0 24 24" fill="currentColor">
|
|
13
|
+
<path d="M0 0h24v24H0z" fill="none" />
|
|
14
|
+
<path d="M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z" />
|
|
15
|
+
</svg>
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
export const Chromatic = () => (
|
|
19
|
+
<>
|
|
20
|
+
<Title title="Default" theme="light" level={2} />
|
|
21
|
+
<ExampleContainer>
|
|
22
|
+
<DxcActionIcon icon={"https://www.freepnglogos.com/uploads/facebook-logo-design-1.png"} title="Favourite" />
|
|
23
|
+
</ExampleContainer>
|
|
24
|
+
<Title title="Disabled" theme="light" level={2} />
|
|
25
|
+
<ExampleContainer>
|
|
26
|
+
<DxcActionIcon icon={iconSVG} title="Favourite" disabled />
|
|
27
|
+
</ExampleContainer>
|
|
28
|
+
<Title title="Hover" theme="light" level={2} />
|
|
29
|
+
<ExampleContainer pseudoState="pseudo-hover">
|
|
30
|
+
<DxcActionIcon icon={iconSVG} title="Favourite" />
|
|
31
|
+
</ExampleContainer>
|
|
32
|
+
<Title title="Focus" theme="light" level={2} />
|
|
33
|
+
<ExampleContainer pseudoState="pseudo-focus">
|
|
34
|
+
<DxcActionIcon icon={iconSVG} title="Favourite" />
|
|
35
|
+
</ExampleContainer>
|
|
36
|
+
<Title title="Active" theme="light" level={2} />
|
|
37
|
+
<ExampleContainer pseudoState="pseudo-active">
|
|
38
|
+
<DxcActionIcon icon={iconSVG} title="Favourite" />
|
|
39
|
+
</ExampleContainer>
|
|
40
|
+
</>
|
|
41
|
+
);
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _react = _interopRequireDefault(require("react"));
|
|
5
|
+
var _react2 = require("@testing-library/react");
|
|
6
|
+
var _ActionIcon = _interopRequireDefault(require("./ActionIcon.tsx"));
|
|
7
|
+
var iconSVG = /*#__PURE__*/_react["default"].createElement("svg", {
|
|
8
|
+
width: "24px",
|
|
9
|
+
height: "24px",
|
|
10
|
+
viewBox: "0 0 24 24",
|
|
11
|
+
fill: "currentColor"
|
|
12
|
+
}, /*#__PURE__*/_react["default"].createElement("path", {
|
|
13
|
+
d: "M0 0h24v24H0z",
|
|
14
|
+
fill: "none"
|
|
15
|
+
}), /*#__PURE__*/_react["default"].createElement("path", {
|
|
16
|
+
d: "M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z"
|
|
17
|
+
}));
|
|
18
|
+
describe("Action icon component tests", function () {
|
|
19
|
+
test("Action icon renders with correct text", function () {
|
|
20
|
+
var _render = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_ActionIcon["default"], {
|
|
21
|
+
icon: iconSVG,
|
|
22
|
+
title: "favourite"
|
|
23
|
+
})),
|
|
24
|
+
getByTitle = _render.getByTitle;
|
|
25
|
+
expect(getByTitle("favourite")).toBeTruthy();
|
|
26
|
+
});
|
|
27
|
+
test("Calls correct function on click", function () {
|
|
28
|
+
var onClick = jest.fn();
|
|
29
|
+
var _render2 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_ActionIcon["default"], {
|
|
30
|
+
icon: iconSVG,
|
|
31
|
+
title: "favourite",
|
|
32
|
+
onClick: onClick
|
|
33
|
+
})),
|
|
34
|
+
getByTitle = _render2.getByTitle;
|
|
35
|
+
var action = getByTitle("favourite");
|
|
36
|
+
_react2.fireEvent.click(action);
|
|
37
|
+
expect(onClick).toHaveBeenCalled();
|
|
38
|
+
});
|
|
39
|
+
test("On click is not called when disabled", function () {
|
|
40
|
+
var onClick = jest.fn();
|
|
41
|
+
var _render3 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_ActionIcon["default"], {
|
|
42
|
+
disabled: true,
|
|
43
|
+
icon: iconSVG,
|
|
44
|
+
title: "favourite",
|
|
45
|
+
onClick: onClick
|
|
46
|
+
})),
|
|
47
|
+
getByTitle = _render3.getByTitle;
|
|
48
|
+
var action = getByTitle("favourite");
|
|
49
|
+
_react2.fireEvent.click(action);
|
|
50
|
+
expect(onClick).toHaveBeenCalledTimes(0);
|
|
51
|
+
});
|
|
52
|
+
test("Renders with correct accessibility attributes", function () {
|
|
53
|
+
var _render4 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_ActionIcon["default"], {
|
|
54
|
+
icon: iconSVG,
|
|
55
|
+
title: "favourite",
|
|
56
|
+
tabIndex: 1
|
|
57
|
+
})),
|
|
58
|
+
getByRole = _render4.getByRole;
|
|
59
|
+
var button = getByRole("button");
|
|
60
|
+
expect(button.getAttribute("aria-label")).toBe("favourite");
|
|
61
|
+
expect(button.getAttribute("title")).toBe("favourite");
|
|
62
|
+
expect(button.getAttribute("tabindex")).toBe("1");
|
|
63
|
+
});
|
|
64
|
+
});
|
package/badge/Badge.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import BadgePropsType from "./types";
|
|
3
|
-
declare const DxcBadge: ({
|
|
3
|
+
declare const DxcBadge: ({ label, title, mode, color, icon, notificationLimit, size, }: BadgePropsType) => JSX.Element;
|
|
4
4
|
export default DxcBadge;
|
package/badge/Badge.js
CHANGED
|
@@ -1,48 +1,159 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports["default"] = void 0;
|
|
9
8
|
var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
|
|
10
9
|
var _react = _interopRequireDefault(require("react"));
|
|
11
|
-
var _styledComponents =
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
10
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
11
|
+
var _Flex = _interopRequireDefault(require("../flex/Flex"));
|
|
12
|
+
var _coreTokens = _interopRequireDefault(require("../common/coreTokens"));
|
|
13
|
+
var _templateObject, _templateObject2, _templateObject3;
|
|
14
|
+
var contextualColorMap = {
|
|
15
|
+
grey: {
|
|
16
|
+
background: _coreTokens["default"].color_grey_200,
|
|
17
|
+
text: _coreTokens["default"].color_grey_900
|
|
18
|
+
},
|
|
19
|
+
blue: {
|
|
20
|
+
background: _coreTokens["default"].color_blue_200,
|
|
21
|
+
text: _coreTokens["default"].color_blue_900
|
|
22
|
+
},
|
|
23
|
+
green: {
|
|
24
|
+
background: _coreTokens["default"].color_green_200,
|
|
25
|
+
text: _coreTokens["default"].color_green_900
|
|
26
|
+
},
|
|
27
|
+
orange: {
|
|
28
|
+
background: _coreTokens["default"].color_orange_200,
|
|
29
|
+
text: _coreTokens["default"].color_orange_900
|
|
30
|
+
},
|
|
31
|
+
red: {
|
|
32
|
+
background: _coreTokens["default"].color_red_200,
|
|
33
|
+
text: _coreTokens["default"].color_red_900
|
|
34
|
+
},
|
|
35
|
+
yellow: {
|
|
36
|
+
background: _coreTokens["default"].color_yellow_200,
|
|
37
|
+
text: _coreTokens["default"].color_yellow_900
|
|
38
|
+
},
|
|
39
|
+
purple: {
|
|
40
|
+
background: _coreTokens["default"].color_purple_200,
|
|
41
|
+
text: _coreTokens["default"].color_purple_900
|
|
42
|
+
}
|
|
26
43
|
};
|
|
27
|
-
var
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
44
|
+
var sizeMap = {
|
|
45
|
+
small: {
|
|
46
|
+
height: "20px",
|
|
47
|
+
width: "20px",
|
|
48
|
+
minWidth: "20px",
|
|
49
|
+
fontSize: _coreTokens["default"].type_scale_01,
|
|
50
|
+
borderRadius: _coreTokens["default"].spacing_12,
|
|
51
|
+
iconSize: "14px",
|
|
52
|
+
padding: {
|
|
53
|
+
contextual: "".concat(_coreTokens["default"].spacing_4),
|
|
54
|
+
notification: "".concat(_coreTokens["default"].spacing_0, " ").concat(_coreTokens["default"].spacing_4)
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
medium: {
|
|
58
|
+
height: "24px",
|
|
59
|
+
width: "24px",
|
|
60
|
+
minWidth: "24px",
|
|
61
|
+
fontSize: _coreTokens["default"].type_scale_02,
|
|
62
|
+
borderRadius: _coreTokens["default"].spacing_12,
|
|
63
|
+
iconSize: "16px",
|
|
64
|
+
padding: {
|
|
65
|
+
contextual: "".concat(_coreTokens["default"].spacing_4, " ").concat(_coreTokens["default"].spacing_8),
|
|
66
|
+
notification: "".concat(_coreTokens["default"].spacing_0, " ").concat(_coreTokens["default"].spacing_4)
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
large: {
|
|
70
|
+
height: "32px",
|
|
71
|
+
width: "32px",
|
|
72
|
+
minWidth: "32px",
|
|
73
|
+
fontSize: _coreTokens["default"].type_scale_04,
|
|
74
|
+
borderRadius: _coreTokens["default"].spacing_24,
|
|
75
|
+
iconSize: "24px",
|
|
76
|
+
padding: {
|
|
77
|
+
contextual: "".concat(_coreTokens["default"].spacing_4, " ").concat(_coreTokens["default"].spacing_8),
|
|
78
|
+
notification: "".concat(_coreTokens["default"].spacing_0, " ").concat(_coreTokens["default"].spacing_8)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
var Label = function Label(_ref) {
|
|
83
|
+
var label = _ref.label,
|
|
84
|
+
notificationLimit = _ref.notificationLimit,
|
|
85
|
+
size = _ref.size;
|
|
86
|
+
return /*#__PURE__*/_react["default"].createElement(LabelContainer, {
|
|
87
|
+
size: size
|
|
88
|
+
}, typeof label === "number" ? label > notificationLimit ? "+" + notificationLimit : label : label);
|
|
89
|
+
};
|
|
90
|
+
var DxcBadge = function DxcBadge(_ref2) {
|
|
91
|
+
var label = _ref2.label,
|
|
92
|
+
title = _ref2.title,
|
|
93
|
+
_ref2$mode = _ref2.mode,
|
|
94
|
+
mode = _ref2$mode === void 0 ? "contextual" : _ref2$mode,
|
|
95
|
+
_ref2$color = _ref2.color,
|
|
96
|
+
color = _ref2$color === void 0 ? "grey" : _ref2$color,
|
|
97
|
+
icon = _ref2.icon,
|
|
98
|
+
_ref2$notificationLim = _ref2.notificationLimit,
|
|
99
|
+
notificationLimit = _ref2$notificationLim === void 0 ? 99 : _ref2$notificationLim,
|
|
100
|
+
_ref2$size = _ref2.size,
|
|
101
|
+
size = _ref2$size === void 0 ? "medium" : _ref2$size;
|
|
102
|
+
return /*#__PURE__*/_react["default"].createElement(BadgeContainer, {
|
|
103
|
+
label: label,
|
|
104
|
+
mode: mode,
|
|
105
|
+
color: mode === "contextual" && color || undefined,
|
|
106
|
+
size: size,
|
|
107
|
+
title: title,
|
|
108
|
+
"aria-label": title
|
|
109
|
+
}, mode === "contextual" && /*#__PURE__*/_react["default"].createElement(_Flex["default"], {
|
|
110
|
+
gap: "0.125rem",
|
|
111
|
+
alignItems: "center"
|
|
112
|
+
}, icon && /*#__PURE__*/_react["default"].createElement(IconContainer, {
|
|
113
|
+
size: size
|
|
114
|
+
}, typeof icon === "string" ? /*#__PURE__*/_react["default"].createElement("img", {
|
|
115
|
+
src: icon,
|
|
116
|
+
alt: title
|
|
117
|
+
}) : icon), /*#__PURE__*/_react["default"].createElement(Label, {
|
|
118
|
+
label: label,
|
|
119
|
+
notificationLimit: notificationLimit,
|
|
120
|
+
size: size
|
|
121
|
+
})) || /*#__PURE__*/_react["default"].createElement(Label, {
|
|
122
|
+
label: label,
|
|
123
|
+
notificationLimit: notificationLimit,
|
|
124
|
+
size: size
|
|
125
|
+
}));
|
|
126
|
+
};
|
|
127
|
+
var getColor = function getColor(mode, color) {
|
|
128
|
+
return mode === "contextual" ? contextualColorMap[color].text : _coreTokens["default"].color_white;
|
|
129
|
+
};
|
|
130
|
+
var getBackgroundColor = function getBackgroundColor(mode, color) {
|
|
131
|
+
return mode === "contextual" ? contextualColorMap[color].background : _coreTokens["default"].color_red_700;
|
|
132
|
+
};
|
|
133
|
+
var getPadding = function getPadding(mode, size) {
|
|
134
|
+
return mode === "contextual" ? sizeMap[size].padding.contextual : sizeMap[size].padding.notification;
|
|
135
|
+
};
|
|
136
|
+
var BadgeContainer = _styledComponents["default"].div(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n color: ", ";\n background-color: ", ";\n border-radius: ", ";\n width: ", ";\n min-width: ", ";\n height: ", ";\n padding: ", ";\n align-items: center;\n justify-content: center;\n box-sizing: border-box;\n"])), function (props) {
|
|
137
|
+
return getColor(props.mode, props.color);
|
|
33
138
|
}, function (props) {
|
|
34
|
-
return props.
|
|
139
|
+
return getBackgroundColor(props.mode, props.color);
|
|
35
140
|
}, function (props) {
|
|
36
|
-
return props.
|
|
141
|
+
return sizeMap[props.size].borderRadius;
|
|
37
142
|
}, function (props) {
|
|
38
|
-
return props.
|
|
143
|
+
return !props.label && props.mode === "notification" ? sizeMap[props.size].width : "fit-content";
|
|
39
144
|
}, function (props) {
|
|
40
|
-
return props.
|
|
145
|
+
return props.mode === "notification" && sizeMap[props.size].minWidth;
|
|
41
146
|
}, function (props) {
|
|
42
|
-
return props.
|
|
147
|
+
return sizeMap[props.size].height;
|
|
43
148
|
}, function (props) {
|
|
44
|
-
return props.
|
|
149
|
+
return props.label ? getPadding(props.mode, props.size) : "";
|
|
150
|
+
});
|
|
151
|
+
var IconContainer = _styledComponents["default"].div(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n img,\n svg {\n height: ", ";\n width: ", ";\n }\n"])), function (props) {
|
|
152
|
+
return sizeMap[props.size].iconSize;
|
|
45
153
|
}, function (props) {
|
|
46
|
-
return props.
|
|
154
|
+
return sizeMap[props.size].iconSize;
|
|
47
155
|
});
|
|
156
|
+
var LabelContainer = _styledComponents["default"].span(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2["default"])(["\n font-family: ", ";\n font-size: ", ";\n font-weight: ", ";\n white-space: nowrap;\n"])), _coreTokens["default"].type_sans, function (props) {
|
|
157
|
+
return sizeMap[props.size].fontSize;
|
|
158
|
+
}, _coreTokens["default"].type_semibold);
|
|
48
159
|
var _default = exports["default"] = DxcBadge;
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import DxcBadge from "./Badge";
|
|
3
|
+
import Title from "../../.storybook/components/Title";
|
|
4
|
+
import ExampleContainer from "../../.storybook/components/ExampleContainer";
|
|
5
|
+
import DxcFlex from "../flex/Flex";
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
title: "Badge",
|
|
9
|
+
component: DxcBadge,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const icon = (
|
|
13
|
+
<svg width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="currentColor">
|
|
14
|
+
<path d="M11 17H13V11H11V17ZM12 2C6.48 2 2 6.48 2 12C2 17.52 6.48 22 12 22C17.52 22 22 17.52 22 12C22 6.48 17.52 2 12 2ZM12 20C7.59 20 4 16.41 4 12C4 7.59 7.59 4 12 4C16.41 4 20 7.59 20 12C20 16.41 16.41 20 12 20ZM11 9H13V7H11V9Z" />
|
|
15
|
+
<path d="M11 7H13V9H11V7ZM11 11H13V17H11V11Z" />
|
|
16
|
+
<path d="M12 2C6.48 2 2 6.48 2 12C2 17.52 6.48 22 12 22C17.52 22 22 17.52 22 12C22 6.48 17.52 2 12 2ZM12 20C7.59 20 4 16.41 4 12C4 7.59 7.59 4 12 4C16.41 4 20 7.59 20 12C20 16.41 16.41 20 12 20Z" />
|
|
17
|
+
</svg>
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
export const Chromatic = () => (
|
|
21
|
+
<>
|
|
22
|
+
<Title title="Notification" theme="light" level={2} />
|
|
23
|
+
<ExampleContainer>
|
|
24
|
+
<Title title="Small" theme="light" level={4} />
|
|
25
|
+
<DxcFlex gap="3rem" alignItems="center">
|
|
26
|
+
<DxcBadge mode="notification" size="small" />
|
|
27
|
+
<DxcBadge mode="notification" label={1} size="small" />
|
|
28
|
+
<DxcBadge mode="notification" label={10} size="small" />
|
|
29
|
+
<DxcBadge mode="notification" label={1000000} size="small" notificationLimit={99999999} />
|
|
30
|
+
<DxcBadge mode="notification" label={100} size="small" notificationLimit={99} />
|
|
31
|
+
</DxcFlex>
|
|
32
|
+
</ExampleContainer>
|
|
33
|
+
<ExampleContainer>
|
|
34
|
+
<Title title="Medium" theme="light" level={4} />
|
|
35
|
+
<DxcFlex gap="3rem" alignContent="center" alignItems="center">
|
|
36
|
+
<DxcBadge mode="notification" size="medium" />
|
|
37
|
+
<DxcBadge mode="notification" label={1} size="medium" />
|
|
38
|
+
<DxcBadge mode="notification" label={10} size="medium" />
|
|
39
|
+
<DxcBadge mode="notification" label={1000000} size="medium" notificationLimit={99999999} />
|
|
40
|
+
<DxcBadge mode="notification" label={100} size="medium" />
|
|
41
|
+
</DxcFlex>
|
|
42
|
+
</ExampleContainer>
|
|
43
|
+
<ExampleContainer>
|
|
44
|
+
<Title title="Large" theme="light" level={4} />
|
|
45
|
+
<DxcFlex gap="3rem" alignItems="center">
|
|
46
|
+
<DxcBadge mode="notification" size="large" />
|
|
47
|
+
<DxcBadge mode="notification" label={1} size="large" />
|
|
48
|
+
<DxcBadge mode="notification" label={10} size="large" />
|
|
49
|
+
<DxcBadge mode="notification" label={1000000} size="large" notificationLimit={99999999} />
|
|
50
|
+
<DxcBadge mode="notification" label={100} size="large" />
|
|
51
|
+
</DxcFlex>
|
|
52
|
+
</ExampleContainer>
|
|
53
|
+
<Title title="Contextual" theme="light" level={2} />
|
|
54
|
+
<Title title="Grey" theme="light" level={3} />
|
|
55
|
+
<ExampleContainer>
|
|
56
|
+
<Title title="Small" theme="light" level={4} />
|
|
57
|
+
<DxcFlex gap="3rem" alignItems="center">
|
|
58
|
+
<DxcBadge label="Label" size="small" />
|
|
59
|
+
<DxcBadge label="Label" size="small" icon={icon} />
|
|
60
|
+
</DxcFlex>
|
|
61
|
+
</ExampleContainer>
|
|
62
|
+
<ExampleContainer>
|
|
63
|
+
<Title title="Medium" theme="light" level={4} />
|
|
64
|
+
<DxcFlex gap="3rem" alignItems="center">
|
|
65
|
+
<DxcBadge label="Label" />
|
|
66
|
+
<DxcBadge label="Label" icon={icon} />
|
|
67
|
+
</DxcFlex>
|
|
68
|
+
</ExampleContainer>
|
|
69
|
+
<ExampleContainer>
|
|
70
|
+
<Title title="Large" theme="light" level={4} />
|
|
71
|
+
<DxcFlex gap="3rem" alignItems="center">
|
|
72
|
+
<DxcBadge label="Label" size="large" />
|
|
73
|
+
<DxcBadge label="Label" size="large" icon={icon} />
|
|
74
|
+
</DxcFlex>
|
|
75
|
+
</ExampleContainer>
|
|
76
|
+
<Title title="Blue" theme="light" level={3} />
|
|
77
|
+
<ExampleContainer>
|
|
78
|
+
<Title title="Small" theme="light" level={4} />
|
|
79
|
+
<DxcFlex gap="3rem" alignItems="center">
|
|
80
|
+
<DxcBadge color="blue" label="Label" size="small" />
|
|
81
|
+
<DxcBadge color="blue" label="Label" size="small" icon={icon} />
|
|
82
|
+
</DxcFlex>
|
|
83
|
+
</ExampleContainer>
|
|
84
|
+
<ExampleContainer>
|
|
85
|
+
<Title title="Medium" theme="light" level={4} />
|
|
86
|
+
<DxcFlex gap="3rem" alignItems="center">
|
|
87
|
+
<DxcBadge color="blue" label="Label" />
|
|
88
|
+
<DxcBadge color="blue" label="Label" icon={icon} />
|
|
89
|
+
</DxcFlex>
|
|
90
|
+
</ExampleContainer>
|
|
91
|
+
<ExampleContainer>
|
|
92
|
+
<Title title="Large" theme="light" level={4} />
|
|
93
|
+
<DxcFlex gap="3rem" alignItems="center">
|
|
94
|
+
<DxcBadge color="blue" label="Label" size="large" />
|
|
95
|
+
<DxcBadge color="blue" label="Label" size="large" icon={icon} />
|
|
96
|
+
</DxcFlex>
|
|
97
|
+
</ExampleContainer>
|
|
98
|
+
<Title title="Green" theme="light" level={3} />
|
|
99
|
+
<ExampleContainer>
|
|
100
|
+
<Title title="Small" theme="light" level={4} />
|
|
101
|
+
<DxcFlex gap="3rem" alignItems="center">
|
|
102
|
+
<DxcBadge color="green" label="Label" size="small" />
|
|
103
|
+
<DxcBadge color="green" label="Label" size="small" icon={icon} />
|
|
104
|
+
</DxcFlex>
|
|
105
|
+
</ExampleContainer>
|
|
106
|
+
<ExampleContainer>
|
|
107
|
+
<Title title="Medium" theme="light" level={4} />
|
|
108
|
+
<DxcFlex gap="3rem" alignItems="center">
|
|
109
|
+
<DxcBadge color="green" label="Label" />
|
|
110
|
+
<DxcBadge color="green" label="Label" icon={icon} />
|
|
111
|
+
</DxcFlex>
|
|
112
|
+
</ExampleContainer>
|
|
113
|
+
<ExampleContainer>
|
|
114
|
+
<Title title="Large" theme="light" level={4} />
|
|
115
|
+
<DxcFlex gap="3rem" alignItems="center">
|
|
116
|
+
<DxcBadge color="green" label="Label" size="large" />
|
|
117
|
+
<DxcBadge color="green" label="Label" size="large" icon={icon} />
|
|
118
|
+
</DxcFlex>
|
|
119
|
+
</ExampleContainer>
|
|
120
|
+
<ExampleContainer></ExampleContainer>
|
|
121
|
+
<Title title="Orange" theme="light" level={3} />
|
|
122
|
+
<ExampleContainer>
|
|
123
|
+
<Title title="Small" theme="light" level={4} />
|
|
124
|
+
<DxcFlex gap="3rem" alignItems="center">
|
|
125
|
+
<DxcBadge color="orange" label="Label" size="small" />
|
|
126
|
+
<DxcBadge color="orange" label="Label" size="small" icon={icon} />
|
|
127
|
+
</DxcFlex>
|
|
128
|
+
</ExampleContainer>
|
|
129
|
+
<ExampleContainer>
|
|
130
|
+
<Title title="Medium" theme="light" level={4} />
|
|
131
|
+
<DxcFlex gap="3rem" alignItems="center">
|
|
132
|
+
<DxcBadge color="orange" label="Label" />
|
|
133
|
+
<DxcBadge color="orange" label="Label" icon={icon} />
|
|
134
|
+
</DxcFlex>
|
|
135
|
+
</ExampleContainer>
|
|
136
|
+
<ExampleContainer>
|
|
137
|
+
<Title title="Large" theme="light" level={4} />
|
|
138
|
+
<DxcFlex gap="3rem" alignItems="center">
|
|
139
|
+
<DxcBadge color="orange" label="Label" size="large" />
|
|
140
|
+
<DxcBadge color="orange" label="Label" size="large" icon={icon} />
|
|
141
|
+
</DxcFlex>
|
|
142
|
+
</ExampleContainer>
|
|
143
|
+
<Title title="Red" theme="light" level={3} />
|
|
144
|
+
<ExampleContainer>
|
|
145
|
+
<Title title="Small" theme="light" level={4} />
|
|
146
|
+
<DxcFlex gap="3rem" alignItems="center">
|
|
147
|
+
<DxcBadge color="red" label="Label" size="small" />
|
|
148
|
+
<DxcBadge color="red" label="Label" size="small" icon={icon} />
|
|
149
|
+
</DxcFlex>
|
|
150
|
+
</ExampleContainer>
|
|
151
|
+
<ExampleContainer>
|
|
152
|
+
<Title title="Medium" theme="light" level={4} />
|
|
153
|
+
<DxcFlex gap="3rem" alignItems="center">
|
|
154
|
+
<DxcBadge color="red" label="Label" />
|
|
155
|
+
<DxcBadge color="red" label="Label" icon={icon} />
|
|
156
|
+
</DxcFlex>
|
|
157
|
+
</ExampleContainer>
|
|
158
|
+
<ExampleContainer>
|
|
159
|
+
<Title title="Large" theme="light" level={4} />
|
|
160
|
+
<DxcFlex gap="3rem" alignItems="center">
|
|
161
|
+
<DxcBadge color="red" label="Label" size="large" />
|
|
162
|
+
<DxcBadge color="red" label="Label" size="large" icon={icon} />
|
|
163
|
+
</DxcFlex>
|
|
164
|
+
</ExampleContainer>
|
|
165
|
+
<Title title="Yellow" theme="light" level={3} />
|
|
166
|
+
<ExampleContainer>
|
|
167
|
+
<Title title="Small" theme="light" level={4} />
|
|
168
|
+
<DxcFlex gap="3rem" alignItems="center">
|
|
169
|
+
<DxcBadge color="yellow" label="Label" size="small" />
|
|
170
|
+
<DxcBadge color="yellow" label="Label" size="small" icon={icon} />
|
|
171
|
+
</DxcFlex>
|
|
172
|
+
</ExampleContainer>
|
|
173
|
+
<ExampleContainer>
|
|
174
|
+
<Title title="Medium" theme="light" level={4} />
|
|
175
|
+
<DxcFlex gap="3rem" alignItems="center">
|
|
176
|
+
<DxcBadge color="yellow" label="Label" />
|
|
177
|
+
<DxcBadge color="yellow" label="Label" icon={icon} />
|
|
178
|
+
</DxcFlex>
|
|
179
|
+
</ExampleContainer>
|
|
180
|
+
<ExampleContainer>
|
|
181
|
+
<Title title="Large" theme="light" level={4} />
|
|
182
|
+
<DxcFlex gap="3rem" alignItems="center">
|
|
183
|
+
<DxcBadge color="yellow" label="Label" size="large" />
|
|
184
|
+
<DxcBadge color="yellow" label="Label" size="large" icon={icon} />
|
|
185
|
+
</DxcFlex>
|
|
186
|
+
</ExampleContainer>
|
|
187
|
+
<Title title="Purple" theme="light" level={3} />
|
|
188
|
+
<ExampleContainer>
|
|
189
|
+
<Title title="Small" theme="light" level={4} />
|
|
190
|
+
<DxcFlex gap="3rem" alignItems="center">
|
|
191
|
+
<DxcBadge color="purple" label="Label" size="small" />
|
|
192
|
+
<DxcBadge color="purple" label="Label" size="small" icon={icon} />
|
|
193
|
+
</DxcFlex>
|
|
194
|
+
</ExampleContainer>
|
|
195
|
+
<ExampleContainer>
|
|
196
|
+
<Title title="Medium" theme="light" level={4} />
|
|
197
|
+
<DxcFlex gap="3rem" alignItems="center">
|
|
198
|
+
<DxcBadge color="purple" label="Label" />
|
|
199
|
+
<DxcBadge color="purple" label="Label" icon={icon} />
|
|
200
|
+
</DxcFlex>
|
|
201
|
+
</ExampleContainer>
|
|
202
|
+
<ExampleContainer>
|
|
203
|
+
<Title title="Large" theme="light" level={4} />
|
|
204
|
+
<DxcFlex gap="3rem" alignItems="center">
|
|
205
|
+
<DxcBadge color="purple" label="Label" size="large" />
|
|
206
|
+
<DxcBadge color="purple" label="Label" size="large" icon={icon} />
|
|
207
|
+
</DxcFlex>
|
|
208
|
+
</ExampleContainer>
|
|
209
|
+
</>
|
|
210
|
+
);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _react = _interopRequireDefault(require("react"));
|
|
5
|
+
var _react2 = require("@testing-library/react");
|
|
6
|
+
var _Badge = _interopRequireDefault(require("./Badge.tsx"));
|
|
7
|
+
var _Flex = _interopRequireDefault(require("../flex/Flex.tsx"));
|
|
8
|
+
describe("Badge component tests", function () {
|
|
9
|
+
test("Badge renders with correct label when it is less than notification limit", function () {
|
|
10
|
+
var _render = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Badge["default"], {
|
|
11
|
+
label: 99,
|
|
12
|
+
mode: "notification"
|
|
13
|
+
})),
|
|
14
|
+
getByText = _render.getByText;
|
|
15
|
+
expect(getByText("99")).toBeTruthy();
|
|
16
|
+
});
|
|
17
|
+
test("Badge renders +99 as label when it is greater than notification limit", function () {
|
|
18
|
+
var _render2 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Flex["default"], null, /*#__PURE__*/_react["default"].createElement(_Badge["default"], {
|
|
19
|
+
label: 120,
|
|
20
|
+
mode: "notification"
|
|
21
|
+
}), /*#__PURE__*/_react["default"].createElement(_Badge["default"], {
|
|
22
|
+
label: 11,
|
|
23
|
+
mode: "notification",
|
|
24
|
+
notificationLimit: 10
|
|
25
|
+
}))),
|
|
26
|
+
getByText = _render2.getByText;
|
|
27
|
+
expect(getByText("+99")).toBeTruthy();
|
|
28
|
+
expect(getByText("+10")).toBeTruthy();
|
|
29
|
+
});
|
|
30
|
+
});
|