carbon-react 142.13.2 → 142.13.3
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/esm/components/badge/badge.component.js +19 -2
- package/esm/components/badge/badge.style.d.ts +2 -0
- package/esm/components/badge/badge.style.js +21 -17
- package/lib/components/badge/badge.component.js +21 -2
- package/lib/components/badge/badge.style.d.ts +2 -0
- package/lib/components/badge/badge.style.js +21 -17
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
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";
|
|
2
|
+
import React, { useState } from "react";
|
|
3
3
|
import PropTypes from "prop-types";
|
|
4
4
|
import { StyledBadgeWrapper, StyledCrossIcon, StyledCounter, StyledBadge } from "./badge.style";
|
|
5
5
|
export const Badge = ({
|
|
@@ -11,6 +11,8 @@ export const Badge = ({
|
|
|
11
11
|
}) => {
|
|
12
12
|
const shouldDisplayCounter = +counter > 0;
|
|
13
13
|
const counterToDisplay = +counter > 99 ? 99 : counter;
|
|
14
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
15
|
+
const [isHovered, setIsHovered] = useState(false);
|
|
14
16
|
const renderCorrectBadge = () => {
|
|
15
17
|
const props = onClick ? {
|
|
16
18
|
buttonType: "secondary",
|
|
@@ -23,7 +25,22 @@ export const Badge = ({
|
|
|
23
25
|
"data-role": "badge",
|
|
24
26
|
"data-component": "badge",
|
|
25
27
|
color: color
|
|
26
|
-
}, props
|
|
28
|
+
}, props, {
|
|
29
|
+
onFocus: () => {
|
|
30
|
+
setIsFocused(true);
|
|
31
|
+
},
|
|
32
|
+
onBlur: () => {
|
|
33
|
+
setIsFocused(false);
|
|
34
|
+
},
|
|
35
|
+
onMouseEnter: () => {
|
|
36
|
+
setIsHovered(true);
|
|
37
|
+
},
|
|
38
|
+
onMouseLeave: () => {
|
|
39
|
+
setIsHovered(false);
|
|
40
|
+
},
|
|
41
|
+
isFocused: isFocused,
|
|
42
|
+
isHovered: isHovered
|
|
43
|
+
}), onClick && /*#__PURE__*/React.createElement(StyledCrossIcon, {
|
|
27
44
|
"data-element": "badge-cross-icon",
|
|
28
45
|
type: "cross"
|
|
29
46
|
}), /*#__PURE__*/React.createElement(StyledCounter, {
|
|
@@ -3,6 +3,8 @@ declare const StyledBadgeWrapper: import("styled-components").StyledComponent<"d
|
|
|
3
3
|
declare const StyledCounter: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
4
4
|
interface StyledBadgeProps {
|
|
5
5
|
color: string;
|
|
6
|
+
isFocused?: boolean;
|
|
7
|
+
isHovered?: boolean;
|
|
6
8
|
}
|
|
7
9
|
declare const StyledBadge: import("styled-components").StyledComponent<"span", any, {
|
|
8
10
|
as: import("react").ForwardRefExoticComponent<import("../button").ButtonProps & import("react").RefAttributes<HTMLButtonElement>> | undefined;
|
|
@@ -52,7 +52,9 @@ const StyledBadge = styled.span.attrs(({
|
|
|
52
52
|
${({
|
|
53
53
|
onClick,
|
|
54
54
|
color,
|
|
55
|
-
theme
|
|
55
|
+
theme,
|
|
56
|
+
isFocused,
|
|
57
|
+
isHovered
|
|
56
58
|
}) => css`
|
|
57
59
|
${onClick && `
|
|
58
60
|
${commonStyles}
|
|
@@ -65,27 +67,29 @@ const StyledBadge = styled.span.attrs(({
|
|
|
65
67
|
}
|
|
66
68
|
|
|
67
69
|
border-color: ${toColor(theme, color)};
|
|
68
|
-
color: ${toColor(theme, color)};
|
|
70
|
+
color: ${toColor(theme, color)};
|
|
69
71
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
${(isFocused || isHovered) && `
|
|
73
|
+
&& {
|
|
74
|
+
background: ${toColor(theme, color)};
|
|
75
|
+
border: none;
|
|
76
|
+
${StyledCounter} {
|
|
77
|
+
display: none;
|
|
78
|
+
}
|
|
77
79
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
${StyledIcon} {
|
|
81
|
+
display: block;
|
|
82
|
+
width: auto;
|
|
83
|
+
height: auto;
|
|
84
|
+
margin-right: 0;
|
|
83
85
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
86
|
+
:before {
|
|
87
|
+
font-size: 20px;
|
|
88
|
+
color: var(--colorsActionMajorYang100);
|
|
89
|
+
}
|
|
87
90
|
}
|
|
88
91
|
}
|
|
92
|
+
`}
|
|
89
93
|
}
|
|
90
94
|
`}
|
|
91
95
|
`}
|
|
@@ -4,10 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = exports.Badge = void 0;
|
|
7
|
-
var _react =
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
9
|
var _badge = require("./badge.style");
|
|
10
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
12
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
11
13
|
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); }
|
|
12
14
|
const Badge = ({
|
|
13
15
|
"aria-label": ariaLabel,
|
|
@@ -18,6 +20,8 @@ const Badge = ({
|
|
|
18
20
|
}) => {
|
|
19
21
|
const shouldDisplayCounter = +counter > 0;
|
|
20
22
|
const counterToDisplay = +counter > 99 ? 99 : counter;
|
|
23
|
+
const [isFocused, setIsFocused] = (0, _react.useState)(false);
|
|
24
|
+
const [isHovered, setIsHovered] = (0, _react.useState)(false);
|
|
21
25
|
const renderCorrectBadge = () => {
|
|
22
26
|
const props = onClick ? {
|
|
23
27
|
buttonType: "secondary",
|
|
@@ -30,7 +34,22 @@ const Badge = ({
|
|
|
30
34
|
"data-role": "badge",
|
|
31
35
|
"data-component": "badge",
|
|
32
36
|
color: color
|
|
33
|
-
}, props
|
|
37
|
+
}, props, {
|
|
38
|
+
onFocus: () => {
|
|
39
|
+
setIsFocused(true);
|
|
40
|
+
},
|
|
41
|
+
onBlur: () => {
|
|
42
|
+
setIsFocused(false);
|
|
43
|
+
},
|
|
44
|
+
onMouseEnter: () => {
|
|
45
|
+
setIsHovered(true);
|
|
46
|
+
},
|
|
47
|
+
onMouseLeave: () => {
|
|
48
|
+
setIsHovered(false);
|
|
49
|
+
},
|
|
50
|
+
isFocused: isFocused,
|
|
51
|
+
isHovered: isHovered
|
|
52
|
+
}), onClick && /*#__PURE__*/_react.default.createElement(_badge.StyledCrossIcon, {
|
|
34
53
|
"data-element": "badge-cross-icon",
|
|
35
54
|
type: "cross"
|
|
36
55
|
}), /*#__PURE__*/_react.default.createElement(_badge.StyledCounter, {
|
|
@@ -3,6 +3,8 @@ declare const StyledBadgeWrapper: import("styled-components").StyledComponent<"d
|
|
|
3
3
|
declare const StyledCounter: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
4
4
|
interface StyledBadgeProps {
|
|
5
5
|
color: string;
|
|
6
|
+
isFocused?: boolean;
|
|
7
|
+
isHovered?: boolean;
|
|
6
8
|
}
|
|
7
9
|
declare const StyledBadge: import("styled-components").StyledComponent<"span", any, {
|
|
8
10
|
as: import("react").ForwardRefExoticComponent<import("../button").ButtonProps & import("react").RefAttributes<HTMLButtonElement>> | undefined;
|
|
@@ -61,7 +61,9 @@ const StyledBadge = exports.StyledBadge = _styledComponents.default.span.attrs((
|
|
|
61
61
|
${({
|
|
62
62
|
onClick,
|
|
63
63
|
color,
|
|
64
|
-
theme
|
|
64
|
+
theme,
|
|
65
|
+
isFocused,
|
|
66
|
+
isHovered
|
|
65
67
|
}) => (0, _styledComponents.css)`
|
|
66
68
|
${onClick && `
|
|
67
69
|
${commonStyles}
|
|
@@ -74,27 +76,29 @@ const StyledBadge = exports.StyledBadge = _styledComponents.default.span.attrs((
|
|
|
74
76
|
}
|
|
75
77
|
|
|
76
78
|
border-color: ${(0, _color.toColor)(theme, color)};
|
|
77
|
-
color: ${(0, _color.toColor)(theme, color)};
|
|
79
|
+
color: ${(0, _color.toColor)(theme, color)};
|
|
78
80
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
81
|
+
${(isFocused || isHovered) && `
|
|
82
|
+
&& {
|
|
83
|
+
background: ${(0, _color.toColor)(theme, color)};
|
|
84
|
+
border: none;
|
|
85
|
+
${StyledCounter} {
|
|
86
|
+
display: none;
|
|
87
|
+
}
|
|
86
88
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
89
|
+
${_icon.default} {
|
|
90
|
+
display: block;
|
|
91
|
+
width: auto;
|
|
92
|
+
height: auto;
|
|
93
|
+
margin-right: 0;
|
|
92
94
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
95
|
+
:before {
|
|
96
|
+
font-size: 20px;
|
|
97
|
+
color: var(--colorsActionMajorYang100);
|
|
98
|
+
}
|
|
96
99
|
}
|
|
97
100
|
}
|
|
101
|
+
`}
|
|
98
102
|
}
|
|
99
103
|
`}
|
|
100
104
|
`}
|