carbon-react 94.0.2 → 94.1.2

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.
@@ -56,7 +56,7 @@ const ActionPopover = ({
56
56
  const [isOpen, setOpenState] = (0, _react.useState)(false);
57
57
  const [focusIndex, setFocusIndex] = (0, _react.useState)(0);
58
58
  const [guid] = (0, _react.useState)((0, _guid.default)());
59
- const button = (0, _react.useRef)();
59
+ const buttonRef = (0, _react.useRef)();
60
60
  const menu = (0, _react.useRef)();
61
61
  const itemCount = (0, _react.useMemo)(() => {
62
62
  return _react.default.Children.toArray(children).filter(child => child.type === _actionPopoverItem.default).length;
@@ -94,7 +94,7 @@ const ActionPopover = ({
94
94
 
95
95
  if (!isOpening) {
96
96
  // Closing the menu should focus the MenuButton
97
- button.current.focus();
97
+ buttonRef.current.querySelector("[data-component='action-popover-button']").focus();
98
98
  }
99
99
  }, [isOpen, setOpen]); // Keyboard commands implemented as recommended by WAI-ARIA best practices
100
100
  // https://www.w3.org/TR/wai-aria-practices/examples/menu-button/menu-button-actions.html
@@ -112,7 +112,7 @@ const ActionPopover = ({
112
112
  setOpen(true);
113
113
  }
114
114
  }, [itemCount, setOpen]);
115
- const focusButton = (0, _react.useCallback)(() => button.current.focus(), []);
115
+ const focusButton = (0, _react.useCallback)(() => buttonRef.current.querySelector("[data-component='action-popover-button']").focus(), []);
116
116
  (0, _react.useEffect)(() => {
117
117
  const handler = ({
118
118
  target
@@ -120,7 +120,7 @@ const ActionPopover = ({
120
120
  // If the event didn't came from part of this component, close the menu.
121
121
  // There will be multiple document click listeners but we cant prevent propagation because it will interfere with
122
122
  // other instances on the same page
123
- if (!button.current.contains(target) && menu.current && !menu.current.contains(target)) {
123
+ if (!buttonRef.current.contains(target) && menu.current && !menu.current.contains(target)) {
124
124
  setOpen(false);
125
125
  }
126
126
  };
@@ -136,23 +136,37 @@ const ActionPopover = ({
136
136
  };
137
137
  }, [setOpen]);
138
138
 
139
- const menuButton = () => {
139
+ const menuButton = menuID => {
140
140
  if (renderButton) {
141
141
  return renderButton({
142
- tabIndex: -1,
143
- "data-element": "action-popover-menu-button"
142
+ tabIndex: isOpen ? "-1" : "0",
143
+ "data-component": "action-popover-button",
144
+ ariaAttributes: {
145
+ "aria-haspopup": "true",
146
+ "aria-label": l.actionPopover.ariaLabel(),
147
+ "aria-controls": menuID,
148
+ "aria-expanded": isOpen
149
+ }
144
150
  });
145
151
  }
146
152
 
147
- return /*#__PURE__*/_react.default.createElement(_actionPopover.ButtonIcon, {
153
+ return /*#__PURE__*/_react.default.createElement(_actionPopover.StyledButtonIcon, {
154
+ role: "button",
155
+ "aria-haspopup": "true",
156
+ "aria-label": l.actionPopover.ariaLabel(),
157
+ "aria-controls": menuID,
158
+ "aria-expanded": isOpen,
159
+ tabIndex: isOpen ? "-1" : "0",
160
+ "data-component": "action-popover-button"
161
+ }, /*#__PURE__*/_react.default.createElement(_actionPopover.ButtonIcon, {
148
162
  type: "ellipsis_vertical"
149
- });
163
+ }));
150
164
  };
151
165
 
152
166
  const parentID = id || `ActionPopoverButton_${guid}`;
153
167
  const menuID = `ActionPopoverMenu_${guid}`;
154
168
  const menuProps = {
155
- button,
169
+ buttonRef,
156
170
  parentID,
157
171
  setFocusIndex,
158
172
  focusIndex,
@@ -165,18 +179,12 @@ const ActionPopover = ({
165
179
  };
166
180
  return /*#__PURE__*/_react.default.createElement(_actionPopover.MenuButton, _extends({
167
181
  id: parentID,
168
- "data-component": "action-popover-button",
169
- role: "button",
170
- "aria-haspopup": "true",
171
- "aria-label": l.actionPopover.ariaLabel(),
172
- "aria-controls": menuID,
173
- "aria-expanded": isOpen,
174
- tabIndex: isOpen ? "-1" : "0",
182
+ "data-component": "action-popover-wrapper",
175
183
  onKeyDown: onButtonKeyDown,
176
184
  onClick: onButtonClick,
177
185
  isOpen,
178
- ref: button
179
- }, rest), menuButton(), /*#__PURE__*/_react.default.createElement(_actionPopoverContext.default.Provider, {
186
+ ref: buttonRef
187
+ }, rest), menuButton(menuID), /*#__PURE__*/_react.default.createElement(_actionPopoverContext.default.Provider, {
180
188
  value: {
181
189
  setOpenPopover: setOpen,
182
190
  focusButton,
@@ -184,7 +192,7 @@ const ActionPopover = ({
184
192
  }
185
193
  }, isOpen && /*#__PURE__*/_react.default.createElement(_popover.default, {
186
194
  placement: mappedPlacement,
187
- reference: button
195
+ reference: buttonRef
188
196
  }, /*#__PURE__*/_react.default.createElement(_actionPopoverMenu.default, _extends({
189
197
  "data-component": "action-popover",
190
198
  role: "menu",
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.StyledMenuItem = exports.MenuButtonOverrideWrapper = exports.SubMenuItemIcon = exports.MenuItemDivider = exports.MenuItemIcon = exports.ButtonIcon = exports.MenuButton = exports.MenuItemFactory = exports.Menu = void 0;
6
+ exports.StyledMenuItem = exports.MenuButtonOverrideWrapper = exports.SubMenuItemIcon = exports.MenuItemDivider = exports.MenuItemIcon = exports.StyledButtonIcon = exports.ButtonIcon = exports.MenuButton = exports.MenuItemFactory = exports.Menu = void 0;
7
7
 
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
 
@@ -131,16 +131,6 @@ const MenuButton = _styledComponents.default.div`
131
131
  isOpen,
132
132
  theme
133
133
  }) => isOpen && `background-color: ${theme.colors.white}`}
134
- &:hover, &:focus {
135
- background-color: ${({
136
- theme
137
- }) => theme.colors.white};
138
- }
139
- &:focus {
140
- outline: 2px solid ${({
141
- theme
142
- }) => theme.colors.focus};
143
- }
144
134
  `;
145
135
  /**
146
136
  * Creates a factory that returns a styled component with a custom
@@ -168,6 +158,21 @@ const iconThemeProviderFactory = (Component, themeFn) => (0, _styledComponents.w
168
158
 
169
159
  const ButtonIcon = iconThemeProviderFactory(_icon.default, palette => palette.slate);
170
160
  exports.ButtonIcon = ButtonIcon;
161
+ const StyledButtonIcon = _styledComponents.default.div`
162
+ &:hover,
163
+ &:focus {
164
+ background-color: ${({
165
+ theme
166
+ }) => theme.colors.white};
167
+ }
168
+
169
+ &:focus {
170
+ outline: 2px solid ${({
171
+ theme
172
+ }) => theme.colors.focus};
173
+ }
174
+ `;
175
+ exports.StyledButtonIcon = StyledButtonIcon;
171
176
  const MenuItemIcon = (0, _styledComponents.default)(iconThemeProviderFactory(_icon.default, () => "inherit"))`
172
177
  ${({
173
178
  theme,
@@ -203,13 +208,18 @@ exports.SubMenuItemIcon = SubMenuItemIcon;
203
208
  const MenuButtonOverrideWrapper = _styledComponents.default.div`
204
209
  ${({
205
210
  theme
206
- }) => `
211
+ }) => (0, _styledComponents.css)`
207
212
  ${_button.default} {
208
213
  padding: 0px ${theme.spacing}px;
209
214
  width: 100%;
210
215
  &:focus {
211
216
  outline-width: 2px;
212
217
  }
218
+
219
+ &:hover,
220
+ &:focus {
221
+ background-color: ${theme.colors.white};
222
+ }
213
223
  }
214
224
  `}
215
225
  `;
@@ -71,6 +71,7 @@ const renderStyledButton = buttonProps => {
71
71
  href,
72
72
  ref,
73
73
  px,
74
+ m = 0,
74
75
  size,
75
76
  noWrap,
76
77
  tooltipMessage,
@@ -117,6 +118,7 @@ const renderStyledButton = buttonProps => {
117
118
  iconType: iconType,
118
119
  size: size,
119
120
  px: px || paddingX,
121
+ m: m,
120
122
  noWrap: noWrap,
121
123
  iconOnly: !rest.children && iconType,
122
124
  target: target,
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _react = _interopRequireDefault(require("react"));
9
+
10
+ var _propTypes = _interopRequireDefault(require("prop-types"));
11
+
12
+ var _propTypes2 = _interopRequireDefault(require("@styled-system/prop-types"));
13
+
14
+ var _dismissibleBox = _interopRequireDefault(require("./dismissible-box.style"));
15
+
16
+ var _iconButton = _interopRequireDefault(require("../icon-button"));
17
+
18
+ var _icon = _interopRequireDefault(require("../icon"));
19
+
20
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
+
22
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
23
+
24
+ const variantStyles = {
25
+ light: {
26
+ backgroundColor: "#FFFFFF"
27
+ },
28
+ dark: {
29
+ backgroundColor: "slateTint90"
30
+ }
31
+ };
32
+
33
+ const DismissibleBox = ({
34
+ hasBorderLeftHighlight = true,
35
+ children,
36
+ onClose,
37
+ variant = "light",
38
+ ...rest
39
+ }) => /*#__PURE__*/_react.default.createElement(_dismissibleBox.default, _extends({
40
+ backgroundColor: variantStyles[variant].backgroundColor,
41
+ p: "20px 24px 20px 20px",
42
+ hasBorderLeftHighlight: hasBorderLeftHighlight
43
+ }, rest, {
44
+ minWidth: "600px",
45
+ display: "flex",
46
+ justifyContent: "space-between"
47
+ }), children, /*#__PURE__*/_react.default.createElement("span", null, /*#__PURE__*/_react.default.createElement(_iconButton.default, {
48
+ onAction: onClose,
49
+ "aria-label": "close-button",
50
+ ml: 3
51
+ }, /*#__PURE__*/_react.default.createElement(_icon.default, {
52
+ type: "close",
53
+ color: "slateTint20"
54
+ }))));
55
+
56
+ DismissibleBox.propTypes = { ..._propTypes2.default.space,
57
+
58
+ /** Flag to control whether the thicker left border highlight should be rendered */
59
+ hasBorderLeftHighlight: _propTypes.default.bool,
60
+
61
+ /** The content to render in the component */
62
+ children: _propTypes.default.node,
63
+
64
+ /** Callback to be called when the close icon button is clicked */
65
+ onClose: _propTypes.default.func.isRequired,
66
+
67
+ /** Use this prop to override the default width. Numbers from 0-1 are converted to percentage widths. Numbers greater
68
+ * than 1 are converted to pixel values. String values are passed as raw CSS values. And arrays are converted to
69
+ * responsive width styles. If theme.sizes is defined, the width prop will attempt to pick up values from the theme.
70
+ * Please note this component has a minWidth of 600px */
71
+ width: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
72
+
73
+ /** Set the base color variant */
74
+ variant: _propTypes.default.oneOf(["light", "dark"])
75
+ };
76
+ var _default = DismissibleBox;
77
+ exports.default = _default;
@@ -0,0 +1,19 @@
1
+ import * as React from "react";
2
+ import { SpaceProps } from "styled-system";
3
+
4
+ type BorderOptions = "top" | "bottom" | "right" | "none";
5
+
6
+ export interface DismissibleBoxProps extends SpaceProps {
7
+ /** Flag to control whether the thicker left border highlight should be rendered */
8
+ hasBorderLeftHighlight?: boolean;
9
+ /** The content to render in the component */
10
+ children?: React.ReactNode;
11
+ /** Callback to be called when the close icon button is clicked */
12
+ onClose: React.MouseEventHandler<HTMLButtonElement>;
13
+ /** Set the base color variant */
14
+ variant?: "light" | "dark";
15
+ }
16
+
17
+ declare function DismissibleBox(props: DismissibleBoxProps): JSX.Element;
18
+
19
+ export default DismissibleBox;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _styledComponents = _interopRequireWildcard(require("styled-components"));
9
+
10
+ var _box = _interopRequireDefault(require("../box"));
11
+
12
+ var _color = require("../../style/utils/color");
13
+
14
+ var _icon = _interopRequireDefault(require("../icon/icon.style"));
15
+
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
18
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
19
+
20
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
+
22
+ var _default = (0, _styledComponents.default)(_box.default)`
23
+ ${({
24
+ hasBorderLeftHighlight,
25
+ theme
26
+ }) => (0, _styledComponents.css)`
27
+ word-break: break-word;
28
+
29
+ border: 1px solid ${(0, _color.toColor)(theme, "slateTint80")};
30
+
31
+ ${hasBorderLeftHighlight && `
32
+ border-left: none;
33
+ box-shadow: -4px 0 0 0 ${(0, _color.toColor)(theme, "slateTint20")};
34
+ `}
35
+
36
+ ${_icon.default}:hover {
37
+ color: ${theme.palette.slate};
38
+ }
39
+ `}
40
+ `;
41
+
42
+ exports.default = _default;
@@ -0,0 +1 @@
1
+ export { default } from "./dismissible-box";
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "default", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _dismissibleBox.default;
10
+ }
11
+ });
12
+
13
+ var _dismissibleBox = _interopRequireDefault(require("./dismissible-box.component"));
14
+
15
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -17,6 +17,8 @@ var _menu2 = _interopRequireDefault(require("../menu.context"));
17
17
 
18
18
  var _focusTrap = _interopRequireDefault(require("../../../__internal__/focus-trap"));
19
19
 
20
+ var _events = _interopRequireDefault(require("../../../__internal__/utils/helpers/events"));
21
+
20
22
  var _box = _interopRequireDefault(require("../../box"));
21
23
 
22
24
  var _iconButton = _interopRequireDefault(require("../../icon-button"));
@@ -47,17 +49,39 @@ const MenuFullscreen = ({
47
49
  const {
48
50
  menuType
49
51
  } = (0, _react.useContext)(_menu2.default);
52
+
53
+ const handleKeyDown = ev => {
54
+ /* istanbul ignore else */
55
+ if (_events.default.isEscKey(ev)) {
56
+ onClose(ev);
57
+ }
58
+ };
59
+
60
+ (0, _react.useLayoutEffect)(() => {
61
+ const checkTransitionEnd = () => {
62
+ menuContentRef.current.focus();
63
+ };
64
+
65
+ const wrapperRef = menuWrapperRef.current;
66
+
67
+ if (isOpen) {
68
+ wrapperRef.addEventListener("transitionend", checkTransitionEnd);
69
+ } else {
70
+ wrapperRef.removeEventListener("transitionend", checkTransitionEnd);
71
+ }
72
+ }, [isOpen]);
50
73
  return /*#__PURE__*/_react.default.createElement("li", {
51
- "aria-label": "menu fullscreen",
52
- role: "menuitem"
74
+ "aria-label": "menu-fullscreen"
53
75
  }, /*#__PURE__*/_react.default.createElement(_portal.default, null, /*#__PURE__*/_react.default.createElement(_focusTrap.default, {
76
+ autoFocus: false,
54
77
  wrapperRef: menuWrapperRef
55
78
  }, /*#__PURE__*/_react.default.createElement(_menuFullScreen.StyledMenuFullscreen, _extends({
56
79
  "data-component": "menu-fullscreen",
57
80
  ref: menuWrapperRef,
58
81
  isOpen: isOpen,
59
82
  menuType: menuType,
60
- startPosition: startPosition
83
+ startPosition: startPosition,
84
+ onKeyDown: handleKeyDown
61
85
  }, rest), /*#__PURE__*/_react.default.createElement(_menuFullScreen.StyledMenuFullscreenHeader, {
62
86
  isOpen: isOpen,
63
87
  menuType: menuType,
@@ -80,8 +104,9 @@ const MenuFullscreen = ({
80
104
  ref: menuContentRef,
81
105
  display: "flex",
82
106
  flexDirection: "column",
83
- role: "menu",
84
- inFullscreenView: true
107
+ role: "list",
108
+ inFullscreenView: true,
109
+ tabIndex: -1
85
110
  }, _react.default.Children.map(children, (child, index) => /*#__PURE__*/_react.default.createElement(_menu2.default.Provider, {
86
111
  value: {
87
112
  inFullscreenView: true,
@@ -83,21 +83,6 @@ const StyledMenuFullscreenHeader = _styledComponents.default.div`
83
83
  background-color: ${theme.menu.dark.submenuBackground};
84
84
  `}
85
85
  `}
86
-
87
- ${({
88
- isOpen,
89
- startPosition
90
- }) => (0, _styledComponents.css)`
91
- ${isOpen && (0, _styledComponents.css)`
92
- ${startPosition}: 0;
93
- transition: all 0.3s ease;
94
- `}
95
-
96
- ${!isOpen && (0, _styledComponents.css)`
97
- ${startPosition}: -100vw;
98
- transition: all 0.3s ease;
99
- `}
100
- `}
101
86
  `;
102
87
  exports.StyledMenuFullscreenHeader = StyledMenuFullscreenHeader;
103
88
  StyledMenuFullscreen.defaultProps = {
@@ -22,6 +22,7 @@ const StyledMenuWrapper = _styledComponents.default.ul`
22
22
  list-style: none;
23
23
  margin: 0;
24
24
  padding: 0;
25
+ outline: none;
25
26
 
26
27
  ${_styledSystem.layout}
27
28
  ${_styledSystem.flexbox}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-react",
3
- "version": "94.0.2",
3
+ "version": "94.1.2",
4
4
  "description": "A library of reusable React components for easily building user interfaces.",
5
5
  "engineStrict": true,
6
6
  "engines": {
@@ -118,7 +118,6 @@
118
118
  "jest-styled-components": "^6.3.1",
119
119
  "lint-staged": "^10.5.3",
120
120
  "mockdate": "^2.0.2",
121
- "moxios": "^0.4.0",
122
121
  "prettier": "^2.1.2",
123
122
  "raf": "^3.4.0",
124
123
  "react": "^16.12.0",
@@ -127,18 +126,16 @@
127
126
  "rimraf": "^3.0.2",
128
127
  "semantic-release": "^17.4.7",
129
128
  "semver": "^7.3.5",
129
+ "sprintf-js": "^1.1.2",
130
130
  "styled-components": "^4.4.1",
131
- "typescript": "^3.9.5",
132
- "xhr-mock": "^2.5.1"
131
+ "typescript": "^3.9.5"
133
132
  },
134
133
  "dependencies": {
135
134
  "@popperjs/core": "^2.9.0",
136
135
  "@styled-system/prop-types": "^5.1.5",
137
136
  "@tippyjs/react": "^4.2.5",
138
- "bignumber.js": "^9.0.1",
139
137
  "classnames": "~2.2.6",
140
138
  "crypto-js": "~3.3.0",
141
- "escape-string-regexp": "^4.0.0",
142
139
  "immutable": "~3.8.2",
143
140
  "invariant": "^2.2.4",
144
141
  "lodash": "^4.17.20",
@@ -150,9 +147,7 @@
150
147
  "react-dnd-html5-backend": "^10.0.2",
151
148
  "react-is": "^17.0.2",
152
149
  "react-transition-group": "^4.4.1",
153
- "sprintf-js": "^1.1.2",
154
150
  "styled-system": "^5.1.5",
155
- "superagent": "~3.8.2",
156
151
  "wait-on": "^5.2.1"
157
152
  },
158
153
  "cypress-cucumber-preprocessor": {