oa-componentbook 0.18.374 → 0.18.375

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.
@@ -22,7 +22,7 @@ var _Typography = _interopRequireDefault(require("../oa-component-typography/Typ
22
22
  var _ColorVariablesMap = _interopRequireDefault(require("../../global-css/ColorVariablesMap"));
23
23
  require("antd/dist/reset.css");
24
24
  var _Elevation = require("../../global-css/Elevation");
25
- const _excluded = ["allText", "children", "defaultValue", "data-test", "mode", "onSelectionChange", "options", "placeholder", "maxSelectForMultiSelect", "onCustomSelect"],
25
+ const _excluded = ["allText", "children", "defaultValue", "data-test", "mode", "onSelectionChange", "options", "placeholder", "maxSelectForMultiSelect", "onCustomSelect", "fixedValue"],
26
26
  _excluded2 = ["label", "disabled", "value"];
27
27
  var _templateObject;
28
28
  /* eslint-disable */
@@ -82,7 +82,8 @@ function CustomSelect(_ref) {
82
82
  options,
83
83
  placeholder,
84
84
  maxSelectForMultiSelect,
85
- onCustomSelect
85
+ onCustomSelect,
86
+ fixedValue
86
87
  } = _ref,
87
88
  props = _objectWithoutProperties(_ref, _excluded);
88
89
  // If allText is present in default values, we select all the options manually.
@@ -195,6 +196,11 @@ function CustomSelect(_ref) {
195
196
  array.push(element);
196
197
  }
197
198
  };
199
+ const safeUnshift = (array, element) => {
200
+ if (!array.includes(element)) {
201
+ array.unshift(element);
202
+ }
203
+ };
198
204
 
199
205
  /**
200
206
  * Given an array of options, add all non-disabled options to the newlySelectedOptions array.
@@ -285,6 +291,12 @@ function CustomSelect(_ref) {
285
291
  var _newlySelectedOptions2;
286
292
  newlySelectedOptions.splice((_newlySelectedOptions2 = newlySelectedOptions.indexOf) === null || _newlySelectedOptions2 === void 0 ? void 0 : _newlySelectedOptions2.call(newlySelectedOptions, value), 1);
287
293
  }
294
+
295
+ // If fixedValue has values, push them to the beginning of newlySelectedOptions
296
+ // BUT only if "All" is not currently selected
297
+ if ((fixedValue === null || fixedValue === void 0 ? void 0 : fixedValue.length) > 0 && !(newlySelectedOptions !== null && newlySelectedOptions !== void 0 && newlySelectedOptions.includes(allText))) {
298
+ fixedValue.forEach(val => safeUnshift(newlySelectedOptions, val));
299
+ }
288
300
  const optionsWithoutAllText = newlySelectedOptions.filter(option => option !== allText);
289
301
 
290
302
  // Passing the data to parent, using a callback.
@@ -416,7 +428,8 @@ CustomSelect.propTypes = {
416
428
  })),
417
429
  size: _propTypes.default.oneOf(["small", "middle"]),
418
430
  placeholder: _propTypes.default.string,
419
- maxSelectForMultiSelect: _propTypes.default.number
431
+ maxSelectForMultiSelect: _propTypes.default.number,
432
+ fixedValue: _propTypes.default.arrayOf(_propTypes.default.string)
420
433
  };
421
434
  CustomSelect.defaultProps = {
422
435
  allText: null,
@@ -428,5 +441,6 @@ CustomSelect.defaultProps = {
428
441
  options: [],
429
442
  size: "middle",
430
443
  placeholder: "",
431
- maxSelectForMultiSelect: null
444
+ maxSelectForMultiSelect: null,
445
+ fixedValue: []
432
446
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oa-componentbook",
3
- "version": "0.18.374",
3
+ "version": "0.18.375",
4
4
  "private": false,
5
5
  "description": "Reusable components",
6
6
  "main": "build/index.js",