@pedidopago/ui 1.7.25 → 1.8.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.
- package/dist/components/Alert/alert.test.js +1 -85
- package/dist/components/Alert/index.js +1 -63
- package/dist/components/Alert/styles.js +1 -32
- package/dist/components/Avatar/avatar.test.js +1 -67
- package/dist/components/Avatar/index.js +1 -94
- package/dist/components/Avatar/styles.js +1 -51
- package/dist/components/Badge/badge.test.js +1 -71
- package/dist/components/Badge/index.js +2 -43
- package/dist/components/Badge/styles.js +1 -33
- package/dist/components/Button/Button.test.js +1 -154
- package/dist/components/Button/index.js +1 -87
- package/dist/components/Button/styles.js +1 -112
- package/dist/components/Card/card.test.js +1 -30
- package/dist/components/Card/index.js +1 -44
- package/dist/components/Card/styles.js +1 -16
- package/dist/components/CheckboxInput/checkbox-input.test.js +1 -170
- package/dist/components/CheckboxInput/components/MultipleCheckbox.js +1 -205
- package/dist/components/CheckboxInput/index.js +1 -94
- package/dist/components/CheckboxInput/styles.js +1 -34
- package/dist/components/ChoiceList/index.d.ts +6 -0
- package/dist/components/ChoiceList/index.d.ts.map +1 -0
- package/dist/components/ChoiceList/index.js +1 -0
- package/dist/components/ChoiceList/styles.d.ts +22 -0
- package/dist/components/ChoiceList/styles.d.ts.map +1 -0
- package/dist/components/ChoiceList/styles.js +1 -0
- package/dist/components/ChoiceList/types.d.ts +24 -0
- package/dist/components/ChoiceList/types.d.ts.map +1 -0
- package/dist/components/ChoiceList/types.js +1 -0
- package/dist/components/CollapseCard/ExpandButton/index.js +1 -40
- package/dist/components/CollapseCard/ExpandButton/styles.js +1 -16
- package/dist/components/CollapseCard/expand-button.test.js +1 -161
- package/dist/components/CollapseCard/index.js +1 -98
- package/dist/components/CollapseCard/styles.js +1 -26
- package/dist/components/ColorPicker/colorpicker.test.js +1 -64
- package/dist/components/ColorPicker/components/ColorHue.js +1 -44
- package/dist/components/ColorPicker/components/ColorInput.js +1 -63
- package/dist/components/ColorPicker/components/ColorPickerBox.js +1 -52
- package/dist/components/ColorPicker/components/ColorPointer.js +1 -25
- package/dist/components/ColorPicker/components/ColorSelector.js +1 -107
- package/dist/components/ColorPicker/hooks/useCachedCallback.js +1 -16
- package/dist/components/ColorPicker/hooks/useHsva.js +1 -53
- package/dist/components/ColorPicker/index.js +1 -93
- package/dist/components/ColorPicker/styles.js +1 -46
- package/dist/components/ColorPicker/utils/checkers.js +1 -55
- package/dist/components/ColorPicker/utils/conversors.js +2 -243
- package/dist/components/ColorPicker/utils/parsers.js +10 -108
- package/dist/components/ComposeIcon/index.js +2 -48
- package/dist/components/ComposeIcon/styles.js +1 -53
- package/dist/components/DateInput/DateInput-example.js +7 -45
- package/dist/components/DateInput/components/ModalWrapper/index.js +1 -35
- package/dist/components/DateInput/components/ModalWrapper/styles.js +1 -21
- package/dist/components/DateInput/dateInput.test.js +2 -43
- package/dist/components/DateInput/index.js +2 -104
- package/dist/components/DateInput/styles.js +1 -18
- package/dist/components/DatePicker/components/DatePickerContent.js +2 -222
- package/dist/components/DatePicker/components/DateYearPicker.js +1 -102
- package/dist/components/DatePicker/datepicker.test.js +1 -120
- package/dist/components/DatePicker/index.js +1 -236
- package/dist/components/DatePicker/styles.js +1 -88
- package/dist/components/DatePicker/utils/getMonthName.js +1 -11
- package/dist/components/Dialog/dialog-example.js +1 -46
- package/dist/components/Dialog/dialog.test.js +1 -68
- package/dist/components/Dialog/index.js +2 -100
- package/dist/components/Dialog/styles.js +1 -31
- package/dist/components/Dropzone/dropzone.test.js +1 -69
- package/dist/components/Dropzone/index.js +1 -289
- package/dist/components/Dropzone/styles.js +1 -75
- package/dist/components/Dropzone/utils/accepts.js +2 -27
- package/dist/components/EmojiPicker/Emote/index.js +2 -24
- package/dist/components/EmojiPicker/Emote/styles.js +1 -27
- package/dist/components/EmojiPicker/EmotePickerData/constants.js +1 -51
- package/dist/components/EmojiPicker/EmotePickerData/index.js +2 -159
- package/dist/components/EmojiPicker/EmotePickerData/styles.js +1 -57
- package/dist/components/EmojiPicker/EmotePickerData/utils.js +1 -41
- package/dist/components/EmojiPicker/Example/EmotePickerExample.js +1 -43
- package/dist/components/EmojiPicker/animation.js +1 -43
- package/dist/components/EmojiPicker/index.js +1 -169
- package/dist/components/EmojiPicker/styles.js +1 -21
- package/dist/components/Flex/flex.test.js +1 -336
- package/dist/components/Flex/index.js +1 -49
- package/dist/components/Flex/styles.js +1 -25
- package/dist/components/Grid/grid.test.js +1 -134
- package/dist/components/Grid/index.js +1 -51
- package/dist/components/Grid/styles.js +1 -48
- package/dist/components/Icon/data/beauty.js +2 -206
- package/dist/components/Icon/data/dash.js +2 -2
- package/dist/components/Icon/data/ecommerce.js +2 -94
- package/dist/components/Icon/data/form.js +2 -248
- package/dist/components/Icon/data/health.js +2 -255
- package/dist/components/Icon/data/illustrations.js +2 -318
- package/dist/components/Icon/data/men.js +2 -52
- package/dist/components/Icon/data/payment.js +2 -94
- package/dist/components/Icon/data/pedidoPago.js +2 -45
- package/dist/components/Icon/data/physicalPerfomance.js +2 -283
- package/dist/components/Icon/data/social.js +2 -24
- package/dist/components/Icon/data/status.js +2 -115
- package/dist/components/Icon/data/summer.js +2 -52
- package/dist/components/Icon/data/woman.js +2 -80
- package/dist/components/Icon/icon.test.js +1 -57
- package/dist/components/Icon/index.js +1 -53
- package/dist/components/Icon/scripts/build.js +9 -104
- package/dist/components/Icon/scripts/extractor.js +2 -33
- package/dist/components/Icon/scripts/run-build.js +2 -7
- package/dist/components/Icon/scripts/writers.js +3 -34
- package/dist/components/Icon/styles.js +1 -22
- package/dist/components/Icon/utils/allIcons.js +1 -28
- package/dist/components/Icon/utils/iconExists.js +1 -13
- package/dist/components/IconItem/IconItem.test.js +1 -58
- package/dist/components/IconItem/index.js +1 -52
- package/dist/components/IconItem/styles.js +1 -43
- package/dist/components/Illustration/illustration.test.js +4 -50
- package/dist/components/Illustration/index.js +2 -65
- package/dist/components/Illustration/styles.js +1 -65
- package/dist/components/ImageItem/imageFake.js +1 -25
- package/dist/components/ImageItem/index.js +2 -66
- package/dist/components/ImageItem/input.test.js +1 -85
- package/dist/components/ImageItem/styles.js +1 -61
- package/dist/components/Input/index.js +1 -163
- package/dist/components/Input/input.test.js +1 -120
- package/dist/components/Input/styles.js +1 -177
- package/dist/components/Label/index.js +1 -45
- package/dist/components/Label/label.test.js +1 -83
- package/dist/components/Label/styles.js +1 -21
- package/dist/components/List/index.js +1 -39
- package/dist/components/List/list.test.js +1 -64
- package/dist/components/List/styles.js +1 -23
- package/dist/components/Modal/ModalExample.js +1 -70
- package/dist/components/Modal/index.js +1 -145
- package/dist/components/Modal/modal.test.js +1 -179
- package/dist/components/Modal/styles.js +1 -33
- package/dist/components/MultipleSelect/MultipleSelect.test.js +1 -334
- package/dist/components/MultipleSelect/animations.js +1 -25
- package/dist/components/MultipleSelect/components/InputWrapper/index.js +1 -26
- package/dist/components/MultipleSelect/components/OptionsArea/index.js +1 -244
- package/dist/components/MultipleSelect/components/OptionsArea/styles.js +1 -68
- package/dist/components/MultipleSelect/components/SelectArea/ButtonsArea.js +1 -27
- package/dist/components/MultipleSelect/components/SelectArea/SelectAreaWrapper.js +1 -37
- package/dist/components/MultipleSelect/components/SelectArea/SelectedOptionsArea.js +1 -49
- package/dist/components/MultipleSelect/components/SelectArea/index.js +1 -100
- package/dist/components/MultipleSelect/components/SelectArea/styles.js +1 -36
- package/dist/components/MultipleSelect/components/index.js +1 -38
- package/dist/components/MultipleSelect/index.js +1 -209
- package/dist/components/NewSelect/Examples/constants.js +1 -56
- package/dist/components/NewSelect/Examples/index.js +1 -161
- package/dist/components/NewSelect/components/Chip/index.js +1 -36
- package/dist/components/NewSelect/components/Chip/styles.js +1 -24
- package/dist/components/NewSelect/components/OptionsSelect/styles.js +1 -21
- package/dist/components/NewSelect/components/SelectInputSearch/index.js +1 -24
- package/dist/components/NewSelect/components/SelectItem/index.js +1 -22
- package/dist/components/NewSelect/components/SelectItem/styles.js +1 -24
- package/dist/components/NewSelect/index.js +1 -18
- package/dist/components/NewSelect/multiple/index.d.ts.map +1 -1
- package/dist/components/NewSelect/multiple/index.js +1 -247
- package/dist/components/NewSelect/newSelect.test.js +1 -108
- package/dist/components/NewSelect/single/index.js +1 -183
- package/dist/components/NewSelect/styles.js +1 -44
- package/dist/components/Observer/index.js +1 -59
- package/dist/components/Observer/observer.test.js +2 -43
- package/dist/components/Pagination/hooks/usePagination.js +1 -57
- package/dist/components/Pagination/index.js +1 -174
- package/dist/components/Pagination/pagination.test.js +1 -118
- package/dist/components/Pagination/styles.js +1 -78
- package/dist/components/Progress/Circle/index.js +1 -102
- package/dist/components/Progress/Circle/styles.js +1 -69
- package/dist/components/Progress/Linear/index.js +1 -62
- package/dist/components/Progress/Linear/styles.js +1 -66
- package/dist/components/Progress/getSteps.js +1 -17
- package/dist/components/Progress/index.js +1 -39
- package/dist/components/Progress/progress.test.js +1 -109
- package/dist/components/Radio/components/RadioGroup/index.d.ts +5 -0
- package/dist/components/Radio/components/RadioGroup/index.d.ts.map +1 -0
- package/dist/components/Radio/components/RadioGroup/index.js +1 -0
- package/dist/components/Radio/components/RadioGroup/styles.d.ts +19 -0
- package/dist/components/Radio/components/RadioGroup/styles.d.ts.map +1 -0
- package/dist/components/Radio/components/RadioGroup/styles.js +1 -0
- package/dist/components/Radio/components/RadioGroup/types.d.ts +17 -0
- package/dist/components/Radio/components/RadioGroup/types.d.ts.map +1 -0
- package/dist/components/Radio/components/RadioGroup/types.js +1 -0
- package/dist/components/Radio/index.d.ts +5 -0
- package/dist/components/Radio/index.d.ts.map +1 -0
- package/dist/components/Radio/index.js +1 -0
- package/dist/components/Radio/styles.d.ts +10 -0
- package/dist/components/Radio/styles.d.ts.map +1 -0
- package/dist/components/Radio/styles.js +1 -0
- package/dist/components/Radio/types.d.ts +6 -0
- package/dist/components/Radio/types.d.ts.map +1 -0
- package/dist/components/Radio/types.js +1 -0
- package/dist/components/Rating/index.js +1 -133
- package/dist/components/Rating/rating.test.js +1 -63
- package/dist/components/Rating/styles.js +1 -27
- package/dist/components/ReactPortal/index.js +1 -43
- package/dist/components/ReactPortal/reactPortal.test.js +1 -21
- package/dist/components/ReactPortal/utils/createWrapperAndApprendToBody.js +1 -12
- package/dist/components/Select/components/OptionsSelect/index.js +1 -73
- package/dist/components/Select/components/OptionsSelect/styles.js +1 -21
- package/dist/components/Select/index.js +4 -247
- package/dist/components/Select/select.test.js +1 -58
- package/dist/components/Select/styles.js +1 -46
- package/dist/components/Skeleton/index.js +1 -28
- package/dist/components/Skeleton/skeleton.test.js +1 -90
- package/dist/components/Skeleton/styles.js +1 -27
- package/dist/components/Slider/SliderExample.js +1 -52
- package/dist/components/Slider/components/SliderPointer.js +1 -39
- package/dist/components/Slider/components/SliderRail.js +1 -116
- package/dist/components/Slider/components/SliderSelector.js +1 -173
- package/dist/components/Slider/hooks/useEventCallback.js +1 -16
- package/dist/components/Slider/index.js +1 -137
- package/dist/components/Slider/slider.test.js +1 -121
- package/dist/components/Slider/styles.js +1 -69
- package/dist/components/Spinner/index.js +1 -26
- package/dist/components/Spinner/spinner.test.js +1 -45
- package/dist/components/Spinner/styles.js +1 -23
- package/dist/components/Steps/components/StepIcon/index.js +1 -50
- package/dist/components/Steps/components/StepIcon/styles.js +1 -42
- package/dist/components/Steps/components/StepIcon/utils.js +1 -22
- package/dist/components/Steps/index.js +1 -116
- package/dist/components/Steps/steps.test.js +1 -53
- package/dist/components/Steps/styles.js +1 -96
- package/dist/components/Steps/utils.js +1 -15
- package/dist/components/Switch/index.js +1 -73
- package/dist/components/Switch/styles.js +1 -58
- package/dist/components/Switch/switch.test.js +2 -115
- package/dist/components/Table/components/MenuItem.js +1 -59
- package/dist/components/Table/components/TableSkeleton.js +1 -39
- package/dist/components/Table/components/animations.js +1 -24
- package/dist/components/Table/index.js +2 -253
- package/dist/components/Table/styles.js +1 -49
- package/dist/components/Table/table.test.js +1 -114
- package/dist/components/Tabs/TabsExample.js +1 -64
- package/dist/components/Tabs/components/Tab.js +1 -49
- package/dist/components/Tabs/components/TabPanel.js +1 -25
- package/dist/components/Tabs/components/Tabs.js +1 -107
- package/dist/components/Tabs/index.js +1 -26
- package/dist/components/Tabs/styles.js +1 -61
- package/dist/components/Tabs/tabs.test.js +1 -146
- package/dist/components/Tag/index.js +1 -53
- package/dist/components/Tag/styles.js +1 -34
- package/dist/components/Tag/tag.test.js +1 -64
- package/dist/components/TextAreaInput/index.js +1 -74
- package/dist/components/TextAreaInput/styles.js +1 -53
- package/dist/components/TextAreaInput/text-area-input.test.js +1 -81
- package/dist/components/Thumbnail/index.js +1 -125
- package/dist/components/Thumbnail/styles.js +1 -47
- package/dist/components/Thumbnail/thumbnail.test.js +1 -66
- package/dist/components/Thumbnail/utils/index.js +1 -27
- package/dist/components/Thumbnail/utils/validate-file-size.js +1 -10
- package/dist/components/Thumbnail/utils/validate-file-type.js +1 -9
- package/dist/components/TimeInput/constants.js +1 -29
- package/dist/components/TimeInput/index.js +1 -288
- package/dist/components/TimeInput/styles.js +1 -34
- package/dist/components/TimeInput/utils.js +1 -94
- package/dist/components/Timeline/components/Timeline.js +1 -17
- package/dist/components/Timeline/components/TimelineContent.js +1 -61
- package/dist/components/Timeline/components/TimelineItem.js +1 -25
- package/dist/components/Timeline/components/TimelineSeparator.js +1 -20
- package/dist/components/Timeline/index.js +1 -33
- package/dist/components/Timeline/styles.js +1 -37
- package/dist/components/Timeline/timeline.test.js +1 -138
- package/dist/components/Toast/button-example.js +1 -31
- package/dist/components/Toast/components/Toast.js +1 -79
- package/dist/components/Toast/contexts/ToastProvider.js +1 -72
- package/dist/components/Toast/hooks/useToast.js +1 -18
- package/dist/components/Toast/index.js +1 -111
- package/dist/components/Toast/styles.js +1 -36
- package/dist/components/Toast/toast.test.js +1 -129
- package/dist/components/Tooltip/components/TooltipLabel.js +1 -71
- package/dist/components/Tooltip/example.js +1 -27
- package/dist/components/Tooltip/index.js +1 -187
- package/dist/components/Tooltip/styles.js +1 -20
- package/dist/components/Typography/index.js +1 -37
- package/dist/components/Typography/styles.js +1 -15
- package/dist/components/Typography/typography.test.js +1 -288
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -548
- package/dist/shared/animations/opacityAnimation.js +1 -21
- package/dist/shared/assets/emotes.js +1 -1
- package/dist/shared/components/FocusLock/index.js +5 -86
- package/dist/shared/formatters/format-number.js +5 -41
- package/dist/shared/global.js +1 -8
- package/dist/shared/hooks/devices.js +1 -14
- package/dist/shared/hooks/useBreakpoints.js +2 -95
- package/dist/shared/hooks/useDebounce.js +1 -35
- package/dist/shared/hooks/useDevices.js +2 -42
- package/dist/shared/hooks/useDisableBodyScroll.js +5 -52
- package/dist/shared/hooks/useDraggableScroll/index.js +5 -65
- package/dist/shared/hooks/useKeyPress.js +1 -18
- package/dist/shared/hooks/useObserver.js +2 -29
- package/dist/shared/hooks/useOnClickOutside.js +1 -30
- package/dist/shared/hooks/useReposition/index.js +2 -53
- package/dist/shared/hooks/useSystemTheme.js +1 -38
- package/dist/shared/hooks/useWindowSize.js +1 -36
- package/dist/shared/tests/test-utils.js +1 -31
- package/dist/shared/theme/button-example.js +1 -31
- package/dist/shared/theme/contexts/ThemeContext.js +1 -90
- package/dist/shared/theme/hooks/useColorMode.js +1 -18
- package/dist/shared/theme/hooks/useColorModeValue.js +1 -13
- package/dist/shared/theme/hooks/useTheme.js +1 -17
- package/dist/shared/theme/index.js +1 -67
- package/dist/shared/theme/objects/breakpoints.js +1 -15
- package/dist/shared/theme/objects/colors.js +1 -177
- package/dist/shared/theme/objects/shadows.js +1 -19
- package/dist/shared/theme/objects/sizes.js +6 -33
- package/dist/shared/theme/objects/spaces.js +1 -75
- package/dist/shared/theme/objects/transitions.js +1 -10
- package/dist/shared/theme/objects/typography.js +1 -20
- package/dist/shared/theme/objects/z-indexes.js +1 -20
- package/dist/shared/theme/theme.js +1 -36
- package/dist/shared/theme/theme.test.js +1 -94
- package/dist/shared/theme/utils/extendTheme.js +1 -25
- package/dist/shared/theme/utils/localStorageController.js +1 -21
- package/dist/styled.d.js +1 -3
- package/dist/utils/GenerateKey.js +3 -18
- package/dist/utils/brightnessColorChange.js +2 -17
- package/dist/utils/colorCheck.js +6 -64
- package/dist/utils/colorFunctions.js +1 -39
- package/dist/utils/colorToGray.js +2 -64
- package/dist/utils/customColorMode.js +1 -11
- package/dist/utils/file.js +5 -124
- package/dist/utils/formatters/bytes.js +2 -17
- package/dist/utils/formatters/capitalize.js +2 -11
- package/dist/utils/formatters/cep.js +3 -18
- package/dist/utils/formatters/cnpj.js +4 -38
- package/dist/utils/formatters/color.js +12 -101
- package/dist/utils/formatters/cpf.js +16 -85
- package/dist/utils/formatters/credit-card.js +5 -54
- package/dist/utils/formatters/email.js +1 -8
- package/dist/utils/formatters/index.js +1 -170
- package/dist/utils/formatters/name.js +4 -31
- package/dist/utils/formatters/number.js +5 -14
- package/dist/utils/formatters/passport.js +5 -33
- package/dist/utils/formatters/phone.js +17 -214
- package/dist/utils/formatters/price.js +3 -21
- package/dist/utils/formatters/rg.js +3 -18
- package/dist/utils/formatters/strings.js +4 -27
- package/dist/utils/fuctionsColors.js +1 -39
- package/dist/utils/generateUUID.js +1 -13
- package/dist/utils/getColorValue.js +2 -23
- package/dist/utils/getSvg.js +1 -17
- package/dist/utils/getValuesBySize.js +1 -9
- package/dist/utils/invertColor.js +4 -40
- package/package.json +2 -1
|
@@ -1,247 +1 @@
|
|
|
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 _optionsModalRef$curr;
|
|
67
|
-
var childs = (_optionsModalRef$curr = optionsModalRef.current) === null || _optionsModalRef$curr === void 0 ? void 0 : _optionsModalRef$curr.childNodes;
|
|
68
|
-
var newOptions = [];
|
|
69
|
-
_react.Children.forEach(children, function (child, index) {
|
|
70
|
-
var _childs$index, _childs$index$classLi;
|
|
71
|
-
if (childs !== null && childs !== void 0 && (_childs$index = childs[index]) !== null && _childs$index !== void 0 && (_childs$index$classLi = _childs$index.classList) !== null && _childs$index$classLi !== void 0 && _childs$index$classLi.contains('select-item')) {
|
|
72
|
-
var _child$props, _childs$index2;
|
|
73
|
-
newOptions.push({
|
|
74
|
-
value: child === null || child === void 0 ? void 0 : (_child$props = child.props) === null || _child$props === void 0 ? void 0 : _child$props.value,
|
|
75
|
-
label: childs === null || childs === void 0 ? void 0 : (_childs$index2 = childs[index]) === null || _childs$index2 === void 0 ? void 0 : _childs$index2.innerText
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
setOptions(newOptions);
|
|
80
|
-
}, [children, optionsModalRef.current]);
|
|
81
|
-
function changeMultipleOption(valueOption) {
|
|
82
|
-
if (valueOption === undefined) {
|
|
83
|
-
setSelectedOptions([]);
|
|
84
|
-
setIsOpenOptions(false);
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
var findOption = selectedOptions.find(function (option) {
|
|
88
|
-
return option.value === valueOption;
|
|
89
|
-
});
|
|
90
|
-
if (findOption) {
|
|
91
|
-
removeOption(valueOption);
|
|
92
|
-
} else {
|
|
93
|
-
var newOption = options.find(function (option) {
|
|
94
|
-
return option.value === valueOption;
|
|
95
|
-
});
|
|
96
|
-
if (newOption) {
|
|
97
|
-
setSelectedOptions([].concat(_toConsumableArray(selectedOptions), [newOption]));
|
|
98
|
-
}
|
|
99
|
-
onChange === null || onChange === void 0 ? void 0 : onChange([].concat(_toConsumableArray(multipleSelectValues), [valueOption]));
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
(0, _react.useEffect)(function () {
|
|
103
|
-
function handler() {
|
|
104
|
-
setIsOpenOptions(false);
|
|
105
|
-
}
|
|
106
|
-
if (isOpenOptions) {
|
|
107
|
-
var _document;
|
|
108
|
-
onOpen === null || onOpen === void 0 ? void 0 : onOpen();
|
|
109
|
-
(_document = document) === null || _document === void 0 ? void 0 : _document.addEventListener('scroll', handler);
|
|
110
|
-
} else {
|
|
111
|
-
var _document2;
|
|
112
|
-
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
113
|
-
(_document2 = document) === null || _document2 === void 0 ? void 0 : _document2.removeEventListener('scroll', handler);
|
|
114
|
-
}
|
|
115
|
-
return function () {
|
|
116
|
-
var _document3;
|
|
117
|
-
return (_document3 = document) === null || _document3 === void 0 ? void 0 : _document3.removeEventListener('scroll', handler);
|
|
118
|
-
};
|
|
119
|
-
}, [isOpenOptions]);
|
|
120
|
-
(0, _useOnClickOutside.useOnClickOutside)([containerRef, optionsModalRef], function () {
|
|
121
|
-
if (isOpenOptions) {
|
|
122
|
-
setIsOpenOptions(false);
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
var positionsSelect = (0, _useReposition.useReposition)({
|
|
126
|
-
containerRef: optionsModalRef,
|
|
127
|
-
triggerRef: selectRef
|
|
128
|
-
}, [children]);
|
|
129
|
-
function removeOption(optionToRemove) {
|
|
130
|
-
var newSelectedOptions = selectedOptions === null || selectedOptions === void 0 ? void 0 : selectedOptions.filter(function (option) {
|
|
131
|
-
return option.value !== optionToRemove;
|
|
132
|
-
});
|
|
133
|
-
var newSelectedValues = newSelectedOptions.map(function (option) {
|
|
134
|
-
return option.value;
|
|
135
|
-
});
|
|
136
|
-
setSelectedOptions(newSelectedOptions);
|
|
137
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(newSelectedValues);
|
|
138
|
-
}
|
|
139
|
-
var SelectedOptionsWithCustomComponent = function SelectedOptionsWithCustomComponent(_ref2) {
|
|
140
|
-
var option = _ref2.option;
|
|
141
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
|
|
142
|
-
children: renderOptions === null || renderOptions === void 0 ? void 0 : renderOptions(option, function () {
|
|
143
|
-
return removeOption(option.value);
|
|
144
|
-
})
|
|
145
|
-
});
|
|
146
|
-
};
|
|
147
|
-
(0, _react.useEffect)(function () {
|
|
148
|
-
var newOptions = options.filter(function (option) {
|
|
149
|
-
return value === null || value === void 0 ? void 0 : value.includes(option.value);
|
|
150
|
-
});
|
|
151
|
-
var newSelectedOptions = selectedOptions.filter(function (selectedOption) {
|
|
152
|
-
return newOptions.every(function (newOption) {
|
|
153
|
-
return newOption.value !== selectedOption.value;
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
setSelectedOptions([].concat(_toConsumableArray(newSelectedOptions), _toConsumableArray(newOptions)));
|
|
157
|
-
}, [value, options]);
|
|
158
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
159
|
-
ref: selectRef,
|
|
160
|
-
style: {
|
|
161
|
-
width: '100%'
|
|
162
|
-
},
|
|
163
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Flex.default, {
|
|
164
|
-
direction: "column",
|
|
165
|
-
style: {
|
|
166
|
-
width: '100%'
|
|
167
|
-
},
|
|
168
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles2.SelectContainer, {
|
|
169
|
-
"data-disabled": rest.disabled,
|
|
170
|
-
"data-variant": variant,
|
|
171
|
-
"data-label-in-top": !!(selectedOptions !== null && selectedOptions !== void 0 && selectedOptions[0]) || !!placeholder,
|
|
172
|
-
alert: alert,
|
|
173
|
-
tabIndex: rest.disabled ? -1 : 0,
|
|
174
|
-
onClick: function onClick() {
|
|
175
|
-
return setIsOpenOptions(!isOpenOptions);
|
|
176
|
-
},
|
|
177
|
-
className: rest.className,
|
|
178
|
-
style: rest.style,
|
|
179
|
-
ref: containerRef,
|
|
180
|
-
children: [label && variant !== 'unstyled' && /*#__PURE__*/(0, _jsxRuntime.jsx)("label", {
|
|
181
|
-
title: label,
|
|
182
|
-
children: label
|
|
183
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Flex.default, {
|
|
184
|
-
spacing: "0.5rem",
|
|
185
|
-
wrap: "wrap",
|
|
186
|
-
style: {
|
|
187
|
-
paddingBlock: '0.5rem'
|
|
188
|
-
},
|
|
189
|
-
children: selectedOptions !== null && selectedOptions !== void 0 && selectedOptions[0] ? selectedOptions.map(function (option, index) {
|
|
190
|
-
return typeof renderOptions === 'function' ? /*#__PURE__*/(0, _jsxRuntime.jsx)(SelectedOptionsWithCustomComponent, {
|
|
191
|
-
option: option
|
|
192
|
-
}, "custom-option-selected-".concat(index)) : /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles2.SelectedOptionSpan, {
|
|
193
|
-
hasSelectedOption: true,
|
|
194
|
-
children: [option.label, selectedOptions.length > 1 && index < selectedOptions.length - 1 && ',']
|
|
195
|
-
}, index);
|
|
196
|
-
}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles2.SelectedOptionSpan, {
|
|
197
|
-
title: "placeholder",
|
|
198
|
-
children: placeholder
|
|
199
|
-
})
|
|
200
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Flex.default, {
|
|
201
|
-
className: "select_container_icon",
|
|
202
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.default, {
|
|
203
|
-
name: "chevron-down"
|
|
204
|
-
})
|
|
205
|
-
})]
|
|
206
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ReactPortal.ReactPortal, {
|
|
207
|
-
wrapperId: "portal-root",
|
|
208
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.OptionsContainer, {
|
|
209
|
-
ref: optionsModalRef,
|
|
210
|
-
open: isOpenOptions,
|
|
211
|
-
style: {
|
|
212
|
-
maxWidth: "".concat((_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.getBoundingClientRect().width, "px"),
|
|
213
|
-
left: positionsSelect.left,
|
|
214
|
-
top: positionsSelect.top
|
|
215
|
-
},
|
|
216
|
-
children: _react.Children.map(children, function (child) {
|
|
217
|
-
var _child$type, _child$type2;
|
|
218
|
-
var childTypeName = (child === null || child === void 0 ? void 0 : (_child$type = child.type) === null || _child$type === void 0 ? void 0 : _child$type.name) || (child === null || child === void 0 ? void 0 : (_child$type2 = child.type) === null || _child$type2 === void 0 ? void 0 : _child$type2.displayName);
|
|
219
|
-
var isSelectItemElement = childTypeName === 'SelectItem';
|
|
220
|
-
if (! /*#__PURE__*/(0, _react.isValidElement)(child) || !isSelectItemElement) return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
221
|
-
children: child
|
|
222
|
-
});
|
|
223
|
-
var childElement = child;
|
|
224
|
-
var isSelectedOption = selectedOptions.find(function (option) {
|
|
225
|
-
var _childElement$props;
|
|
226
|
-
return option.value === ((_childElement$props = childElement.props) === null || _childElement$props === void 0 ? void 0 : _childElement$props.value);
|
|
227
|
-
});
|
|
228
|
-
var className = (0, _classnames.default)('select-item', {
|
|
229
|
-
selected: isSelectedOption
|
|
230
|
-
});
|
|
231
|
-
return /*#__PURE__*/(0, _react.cloneElement)(childElement, {
|
|
232
|
-
onClick: function onClick(event) {
|
|
233
|
-
if (event.currentTarget.classList.contains('select-item')) {
|
|
234
|
-
changeMultipleOption(childElement.props.value);
|
|
235
|
-
}
|
|
236
|
-
},
|
|
237
|
-
className: className
|
|
238
|
-
});
|
|
239
|
-
})
|
|
240
|
-
})
|
|
241
|
-
}), !!helperText && /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles2.HelperText, {
|
|
242
|
-
alert: alert,
|
|
243
|
-
children: helperText
|
|
244
|
-
})]
|
|
245
|
-
})
|
|
246
|
-
});
|
|
247
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.NewMultipleSelect=NewMultipleSelect;var _react=require("react"),_classnames=_interopRequireDefault(require("classnames")),_Flex=_interopRequireDefault(require("../../Flex")),_Icon=_interopRequireDefault(require("../../Icon")),_ReactPortal=require("../../ReactPortal"),_styles=require("../components/OptionsSelect/styles"),_useReposition=require("../../../shared/hooks/useReposition"),_useOnClickOutside=require("../../../shared/hooks/useOnClickOutside"),_styles2=require("../styles"),_SelectItem=require("../components/SelectItem"),_jsxRuntime=require("react/jsx-runtime"),_excluded=["label","placeholder","alert","helperText","variant","children","value","onClose","onOpen","renderOptions","onChange"];function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _toConsumableArray(arr){return _arrayWithoutHoles(arr)||_iterableToArray(arr)||_unsupportedIterableToArray(arr)||_nonIterableSpread()}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.")}function _iterableToArray(iter){if("undefined"!=typeof Symbol&&null!=iter[Symbol.iterator]||null!=iter["@@iterator"])return Array.from(iter)}function _arrayWithoutHoles(arr){if(Array.isArray(arr))return _arrayLikeToArray(arr)}function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_unsupportedIterableToArray(arr,i)||_nonIterableRest()}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.")}function _unsupportedIterableToArray(o,minLen){if(o){if("string"==typeof o)return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);return"Object"===n&&o.constructor&&(n=o.constructor.name),"Map"===n||"Set"===n?Array.from(o):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_arrayLikeToArray(o,minLen):void 0}}function _arrayLikeToArray(arr,len){(null==len||len>arr.length)&&(len=arr.length);for(var i=0,arr2=Array(len);i<len;i++)arr2[i]=arr[i];return arr2}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}}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr}function _objectWithoutProperties(source,excluded){if(null==source)return{};var key,i,target=_objectWithoutPropertiesLoose(source,excluded);if(Object.getOwnPropertySymbols){var sourceSymbolKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceSymbolKeys.length;i++)key=sourceSymbolKeys[i],0<=excluded.indexOf(key)||Object.prototype.propertyIsEnumerable.call(source,key)&&(target[key]=source[key])}return target}function _objectWithoutPropertiesLoose(source,excluded){if(null==source)return{};var key,i,target={},sourceKeys=Object.keys(source);for(i=0;i<sourceKeys.length;i++)key=sourceKeys[i],0<=excluded.indexOf(key)||(target[key]=source[key]);return target}function NewMultipleSelect(_ref){function changeMultipleOption(valueOption){if(void 0===valueOption)return setSelectedOptions([]),void setIsOpenOptions(!1);var findOption=selectedOptions.find(function(option){return option.value===valueOption});if(findOption)removeOption(valueOption);else{var newOption=options.find(function(option){return option.value===valueOption});newOption&&setSelectedOptions([].concat(_toConsumableArray(selectedOptions),[newOption])),null===onChange||void 0===onChange?void 0:onChange([].concat(_toConsumableArray(multipleSelectValues),[valueOption]))}}function removeOption(optionToRemove){var newSelectedOptions=null===selectedOptions||void 0===selectedOptions?void 0:selectedOptions.filter(function(option){return option.value!==optionToRemove}),newSelectedValues=newSelectedOptions.map(function(option){return option.value});setSelectedOptions(newSelectedOptions),null===onChange||void 0===onChange?void 0:onChange(newSelectedValues)}var _containerRef$current,_ref$label=_ref.label,label=void 0===_ref$label?"":_ref$label,_ref$placeholder=_ref.placeholder,placeholder=void 0===_ref$placeholder?"":_ref$placeholder,alert=_ref.alert,helperText=_ref.helperText,variant=_ref.variant,children=_ref.children,value=_ref.value,onClose=_ref.onClose,onOpen=_ref.onOpen,renderOptions=_ref.renderOptions,onChange=_ref.onChange,rest=_objectWithoutProperties(_ref,_excluded),containerRef=(0,_react.useRef)(null),selectRef=(0,_react.useRef)(null),_useState=(0,_react.useState)(!1),_useState2=_slicedToArray(_useState,2),isOpenOptions=_useState2[0],setIsOpenOptions=_useState2[1],_useState3=(0,_react.useState)([]),_useState4=_slicedToArray(_useState3,2),selectedOptions=_useState4[0],setSelectedOptions=_useState4[1],multipleSelectValues=selectedOptions.map(function(option){return option.value}),optionsModalRef=(0,_react.useRef)(null),_useState5=(0,_react.useState)([]),_useState6=_slicedToArray(_useState5,2),options=_useState6[0],setOptions=_useState6[1];(0,_react.useEffect)(function(){var _optionsModalRef$curr,childs=null===(_optionsModalRef$curr=optionsModalRef.current)||void 0===_optionsModalRef$curr?void 0:_optionsModalRef$curr.childNodes,newOptions=[];_react.Children.forEach(children,function(child,index){var _childs$index,_childs$index$classLi;if(null!==childs&&void 0!==childs&&null!==(_childs$index=childs[index])&&void 0!==_childs$index&&null!==(_childs$index$classLi=_childs$index.classList)&&void 0!==_childs$index$classLi&&_childs$index$classLi.contains("select-item")){var _child$props,_childs$index2;newOptions.push({value:null===child||void 0===child||null===(_child$props=child.props)||void 0===_child$props?void 0:_child$props.value,label:null===childs||void 0===childs||null===(_childs$index2=childs[index])||void 0===_childs$index2?void 0:_childs$index2.innerText})}}),setOptions(newOptions)},[children,optionsModalRef.current]),(0,_react.useEffect)(function(){function handler(){setIsOpenOptions(!1)}if(isOpenOptions){var _document;null===onOpen||void 0===onOpen?void 0:onOpen(),null===(_document=document)||void 0===_document?void 0:_document.addEventListener("scroll",handler)}else{var _document2;null===onClose||void 0===onClose?void 0:onClose(),null===(_document2=document)||void 0===_document2?void 0:_document2.removeEventListener("scroll",handler)}return function(){var _document3;return null===(_document3=document)||void 0===_document3?void 0:_document3.removeEventListener("scroll",handler)}},[isOpenOptions]),(0,_useOnClickOutside.useOnClickOutside)([containerRef,optionsModalRef],function(){isOpenOptions&&setIsOpenOptions(!1)});var positionsSelect=(0,_useReposition.useReposition)({containerRef:optionsModalRef,triggerRef:selectRef},[children]),SelectedOptionsWithCustomComponent=function(_ref2){var option=_ref2.option;return/*#__PURE__*/(0,_jsxRuntime.jsx)(_jsxRuntime.Fragment,{children:null===renderOptions||void 0===renderOptions?void 0:renderOptions(option,function(){return removeOption(option.value)})})};return(0,_react.useEffect)(function(){var newOptions=options.filter(function(option){return null===value||void 0===value?void 0:value.includes(option.value)}),newSelectedOptions=selectedOptions.filter(function(selectedOption){return newOptions.every(function(newOption){return newOption.value!==selectedOption.value})});setSelectedOptions([].concat(_toConsumableArray(newSelectedOptions),_toConsumableArray(newOptions)))},[value,options]),/*#__PURE__*/(0,_jsxRuntime.jsx)("div",{ref:selectRef,style:{width:"100%"},children:/*#__PURE__*/(0,_jsxRuntime.jsxs)(_Flex.default,{direction:"column",style:{width:"100%"},children:[/*#__PURE__*/(0,_jsxRuntime.jsxs)(_styles2.SelectContainer,{"data-disabled":rest.disabled,"data-variant":variant,"data-label-in-top":!!(null!==selectedOptions&&void 0!==selectedOptions&&selectedOptions[0])||!!placeholder,alert:alert,tabIndex:rest.disabled?-1:0,onClick:function onClick(){return setIsOpenOptions(!isOpenOptions)},className:rest.className,style:rest.style,ref:containerRef,children:[label&&"unstyled"!==variant&&/*#__PURE__*/(0,_jsxRuntime.jsx)("label",{title:label,children:label}),/*#__PURE__*/(0,_jsxRuntime.jsx)(_Flex.default,{spacing:"0.5rem",wrap:"wrap",style:{paddingBlock:"0.5rem"},children:null!==selectedOptions&&void 0!==selectedOptions&&selectedOptions[0]?selectedOptions.map(function(option,index){return"function"==typeof renderOptions?/*#__PURE__*/(0,_jsxRuntime.jsx)(SelectedOptionsWithCustomComponent,{option:option},"custom-option-selected-".concat(index)):/*#__PURE__*/(0,_jsxRuntime.jsxs)(_styles2.SelectedOptionSpan,{hasSelectedOption:!0,children:[option.label,1<selectedOptions.length&&index<selectedOptions.length-1&&","]},index)}):/*#__PURE__*/(0,_jsxRuntime.jsx)(_styles2.SelectedOptionSpan,{title:"placeholder",children:placeholder})}),/*#__PURE__*/(0,_jsxRuntime.jsx)(_Flex.default,{className:"select_container_icon",children:/*#__PURE__*/(0,_jsxRuntime.jsx)(_Icon.default,{name:"chevron-down"})})]}),/*#__PURE__*/(0,_jsxRuntime.jsx)(_ReactPortal.ReactPortal,{wrapperId:"portal-root",children:/*#__PURE__*/(0,_jsxRuntime.jsx)(_styles.OptionsContainer,{ref:optionsModalRef,open:isOpenOptions,style:{maxWidth:"".concat(null===(_containerRef$current=containerRef.current)||void 0===_containerRef$current?void 0:_containerRef$current.getBoundingClientRect().width,"px"),left:positionsSelect.left,top:positionsSelect.top},children:_react.Children.map(children,function(child){var isSelectItemElement=(null===child||void 0===child?void 0:child.type)===_SelectItem.SelectItem;if(!/*#__PURE__*/(0,_react.isValidElement)(child)||!isSelectItemElement)return/*#__PURE__*/(0,_jsxRuntime.jsx)("div",{children:child});var childElement=child,isSelectedOption=selectedOptions.find(function(option){var _childElement$props;return option.value===(null===(_childElement$props=childElement.props)||void 0===_childElement$props?void 0:_childElement$props.value)}),className=(0,_classnames.default)("select-item",{selected:isSelectedOption});return/*#__PURE__*/(0,_react.cloneElement)(childElement,{onClick:function onClick(event){event.currentTarget.classList.contains("select-item")&&changeMultipleOption(childElement.props.value)},className:className})})})}),!!helperText&&/*#__PURE__*/(0,_jsxRuntime.jsx)(_styles2.HelperText,{alert:alert,children:helperText})]})})}
|
|
@@ -1,108 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _react = require("@testing-library/react");
|
|
4
|
-
var _ = require(".");
|
|
5
|
-
var _SelectItem = require("./components/SelectItem");
|
|
6
|
-
var _testUtils = require("../../shared/tests/test-utils");
|
|
7
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
|
-
var optionsSelect = [{
|
|
9
|
-
label: 'Opção 1',
|
|
10
|
-
value: 'option1'
|
|
11
|
-
}, {
|
|
12
|
-
label: 'Opção 2',
|
|
13
|
-
value: 'option2'
|
|
14
|
-
}];
|
|
15
|
-
describe('Select', function () {
|
|
16
|
-
test('Change option', function () {
|
|
17
|
-
var handleClick = jest.fn();
|
|
18
|
-
var _render = (0, _testUtils.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_.NewSelect, {
|
|
19
|
-
value: "option1",
|
|
20
|
-
onChange: handleClick,
|
|
21
|
-
children: optionsSelect.map(function (option) {
|
|
22
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_SelectItem.SelectItem, {
|
|
23
|
-
value: option.value,
|
|
24
|
-
children: option.label
|
|
25
|
-
}, option.value);
|
|
26
|
-
})
|
|
27
|
-
})),
|
|
28
|
-
getByRole = _render.getByRole,
|
|
29
|
-
getByTestId = _render.getByTestId;
|
|
30
|
-
var button = getByRole('button', {
|
|
31
|
-
name: /opção 1/i
|
|
32
|
-
});
|
|
33
|
-
_react.fireEvent.click(button);
|
|
34
|
-
var spanOfSelectedOption = getByTestId('span-selected-option');
|
|
35
|
-
var textOfSpan = spanOfSelectedOption.textContent;
|
|
36
|
-
expect(textOfSpan).toEqual('Opção 1');
|
|
37
|
-
expect(handleClick).toHaveBeenCalledTimes(1);
|
|
38
|
-
});
|
|
39
|
-
test('Default value', function () {
|
|
40
|
-
var handleClick = jest.fn();
|
|
41
|
-
var _render2 = (0, _testUtils.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_.NewSelect, {
|
|
42
|
-
value: "option1",
|
|
43
|
-
onChange: handleClick,
|
|
44
|
-
children: optionsSelect.map(function (option) {
|
|
45
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_SelectItem.SelectItem, {
|
|
46
|
-
value: option.value,
|
|
47
|
-
children: option.label
|
|
48
|
-
}, option.value);
|
|
49
|
-
})
|
|
50
|
-
})),
|
|
51
|
-
getByTestId = _render2.getByTestId;
|
|
52
|
-
var spanOfSelectedOption = getByTestId('span-selected-option');
|
|
53
|
-
var textOfSpan = spanOfSelectedOption.textContent;
|
|
54
|
-
expect(textOfSpan).toEqual('Opção 1');
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
describe('MultipleSelect', function () {
|
|
58
|
-
test('Change option ', function () {
|
|
59
|
-
var _containerOfMultipleO;
|
|
60
|
-
var handleClick = jest.fn();
|
|
61
|
-
var _render3 = (0, _testUtils.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_.NewSelect, {
|
|
62
|
-
value: ['option1'],
|
|
63
|
-
multiple: true,
|
|
64
|
-
onChange: handleClick,
|
|
65
|
-
children: optionsSelect.map(function (option) {
|
|
66
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_SelectItem.SelectItem, {
|
|
67
|
-
value: option.value,
|
|
68
|
-
children: option.label
|
|
69
|
-
}, option.value);
|
|
70
|
-
})
|
|
71
|
-
})),
|
|
72
|
-
getByTestId = _render3.getByTestId,
|
|
73
|
-
getByRole = _render3.getByRole;
|
|
74
|
-
var buttonFirstOption = getByRole('button', {
|
|
75
|
-
name: /opção 1/i
|
|
76
|
-
});
|
|
77
|
-
var buttonSecondOption = getByRole('button', {
|
|
78
|
-
name: /opção 2/i
|
|
79
|
-
});
|
|
80
|
-
_react.fireEvent.click(buttonSecondOption);
|
|
81
|
-
expect(handleClick).toBeCalled();
|
|
82
|
-
_react.fireEvent.click(buttonFirstOption);
|
|
83
|
-
expect(handleClick).toBeCalled();
|
|
84
|
-
var containerOfMultipleOptions = getByTestId('container-multiple-options');
|
|
85
|
-
var firstOptionText = (_containerOfMultipleO = containerOfMultipleOptions.children[0]) === null || _containerOfMultipleO === void 0 ? void 0 : _containerOfMultipleO.textContent;
|
|
86
|
-
expect(firstOptionText).toEqual('Opção 1');
|
|
87
|
-
});
|
|
88
|
-
test('default value', function () {
|
|
89
|
-
var handleClick = jest.fn();
|
|
90
|
-
var _render4 = (0, _testUtils.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_.NewSelect, {
|
|
91
|
-
value: ['option1', 'option2'],
|
|
92
|
-
multiple: true,
|
|
93
|
-
onChange: handleClick,
|
|
94
|
-
children: optionsSelect.map(function (option) {
|
|
95
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_SelectItem.SelectItem, {
|
|
96
|
-
value: option.value,
|
|
97
|
-
children: option.label
|
|
98
|
-
}, option.value);
|
|
99
|
-
})
|
|
100
|
-
})),
|
|
101
|
-
getByTestId = _render4.getByTestId;
|
|
102
|
-
var containerOfMultipleOptions = getByTestId('container-multiple-options');
|
|
103
|
-
var firstOptionText = containerOfMultipleOptions.children[0].textContent;
|
|
104
|
-
var secondOptionText = containerOfMultipleOptions.children[1].textContent;
|
|
105
|
-
expect(firstOptionText).toEqual('Opção 1,');
|
|
106
|
-
expect(secondOptionText).toEqual('Opção 2');
|
|
107
|
-
});
|
|
108
|
-
});
|
|
1
|
+
"use strict";var _react=require("@testing-library/react"),_=require("."),_SelectItem=require("./components/SelectItem"),_testUtils=require("../../shared/tests/test-utils"),_jsxRuntime=require("react/jsx-runtime"),optionsSelect=[{label:"Op\xE7\xE3o 1",value:"option1"},{label:"Op\xE7\xE3o 2",value:"option2"}];describe("Select",function(){test("Change option",function(){var handleClick=jest.fn(),_render=(0,_testUtils.render)(/*#__PURE__*/(0,_jsxRuntime.jsx)(_.NewSelect,{value:"option1",onChange:handleClick,children:optionsSelect.map(function(option){return/*#__PURE__*/(0,_jsxRuntime.jsx)(_SelectItem.SelectItem,{value:option.value,children:option.label},option.value)})})),getByRole=_render.getByRole,getByTestId=_render.getByTestId,button=getByRole("button",{name:/opção 1/i});_react.fireEvent.click(button);var spanOfSelectedOption=getByTestId("span-selected-option"),textOfSpan=spanOfSelectedOption.textContent;expect(textOfSpan).toEqual("Op\xE7\xE3o 1"),expect(handleClick).toHaveBeenCalledTimes(1)}),test("Default value",function(){var handleClick=jest.fn(),_render2=(0,_testUtils.render)(/*#__PURE__*/(0,_jsxRuntime.jsx)(_.NewSelect,{value:"option1",onChange:handleClick,children:optionsSelect.map(function(option){return/*#__PURE__*/(0,_jsxRuntime.jsx)(_SelectItem.SelectItem,{value:option.value,children:option.label},option.value)})})),getByTestId=_render2.getByTestId,spanOfSelectedOption=getByTestId("span-selected-option"),textOfSpan=spanOfSelectedOption.textContent;expect(textOfSpan).toEqual("Op\xE7\xE3o 1")})}),describe("MultipleSelect",function(){test("Change option ",function(){var _containerOfMultipleO,handleClick=jest.fn(),_render3=(0,_testUtils.render)(/*#__PURE__*/(0,_jsxRuntime.jsx)(_.NewSelect,{value:["option1"],multiple:!0,onChange:handleClick,children:optionsSelect.map(function(option){return/*#__PURE__*/(0,_jsxRuntime.jsx)(_SelectItem.SelectItem,{value:option.value,children:option.label},option.value)})})),getByTestId=_render3.getByTestId,getByRole=_render3.getByRole,buttonFirstOption=getByRole("button",{name:/opção 1/i}),buttonSecondOption=getByRole("button",{name:/opção 2/i});_react.fireEvent.click(buttonSecondOption),expect(handleClick).toBeCalled(),_react.fireEvent.click(buttonFirstOption),expect(handleClick).toBeCalled();var containerOfMultipleOptions=getByTestId("container-multiple-options"),firstOptionText=null===(_containerOfMultipleO=containerOfMultipleOptions.children[0])||void 0===_containerOfMultipleO?void 0:_containerOfMultipleO.textContent;expect(firstOptionText).toEqual("Op\xE7\xE3o 1")}),test("default value",function(){var handleClick=jest.fn(),_render4=(0,_testUtils.render)(/*#__PURE__*/(0,_jsxRuntime.jsx)(_.NewSelect,{value:["option1","option2"],multiple:!0,onChange:handleClick,children:optionsSelect.map(function(option){return/*#__PURE__*/(0,_jsxRuntime.jsx)(_SelectItem.SelectItem,{value:option.value,children:option.label},option.value)})})),getByTestId=_render4.getByTestId,containerOfMultipleOptions=getByTestId("container-multiple-options"),firstOptionText=containerOfMultipleOptions.children[0].textContent,secondOptionText=containerOfMultipleOptions.children[1].textContent;expect(firstOptionText).toEqual("Op\xE7\xE3o 1,"),expect(secondOptionText).toEqual("Op\xE7\xE3o 2")})});
|
|
@@ -1,183 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.NewSingleSelect = NewSingleSelect;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var _Flex = _interopRequireDefault(require("../../Flex"));
|
|
9
|
-
var _Icon = _interopRequireDefault(require("../../Icon"));
|
|
10
|
-
var _ReactPortal = require("../../ReactPortal");
|
|
11
|
-
var _SelectItem = require("../components/SelectItem");
|
|
12
|
-
var _useReposition = require("../../../shared/hooks/useReposition");
|
|
13
|
-
var _useOnClickOutside = require("../../../shared/hooks/useOnClickOutside");
|
|
14
|
-
var _styles = require("../components/OptionsSelect/styles");
|
|
15
|
-
var _styles2 = require("../styles");
|
|
16
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
17
|
-
var _excluded = ["label", "placeholder", "alert", "helperText", "variant", "children", "value", "onClose", "onOpen", "onChange", "renderOptions"];
|
|
18
|
-
/* eslint-disable no-console */
|
|
19
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
21
|
-
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."); }
|
|
22
|
-
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); }
|
|
23
|
-
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; }
|
|
24
|
-
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; } }
|
|
25
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
26
|
-
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; }
|
|
27
|
-
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; }
|
|
28
|
-
function NewSingleSelect(_ref) {
|
|
29
|
-
var _containerRef$current;
|
|
30
|
-
var _ref$label = _ref.label,
|
|
31
|
-
label = _ref$label === void 0 ? '' : _ref$label,
|
|
32
|
-
_ref$placeholder = _ref.placeholder,
|
|
33
|
-
placeholder = _ref$placeholder === void 0 ? '' : _ref$placeholder,
|
|
34
|
-
alert = _ref.alert,
|
|
35
|
-
helperText = _ref.helperText,
|
|
36
|
-
variant = _ref.variant,
|
|
37
|
-
children = _ref.children,
|
|
38
|
-
value = _ref.value,
|
|
39
|
-
onClose = _ref.onClose,
|
|
40
|
-
onOpen = _ref.onOpen,
|
|
41
|
-
onChange = _ref.onChange,
|
|
42
|
-
renderOptions = _ref.renderOptions,
|
|
43
|
-
rest = _objectWithoutProperties(_ref, _excluded);
|
|
44
|
-
var containerRef = (0, _react.useRef)(null);
|
|
45
|
-
var selectRef = (0, _react.useRef)(null);
|
|
46
|
-
var _useState = (0, _react.useState)(false),
|
|
47
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
48
|
-
isOpenOptions = _useState2[0],
|
|
49
|
-
setIsOpenOptions = _useState2[1];
|
|
50
|
-
var _useState3 = (0, _react.useState)(),
|
|
51
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
52
|
-
selectedOption = _useState4[0],
|
|
53
|
-
setSelectedOption = _useState4[1];
|
|
54
|
-
var optionsModalRef = (0, _react.useRef)(null);
|
|
55
|
-
var _useState5 = (0, _react.useState)([]),
|
|
56
|
-
_useState6 = _slicedToArray(_useState5, 2),
|
|
57
|
-
options = _useState6[0],
|
|
58
|
-
setOptions = _useState6[1];
|
|
59
|
-
var findOption = options.find(function (option) {
|
|
60
|
-
return option.value === selectedOption;
|
|
61
|
-
});
|
|
62
|
-
var isFalseOptions = (findOption === null || findOption === void 0 ? void 0 : findOption.value) === false;
|
|
63
|
-
var textPlaceholder = findOption !== null && findOption !== void 0 && findOption.value || isFalseOptions ? findOption === null || findOption === void 0 ? void 0 : findOption.label : placeholder;
|
|
64
|
-
(0, _react.useEffect)(function () {
|
|
65
|
-
var _options$, _optionsModalRef$curr;
|
|
66
|
-
if (options !== null && options !== void 0 && (_options$ = options[0]) !== null && _options$ !== void 0 && _options$.value) return;
|
|
67
|
-
var childs = (_optionsModalRef$curr = optionsModalRef.current) === null || _optionsModalRef$curr === void 0 ? void 0 : _optionsModalRef$curr.childNodes;
|
|
68
|
-
var newOptions = [];
|
|
69
|
-
_react.Children.forEach(children, function (child, index) {
|
|
70
|
-
var _childs$index, _childs$index$classLi;
|
|
71
|
-
if (childs !== null && childs !== void 0 && (_childs$index = childs[index]) !== null && _childs$index !== void 0 && (_childs$index$classLi = _childs$index.classList) !== null && _childs$index$classLi !== void 0 && _childs$index$classLi.contains('select-item')) {
|
|
72
|
-
var _child$props, _childs$index2;
|
|
73
|
-
newOptions.push({
|
|
74
|
-
value: child === null || child === void 0 ? void 0 : (_child$props = child.props) === null || _child$props === void 0 ? void 0 : _child$props.value,
|
|
75
|
-
label: childs === null || childs === void 0 ? void 0 : (_childs$index2 = childs[index]) === null || _childs$index2 === void 0 ? void 0 : _childs$index2.innerText
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
setOptions(newOptions);
|
|
80
|
-
}, [children, optionsModalRef.current, containerRef.current]);
|
|
81
|
-
(0, _react.useEffect)(function () {
|
|
82
|
-
function handler() {
|
|
83
|
-
setIsOpenOptions(false);
|
|
84
|
-
}
|
|
85
|
-
if (isOpenOptions) {
|
|
86
|
-
var _document;
|
|
87
|
-
onOpen === null || onOpen === void 0 ? void 0 : onOpen();
|
|
88
|
-
(_document = document) === null || _document === void 0 ? void 0 : _document.addEventListener('scroll', handler);
|
|
89
|
-
} else {
|
|
90
|
-
var _document2;
|
|
91
|
-
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
92
|
-
(_document2 = document) === null || _document2 === void 0 ? void 0 : _document2.removeEventListener('scroll', handler);
|
|
93
|
-
}
|
|
94
|
-
return function () {
|
|
95
|
-
var _document3;
|
|
96
|
-
return (_document3 = document) === null || _document3 === void 0 ? void 0 : _document3.removeEventListener('scroll', handler);
|
|
97
|
-
};
|
|
98
|
-
}, [isOpenOptions]);
|
|
99
|
-
(0, _useOnClickOutside.useOnClickOutside)([containerRef, optionsModalRef], function () {
|
|
100
|
-
if (isOpenOptions) {
|
|
101
|
-
setIsOpenOptions(false);
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
var positionsSelect = (0, _useReposition.useReposition)({
|
|
105
|
-
containerRef: optionsModalRef,
|
|
106
|
-
triggerRef: selectRef
|
|
107
|
-
}, [children]);
|
|
108
|
-
var SelectedOptionsWithCustomComponent = function SelectedOptionsWithCustomComponent() {
|
|
109
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
|
|
110
|
-
children: renderOptions === null || renderOptions === void 0 ? void 0 : renderOptions(selectedOption)
|
|
111
|
-
});
|
|
112
|
-
};
|
|
113
|
-
(0, _react.useEffect)(function () {
|
|
114
|
-
setSelectedOption(value);
|
|
115
|
-
}, [value]);
|
|
116
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
117
|
-
ref: selectRef,
|
|
118
|
-
style: {
|
|
119
|
-
width: '100%'
|
|
120
|
-
},
|
|
121
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Flex.default, {
|
|
122
|
-
direction: "column",
|
|
123
|
-
style: {
|
|
124
|
-
width: '100%'
|
|
125
|
-
},
|
|
126
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles2.SelectContainer, {
|
|
127
|
-
"data-disabled": rest.disabled,
|
|
128
|
-
"data-variant": variant,
|
|
129
|
-
"data-label-in-top": !!textPlaceholder || !!placeholder,
|
|
130
|
-
alert: alert,
|
|
131
|
-
tabIndex: rest.disabled ? -1 : 0,
|
|
132
|
-
onClick: function onClick() {
|
|
133
|
-
return setIsOpenOptions(!isOpenOptions);
|
|
134
|
-
},
|
|
135
|
-
className: rest.className,
|
|
136
|
-
style: rest.style,
|
|
137
|
-
ref: containerRef,
|
|
138
|
-
children: [label && variant !== 'unstyled' && /*#__PURE__*/(0, _jsxRuntime.jsx)("label", {
|
|
139
|
-
children: label
|
|
140
|
-
}), typeof renderOptions === 'function' && selectedOption ? /*#__PURE__*/(0, _jsxRuntime.jsx)(SelectedOptionsWithCustomComponent, {}, "custom-option-selected-".concat(textPlaceholder)) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles2.SelectedOptionSpan, {
|
|
141
|
-
hasSelectedOption: !!selectedOption || isFalseOptions,
|
|
142
|
-
children: textPlaceholder
|
|
143
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Flex.default, {
|
|
144
|
-
className: "select_container_icon",
|
|
145
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.default, {
|
|
146
|
-
name: "chevron-down",
|
|
147
|
-
color: "neutral.neutral5"
|
|
148
|
-
})
|
|
149
|
-
})]
|
|
150
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ReactPortal.ReactPortal, {
|
|
151
|
-
wrapperId: "portal-root",
|
|
152
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.OptionsContainer, {
|
|
153
|
-
ref: optionsModalRef,
|
|
154
|
-
open: isOpenOptions,
|
|
155
|
-
style: {
|
|
156
|
-
maxWidth: "".concat((_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.getBoundingClientRect().width, "px"),
|
|
157
|
-
left: positionsSelect.left,
|
|
158
|
-
top: positionsSelect.top
|
|
159
|
-
},
|
|
160
|
-
children: _react.Children.map(children, function (child) {
|
|
161
|
-
var isSelectItemElement = child.type === _SelectItem.SelectItem;
|
|
162
|
-
if (! /*#__PURE__*/(0, _react.isValidElement)(child) || !isSelectItemElement) return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
|
|
163
|
-
children: child
|
|
164
|
-
});
|
|
165
|
-
var childElement = child;
|
|
166
|
-
return /*#__PURE__*/(0, _react.cloneElement)(childElement, {
|
|
167
|
-
onClick: function onClick(event) {
|
|
168
|
-
if (event.currentTarget.classList.contains('select-item')) {
|
|
169
|
-
setIsOpenOptions(false);
|
|
170
|
-
setSelectedOption(childElement.props.value);
|
|
171
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(childElement.props.value);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
})
|
|
176
|
-
})
|
|
177
|
-
}), !!helperText && /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles2.HelperText, {
|
|
178
|
-
alert: alert,
|
|
179
|
-
children: helperText
|
|
180
|
-
})]
|
|
181
|
-
})
|
|
182
|
-
});
|
|
183
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.NewSingleSelect=NewSingleSelect;var _react=require("react"),_Flex=_interopRequireDefault(require("../../Flex")),_Icon=_interopRequireDefault(require("../../Icon")),_ReactPortal=require("../../ReactPortal"),_SelectItem=require("../components/SelectItem"),_useReposition=require("../../../shared/hooks/useReposition"),_useOnClickOutside=require("../../../shared/hooks/useOnClickOutside"),_styles=require("../components/OptionsSelect/styles"),_styles2=require("../styles"),_jsxRuntime=require("react/jsx-runtime"),_excluded=["label","placeholder","alert","helperText","variant","children","value","onClose","onOpen","onChange","renderOptions"];/* eslint-disable no-console */function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_unsupportedIterableToArray(arr,i)||_nonIterableRest()}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.")}function _unsupportedIterableToArray(o,minLen){if(o){if("string"==typeof o)return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);return"Object"===n&&o.constructor&&(n=o.constructor.name),"Map"===n||"Set"===n?Array.from(o):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_arrayLikeToArray(o,minLen):void 0}}function _arrayLikeToArray(arr,len){(null==len||len>arr.length)&&(len=arr.length);for(var i=0,arr2=Array(len);i<len;i++)arr2[i]=arr[i];return arr2}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}}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr}function _objectWithoutProperties(source,excluded){if(null==source)return{};var key,i,target=_objectWithoutPropertiesLoose(source,excluded);if(Object.getOwnPropertySymbols){var sourceSymbolKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceSymbolKeys.length;i++)key=sourceSymbolKeys[i],0<=excluded.indexOf(key)||Object.prototype.propertyIsEnumerable.call(source,key)&&(target[key]=source[key])}return target}function _objectWithoutPropertiesLoose(source,excluded){if(null==source)return{};var key,i,target={},sourceKeys=Object.keys(source);for(i=0;i<sourceKeys.length;i++)key=sourceKeys[i],0<=excluded.indexOf(key)||(target[key]=source[key]);return target}function NewSingleSelect(_ref){var _containerRef$current,_ref$label=_ref.label,label=void 0===_ref$label?"":_ref$label,_ref$placeholder=_ref.placeholder,placeholder=void 0===_ref$placeholder?"":_ref$placeholder,alert=_ref.alert,helperText=_ref.helperText,variant=_ref.variant,children=_ref.children,value=_ref.value,onClose=_ref.onClose,onOpen=_ref.onOpen,onChange=_ref.onChange,renderOptions=_ref.renderOptions,rest=_objectWithoutProperties(_ref,_excluded),containerRef=(0,_react.useRef)(null),selectRef=(0,_react.useRef)(null),_useState=(0,_react.useState)(!1),_useState2=_slicedToArray(_useState,2),isOpenOptions=_useState2[0],setIsOpenOptions=_useState2[1],_useState3=(0,_react.useState)(),_useState4=_slicedToArray(_useState3,2),selectedOption=_useState4[0],setSelectedOption=_useState4[1],optionsModalRef=(0,_react.useRef)(null),_useState5=(0,_react.useState)([]),_useState6=_slicedToArray(_useState5,2),options=_useState6[0],setOptions=_useState6[1],findOption=options.find(function(option){return option.value===selectedOption}),isFalseOptions=!1===(null===findOption||void 0===findOption?void 0:findOption.value),textPlaceholder=null!==findOption&&void 0!==findOption&&findOption.value||isFalseOptions?null===findOption||void 0===findOption?void 0:findOption.label:placeholder;(0,_react.useEffect)(function(){var _options$,_optionsModalRef$curr;if(!(null!==options&&void 0!==options&&null!==(_options$=options[0])&&void 0!==_options$&&_options$.value)){var childs=null===(_optionsModalRef$curr=optionsModalRef.current)||void 0===_optionsModalRef$curr?void 0:_optionsModalRef$curr.childNodes,newOptions=[];_react.Children.forEach(children,function(child,index){var _childs$index,_childs$index$classLi;if(null!==childs&&void 0!==childs&&null!==(_childs$index=childs[index])&&void 0!==_childs$index&&null!==(_childs$index$classLi=_childs$index.classList)&&void 0!==_childs$index$classLi&&_childs$index$classLi.contains("select-item")){var _child$props,_childs$index2;newOptions.push({value:null===child||void 0===child||null===(_child$props=child.props)||void 0===_child$props?void 0:_child$props.value,label:null===childs||void 0===childs||null===(_childs$index2=childs[index])||void 0===_childs$index2?void 0:_childs$index2.innerText})}}),setOptions(newOptions)}},[children,optionsModalRef.current,containerRef.current]),(0,_react.useEffect)(function(){function handler(){setIsOpenOptions(!1)}if(isOpenOptions){var _document;null===onOpen||void 0===onOpen?void 0:onOpen(),null===(_document=document)||void 0===_document?void 0:_document.addEventListener("scroll",handler)}else{var _document2;null===onClose||void 0===onClose?void 0:onClose(),null===(_document2=document)||void 0===_document2?void 0:_document2.removeEventListener("scroll",handler)}return function(){var _document3;return null===(_document3=document)||void 0===_document3?void 0:_document3.removeEventListener("scroll",handler)}},[isOpenOptions]),(0,_useOnClickOutside.useOnClickOutside)([containerRef,optionsModalRef],function(){isOpenOptions&&setIsOpenOptions(!1)});var positionsSelect=(0,_useReposition.useReposition)({containerRef:optionsModalRef,triggerRef:selectRef},[children]);return(0,_react.useEffect)(function(){setSelectedOption(value)},[value]),/*#__PURE__*/(0,_jsxRuntime.jsx)("div",{ref:selectRef,style:{width:"100%"},children:/*#__PURE__*/(0,_jsxRuntime.jsxs)(_Flex.default,{direction:"column",style:{width:"100%"},children:[/*#__PURE__*/(0,_jsxRuntime.jsxs)(_styles2.SelectContainer,{"data-disabled":rest.disabled,"data-variant":variant,"data-label-in-top":!!textPlaceholder||!!placeholder,alert:alert,tabIndex:rest.disabled?-1:0,onClick:function onClick(){return setIsOpenOptions(!isOpenOptions)},className:rest.className,style:rest.style,ref:containerRef,children:[label&&"unstyled"!==variant&&/*#__PURE__*/(0,_jsxRuntime.jsx)("label",{children:label}),"function"==typeof renderOptions&&selectedOption?/*#__PURE__*/(0,_jsxRuntime.jsx)(function SelectedOptionsWithCustomComponent(){return/*#__PURE__*/(0,_jsxRuntime.jsx)(_jsxRuntime.Fragment,{children:null===renderOptions||void 0===renderOptions?void 0:renderOptions(selectedOption)})},{},"custom-option-selected-".concat(textPlaceholder)):/*#__PURE__*/(0,_jsxRuntime.jsx)(_styles2.SelectedOptionSpan,{hasSelectedOption:!!selectedOption||isFalseOptions,children:textPlaceholder}),/*#__PURE__*/(0,_jsxRuntime.jsx)(_Flex.default,{className:"select_container_icon",children:/*#__PURE__*/(0,_jsxRuntime.jsx)(_Icon.default,{name:"chevron-down",color:"neutral.neutral5"})})]}),/*#__PURE__*/(0,_jsxRuntime.jsx)(_ReactPortal.ReactPortal,{wrapperId:"portal-root",children:/*#__PURE__*/(0,_jsxRuntime.jsx)(_styles.OptionsContainer,{ref:optionsModalRef,open:isOpenOptions,style:{maxWidth:"".concat(null===(_containerRef$current=containerRef.current)||void 0===_containerRef$current?void 0:_containerRef$current.getBoundingClientRect().width,"px"),left:positionsSelect.left,top:positionsSelect.top},children:_react.Children.map(children,function(child){var isSelectItemElement=(null===child||void 0===child?void 0:child.type)===_SelectItem.SelectItem;if(!/*#__PURE__*/(0,_react.isValidElement)(child)||!isSelectItemElement)return/*#__PURE__*/(0,_jsxRuntime.jsx)(_jsxRuntime.Fragment,{children:child});var childElement=child;return/*#__PURE__*/(0,_react.cloneElement)(childElement,{onClick:function onClick(event){event.currentTarget.classList.contains("select-item")&&(setIsOpenOptions(!1),setSelectedOption(childElement.props.value),null===onChange||void 0===onChange?void 0:onChange(childElement.props.value))}})})})}),!!helperText&&/*#__PURE__*/(0,_jsxRuntime.jsx)(_styles2.HelperText,{alert:alert,children:helperText})]})})}
|