@carbon/ibm-products 2.43.2-canary.56 → 2.43.2-canary.57

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 (21) hide show
  1. package/es/components/ConditionBuilder/ConditionBlock/ConditionBlock.js +16 -13
  2. package/es/components/ConditionBuilder/ConditionBuilder.js +1 -1
  3. package/es/components/ConditionBuilder/ConditionBuilderContext/DataConfigs.js +5 -3
  4. package/es/components/ConditionBuilder/ConditionBuilderContext/translationObject.d.ts +1 -0
  5. package/es/components/ConditionBuilder/ConditionBuilderContext/translationObject.js +1 -0
  6. package/es/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItem.d.ts +3 -1
  7. package/es/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItem.js +33 -15
  8. package/es/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItemDate/ConditionBuilderItemDate.d.ts +3 -1
  9. package/es/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItemDate/ConditionBuilderItemDate.js +16 -6
  10. package/es/components/Tearsheet/TearsheetShell.js +2 -2
  11. package/lib/components/ConditionBuilder/ConditionBlock/ConditionBlock.js +16 -13
  12. package/lib/components/ConditionBuilder/ConditionBuilder.js +1 -1
  13. package/lib/components/ConditionBuilder/ConditionBuilderContext/DataConfigs.js +5 -3
  14. package/lib/components/ConditionBuilder/ConditionBuilderContext/translationObject.d.ts +1 -0
  15. package/lib/components/ConditionBuilder/ConditionBuilderContext/translationObject.js +1 -0
  16. package/lib/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItem.d.ts +3 -1
  17. package/lib/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItem.js +33 -15
  18. package/lib/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItemDate/ConditionBuilderItemDate.d.ts +3 -1
  19. package/lib/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItemDate/ConditionBuilderItemDate.js +16 -6
  20. package/lib/components/Tearsheet/TearsheetShell.js +2 -2
  21. package/package.json +3 -3
@@ -139,11 +139,23 @@ var ConditionBlock = function ConditionBlock(props) {
139
139
  'aria-setsize': aria.setsize
140
140
  } : {};
141
141
  };
142
+ var renderChildren = function renderChildren(popoverRef) {
143
+ return /*#__PURE__*/React__default.createElement(ItemComponent, {
144
+ conditionState: {
145
+ property: property,
146
+ operator: operator,
147
+ value: value
148
+ },
149
+ onChange: onValueChangeHandler,
150
+ config: config,
151
+ "data-name": "valueField",
152
+ parentRef: popoverRef
153
+ });
154
+ };
142
155
  return /*#__PURE__*/React__default.createElement("div", _extends({
143
156
  className: cx("".concat(blockClass, "__condition-block"), _defineProperty({}, "".concat(blockClass, "__condition__deletion-preview"), showDeletionPreview), _defineProperty({}, "".concat(blockClass, "__gap-bottom"), variant == 'tree' && !(conditionIndex + 1 >= group.conditions.length)), _defineProperty({}, "".concat(blockClass, "__gap ").concat(blockClass, "__gap-bottom"), variant == 'sentence')),
144
157
  role: "row",
145
- "aria-label": conditionRowText,
146
- tabIndex: -1
158
+ "aria-label": conditionRowText
147
159
  }, getAriaAttributes()), conjunction ? /*#__PURE__*/React__default.createElement(ConditionConnector, {
148
160
  className: "".concat(blockClass, "__gap"),
149
161
  operator: conjunction,
@@ -206,18 +218,9 @@ var ConditionBlock = function ConditionBlock(props) {
206
218
  showToolTip: true,
207
219
  "data-name": "valueField",
208
220
  condition: condition,
209
- config: config
210
- }, /*#__PURE__*/React__default.createElement(ItemComponent, {
211
- conditionState: {
212
- property: property,
213
- operator: operator,
214
- value: value
215
- },
216
- onChange: onValueChangeHandler,
217
221
  config: config,
218
- type: type,
219
- "data-name": "valueField"
220
- })), /*#__PURE__*/React__default.createElement("span", {
222
+ renderChildren: renderChildren
223
+ }), /*#__PURE__*/React__default.createElement("span", {
221
224
  role: "gridcell",
222
225
  "aria-label": removeConditionText
223
226
  }, /*#__PURE__*/React__default.createElement(ConditionBuilderButton, {
@@ -202,7 +202,7 @@ ConditionBuilder.propTypes = {
202
202
  /**
203
203
  * Optional prop, if you need to pass translations to the texts on the component instead of the defined defaults.
204
204
  * This callback function will receive the message id and you need to return the corresponding text for that id.
205
- * The message id will be one of [ "ifText","addConditionText", "addConditionGroupText", "addSubgroupText", "conditionText", "propertyText", "operatorText", "valueText", "connectorText", "conditionRowText", "removeConditionText", "addConditionRowText", "startText", "endText", "clearSearchText", "actionsText", "then", "removeActionText", "addActionText", "invalidText", "invalidNumberWarnText"]
205
+ * The message id will be one of [ "ifText","addConditionText", "addConditionGroupText", "addSubgroupText", "conditionText", "propertyText", "operatorText", "valueText", "connectorText", "conditionRowText", "removeConditionText", "addConditionRowText", "startText", "endText", "clearSearchText", "actionsText", "then", "removeActionText", "addActionText", "invalidText", "invalidDateText", "invalidNumberWarnText"]
206
206
  ]
207
207
  */
208
208
  translateWithId: PropTypes.func,
@@ -106,11 +106,13 @@ var valueRenderers = {
106
106
  },
107
107
  date: function date(value) {
108
108
  if (Array.isArray(value) && value.length > 1) {
109
- var start = value !== null && value !== void 0 && value[0] ? formatDate(new Date(value[0])) : '';
110
- var end = value !== null && value !== void 0 && value[1] ? formatDate(new Date(value[1])) : '';
109
+ var start = value !== null && value !== void 0 && value[0] && !isNaN(new Date(value[0])) ? formatDate(new Date(value[0])) : '';
110
+ var end = value !== null && value !== void 0 && value[1] && !isNaN(new Date(value[1])) ? formatDate(new Date(value[1])) : '';
111
111
  return "".concat(start, " To ").concat(end);
112
+ } else if (Array.isArray(value) && !isNaN(new Date(value[0]))) {
113
+ return formatDate(new Date(value[0]));
112
114
  } else {
113
- return value && new Date(value) ? formatDate(new Date(value)) : value;
115
+ return value;
114
116
  }
115
117
  },
116
118
  custom: function custom(value) {
@@ -34,5 +34,6 @@ export namespace translationsObject {
34
34
  let removeActionText: string;
35
35
  let addActionText: string;
36
36
  let invalidText: string;
37
+ let invalidDateText: string;
37
38
  let invalidNumberWarnText: string;
38
39
  }
@@ -41,6 +41,7 @@ var translationsObject = {
41
41
  removeActionText: 'Remove Action',
42
42
  addActionText: 'Add action',
43
43
  invalidText: 'Incomplete',
44
+ invalidDateText: 'Invalid Date',
44
45
  invalidNumberWarnText: 'Invalid number, must be 0 or greater'
45
46
  };
46
47
 
@@ -1,4 +1,4 @@
1
- export function ConditionBuilderItem({ children, className, label, renderIcon, title, type, showToolTip, condition, popOverClassName, config, ...rest }: {
1
+ export function ConditionBuilderItem({ children, className, label, renderIcon, title, type, showToolTip, condition, popOverClassName, config, renderChildren, ...rest }: {
2
2
  [x: string]: any;
3
3
  children: any;
4
4
  className: any;
@@ -10,6 +10,7 @@ export function ConditionBuilderItem({ children, className, label, renderIcon, t
10
10
  condition: any;
11
11
  popOverClassName: any;
12
12
  config: any;
13
+ renderChildren: any;
13
14
  }): import("react/jsx-runtime").JSX.Element;
14
15
  export namespace ConditionBuilderItem {
15
16
  namespace propTypes {
@@ -19,6 +20,7 @@ export namespace ConditionBuilderItem {
19
20
  let config: PropTypes.Requireable<object>;
20
21
  let label: PropTypes.Requireable<NonNullable<string | object | null | undefined>>;
21
22
  let popOverClassName: PropTypes.Requireable<string>;
23
+ let renderChildren: PropTypes.Requireable<(...args: any[]) => any>;
22
24
  let renderIcon: PropTypes.Requireable<object>;
23
25
  let showToolTip: PropTypes.Requireable<boolean>;
24
26
  let title: PropTypes.Requireable<string>;
@@ -14,7 +14,7 @@ import { blockClass, valueRenderers } from '../ConditionBuilderContext/DataConfi
14
14
  import { ConditionBuilderButton } from '../ConditionBuilderButton/ConditionBuilderButton.js';
15
15
  import { useTranslations } from '../utils/useTranslations.js';
16
16
 
17
- var _excluded = ["children", "className", "label", "renderIcon", "title", "type", "showToolTip", "condition", "popOverClassName", "config"];
17
+ var _excluded = ["children", "className", "label", "renderIcon", "title", "type", "showToolTip", "condition", "popOverClassName", "config", "renderChildren"];
18
18
  var ConditionBuilderItem = function ConditionBuilderItem(_ref) {
19
19
  var children = _ref.children,
20
20
  className = _ref.className,
@@ -26,23 +26,31 @@ var ConditionBuilderItem = function ConditionBuilderItem(_ref) {
26
26
  condition = _ref.condition,
27
27
  popOverClassName = _ref.popOverClassName,
28
28
  config = _ref.config,
29
+ renderChildren = _ref.renderChildren,
29
30
  rest = _objectWithoutProperties(_ref, _excluded);
30
31
  var contentRef = useRef(null);
32
+ var popoverRef = useRef(null);
31
33
  var _useState = useState(false),
32
34
  _useState2 = _slicedToArray(_useState, 2),
33
35
  open = _useState2[0],
34
36
  setOpen = _useState2[1];
35
- var _useTranslations = useTranslations(['invalidText', 'addConditionText', label]),
36
- _useTranslations2 = _slicedToArray(_useTranslations, 3),
37
+ var _useTranslations = useTranslations(['invalidText', 'addConditionText', label, 'invalidDateText']),
38
+ _useTranslations2 = _slicedToArray(_useTranslations, 4),
37
39
  invalidText = _useTranslations2[0],
38
40
  addConditionText = _useTranslations2[1],
39
- labelText = _useTranslations2[2];
41
+ labelText = _useTranslations2[2],
42
+ invalidDateText = _useTranslations2[3];
40
43
  var getPropertyDetails = function getPropertyDetails() {
41
44
  if (label === 'INVALID') {
42
45
  return {
43
46
  propertyLabel: invalidText,
44
47
  isInvalid: true
45
48
  };
49
+ } else if (label === 'INVALID_DATE') {
50
+ return {
51
+ propertyLabel: invalidDateText,
52
+ isInvalid: true
53
+ };
46
54
  }
47
55
  var propertyId = rest['data-name'] == 'valueField' && type ? valueRenderers[type](label, config) : labelText;
48
56
  return {
@@ -63,19 +71,19 @@ var ConditionBuilderItem = function ConditionBuilderItem(_ref) {
63
71
  //if any condition is changed, state prop is triggered
64
72
  if (condition.popoverToOpen && currentField !== condition.popoverToOpen) {
65
73
  // close the previous popover
66
- setOpen(false);
74
+ closePopover();
67
75
  } else if (currentField == 'valueField' && type == 'option' && condition.operator !== 'oneOf') {
68
76
  //close the current popover if the field is valueField and is a single select dropdown. For all other inputs ,popover need to be open on value changes.
69
- setOpen(false);
77
+ closePopover();
70
78
  }
71
79
  if (condition.popoverToOpen == currentField) {
72
80
  //current popover need to be opened
73
- setOpen(true);
81
+ openPopOver();
74
82
  }
75
83
  } else {
76
84
  // when we change any statement(if/ excl.if) which is not part of condition state, label change is triggered.
77
85
  //close popOver when statement is changed.
78
- setOpen(false);
86
+ closePopover();
79
87
  }
80
88
  // eslint-disable-next-line react-hooks/exhaustive-deps
81
89
  }, [condition, label]);
@@ -88,20 +96,26 @@ var ConditionBuilderItem = function ConditionBuilderItem(_ref) {
88
96
  }
89
97
  }
90
98
  }, [contentRef, open]);
99
+ var closePopover = function closePopover() {
100
+ return setOpen(false);
101
+ };
102
+ var openPopOver = function openPopOver() {
103
+ return setOpen(true);
104
+ };
105
+ var togglePopover = function togglePopover() {
106
+ return setOpen(!open);
107
+ };
91
108
  return /*#__PURE__*/React__default.createElement(Popover, {
92
109
  open: open,
93
110
  isTabTip: true,
94
111
  role: "gridcell",
95
112
  className: popOverClassName,
96
- onRequestClose: function onRequestClose() {
97
- setOpen(false);
98
- }
113
+ ref: popoverRef,
114
+ onRequestClose: closePopover
99
115
  }, /*#__PURE__*/React__default.createElement(ConditionBuilderButton, _extends({
100
116
  label: propertyLabel !== null && propertyLabel !== void 0 ? propertyLabel : addConditionText,
101
117
  hideLabel: !label ? true : false,
102
- onClick: function onClick() {
103
- children ? setOpen(!open) : null;
104
- },
118
+ onClick: togglePopover,
105
119
  className: className,
106
120
  "aria-haspopup": true,
107
121
  "aria-expanded": open,
@@ -118,7 +132,7 @@ var ConditionBuilderItem = function ConditionBuilderItem(_ref) {
118
132
  }, title), /*#__PURE__*/React__default.createElement("div", {
119
133
  ref: contentRef,
120
134
  className: "".concat(blockClass, "__popover-content")
121
- }, children))));
135
+ }, renderChildren ? renderChildren(popoverRef) : children))));
122
136
  };
123
137
  ConditionBuilderItem.propTypes = {
124
138
  /**
@@ -146,6 +160,10 @@ ConditionBuilderItem.propTypes = {
146
160
  * class name for popover
147
161
  */
148
162
  popOverClassName: PropTypes.string,
163
+ /**
164
+ * callback prop that returns the jsx for children
165
+ */
166
+ renderChildren: PropTypes.func,
149
167
  /**
150
168
  * Optional prop to allow overriding the icon rendering.
151
169
  */
@@ -1,11 +1,13 @@
1
- export function ConditionBuilderItemDate({ conditionState, onChange }: {
1
+ export function ConditionBuilderItemDate({ conditionState, onChange, parentRef, }: {
2
2
  conditionState: any;
3
3
  onChange: any;
4
+ parentRef: any;
4
5
  }): import("react/jsx-runtime").JSX.Element;
5
6
  export namespace ConditionBuilderItemDate {
6
7
  namespace propTypes {
7
8
  let conditionState: PropTypes.Requireable<object>;
8
9
  let onChange: PropTypes.Requireable<(...args: any[]) => any>;
10
+ let parentRef: PropTypes.Requireable<object>;
9
11
  }
10
12
  }
11
13
  import PropTypes from 'prop-types';
@@ -15,21 +15,26 @@ import { useTranslations } from '../../utils/useTranslations.js';
15
15
  var blockClass = "".concat(pkg.prefix, "--condition-builder");
16
16
  var ConditionBuilderItemDate = function ConditionBuilderItemDate(_ref) {
17
17
  var conditionState = _ref.conditionState,
18
- onChange = _ref.onChange;
18
+ onChange = _ref.onChange,
19
+ parentRef = _ref.parentRef;
19
20
  var DatePickerInputRef = useRef();
20
21
  var _useTranslations = useTranslations(['startText', 'endText']),
21
22
  _useTranslations2 = _slicedToArray(_useTranslations, 2),
22
23
  startText = _useTranslations2[0],
23
24
  endText = _useTranslations2[1];
24
25
  var datePickerType = conditionState.operator == 'between' ? 'range' : 'single';
26
+ var onCloseHandler = function onCloseHandler(selectedDate) {
27
+ onChange(selectedDate && selectedDate.length > 0 ? selectedDate : 'INVALID_DATE');
28
+ };
25
29
  return /*#__PURE__*/React__default.createElement("div", {
26
30
  className: "".concat(blockClass, "__item-date ")
27
31
  }, datePickerType == 'single' && /*#__PURE__*/React__default.createElement(DatePicker, {
28
32
  ref: DatePickerInputRef,
29
33
  dateFormat: "d/m/Y",
30
34
  datePickerType: "single",
31
- onClose: onChange,
32
- value: conditionState.value
35
+ value: conditionState.value,
36
+ onClose: onCloseHandler,
37
+ appendTo: parentRef === null || parentRef === void 0 ? void 0 : parentRef.current
33
38
  }, /*#__PURE__*/React__default.createElement(DatePickerInput, {
34
39
  id: "datePicker",
35
40
  placeholder: "dd/mm/yyyy",
@@ -38,8 +43,9 @@ var ConditionBuilderItemDate = function ConditionBuilderItemDate(_ref) {
38
43
  ref: DatePickerInputRef,
39
44
  dateFormat: "d/m/Y",
40
45
  datePickerType: datePickerType,
41
- onClose: onChange,
42
- value: conditionState.value
46
+ onClose: onCloseHandler,
47
+ value: conditionState.value,
48
+ appendTo: parentRef === null || parentRef === void 0 ? void 0 : parentRef.current
43
49
  }, /*#__PURE__*/React__default.createElement(DatePickerInput, {
44
50
  id: "datePickerStart",
45
51
  placeholder: "dd/mm/yyyy",
@@ -58,7 +64,11 @@ ConditionBuilderItemDate.propTypes = {
58
64
  /**
59
65
  * callback to update state oin date change
60
66
  */
61
- onChange: PropTypes.func
67
+ onChange: PropTypes.func,
68
+ /**
69
+ * reference to the popover node
70
+ */
71
+ parentRef: PropTypes.object
62
72
  };
63
73
 
64
74
  export { ConditionBuilderItemDate };
@@ -313,9 +313,9 @@ var TearsheetShell = /*#__PURE__*/React__default.forwardRef(function (_ref, ref)
313
313
  // The display name of the component, used by React. Note that displayName
314
314
  // is used in preference to relying on function.name.
315
315
  TearsheetShell.displayName = componentName;
316
- var portalType = typeof Element === 'undefined' ? PropTypes.object
316
+ var portalType = typeof Element === 'undefined' ? PropTypes.object :
317
317
  // eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope
318
- : PropTypes.instanceOf(Element);
318
+ PropTypes.instanceOf(Element);
319
319
  var deprecatedProps = {
320
320
  /**
321
321
  * **Deprecated**
@@ -148,11 +148,23 @@ var ConditionBlock = function ConditionBlock(props) {
148
148
  'aria-setsize': aria.setsize
149
149
  } : {};
150
150
  };
151
+ var renderChildren = function renderChildren(popoverRef) {
152
+ return /*#__PURE__*/React__default["default"].createElement(ItemComponent, {
153
+ conditionState: {
154
+ property: property,
155
+ operator: operator,
156
+ value: value
157
+ },
158
+ onChange: onValueChangeHandler,
159
+ config: config,
160
+ "data-name": "valueField",
161
+ parentRef: popoverRef
162
+ });
163
+ };
151
164
  return /*#__PURE__*/React__default["default"].createElement("div", _rollupPluginBabelHelpers["extends"]({
152
165
  className: cx__default["default"]("".concat(DataConfigs.blockClass, "__condition-block"), _rollupPluginBabelHelpers.defineProperty({}, "".concat(DataConfigs.blockClass, "__condition__deletion-preview"), showDeletionPreview), _rollupPluginBabelHelpers.defineProperty({}, "".concat(DataConfigs.blockClass, "__gap-bottom"), variant == 'tree' && !(conditionIndex + 1 >= group.conditions.length)), _rollupPluginBabelHelpers.defineProperty({}, "".concat(DataConfigs.blockClass, "__gap ").concat(DataConfigs.blockClass, "__gap-bottom"), variant == 'sentence')),
153
166
  role: "row",
154
- "aria-label": conditionRowText,
155
- tabIndex: -1
167
+ "aria-label": conditionRowText
156
168
  }, getAriaAttributes()), conjunction ? /*#__PURE__*/React__default["default"].createElement(ConditionConnector["default"], {
157
169
  className: "".concat(DataConfigs.blockClass, "__gap"),
158
170
  operator: conjunction,
@@ -215,18 +227,9 @@ var ConditionBlock = function ConditionBlock(props) {
215
227
  showToolTip: true,
216
228
  "data-name": "valueField",
217
229
  condition: condition,
218
- config: config
219
- }, /*#__PURE__*/React__default["default"].createElement(ItemComponent, {
220
- conditionState: {
221
- property: property,
222
- operator: operator,
223
- value: value
224
- },
225
- onChange: onValueChangeHandler,
226
230
  config: config,
227
- type: type,
228
- "data-name": "valueField"
229
- })), /*#__PURE__*/React__default["default"].createElement("span", {
231
+ renderChildren: renderChildren
232
+ }), /*#__PURE__*/React__default["default"].createElement("span", {
230
233
  role: "gridcell",
231
234
  "aria-label": removeConditionText
232
235
  }, /*#__PURE__*/React__default["default"].createElement(ConditionBuilderButton.ConditionBuilderButton, {
@@ -211,7 +211,7 @@ exports.ConditionBuilder.propTypes = {
211
211
  /**
212
212
  * Optional prop, if you need to pass translations to the texts on the component instead of the defined defaults.
213
213
  * This callback function will receive the message id and you need to return the corresponding text for that id.
214
- * The message id will be one of [ "ifText","addConditionText", "addConditionGroupText", "addSubgroupText", "conditionText", "propertyText", "operatorText", "valueText", "connectorText", "conditionRowText", "removeConditionText", "addConditionRowText", "startText", "endText", "clearSearchText", "actionsText", "then", "removeActionText", "addActionText", "invalidText", "invalidNumberWarnText"]
214
+ * The message id will be one of [ "ifText","addConditionText", "addConditionGroupText", "addSubgroupText", "conditionText", "propertyText", "operatorText", "valueText", "connectorText", "conditionRowText", "removeConditionText", "addConditionRowText", "startText", "endText", "clearSearchText", "actionsText", "then", "removeActionText", "addActionText", "invalidText", "invalidDateText", "invalidNumberWarnText"]
215
215
  ]
216
216
  */
217
217
  translateWithId: index["default"].func,
@@ -110,11 +110,13 @@ var valueRenderers = {
110
110
  },
111
111
  date: function date(value) {
112
112
  if (Array.isArray(value) && value.length > 1) {
113
- var start = value !== null && value !== void 0 && value[0] ? formatDate(new Date(value[0])) : '';
114
- var end = value !== null && value !== void 0 && value[1] ? formatDate(new Date(value[1])) : '';
113
+ var start = value !== null && value !== void 0 && value[0] && !isNaN(new Date(value[0])) ? formatDate(new Date(value[0])) : '';
114
+ var end = value !== null && value !== void 0 && value[1] && !isNaN(new Date(value[1])) ? formatDate(new Date(value[1])) : '';
115
115
  return "".concat(start, " To ").concat(end);
116
+ } else if (Array.isArray(value) && !isNaN(new Date(value[0]))) {
117
+ return formatDate(new Date(value[0]));
116
118
  } else {
117
- return value && new Date(value) ? formatDate(new Date(value)) : value;
119
+ return value;
118
120
  }
119
121
  },
120
122
  custom: function custom(value) {
@@ -34,5 +34,6 @@ export namespace translationsObject {
34
34
  let removeActionText: string;
35
35
  let addActionText: string;
36
36
  let invalidText: string;
37
+ let invalidDateText: string;
37
38
  let invalidNumberWarnText: string;
38
39
  }
@@ -45,6 +45,7 @@ var translationsObject = {
45
45
  removeActionText: 'Remove Action',
46
46
  addActionText: 'Add action',
47
47
  invalidText: 'Incomplete',
48
+ invalidDateText: 'Invalid Date',
48
49
  invalidNumberWarnText: 'Invalid number, must be 0 or greater'
49
50
  };
50
51
 
@@ -1,4 +1,4 @@
1
- export function ConditionBuilderItem({ children, className, label, renderIcon, title, type, showToolTip, condition, popOverClassName, config, ...rest }: {
1
+ export function ConditionBuilderItem({ children, className, label, renderIcon, title, type, showToolTip, condition, popOverClassName, config, renderChildren, ...rest }: {
2
2
  [x: string]: any;
3
3
  children: any;
4
4
  className: any;
@@ -10,6 +10,7 @@ export function ConditionBuilderItem({ children, className, label, renderIcon, t
10
10
  condition: any;
11
11
  popOverClassName: any;
12
12
  config: any;
13
+ renderChildren: any;
13
14
  }): import("react/jsx-runtime").JSX.Element;
14
15
  export namespace ConditionBuilderItem {
15
16
  namespace propTypes {
@@ -19,6 +20,7 @@ export namespace ConditionBuilderItem {
19
20
  let config: PropTypes.Requireable<object>;
20
21
  let label: PropTypes.Requireable<NonNullable<string | object | null | undefined>>;
21
22
  let popOverClassName: PropTypes.Requireable<string>;
23
+ let renderChildren: PropTypes.Requireable<(...args: any[]) => any>;
22
24
  let renderIcon: PropTypes.Requireable<object>;
23
25
  let showToolTip: PropTypes.Requireable<boolean>;
24
26
  let title: PropTypes.Requireable<string>;
@@ -22,7 +22,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
22
22
 
23
23
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
24
24
 
25
- var _excluded = ["children", "className", "label", "renderIcon", "title", "type", "showToolTip", "condition", "popOverClassName", "config"];
25
+ var _excluded = ["children", "className", "label", "renderIcon", "title", "type", "showToolTip", "condition", "popOverClassName", "config", "renderChildren"];
26
26
  var ConditionBuilderItem = function ConditionBuilderItem(_ref) {
27
27
  var children = _ref.children,
28
28
  className = _ref.className,
@@ -34,23 +34,31 @@ var ConditionBuilderItem = function ConditionBuilderItem(_ref) {
34
34
  condition = _ref.condition,
35
35
  popOverClassName = _ref.popOverClassName,
36
36
  config = _ref.config,
37
+ renderChildren = _ref.renderChildren,
37
38
  rest = _rollupPluginBabelHelpers.objectWithoutProperties(_ref, _excluded);
38
39
  var contentRef = React.useRef(null);
40
+ var popoverRef = React.useRef(null);
39
41
  var _useState = React.useState(false),
40
42
  _useState2 = _rollupPluginBabelHelpers.slicedToArray(_useState, 2),
41
43
  open = _useState2[0],
42
44
  setOpen = _useState2[1];
43
- var _useTranslations = useTranslations.useTranslations(['invalidText', 'addConditionText', label]),
44
- _useTranslations2 = _rollupPluginBabelHelpers.slicedToArray(_useTranslations, 3),
45
+ var _useTranslations = useTranslations.useTranslations(['invalidText', 'addConditionText', label, 'invalidDateText']),
46
+ _useTranslations2 = _rollupPluginBabelHelpers.slicedToArray(_useTranslations, 4),
45
47
  invalidText = _useTranslations2[0],
46
48
  addConditionText = _useTranslations2[1],
47
- labelText = _useTranslations2[2];
49
+ labelText = _useTranslations2[2],
50
+ invalidDateText = _useTranslations2[3];
48
51
  var getPropertyDetails = function getPropertyDetails() {
49
52
  if (label === 'INVALID') {
50
53
  return {
51
54
  propertyLabel: invalidText,
52
55
  isInvalid: true
53
56
  };
57
+ } else if (label === 'INVALID_DATE') {
58
+ return {
59
+ propertyLabel: invalidDateText,
60
+ isInvalid: true
61
+ };
54
62
  }
55
63
  var propertyId = rest['data-name'] == 'valueField' && type ? DataConfigs.valueRenderers[type](label, config) : labelText;
56
64
  return {
@@ -71,19 +79,19 @@ var ConditionBuilderItem = function ConditionBuilderItem(_ref) {
71
79
  //if any condition is changed, state prop is triggered
72
80
  if (condition.popoverToOpen && currentField !== condition.popoverToOpen) {
73
81
  // close the previous popover
74
- setOpen(false);
82
+ closePopover();
75
83
  } else if (currentField == 'valueField' && type == 'option' && condition.operator !== 'oneOf') {
76
84
  //close the current popover if the field is valueField and is a single select dropdown. For all other inputs ,popover need to be open on value changes.
77
- setOpen(false);
85
+ closePopover();
78
86
  }
79
87
  if (condition.popoverToOpen == currentField) {
80
88
  //current popover need to be opened
81
- setOpen(true);
89
+ openPopOver();
82
90
  }
83
91
  } else {
84
92
  // when we change any statement(if/ excl.if) which is not part of condition state, label change is triggered.
85
93
  //close popOver when statement is changed.
86
- setOpen(false);
94
+ closePopover();
87
95
  }
88
96
  // eslint-disable-next-line react-hooks/exhaustive-deps
89
97
  }, [condition, label]);
@@ -96,20 +104,26 @@ var ConditionBuilderItem = function ConditionBuilderItem(_ref) {
96
104
  }
97
105
  }
98
106
  }, [contentRef, open]);
107
+ var closePopover = function closePopover() {
108
+ return setOpen(false);
109
+ };
110
+ var openPopOver = function openPopOver() {
111
+ return setOpen(true);
112
+ };
113
+ var togglePopover = function togglePopover() {
114
+ return setOpen(!open);
115
+ };
99
116
  return /*#__PURE__*/React__default["default"].createElement(react.Popover, {
100
117
  open: open,
101
118
  isTabTip: true,
102
119
  role: "gridcell",
103
120
  className: popOverClassName,
104
- onRequestClose: function onRequestClose() {
105
- setOpen(false);
106
- }
121
+ ref: popoverRef,
122
+ onRequestClose: closePopover
107
123
  }, /*#__PURE__*/React__default["default"].createElement(ConditionBuilderButton.ConditionBuilderButton, _rollupPluginBabelHelpers["extends"]({
108
124
  label: propertyLabel !== null && propertyLabel !== void 0 ? propertyLabel : addConditionText,
109
125
  hideLabel: !label ? true : false,
110
- onClick: function onClick() {
111
- children ? setOpen(!open) : null;
112
- },
126
+ onClick: togglePopover,
113
127
  className: className,
114
128
  "aria-haspopup": true,
115
129
  "aria-expanded": open,
@@ -126,7 +140,7 @@ var ConditionBuilderItem = function ConditionBuilderItem(_ref) {
126
140
  }, title), /*#__PURE__*/React__default["default"].createElement("div", {
127
141
  ref: contentRef,
128
142
  className: "".concat(DataConfigs.blockClass, "__popover-content")
129
- }, children))));
143
+ }, renderChildren ? renderChildren(popoverRef) : children))));
130
144
  };
131
145
  ConditionBuilderItem.propTypes = {
132
146
  /**
@@ -154,6 +168,10 @@ ConditionBuilderItem.propTypes = {
154
168
  * class name for popover
155
169
  */
156
170
  popOverClassName: index["default"].string,
171
+ /**
172
+ * callback prop that returns the jsx for children
173
+ */
174
+ renderChildren: index["default"].func,
157
175
  /**
158
176
  * Optional prop to allow overriding the icon rendering.
159
177
  */
@@ -1,11 +1,13 @@
1
- export function ConditionBuilderItemDate({ conditionState, onChange }: {
1
+ export function ConditionBuilderItemDate({ conditionState, onChange, parentRef, }: {
2
2
  conditionState: any;
3
3
  onChange: any;
4
+ parentRef: any;
4
5
  }): import("react/jsx-runtime").JSX.Element;
5
6
  export namespace ConditionBuilderItemDate {
6
7
  namespace propTypes {
7
8
  let conditionState: PropTypes.Requireable<object>;
8
9
  let onChange: PropTypes.Requireable<(...args: any[]) => any>;
10
+ let parentRef: PropTypes.Requireable<object>;
9
11
  }
10
12
  }
11
13
  import PropTypes from 'prop-types';
@@ -23,21 +23,26 @@ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
23
23
  var blockClass = "".concat(settings.pkg.prefix, "--condition-builder");
24
24
  var ConditionBuilderItemDate = function ConditionBuilderItemDate(_ref) {
25
25
  var conditionState = _ref.conditionState,
26
- onChange = _ref.onChange;
26
+ onChange = _ref.onChange,
27
+ parentRef = _ref.parentRef;
27
28
  var DatePickerInputRef = React.useRef();
28
29
  var _useTranslations = useTranslations.useTranslations(['startText', 'endText']),
29
30
  _useTranslations2 = _rollupPluginBabelHelpers.slicedToArray(_useTranslations, 2),
30
31
  startText = _useTranslations2[0],
31
32
  endText = _useTranslations2[1];
32
33
  var datePickerType = conditionState.operator == 'between' ? 'range' : 'single';
34
+ var onCloseHandler = function onCloseHandler(selectedDate) {
35
+ onChange(selectedDate && selectedDate.length > 0 ? selectedDate : 'INVALID_DATE');
36
+ };
33
37
  return /*#__PURE__*/React__default["default"].createElement("div", {
34
38
  className: "".concat(blockClass, "__item-date ")
35
39
  }, datePickerType == 'single' && /*#__PURE__*/React__default["default"].createElement(react.DatePicker, {
36
40
  ref: DatePickerInputRef,
37
41
  dateFormat: "d/m/Y",
38
42
  datePickerType: "single",
39
- onClose: onChange,
40
- value: conditionState.value
43
+ value: conditionState.value,
44
+ onClose: onCloseHandler,
45
+ appendTo: parentRef === null || parentRef === void 0 ? void 0 : parentRef.current
41
46
  }, /*#__PURE__*/React__default["default"].createElement(react.DatePickerInput, {
42
47
  id: "datePicker",
43
48
  placeholder: "dd/mm/yyyy",
@@ -46,8 +51,9 @@ var ConditionBuilderItemDate = function ConditionBuilderItemDate(_ref) {
46
51
  ref: DatePickerInputRef,
47
52
  dateFormat: "d/m/Y",
48
53
  datePickerType: datePickerType,
49
- onClose: onChange,
50
- value: conditionState.value
54
+ onClose: onCloseHandler,
55
+ value: conditionState.value,
56
+ appendTo: parentRef === null || parentRef === void 0 ? void 0 : parentRef.current
51
57
  }, /*#__PURE__*/React__default["default"].createElement(react.DatePickerInput, {
52
58
  id: "datePickerStart",
53
59
  placeholder: "dd/mm/yyyy",
@@ -66,7 +72,11 @@ ConditionBuilderItemDate.propTypes = {
66
72
  /**
67
73
  * callback to update state oin date change
68
74
  */
69
- onChange: index["default"].func
75
+ onChange: index["default"].func,
76
+ /**
77
+ * reference to the popover node
78
+ */
79
+ parentRef: index["default"].object
70
80
  };
71
81
 
72
82
  exports.ConditionBuilderItemDate = ConditionBuilderItemDate;
@@ -322,9 +322,9 @@ var TearsheetShell = /*#__PURE__*/React__default["default"].forwardRef(function
322
322
  // The display name of the component, used by React. Note that displayName
323
323
  // is used in preference to relying on function.name.
324
324
  TearsheetShell.displayName = componentName;
325
- var portalType = typeof Element === 'undefined' ? index["default"].object
325
+ var portalType = typeof Element === 'undefined' ? index["default"].object :
326
326
  // eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope
327
- : index["default"].instanceOf(Element);
327
+ index["default"].instanceOf(Element);
328
328
  var deprecatedProps = {
329
329
  /**
330
330
  * **Deprecated**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@carbon/ibm-products",
3
3
  "description": "Carbon for IBM Products",
4
- "version": "2.43.2-canary.56+da5fd0a09",
4
+ "version": "2.43.2-canary.57+e093199d5",
5
5
  "license": "Apache-2.0",
6
6
  "main": "lib/index.js",
7
7
  "module": "es/index.js",
@@ -96,7 +96,7 @@
96
96
  "dependencies": {
97
97
  "@babel/runtime": "^7.23.9",
98
98
  "@carbon/feature-flags": "^0.20.0",
99
- "@carbon/ibm-products-styles": "^2.39.1-canary.66+da5fd0a09",
99
+ "@carbon/ibm-products-styles": "^2.40.0-rc.1",
100
100
  "@carbon/telemetry": "^0.1.0",
101
101
  "@dnd-kit/core": "^6.0.8",
102
102
  "@dnd-kit/modifiers": "^7.0.0",
@@ -120,5 +120,5 @@
120
120
  "react": "^16.8.6 || ^17.0.1 || ^18.2.0",
121
121
  "react-dom": "^16.8.6 || ^17.0.1 || ^18.2.0"
122
122
  },
123
- "gitHead": "da5fd0a09a05696e4f22cf9e3241e1ad67a941b9"
123
+ "gitHead": "e093199d509d0eb222ee9eedbdc455fae6f66aaf"
124
124
  }