carbon-react 142.13.2 → 142.13.4

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.
@@ -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), onClick && /*#__PURE__*/React.createElement(StyledCrossIcon, {
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
- &:hover,
71
- &:focus {
72
- background: ${toColor(theme, color)};
73
- border: none;
74
- ${StyledCounter} {
75
- display: none;
76
- }
72
+ ${(isFocused || isHovered) && `
73
+ && {
74
+ background: ${toColor(theme, color)};
75
+ border: none;
76
+ ${StyledCounter} {
77
+ display: none;
78
+ }
77
79
 
78
- ${StyledIcon} {
79
- display: block;
80
- width: auto;
81
- height: auto;
82
- margin-right: 0;
80
+ ${StyledIcon} {
81
+ display: block;
82
+ width: auto;
83
+ height: auto;
84
+ margin-right: 0;
83
85
 
84
- :before {
85
- font-size: 20px;
86
- color: var(--colorsActionMajorYang100);
86
+ :before {
87
+ font-size: 20px;
88
+ color: var(--colorsActionMajorYang100);
89
+ }
87
90
  }
88
91
  }
92
+ `}
89
93
  }
90
94
  `}
91
95
  `}
@@ -1,5 +1,4 @@
1
1
  import React from "react";
2
- import { CustomSelectChangeEvent } from "../../simple-select/simple-select.component";
3
2
  import { CommonTextboxProps } from "../../../textbox";
4
3
  import { ValidationProps } from "../../../../__internal__/validations";
5
4
  export interface FormInputPropTypes extends ValidationProps, Omit<CommonTextboxProps, "onClick" | "onChange"> {
@@ -29,8 +28,6 @@ export interface FormInputPropTypes extends ValidationProps, Omit<CommonTextboxP
29
28
  name?: string;
30
29
  /** Specify a callback triggered on blur */
31
30
  onBlur?: (ev: React.FocusEvent<HTMLInputElement>) => void;
32
- /** Specify a callback triggered on change */
33
- onChange?: (ev: CustomSelectChangeEvent | React.ChangeEvent<HTMLInputElement>) => void;
34
31
  /** Specify a callback triggered on click */
35
32
  onClick?: (ev: React.MouseEvent<HTMLInputElement>) => void;
36
33
  /** Specify a callback triggered on focus */
@@ -20,7 +20,6 @@ const SelectTextbox = /*#__PURE__*/React.forwardRef(({
20
20
  onClick,
21
21
  onFocus,
22
22
  onBlur,
23
- onChange,
24
23
  formattedValue = "",
25
24
  selectedValue,
26
25
  required,
@@ -75,8 +74,10 @@ const SelectTextbox = /*#__PURE__*/React.forwardRef(({
75
74
  "data-role": "select-textbox",
76
75
  inputIcon: "dropdown",
77
76
  autoComplete: "off",
78
- size: size,
79
- onChange: onChange,
77
+ size: size
78
+ // prevent uncontrolled warning being fired
79
+ ,
80
+ onChange: () => {},
80
81
  formattedValue: formattedValue,
81
82
  value: hasStringValue ? selectedValue : undefined,
82
83
  placeholder: hasTextCursor ? placeholder : undefined
@@ -404,7 +405,6 @@ if (process.env.NODE_ENV !== "production") {
404
405
  "onCanPlayCapture": PropTypes.func,
405
406
  "onCanPlayThrough": PropTypes.func,
406
407
  "onCanPlayThroughCapture": PropTypes.func,
407
- "onChange": PropTypes.func,
408
408
  "onChangeCapture": PropTypes.func,
409
409
  "onChangeDeferred": PropTypes.func,
410
410
  "onClick": PropTypes.func,
@@ -2,6 +2,7 @@ import React from "react";
2
2
  import { Side } from "@floating-ui/dom";
3
3
  import { ButtonProps } from "../../button";
4
4
  import { FormInputPropTypes } from "../__internal__/select-textbox";
5
+ import { CustomSelectChangeEvent } from "../simple-select";
5
6
  export interface FilterableSelectProps extends Omit<FormInputPropTypes, "defaultValue" | "value"> {
6
7
  /** Prop to specify the aria-label attribute of the component input */
7
8
  "aria-label"?: string;
@@ -65,6 +66,8 @@ export interface FilterableSelectProps extends Omit<FormInputPropTypes, "default
65
66
  isOptional?: boolean;
66
67
  /** Flag to configure component as mandatory */
67
68
  required?: boolean;
69
+ /** Specify a callback triggered on change */
70
+ onChange?: (ev: CustomSelectChangeEvent | React.ChangeEvent<HTMLInputElement>) => void;
68
71
  }
69
72
  export declare const FilterableSelect: React.ForwardRefExoticComponent<FilterableSelectProps & React.RefAttributes<HTMLInputElement>>;
70
73
  export default FilterableSelect;
@@ -1,6 +1,7 @@
1
1
  import React from "react";
2
2
  import { Side } from "@floating-ui/dom";
3
3
  import { FormInputPropTypes } from "../__internal__/select-textbox";
4
+ import { CustomSelectChangeEvent } from "../simple-select";
4
5
  export interface MultiSelectProps extends Omit<FormInputPropTypes, "defaultValue" | "value"> {
5
6
  /** Prop to specify the aria-label attribute of the component input */
6
7
  "aria-label"?: string;
@@ -57,6 +58,8 @@ export interface MultiSelectProps extends Omit<FormInputPropTypes, "defaultValue
57
58
  virtualScrollOverscan?: number;
58
59
  /** Flag to configure component as optional. */
59
60
  isOptional?: boolean;
61
+ /** Specify a callback triggered on change */
62
+ onChange?: (ev: CustomSelectChangeEvent | React.ChangeEvent<HTMLInputElement>) => void;
60
63
  }
61
64
  export declare const MultiSelect: React.ForwardRefExoticComponent<MultiSelectProps & React.RefAttributes<HTMLInputElement>>;
62
65
  export default MultiSelect;
@@ -65,6 +65,8 @@ export interface SimpleSelectProps extends Omit<FormInputPropTypes, "defaultValu
65
65
  isOptional?: boolean;
66
66
  /** Flag to configure component as mandatory */
67
67
  isRequired?: boolean;
68
+ /** Specify a callback triggered on change */
69
+ onChange?: (ev: CustomSelectChangeEvent | React.ChangeEvent<HTMLInputElement>) => void;
68
70
  }
69
71
  export declare const SimpleSelect: React.ForwardRefExoticComponent<SimpleSelectProps & React.RefAttributes<HTMLInputElement>>;
70
72
  export default SimpleSelect;
@@ -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 = _interopRequireDefault(require("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), onClick && /*#__PURE__*/_react.default.createElement(_badge.StyledCrossIcon, {
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
- &:hover,
80
- &:focus {
81
- background: ${(0, _color.toColor)(theme, color)};
82
- border: none;
83
- ${StyledCounter} {
84
- display: none;
85
- }
81
+ ${(isFocused || isHovered) && `
82
+ && {
83
+ background: ${(0, _color.toColor)(theme, color)};
84
+ border: none;
85
+ ${StyledCounter} {
86
+ display: none;
87
+ }
86
88
 
87
- ${_icon.default} {
88
- display: block;
89
- width: auto;
90
- height: auto;
91
- margin-right: 0;
89
+ ${_icon.default} {
90
+ display: block;
91
+ width: auto;
92
+ height: auto;
93
+ margin-right: 0;
92
94
 
93
- :before {
94
- font-size: 20px;
95
- color: var(--colorsActionMajorYang100);
95
+ :before {
96
+ font-size: 20px;
97
+ color: var(--colorsActionMajorYang100);
98
+ }
96
99
  }
97
100
  }
101
+ `}
98
102
  }
99
103
  `}
100
104
  `}
@@ -1,5 +1,4 @@
1
1
  import React from "react";
2
- import { CustomSelectChangeEvent } from "../../simple-select/simple-select.component";
3
2
  import { CommonTextboxProps } from "../../../textbox";
4
3
  import { ValidationProps } from "../../../../__internal__/validations";
5
4
  export interface FormInputPropTypes extends ValidationProps, Omit<CommonTextboxProps, "onClick" | "onChange"> {
@@ -29,8 +28,6 @@ export interface FormInputPropTypes extends ValidationProps, Omit<CommonTextboxP
29
28
  name?: string;
30
29
  /** Specify a callback triggered on blur */
31
30
  onBlur?: (ev: React.FocusEvent<HTMLInputElement>) => void;
32
- /** Specify a callback triggered on change */
33
- onChange?: (ev: CustomSelectChangeEvent | React.ChangeEvent<HTMLInputElement>) => void;
34
31
  /** Specify a callback triggered on click */
35
32
  onClick?: (ev: React.MouseEvent<HTMLInputElement>) => void;
36
33
  /** Specify a callback triggered on focus */
@@ -27,7 +27,6 @@ const SelectTextbox = /*#__PURE__*/_react.default.forwardRef(({
27
27
  onClick,
28
28
  onFocus,
29
29
  onBlur,
30
- onChange,
31
30
  formattedValue = "",
32
31
  selectedValue,
33
32
  required,
@@ -82,8 +81,10 @@ const SelectTextbox = /*#__PURE__*/_react.default.forwardRef(({
82
81
  "data-role": "select-textbox",
83
82
  inputIcon: "dropdown",
84
83
  autoComplete: "off",
85
- size: size,
86
- onChange: onChange,
84
+ size: size
85
+ // prevent uncontrolled warning being fired
86
+ ,
87
+ onChange: () => {},
87
88
  formattedValue: formattedValue,
88
89
  value: hasStringValue ? selectedValue : undefined,
89
90
  placeholder: hasTextCursor ? placeholder : undefined
@@ -411,7 +412,6 @@ if (process.env.NODE_ENV !== "production") {
411
412
  "onCanPlayCapture": _propTypes.default.func,
412
413
  "onCanPlayThrough": _propTypes.default.func,
413
414
  "onCanPlayThroughCapture": _propTypes.default.func,
414
- "onChange": _propTypes.default.func,
415
415
  "onChangeCapture": _propTypes.default.func,
416
416
  "onChangeDeferred": _propTypes.default.func,
417
417
  "onClick": _propTypes.default.func,
@@ -2,6 +2,7 @@ import React from "react";
2
2
  import { Side } from "@floating-ui/dom";
3
3
  import { ButtonProps } from "../../button";
4
4
  import { FormInputPropTypes } from "../__internal__/select-textbox";
5
+ import { CustomSelectChangeEvent } from "../simple-select";
5
6
  export interface FilterableSelectProps extends Omit<FormInputPropTypes, "defaultValue" | "value"> {
6
7
  /** Prop to specify the aria-label attribute of the component input */
7
8
  "aria-label"?: string;
@@ -65,6 +66,8 @@ export interface FilterableSelectProps extends Omit<FormInputPropTypes, "default
65
66
  isOptional?: boolean;
66
67
  /** Flag to configure component as mandatory */
67
68
  required?: boolean;
69
+ /** Specify a callback triggered on change */
70
+ onChange?: (ev: CustomSelectChangeEvent | React.ChangeEvent<HTMLInputElement>) => void;
68
71
  }
69
72
  export declare const FilterableSelect: React.ForwardRefExoticComponent<FilterableSelectProps & React.RefAttributes<HTMLInputElement>>;
70
73
  export default FilterableSelect;
@@ -1,6 +1,7 @@
1
1
  import React from "react";
2
2
  import { Side } from "@floating-ui/dom";
3
3
  import { FormInputPropTypes } from "../__internal__/select-textbox";
4
+ import { CustomSelectChangeEvent } from "../simple-select";
4
5
  export interface MultiSelectProps extends Omit<FormInputPropTypes, "defaultValue" | "value"> {
5
6
  /** Prop to specify the aria-label attribute of the component input */
6
7
  "aria-label"?: string;
@@ -57,6 +58,8 @@ export interface MultiSelectProps extends Omit<FormInputPropTypes, "defaultValue
57
58
  virtualScrollOverscan?: number;
58
59
  /** Flag to configure component as optional. */
59
60
  isOptional?: boolean;
61
+ /** Specify a callback triggered on change */
62
+ onChange?: (ev: CustomSelectChangeEvent | React.ChangeEvent<HTMLInputElement>) => void;
60
63
  }
61
64
  export declare const MultiSelect: React.ForwardRefExoticComponent<MultiSelectProps & React.RefAttributes<HTMLInputElement>>;
62
65
  export default MultiSelect;
@@ -65,6 +65,8 @@ export interface SimpleSelectProps extends Omit<FormInputPropTypes, "defaultValu
65
65
  isOptional?: boolean;
66
66
  /** Flag to configure component as mandatory */
67
67
  isRequired?: boolean;
68
+ /** Specify a callback triggered on change */
69
+ onChange?: (ev: CustomSelectChangeEvent | React.ChangeEvent<HTMLInputElement>) => void;
68
70
  }
69
71
  export declare const SimpleSelect: React.ForwardRefExoticComponent<SimpleSelectProps & React.RefAttributes<HTMLInputElement>>;
70
72
  export default SimpleSelect;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-react",
3
- "version": "142.13.2",
3
+ "version": "142.13.4",
4
4
  "description": "A library of reusable React components for easily building user interfaces.",
5
5
  "files": [
6
6
  "lib",