oa-componentbook 0.17.91 → 0.17.92
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.
|
@@ -2,23 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
require("core-js/modules/es.symbol.description.js");
|
|
4
4
|
require("core-js/modules/es.object.assign.js");
|
|
5
|
+
require("core-js/modules/es.weak-map.js");
|
|
5
6
|
Object.defineProperty(exports, "__esModule", {
|
|
6
7
|
value: true
|
|
7
8
|
});
|
|
8
9
|
exports.default = CustomSelect;
|
|
9
|
-
|
|
10
|
+
require("core-js/modules/web.dom-collections.iterator.js");
|
|
11
|
+
require("core-js/modules/es.array.includes.js");
|
|
12
|
+
require("core-js/modules/es.string.includes.js");
|
|
13
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
10
14
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
15
|
var _antd = require("antd");
|
|
12
16
|
var _KeyboardArrowDown = _interopRequireDefault(require("@material-ui/icons/KeyboardArrowDown"));
|
|
17
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
13
18
|
var _utils = require("../../utils");
|
|
14
19
|
var _MaterialIcon = _interopRequireDefault(require("../oa-component-icons/MaterialIcon"));
|
|
15
20
|
var _Typography = _interopRequireDefault(require("../oa-component-typography/Typography"));
|
|
16
21
|
var _ColorVariablesMap = _interopRequireDefault(require("../../global-css/ColorVariablesMap"));
|
|
17
22
|
require("antd/dist/reset.css");
|
|
18
23
|
var _Elevation = require("../../global-css/Elevation");
|
|
19
|
-
const _excluded = ["data-test", "options"],
|
|
20
|
-
_excluded2 = ["label", "disabled"];
|
|
24
|
+
const _excluded = ["allText", "children", "data-test", "onSelectionChange", "options"],
|
|
25
|
+
_excluded2 = ["label", "disabled", "value"];
|
|
26
|
+
var _templateObject;
|
|
21
27
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
28
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
29
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
22
30
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
23
31
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
24
32
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
@@ -27,16 +35,25 @@ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typ
|
|
|
27
35
|
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
28
36
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
29
37
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
38
|
+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
39
|
+
const {
|
|
40
|
+
Option
|
|
41
|
+
} = _antd.Select;
|
|
42
|
+
const StyledSelect = (0, _styledComponents.default)(_antd.Select)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n /* Hiding the last tag in case of All being selected. */\n .ant-select-selection-overflow-item.ant-select-selection-overflow-item-rest {\n display: ", "\n }\n"])), props => props.maxTagCount === 1 ? 'none' : undefined);
|
|
30
43
|
function CustomSelect(_ref) {
|
|
31
44
|
let {
|
|
45
|
+
allText,
|
|
46
|
+
children,
|
|
32
47
|
'data-test': dataTest,
|
|
48
|
+
onSelectionChange,
|
|
33
49
|
options
|
|
34
50
|
} = _ref,
|
|
35
51
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
36
52
|
const actualOptions = options === null || options === void 0 ? void 0 : options.map(option => {
|
|
37
53
|
const {
|
|
38
54
|
label,
|
|
39
|
-
disabled
|
|
55
|
+
disabled = false,
|
|
56
|
+
value
|
|
40
57
|
} = option,
|
|
41
58
|
otherProperties = _objectWithoutProperties(option, _excluded2);
|
|
42
59
|
if ((0, _utils.isString)(label) || (0, _utils.isNumber)(label)) {
|
|
@@ -46,19 +63,83 @@ function CustomSelect(_ref) {
|
|
|
46
63
|
typography: "type-b2-400",
|
|
47
64
|
"data-test": dataTest ? "".concat(dataTest, "-(").concat(label, ")") : undefined
|
|
48
65
|
}, label),
|
|
49
|
-
disabled
|
|
66
|
+
disabled,
|
|
67
|
+
value
|
|
50
68
|
}, otherProperties);
|
|
51
69
|
}
|
|
52
70
|
if ( /*#__PURE__*/_react.default.isValidElement(label)) {
|
|
53
71
|
return _objectSpread({
|
|
54
|
-
label: /*#__PURE__*/_react.default.cloneElement(label, {
|
|
55
|
-
'data-test':
|
|
56
|
-
}),
|
|
72
|
+
label: dataTest ? /*#__PURE__*/_react.default.cloneElement(label, {
|
|
73
|
+
'data-test': "".concat(dataTest, "-(").concat(label, ")")
|
|
74
|
+
}) : label,
|
|
75
|
+
disabled,
|
|
76
|
+
value
|
|
77
|
+
}, otherProperties);
|
|
78
|
+
}
|
|
79
|
+
if ((0, _utils.isString)(value) || (0, _utils.isNumber)(value)) {
|
|
80
|
+
return _objectSpread({
|
|
81
|
+
label: /*#__PURE__*/_react.default.createElement(_Typography.default, {
|
|
82
|
+
color: disabled ? 'placeholder-text' : undefined,
|
|
83
|
+
typography: "type-b2-400",
|
|
84
|
+
"data-test": dataTest ? "".concat(dataTest, "-(").concat(value, ")") : undefined
|
|
85
|
+
}, value),
|
|
86
|
+
value,
|
|
57
87
|
disabled
|
|
58
88
|
}, otherProperties);
|
|
59
89
|
}
|
|
60
90
|
return option;
|
|
61
91
|
});
|
|
92
|
+
const [selectedOptions, setSelectedOptions] = (0, _react.useState)([]);
|
|
93
|
+
const getMaxTagPlaceholder = omittedValues => {
|
|
94
|
+
if (selectedOptions.indexOf(allText) !== -1) {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
return "".concat("+".concat(omittedValues.length, " more"));
|
|
98
|
+
};
|
|
99
|
+
const safePush = (array, element) => {
|
|
100
|
+
if (!array.includes(element)) {
|
|
101
|
+
array.push(element);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
const addAllOptions = (optionsToBeAdded, newlySelectedOptions) => {
|
|
105
|
+
optionsToBeAdded.forEach(option => {
|
|
106
|
+
if ((option === null || option === void 0 ? void 0 : option.disabled) !== true) {
|
|
107
|
+
if (option.value) {
|
|
108
|
+
safePush(newlySelectedOptions, option.value);
|
|
109
|
+
} else {
|
|
110
|
+
safePush(newlySelectedOptions, option);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
const onOptionsChange = (select, value) => {
|
|
116
|
+
const newlySelectedOptions = selectedOptions.slice(0);
|
|
117
|
+
const allIndex = newlySelectedOptions.indexOf(allText);
|
|
118
|
+
if (allIndex !== -1) {
|
|
119
|
+
newlySelectedOptions.splice(allIndex, 1);
|
|
120
|
+
}
|
|
121
|
+
if (select) {
|
|
122
|
+
if (value === allText) {
|
|
123
|
+
newlySelectedOptions.length = 0; // Emptying the array.
|
|
124
|
+
|
|
125
|
+
safePush(newlySelectedOptions, allText);
|
|
126
|
+
addAllOptions(options, newlySelectedOptions);
|
|
127
|
+
} else {
|
|
128
|
+
safePush(newlySelectedOptions, value);
|
|
129
|
+
if (newlySelectedOptions.length === options.length && allText) {
|
|
130
|
+
newlySelectedOptions.unshift(allText);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
} else if (value === allText) {
|
|
134
|
+
newlySelectedOptions.length = 0; // Emptying the array.
|
|
135
|
+
} else {
|
|
136
|
+
newlySelectedOptions.splice(newlySelectedOptions.indexOf(value), 1);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Passing the data to parent, using a callback.
|
|
140
|
+
onSelectionChange(newlySelectedOptions);
|
|
141
|
+
setSelectedOptions(newlySelectedOptions);
|
|
142
|
+
};
|
|
62
143
|
return /*#__PURE__*/_react.default.createElement(_antd.ConfigProvider, {
|
|
63
144
|
theme: {
|
|
64
145
|
components: {
|
|
@@ -122,32 +203,51 @@ function CustomSelect(_ref) {
|
|
|
122
203
|
boxShadowSecondary: _Elevation.ElevationMap['elevation-white-1'] // Box shadow of dropdown.
|
|
123
204
|
}
|
|
124
205
|
}
|
|
125
|
-
}, /*#__PURE__*/_react.default.createElement(
|
|
206
|
+
}, /*#__PURE__*/_react.default.createElement(StyledSelect, _extends({
|
|
126
207
|
"data-test": dataTest,
|
|
127
|
-
options: (actualOptions === null || actualOptions === void 0 ? void 0 : actualOptions.length) > 0 ? actualOptions : undefined,
|
|
128
208
|
dropdownStyle: {
|
|
129
209
|
padding: '0px'
|
|
130
210
|
},
|
|
131
|
-
maxTagCount:
|
|
211
|
+
maxTagCount: selectedOptions.indexOf(allText) === -1 ? 'responsive' : 1,
|
|
212
|
+
maxTagPlaceholder: getMaxTagPlaceholder,
|
|
213
|
+
onDeselect: value => onOptionsChange(false, value),
|
|
214
|
+
onSelect: value => onOptionsChange(true, value),
|
|
132
215
|
suffixIcon: /*#__PURE__*/_react.default.createElement(_MaterialIcon.default, {
|
|
133
216
|
icon: _KeyboardArrowDown.default,
|
|
134
217
|
size: 20
|
|
135
|
-
})
|
|
136
|
-
|
|
218
|
+
}),
|
|
219
|
+
value: (options === null || options === void 0 ? void 0 : options.length) > 0 ? selectedOptions : [],
|
|
220
|
+
virtual: false
|
|
221
|
+
}, props), allText && /*#__PURE__*/_react.default.createElement(Option, {
|
|
222
|
+
value: allText
|
|
223
|
+
}, allText), actualOptions === null || actualOptions === void 0 ? void 0 : actualOptions.map(actualOption => {
|
|
224
|
+
var _actualOption$disable;
|
|
225
|
+
return /*#__PURE__*/_react.default.createElement(Option, {
|
|
226
|
+
disabled: (_actualOption$disable = actualOption.disabled) !== null && _actualOption$disable !== void 0 ? _actualOption$disable : false,
|
|
227
|
+
value: actualOption.value,
|
|
228
|
+
key: (0, _utils.getUUID)()
|
|
229
|
+
}, actualOption.label);
|
|
230
|
+
})));
|
|
137
231
|
}
|
|
138
232
|
CustomSelect.Option = _antd.Select.Option;
|
|
139
233
|
CustomSelect.propTypes = {
|
|
234
|
+
allText: _propTypes.default.string,
|
|
235
|
+
children: _propTypes.default.node,
|
|
140
236
|
'data-test': _propTypes.default.string,
|
|
141
|
-
|
|
237
|
+
onSelectionChange: _propTypes.default.func,
|
|
142
238
|
options: _propTypes.default.arrayOf(
|
|
143
239
|
// Checked from antd's github
|
|
144
240
|
_propTypes.default.shape({
|
|
145
241
|
label: _propTypes.default.node,
|
|
146
242
|
value: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]).isRequired
|
|
147
|
-
}))
|
|
243
|
+
})),
|
|
244
|
+
size: _propTypes.default.oneOf(['small', 'middle'])
|
|
148
245
|
};
|
|
149
246
|
CustomSelect.defaultProps = {
|
|
247
|
+
allText: null,
|
|
248
|
+
children: null,
|
|
150
249
|
'data-test': null,
|
|
250
|
+
onSelectionChange: selection => {},
|
|
151
251
|
options: [],
|
|
152
252
|
size: 'middle'
|
|
153
253
|
};
|