@rhc-shared-components/form-multi-select-component 0.0.4 → 0.0.6

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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,37 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## [0.0.4](https://gitlab.cee.redhat.com/customer-platform/rhc-shared-components/compare/@rhc-shared-components/form-multi-select-component@0.0.2...@rhc-shared-components/form-multi-select-component@0.0.4) (2022-10-27)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * added setTouched prop in multiselect component. ([3b0b6ff](https://gitlab.cee.redhat.com/customer-platform/rhc-shared-components/commit/3b0b6ff0445995129bc2b2908861768a513339d8))
12
+ * added touched handler ([82e397e](https://gitlab.cee.redhat.com/customer-platform/rhc-shared-components/commit/82e397e3c8ae90944d3110dd5d7b3d5ff98b0589))
13
+
14
+
15
+
16
+ ## 0.0.3 (2022-10-27)
17
+
18
+
19
+ ### Bug Fixes
20
+
21
+ * added meta.touched prop to the form multi select component. ([590886f](https://gitlab.cee.redhat.com/customer-platform/rhc-shared-components/commit/590886fd8eb49a2153f6d5b512c6bd61cbae205c))
22
+
23
+
24
+
25
+
26
+
27
+ ## [0.0.2](https://gitlab.cee.redhat.com/customer-platform/rhc-shared-components/compare/@rhc-shared-components/form-multi-select-component@0.0.1...@rhc-shared-components/form-multi-select-component@0.0.2) (2022-01-05)
28
+
29
+ **Note:** Version bump only for package @rhc-shared-components/form-multi-select-component
30
+
31
+
32
+
33
+
34
+
35
+ ## 0.0.1 (2021-12-06)
36
+
37
+ **Note:** Version bump only for package @rhc-shared-components/form-multi-select-component
@@ -12,8 +12,10 @@ export interface FormMultiSelectInputProps {
12
12
  selectOptions: IMultiSelectItem[];
13
13
  ariaLabel?: string;
14
14
  helperText?: string;
15
- maxItems?: number;
16
15
  maxHeight?: string | number;
16
+ isDisabled?: boolean;
17
+ classNames?: string;
18
+ menuAppendTo?: HTMLElement | (() => HTMLElement) | 'inline' | 'parent';
17
19
  }
18
20
  declare const FormMultiSelectInput: React.FC<FormMultiSelectInputProps>;
19
21
  export default FormMultiSelectInput;
package/dist/index.js CHANGED
@@ -39,7 +39,7 @@ function _objectWithoutPropertiesLoose(source, excluded) {
39
39
  return target;
40
40
  }
41
41
 
42
- var _excluded = ["label", "isRequired", "children", "selectOptions", "ariaLabel", "placeholder", "helperText", "maxItems", "maxHeight"];
42
+ var _excluded = ["label", "isRequired", "children", "selectOptions", "ariaLabel", "placeholder", "helperText", "maxHeight", "isDisabled", "classNames", "menuAppendTo"];
43
43
 
44
44
  var FormMultiSelectInput = function FormMultiSelectInput(_ref) {
45
45
  var label = _ref.label,
@@ -49,8 +49,10 @@ var FormMultiSelectInput = function FormMultiSelectInput(_ref) {
49
49
  ariaLabel = _ref$ariaLabel === void 0 ? 'Select Input' : _ref$ariaLabel,
50
50
  placeholder = _ref.placeholder,
51
51
  helperText = _ref.helperText,
52
- maxItems = _ref.maxItems,
53
52
  maxHeight = _ref.maxHeight,
53
+ isDisabled = _ref.isDisabled,
54
+ classNames = _ref.classNames,
55
+ menuAppendTo = _ref.menuAppendTo,
54
56
  rest = _objectWithoutPropertiesLoose(_ref, _excluded);
55
57
 
56
58
  var _useField = formik.useField(rest),
@@ -61,42 +63,22 @@ var FormMultiSelectInput = function FormMultiSelectInput(_ref) {
61
63
  var _useFormikContext = formik.useFormikContext(),
62
64
  isSubmitting = _useFormikContext.isSubmitting,
63
65
  setFieldValue = _useFormikContext.setFieldValue,
64
- validateField = _useFormikContext.validateField,
65
66
  setFieldTouched = _useFormikContext.setFieldTouched;
66
67
 
67
68
  var _React$useState = React__namespace.useState(false),
68
69
  isOpen = _React$useState[0],
69
70
  setIsOpen = _React$useState[1];
70
71
 
71
- var _React$useState2 = React__namespace.useState([]),
72
- selected = _React$useState2[0],
73
- setSelected = _React$useState2[1];
74
-
75
72
  var onSelect = function onSelect(_event, selection) {
76
- if (value.includes(selection)) {
77
- setFieldValue(rest.name, value.filter(function (item) {
78
- return item !== selection;
79
- }));
80
- validateField(rest.name);
81
- } else {
82
- if (maxItems && value.length === maxItems) {
83
- return;
84
- }
85
-
86
- setFieldValue(rest.name, [].concat(value, [selection]));
87
- validateField(rest.name);
88
- }
89
-
90
- setFieldTouched(rest.name, true);
73
+ var newValues = value.includes(selection) ? value.filter(function (item) {
74
+ return item !== selection;
75
+ }) : [].concat(value, [selection]);
76
+ setFieldTouched(rest.name, true, false);
77
+ setFieldValue(rest.name, newValues, true);
91
78
  };
92
79
 
93
- React__namespace.useEffect(function () {
94
- setSelected(value);
95
- }, [value]);
96
-
97
80
  var onClear = function onClear() {
98
- setFieldValue(rest.name, []);
99
- validateField(rest.name);
81
+ setFieldValue(rest.name, [], true);
100
82
  setIsOpen(false);
101
83
  };
102
84
 
@@ -119,13 +101,17 @@ var FormMultiSelectInput = function FormMultiSelectInput(_ref) {
119
101
  onToggle: onToggle,
120
102
  onSelect: onSelect,
121
103
  onClear: onClear,
122
- selections: selected,
104
+ selections: value,
123
105
  isOpen: isOpen
124
106
  }, maxHeight && {
125
107
  maxHeight: maxHeight
126
108
  }, {
127
- isDisabled: isSubmitting,
109
+ isDisabled: isSubmitting || isDisabled,
128
110
  "aria-label": ariaLabel
111
+ }, classNames && {
112
+ className: classNames
113
+ }, menuAppendTo && {
114
+ menuAppendTo: menuAppendTo
129
115
  }, rest), lodash.map(selectOptions, function (option, index) {
130
116
  return React__namespace.createElement(reactCore.SelectOption, Object.assign({
131
117
  key: index,
@@ -19,7 +19,7 @@ function _objectWithoutPropertiesLoose(source, excluded) {
19
19
  return target;
20
20
  }
21
21
 
22
- const _excluded = ["label", "isRequired", "children", "selectOptions", "ariaLabel", "placeholder", "helperText", "maxItems", "maxHeight"];
22
+ const _excluded = ["label", "isRequired", "children", "selectOptions", "ariaLabel", "placeholder", "helperText", "maxHeight", "isDisabled", "classNames", "menuAppendTo"];
23
23
 
24
24
  const FormMultiSelectInput = _ref => {
25
25
  let {
@@ -29,8 +29,10 @@ const FormMultiSelectInput = _ref => {
29
29
  ariaLabel = 'Select Input',
30
30
  placeholder,
31
31
  helperText,
32
- maxItems,
33
- maxHeight
32
+ maxHeight,
33
+ isDisabled,
34
+ classNames,
35
+ menuAppendTo
34
36
  } = _ref,
35
37
  rest = _objectWithoutPropertiesLoose(_ref, _excluded);
36
38
 
@@ -41,35 +43,18 @@ const FormMultiSelectInput = _ref => {
41
43
  const {
42
44
  isSubmitting,
43
45
  setFieldValue,
44
- validateField,
45
46
  setFieldTouched
46
47
  } = useFormikContext();
47
48
  const [isOpen, setIsOpen] = React.useState(false);
48
- const [selected, setSelected] = React.useState([]);
49
49
 
50
50
  const onSelect = (_event, selection) => {
51
- if (value.includes(selection)) {
52
- setFieldValue(rest.name, value.filter(item => item !== selection));
53
- validateField(rest.name);
54
- } else {
55
- if (maxItems && value.length === maxItems) {
56
- return;
57
- }
58
-
59
- setFieldValue(rest.name, [...value, selection]);
60
- validateField(rest.name);
61
- }
62
-
63
- setFieldTouched(rest.name, true);
51
+ const newValues = value.includes(selection) ? value.filter(item => item !== selection) : [...value, selection];
52
+ setFieldTouched(rest.name, true, false);
53
+ setFieldValue(rest.name, newValues, true);
64
54
  };
65
55
 
66
- React.useEffect(() => {
67
- setSelected(value);
68
- }, [value]);
69
-
70
56
  const onClear = () => {
71
- setFieldValue(rest.name, []);
72
- validateField(rest.name);
57
+ setFieldValue(rest.name, [], true);
73
58
  setIsOpen(false);
74
59
  };
75
60
 
@@ -92,13 +77,17 @@ const FormMultiSelectInput = _ref => {
92
77
  onToggle: onToggle,
93
78
  onSelect: onSelect,
94
79
  onClear: onClear,
95
- selections: selected,
80
+ selections: value,
96
81
  isOpen: isOpen
97
82
  }, maxHeight && {
98
83
  maxHeight
99
84
  }, {
100
- isDisabled: isSubmitting,
85
+ isDisabled: isSubmitting || isDisabled,
101
86
  "aria-label": ariaLabel
87
+ }, classNames && {
88
+ className: classNames
89
+ }, menuAppendTo && {
90
+ menuAppendTo
102
91
  }, rest), map(selectOptions, (option, index) => React.createElement(SelectOption, Object.assign({
103
92
  key: index,
104
93
  value: option.value,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhc-shared-components/form-multi-select-component",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "project description",
5
5
  "author": "shkale",
6
6
  "license": "MIT",
@@ -76,6 +76,5 @@
76
76
  ],
77
77
  "publishConfig": {
78
78
  "access": "public"
79
- },
80
- "gitHead": "a8ed9cc748eefbfdd57bfae01aef27dd11ea0f0b"
79
+ }
81
80
  }