@carbon/ibm-products 2.43.2-canary.19 → 2.43.2-canary.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. package/css/index-full-carbon.css +32 -1
  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.css +32 -1
  6. package/css/index-without-carbon.css.map +1 -1
  7. package/css/index-without-carbon.min.css +1 -1
  8. package/css/index-without-carbon.min.css.map +1 -1
  9. package/css/index.css +32 -1
  10. package/css/index.css.map +1 -1
  11. package/css/index.min.css +1 -1
  12. package/css/index.min.css.map +1 -1
  13. package/es/components/ConditionBuilder/ConditionBlock/ConditionBlock.js +23 -21
  14. package/es/components/ConditionBuilder/ConditionBuilder.js +67 -20
  15. package/es/components/ConditionBuilder/ConditionBuilderActions/ConditionBuilderActions.d.ts +15 -0
  16. package/es/components/ConditionBuilder/ConditionBuilderActions/ConditionBuilderActions.js +129 -0
  17. package/es/components/ConditionBuilder/ConditionBuilderAdd/ConditionBuilderAdd.js +6 -4
  18. package/es/components/ConditionBuilder/ConditionBuilderButton/ConditionBuilderButton.d.ts +5 -1
  19. package/es/components/ConditionBuilder/ConditionBuilderButton/ConditionBuilderButton.js +16 -4
  20. package/es/components/ConditionBuilder/ConditionBuilderConnector/ConditionConnector.js +2 -2
  21. package/es/components/ConditionBuilder/ConditionBuilderConnector/GroupConnector.js +2 -2
  22. package/es/components/ConditionBuilder/ConditionBuilderContent/ConditionBuilderContent.d.ts +9 -11
  23. package/es/components/ConditionBuilder/ConditionBuilderContent/ConditionBuilderContent.js +36 -32
  24. package/es/components/ConditionBuilder/ConditionBuilderContext/ConditionBuilderProvider.d.ts +0 -1
  25. package/es/components/ConditionBuilder/ConditionBuilderContext/ConditionBuilderProvider.js +7 -2
  26. package/es/components/ConditionBuilder/ConditionBuilderContext/DataConfigs.d.ts +6 -1
  27. package/es/components/ConditionBuilder/ConditionBuilderContext/DataConfigs.js +18 -10
  28. package/es/components/ConditionBuilder/ConditionBuilderContext/translationObject.d.ts +39 -36
  29. package/es/components/ConditionBuilder/ConditionBuilderContext/translationObject.js +12 -10
  30. package/es/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItem.d.ts +1 -1
  31. package/es/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItem.js +24 -16
  32. package/es/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItemNumber/ConditionBuilderItemNumber.js +19 -4
  33. package/es/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItemOption/ItemOption.d.ts +13 -0
  34. package/es/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItemOption/ItemOption.js +109 -0
  35. package/es/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItemOption/{ConditionBuilderItemOption.d.ts → ItemOptionForValueField.d.ts} +2 -2
  36. package/es/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItemOption/{ConditionBuilderItemOption.js → ItemOptionForValueField.js} +58 -33
  37. package/es/components/ConditionBuilder/ConditionGroupBuilder/ConditionGroupBuilder.js +4 -6
  38. package/es/components/ConditionBuilder/ConditionPreview/ConditionPreview.js +14 -5
  39. package/es/components/ConditionBuilder/utils/handleKeyboardEvents.js +1 -2
  40. package/es/components/ConditionBuilder/utils/util.d.ts +1 -0
  41. package/es/components/ConditionBuilder/utils/util.js +16 -1
  42. package/lib/components/ConditionBuilder/ConditionBlock/ConditionBlock.js +23 -21
  43. package/lib/components/ConditionBuilder/ConditionBuilder.js +67 -20
  44. package/lib/components/ConditionBuilder/ConditionBuilderActions/ConditionBuilderActions.d.ts +15 -0
  45. package/lib/components/ConditionBuilder/ConditionBuilderActions/ConditionBuilderActions.js +137 -0
  46. package/lib/components/ConditionBuilder/ConditionBuilderAdd/ConditionBuilderAdd.js +6 -3
  47. package/lib/components/ConditionBuilder/ConditionBuilderButton/ConditionBuilderButton.d.ts +5 -1
  48. package/lib/components/ConditionBuilder/ConditionBuilderButton/ConditionBuilderButton.js +16 -4
  49. package/lib/components/ConditionBuilder/ConditionBuilderConnector/ConditionConnector.js +2 -2
  50. package/lib/components/ConditionBuilder/ConditionBuilderConnector/GroupConnector.js +2 -2
  51. package/lib/components/ConditionBuilder/ConditionBuilderContent/ConditionBuilderContent.d.ts +9 -11
  52. package/lib/components/ConditionBuilder/ConditionBuilderContent/ConditionBuilderContent.js +36 -32
  53. package/lib/components/ConditionBuilder/ConditionBuilderContext/ConditionBuilderProvider.d.ts +0 -1
  54. package/lib/components/ConditionBuilder/ConditionBuilderContext/ConditionBuilderProvider.js +7 -2
  55. package/lib/components/ConditionBuilder/ConditionBuilderContext/DataConfigs.d.ts +6 -1
  56. package/lib/components/ConditionBuilder/ConditionBuilderContext/DataConfigs.js +18 -10
  57. package/lib/components/ConditionBuilder/ConditionBuilderContext/translationObject.d.ts +39 -36
  58. package/lib/components/ConditionBuilder/ConditionBuilderContext/translationObject.js +12 -10
  59. package/lib/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItem.d.ts +1 -1
  60. package/lib/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItem.js +23 -15
  61. package/lib/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItemNumber/ConditionBuilderItemNumber.js +20 -5
  62. package/lib/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItemOption/ItemOption.d.ts +13 -0
  63. package/lib/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItemOption/ItemOption.js +117 -0
  64. package/lib/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItemOption/{ConditionBuilderItemOption.d.ts → ItemOptionForValueField.d.ts} +2 -2
  65. package/lib/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItemOption/{ConditionBuilderItemOption.js → ItemOptionForValueField.js} +56 -31
  66. package/lib/components/ConditionBuilder/ConditionGroupBuilder/ConditionGroupBuilder.js +4 -6
  67. package/lib/components/ConditionBuilder/ConditionPreview/ConditionPreview.js +14 -4
  68. package/lib/components/ConditionBuilder/utils/handleKeyboardEvents.js +1 -2
  69. package/lib/components/ConditionBuilder/utils/util.d.ts +1 -0
  70. package/lib/components/ConditionBuilder/utils/util.js +17 -0
  71. package/package.json +3 -3
  72. package/scss/components/ConditionBuilder/styles/_conditionBuilderCondition.scss +9 -1
  73. package/scss/components/ConditionBuilder/styles/_conditionBuilderItem.scss +26 -1
  74. package/es/components/ConditionBuilder/utils/checkForHoldingKey.d.ts +0 -1
  75. package/es/components/ConditionBuilder/utils/checkForHoldingKey.js +0 -16
  76. package/lib/components/ConditionBuilder/utils/checkForHoldingKey.d.ts +0 -1
  77. package/lib/components/ConditionBuilder/utils/checkForHoldingKey.js +0 -20
@@ -21,7 +21,6 @@ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
21
21
  var emptyState = {
22
22
  operator: 'or',
23
23
  groups: [{
24
- groupSeparateOperator: null,
25
24
  groupOperator: 'and',
26
25
  statement: 'if',
27
26
  id: uuidv4["default"](),
@@ -58,10 +57,16 @@ var ConditionBuilderProvider = function ConditionBuilderProvider(props) {
58
57
  _useState2 = _rollupPluginBabelHelpers.slicedToArray(_useState, 2),
59
58
  rootState = _useState2[0],
60
59
  setRootState = _useState2[1];
60
+ var _useState3 = React.useState([]),
61
+ _useState4 = _rollupPluginBabelHelpers.slicedToArray(_useState3, 2),
62
+ actionState = _useState4[0],
63
+ setActionState = _useState4[1];
61
64
  return /*#__PURE__*/React__default["default"].createElement(ConditionBuilderContext.Provider, {
62
65
  value: {
63
66
  rootState: rootState,
64
67
  setRootState: setRootState,
68
+ actionState: actionState,
69
+ setActionState: setActionState,
65
70
  inputConfig: props.inputConfig,
66
71
  popOverSearchThreshold: props.popOverSearchThreshold,
67
72
  getOptions: props.getOptions,
@@ -95,7 +100,7 @@ ConditionBuilderProvider.propTypes = {
95
100
  id: index["default"].string,
96
101
  label: index["default"].string,
97
102
  icon: index["default"].oneOfType([index["default"].func, index["default"].object]),
98
- type: index["default"].oneOf(['text', 'number', 'date', 'option', 'time']),
103
+ type: index["default"].oneOf(['text', 'number', 'date', 'option', 'time', 'custom']),
99
104
  config: index["default"].shape({
100
105
  options: index["default"].arrayOf(index["default"].shape({
101
106
  id: index["default"].string,
@@ -6,6 +6,10 @@ export const connectorConfig: {
6
6
  label: string;
7
7
  id: string;
8
8
  }[];
9
+ export const actionConfig: {
10
+ label: string;
11
+ id: string;
12
+ }[];
9
13
  export const operatorConfig: {
10
14
  label: string;
11
15
  id: string;
@@ -16,7 +20,8 @@ export function translateWithId(key: any): any;
16
20
  export namespace valueRenderers {
17
21
  function text(val: any): any;
18
22
  function time(val: any): any;
19
- function number(val: any, config: any): any;
23
+ function number(val: any): any;
20
24
  function option(value: any): any;
21
25
  function date(value: any): any;
26
+ function custom(value: any): any;
22
27
  }
@@ -17,7 +17,7 @@ var statementConfig = [{
17
17
  id: 'if'
18
18
  }, {
19
19
  label: 'excl.if',
20
- id: 'excl.if'
20
+ id: 'excl_if'
21
21
  }];
22
22
  var connectorConfig = [{
23
23
  label: 'and',
@@ -26,7 +26,6 @@ var connectorConfig = [{
26
26
  label: 'or',
27
27
  id: 'or'
28
28
  }];
29
- //op types : option, text, number, date,
30
29
  var operatorConfig = [{
31
30
  label: 'is',
32
31
  id: 'is',
@@ -37,7 +36,7 @@ var operatorConfig = [{
37
36
  type: 'number'
38
37
  }, {
39
38
  label: 'is greater than or equal to',
40
- id: 'greater-equal',
39
+ id: 'greater_equal',
41
40
  type: 'number'
42
41
  }, {
43
42
  label: 'is lower than',
@@ -45,15 +44,15 @@ var operatorConfig = [{
45
44
  type: 'number'
46
45
  }, {
47
46
  label: 'is lower than or equal to',
48
- id: 'lower-equal',
47
+ id: 'lower_equal',
49
48
  type: 'number'
50
49
  }, {
51
50
  label: 'starts with',
52
- id: 'starts-with',
51
+ id: 'starts_with',
53
52
  type: 'text'
54
53
  }, {
55
54
  label: 'ends with',
56
- id: 'ends-with',
55
+ id: 'ends_with',
57
56
  type: 'text'
58
57
  }, {
59
58
  label: 'contains',
@@ -61,7 +60,7 @@ var operatorConfig = [{
61
60
  type: 'text'
62
61
  }, {
63
62
  label: 'is one of',
64
- id: 'one-of',
63
+ id: 'one_of',
65
64
  type: 'option'
66
65
  }, {
67
66
  label: 'is before',
@@ -96,11 +95,17 @@ var valueRenderers = {
96
95
  time: function time(val) {
97
96
  return val;
98
97
  },
99
- number: function number(val, config) {
100
- return config.unit && val ? "".concat(val, " ").concat(config.unit) : val;
98
+ number: function number(val) {
99
+ return val;
101
100
  },
102
101
  option: function option(value) {
103
- return Array.isArray(value) ? value.join(', ') : value;
102
+ if (value && typeof value !== 'string') {
103
+ var selectedValues = Array.isArray(value) ? value : [value];
104
+ return selectedValues.map(function (option) {
105
+ return option.label;
106
+ }).join(', ');
107
+ }
108
+ return value;
104
109
  },
105
110
  date: function date(value) {
106
111
  if (Array.isArray(value) && value.length > 1) {
@@ -110,6 +115,9 @@ var valueRenderers = {
110
115
  } else {
111
116
  return value && new Date(value) ? formatDate(new Date(value)) : value;
112
117
  }
118
+ },
119
+ custom: function custom(value) {
120
+ return value;
113
121
  }
114
122
  };
115
123
 
@@ -1,38 +1,41 @@
1
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
- 'add-condition-group': string;
21
- 'add-condition-sub-group': string;
22
- condition: string;
23
- property: string;
24
- operator: string;
25
- value: string;
26
- connector: string;
27
- condition_row: string;
28
- remove_condition: string;
29
- add_condition_row: string;
30
- start: string;
31
- end: string;
32
- clear_search: string;
33
- actions: string;
34
- then: string;
35
- remove_action: string;
36
- add_action: string;
37
- };
2
+ namespace en {
3
+ let _if: string;
4
+ export { _if as if };
5
+ export let excl_if: string;
6
+ export let and: string;
7
+ export let or: string;
8
+ export let is: string;
9
+ export let greater: string;
10
+ export let greater_equal: string;
11
+ export let lower: string;
12
+ export let lower_equal: string;
13
+ export let starts_with: string;
14
+ export let ends_with: string;
15
+ export let contains: string;
16
+ export let one_of: string;
17
+ export let before: string;
18
+ export let after: string;
19
+ export let between: string;
20
+ export let add_condition: string;
21
+ export let add_condition_group: string;
22
+ export let add_subgroup: string;
23
+ export let condition: string;
24
+ export let property: string;
25
+ export let operator: string;
26
+ export let value: string;
27
+ export let connector: string;
28
+ export let condition_row: string;
29
+ export let remove_condition: string;
30
+ export let add_condition_row: string;
31
+ export let start: string;
32
+ export let end: string;
33
+ export let clear_search: string;
34
+ export let actions: string;
35
+ export let then: string;
36
+ export let remove_action: string;
37
+ export let add_action: string;
38
+ export let invalid_text: string;
39
+ export let text_invalid_number: string;
40
+ }
38
41
  }
@@ -12,24 +12,24 @@ Object.defineProperty(exports, '__esModule', { value: true });
12
12
  var translationsObject = {
13
13
  en: {
14
14
  if: 'if',
15
- 'excl-if': 'excl.if',
15
+ excl_if: 'excl.if',
16
16
  and: 'and',
17
17
  or: 'or',
18
18
  is: 'is',
19
19
  greater: 'is greater than',
20
- 'greater-equal': 'is greater than or equal to',
20
+ greater_equal: 'is greater than or equal to',
21
21
  lower: 'is lower than',
22
- 'lower-equal': 'is lower than or equal to',
23
- 'starts-with': 'starts with',
24
- 'ends-with': 'ends with',
22
+ lower_equal: 'is lower than or equal to',
23
+ starts_with: 'starts with',
24
+ ends_with: 'ends with',
25
25
  contains: 'contains',
26
- 'one-of': 'is one of',
26
+ one_of: 'is one of',
27
27
  before: 'is before',
28
28
  after: 'is after',
29
29
  between: 'is between',
30
- 'add-condition': 'Add Condition',
31
- 'add-condition-group': 'Add Condition Group',
32
- 'add-condition-sub-group': 'Add Condition sub group',
30
+ add_condition: 'Add condition',
31
+ add_condition_group: 'Add condition group',
32
+ add_subgroup: 'Add subgroup',
33
33
  condition: 'Condition',
34
34
  property: 'Property',
35
35
  operator: 'Operator',
@@ -44,7 +44,9 @@ var translationsObject = {
44
44
  actions: 'Actions',
45
45
  then: 'then',
46
46
  remove_action: 'Remove Action',
47
- add_action: 'Add action'
47
+ add_action: 'Add action',
48
+ invalid_text: 'Incomplete',
49
+ text_invalid_number: 'Invalid number, must be 0 or greater'
48
50
  }
49
51
  };
50
52
 
@@ -17,7 +17,7 @@ export namespace ConditionBuilderItem {
17
17
  let className: PropTypes.Requireable<string>;
18
18
  let condition: PropTypes.Requireable<object>;
19
19
  let config: PropTypes.Requireable<object>;
20
- let label: PropTypes.Requireable<NonNullable<string | any[] | null | undefined>>;
20
+ let label: PropTypes.Requireable<NonNullable<string | object | null | undefined>>;
21
21
  let popOverClassName: PropTypes.Requireable<string>;
22
22
  let renderIcon: PropTypes.Requireable<object>;
23
23
  let showToolTip: PropTypes.Requireable<boolean>;
@@ -35,19 +35,26 @@ var ConditionBuilderItem = function ConditionBuilderItem(_ref) {
35
35
  config = _ref.config,
36
36
  rest = _rollupPluginBabelHelpers.objectWithoutProperties(_ref, _excluded);
37
37
  var contentRef = React.useRef(null);
38
- var _useState = React.useState(label),
38
+ var _useState = React.useState(false),
39
39
  _useState2 = _rollupPluginBabelHelpers.slicedToArray(_useState, 2),
40
- propertyLabel = _useState2[0],
41
- setPropertyLabel = _useState2[1];
42
- var _useState3 = React.useState(false),
43
- _useState4 = _rollupPluginBabelHelpers.slicedToArray(_useState3, 2),
44
- open = _useState4[0],
45
- setOpen = _useState4[1];
46
- React.useEffect(function () {
40
+ open = _useState2[0],
41
+ setOpen = _useState2[1];
42
+ var getPropertyDetails = function getPropertyDetails() {
43
+ if (label === 'INVALID') {
44
+ return {
45
+ propertyLabel: DataConfigs.translateWithId('invalid_text'),
46
+ isInvalid: true
47
+ };
48
+ }
47
49
  var propertyId = rest['data-name'] == 'valueField' && type ? DataConfigs.valueRenderers[type](label, config) : label;
48
- setPropertyLabel(DataConfigs.translateWithId(propertyId));
49
- // eslint-disable-next-line react-hooks/exhaustive-deps
50
- }, [label]);
50
+ return {
51
+ isInvalid: false,
52
+ propertyLabel: DataConfigs.translateWithId(propertyId)
53
+ };
54
+ };
55
+ var _getPropertyDetails = getPropertyDetails(),
56
+ propertyLabel = _getPropertyDetails.propertyLabel,
57
+ isInvalid = _getPropertyDetails.isInvalid;
51
58
  React.useEffect(function () {
52
59
  /**
53
60
  * rest['data-name'] holds the current field name
@@ -59,7 +66,7 @@ var ConditionBuilderItem = function ConditionBuilderItem(_ref) {
59
66
  if (condition.popoverToOpen && currentField !== condition.popoverToOpen) {
60
67
  // close the previous popover
61
68
  setOpen(false);
62
- } else if (currentField == 'valueField' && type == 'option' && condition.operator !== 'one-of') {
69
+ } else if (currentField == 'valueField' && type == 'option' && condition.operator !== 'one_of') {
63
70
  //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.
64
71
  setOpen(false);
65
72
  }
@@ -92,7 +99,7 @@ var ConditionBuilderItem = function ConditionBuilderItem(_ref) {
92
99
  setOpen(false);
93
100
  }
94
101
  }, /*#__PURE__*/React__default["default"].createElement(ConditionBuilderButton.ConditionBuilderButton, _rollupPluginBabelHelpers["extends"]({
95
- label: propertyLabel !== null && propertyLabel !== void 0 ? propertyLabel : DataConfigs.translateWithId('add-condition'),
102
+ label: propertyLabel !== null && propertyLabel !== void 0 ? propertyLabel : DataConfigs.translateWithId('add_condition'),
96
103
  hideLabel: !label ? true : false,
97
104
  onClick: function onClick() {
98
105
  children ? setOpen(!open) : null;
@@ -101,7 +108,8 @@ var ConditionBuilderItem = function ConditionBuilderItem(_ref) {
101
108
  "aria-haspopup": true,
102
109
  "aria-expanded": open,
103
110
  renderIcon: renderIcon ? renderIcon : label == undefined ? icons.Add : null,
104
- showToolTip: showToolTip
111
+ showToolTip: showToolTip,
112
+ isInvalid: isInvalid
105
113
  }, rest)), /*#__PURE__*/React__default["default"].createElement(react.PopoverContent, {
106
114
  className: "".concat(DataConfigs.blockClass, "__item__content"),
107
115
  role: "dialog",
@@ -133,7 +141,7 @@ ConditionBuilderItem.propTypes = {
133
141
  /**
134
142
  * text to be displayed in the field
135
143
  */
136
- label: index["default"].oneOfType([index["default"].string, index["default"].array]),
144
+ label: index["default"].oneOfType([index["default"].string, index["default"].array, index["default"].object]),
137
145
  /**
138
146
  * class name for popover
139
147
  */
@@ -11,14 +11,13 @@ Object.defineProperty(exports, '__esModule', { value: true });
11
11
 
12
12
  var React = require('react');
13
13
  var react = require('@carbon/react');
14
- var settings = require('../../../../settings.js');
15
14
  var index = require('../../../../node_modules/prop-types/index.js');
15
+ var DataConfigs = require('../../ConditionBuilderContext/DataConfigs.js');
16
16
 
17
17
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
18
18
 
19
19
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
20
20
 
21
- var blockClass = "".concat(settings.pkg.prefix, "--condition-builder");
22
21
  var ConditionBuilderItemNumber = function ConditionBuilderItemNumber(_ref) {
23
22
  var _conditionState$prope;
24
23
  var conditionState = _ref.conditionState,
@@ -26,18 +25,34 @@ var ConditionBuilderItemNumber = function ConditionBuilderItemNumber(_ref) {
26
25
  onChange = _ref.onChange;
27
26
  var onChangeHandler = function onChangeHandler(e, _ref2) {
28
27
  var value = _ref2.value;
29
- onChange(value + '');
28
+ if (checkIfValid(value)) {
29
+ var _config$unit;
30
+ onChange("".concat(value, " ").concat((_config$unit = config.unit) !== null && _config$unit !== void 0 ? _config$unit : ''));
31
+ } else {
32
+ onChange('INVALID');
33
+ }
34
+ };
35
+ var checkIfValid = function checkIfValid(value) {
36
+ if (value > config.max || value < config.min) {
37
+ return false;
38
+ }
39
+ return true;
40
+ };
41
+ var getDefaultValue = function getDefaultValue() {
42
+ var _conditionState$value;
43
+ return (_conditionState$value = conditionState.value) === null || _conditionState$value === void 0 || (_conditionState$value = _conditionState$value.split(' ')) === null || _conditionState$value === void 0 ? void 0 : _conditionState$value[0];
30
44
  };
31
45
  return /*#__PURE__*/React__default["default"].createElement("div", {
32
- className: "".concat(blockClass, "__item-number")
46
+ className: "".concat(DataConfigs.blockClass, "__item-number")
33
47
  }, /*#__PURE__*/React__default["default"].createElement(react.NumberInput, {
34
48
  label: conditionState.property,
35
49
  hideLabel: true,
50
+ defaultValue: getDefaultValue(),
36
51
  id: (_conditionState$prope = conditionState.property) === null || _conditionState$prope === void 0 ? void 0 : _conditionState$prope.replace(/\s/g, ''),
37
- value: conditionState.value ? conditionState.value.split(' ')[0] : conditionState.value,
38
52
  min: config.min,
39
53
  max: config.max,
40
54
  step: config.step,
55
+ invalidText: DataConfigs.translateWithId('text_invalid_number'),
41
56
  allowEmpty: true,
42
57
  onChange: onChangeHandler
43
58
  }));
@@ -0,0 +1,13 @@
1
+ export function ItemOption({ conditionState, config, onChange }: {
2
+ conditionState?: {} | undefined;
3
+ config?: {} | undefined;
4
+ onChange: any;
5
+ }): import("react/jsx-runtime").JSX.Element | undefined;
6
+ export namespace ItemOption {
7
+ namespace propTypes {
8
+ let conditionState: PropTypes.Requireable<object>;
9
+ let config: PropTypes.Requireable<object>;
10
+ let onChange: PropTypes.Requireable<(...args: any[]) => any>;
11
+ }
12
+ }
13
+ import PropTypes from 'prop-types';
@@ -0,0 +1,117 @@
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
+ 'use strict';
9
+
10
+ Object.defineProperty(exports, '__esModule', { value: true });
11
+
12
+ var _rollupPluginBabelHelpers = require('../../../../_virtual/_rollupPluginBabelHelpers.js');
13
+ var React = require('react');
14
+ var react = require('@carbon/react');
15
+ var icons = require('@carbon/react/icons');
16
+ var index = require('../../../../node_modules/prop-types/index.js');
17
+ var ConditionBuilderProvider = require('../../ConditionBuilderContext/ConditionBuilderProvider.js');
18
+ var DataConfigs = require('../../ConditionBuilderContext/DataConfigs.js');
19
+
20
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
21
+
22
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
23
+
24
+ var ItemOption = function ItemOption(_ref) {
25
+ var _ref$conditionState = _ref.conditionState,
26
+ conditionState = _ref$conditionState === void 0 ? {} : _ref$conditionState,
27
+ _ref$config = _ref.config,
28
+ config = _ref$config === void 0 ? {} : _ref$config,
29
+ onChange = _ref.onChange;
30
+ var _useContext = React.useContext(ConditionBuilderProvider.ConditionBuilderContext),
31
+ popOverSearchThreshold = _useContext.popOverSearchThreshold;
32
+ var contentRef = React.useRef();
33
+ var allOptions = config.options;
34
+ var _useState = React.useState(''),
35
+ _useState2 = _rollupPluginBabelHelpers.slicedToArray(_useState, 2),
36
+ searchValue = _useState2[0],
37
+ setSearchValue = _useState2[1];
38
+ var selection = conditionState.value;
39
+ var filteredItems = allOptions === null || allOptions === void 0 ? void 0 : allOptions.filter(function (opt) {
40
+ return opt.label.toLowerCase().includes(searchValue.toLowerCase());
41
+ });
42
+ React.useEffect(function () {
43
+ //this will focus the first input field in the popover
44
+
45
+ if (contentRef.current) {
46
+ var firstFocusableElement = contentRef.current.querySelector('input, button,li');
47
+ if (firstFocusableElement) {
48
+ firstFocusableElement.focus();
49
+ }
50
+ }
51
+ }, [allOptions]);
52
+ var onClickHandler = function onClickHandler(evt, option) {
53
+ onChange(option.id, evt);
54
+ };
55
+ var onSearchChangeHandler = function onSearchChangeHandler(evt) {
56
+ var value = evt.target.value;
57
+ setSearchValue(value);
58
+ };
59
+ var getAriaLabel = function getAriaLabel() {
60
+ return conditionState.label ? conditionState.label : conditionState.property ? conditionState.property : DataConfigs.translateWithId('property');
61
+ };
62
+ if (!allOptions) {
63
+ return;
64
+ }
65
+ return /*#__PURE__*/React__default["default"].createElement("div", {
66
+ className: "".concat(DataConfigs.blockClass, "__item-option"),
67
+ ref: contentRef
68
+ }, allOptions.length > popOverSearchThreshold && /*#__PURE__*/React__default["default"].createElement("div", {
69
+ className: "".concat(DataConfigs.blockClass, "__item-option__search")
70
+ }, /*#__PURE__*/React__default["default"].createElement(react.Search, {
71
+ size: "sm",
72
+ labelText: DataConfigs.translateWithId('clear_search'),
73
+ closeButtonLabelText: DataConfigs.translateWithId('clear_search'),
74
+ onChange: onSearchChangeHandler
75
+ })), /*#__PURE__*/React__default["default"].createElement("ul", {
76
+ "aria-label": getAriaLabel(),
77
+ role: "listbox"
78
+ }, filteredItems === null || filteredItems === void 0 ? void 0 : filteredItems.map(function (option) {
79
+ var isSelected = selection === option.id;
80
+ var Icon = option.icon;
81
+ return /*#__PURE__*/React__default["default"].createElement("li", {
82
+ tabIndex: 0,
83
+ key: option.id,
84
+ role: "option",
85
+ "aria-selected": isSelected,
86
+ className: "".concat(DataConfigs.blockClass, "__item-option__option"),
87
+ onKeyUp: function onKeyUp() {
88
+ return false;
89
+ },
90
+ onClick: function onClick(evt) {
91
+ return onClickHandler(evt, option);
92
+ }
93
+ }, /*#__PURE__*/React__default["default"].createElement("div", {
94
+ className: "".concat(DataConfigs.blockClass, "__item-option__option-content")
95
+ }, /*#__PURE__*/React__default["default"].createElement("span", {
96
+ className: "".concat(DataConfigs.blockClass, "__item-option__option-label")
97
+ }, Icon && /*#__PURE__*/React__default["default"].createElement(Icon, null), option.label), isSelected && /*#__PURE__*/React__default["default"].createElement(icons.Checkmark, {
98
+ className: "".concat(DataConfigs.blockClass, "__checkmark")
99
+ })));
100
+ })));
101
+ };
102
+ ItemOption.propTypes = {
103
+ /**
104
+ * current condition object
105
+ */
106
+ conditionState: index["default"].object,
107
+ /**
108
+ * current config object that this property is part of
109
+ */
110
+ config: index["default"].object,
111
+ /**
112
+ * callback to update state oin date change
113
+ */
114
+ onChange: index["default"].func
115
+ };
116
+
117
+ exports.ItemOption = ItemOption;
@@ -1,9 +1,9 @@
1
- export function ConditionBuilderItemOption({ conditionState, config, onChange, }: {
1
+ export function ItemOptionForValueField({ conditionState, config, onChange, }: {
2
2
  conditionState?: {} | undefined;
3
3
  config?: {} | undefined;
4
4
  onChange: any;
5
5
  }): import("react/jsx-runtime").JSX.Element;
6
- export namespace ConditionBuilderItemOption {
6
+ export namespace ItemOptionForValueField {
7
7
  namespace propTypes {
8
8
  let conditionState: PropTypes.Requireable<object>;
9
9
  let config: PropTypes.Requireable<object>;