@pedidopago/ui 1.7.12 → 1.7.14

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.
Files changed (87) hide show
  1. package/dist/components/ComposeIcon/index.d.ts.map +1 -1
  2. package/dist/components/ComposeIcon/index.js +7 -1
  3. package/dist/components/ComposeIcon/styles.d.ts.map +1 -1
  4. package/dist/components/ComposeIcon/styles.js +13 -4
  5. package/dist/components/ComposeIcon/types.d.ts +2 -0
  6. package/dist/components/ComposeIcon/types.d.ts.map +1 -1
  7. package/dist/components/Icon/data/dash.js +1 -1
  8. package/dist/components/Icon/data/illustrations.d.ts.map +1 -1
  9. package/dist/components/Icon/data/illustrations.js +7 -0
  10. package/dist/components/Icon/types.d.ts +1 -1
  11. package/dist/components/Icon/types.d.ts.map +1 -1
  12. package/dist/components/Input/index.d.ts.map +1 -1
  13. package/dist/components/Input/index.js +5 -3
  14. package/dist/components/Input/styles.d.ts.map +1 -1
  15. package/dist/components/Input/styles.js +8 -4
  16. package/dist/components/NewSelect/Examples/index.d.ts.map +1 -1
  17. package/dist/components/NewSelect/Examples/index.js +4 -6
  18. package/dist/components/NewSelect/components/Chip/index.d.ts.map +1 -1
  19. package/dist/components/NewSelect/components/Chip/index.js +2 -2
  20. package/dist/components/NewSelect/components/OptionsSelect/styles.d.ts.map +1 -1
  21. package/dist/components/NewSelect/components/OptionsSelect/styles.js +1 -1
  22. package/dist/components/NewSelect/components/OptionsSelect/types.d.ts +0 -4
  23. package/dist/components/NewSelect/components/OptionsSelect/types.d.ts.map +1 -1
  24. package/dist/components/NewSelect/components/SelectInputSearch/index.js +1 -3
  25. package/dist/components/NewSelect/components/SelectItem/index.js +1 -1
  26. package/dist/components/NewSelect/components/SelectItem/styles.d.ts +2 -3
  27. package/dist/components/NewSelect/components/SelectItem/styles.d.ts.map +1 -1
  28. package/dist/components/NewSelect/components/SelectItem/styles.js +3 -3
  29. package/dist/components/NewSelect/components/SelectItem/types.d.ts +2 -5
  30. package/dist/components/NewSelect/components/SelectItem/types.d.ts.map +1 -1
  31. package/dist/components/NewSelect/index.d.ts +1 -4
  32. package/dist/components/NewSelect/index.d.ts.map +1 -1
  33. package/dist/components/NewSelect/index.js +11 -247
  34. package/dist/components/NewSelect/multiple/index.d.ts +4 -0
  35. package/dist/components/NewSelect/multiple/index.d.ts.map +1 -0
  36. package/dist/components/NewSelect/multiple/index.js +236 -0
  37. package/dist/components/NewSelect/single/index.d.ts +4 -0
  38. package/dist/components/NewSelect/single/index.d.ts.map +1 -0
  39. package/dist/components/NewSelect/single/index.js +174 -0
  40. package/dist/components/NewSelect/styles.d.ts +1 -1
  41. package/dist/components/NewSelect/styles.d.ts.map +1 -1
  42. package/dist/components/NewSelect/styles.js +3 -3
  43. package/dist/components/NewSelect/types.d.ts +14 -13
  44. package/dist/components/NewSelect/types.d.ts.map +1 -1
  45. package/package.json +1 -1
  46. package/dist/components/Illustration/AlternativeOrderSvg/index.d.ts +0 -5
  47. package/dist/components/Illustration/AlternativeOrderSvg/index.d.ts.map +0 -1
  48. package/dist/components/Illustration/AlternativeOrderSvg/index.js +0 -107
  49. package/dist/components/Illustration/BoletoSvg/index.d.ts +0 -5
  50. package/dist/components/Illustration/BoletoSvg/index.d.ts.map +0 -1
  51. package/dist/components/Illustration/BoletoSvg/index.js +0 -168
  52. package/dist/components/Illustration/BoxClosedSvg/index.d.ts +0 -5
  53. package/dist/components/Illustration/BoxClosedSvg/index.d.ts.map +0 -1
  54. package/dist/components/Illustration/BoxClosedSvg/index.js +0 -99
  55. package/dist/components/Illustration/BoxDeliverySvg/index.d.ts +0 -5
  56. package/dist/components/Illustration/BoxDeliverySvg/index.d.ts.map +0 -1
  57. package/dist/components/Illustration/BoxDeliverySvg/index.js +0 -111
  58. package/dist/components/Illustration/BoxOpenSvg/index.d.ts +0 -5
  59. package/dist/components/Illustration/BoxOpenSvg/index.d.ts.map +0 -1
  60. package/dist/components/Illustration/BoxOpenSvg/index.js +0 -108
  61. package/dist/components/Illustration/CalendarSvg/index.d.ts +0 -5
  62. package/dist/components/Illustration/CalendarSvg/index.d.ts.map +0 -1
  63. package/dist/components/Illustration/CalendarSvg/index.js +0 -109
  64. package/dist/components/Illustration/CardSvg/index.d.ts +0 -5
  65. package/dist/components/Illustration/CardSvg/index.d.ts.map +0 -1
  66. package/dist/components/Illustration/CardSvg/index.js +0 -110
  67. package/dist/components/Illustration/CollaboratorSvg/index.d.ts +0 -5
  68. package/dist/components/Illustration/CollaboratorSvg/index.d.ts.map +0 -1
  69. package/dist/components/Illustration/CollaboratorSvg/index.js +0 -99
  70. package/dist/components/Illustration/InquirySvg/index.d.ts +0 -5
  71. package/dist/components/Illustration/InquirySvg/index.d.ts.map +0 -1
  72. package/dist/components/Illustration/InquirySvg/index.js +0 -219
  73. package/dist/components/Illustration/OrderSvg/index.d.ts +0 -5
  74. package/dist/components/Illustration/OrderSvg/index.d.ts.map +0 -1
  75. package/dist/components/Illustration/OrderSvg/index.js +0 -135
  76. package/dist/components/Illustration/PixSvg/index.d.ts +0 -5
  77. package/dist/components/Illustration/PixSvg/index.d.ts.map +0 -1
  78. package/dist/components/Illustration/PixSvg/index.js +0 -93
  79. package/dist/components/Illustration/PrescriptionSvg/index.d.ts +0 -5
  80. package/dist/components/Illustration/PrescriptionSvg/index.d.ts.map +0 -1
  81. package/dist/components/Illustration/PrescriptionSvg/index.js +0 -81
  82. package/dist/components/Illustration/TransportSvg/index.d.ts +0 -5
  83. package/dist/components/Illustration/TransportSvg/index.d.ts.map +0 -1
  84. package/dist/components/Illustration/TransportSvg/index.js +0 -102
  85. package/dist/components/NewSelect/components/OptionsSelect/index.d.ts +0 -4
  86. package/dist/components/NewSelect/components/OptionsSelect/index.d.ts.map +0 -1
  87. package/dist/components/NewSelect/components/OptionsSelect/index.js +0 -56
@@ -4,251 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.NewSelect = NewSelect;
7
- var _react = require("react");
8
- var _classnames = _interopRequireDefault(require("classnames"));
9
- var _Flex = _interopRequireDefault(require("../Flex"));
10
- var _Icon = _interopRequireDefault(require("../Icon"));
11
- var _ReactPortal = require("../ReactPortal");
12
- var _OptionsSelect = require("./components/OptionsSelect");
13
- var _useOnClickOutside = require("../../shared/hooks/useOnClickOutside");
14
- var _useReposition = require("../../shared/hooks/useReposition");
15
- var _styles = require("./styles");
7
+ var _multiple = require("./multiple");
8
+ var _single = require("./single");
16
9
  var _jsxRuntime = require("react/jsx-runtime");
17
- var _excluded = ["label", "placeholder", "alert", "helperText", "variant", "children", "value", "onClose", "onOpen", "multiple", "renderOptions", "onChange"];
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
20
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
21
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
22
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
23
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
24
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
25
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
26
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
27
- function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
28
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
29
- 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; }
30
- 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; }
31
- function NewSelect(_ref) {
32
- var _optionsModalRef$curr, _containerRef$current;
33
- var _ref$label = _ref.label,
34
- label = _ref$label === void 0 ? '' : _ref$label,
35
- _ref$placeholder = _ref.placeholder,
36
- placeholder = _ref$placeholder === void 0 ? '' : _ref$placeholder,
37
- alert = _ref.alert,
38
- helperText = _ref.helperText,
39
- variant = _ref.variant,
40
- children = _ref.children,
41
- value = _ref.value,
42
- onClose = _ref.onClose,
43
- onOpen = _ref.onOpen,
44
- multiple = _ref.multiple,
45
- renderOptions = _ref.renderOptions,
46
- onChange = _ref.onChange,
47
- rest = _objectWithoutProperties(_ref, _excluded);
48
- var containerRef = (0, _react.useRef)(null);
49
- var selectRef = (0, _react.useRef)(null);
50
- var _useState = (0, _react.useState)(false),
51
- _useState2 = _slicedToArray(_useState, 2),
52
- isOpenOptions = _useState2[0],
53
- setIsOpenOptions = _useState2[1];
54
- var _useState3 = (0, _react.useState)([]),
55
- _useState4 = _slicedToArray(_useState3, 2),
56
- multipleSelectedOptions = _useState4[0],
57
- setMultipleSelectedOptions = _useState4[1];
58
- var multipleSelectValues = multipleSelectedOptions.map(function (option) {
59
- return option.value;
60
- });
61
- var _useState5 = (0, _react.useState)(placeholder),
62
- _useState6 = _slicedToArray(_useState5, 2),
63
- labelSelectedOption = _useState6[0],
64
- setLabelSelectedOption = _useState6[1];
65
- var optionsModalRef = (0, _react.useRef)(null);
66
- var buttonOptions = (_optionsModalRef$curr = optionsModalRef.current) === null || _optionsModalRef$curr === void 0 ? void 0 : _optionsModalRef$curr.querySelectorAll('.select-item');
67
- (0, _react.useEffect)(function () {
68
- if (Array.isArray(value) && value.length === 0) {
69
- setMultipleSelectedOptions([]);
70
- return;
71
- }
72
- if (value === undefined || value === '') {
73
- setLabelSelectedOption('');
74
- return;
75
- }
76
- var options = [];
77
- var validChildrenOptions = _react.Children.toArray(children).filter(function (child) {
78
- if ( /*#__PURE__*/(0, _react.isValidElement)(child)) {
79
- var _ref2 = child,
80
- type = _ref2.type;
81
- return type.name === 'SelectItem';
82
- }
83
- return false;
84
- });
85
- validChildrenOptions.forEach(function (child, index) {
86
- var _buttonOptions$index;
87
- options.push({
88
- value: child.props.value,
89
- label: buttonOptions === null || buttonOptions === void 0 ? void 0 : (_buttonOptions$index = buttonOptions[index]) === null || _buttonOptions$index === void 0 ? void 0 : _buttonOptions$index.textContent
90
- });
91
- });
92
- if (Array.isArray(value)) {
93
- var findMultipleOptions = options.filter(function (option) {
94
- return value.includes(option.value);
95
- });
96
- if (!findMultipleOptions[0]) return;
97
- setMultipleSelectedOptions(findMultipleOptions);
98
- } else {
99
- var findOption = options.find(function (option) {
100
- return option.value === value;
101
- });
102
- if (!findOption) return;
103
- setLabelSelectedOption((findOption === null || findOption === void 0 ? void 0 : findOption.label) || '');
104
- }
105
- }, [value, buttonOptions === null || buttonOptions === void 0 ? void 0 : buttonOptions.length]);
106
- function changeMultipleOption(event, valueOption) {
107
- event.stopPropagation();
108
- if (!multiple) return;
109
- if (value.includes(valueOption)) {
110
- removeOption(valueOption);
111
- } else {
112
- if (multiple) onChange === null || onChange === void 0 ? void 0 : onChange([].concat(_toConsumableArray(multipleSelectValues), [valueOption]));
113
- }
114
- }
115
- (0, _react.useEffect)(function () {
116
- function handler() {
117
- setIsOpenOptions(false);
118
- }
119
- if (isOpenOptions) {
120
- var _document;
121
- onOpen === null || onOpen === void 0 ? void 0 : onOpen();
122
- (_document = document) === null || _document === void 0 ? void 0 : _document.addEventListener('scroll', handler);
123
- } else {
124
- var _document2;
125
- onClose === null || onClose === void 0 ? void 0 : onClose();
126
- (_document2 = document) === null || _document2 === void 0 ? void 0 : _document2.removeEventListener('scroll', handler);
127
- }
128
- return function () {
129
- var _document3;
130
- return (_document3 = document) === null || _document3 === void 0 ? void 0 : _document3.removeEventListener('scroll', handler);
131
- };
132
- }, [isOpenOptions]);
133
- (0, _useOnClickOutside.useOnClickOutside)([selectRef, optionsModalRef], function () {
134
- if (isOpenOptions) {
135
- setIsOpenOptions(false);
136
- }
137
- });
138
- var positionsSelect = (0, _useReposition.useReposition)({
139
- containerRef: optionsModalRef,
140
- triggerRef: selectRef
141
- }, [children]);
142
- function removeOption(optionToRemove) {
143
- if (!multiple) return;
144
- var newSelectedOptions = value.filter(function (option) {
145
- return option !== optionToRemove;
146
- });
147
- onChange === null || onChange === void 0 ? void 0 : onChange(newSelectedOptions);
148
- }
149
- var SelectedOptionsWithCustomComponent = function SelectedOptionsWithCustomComponent(_ref3) {
150
- var option = _ref3.option;
151
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
152
- children: renderOptions === null || renderOptions === void 0 ? void 0 : renderOptions(option, function () {
153
- return removeOption(option.value);
154
- })
155
- });
156
- };
157
- return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
158
- ref: selectRef,
159
- children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Flex.default, {
160
- direction: "column",
161
- style: {
162
- width: '100%'
163
- },
164
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.SelectContainer, {
165
- "data-disabled": rest.disabled,
166
- "data-variant": variant,
167
- "data-label-in-top": !!labelSelectedOption || !!(multipleSelectedOptions !== null && multipleSelectedOptions !== void 0 && multipleSelectedOptions[0]),
168
- alert: alert,
169
- tabIndex: rest.disabled ? -1 : 0,
170
- onClick: function onClick() {
171
- return setIsOpenOptions(!isOpenOptions);
172
- },
173
- className: rest.className,
174
- style: rest.style,
175
- ref: containerRef,
176
- children: [label && variant !== 'unstyled' && /*#__PURE__*/(0, _jsxRuntime.jsx)("label", {
177
- children: label
178
- }), multiple ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Flex.default, {
179
- spacing: "0.5rem",
180
- wrap: "wrap",
181
- "data-testId": "container-multiple-options",
182
- children: multipleSelectedOptions.map(function (option, index) {
183
- return typeof renderOptions === 'function' ? /*#__PURE__*/(0, _jsxRuntime.jsx)(SelectedOptionsWithCustomComponent, {
184
- option: option
185
- }, "custom-option-selected-".concat(index)) : /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.SelectedOptionSpan, {
186
- onClick: function onClick(event) {
187
- event.stopPropagation();
188
- removeOption(option.value);
189
- },
190
- hasSelectedOption: true,
191
- children: [option.label, multipleSelectedOptions.length > 1 && index < multipleSelectedOptions.length - 1 && ',']
192
- }, index);
193
- })
194
- }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.SelectedOptionSpan, {
195
- "data-testId": "span-selected-option",
196
- hasSelectedOption: !!labelSelectedOption,
197
- children: labelSelectedOption
198
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.default, {
199
- name: "chevron-down"
200
- })]
201
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ReactPortal.ReactPortal, {
202
- wrapperId: "portal-root",
203
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_OptionsSelect.OptionsSelect, {
204
- ref: optionsModalRef,
205
- open: isOpenOptions,
206
- maxWidth: "".concat((_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.getBoundingClientRect().width, "px"),
207
- left: positionsSelect.left,
208
- top: positionsSelect.top,
209
- handleDefaultValue: function handleDefaultValue(options) {
210
- if (multiple) {
211
- var defaultOptions = options === null || options === void 0 ? void 0 : options.filter(function (selectedOption) {
212
- return value === null || value === void 0 ? void 0 : value.includes(String(selectedOption.value));
213
- });
214
- setMultipleSelectedOptions(defaultOptions || []);
215
- } else {
216
- var defaultOption = options.find(function (option) {
217
- return String(option.value).includes(String(value));
218
- });
219
- setLabelSelectedOption(defaultOption === null || defaultOption === void 0 ? void 0 : defaultOption.label);
220
- }
221
- },
222
- children: _react.Children.map(children, function (child) {
223
- var isSelectedOption = multipleSelectedOptions.find(function (option) {
224
- var _child$props;
225
- return option.value === ((_child$props = child.props) === null || _child$props === void 0 ? void 0 : _child$props.value);
226
- });
227
- var childTypeName = child.type.name || child.type.displayName;
228
- var isSelectItemElement = /*#__PURE__*/(0, _react.isValidElement)(child) && childTypeName === 'SelectItem';
229
- var className = (0, _classnames.default)(isSelectItemElement ? 'select-item' : '', {
230
- selected: isSelectedOption
231
- });
232
- return /*#__PURE__*/(0, _react.cloneElement)(child, {
233
- onClick: function onClick(event) {
234
- if (event.currentTarget.classList.contains('select-item')) {
235
- if (multiple) {
236
- changeMultipleOption(event, child.props.value);
237
- } else {
238
- setIsOpenOptions(false);
239
- onChange(child.props.value);
240
- }
241
- }
242
- },
243
- className: className
244
- });
245
- })
246
- })
247
- }), !!helperText && /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.HelperText, {
248
- alert: alert,
249
- children: helperText
250
- })]
251
- })
252
- });
253
- }
254
- NewSelect.displayName = 'NewSelect';
10
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
11
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
12
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
13
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
14
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
15
+ 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); }
16
+ function NewSelect(props) {
17
+ return props.multiple ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_multiple.NewMultipleSelect, _objectSpread({}, props)) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_single.NewSingleSelect, _objectSpread({}, props));
18
+ }
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import { SelectPropsMultipleSelect } from '../types';
3
+ export declare function NewMultipleSelect({ label, placeholder, alert, helperText, variant, children, value, onClose, onOpen, renderOptions, onChange, ...rest }: SelectPropsMultipleSelect): JSX.Element;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/NewSelect/multiple/index.tsx"],"names":[],"mappings":";AAmBA,OAAO,EAAgB,yBAAyB,EAAe,MAAM,UAAU,CAAC;AAGhF,wBAAgB,iBAAiB,CAAC,EAChC,KAAU,EACV,WAAgB,EAChB,KAAK,EACL,UAAU,EACV,OAAO,EACP,QAAQ,EACR,KAAK,EACL,OAAO,EACP,MAAM,EACN,aAAa,EACb,QAAQ,EACR,GAAG,IAAI,EACR,EAAE,yBAAyB,eAiL3B"}
@@ -0,0 +1,236 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.NewMultipleSelect = NewMultipleSelect;
7
+ var _react = require("react");
8
+ var _classnames = _interopRequireDefault(require("classnames"));
9
+ var _Flex = _interopRequireDefault(require("../../Flex"));
10
+ var _Icon = _interopRequireDefault(require("../../Icon"));
11
+ var _ReactPortal = require("../../ReactPortal");
12
+ var _styles = require("../components/OptionsSelect/styles");
13
+ var _useReposition = require("../../../shared/hooks/useReposition");
14
+ var _useOnClickOutside = require("../../../shared/hooks/useOnClickOutside");
15
+ var _styles2 = require("../styles");
16
+ var _jsxRuntime = require("react/jsx-runtime");
17
+ var _excluded = ["label", "placeholder", "alert", "helperText", "variant", "children", "value", "onClose", "onOpen", "renderOptions", "onChange"];
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
20
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
21
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
22
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
23
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
24
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
25
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
26
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
27
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
28
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
29
+ 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; }
30
+ 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; }
31
+ function NewMultipleSelect(_ref) {
32
+ var _containerRef$current;
33
+ var _ref$label = _ref.label,
34
+ label = _ref$label === void 0 ? '' : _ref$label,
35
+ _ref$placeholder = _ref.placeholder,
36
+ placeholder = _ref$placeholder === void 0 ? '' : _ref$placeholder,
37
+ alert = _ref.alert,
38
+ helperText = _ref.helperText,
39
+ variant = _ref.variant,
40
+ children = _ref.children,
41
+ value = _ref.value,
42
+ onClose = _ref.onClose,
43
+ onOpen = _ref.onOpen,
44
+ renderOptions = _ref.renderOptions,
45
+ onChange = _ref.onChange,
46
+ rest = _objectWithoutProperties(_ref, _excluded);
47
+ var containerRef = (0, _react.useRef)(null);
48
+ var selectRef = (0, _react.useRef)(null);
49
+ var _useState = (0, _react.useState)(false),
50
+ _useState2 = _slicedToArray(_useState, 2),
51
+ isOpenOptions = _useState2[0],
52
+ setIsOpenOptions = _useState2[1];
53
+ var _useState3 = (0, _react.useState)([]),
54
+ _useState4 = _slicedToArray(_useState3, 2),
55
+ selectedOptions = _useState4[0],
56
+ setSelectedOptions = _useState4[1];
57
+ var multipleSelectValues = selectedOptions.map(function (option) {
58
+ return option.value;
59
+ });
60
+ var optionsModalRef = (0, _react.useRef)(null);
61
+ var _useState5 = (0, _react.useState)([]),
62
+ _useState6 = _slicedToArray(_useState5, 2),
63
+ options = _useState6[0],
64
+ setOptions = _useState6[1];
65
+ (0, _react.useEffect)(function () {
66
+ var _options$, _optionsModalRef$curr;
67
+ if (options !== null && options !== void 0 && (_options$ = options[0]) !== null && _options$ !== void 0 && _options$.value) return;
68
+ var childs = (_optionsModalRef$curr = optionsModalRef.current) === null || _optionsModalRef$curr === void 0 ? void 0 : _optionsModalRef$curr.childNodes;
69
+ var newOptions = [];
70
+ _react.Children.forEach(children, function (child, index) {
71
+ if (childs !== null && childs !== void 0 && childs[index].classList.contains('select-item')) {
72
+ newOptions.push({
73
+ value: child.props.value,
74
+ label: childs[index].innerText
75
+ });
76
+ }
77
+ });
78
+ setOptions(newOptions);
79
+ }, [children, optionsModalRef.current]);
80
+ function changeMultipleOption(valueOption) {
81
+ if (valueOption === undefined) {
82
+ setSelectedOptions([]);
83
+ setIsOpenOptions(false);
84
+ return;
85
+ }
86
+ var findOption = selectedOptions.find(function (option) {
87
+ return option.value === valueOption;
88
+ });
89
+ if (findOption) {
90
+ removeOption(valueOption);
91
+ } else {
92
+ var newOption = options.find(function (option) {
93
+ return option.value === valueOption;
94
+ });
95
+ if (newOption) {
96
+ setSelectedOptions([].concat(_toConsumableArray(selectedOptions), [newOption]));
97
+ }
98
+ onChange === null || onChange === void 0 ? void 0 : onChange([].concat(_toConsumableArray(multipleSelectValues), [valueOption]));
99
+ }
100
+ }
101
+ (0, _react.useEffect)(function () {
102
+ function handler() {
103
+ setIsOpenOptions(false);
104
+ }
105
+ if (isOpenOptions) {
106
+ var _document;
107
+ onOpen === null || onOpen === void 0 ? void 0 : onOpen();
108
+ (_document = document) === null || _document === void 0 ? void 0 : _document.addEventListener('scroll', handler);
109
+ } else {
110
+ var _document2;
111
+ onClose === null || onClose === void 0 ? void 0 : onClose();
112
+ (_document2 = document) === null || _document2 === void 0 ? void 0 : _document2.removeEventListener('scroll', handler);
113
+ }
114
+ return function () {
115
+ var _document3;
116
+ return (_document3 = document) === null || _document3 === void 0 ? void 0 : _document3.removeEventListener('scroll', handler);
117
+ };
118
+ }, [isOpenOptions]);
119
+ (0, _useOnClickOutside.useOnClickOutside)([containerRef, optionsModalRef], function () {
120
+ if (isOpenOptions) {
121
+ setIsOpenOptions(false);
122
+ }
123
+ });
124
+ var positionsSelect = (0, _useReposition.useReposition)({
125
+ containerRef: optionsModalRef,
126
+ triggerRef: selectRef
127
+ }, [children]);
128
+ function removeOption(optionToRemove) {
129
+ var newSelectedOptions = selectedOptions === null || selectedOptions === void 0 ? void 0 : selectedOptions.filter(function (option) {
130
+ return option.value !== optionToRemove;
131
+ });
132
+ var newSelectedValues = newSelectedOptions.map(function (option) {
133
+ return option.value;
134
+ });
135
+ setSelectedOptions(newSelectedOptions);
136
+ onChange === null || onChange === void 0 ? void 0 : onChange(newSelectedValues);
137
+ }
138
+ var SelectedOptionsWithCustomComponent = function SelectedOptionsWithCustomComponent(_ref2) {
139
+ var option = _ref2.option;
140
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
141
+ children: renderOptions === null || renderOptions === void 0 ? void 0 : renderOptions(option, function () {
142
+ return removeOption(option.value);
143
+ })
144
+ });
145
+ };
146
+ (0, _react.useEffect)(function () {
147
+ var newOptions = options.filter(function (option) {
148
+ return value === null || value === void 0 ? void 0 : value.includes(option.value);
149
+ });
150
+ setSelectedOptions(newOptions);
151
+ }, [value, options]);
152
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
153
+ ref: selectRef,
154
+ style: {
155
+ width: '100%'
156
+ },
157
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Flex.default, {
158
+ direction: "column",
159
+ style: {
160
+ width: '100%'
161
+ },
162
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles2.SelectContainer, {
163
+ "data-disabled": rest.disabled,
164
+ "data-variant": variant,
165
+ "data-label-in-top": !!(selectedOptions !== null && selectedOptions !== void 0 && selectedOptions[0]) || !!placeholder,
166
+ alert: alert,
167
+ tabIndex: rest.disabled ? -1 : 0,
168
+ onClick: function onClick() {
169
+ return setIsOpenOptions(!isOpenOptions);
170
+ },
171
+ className: rest.className,
172
+ style: rest.style,
173
+ ref: containerRef,
174
+ children: [label && variant !== 'unstyled' && /*#__PURE__*/(0, _jsxRuntime.jsx)("label", {
175
+ title: label,
176
+ children: label
177
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Flex.default, {
178
+ spacing: "0.5rem",
179
+ wrap: "wrap",
180
+ style: {
181
+ paddingBlock: '0.5rem'
182
+ },
183
+ children: selectedOptions !== null && selectedOptions !== void 0 && selectedOptions[0] ? selectedOptions.map(function (option, index) {
184
+ return typeof renderOptions === 'function' ? /*#__PURE__*/(0, _jsxRuntime.jsx)(SelectedOptionsWithCustomComponent, {
185
+ option: option
186
+ }, "custom-option-selected-".concat(index)) : /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles2.SelectedOptionSpan, {
187
+ hasSelectedOption: true,
188
+ children: [option.label, selectedOptions.length > 1 && index < selectedOptions.length - 1 && ',']
189
+ }, index);
190
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles2.SelectedOptionSpan, {
191
+ title: "placeholder",
192
+ children: placeholder
193
+ })
194
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Flex.default, {
195
+ className: "select_container_icon",
196
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.default, {
197
+ name: "chevron-down"
198
+ })
199
+ })]
200
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ReactPortal.ReactPortal, {
201
+ wrapperId: "portal-root",
202
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.OptionsContainer, {
203
+ ref: optionsModalRef,
204
+ open: isOpenOptions,
205
+ style: {
206
+ maxWidth: "".concat((_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.getBoundingClientRect().width, "px"),
207
+ left: positionsSelect.left,
208
+ top: positionsSelect.top
209
+ },
210
+ children: _react.Children.map(children, function (child) {
211
+ var isSelectedOption = selectedOptions.find(function (option) {
212
+ var _child$props;
213
+ return option.value === ((_child$props = child.props) === null || _child$props === void 0 ? void 0 : _child$props.value);
214
+ });
215
+ var childTypeName = child.type.name || child.type.displayName;
216
+ var isSelectItemElement = /*#__PURE__*/(0, _react.isValidElement)(child) && childTypeName === 'SelectItem';
217
+ var className = (0, _classnames.default)(isSelectItemElement ? 'select-item' : '', {
218
+ selected: isSelectedOption
219
+ });
220
+ return /*#__PURE__*/(0, _react.cloneElement)(child, {
221
+ onClick: function onClick(event) {
222
+ if (event.currentTarget.classList.contains('select-item')) {
223
+ changeMultipleOption(child.props.value);
224
+ }
225
+ },
226
+ className: className
227
+ });
228
+ })
229
+ })
230
+ }), !!helperText && /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles2.HelperText, {
231
+ alert: alert,
232
+ children: helperText
233
+ })]
234
+ })
235
+ });
236
+ }
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import { SelectPropsSingleSelect } from '../types';
3
+ export declare function NewSingleSelect<T>({ label, placeholder, alert, helperText, variant, children, value, onClose, onOpen, onChange, renderOptions, ...rest }: SelectPropsSingleSelect<T>): JSX.Element;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/NewSelect/single/index.tsx"],"names":[],"mappings":";AAWA,OAAO,EAAgB,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAEjE,wBAAgB,eAAe,CAAC,CAAC,EAAE,EACjC,KAAU,EACV,WAAgB,EAChB,KAAK,EACL,UAAU,EACV,OAAO,EACP,QAAQ,EACR,KAAK,EACL,OAAO,EACP,MAAM,EACN,QAAQ,EACR,aAAa,EACb,GAAG,IAAI,EACR,EAAE,uBAAuB,CAAC,CAAC,CAAC,eAgI5B"}