@carbon/ibm-products 2.36.0 → 2.37.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. package/css/index-full-carbon.css +5404 -5117
  2. package/css/index-full-carbon.css.map +1 -1
  3. package/css/index-full-carbon.min.css +1 -1
  4. package/css/index-full-carbon.min.css.map +1 -1
  5. package/css/index-without-carbon-released-only.css +4 -4
  6. package/css/index-without-carbon-released-only.css.map +1 -1
  7. package/css/index-without-carbon-released-only.min.css +1 -1
  8. package/css/index-without-carbon-released-only.min.css.map +1 -1
  9. package/css/index-without-carbon.css +820 -61
  10. package/css/index-without-carbon.css.map +1 -1
  11. package/css/index-without-carbon.min.css +1 -1
  12. package/css/index-without-carbon.min.css.map +1 -1
  13. package/css/index.css +329 -6
  14. package/css/index.css.map +1 -1
  15. package/css/index.min.css +1 -1
  16. package/css/index.min.css.map +1 -1
  17. package/es/_virtual/_rollupPluginBabelHelpers.js +9 -10
  18. package/es/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.d.ts +3 -1
  19. package/es/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +8 -2
  20. package/es/components/ConditionBuilder/ConditionBlock/ConditionBlock.d.ts +21 -0
  21. package/es/components/ConditionBuilder/ConditionBlock/ConditionBlock.js +261 -0
  22. package/es/components/ConditionBuilder/ConditionBuilder.js +45 -16
  23. package/es/components/ConditionBuilder/ConditionBuilderAdd/ConditionBuilderAdd.d.ts +12 -0
  24. package/es/components/ConditionBuilder/ConditionBuilderAdd/ConditionBuilderAdd.js +40 -0
  25. package/es/components/ConditionBuilder/ConditionBuilderButton/ConditionBuilderButton.d.ts +22 -0
  26. package/es/components/ConditionBuilder/ConditionBuilderButton/ConditionBuilderButton.js +74 -0
  27. package/es/components/ConditionBuilder/ConditionBuilderContent/ConditionBuilderContent.d.ts +18 -1
  28. package/es/components/ConditionBuilder/ConditionBuilderContent/ConditionBuilderContent.js +90 -42
  29. package/es/components/ConditionBuilder/ConditionBuilderContext/{DataTreeContext.d.ts → ConditionBuilderProvider.d.ts} +5 -2
  30. package/es/components/ConditionBuilder/ConditionBuilderContext/{DataTreeContext.js → ConditionBuilderProvider.js} +27 -8
  31. package/es/components/ConditionBuilder/ConditionBuilderContext/DataConfigs.d.ts +22 -0
  32. package/es/components/ConditionBuilder/ConditionBuilderContext/DataConfigs.js +112 -0
  33. package/es/components/ConditionBuilder/ConditionBuilderContext/translationObject.d.ts +31 -0
  34. package/es/components/ConditionBuilder/ConditionBuilderContext/translationObject.js +40 -0
  35. package/es/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItem.d.ts +28 -0
  36. package/es/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItem.js +151 -0
  37. package/es/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItemDate/ConditionBuilderItemDate.d.ts +11 -0
  38. package/es/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItemDate/ConditionBuilderItemDate.js +59 -0
  39. package/es/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItemNumber/ConditionBuilderItemNumber.d.ts +13 -0
  40. package/es/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItemNumber/ConditionBuilderItemNumber.js +52 -0
  41. package/es/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItemOption/ConditionBuilderItemOption.d.ts +13 -0
  42. package/es/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItemOption/ConditionBuilderItemOption.js +162 -0
  43. package/es/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItemText/ConditionBuilderItemText.d.ts +11 -0
  44. package/es/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItemText/ConditionBuilderItemText.js +40 -0
  45. package/es/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItemTime/ConditionBuilderItemTime.d.ts +11 -0
  46. package/es/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItemTime/ConditionBuilderItemTime.js +82 -0
  47. package/es/components/ConditionBuilder/ConditionConnector/ConditionConnector.d.ts +15 -0
  48. package/es/components/ConditionBuilder/ConditionConnector/ConditionConnector.js +85 -0
  49. package/es/components/ConditionBuilder/ConditionGroupBuilder/ConditionGroupBuilder.d.ts +24 -0
  50. package/es/components/ConditionBuilder/ConditionGroupBuilder/ConditionGroupBuilder.js +145 -0
  51. package/es/components/ConditionBuilder/utils/util.d.ts +4 -0
  52. package/es/components/ConditionBuilder/utils/util.js +16 -0
  53. package/es/components/CreateTearsheet/CreateTearsheet.d.ts +106 -4
  54. package/es/components/CreateTearsheet/CreateTearsheet.js +12 -32
  55. package/es/components/Datagrid/useParentDimensions.js +1 -1
  56. package/es/components/EditUpdateCards/EditUpdateCards.d.ts +104 -2
  57. package/es/components/EditUpdateCards/EditUpdateCards.js +3 -0
  58. package/es/components/EmptyStates/NotificationsEmptyState/NotificationsEmptyState.d.ts +61 -2
  59. package/es/components/EmptyStates/NotificationsEmptyState/NotificationsEmptyState.js +1 -3
  60. package/es/components/ExpressiveCard/ExpressiveCard.d.ts +97 -2
  61. package/es/components/ExpressiveCard/ExpressiveCard.js +4 -0
  62. package/es/components/InlineTip/InlineTipButton.d.ts +21 -2
  63. package/es/components/InterstitialScreen/InterstitialScreen.d.ts +100 -2
  64. package/es/components/InterstitialScreen/InterstitialScreen.js +25 -14
  65. package/es/components/Nav/NavItem.js +1 -1
  66. package/es/components/NotificationsPanel/NotificationsPanel.js +5 -6
  67. package/es/components/PageHeader/PageHeader.js +12 -3
  68. package/es/components/SidePanel/SidePanel.js +1 -1
  69. package/es/components/SimpleHeader/SimpleHeader.d.ts +1 -5
  70. package/es/components/SimpleHeader/SimpleHeader.js +2 -4
  71. package/es/components/Tearsheet/TearsheetNarrow.d.ts +4 -13
  72. package/es/components/Tearsheet/TearsheetShell.d.ts +119 -10
  73. package/es/components/Tearsheet/TearsheetShell.js +18 -8
  74. package/es/components/WebTerminal/WebTerminal.d.ts +46 -2
  75. package/es/components/WebTerminal/WebTerminal.js +2 -2
  76. package/es/global/js/hooks/usePrefersReducedMotion.d.ts +2 -0
  77. package/es/global/js/hooks/usePrefersReducedMotion.js +28 -0
  78. package/es/global/js/utils/Wrap.d.ts +31 -2
  79. package/es/global/js/utils/Wrap.js +7 -9
  80. package/es/global/js/utils/getNodeTextContent.d.ts +1 -1
  81. package/es/global/js/utils/getNodeTextContent.js +1 -1
  82. package/es/global/js/utils/window.d.ts +2 -0
  83. package/es/global/js/utils/window.js +12 -0
  84. package/es/node_modules/@carbon/icons-react/es/generated/bucket-9.js +2780 -0
  85. package/lib/_virtual/_rollupPluginBabelHelpers.js +9 -10
  86. package/lib/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.d.ts +3 -1
  87. package/lib/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +8 -2
  88. package/lib/components/ConditionBuilder/ConditionBlock/ConditionBlock.d.ts +21 -0
  89. package/lib/components/ConditionBuilder/ConditionBlock/ConditionBlock.js +270 -0
  90. package/lib/components/ConditionBuilder/ConditionBuilder.js +46 -17
  91. package/lib/components/ConditionBuilder/ConditionBuilderAdd/ConditionBuilderAdd.d.ts +12 -0
  92. package/lib/components/ConditionBuilder/ConditionBuilderAdd/ConditionBuilderAdd.js +48 -0
  93. package/lib/components/ConditionBuilder/ConditionBuilderButton/ConditionBuilderButton.d.ts +22 -0
  94. package/lib/components/ConditionBuilder/ConditionBuilderButton/ConditionBuilderButton.js +83 -0
  95. package/lib/components/ConditionBuilder/ConditionBuilderContent/ConditionBuilderContent.d.ts +18 -1
  96. package/lib/components/ConditionBuilder/ConditionBuilderContent/ConditionBuilderContent.js +90 -42
  97. package/lib/components/ConditionBuilder/ConditionBuilderContext/{DataTreeContext.d.ts → ConditionBuilderProvider.d.ts} +5 -2
  98. package/lib/components/ConditionBuilder/ConditionBuilderContext/{DataTreeContext.js → ConditionBuilderProvider.js} +27 -8
  99. package/lib/components/ConditionBuilder/ConditionBuilderContext/DataConfigs.d.ts +22 -0
  100. package/lib/components/ConditionBuilder/ConditionBuilderContext/DataConfigs.js +121 -0
  101. package/lib/components/ConditionBuilder/ConditionBuilderContext/translationObject.d.ts +31 -0
  102. package/lib/components/ConditionBuilder/ConditionBuilderContext/translationObject.js +44 -0
  103. package/lib/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItem.d.ts +28 -0
  104. package/lib/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItem.js +159 -0
  105. package/lib/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItemDate/ConditionBuilderItemDate.d.ts +11 -0
  106. package/lib/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItemDate/ConditionBuilderItemDate.js +67 -0
  107. package/lib/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItemNumber/ConditionBuilderItemNumber.d.ts +13 -0
  108. package/lib/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItemNumber/ConditionBuilderItemNumber.js +60 -0
  109. package/lib/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItemOption/ConditionBuilderItemOption.d.ts +13 -0
  110. package/lib/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItemOption/ConditionBuilderItemOption.js +170 -0
  111. package/lib/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItemText/ConditionBuilderItemText.d.ts +11 -0
  112. package/lib/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItemText/ConditionBuilderItemText.js +48 -0
  113. package/lib/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItemTime/ConditionBuilderItemTime.d.ts +11 -0
  114. package/lib/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItemTime/ConditionBuilderItemTime.js +90 -0
  115. package/lib/components/ConditionBuilder/ConditionConnector/ConditionConnector.d.ts +15 -0
  116. package/lib/components/ConditionBuilder/ConditionConnector/ConditionConnector.js +93 -0
  117. package/lib/components/ConditionBuilder/ConditionGroupBuilder/ConditionGroupBuilder.d.ts +24 -0
  118. package/lib/components/ConditionBuilder/ConditionGroupBuilder/ConditionGroupBuilder.js +153 -0
  119. package/lib/components/ConditionBuilder/utils/util.d.ts +4 -0
  120. package/lib/components/ConditionBuilder/utils/util.js +20 -0
  121. package/lib/components/CreateTearsheet/CreateTearsheet.d.ts +106 -4
  122. package/lib/components/CreateTearsheet/CreateTearsheet.js +12 -32
  123. package/lib/components/Datagrid/useParentDimensions.js +1 -1
  124. package/lib/components/EditUpdateCards/EditUpdateCards.d.ts +104 -2
  125. package/lib/components/EditUpdateCards/EditUpdateCards.js +3 -0
  126. package/lib/components/EmptyStates/NotificationsEmptyState/NotificationsEmptyState.d.ts +61 -2
  127. package/lib/components/EmptyStates/NotificationsEmptyState/NotificationsEmptyState.js +1 -3
  128. package/lib/components/ExpressiveCard/ExpressiveCard.d.ts +97 -2
  129. package/lib/components/ExpressiveCard/ExpressiveCard.js +4 -0
  130. package/lib/components/InlineTip/InlineTipButton.d.ts +21 -2
  131. package/lib/components/InterstitialScreen/InterstitialScreen.d.ts +100 -2
  132. package/lib/components/InterstitialScreen/InterstitialScreen.js +24 -13
  133. package/lib/components/Nav/NavItem.js +2 -2
  134. package/lib/components/NotificationsPanel/NotificationsPanel.js +5 -6
  135. package/lib/components/PageHeader/PageHeader.js +11 -2
  136. package/lib/components/SidePanel/SidePanel.js +1 -1
  137. package/lib/components/SimpleHeader/SimpleHeader.d.ts +1 -5
  138. package/lib/components/SimpleHeader/SimpleHeader.js +2 -4
  139. package/lib/components/Tearsheet/TearsheetNarrow.d.ts +4 -13
  140. package/lib/components/Tearsheet/TearsheetShell.d.ts +119 -10
  141. package/lib/components/Tearsheet/TearsheetShell.js +16 -6
  142. package/lib/components/WebTerminal/WebTerminal.d.ts +46 -2
  143. package/lib/components/WebTerminal/WebTerminal.js +2 -2
  144. package/lib/global/js/hooks/usePrefersReducedMotion.d.ts +2 -0
  145. package/lib/global/js/hooks/usePrefersReducedMotion.js +32 -0
  146. package/lib/global/js/utils/Wrap.d.ts +31 -2
  147. package/lib/global/js/utils/Wrap.js +7 -9
  148. package/lib/global/js/utils/getNodeTextContent.d.ts +1 -1
  149. package/lib/global/js/utils/getNodeTextContent.js +1 -1
  150. package/lib/global/js/utils/window.d.ts +2 -0
  151. package/lib/global/js/utils/window.js +16 -0
  152. package/lib/node_modules/@carbon/icons-react/es/generated/bucket-9.js +2912 -0
  153. package/package.json +4 -4
  154. package/scss/components/CoachmarkOverlayElements/_coachmark-overlay-elements.scss +1 -1
  155. package/scss/components/ConditionBuilder/_condition-builder.scss +26 -0
  156. package/scss/components/ConditionBuilder/styles/_conditionBuilderCondition.scss +46 -0
  157. package/scss/components/ConditionBuilder/styles/_conditionBuilderItem.scss +194 -0
  158. package/scss/components/ConditionBuilder/styles/_index.scss +2 -0
  159. package/scss/components/Guidebanner/_guidebanner.scss +3 -0
  160. package/scss/components/InterstitialScreen/_interstitial-screen.scss +1 -6
  161. package/scss/components/Tearsheet/_tearsheet.scss +3 -1
  162. package/es/components/ConditionBuilder/assets/sampleInput.d.ts +0 -58
  163. package/es/global/js/utils/keyboardNavigation.d.ts +0 -27
  164. package/es/global/js/utils/keyboardNavigation.js +0 -33
  165. package/es/global/js/utils/wrapFocus.d.ts +0 -25
  166. package/es/global/js/utils/wrapFocus.js +0 -68
  167. package/es/node_modules/@carbon/icons-react/es/generated/bucket-8.js +0 -3004
  168. package/lib/components/ConditionBuilder/assets/sampleInput.d.ts +0 -58
  169. package/lib/global/js/utils/keyboardNavigation.d.ts +0 -27
  170. package/lib/global/js/utils/keyboardNavigation.js +0 -39
  171. package/lib/global/js/utils/wrapFocus.d.ts +0 -25
  172. package/lib/global/js/utils/wrapFocus.js +0 -73
  173. package/lib/node_modules/@carbon/icons-react/es/generated/bucket-8.js +0 -3136
@@ -5,18 +5,21 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import { slicedToArray as _slicedToArray, extends as _extends } from '../../../_virtual/_rollupPluginBabelHelpers.js';
9
- import React__default, { useContext, useState, useRef, useEffect } from 'react';
10
- import { pkg } from '../../../settings.js';
8
+ import { slicedToArray as _slicedToArray, objectSpread2 as _objectSpread2, extends as _extends } from '../../../_virtual/_rollupPluginBabelHelpers.js';
9
+ import React__default, { useContext, useState, useEffect, useCallback } from 'react';
11
10
  import PropTypes from '../../../node_modules/prop-types/index.js';
12
11
  import { Button } from '@carbon/react';
13
12
  import { Add } from '@carbon/react/icons';
14
- import { ConditionBuilderContext, emptyState } from '../ConditionBuilderContext/DataTreeContext.js';
13
+ import ConditionGroupBuilder from '../ConditionGroupBuilder/ConditionGroupBuilder.js';
14
+ import { ConditionBuilderContext, emptyState } from '../ConditionBuilderContext/ConditionBuilderProvider.js';
15
+ import { blockClass } from '../ConditionBuilderContext/DataConfigs.js';
15
16
 
16
- var blockClass = "".concat(pkg.prefix, "--condition-builder");
17
- function ConditionBuilderContent(_ref) {
17
+ var ConditionBuilderContent = function ConditionBuilderContent(_ref) {
18
18
  var _rootState$groups2;
19
- var startConditionLabel = _ref.startConditionLabel;
19
+ var startConditionLabel = _ref.startConditionLabel,
20
+ conditionBuilderRef = _ref.conditionBuilderRef,
21
+ getConditionState = _ref.getConditionState,
22
+ initialState = _ref.initialState;
20
23
  var _useContext = useContext(ConditionBuilderContext),
21
24
  rootState = _useContext.rootState,
22
25
  setRootState = _useContext.setRootState;
@@ -24,30 +27,56 @@ function ConditionBuilderContent(_ref) {
24
27
  _useState2 = _slicedToArray(_useState, 2),
25
28
  isConditionBuilderActive = _useState2[0],
26
29
  setIsConditionBuilderActive = _useState2[1];
27
- var conditionBuilderRef = useRef();
28
30
  useEffect(function () {
29
31
  var _rootState$groups;
30
32
  if (rootState !== null && rootState !== void 0 && (_rootState$groups = rootState.groups) !== null && _rootState$groups !== void 0 && _rootState$groups.length) {
31
33
  setIsConditionBuilderActive(false);
32
- if (rootState.groups[0].conditions.length == 1 && rootState.groups[0].conditions[0].property == undefined) {
33
- // when the add condition clicked to start the condition building, we by default open the popover of the first property
34
- setTimeout(function () {
35
- conditionBuilderRef.current.querySelector('.propertyField').click();
36
- }, 0);
37
- }
38
34
  } else {
39
35
  setIsConditionBuilderActive(true);
40
36
  }
41
- }, [rootState]);
37
+ if (getConditionState) {
38
+ getConditionState(rootState);
39
+ }
40
+
41
+ // eslint-disable-next-line react-hooks/exhaustive-deps
42
+ }, [rootState, conditionBuilderRef]);
43
+ useEffect(function () {
44
+ if (isConditionBuilderActive == false) {
45
+ if (conditionBuilderRef.current) {
46
+ var initial = conditionBuilderRef.current.querySelector('[role="gridcell"] button');
47
+ if (initial) {
48
+ initial.setAttribute('tabindex', '0');
49
+ }
50
+ }
51
+ }
52
+ }, [isConditionBuilderActive, conditionBuilderRef]);
42
53
  var onStartConditionBuilder = function onStartConditionBuilder() {
43
54
  //when add condition button is clicked.
44
55
  setIsConditionBuilderActive(false);
45
- setRootState(emptyState); //here we can set an empty skeleton object for an empty condition builder,
56
+ setRootState(initialState !== null && initialState !== void 0 ? initialState : emptyState); //here we can set an empty skeleton object for an empty condition builder,
46
57
  //or we can even pre-populate some existing builder and continue editing
47
58
  };
59
+ var _onRemove = useCallback(function (groupIndex) {
60
+ setRootState(_objectSpread2(_objectSpread2({}, rootState), {}, {
61
+ groups: rootState.groups.filter(function (group, gIndex) {
62
+ return groupIndex !== gIndex;
63
+ })
64
+ }));
65
+ }, [setRootState, rootState]);
66
+ var onChangeHandler = function onChangeHandler(updatedGroup, groupIndex) {
67
+ /**
68
+ * This method is triggered from inner components. This will be called every time when any change is to be updated in the rootState.
69
+ * This gets the updated group as argument.
70
+ */
71
+ setRootState(_objectSpread2(_objectSpread2({}, rootState), {}, {
72
+ groups: rootState.groups.map(function (group, gIndex) {
73
+ return groupIndex === gIndex ? updatedGroup : group;
74
+ })
75
+ }));
76
+ };
48
77
  return /*#__PURE__*/React__default.createElement("div", {
49
- ref: conditionBuilderRef,
50
- className: "".concat(blockClass, "__content-container")
78
+ className: "".concat(blockClass, "__content-container"),
79
+ tabIndex: -1
51
80
  }, isConditionBuilderActive && /*#__PURE__*/React__default.createElement(Button, {
52
81
  className: "".concat(blockClass, "__condition-builder"),
53
82
  renderIcon: function renderIcon(props) {
@@ -59,34 +88,53 @@ function ConditionBuilderContent(_ref) {
59
88
  kind: "ghost",
60
89
  size: "sm",
61
90
  onClick: onStartConditionBuilder
62
- }, startConditionLabel), rootState && (rootState === null || rootState === void 0 || (_rootState$groups2 = rootState.groups) === null || _rootState$groups2 === void 0 ? void 0 : _rootState$groups2.map(function () {
63
- return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, "conditionBuilder group renders here")
64
- // <ConditionBuilderGroup
65
- // state={eachGroup}
66
- // onRemove={() => {
67
- // onRemove(groupIndex);
68
- // }}
69
- // onChange={(updatedGroup) => {
70
- // /**
71
- // * This method is triggered from inner components. This will be called every time when any change is to be updated in the rootState.
72
- // * This gets the updated group as argument.
73
- // */
74
- // setRootState({
75
- // ...rootState,
76
- // groups: rootState.groups.map((group, gIndex) =>
77
- // groupIndex === gIndex ? updatedGroup : group
78
- // ),
79
- // });
80
- // }}
81
- //>
82
- ;
91
+ }, startConditionLabel), rootState && (rootState === null || rootState === void 0 || (_rootState$groups2 = rootState.groups) === null || _rootState$groups2 === void 0 ? void 0 : _rootState$groups2.map(function (eachGroup, groupIndex) {
92
+ return /*#__PURE__*/React__default.createElement(ConditionGroupBuilder, {
93
+ key: groupIndex,
94
+ aria: {
95
+ level: 1,
96
+ posinset: groupIndex * 2 + 1,
97
+ setsize: rootState.groups.length * 2
98
+ },
99
+ state: eachGroup,
100
+ onRemove: function onRemove() {
101
+ _onRemove(groupIndex);
102
+ },
103
+ onChange: function onChange(updatedGroup) {
104
+ onChangeHandler(updatedGroup, groupIndex);
105
+ },
106
+ conditionBuilderRef: conditionBuilderRef
107
+ });
83
108
  })));
84
- }
109
+ };
110
+ var ConditionBuilderContent$1 = ConditionBuilderContent;
85
111
  ConditionBuilderContent.propTypes = {
86
112
  /**
87
- * Provide a label to the button that starts condition builder
113
+ * ref of condition builder
114
+ */
115
+ conditionBuilderRef: PropTypes.object,
116
+ /**
117
+ * This is a callback function that returns the updated state
118
+ */
119
+ getConditionState: PropTypes.func.isRequired,
120
+ /**
121
+ * Optional prop if the condition building need to start from a predefined initial state
122
+ */
123
+ initialState: PropTypes.shape({
124
+ groups: PropTypes.arrayOf(PropTypes.shape({
125
+ groupSeparateOperator: PropTypes.string,
126
+ groupOperator: PropTypes.string,
127
+ statement: PropTypes.string,
128
+ conditions: PropTypes.arrayOf(PropTypes.shape({
129
+ property: PropTypes.string,
130
+ operator: PropTypes.string,
131
+ value: PropTypes.string
132
+ }))
133
+ }))
134
+ }),
135
+ /* Provide a label to the button that starts condition builder
88
136
  */
89
137
  startConditionLabel: PropTypes.string.isRequired
90
138
  };
91
139
 
92
- export { ConditionBuilderContent as default };
140
+ export { ConditionBuilderContent$1 as default };
@@ -7,6 +7,7 @@ export namespace emptyState {
7
7
  property: undefined;
8
8
  operator: string;
9
9
  value: string;
10
+ popoverToOpen: string;
10
11
  }[];
11
12
  }[];
12
13
  }
@@ -15,23 +16,25 @@ export function ConditionBuilderProvider(props: any): import("react/jsx-runtime"
15
16
  export namespace ConditionBuilderProvider {
16
17
  namespace propTypes {
17
18
  let children: PropTypes.Validator<NonNullable<PropTypes.ReactNodeLike>>;
19
+ let getOptions: PropTypes.Requireable<(...args: any[]) => any>;
18
20
  let inputConfig: PropTypes.Validator<NonNullable<PropTypes.InferProps<{
19
21
  properties: PropTypes.Requireable<(PropTypes.InferProps<{
20
22
  id: PropTypes.Requireable<string>;
21
23
  label: PropTypes.Requireable<string>;
22
- icon: PropTypes.Requireable<(...args: any[]) => any>;
24
+ icon: PropTypes.Requireable<object>;
23
25
  type: PropTypes.Requireable<string>;
24
26
  config: PropTypes.Requireable<PropTypes.InferProps<{
25
27
  options: PropTypes.Requireable<(PropTypes.InferProps<{
26
28
  id: PropTypes.Requireable<string>;
27
29
  label: PropTypes.Requireable<string>;
28
- icon: PropTypes.Requireable<(...args: any[]) => any>;
30
+ icon: PropTypes.Requireable<object>;
29
31
  }> | null | undefined)[]>;
30
32
  includeSearch: PropTypes.Requireable<boolean>;
31
33
  }>>;
32
34
  }> | null | undefined)[]>;
33
35
  }>>>;
34
36
  let popOverSearchThreshold: PropTypes.Validator<number>;
37
+ let variant: PropTypes.Validator<string>;
35
38
  }
36
39
  }
37
40
  import React from 'react';
@@ -17,7 +17,8 @@ var emptyState = {
17
17
  conditions: [{
18
18
  property: undefined,
19
19
  operator: '',
20
- value: ''
20
+ value: '',
21
+ popoverToOpen: 'propertyField'
21
22
  }]
22
23
  }]
23
24
  };
@@ -50,7 +51,9 @@ var ConditionBuilderProvider = function ConditionBuilderProvider(props) {
50
51
  rootState: rootState,
51
52
  setRootState: setRootState,
52
53
  inputConfig: props.inputConfig,
53
- popOverSearchThreshold: props.popOverSearchThreshold
54
+ popOverSearchThreshold: props.popOverSearchThreshold,
55
+ getOptions: props.getOptions,
56
+ variant: props.variant
54
57
  }
55
58
  },
56
59
  // eslint-disable-next-line react/prop-types
@@ -61,28 +64,44 @@ ConditionBuilderProvider.propTypes = {
61
64
  * Provide the contents of the ConditionBuilder.
62
65
  */
63
66
  children: PropTypes.node.isRequired,
67
+ /**
68
+ * This is an optional callback function that will be triggered when options array is not passed in the inputConfig against a property.
69
+ * This can be a asynchronous function that need to return a promise, so it will allow to fetch options from API call.
70
+ * options has to be in valid format
71
+ * [{
72
+ label: 'label',
73
+ id: 'id',
74
+ },...]
75
+ */
76
+ getOptions: PropTypes.func,
64
77
  /**
65
78
  * This is a mandatory prop that defines the input to the condition builder.
66
-
79
+
67
80
  */
68
81
  inputConfig: PropTypes.shape({
69
82
  properties: PropTypes.arrayOf(PropTypes.shape({
70
83
  id: PropTypes.string,
71
84
  label: PropTypes.string,
72
- icon: PropTypes.func,
73
- type: PropTypes.oneOf(['text', 'number', 'date', 'option']),
85
+ icon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
86
+ type: PropTypes.oneOf(['text', 'number', 'date', 'option', 'time']),
74
87
  config: PropTypes.shape({
75
88
  options: PropTypes.arrayOf(PropTypes.shape({
76
89
  id: PropTypes.string,
77
90
  label: PropTypes.string,
78
- icon: PropTypes.func
91
+ icon: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
79
92
  })),
80
93
  includeSearch: PropTypes.bool
81
94
  })
82
95
  }))
83
96
  }).isRequired,
84
- popOverSearchThreshold: PropTypes.number.isRequired
85
- /* TODO: add types and DocGen for all props. */
97
+ /**
98
+ * Provide an mandatory numeric value that will be used to enable search option in the popovers with list.
99
+ */
100
+ popOverSearchThreshold: PropTypes.number.isRequired,
101
+ /**
102
+ * Provide the condition builder variant: sentence/ tree
103
+ */
104
+ variant: PropTypes.string.isRequired
86
105
  };
87
106
 
88
107
  export { ConditionBuilderContext, ConditionBuilderProvider, emptyState };
@@ -0,0 +1,22 @@
1
+ export const statementConfig: {
2
+ label: string;
3
+ id: string;
4
+ }[];
5
+ export const connectorConfig: {
6
+ label: string;
7
+ id: string;
8
+ }[];
9
+ export const operatorConfig: {
10
+ label: string;
11
+ id: string;
12
+ type: string;
13
+ }[];
14
+ export const blockClass: string;
15
+ export function translateWithId(key: any): any;
16
+ export namespace valueRenderers {
17
+ function text(val: any): any;
18
+ function time(val: any): any;
19
+ function number(val: any, config: any): any;
20
+ function option(value: any): any;
21
+ function date(value: any): any;
22
+ }
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Copyright IBM Corp. 2020, 2024
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import { pkg } from '../../../settings.js';
9
+ import { translationsObject } from './translationObject.js';
10
+
11
+ var statementConfig = [{
12
+ label: 'if',
13
+ id: 'if'
14
+ }, {
15
+ label: 'excl.if',
16
+ id: 'excl.if'
17
+ }];
18
+ var connectorConfig = [{
19
+ label: 'and',
20
+ id: 'and'
21
+ }, {
22
+ label: 'or',
23
+ id: 'or'
24
+ }];
25
+ //op types : option, text, number, date,
26
+ var operatorConfig = [{
27
+ label: 'is',
28
+ id: 'is',
29
+ type: 'all'
30
+ }, {
31
+ label: 'is greater than',
32
+ id: 'greater',
33
+ type: 'number'
34
+ }, {
35
+ label: 'is greater than or equal to',
36
+ id: 'greater-equal',
37
+ type: 'number'
38
+ }, {
39
+ label: 'is lower than',
40
+ id: 'lower',
41
+ type: 'number'
42
+ }, {
43
+ label: 'is lower than or equal to',
44
+ id: 'lower-equal',
45
+ type: 'number'
46
+ }, {
47
+ label: 'starts with',
48
+ id: 'starts-with',
49
+ type: 'text'
50
+ }, {
51
+ label: 'ends with',
52
+ id: 'ends-with',
53
+ type: 'text'
54
+ }, {
55
+ label: 'contains',
56
+ id: 'contains',
57
+ type: 'text'
58
+ }, {
59
+ label: 'is one of',
60
+ id: 'one-of',
61
+ type: 'option'
62
+ }, {
63
+ label: 'is before',
64
+ id: 'before',
65
+ type: 'date,time'
66
+ }, {
67
+ label: 'is after',
68
+ id: 'after',
69
+ type: 'date,time'
70
+ }, {
71
+ label: 'is between',
72
+ id: 'between',
73
+ type: 'date'
74
+ }];
75
+ // The block part of our conventional BEM class names (blockClass__E--M).
76
+ var blockClass = "".concat(pkg.prefix, "--condition-builder");
77
+ var formatDate = function formatDate(date) {
78
+ var day = String(date.getDate()).padStart(2, '0');
79
+ var month = String(date.getMonth() + 1).padStart(2, '0');
80
+ var year = date.getFullYear();
81
+ return "".concat(day, "/").concat(month, "/").concat(year);
82
+ };
83
+ var translationsObjectCurrent = translationsObject['en']; // TO DO: need to discuss if language is to be passed as prop
84
+ var translateWithId = function translateWithId(key) {
85
+ var _translationsObjectCu;
86
+ return (_translationsObjectCu = translationsObjectCurrent[key]) !== null && _translationsObjectCu !== void 0 ? _translationsObjectCu : key;
87
+ };
88
+ var valueRenderers = {
89
+ text: function text(val) {
90
+ return val;
91
+ },
92
+ time: function time(val) {
93
+ return val;
94
+ },
95
+ number: function number(val, config) {
96
+ return config.unit && val ? "".concat(val, " ").concat(config.unit) : val;
97
+ },
98
+ option: function option(value) {
99
+ return Array.isArray(value) ? value.join(', ') : value;
100
+ },
101
+ date: function date(value) {
102
+ if (Array.isArray(value) && value.length > 1) {
103
+ var start = value !== null && value !== void 0 && value[0] ? formatDate(new Date(value[0])) : '';
104
+ var end = value !== null && value !== void 0 && value[1] ? formatDate(new Date(value[1])) : '';
105
+ return "".concat(start, " To ").concat(end);
106
+ } else {
107
+ return value && new Date(value) ? formatDate(new Date(value)) : value;
108
+ }
109
+ }
110
+ };
111
+
112
+ export { blockClass, connectorConfig, operatorConfig, statementConfig, translateWithId, valueRenderers };
@@ -0,0 +1,31 @@
1
+ export namespace translationsObject {
2
+ let en: {
3
+ if: string;
4
+ 'excl-if': string;
5
+ and: string;
6
+ or: string;
7
+ is: string;
8
+ greater: string;
9
+ 'greater-equal': string;
10
+ lower: string;
11
+ 'lower-equal': string;
12
+ 'starts-with': string;
13
+ 'ends-with': string;
14
+ contains: string;
15
+ 'one-of': string;
16
+ before: string;
17
+ after: string;
18
+ between: string;
19
+ 'add-condition': string;
20
+ condition: string;
21
+ property: string;
22
+ operator: string;
23
+ connector: string;
24
+ condition_row: string;
25
+ remove_condition: string;
26
+ add_condition_row: string;
27
+ start: string;
28
+ end: string;
29
+ clear_search: string;
30
+ };
31
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Copyright IBM Corp. 2020, 2024
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ var translationsObject = {
9
+ en: {
10
+ if: 'if',
11
+ 'excl-if': 'excl.if',
12
+ and: 'and',
13
+ or: 'or',
14
+ is: 'is',
15
+ greater: 'is greater than',
16
+ 'greater-equal': 'is greater than or equal to',
17
+ lower: 'is lower than',
18
+ 'lower-equal': 'is lower than or equal to',
19
+ 'starts-with': 'starts with',
20
+ 'ends-with': 'ends with',
21
+ contains: 'contains',
22
+ 'one-of': 'is one of',
23
+ before: 'is before',
24
+ after: 'is after',
25
+ between: 'is between',
26
+ 'add-condition': 'Add Condition',
27
+ condition: 'Condition',
28
+ property: 'Property',
29
+ operator: 'Operator',
30
+ connector: 'Connector',
31
+ condition_row: 'Condition row',
32
+ remove_condition: 'Remove condition',
33
+ add_condition_row: 'Add condition row',
34
+ start: 'Start',
35
+ end: 'End',
36
+ clear_search: 'Clear search input'
37
+ }
38
+ };
39
+
40
+ export { translationsObject };
@@ -0,0 +1,28 @@
1
+ export function ConditionBuilderItem({ children, className, label, renderIcon, title, type, showToolTip, state, popOverClassName, config, ...rest }: {
2
+ [x: string]: any;
3
+ children: any;
4
+ className: any;
5
+ label: any;
6
+ renderIcon: any;
7
+ title: any;
8
+ type: any;
9
+ showToolTip: any;
10
+ state: any;
11
+ popOverClassName: any;
12
+ config: any;
13
+ }): import("react/jsx-runtime").JSX.Element;
14
+ export namespace ConditionBuilderItem {
15
+ namespace propTypes {
16
+ let children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
17
+ let className: PropTypes.Requireable<string>;
18
+ let config: PropTypes.Requireable<object>;
19
+ let label: PropTypes.Requireable<NonNullable<string | any[] | null | undefined>>;
20
+ let popOverClassName: PropTypes.Requireable<string>;
21
+ let renderIcon: PropTypes.Requireable<object>;
22
+ let showToolTip: PropTypes.Requireable<boolean>;
23
+ let state: PropTypes.Requireable<object>;
24
+ let title: PropTypes.Requireable<string>;
25
+ let type: PropTypes.Requireable<string>;
26
+ }
27
+ }
28
+ import PropTypes from 'prop-types';
@@ -0,0 +1,151 @@
1
+ /**
2
+ * Copyright IBM Corp. 2020, 2024
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import { objectWithoutProperties as _objectWithoutProperties, slicedToArray as _slicedToArray, extends as _extends } from '../../../_virtual/_rollupPluginBabelHelpers.js';
9
+ import React__default, { useRef, useState, useEffect } from 'react';
10
+ import { Popover, PopoverContent, Layer } from '@carbon/react';
11
+ import PropTypes from '../../../node_modules/prop-types/index.js';
12
+ import { Add } from '@carbon/react/icons';
13
+ import { valueRenderers, translateWithId, blockClass } from '../ConditionBuilderContext/DataConfigs.js';
14
+ import { ConditionBuilderButton } from '../ConditionBuilderButton/ConditionBuilderButton.js';
15
+
16
+ var _excluded = ["children", "className", "label", "renderIcon", "title", "type", "showToolTip", "state", "popOverClassName", "config"];
17
+ var ConditionBuilderItem = function ConditionBuilderItem(_ref) {
18
+ var children = _ref.children,
19
+ className = _ref.className,
20
+ label = _ref.label,
21
+ renderIcon = _ref.renderIcon,
22
+ title = _ref.title,
23
+ type = _ref.type,
24
+ showToolTip = _ref.showToolTip,
25
+ state = _ref.state,
26
+ popOverClassName = _ref.popOverClassName,
27
+ config = _ref.config,
28
+ rest = _objectWithoutProperties(_ref, _excluded);
29
+ var contentRef = useRef(null);
30
+ var _useState = useState(label),
31
+ _useState2 = _slicedToArray(_useState, 2),
32
+ propertyLabel = _useState2[0],
33
+ setPropertyLabel = _useState2[1];
34
+ var _useState3 = useState(false),
35
+ _useState4 = _slicedToArray(_useState3, 2),
36
+ open = _useState4[0],
37
+ setOpen = _useState4[1];
38
+ useEffect(function () {
39
+ var propertyId = rest['data-name'] == 'valueField' && type ? valueRenderers[type](label, config) : label;
40
+ setPropertyLabel(translateWithId(propertyId));
41
+ // eslint-disable-next-line react-hooks/exhaustive-deps
42
+ }, [label]);
43
+ useEffect(function () {
44
+ /**
45
+ * rest['data-name'] holds the current field name
46
+ * popoverToOpen hold the next popover to be opened if required
47
+ */
48
+ if (state) {
49
+ var currentField = rest['data-name'];
50
+ //if any condition is changed, state prop is triggered
51
+ if (state.popoverToOpen && currentField !== state.popoverToOpen) {
52
+ // close the previous popover
53
+ setOpen(false);
54
+ } else if (currentField == 'valueField' && type == 'option' && state.operator !== 'one-of') {
55
+ //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.
56
+ setOpen(false);
57
+ }
58
+ if (state.popoverToOpen == currentField) {
59
+ //current popover need to be opened
60
+ setOpen(true);
61
+ }
62
+ } else {
63
+ // when we change any statement(if/ excl.if) which is not part of condition state, label change is triggered.
64
+ //close popOver when statement is changed.
65
+ setOpen(false);
66
+ }
67
+ // eslint-disable-next-line react-hooks/exhaustive-deps
68
+ }, [state, label]);
69
+ useEffect(function () {
70
+ //this will focus the first input field in the popover
71
+ if (open && contentRef.current) {
72
+ var firstFocusableElement = contentRef.current.querySelector('input, button,li');
73
+ if (firstFocusableElement) {
74
+ firstFocusableElement.focus();
75
+ }
76
+ }
77
+ }, [contentRef, open]);
78
+ return /*#__PURE__*/React__default.createElement(Popover, {
79
+ open: open,
80
+ isTabTip: true,
81
+ role: "gridcell",
82
+ className: popOverClassName,
83
+ onRequestClose: function onRequestClose() {
84
+ setOpen(false);
85
+ }
86
+ }, /*#__PURE__*/React__default.createElement(ConditionBuilderButton, _extends({
87
+ label: propertyLabel !== null && propertyLabel !== void 0 ? propertyLabel : translateWithId('add-condition'),
88
+ hideLabel: !label ? true : false,
89
+ onClick: function onClick() {
90
+ setOpen(!open);
91
+ },
92
+ className: className,
93
+ "aria-haspopup": true,
94
+ "aria-expanded": open,
95
+ renderIcon: renderIcon ? renderIcon : label == undefined ? Add : null,
96
+ showToolTip: showToolTip
97
+ }, rest)), /*#__PURE__*/React__default.createElement(PopoverContent, {
98
+ className: "".concat(blockClass, "__condition-builder-item__content"),
99
+ role: "dialog",
100
+ "aria-label": "".concat(title)
101
+ }, /*#__PURE__*/React__default.createElement(Layer, null, /*#__PURE__*/React__default.createElement("h1", {
102
+ className: "".concat(blockClass, "__condition-builder-item__title")
103
+ }, title), /*#__PURE__*/React__default.createElement("div", {
104
+ ref: contentRef
105
+ }, open && children))));
106
+ };
107
+ ConditionBuilderItem.propTypes = {
108
+ /**
109
+ * provide the contents of the popover
110
+ */
111
+ children: PropTypes.node,
112
+ /**
113
+ * Provide an optional class to be applied to the containing node.
114
+ */
115
+ className: PropTypes.string,
116
+ /**
117
+ * this is the config object again the current property from inputConfig
118
+ */
119
+
120
+ config: PropTypes.object,
121
+ /**
122
+ * text to be displayed in the field
123
+ */
124
+ label: PropTypes.oneOfType([PropTypes.string, PropTypes.array]),
125
+ /**
126
+ * class name for popover
127
+ */
128
+ popOverClassName: PropTypes.string,
129
+ /**
130
+ * Optional prop to allow overriding the icon rendering.
131
+ */
132
+ renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
133
+ /**
134
+ * show tool tip
135
+ */
136
+ showToolTip: PropTypes.bool,
137
+ /**
138
+ * current condition state object
139
+ */
140
+ state: PropTypes.object,
141
+ /**
142
+ * title of the popover
143
+ */
144
+ title: PropTypes.string,
145
+ /**
146
+ * input type
147
+ */
148
+ type: PropTypes.string
149
+ };
150
+
151
+ export { ConditionBuilderItem };