@mailstep/design-system 0.8.22 → 0.8.23-beta.0

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.
@@ -64,7 +64,7 @@ import omit from 'lodash/fp/omit';
64
64
  var CREATE = "_create_".concat(nanoid(), "_");
65
65
  var defaultFilterOption = createFilter();
66
66
  var creatableFilterOption = function (option, rawInput) {
67
- if ((option === null || option === void 0 ? void 0 : option.value) == CREATE)
67
+ if ((option === null || option === void 0 ? void 0 : option.value) === CREATE)
68
68
  return true;
69
69
  return defaultFilterOption(option, rawInput);
70
70
  };
@@ -88,7 +88,7 @@ var SingleSelect = function (props) {
88
88
  if (!loadOptions)
89
89
  return i18n._({ id: 'components.dropdown.noOptions', message: 'No options' });
90
90
  if (inputValue.length < asyncLoadMinChars)
91
- return i18n._({ id: 'components.dropdown.writeMoreChars', message: 'Write at least ${asyncLoadMinChars} characters.' });
91
+ return i18n._({ id: 'components.dropdown.writeMoreChars', message: "Write at least ".concat(asyncLoadMinChars, " characters.") });
92
92
  return i18n._({ id: 'dataGrid.filterCell', message: 'Type to filter' });
93
93
  }, [loadOptions, asyncLoadMinChars]);
94
94
  var handleLoadOptions = useCallback(function (inputValue) { return __awaiter(void 0, void 0, void 0, function () {
@@ -119,19 +119,21 @@ var SingleSelect = function (props) {
119
119
  var _f = useState(options || []), loadedDefaultOptions = _f[0], setLoadedDefaultOptions = _f[1];
120
120
  useEffect(function () {
121
121
  if (loadOptions && preload && !props.value)
122
- loadOptions('', false).then(setLoadedDefaultOptions);
122
+ loadOptions('', false).then(setLoadedDefaultOptions).catch(console.error);
123
123
  // eslint-disable-next-line react-hooks/exhaustive-deps
124
124
  }, [loadOptions]); // this is intentional
125
125
  var _g = useState(null), storedSelectedOption = _g[0], setStoredSelectedOption = _g[1];
126
126
  useEffect(function () {
127
- if (initialOptions && initialOptions.length) {
128
- var selectedOption = initialOptions.find(function (option) { return option.value == props.value; }) || null;
127
+ if (initialOptions === null || initialOptions === void 0 ? void 0 : initialOptions.length) {
128
+ var selectedOption = initialOptions.find(function (option) { return option.value === props.value; }) || null;
129
129
  setStoredSelectedOption(selectedOption);
130
130
  }
131
131
  if (loadOptions && !initialOptions && props.value) {
132
- loadOptions(String(props.value), true).then(function (selectedOptions) {
132
+ loadOptions(String(props.value), true)
133
+ .then(function (selectedOptions) {
133
134
  setStoredSelectedOption((selectedOptions === null || selectedOptions === void 0 ? void 0 : selectedOptions[0]) || null);
134
- });
135
+ })
136
+ .catch(console.error);
135
137
  }
136
138
  // ignored because of props.value, this only finds option for initial value
137
139
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -147,7 +149,7 @@ var SingleSelect = function (props) {
147
149
  return __generator(this, function (_e) {
148
150
  switch (_e.label) {
149
151
  case 0:
150
- if (!(onCreateOption && (option === null || option === void 0 ? void 0 : option.value) == CREATE)) return [3 /*break*/, 4];
152
+ if (!(onCreateOption && (option === null || option === void 0 ? void 0 : option.value) === CREATE)) return [3 /*break*/, 4];
151
153
  if (!((option === null || option === void 0 ? void 0 : option.inputValue) && ((_b = (_a = option === null || option === void 0 ? void 0 : option.inputValue) === null || _a === void 0 ? void 0 : _a.trim()) === null || _b === void 0 ? void 0 : _b.length) < 2)) return [3 /*break*/, 1];
152
154
  props === null || props === void 0 ? void 0 : props.form.setFieldTouched(name, true, true);
153
155
  props === null || props === void 0 ? void 0 : props.form.setFieldError(name, i18n._({ id: 'form.general.min2Chars', message: 'Minimal length is 2 characters.' }));
@@ -182,17 +184,6 @@ var SingleSelect = function (props) {
182
184
  }
183
185
  });
184
186
  }); }, [onCreateOption, loadOptions, onChange, onValueChange, props === null || props === void 0 ? void 0 : props.form, name]);
185
- var handleBlur = useCallback(function (option) {
186
- if (onBlur) {
187
- onBlur({
188
- target: {
189
- name: name,
190
- type: 'blur',
191
- value: getOptionValue(option)
192
- }
193
- });
194
- }
195
- }, [name, onBlur]);
196
187
  var omitted = ['onValueChange', 'placeholder', 'options', 'loadOptions', 'asyncLoadMinChars'];
197
188
  var displayLockedText = isLocked && !disabled;
198
189
  var placeholderValue = displayLockedText ? lockedText : placeholder;
@@ -204,6 +195,6 @@ var SingleSelect = function (props) {
204
195
  return staticOptions || undefined;
205
196
  return staticOptions ? __spreadArray(__spreadArray([], staticOptions, true), [storedSelectedOption], false) : [storedSelectedOption];
206
197
  }, [asAsync, loadedDefaultOptions, onCreateOption, options, storedSelectedOption]);
207
- return (_jsx(Select, __assign({}, omit(omitted, props), { filterOption: (filterOption || creatableFilterOption), disabled: disabled || isLocked, onChange: handleChange, onBlur: handleBlur, placeholder: placeholderValue, loadingMessage: loadingMessage, noOptionsMessage: noOptionsMessage, loadOptions: asAsync ? handleLoadOptions : undefined, containerVariant: asAsync ? 'search' : undefined, defaultOptions: defaultOptions, options: !asAsync ? options : undefined, isLoading: isCreating || props.isLoading })));
198
+ return (_jsx(Select, __assign({}, omit(omitted, props), { filterOption: (filterOption || creatableFilterOption), disabled: disabled || isLocked, onChange: handleChange, onBlur: onBlur, placeholder: placeholderValue, loadingMessage: loadingMessage, noOptionsMessage: noOptionsMessage, loadOptions: asAsync ? handleLoadOptions : undefined, containerVariant: asAsync ? 'search' : undefined, defaultOptions: defaultOptions, options: !asAsync ? options : undefined, isLoading: isCreating || props.isLoading })));
208
199
  };
209
200
  export default SingleSelect;