@rhc-shared-components/form-multi-select-component 0.1.1 → 0.1.3

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.
@@ -18,7 +18,6 @@ export interface FormMultiSelectInputProps {
18
18
  isDisabled?: boolean;
19
19
  classNames?: string;
20
20
  menuAppendTo?: HTMLElement | (() => HTMLElement) | 'inline' | 'parent';
21
- chipGroupComponent?: React.ReactNode;
22
21
  extraProps?: any;
23
22
  }
24
23
  declare const FormMultiSelectInput: React.FC<FormMultiSelectInputProps>;
package/dist/index.js CHANGED
@@ -57,7 +57,7 @@ function _objectWithoutPropertiesLoose(source, excluded) {
57
57
  return target;
58
58
  }
59
59
 
60
- var _excluded = ["label", "isRequired", "children", "selectOptions", "ariaLabel", "placeholder", "helperText", "maxHeight", "isDisabled", "classNames", "menuAppendTo", "chipGroupComponent", "extraProps"];
60
+ var _excluded = ["label", "isRequired", "children", "selectOptions", "ariaLabel", "placeholder", "helperText", "maxHeight", "isDisabled", "classNames", "menuAppendTo", "extraProps"];
61
61
 
62
62
  var FormMultiSelectInput = function FormMultiSelectInput(_ref) {
63
63
  var label = _ref.label,
@@ -71,7 +71,6 @@ var FormMultiSelectInput = function FormMultiSelectInput(_ref) {
71
71
  isDisabled = _ref.isDisabled,
72
72
  classNames = _ref.classNames,
73
73
  menuAppendTo = _ref.menuAppendTo,
74
- chipGroupComponent = _ref.chipGroupComponent,
75
74
  extraProps = _ref.extraProps,
76
75
  rest = _objectWithoutPropertiesLoose(_ref, _excluded);
77
76
 
@@ -97,8 +96,36 @@ var FormMultiSelectInput = function FormMultiSelectInput(_ref) {
97
96
  setFieldValue(rest.name, newValues, true);
98
97
  };
99
98
 
99
+ var disabledItems = selectOptions.filter(function (selectItem) {
100
+ var _selectItem$extraProp;
101
+
102
+ return (selectItem == null ? void 0 : selectItem.isDisabled) || (selectItem == null ? void 0 : (_selectItem$extraProp = selectItem.extraProps) == null ? void 0 : _selectItem$extraProp.isDisabled);
103
+ });
104
+
105
+ var CustomChipGroup = function CustomChipGroup() {
106
+ return React__namespace.createElement(reactCore.ChipGroup, null, (value || []).map(function (currentValue) {
107
+ return React__namespace.createElement(reactCore.Chip, {
108
+ isReadOnly: !!disabledItems.find(function (item) {
109
+ return item.value === currentValue;
110
+ }),
111
+ key: currentValue,
112
+ onClick: function onClick(event) {
113
+ return onSelect(event, currentValue);
114
+ }
115
+ }, currentValue);
116
+ }));
117
+ };
118
+
100
119
  var onClear = function onClear() {
101
- setFieldValue(rest.name, [], true);
120
+ var filtered = value == null ? void 0 : value.filter(function (item) {
121
+ var _selectItem$extraProp2;
122
+
123
+ var selectItem = disabledItems.find(function (obj) {
124
+ return obj.value === item;
125
+ });
126
+ return (selectItem == null ? void 0 : selectItem.isDisabled) || (selectItem == null ? void 0 : (_selectItem$extraProp2 = selectItem.extraProps) == null ? void 0 : _selectItem$extraProp2.isDisabled);
127
+ });
128
+ setFieldValue(rest.name, [].concat(filtered), true);
102
129
  setIsOpen(false);
103
130
  };
104
131
 
@@ -128,8 +155,8 @@ var FormMultiSelectInput = function FormMultiSelectInput(_ref) {
128
155
  }, {
129
156
  isDisabled: isSubmitting || isDisabled,
130
157
  "aria-label": ariaLabel
131
- }, chipGroupComponent && {
132
- chipGroupComponent: chipGroupComponent
158
+ }, disabledItems && {
159
+ chipGroupComponent: React__namespace.createElement(CustomChipGroup, null)
133
160
  }, classNames && {
134
161
  className: classNames
135
162
  }, menuAppendTo && {
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { useField, useFormikContext } from 'formik';
3
- import { ValidatedOptions, Select, SelectVariant, SelectOption } from '@patternfly/react-core';
3
+ import { ValidatedOptions, Select, SelectVariant, SelectOption, ChipGroup, Chip } from '@patternfly/react-core';
4
4
  import { FormGroupContainer } from '@rhc-shared-components/form-group-container';
5
5
  import { map } from 'lodash';
6
6
 
@@ -37,7 +37,7 @@ function _objectWithoutPropertiesLoose(source, excluded) {
37
37
  return target;
38
38
  }
39
39
 
40
- const _excluded = ["label", "isRequired", "children", "selectOptions", "ariaLabel", "placeholder", "helperText", "maxHeight", "isDisabled", "classNames", "menuAppendTo", "chipGroupComponent", "extraProps"];
40
+ const _excluded = ["label", "isRequired", "children", "selectOptions", "ariaLabel", "placeholder", "helperText", "maxHeight", "isDisabled", "classNames", "menuAppendTo", "extraProps"];
41
41
 
42
42
  const FormMultiSelectInput = _ref => {
43
43
  let {
@@ -51,7 +51,6 @@ const FormMultiSelectInput = _ref => {
51
51
  isDisabled,
52
52
  classNames,
53
53
  menuAppendTo,
54
- chipGroupComponent,
55
54
  extraProps
56
55
  } = _ref,
57
56
  rest = _objectWithoutPropertiesLoose(_ref, _excluded);
@@ -73,8 +72,26 @@ const FormMultiSelectInput = _ref => {
73
72
  setFieldValue(rest.name, newValues, true);
74
73
  };
75
74
 
75
+ const disabledItems = selectOptions.filter(selectItem => {
76
+ var _selectItem$extraProp;
77
+
78
+ return (selectItem == null ? void 0 : selectItem.isDisabled) || (selectItem == null ? void 0 : (_selectItem$extraProp = selectItem.extraProps) == null ? void 0 : _selectItem$extraProp.isDisabled);
79
+ });
80
+
81
+ const CustomChipGroup = () => React.createElement(ChipGroup, null, (value || []).map(currentValue => React.createElement(Chip, {
82
+ isReadOnly: !!disabledItems.find(item => item.value === currentValue),
83
+ key: currentValue,
84
+ onClick: event => onSelect(event, currentValue)
85
+ }, currentValue)));
86
+
76
87
  const onClear = () => {
77
- setFieldValue(rest.name, [], true);
88
+ const filtered = value == null ? void 0 : value.filter(item => {
89
+ var _selectItem$extraProp2;
90
+
91
+ const selectItem = disabledItems.find(obj => obj.value === item);
92
+ return (selectItem == null ? void 0 : selectItem.isDisabled) || (selectItem == null ? void 0 : (_selectItem$extraProp2 = selectItem.extraProps) == null ? void 0 : _selectItem$extraProp2.isDisabled);
93
+ });
94
+ setFieldValue(rest.name, [...filtered], true);
78
95
  setIsOpen(false);
79
96
  };
80
97
 
@@ -104,8 +121,8 @@ const FormMultiSelectInput = _ref => {
104
121
  }, {
105
122
  isDisabled: isSubmitting || isDisabled,
106
123
  "aria-label": ariaLabel
107
- }, chipGroupComponent && {
108
- chipGroupComponent
124
+ }, disabledItems && {
125
+ chipGroupComponent: React.createElement(CustomChipGroup, null)
109
126
  }, classNames && {
110
127
  className: classNames
111
128
  }, menuAppendTo && {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhc-shared-components/form-multi-select-component",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "project description",
5
5
  "author": "shkale",
6
6
  "license": "MIT",