carbon-react 114.9.0 → 114.10.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 (59) hide show
  1. package/esm/__internal__/popover/popover.component.js +1 -1
  2. package/esm/components/draggable/draggable-container.component.js +4 -4
  3. package/esm/components/draggable/draggable-container.d.ts +4 -1
  4. package/esm/components/duelling-picklist/duelling-picklist.component.d.ts +21 -0
  5. package/esm/components/duelling-picklist/duelling-picklist.component.js +171 -36
  6. package/esm/components/duelling-picklist/duelling-picklist.context.d.ts +11 -0
  7. package/esm/components/duelling-picklist/duelling-picklist.context.js +6 -1
  8. package/esm/components/duelling-picklist/duelling-picklist.style.d.ts +10 -0
  9. package/esm/components/duelling-picklist/index.d.ts +12 -6
  10. package/esm/components/duelling-picklist/picklist/picklist.component.d.ts +16 -0
  11. package/esm/components/duelling-picklist/picklist/picklist.component.js +31 -39
  12. package/esm/components/duelling-picklist/picklist/picklist.style.d.ts +5 -0
  13. package/esm/components/duelling-picklist/picklist-divider/picklist-divider.component.d.ts +5 -0
  14. package/esm/components/duelling-picklist/picklist-divider/picklist-divider.component.js +4 -0
  15. package/esm/components/duelling-picklist/picklist-divider/picklist-divider.style.d.ts +2 -0
  16. package/esm/components/duelling-picklist/picklist-group/picklist-group.component.d.ts +19 -0
  17. package/esm/components/duelling-picklist/picklist-group/picklist-group.component.js +30 -32
  18. package/esm/components/duelling-picklist/picklist-group/picklist-group.style.d.ts +14 -0
  19. package/esm/components/duelling-picklist/picklist-item/picklist-item.component.d.ts +28 -0
  20. package/esm/components/duelling-picklist/picklist-item/picklist-item.component.js +16 -44
  21. package/esm/components/duelling-picklist/picklist-item/picklist-item.style.d.ts +7 -0
  22. package/esm/components/duelling-picklist/picklist-placeholder/picklist-placeholder.component.d.ts +7 -0
  23. package/esm/components/duelling-picklist/picklist-placeholder/picklist-placeholder.component.js +2 -2
  24. package/lib/__internal__/popover/popover.component.js +1 -1
  25. package/lib/components/draggable/draggable-container.component.js +4 -4
  26. package/lib/components/draggable/draggable-container.d.ts +4 -1
  27. package/lib/components/duelling-picklist/duelling-picklist.component.d.ts +21 -0
  28. package/lib/components/duelling-picklist/duelling-picklist.component.js +172 -39
  29. package/lib/components/duelling-picklist/duelling-picklist.context.d.ts +11 -0
  30. package/lib/components/duelling-picklist/duelling-picklist.context.js +6 -1
  31. package/lib/components/duelling-picklist/duelling-picklist.style.d.ts +10 -0
  32. package/lib/components/duelling-picklist/index.d.ts +12 -6
  33. package/lib/components/duelling-picklist/picklist/picklist.component.d.ts +16 -0
  34. package/lib/components/duelling-picklist/picklist/picklist.component.js +28 -44
  35. package/lib/components/duelling-picklist/picklist/picklist.style.d.ts +5 -0
  36. package/lib/components/duelling-picklist/picklist-divider/picklist-divider.component.d.ts +5 -0
  37. package/lib/components/duelling-picklist/picklist-divider/picklist-divider.component.js +5 -0
  38. package/lib/components/duelling-picklist/picklist-divider/picklist-divider.style.d.ts +2 -0
  39. package/lib/components/duelling-picklist/picklist-group/picklist-group.component.d.ts +19 -0
  40. package/lib/components/duelling-picklist/picklist-group/picklist-group.component.js +31 -33
  41. package/lib/components/duelling-picklist/picklist-group/picklist-group.style.d.ts +14 -0
  42. package/lib/components/duelling-picklist/picklist-item/picklist-item.component.d.ts +28 -0
  43. package/lib/components/duelling-picklist/picklist-item/picklist-item.component.js +17 -45
  44. package/lib/components/duelling-picklist/picklist-item/picklist-item.style.d.ts +7 -0
  45. package/lib/components/duelling-picklist/picklist-placeholder/picklist-placeholder.component.d.ts +7 -0
  46. package/lib/components/duelling-picklist/picklist-placeholder/picklist-placeholder.component.js +3 -3
  47. package/package.json +1 -1
  48. package/esm/components/duelling-picklist/duelling-picklist.d.ts +0 -24
  49. package/esm/components/duelling-picklist/picklist/picklist.d.ts +0 -19
  50. package/esm/components/duelling-picklist/picklist-divider/picklist-divider.d.ts +0 -12
  51. package/esm/components/duelling-picklist/picklist-group/picklist-group.d.ts +0 -18
  52. package/esm/components/duelling-picklist/picklist-item/picklist-item.d.ts +0 -24
  53. package/esm/components/duelling-picklist/picklist-placeholder/picklist-placeholder.d.ts +0 -10
  54. package/lib/components/duelling-picklist/duelling-picklist.d.ts +0 -24
  55. package/lib/components/duelling-picklist/picklist/picklist.d.ts +0 -19
  56. package/lib/components/duelling-picklist/picklist-divider/picklist-divider.d.ts +0 -12
  57. package/lib/components/duelling-picklist/picklist-group/picklist-group.d.ts +0 -18
  58. package/lib/components/duelling-picklist/picklist-item/picklist-item.d.ts +0 -24
  59. package/lib/components/duelling-picklist/picklist-placeholder/picklist-placeholder.d.ts +0 -10
@@ -57,7 +57,7 @@ const Popover = ({
57
57
  });
58
58
  useEffect(() => {
59
59
  return () => {
60
- if (!disablePortal) {
60
+ if (!disablePortal && elementDOM.current) {
61
61
  mountNode.removeChild(elementDOM.current);
62
62
  elementDOM.current = null;
63
63
  }
@@ -18,8 +18,8 @@ const DropTarget = ({
18
18
  const [, drop] = useDrop({
19
19
  accept: "draggableItem",
20
20
 
21
- drop() {
22
- getOrder();
21
+ drop(item) {
22
+ getOrder(item === null || item === void 0 ? void 0 : item.id);
23
23
  }
24
24
 
25
25
  });
@@ -65,13 +65,13 @@ const DraggableContainer = ({
65
65
  setDraggableItems(copyOfDraggableItems);
66
66
  };
67
67
 
68
- const getItemsId = () => {
68
+ const getItemsId = item => {
69
69
  if (!getOrder) {
70
70
  return;
71
71
  }
72
72
 
73
73
  const draggableItemIds = draggableItems.map(draggableItem => draggableItem.props.id);
74
- getOrder(draggableItemIds);
74
+ getOrder(draggableItemIds, item);
75
75
  };
76
76
 
77
77
  const marginProps = filterStyledSystemMarginProps(rest);
@@ -9,7 +9,10 @@ type DraggableContainerChild =
9
9
 
10
10
  export interface DraggableContainerProps {
11
11
  /** Callback fired when order is changed */
12
- getOrder?: (draggableItemIds: number[]) => void;
12
+ getOrder?: (
13
+ draggableItemIds: (number | string)[],
14
+ movedItemId: string | number
15
+ ) => void;
13
16
  /**
14
17
  * The content of the component
15
18
  *
@@ -0,0 +1,21 @@
1
+ import React from "react";
2
+ import { MarginProps } from "styled-system";
3
+ export interface DuellingPicklistProps extends MarginProps {
4
+ /**
5
+ * Content of the component, should contain two Picklist children
6
+ * and a PicklistDivider
7
+ */
8
+ children?: React.ReactNode;
9
+ /** Indicate if component is disabled */
10
+ disabled?: boolean;
11
+ /** Place for components like Search or Filter placed above the left list */
12
+ leftControls?: React.ReactNode;
13
+ /** Left list label */
14
+ leftLabel?: string;
15
+ /** Place for components like Search or Filter placed above the right list */
16
+ rightControls?: React.ReactNode;
17
+ /** Right list label */
18
+ rightLabel?: string;
19
+ }
20
+ export declare const DuellingPicklist: ({ children, disabled, leftControls, rightControls, leftLabel, rightLabel, ...rest }: DuellingPicklistProps) => JSX.Element;
21
+ export default DuellingPicklist;
@@ -2,12 +2,10 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
2
2
 
3
3
  import React, { useState } from "react";
4
4
  import PropTypes from "prop-types";
5
- import styledSystemPropTypes from "@styled-system/prop-types";
6
5
  import { filterStyledSystemMarginProps } from "../../style/utils";
7
6
  import { StyledDuellingPicklistOverlay, StyledDuellingPicklist, StyledLabelContainer, StyledLabel, StyledControlsContainer, StyledControl } from "./duelling-picklist.style";
8
7
  import { Picklist } from "./picklist/picklist.component";
9
8
  import FocusContext from "./duelling-picklist.context";
10
- const marginPropTypes = filterStyledSystemMarginProps(styledSystemPropTypes.space);
11
9
 
12
10
  const DuellingPicklist = ({
13
11
  children,
@@ -37,9 +35,15 @@ const DuellingPicklist = ({
37
35
  return index;
38
36
  };
39
37
 
40
- const clonedChildren = React.Children.map(children, child => child && /*#__PURE__*/React.cloneElement(child, {
41
- index: child.type === Picklist ? getIndex() : undefined
42
- }));
38
+ const clonedChildren = React.Children.map(children, child => {
39
+ if ( /*#__PURE__*/React.isValidElement(child) && child.type === Picklist) {
40
+ return /*#__PURE__*/React.cloneElement(child, {
41
+ index: getIndex()
42
+ });
43
+ }
44
+
45
+ return child;
46
+ });
43
47
  return /*#__PURE__*/React.createElement(StyledDuellingPicklistOverlay, _extends({
44
48
  disabled: disabled,
45
49
  "data-component": "duelling-picklist"
@@ -59,36 +63,167 @@ const DuellingPicklist = ({
59
63
  }, /*#__PURE__*/React.createElement(StyledDuellingPicklist, null, clonedChildren)));
60
64
  };
61
65
 
62
- DuellingPicklist.propTypes = { ...marginPropTypes,
63
-
64
- /**
65
- * Content of the component, should contain two Picklist children
66
- * and a PicklistDivider
67
- */
68
- children: (props, propName) => {
69
- const prop = props[propName];
70
- let error;
71
-
72
- if (!prop || !Array.isArray(prop) || prop.filter(el => el.type === Picklist).length !== 2) {
73
- error = new Error(`\`${propName}\` must have two \`${Picklist.displayName}\`s`);
74
- }
75
-
76
- return error;
77
- },
78
-
79
- /** Indicate if component is disabled */
80
- disabled: PropTypes.bool,
81
-
82
- /** Place for components like Search or Filter placed above the left list */
83
- leftControls: PropTypes.node,
84
-
85
- /** Place for components like Search or Filter placed above the right list */
86
- rightControls: PropTypes.node,
87
-
88
- /** Left list label */
89
- leftLabel: PropTypes.string,
90
-
91
- /** Right list label */
92
- rightLabel: PropTypes.string
66
+ DuellingPicklist.propTypes = {
67
+ "children": PropTypes.node,
68
+ "disabled": PropTypes.bool,
69
+ "leftControls": PropTypes.node,
70
+ "leftLabel": PropTypes.string,
71
+ "m": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.number, PropTypes.shape({
72
+ "__@toStringTag": PropTypes.string.isRequired,
73
+ "description": PropTypes.string,
74
+ "toString": PropTypes.func.isRequired,
75
+ "valueOf": PropTypes.func.isRequired
76
+ }), PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.shape({
77
+ "__@toStringTag": PropTypes.string.isRequired,
78
+ "description": PropTypes.string,
79
+ "toString": PropTypes.func.isRequired,
80
+ "valueOf": PropTypes.func.isRequired
81
+ }), PropTypes.string]),
82
+ "margin": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.number, PropTypes.shape({
83
+ "__@toStringTag": PropTypes.string.isRequired,
84
+ "description": PropTypes.string,
85
+ "toString": PropTypes.func.isRequired,
86
+ "valueOf": PropTypes.func.isRequired
87
+ }), PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.shape({
88
+ "__@toStringTag": PropTypes.string.isRequired,
89
+ "description": PropTypes.string,
90
+ "toString": PropTypes.func.isRequired,
91
+ "valueOf": PropTypes.func.isRequired
92
+ }), PropTypes.string]),
93
+ "marginBottom": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.number, PropTypes.shape({
94
+ "__@toStringTag": PropTypes.string.isRequired,
95
+ "description": PropTypes.string,
96
+ "toString": PropTypes.func.isRequired,
97
+ "valueOf": PropTypes.func.isRequired
98
+ }), PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.shape({
99
+ "__@toStringTag": PropTypes.string.isRequired,
100
+ "description": PropTypes.string,
101
+ "toString": PropTypes.func.isRequired,
102
+ "valueOf": PropTypes.func.isRequired
103
+ }), PropTypes.string]),
104
+ "marginLeft": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.number, PropTypes.shape({
105
+ "__@toStringTag": PropTypes.string.isRequired,
106
+ "description": PropTypes.string,
107
+ "toString": PropTypes.func.isRequired,
108
+ "valueOf": PropTypes.func.isRequired
109
+ }), PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.shape({
110
+ "__@toStringTag": PropTypes.string.isRequired,
111
+ "description": PropTypes.string,
112
+ "toString": PropTypes.func.isRequired,
113
+ "valueOf": PropTypes.func.isRequired
114
+ }), PropTypes.string]),
115
+ "marginRight": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.number, PropTypes.shape({
116
+ "__@toStringTag": PropTypes.string.isRequired,
117
+ "description": PropTypes.string,
118
+ "toString": PropTypes.func.isRequired,
119
+ "valueOf": PropTypes.func.isRequired
120
+ }), PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.shape({
121
+ "__@toStringTag": PropTypes.string.isRequired,
122
+ "description": PropTypes.string,
123
+ "toString": PropTypes.func.isRequired,
124
+ "valueOf": PropTypes.func.isRequired
125
+ }), PropTypes.string]),
126
+ "marginTop": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.number, PropTypes.shape({
127
+ "__@toStringTag": PropTypes.string.isRequired,
128
+ "description": PropTypes.string,
129
+ "toString": PropTypes.func.isRequired,
130
+ "valueOf": PropTypes.func.isRequired
131
+ }), PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.shape({
132
+ "__@toStringTag": PropTypes.string.isRequired,
133
+ "description": PropTypes.string,
134
+ "toString": PropTypes.func.isRequired,
135
+ "valueOf": PropTypes.func.isRequired
136
+ }), PropTypes.string]),
137
+ "marginX": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.number, PropTypes.shape({
138
+ "__@toStringTag": PropTypes.string.isRequired,
139
+ "description": PropTypes.string,
140
+ "toString": PropTypes.func.isRequired,
141
+ "valueOf": PropTypes.func.isRequired
142
+ }), PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.shape({
143
+ "__@toStringTag": PropTypes.string.isRequired,
144
+ "description": PropTypes.string,
145
+ "toString": PropTypes.func.isRequired,
146
+ "valueOf": PropTypes.func.isRequired
147
+ }), PropTypes.string]),
148
+ "marginY": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.number, PropTypes.shape({
149
+ "__@toStringTag": PropTypes.string.isRequired,
150
+ "description": PropTypes.string,
151
+ "toString": PropTypes.func.isRequired,
152
+ "valueOf": PropTypes.func.isRequired
153
+ }), PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.shape({
154
+ "__@toStringTag": PropTypes.string.isRequired,
155
+ "description": PropTypes.string,
156
+ "toString": PropTypes.func.isRequired,
157
+ "valueOf": PropTypes.func.isRequired
158
+ }), PropTypes.string]),
159
+ "mb": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.number, PropTypes.shape({
160
+ "__@toStringTag": PropTypes.string.isRequired,
161
+ "description": PropTypes.string,
162
+ "toString": PropTypes.func.isRequired,
163
+ "valueOf": PropTypes.func.isRequired
164
+ }), PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.shape({
165
+ "__@toStringTag": PropTypes.string.isRequired,
166
+ "description": PropTypes.string,
167
+ "toString": PropTypes.func.isRequired,
168
+ "valueOf": PropTypes.func.isRequired
169
+ }), PropTypes.string]),
170
+ "ml": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.number, PropTypes.shape({
171
+ "__@toStringTag": PropTypes.string.isRequired,
172
+ "description": PropTypes.string,
173
+ "toString": PropTypes.func.isRequired,
174
+ "valueOf": PropTypes.func.isRequired
175
+ }), PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.shape({
176
+ "__@toStringTag": PropTypes.string.isRequired,
177
+ "description": PropTypes.string,
178
+ "toString": PropTypes.func.isRequired,
179
+ "valueOf": PropTypes.func.isRequired
180
+ }), PropTypes.string]),
181
+ "mr": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.number, PropTypes.shape({
182
+ "__@toStringTag": PropTypes.string.isRequired,
183
+ "description": PropTypes.string,
184
+ "toString": PropTypes.func.isRequired,
185
+ "valueOf": PropTypes.func.isRequired
186
+ }), PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.shape({
187
+ "__@toStringTag": PropTypes.string.isRequired,
188
+ "description": PropTypes.string,
189
+ "toString": PropTypes.func.isRequired,
190
+ "valueOf": PropTypes.func.isRequired
191
+ }), PropTypes.string]),
192
+ "mt": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.number, PropTypes.shape({
193
+ "__@toStringTag": PropTypes.string.isRequired,
194
+ "description": PropTypes.string,
195
+ "toString": PropTypes.func.isRequired,
196
+ "valueOf": PropTypes.func.isRequired
197
+ }), PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.shape({
198
+ "__@toStringTag": PropTypes.string.isRequired,
199
+ "description": PropTypes.string,
200
+ "toString": PropTypes.func.isRequired,
201
+ "valueOf": PropTypes.func.isRequired
202
+ }), PropTypes.string]),
203
+ "mx": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.number, PropTypes.shape({
204
+ "__@toStringTag": PropTypes.string.isRequired,
205
+ "description": PropTypes.string,
206
+ "toString": PropTypes.func.isRequired,
207
+ "valueOf": PropTypes.func.isRequired
208
+ }), PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.shape({
209
+ "__@toStringTag": PropTypes.string.isRequired,
210
+ "description": PropTypes.string,
211
+ "toString": PropTypes.func.isRequired,
212
+ "valueOf": PropTypes.func.isRequired
213
+ }), PropTypes.string]),
214
+ "my": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.number, PropTypes.shape({
215
+ "__@toStringTag": PropTypes.string.isRequired,
216
+ "description": PropTypes.string,
217
+ "toString": PropTypes.func.isRequired,
218
+ "valueOf": PropTypes.func.isRequired
219
+ }), PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.shape({
220
+ "__@toStringTag": PropTypes.string.isRequired,
221
+ "description": PropTypes.string,
222
+ "toString": PropTypes.func.isRequired,
223
+ "valueOf": PropTypes.func.isRequired
224
+ }), PropTypes.string]),
225
+ "rightControls": PropTypes.node,
226
+ "rightLabel": PropTypes.string
93
227
  };
228
+ export { DuellingPicklist };
94
229
  export default DuellingPicklist;
@@ -0,0 +1,11 @@
1
+ import React from "react";
2
+ export declare type FocusContextType = {
3
+ setElementToFocus: (itemIndex?: number, listIndex?: number, groupIndex?: number) => void;
4
+ elementToFocus: {
5
+ itemIndex?: number;
6
+ listIndex?: number;
7
+ groupIndex?: number;
8
+ };
9
+ };
10
+ declare const FocusContext: React.Context<FocusContextType>;
11
+ export default FocusContext;
@@ -1,3 +1,8 @@
1
1
  import React from "react";
2
- const FocusContext = /*#__PURE__*/React.createContext({});
2
+ const FocusContext = /*#__PURE__*/React.createContext({
3
+ setElementToFocus:
4
+ /* istanbul ignore next */
5
+ () => {},
6
+ elementToFocus: {}
7
+ });
3
8
  export default FocusContext;
@@ -0,0 +1,10 @@
1
+ declare const StyledDuellingPicklistOverlay: import("styled-components").StyledComponent<"div", any, {
2
+ disabled?: boolean | undefined;
3
+ }, never>;
4
+ declare const StyledDuellingPicklist: import("styled-components").StyledComponent<"div", any, {}, never>;
5
+ declare const StyledLabelContainer: import("styled-components").StyledComponent<"div", any, {}, never>;
6
+ declare const StyledLabel: import("styled-components").StyledComponent<"p", any, {}, never>;
7
+ declare const StyledControlsContainer: import("styled-components").StyledComponent<"div", any, {}, never>;
8
+ declare const StyledControl: import("styled-components").StyledComponent<"div", any, {}, never>;
9
+ declare const StyledPicklistPlaceholder: import("styled-components").StyledComponent<"div", any, {}, never>;
10
+ export { StyledDuellingPicklist, StyledDuellingPicklistOverlay, StyledLabelContainer, StyledLabel, StyledControlsContainer, StyledControl, StyledPicklistPlaceholder, };
@@ -1,6 +1,12 @@
1
- export { default as DuellingPicklist } from "./duelling-picklist";
2
- export { default as PicklistDivider } from "./picklist-divider/picklist-divider";
3
- export { default as PicklistItem } from "./picklist-item/picklist-item";
4
- export { default as Picklist } from "./picklist/picklist";
5
- export { default as PicklistPlaceholder } from "./picklist-placeholder/picklist-placeholder";
6
- export { default as PicklistGroup } from "./picklist-group/picklist-group";
1
+ export { default as DuellingPicklist } from "./duelling-picklist.component";
2
+ export type { DuellingPicklistProps } from "./duelling-picklist.component";
3
+ export { default as PicklistDivider } from "./picklist-divider/picklist-divider.component";
4
+ export type { PicklistDividerProps } from "./picklist-divider/picklist-divider.component";
5
+ export { default as PicklistItem } from "./picklist-item/picklist-item.component";
6
+ export type { PicklistItemProps } from "./picklist-item/picklist-item.component";
7
+ export { default as Picklist } from "./picklist/picklist.component";
8
+ export type { PicklistProps } from "./picklist/picklist.component";
9
+ export { default as PicklistPlaceholder } from "./picklist-placeholder/picklist-placeholder.component";
10
+ export type { PicklistPlaceholderProps } from "./picklist-placeholder/picklist-placeholder.component";
11
+ export { default as PicklistGroup } from "./picklist-group/picklist-group.component";
12
+ export type { PicklistGroupProps } from "./picklist-group/picklist-group.component";
@@ -0,0 +1,16 @@
1
+ import React from "react";
2
+ export interface PicklistProps {
3
+ /** List of PicklistItem elements */
4
+ children?: React.ReactNode;
5
+ /** Placeholder to be rendered when list is empty */
6
+ placeholder?: React.ReactNode;
7
+ /** Indicate if component is disabled */
8
+ disabled?: boolean;
9
+ /** @private @ignore */
10
+ index?: number;
11
+ }
12
+ export declare const Picklist: {
13
+ ({ disabled, children, placeholder, index, }: PicklistProps): JSX.Element;
14
+ displayName: string;
15
+ };
16
+ export default Picklist;
@@ -5,7 +5,8 @@ import { StyledPicklist, StyledEmptyContainer } from "./picklist.style";
5
5
  import FocusContext from "../duelling-picklist.context";
6
6
  import Events from "../../../__internal__/utils/helpers/events";
7
7
  import PicklistGroup from "../picklist-group/picklist-group.component";
8
- export const Picklist = ({
8
+
9
+ const Picklist = ({
9
10
  disabled,
10
11
  children,
11
12
  placeholder,
@@ -21,8 +22,10 @@ export const Picklist = ({
21
22
  length: filteredChildren.length
22
23
  }, () => /*#__PURE__*/React.createRef()), [filteredChildren.length]);
23
24
  const focusItem = useCallback((ev, itemIndex) => {
25
+ var _refs$itemIndex$curre;
26
+
24
27
  ev.preventDefault();
25
- refs[itemIndex].current.focus();
28
+ (_refs$itemIndex$curre = refs[itemIndex].current) === null || _refs$itemIndex$curre === void 0 ? void 0 : _refs$itemIndex$curre.focus();
26
29
  }, [refs]);
27
30
  const handleKeyDown = useCallback(ev => {
28
31
  if (Events.isHomeKey(ev)) {
@@ -31,22 +34,31 @@ export const Picklist = ({
31
34
  focusItem(ev, refs.length - 1);
32
35
  }
33
36
  }, [focusItem, refs]);
34
- const content = filteredChildren.map((child, childIndex) => child && /*#__PURE__*/React.cloneElement(child, {
35
- ref: refs[childIndex],
36
- disabled,
37
- index: childIndex,
38
- listIndex: index,
39
- isLastGroup: child.type === PicklistGroup && childIndex === filteredChildren.length - 1
40
- }));
37
+ const content = filteredChildren.map((child, childIndex) => {
38
+ if (! /*#__PURE__*/React.isValidElement(child)) {
39
+ return child;
40
+ }
41
+
42
+ const props = {
43
+ ref: refs[childIndex],
44
+ disabled,
45
+ index: childIndex,
46
+ listIndex: index,
47
+ isLastGroup: child.type === PicklistGroup && childIndex === filteredChildren.length - 1
48
+ };
49
+ return /*#__PURE__*/React.cloneElement(child, props);
50
+ });
41
51
  useEffect(() => {
42
- if ((elementToFocus === null || elementToFocus === void 0 ? void 0 : elementToFocus.groupIndex) === undefined && index === (elementToFocus === null || elementToFocus === void 0 ? void 0 : elementToFocus.listIndex)) {
52
+ if (elementToFocus.groupIndex === undefined && elementToFocus.listIndex === index && elementToFocus.itemIndex !== undefined) {
43
53
  var _refs$elementToFocus$;
44
54
 
45
- if ((_refs$elementToFocus$ = refs[elementToFocus === null || elementToFocus === void 0 ? void 0 : elementToFocus.itemIndex]) !== null && _refs$elementToFocus$ !== void 0 && _refs$elementToFocus$.current) {
46
- refs[elementToFocus.itemIndex].current.focus();
55
+ const itemToBeFocused = (_refs$elementToFocus$ = refs[elementToFocus.itemIndex]) === null || _refs$elementToFocus$ === void 0 ? void 0 : _refs$elementToFocus$.current;
56
+
57
+ if (itemToBeFocused) {
58
+ itemToBeFocused.focus();
47
59
  setElementToFocus();
48
60
  } else {
49
- setElementToFocus(0, index === 0 ? 1 : 0, elementToFocus === null || elementToFocus === void 0 ? void 0 : elementToFocus.groupIndex);
61
+ setElementToFocus(0, index === 0 ? 1 : 0, elementToFocus.groupIndex);
50
62
  }
51
63
  }
52
64
  }, [elementToFocus, index, refs, setElementToFocus]);
@@ -58,33 +70,13 @@ export const Picklist = ({
58
70
  component: null
59
71
  }, content));
60
72
  };
61
- Picklist.propTypes = {
62
- /** List of PicklistItem elements */
63
- children: PropTypes.node,
64
-
65
- /** Placeholder to be rendered when list is empty */
66
- placeholder: PropTypes.node,
67
73
 
68
- /** Indicate if component is disabled */
69
- disabled: PropTypes.bool,
70
-
71
- /** @private @ignore */
72
- index: PropTypes.number
73
- };
74
- export const areEqual = (prevProps, nextProps) => {
75
- let changesCounter = 0;
76
- const prevChildCount = React.Children.count(prevProps.children);
77
- const nextChildCount = React.Children.count(nextProps.children);
78
-
79
- if (prevChildCount !== nextChildCount) {
80
- changesCounter += 1;
81
- }
82
-
83
- if (prevProps.disabled !== nextProps.disabled) {
84
- changesCounter += 1;
85
- }
86
-
87
- return !changesCounter;
74
+ Picklist.propTypes = {
75
+ "children": PropTypes.node,
76
+ "disabled": PropTypes.bool,
77
+ "index": PropTypes.number,
78
+ "placeholder": PropTypes.node
88
79
  };
80
+ export { Picklist };
89
81
  Picklist.displayName = "Picklist";
90
82
  export default Picklist;
@@ -0,0 +1,5 @@
1
+ declare const StyledPicklist: import("styled-components").StyledComponent<"div", any, import("../../box").BoxProps & {
2
+ as: string;
3
+ }, "as">;
4
+ declare const StyledEmptyContainer: import("styled-components").StyledComponent<"li", any, {}, never>;
5
+ export { StyledPicklist, StyledEmptyContainer };
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import { StyledComponentProps } from "styled-components";
3
+ export declare type PicklistDividerProps = StyledComponentProps<"div", Record<string, unknown>, Record<string, unknown>, "">;
4
+ declare const PicklistDivider: (props: PicklistDividerProps) => JSX.Element;
5
+ export default PicklistDivider;
@@ -1,10 +1,14 @@
1
1
  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); }
2
2
 
3
3
  import React from "react";
4
+ import PropTypes from "prop-types";
4
5
  import StyledPicklistDivider from "./picklist-divider.style";
5
6
 
6
7
  const PicklistDivider = props => /*#__PURE__*/React.createElement(StyledPicklistDivider, _extends({}, props, {
7
8
  "data-element": "picklist-divider"
8
9
  }));
9
10
 
11
+ PicklistDivider.propTypes = {
12
+ "theme": PropTypes.object
13
+ };
10
14
  export default PicklistDivider;
@@ -0,0 +1,2 @@
1
+ declare const StyledPicklistDivider: import("styled-components").StyledComponent<"div", any, {}, never>;
2
+ export default StyledPicklistDivider;
@@ -0,0 +1,19 @@
1
+ import React from "react";
2
+ export interface PicklistGroupProps {
3
+ /** Group title */
4
+ title: React.ReactNode;
5
+ /** Item content */
6
+ children: React.ReactNode;
7
+ /** Define if item is of type add or remove */
8
+ type: "add" | "remove";
9
+ /** Handler invoked when add/remove button is clicked or when space/enter is pressed on the whole item */
10
+ onChange: () => void;
11
+ /** @private @ignore */
12
+ index?: number;
13
+ /** @private @ignore */
14
+ listIndex?: number;
15
+ /** @private @ignore */
16
+ isLastGroup?: boolean;
17
+ }
18
+ export declare const PicklistGroup: React.ForwardRefExoticComponent<PicklistGroupProps & React.RefAttributes<HTMLButtonElement>>;
19
+ export default PicklistGroup;
@@ -14,7 +14,7 @@ const PicklistGroup = /*#__PURE__*/React.forwardRef(({
14
14
  index,
15
15
  listIndex,
16
16
  isLastGroup,
17
- ...rest
17
+ ...transitionGroupProps
18
18
  }, ref) => {
19
19
  const {
20
20
  setElementToFocus,
@@ -36,17 +36,26 @@ const PicklistGroup = /*#__PURE__*/React.forwardRef(({
36
36
  const refs = useMemo(() => Array.from({
37
37
  length: filteredChildren.length
38
38
  }, () => /*#__PURE__*/React.createRef()), [filteredChildren.length]);
39
- const content = React.Children.map(children, (child, childIndex) => child && /*#__PURE__*/React.cloneElement(child, {
40
- ref: refs[childIndex],
41
- index: childIndex,
42
- listIndex,
43
- groupIndex: index,
44
- isLastGroup,
45
- isLastItem: childIndex === filteredChildren.length - 1
46
- }));
39
+ const content = React.Children.map(children, (child, childIndex) => {
40
+ if (! /*#__PURE__*/React.isValidElement(child)) {
41
+ return child;
42
+ }
43
+
44
+ const props = {
45
+ ref: refs[childIndex],
46
+ index: childIndex,
47
+ listIndex,
48
+ groupIndex: index,
49
+ isLastGroup,
50
+ isLastItem: childIndex === filteredChildren.length - 1
51
+ };
52
+ return /*#__PURE__*/React.cloneElement(child, props);
53
+ });
47
54
  useEffect(() => {
48
- if (index === (elementToFocus === null || elementToFocus === void 0 ? void 0 : elementToFocus.groupIndex) && listIndex === (elementToFocus === null || elementToFocus === void 0 ? void 0 : elementToFocus.listIndex)) {
49
- refs[elementToFocus === null || elementToFocus === void 0 ? void 0 : elementToFocus.itemIndex].current.focus();
55
+ if (elementToFocus.groupIndex === index && elementToFocus.listIndex === listIndex && elementToFocus.itemIndex !== undefined) {
56
+ var _refs$elementToFocus$;
57
+
58
+ (_refs$elementToFocus$ = refs[elementToFocus.itemIndex].current) === null || _refs$elementToFocus$ === void 0 ? void 0 : _refs$elementToFocus$.focus();
50
59
  setElementToFocus();
51
60
  }
52
61
  }, [elementToFocus, index, isLastGroup, listIndex, refs, setElementToFocus]);
@@ -57,7 +66,7 @@ const PicklistGroup = /*#__PURE__*/React.forwardRef(({
57
66
  exit: 0
58
67
  },
59
68
  classNames: "picklist-group"
60
- }, rest, type === "add" ? {
69
+ }, transitionGroupProps, type === "add" ? {
61
70
  enter: false
62
71
  } : {}), /*#__PURE__*/React.createElement(StyledGroupWrapper, {
63
72
  highlighted: highlighted,
@@ -80,25 +89,14 @@ const PicklistGroup = /*#__PURE__*/React.forwardRef(({
80
89
  }, content))));
81
90
  });
82
91
  PicklistGroup.propTypes = {
83
- /** Group title */
84
- title: PropTypes.node.isRequired,
85
-
86
- /** Item content */
87
- children: PropTypes.node.isRequired,
88
-
89
- /** Define if item is of type add or remove */
90
- type: PropTypes.oneOf(["add", "remove"]).isRequired,
91
-
92
- /** Handler invoked when add/remove button is clicked or when space/enter is pressed on the whole item */
93
- onChange: PropTypes.func.isRequired,
94
-
95
- /** @private @ignore */
96
- index: PropTypes.number,
97
-
98
- /** @private @ignore */
99
- listIndex: PropTypes.number,
100
-
101
- /** @private @ignore */
102
- isLastGroup: PropTypes.bool
92
+ "children": PropTypes.node,
93
+ "index": PropTypes.number,
94
+ "isLastGroup": PropTypes.bool,
95
+ "listIndex": PropTypes.number,
96
+ "onChange": PropTypes.func.isRequired,
97
+ "title": PropTypes.node,
98
+ "type": PropTypes.oneOf(["add", "remove"]).isRequired
103
99
  };
100
+ export { PicklistGroup };
101
+ PicklistGroup.displayName = "PicklistGroup";
104
102
  export default PicklistGroup;
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ import { PicklistGroupProps } from "./picklist-group.component";
3
+ declare const StyledGroupWrapper: import("styled-components").StyledComponent<"li", any, {
4
+ highlighted: boolean;
5
+ type: PicklistGroupProps["type"];
6
+ }, never>;
7
+ declare const StyledPicklistGroupUl: import("styled-components").StyledComponent<"ul", any, {}, never>;
8
+ declare const StyledPicklistGroup: import("styled-components").StyledComponent<"li", any, {}, never>;
9
+ declare const StyledGroupButton: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("../../button").ButtonProps & import("react").RefAttributes<HTMLButtonElement>>, any, {
10
+ onMouseEnter: (e: React.MouseEvent<HTMLButtonElement>) => void;
11
+ onMouseLeave: (e: React.MouseEvent<HTMLButtonElement>) => void;
12
+ iconType: PicklistGroupProps["type"];
13
+ }, never>;
14
+ export { StyledGroupWrapper, StyledPicklistGroupUl, StyledPicklistGroup, StyledGroupButton, };