zds-pickers 3.11.0 → 3.11.1

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.
@@ -1,14 +1,18 @@
1
- import _extends from "@babel/runtime/helpers/extends";import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";var _excluded = ["channels", "className"];import React, { forwardRef, useCallback } from 'react';
1
+ import _extends from "@babel/runtime/helpers/extends";import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";var _excluded = ["channels", "className"];import React, { forwardRef, useCallback, useMemo } from 'react';
2
2
  import cl from 'classnames';
3
3
  import PropTypes from 'prop-types';
4
4
  import { arraySequence } from '../utils';
5
5
  import Select from './Select';
6
6
 
7
- var options = arraySequence(16).map(function (value) {return { value: value, label: value };});
7
+ var defaultOptions = arraySequence(16).map(function (value) {return { value: value, label: value };});
8
8
 
9
9
  var ChannelMappingPicker = /*#__PURE__*/forwardRef(function (_ref, ref) {var channels = _ref.channels,className = _ref.className,rest = _objectWithoutProperties(_ref, _excluded);
10
10
  var formatOptionLabel = useCallback(
11
- function (_ref2, _ref3) {var value = _ref2.value;var context = _ref3.context;
11
+ function (_ref2, _ref3) {var value = _ref2.value,label = _ref2.label;var context = _ref3.context;
12
+ if (value === 'separator') {
13
+ return /*#__PURE__*/React.createElement("span", { className: "zds-mappings-user-mapping" }, label);
14
+ }
15
+
12
16
  var mapping = channels[value];
13
17
 
14
18
  return mapping ? /*#__PURE__*/
@@ -32,6 +36,29 @@ var ChannelMappingPicker = /*#__PURE__*/forwardRef(function (_ref, ref) {var cha
32
36
  [channels]
33
37
  );
34
38
 
39
+ var options = useMemo(function () {
40
+ var result = defaultOptions.sort(function (a, b) {
41
+ if (channels[a.value] && !channels[b.value]) {
42
+ return -1;
43
+ }
44
+
45
+ if (!channels[a.value] && channels[b.value]) {
46
+ return 1;
47
+ }
48
+
49
+ return a.value - b.value;
50
+ });
51
+
52
+ var numFilled = result.filter(function (_ref4) {var value = _ref4.value;return !!channels[value];}).length;
53
+
54
+ if (numFilled && numFilled < 16) {
55
+ // insert a separator after the count of filled items
56
+ result.splice(numFilled, 0, { label: /*#__PURE__*/React.createElement("hr", null), value: 'separator' });
57
+ }
58
+
59
+ return result;
60
+ }, [channels]);
61
+
35
62
  return /*#__PURE__*/(
36
63
  React.createElement(Select, _extends({},
37
64
  rest, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zds-pickers",
3
- "version": "3.11.0",
3
+ "version": "3.11.1",
4
4
  "homepage": "https://github.com/dkadrios/zds-pickers#readme",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",