@commercetools-uikit/selectable-search-input 16.0.0 → 16.1.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.
@@ -51,106 +51,79 @@ var Constraints__default = /*#__PURE__*/_interopDefault(Constraints);
51
51
  var Select__default = /*#__PURE__*/_interopDefault(Select);
52
52
 
53
53
  function ownKeys$2(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
54
-
55
54
  function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$2(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$2(Object(source))).call(_context2, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
56
-
57
55
  const getInputContainerBorderColor = function (props) {
58
56
  let defaultColor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : designSystem.designTokens.borderColorForInput;
59
-
60
57
  if (props.isDisabled) {
61
58
  return designSystem.designTokens.borderColorForInputWhenDisabled;
62
59
  }
63
-
64
60
  if (props.isReadOnly) {
65
61
  return designSystem.designTokens.borderColorForInputWhenReadonly;
66
62
  }
67
-
68
63
  if (props.hasError) {
69
64
  return designSystem.designTokens.borderColorForInputWhenError;
70
65
  }
71
-
72
66
  if (props.hasWarning) {
73
67
  return designSystem.designTokens.borderColorForInputWhenWarning;
74
68
  }
75
-
76
69
  return defaultColor;
77
70
  };
78
-
79
71
  const getInputFontColor = props => {
80
72
  if (props.isDisabled) {
81
73
  return designSystem.designTokens.fontColorForInputWhenDisabled;
82
74
  }
83
-
84
75
  if (props.isReadOnly) {
85
76
  return designSystem.designTokens.fontColorForInputWhenReadonly;
86
77
  }
87
-
88
78
  if (props.hasError) {
89
79
  return designSystem.designTokens.fontColorForInputWhenError;
90
80
  }
91
-
92
81
  if (props.hasWarning) {
93
82
  return designSystem.designTokens.fontColorForInputWhenWarning;
94
83
  }
95
-
96
84
  return designSystem.designTokens.fontColorForInput;
97
85
  };
98
-
99
86
  const getInputBoxShadow = props => {
100
87
  if (props.hasError) {
101
88
  return designSystem.designTokens.shadowForInputWhenError;
102
89
  }
103
-
104
90
  if (props.hasWarning) {
105
91
  return designSystem.designTokens.shadowForInputWhenWarning;
106
92
  }
107
-
108
93
  return designSystem.designTokens.shadowForInput;
109
94
  };
110
-
111
95
  const getSelectableSearchInputStyles = props => [inputUtils.getInputStyles(props), /*#__PURE__*/react.css("border:none;box-shadow:none;background:none;&,&:focus,&:focus:not(:read-only){box-shadow:none;}&:focus,&:hover{background-color:transparent!important;}width:100%;color:", getInputFontColor(props), ";" + ("" ), "" )];
112
-
113
96
  const getButtonStyles = () => /*#__PURE__*/react.css("border:none;background:none;height:100%;border-top-right-radius:", designSystem.designTokens.borderRadiusForInput, ";border-bottom-right-radius:", designSystem.designTokens.borderRadiusForInput, ";border-left:none;align-items:center;transition:border-color ", designSystem.designTokens.transitionStandard, ",background-color ", designSystem.designTokens.transitionStandard, ";transition:border-color ", designSystem.designTokens.transitionStandard, ",box-shadow ", designSystem.designTokens.transitionStandard, ";margin-right:", designSystem.designTokens.marginRightForClearInputIcon, ";" + ("" ), "" );
114
-
115
97
  const getIconColor = (props, defaultColor) => {
116
98
  if (props.isDisabled) {
117
99
  return designSystem.designTokens.fontColorForInputWhenDisabled;
118
100
  }
119
-
120
101
  if (props.isReadOnly) {
121
102
  return designSystem.designTokens.fontColorForSearchInputIconWhenReadonly;
122
103
  }
123
-
124
104
  return defaultColor;
125
105
  };
126
-
127
106
  const getClearIconButtonStyles = props => [getButtonStyles(), /*#__PURE__*/react.css("fill:", getIconColor(props, designSystem.designTokens.fontColorForClearInputIcon), ";&:hover{fill:", getIconColor(props, designSystem.designTokens.fontColorForClearInputIconWhenHovered), ";}" + ("" ), "" )];
128
-
129
107
  const getSearchIconButtonStyles = props => [getButtonStyles(), /*#__PURE__*/react.css("margin-right:", designSystem.designTokens.marginRightForSearchInputIcon, ";fill:", getIconColor(props, designSystem.designTokens.fontColorForSearchInputIcon), ";cursor:", props.isReadOnly ? 'default' : 'pointer', ";&:hover{fill:", getIconColor(props, designSystem.designTokens.fontColorForSearchInputIconWhenHovered), ";}" + ("" ), "" )];
130
-
131
108
  const getBackgroundColor = (props, defaultColor) => {
132
109
  if (props.isDisabled) {
133
110
  return designSystem.designTokens.backgroundColorForInputWhenDisabled;
134
111
  }
135
-
136
112
  if (props.isReadOnly) {
137
113
  return designSystem.designTokens.backgroundColorForInputWhenReadonly;
138
114
  }
139
-
140
115
  return defaultColor;
141
116
  };
142
-
143
117
  const getSelectableSearchInputContainerStyles = props => [/*#__PURE__*/react.css("display:flex;align-items:center;background-color:", getBackgroundColor(props, designSystem.designTokens.backgroundColorForInput), ";border:1px solid ", getInputContainerBorderColor(props), ";border-radius:", designSystem.designTokens.borderRadiusForInput, ";box-shadow:", getInputBoxShadow(props), ";height:", designSystem.designTokens.heightForInput, ";box-sizing:border-box;border-top-left-radius:0;border-bottom-left-radius:0;margin-left:0;width:100%;transition:border-color ", designSystem.designTokens.transitionStandard, ",background-color ", designSystem.designTokens.transitionStandard, ";&::placeholder{color:", designSystem.designTokens.placeholderFontColorForInput, ";}&:hover{border-color:", getInputContainerBorderColor(props, designSystem.designTokens.borderColorForInputWhenHovered), ";background-color:", getBackgroundColor(props, designSystem.designTokens.backgroundColorForInputWhenHovered), ";}&:focus{border-color:", designSystem.designTokens.borderColorForInputWhenFocused, ";}" + ("" ), "" ), !props.isDisabled && !props.isReadOnly && /*#__PURE__*/react.css("&:focus-within{border-color:", designSystem.designTokens.borderColorForInputWhenFocused, ";box-shadow:", designSystem.designTokens.boxShadowForDatetimeInputWhenHovered, " ", designSystem.designTokens.borderColorForInputWhenFocused, ";}" + ("" ), "" )];
144
-
145
118
  const createSelectableSelectStyles = _ref => {
146
119
  let hasWarning = _ref.hasWarning,
147
- hasError = _ref.hasError,
148
- isDisabled = _ref.isDisabled,
149
- isReadOnly = _ref.isReadOnly,
150
- menuPortalZIndex = _ref.menuPortalZIndex,
151
- isNewTheme = _ref.isNewTheme,
152
- dropdownHasFocus = _ref.dropdownHasFocus,
153
- textInputHasFocus = _ref.textInputHasFocus;
120
+ hasError = _ref.hasError,
121
+ isDisabled = _ref.isDisabled,
122
+ isReadOnly = _ref.isReadOnly,
123
+ menuPortalZIndex = _ref.menuPortalZIndex,
124
+ isNewTheme = _ref.isNewTheme,
125
+ dropdownHasFocus = _ref.dropdownHasFocus,
126
+ textInputHasFocus = _ref.textInputHasFocus;
154
127
  const selectStyles = selectUtils.createSelectStyles({
155
128
  hasWarning,
156
129
  hasError,
@@ -171,15 +144,12 @@ const createSelectableSelectStyles = _ref => {
171
144
  if (isReadOnly) return "".concat(designSystem.designTokens.borderColorForInputWhenReadonly, " !important");
172
145
  if (hasError) return designSystem.designTokens.borderColorForInputWhenError;
173
146
  if (hasWarning) return designSystem.designTokens.borderColorForInputWhenWarning;
174
-
175
147
  if (textInputHasFocus && !isNewTheme) {
176
148
  return designSystem.designTokens.borderColorForInputWhenFocused;
177
149
  }
178
-
179
150
  if (dropdownHasFocus) {
180
151
  return designSystem.designTokens.borderColorForInputWhenFocused;
181
152
  }
182
-
183
153
  return designSystem.designTokens.borderColorForInput;
184
154
  })(),
185
155
  cursor: (() => {
@@ -215,15 +185,11 @@ const createSelectableSelectStyles = _ref => {
215
185
  };
216
186
 
217
187
  const _excluded = ["id"];
218
-
219
188
  function ownKeys$1(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
220
-
221
189
  function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$1(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$1(Object(source))).call(_context2, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
222
-
223
190
  const SingleValue = _ref => {
224
191
  let id = _ref.id,
225
- props = _objectWithoutProperties(_ref, _excluded);
226
-
192
+ props = _objectWithoutProperties(_ref, _excluded);
227
193
  return jsxRuntime.jsx(Select.components.SingleValue, _objectSpread$1(_objectSpread$1({}, props), {}, {
228
194
  children: jsxRuntime.jsx("label", {
229
195
  htmlFor: id,
@@ -231,15 +197,11 @@ const SingleValue = _ref => {
231
197
  })
232
198
  }));
233
199
  };
234
-
235
200
  SingleValue.propTypes = {};
236
-
237
201
  const SelectableSelect = props => {
238
202
  const intl = reactIntl.useIntl();
239
-
240
203
  const _useTheme = designSystem.useTheme(),
241
- isNewTheme = _useTheme.isNewTheme;
242
-
204
+ isNewTheme = _useTheme.isNewTheme;
243
205
  const dropdownStyles = createSelectableSelectStyles({
244
206
  hasWarning: props.hasWarning,
245
207
  hasError: props.hasError,
@@ -251,12 +213,11 @@ const SelectableSelect = props => {
251
213
  textInputHasFocus: props.textInputHasFocus
252
214
  });
253
215
  const onChange = props.onChange,
254
- name = props.name,
255
- id = props.id,
256
- textInputRef = props.textInputRef;
216
+ name = props.name,
217
+ id = props.id,
218
+ textInputRef = props.textInputRef;
257
219
  const handleDropdownChange = react$1.useCallback(nextSelectedOptions => {
258
220
  var _textInputRef$current;
259
-
260
221
  if (onChange) {
261
222
  onChange({
262
223
  target: {
@@ -266,7 +227,6 @@ const SelectableSelect = props => {
266
227
  }
267
228
  });
268
229
  }
269
-
270
230
  (_textInputRef$current = textInputRef.current) === null || _textInputRef$current === void 0 ? void 0 : _textInputRef$current.focus();
271
231
  }, [onChange, id, name, textInputRef]);
272
232
  return jsxRuntime.jsx(Select__default["default"], {
@@ -301,25 +261,19 @@ const SelectableSelect = props => {
301
261
  })
302
262
  });
303
263
  };
304
-
305
264
  SelectableSelect.propTypes = {};
306
265
  var SelectableSelect$1 = SelectableSelect;
307
266
 
308
267
  function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
309
-
310
268
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context3, _context4; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context3 = ownKeys(Object(source), !0)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
311
-
312
269
  const Container = /*#__PURE__*/_styled__default["default"]("div", {
313
270
  target: "encv1cf0"
314
271
  } )({
315
272
  name: "zjik7",
316
273
  styles: "display:flex"
317
274
  } );
318
-
319
275
  const getTextInputName = name => name ? "".concat(name, ".textInput") : undefined;
320
-
321
276
  const getDropdownName = name => name ? "".concat(name, ".dropdown") : undefined;
322
-
323
277
  const defaultProps = {
324
278
  horizontalConstraint: 'scale',
325
279
  isClearable: true,
@@ -329,55 +283,42 @@ const defaultProps = {
329
283
  options: []
330
284
  };
331
285
  const selectableSearchInputSequentialId = utils.createSequentialId('selectable-search-input-');
332
-
333
286
  const isOptionObject = option => option.options !== undefined;
334
-
335
287
  const SelectableSearchInput = props => {
336
288
  var _context;
337
-
338
289
  const _useToggleState = hooks.useToggleState(false),
339
- _useToggleState2 = _slicedToArray(_useToggleState, 2),
340
- textInputHasFocus = _useToggleState2[0],
341
- toggleTextInputHasFocus = _useToggleState2[1];
342
-
290
+ _useToggleState2 = _slicedToArray(_useToggleState, 2),
291
+ textInputHasFocus = _useToggleState2[0],
292
+ toggleTextInputHasFocus = _useToggleState2[1];
343
293
  const _useToggleState3 = hooks.useToggleState(false),
344
- _useToggleState4 = _slicedToArray(_useToggleState3, 2),
345
- dropdownHasFocus = _useToggleState4[0],
346
- toggleDropdownHasFocus = _useToggleState4[1];
347
-
294
+ _useToggleState4 = _slicedToArray(_useToggleState3, 2),
295
+ dropdownHasFocus = _useToggleState4[0],
296
+ toggleDropdownHasFocus = _useToggleState4[1];
348
297
  const _useState = react$1.useState(props.value.text || ''),
349
- _useState2 = _slicedToArray(_useState, 2),
350
- searchValue = _useState2[0],
351
- setSearchValue = _useState2[1];
352
-
298
+ _useState2 = _slicedToArray(_useState, 2),
299
+ searchValue = _useState2[0],
300
+ setSearchValue = _useState2[1];
353
301
  const containerRef = react$1.useRef(null);
354
302
  const textInputRef = react$1.useRef(null);
355
-
356
303
  const _useTheme = designSystem.useTheme(),
357
- isNewTheme = _useTheme.isNewTheme;
358
-
304
+ isNewTheme = _useTheme.isNewTheme;
359
305
  const optionsWithoutGroups = _flatMapInstanceProperty__default["default"](_context = props.options).call(_context, option => {
360
306
  if (isOptionObject(option)) {
361
307
  return option.options;
362
308
  }
363
-
364
309
  return option;
365
310
  });
366
-
367
311
  const selectedOption = _findInstanceProperty__default["default"](optionsWithoutGroups).call(optionsWithoutGroups, option => option.value === props.value.option);
368
-
369
312
  const selectablSearchInputId = hooks.useFieldId(props.id, selectableSearchInputSequentialId);
370
-
371
313
  if (!props.isReadOnly) ;
372
-
373
314
  selectUtils.warnIfMenuPortalPropsAreMissing({
374
315
  menuPortalZIndex: props.menuPortalZIndex,
375
316
  menuPortalTarget: props.menuPortalTarget,
376
317
  componentName: 'SelectableSearchInput'
377
318
  });
378
319
  const onFocus = props.onFocus,
379
- onBlur = props.onBlur,
380
- name = props.name;
320
+ onBlur = props.onBlur,
321
+ name = props.name;
381
322
  const handleTextInputFocus = react$1.useCallback(() => {
382
323
  if (onFocus) {
383
324
  onFocus({
@@ -387,7 +328,6 @@ const SelectableSearchInput = props => {
387
328
  }
388
329
  });
389
330
  }
390
-
391
331
  toggleTextInputHasFocus(true);
392
332
  }, [toggleTextInputHasFocus, onFocus, selectablSearchInputId, name]);
393
333
  const handleTextInputBlur = react$1.useCallback(() => {
@@ -399,21 +339,16 @@ const SelectableSearchInput = props => {
399
339
  }
400
340
  });
401
341
  }
402
-
403
342
  toggleTextInputHasFocus(false);
404
343
  }, [toggleTextInputHasFocus, onBlur, selectablSearchInputId, name]);
405
-
406
344
  const handleClear = () => {
407
345
  setSearchValue('');
408
-
409
346
  if (props.onReset) {
410
347
  props.onReset();
411
348
  }
412
349
  };
413
-
414
350
  const handleChange = event => {
415
351
  setSearchValue(event.target.value);
416
-
417
352
  if (props.onChange) {
418
353
  props.onChange({
419
354
  target: {
@@ -424,20 +359,16 @@ const SelectableSearchInput = props => {
424
359
  });
425
360
  }
426
361
  };
427
-
428
362
  const handleSubmit = event => {
429
363
  event.preventDefault();
430
-
431
364
  if (props.onSubmit) {
432
365
  var _selectedOption$value;
433
-
434
366
  props.onSubmit({
435
367
  text: searchValue,
436
368
  option: (_selectedOption$value = selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.value) !== null && _selectedOption$value !== void 0 ? _selectedOption$value : ''
437
369
  });
438
370
  }
439
371
  };
440
-
441
372
  const dropdownName = getDropdownName(props.name);
442
373
  const dropdownId = SelectableSearchInput.getDropdownId(selectablSearchInputId);
443
374
  const handleDropdownFocus = react$1.useCallback(() => {
@@ -449,7 +380,6 @@ const SelectableSearchInput = props => {
449
380
  }
450
381
  });
451
382
  }
452
-
453
383
  toggleDropdownHasFocus(true);
454
384
  }, [onFocus, toggleDropdownHasFocus, dropdownName, dropdownId]);
455
385
  const handleDropdownBlur = react$1.useCallback(() => {
@@ -461,12 +391,10 @@ const SelectableSearchInput = props => {
461
391
  }
462
392
  });
463
393
  }
464
-
465
394
  toggleDropdownHasFocus(false);
466
395
  }, [toggleDropdownHasFocus, onBlur, dropdownName, dropdownId]);
467
396
  const handleContainerBlur = react$1.useCallback(event => {
468
397
  var _containerRef$current;
469
-
470
398
  // ensures that both fields are marked as touched when one of them
471
399
  // is blurred
472
400
  if (typeof onBlur === 'function' && !((_containerRef$current = containerRef.current) !== null && _containerRef$current !== void 0 && _containerRef$current.contains(event.relatedTarget))) {
@@ -549,23 +477,19 @@ const SelectableSearchInput = props => {
549
477
  })
550
478
  });
551
479
  };
552
-
553
480
  SelectableSearchInput.propTypes = {};
554
481
  SelectableSearchInput.displayName = 'SelectableSearchInput';
555
482
  SelectableSearchInput.defaultProps = defaultProps;
556
-
557
483
  SelectableSearchInput.isEmpty = formValue => {
558
484
  var _context2;
559
-
560
485
  return !formValue || _trimInstanceProperty__default["default"](_context2 = formValue.text).call(_context2) === '';
561
486
  };
562
-
563
487
  SelectableSearchInput.getTextInputId = getTextInputName;
564
488
  SelectableSearchInput.getDropdownId = getDropdownName;
565
489
  var SelectableSearchInput$1 = SelectableSearchInput;
566
490
 
567
491
  // NOTE: This string will be replaced on build time with the package version.
568
- var version = "16.0.0";
492
+ var version = "16.1.0";
569
493
 
570
494
  exports["default"] = SelectableSearchInput$1;
571
495
  exports.version = version;