carbon-react 114.16.0 → 114.17.0

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.
Files changed (37) hide show
  1. package/esm/__internal__/focus-trap/focus-trap.component.d.ts +2 -2
  2. package/esm/__internal__/focus-trap/index.d.ts +1 -1
  3. package/esm/components/advanced-color-picker/advanced-color-picker-cell.style.d.ts +4 -0
  4. package/esm/components/advanced-color-picker/advanced-color-picker.component.d.ts +43 -0
  5. package/esm/components/advanced-color-picker/advanced-color-picker.component.js +203 -74
  6. package/esm/components/advanced-color-picker/advanced-color-picker.style.d.ts +6 -0
  7. package/esm/components/advanced-color-picker/index.d.ts +2 -1
  8. package/esm/components/alert/alert.component.js +11 -5
  9. package/esm/components/confirm/confirm.component.js +11 -5
  10. package/esm/components/dialog/dialog.component.d.ts +2 -4
  11. package/esm/components/dialog/dialog.component.js +11 -5
  12. package/esm/components/dialog-full-screen/dialog-full-screen.component.d.ts +3 -2
  13. package/esm/components/dialog-full-screen/dialog-full-screen.component.js +14 -8
  14. package/esm/components/search/index.d.ts +1 -1
  15. package/esm/components/simple-color-picker/index.d.ts +1 -1
  16. package/esm/components/simple-color-picker/simple-color-picker.component.d.ts +5 -1
  17. package/esm/components/simple-color-picker/simple-color-picker.component.js +20 -15
  18. package/lib/__internal__/focus-trap/focus-trap.component.d.ts +2 -2
  19. package/lib/__internal__/focus-trap/index.d.ts +1 -1
  20. package/lib/components/advanced-color-picker/advanced-color-picker-cell.style.d.ts +4 -0
  21. package/lib/components/advanced-color-picker/advanced-color-picker.component.d.ts +43 -0
  22. package/lib/components/advanced-color-picker/advanced-color-picker.component.js +203 -76
  23. package/lib/components/advanced-color-picker/advanced-color-picker.style.d.ts +6 -0
  24. package/lib/components/advanced-color-picker/index.d.ts +2 -1
  25. package/lib/components/alert/alert.component.js +11 -5
  26. package/lib/components/confirm/confirm.component.js +11 -5
  27. package/lib/components/dialog/dialog.component.d.ts +2 -4
  28. package/lib/components/dialog/dialog.component.js +11 -5
  29. package/lib/components/dialog-full-screen/dialog-full-screen.component.d.ts +3 -2
  30. package/lib/components/dialog-full-screen/dialog-full-screen.component.js +14 -8
  31. package/lib/components/search/index.d.ts +1 -1
  32. package/lib/components/simple-color-picker/index.d.ts +1 -1
  33. package/lib/components/simple-color-picker/simple-color-picker.component.d.ts +5 -1
  34. package/lib/components/simple-color-picker/simple-color-picker.component.js +19 -12
  35. package/package.json +1 -1
  36. package/esm/components/advanced-color-picker/advanced-color-picker.d.ts +0 -42
  37. package/lib/components/advanced-color-picker/advanced-color-picker.d.ts +0 -42
@@ -1,5 +1,6 @@
1
1
  import React from "react";
2
2
  import { ModalProps } from "../modal";
3
+ import { CustomRefObject } from "../../__internal__/focus-trap";
3
4
  export interface DialogFullScreenProps extends ModalProps {
4
5
  /** Prop to specify the aria-describedby property of the DialogFullscreen component */
5
6
  "aria-describedby"?: string;
@@ -23,7 +24,7 @@ export interface DialogFullScreenProps extends ModalProps {
23
24
  /** remove padding from content */
24
25
  disableContentPadding?: boolean;
25
26
  /** Optional reference to an element meant to be focused on open */
26
- focusFirstElement?: React.MutableRefObject<HTMLElement | null>;
27
+ focusFirstElement?: CustomRefObject<HTMLElement> | HTMLElement | null;
27
28
  /**
28
29
  * Function to replace focus trap
29
30
  * @ignore
@@ -45,7 +46,7 @@ export interface DialogFullScreenProps extends ModalProps {
45
46
  /** The ARIA role to be applied to the DialogFullscreen container */
46
47
  role?: string;
47
48
  /** an optional array of refs to containers whose content should also be reachable by tabbing from the dialog */
48
- focusableContainers?: React.MutableRefObject<HTMLElement | null>[];
49
+ focusableContainers?: CustomRefObject<HTMLElement>[];
49
50
  /** Optional selector to identify the focusable elements, if not provided a default selector is used */
50
51
  focusableSelectors?: string;
51
52
  /** A custom close event handler */
@@ -162,24 +162,30 @@ DialogFullScreen.propTypes = {
162
162
  "disableEscKey": _propTypes.default.bool,
163
163
  "enableBackgroundUI": _propTypes.default.bool,
164
164
  "focusableContainers": _propTypes.default.arrayOf(_propTypes.default.shape({
165
- "current": _propTypes.default.oneOfType([_propTypes.default.oneOf([null]), function (props, propName) {
165
+ "current": function (props, propName) {
166
166
  if (props[propName] == null) {
167
- return new Error("Prop '" + propName + "' is required but wasn't specified");
167
+ return null;
168
168
  } else if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) {
169
169
  return new Error("Expected prop '" + propName + "' to be of type Element");
170
170
  }
171
- }]).isRequired
171
+ }
172
172
  })),
173
173
  "focusableSelectors": _propTypes.default.string,
174
- "focusFirstElement": _propTypes.default.shape({
175
- "current": _propTypes.default.oneOfType([_propTypes.default.oneOf([null]), function (props, propName) {
174
+ "focusFirstElement": _propTypes.default.oneOfType([function (props, propName) {
175
+ if (props[propName] == null) {
176
+ return new Error("Prop '" + propName + "' is required but wasn't specified");
177
+ } else if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) {
178
+ return new Error("Expected prop '" + propName + "' to be of type Element");
179
+ }
180
+ }, _propTypes.default.shape({
181
+ "current": function (props, propName) {
176
182
  if (props[propName] == null) {
177
- return new Error("Prop '" + propName + "' is required but wasn't specified");
183
+ return null;
178
184
  } else if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) {
179
185
  return new Error("Expected prop '" + propName + "' to be of type Element");
180
186
  }
181
- }]).isRequired
182
- }),
187
+ }
188
+ })]),
183
189
  "headerChildren": _propTypes.default.node,
184
190
  "help": _propTypes.default.string,
185
191
  "onCancel": _propTypes.default.func,
@@ -1,2 +1,2 @@
1
1
  export { default } from "./search.component";
2
- export type { SearchProps } from "./search.component";
2
+ export type { SearchProps, SearchEvent } from "./search.component";
@@ -1,4 +1,4 @@
1
1
  export { default as SimpleColorPicker } from "./simple-color-picker.component";
2
- export type { SimpleColorPickerProps } from "./simple-color-picker.component";
2
+ export type { SimpleColorPickerProps, SimpleColorPickerRef, } from "./simple-color-picker.component";
3
3
  export { default as SimpleColor } from "./simple-color";
4
4
  export type { SimpleColorProps } from "./simple-color";
@@ -27,5 +27,9 @@ export interface SimpleColorPickerProps extends ValidationProps, MarginProps {
27
27
  /** The currently selected color. */
28
28
  value?: string;
29
29
  }
30
- export declare const SimpleColorPicker: (props: SimpleColorPickerProps) => JSX.Element;
30
+ export interface SimpleColorPickerRef {
31
+ /** List of color input HTML refs */
32
+ gridItemRefs: (HTMLInputElement | null)[];
33
+ }
34
+ export declare const SimpleColorPicker: React.ForwardRefExoticComponent<SimpleColorPickerProps & React.RefAttributes<SimpleColorPickerRef>>;
31
35
  export default SimpleColorPicker;
@@ -37,7 +37,7 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
37
37
 
38
38
  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); }
39
39
 
40
- const SimpleColorPicker = props => {
40
+ const SimpleColorPicker = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
41
41
  const {
42
42
  children,
43
43
  error,
@@ -77,7 +77,7 @@ const SimpleColorPicker = props => {
77
77
  let blankSlots = itemsPerRow * rowCount - (filteredChildren === null || filteredChildren === void 0 ? void 0 : filteredChildren.length);
78
78
  let currentRow = 1;
79
79
  let loopCounter = 1;
80
- const gridItemRefs = (0, _react.useMemo)(() => filteredChildren.map(child => child.ref || /*#__PURE__*/_react.default.createRef()), [filteredChildren]);
80
+ const gridItemRefs = (0, _react.useRef)([]);
81
81
  const navigationGrid = filteredChildren.map((child, index) => {
82
82
  const allowUp = currentRow !== 1;
83
83
  let allowDown = false;
@@ -107,7 +107,9 @@ const SimpleColorPicker = props => {
107
107
  }
108
108
 
109
109
  const childProps = {
110
- ref: gridItemRefs[index],
110
+ ref: element => {
111
+ gridItemRefs.current[index] = element;
112
+ },
111
113
  "data-up": allowUp,
112
114
  "data-down": allowDown,
113
115
  "data-item-up": upItem,
@@ -117,6 +119,14 @@ const SimpleColorPicker = props => {
117
119
  loopCounter += 1;
118
120
  return /*#__PURE__*/_react.default.cloneElement(child, childProps);
119
121
  });
122
+ (0, _react.useImperativeHandle)(ref, () => ({
123
+ gridItemRefs: gridItemRefs.current
124
+ }), [gridItemRefs]);
125
+ const getElementPosition = (0, _react.useCallback)(target => {
126
+ return navigationGrid.findIndex(element => {
127
+ return target.getAttribute("value") === element.props.value;
128
+ });
129
+ }, [navigationGrid]);
120
130
  const onKeyDownHandler = (0, _react.useCallback)(e => {
121
131
  if (onKeyDown) {
122
132
  onKeyDown(e);
@@ -137,14 +147,10 @@ const SimpleColorPicker = props => {
137
147
  }
138
148
 
139
149
  if (_events.default.isLeftKey(e) || _events.default.isRightKey(e)) {
140
- const position = element => {
141
- return target.getAttribute("value") === element.props.value;
142
- };
143
-
144
150
  if (_events.default.isLeftKey(e)) {
145
- itemIndex = navigationGrid.findIndex(position) - 1;
151
+ itemIndex = getElementPosition(target) - 1;
146
152
  } else {
147
- itemIndex = navigationGrid.findIndex(position) + 1;
153
+ itemIndex = getElementPosition(target) + 1;
148
154
  }
149
155
 
150
156
  if (itemIndex < 0) {
@@ -157,11 +163,11 @@ const SimpleColorPicker = props => {
157
163
 
158
164
 
159
165
  if (itemIndex !== null) {
160
- const item = gridItemRefs[itemIndex].current;
166
+ const item = gridItemRefs.current[itemIndex];
161
167
  item === null || item === void 0 ? void 0 : item.focus();
162
168
  item === null || item === void 0 ? void 0 : item.click();
163
169
  }
164
- }, [onKeyDown, navigationGrid, gridItemRefs]);
170
+ }, [onKeyDown, navigationGrid, getElementPosition]);
165
171
 
166
172
  const handleClickOutside = ev => {
167
173
  if (internalRef.current && ev.target && !internalRef.current.contains(ev.target)) {
@@ -229,7 +235,7 @@ const SimpleColorPicker = props => {
229
235
  }, navigationGrid))), !validationOnLegend && /*#__PURE__*/_react.default.createElement(_validationIcon.default, _extends({}, validationProps, {
230
236
  tooltipFlipOverrides: ["top", "bottom"]
231
237
  }))));
232
- };
238
+ });
233
239
 
234
240
  exports.SimpleColorPicker = SimpleColorPicker;
235
241
  SimpleColorPicker.propTypes = {
@@ -403,5 +409,6 @@ SimpleColorPicker.propTypes = {
403
409
  "value": _propTypes.default.string,
404
410
  "warning": _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.bool])
405
411
  };
412
+ SimpleColorPicker.displayName = "SimpleColorPicker";
406
413
  var _default = SimpleColorPicker;
407
414
  exports.default = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-react",
3
- "version": "114.16.0",
3
+ "version": "114.17.0",
4
4
  "description": "A library of reusable React components for easily building user interfaces.",
5
5
  "files": [
6
6
  "lib",
@@ -1,42 +0,0 @@
1
- import * as React from "react";
2
- import { MarginProps } from "styled-system";
3
-
4
- export interface AdvancedColor {
5
- label: string;
6
- value: string;
7
- }
8
-
9
- export interface AdvancedColorPickerPropTypes extends MarginProps {
10
- /** Prop to specify the aria-describedby property of the component */
11
- "aria-describedby"?: string;
12
- /** Prop to specify the aria-label of the component */
13
- "aria-label"?: string;
14
- /** Prop to specify the aria-labeledby property of the component */
15
- "aria-labelledby"?: string;
16
- /** Prop for `availableColors` containing array of objects of colors */
17
- availableColors: AdvancedColor[];
18
- /** Prop for `defaultColor` containing the default color for `uncontrolled` use */
19
- defaultColor: string;
20
- /** Specifies the name prop to be applied to each color in the group */
21
- name: string;
22
- /** Prop for `onBlur` event */
23
- onBlur?: (ev: React.FocusEvent<HTMLInputElement>) => void;
24
- /** Prop for `onChange` event */
25
- onChange?: (ev: React.ChangeEvent<HTMLElement>) => void;
26
- /** Prop for `onClose` event */
27
- onClose?: (ev: React.MouseEvent<HTMLElement>) => void;
28
- /** Prop for `onOpen` event */
29
- onOpen?: (ev: React.MouseEvent<HTMLElement>) => void;
30
- /** Prop for `open` status */
31
- open?: boolean;
32
- /** The ARIA role to be applied to the component container */
33
- role?: string;
34
- /** Prop for `selectedColor` containing pre-selected color for `controlled` use */
35
- selectedColor?: string;
36
- }
37
-
38
- declare function AdvancedColorPicker(
39
- props: AdvancedColorPickerPropTypes
40
- ): JSX.Element;
41
-
42
- export default AdvancedColorPicker;
@@ -1,42 +0,0 @@
1
- import * as React from "react";
2
- import { MarginProps } from "styled-system";
3
-
4
- export interface AdvancedColor {
5
- label: string;
6
- value: string;
7
- }
8
-
9
- export interface AdvancedColorPickerPropTypes extends MarginProps {
10
- /** Prop to specify the aria-describedby property of the component */
11
- "aria-describedby"?: string;
12
- /** Prop to specify the aria-label of the component */
13
- "aria-label"?: string;
14
- /** Prop to specify the aria-labeledby property of the component */
15
- "aria-labelledby"?: string;
16
- /** Prop for `availableColors` containing array of objects of colors */
17
- availableColors: AdvancedColor[];
18
- /** Prop for `defaultColor` containing the default color for `uncontrolled` use */
19
- defaultColor: string;
20
- /** Specifies the name prop to be applied to each color in the group */
21
- name: string;
22
- /** Prop for `onBlur` event */
23
- onBlur?: (ev: React.FocusEvent<HTMLInputElement>) => void;
24
- /** Prop for `onChange` event */
25
- onChange?: (ev: React.ChangeEvent<HTMLElement>) => void;
26
- /** Prop for `onClose` event */
27
- onClose?: (ev: React.MouseEvent<HTMLElement>) => void;
28
- /** Prop for `onOpen` event */
29
- onOpen?: (ev: React.MouseEvent<HTMLElement>) => void;
30
- /** Prop for `open` status */
31
- open?: boolean;
32
- /** The ARIA role to be applied to the component container */
33
- role?: string;
34
- /** Prop for `selectedColor` containing pre-selected color for `controlled` use */
35
- selectedColor?: string;
36
- }
37
-
38
- declare function AdvancedColorPicker(
39
- props: AdvancedColorPickerPropTypes
40
- ): JSX.Element;
41
-
42
- export default AdvancedColorPicker;