@cashub/ui-elv 1.0.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/Tab/Tab.js +28 -0
- package/Tab/TabList.js +167 -0
- package/Tab/TabPanel.js +49 -0
- package/Tab/TabTab.js +105 -0
- package/Tab/index.js +30 -0
- package/Tab/subComponent/TabContext.js +9 -0
- package/Tab/subComponent/TabListV2.js +25 -0
- package/Tab/subComponent/TabPanelV2.js +52 -0
- package/Tab/subComponent/TabTabV2.js +63 -0
- package/VerticalTab/TabList.js +27 -0
- package/VerticalTab/TabPanel.js +52 -0
- package/VerticalTab/TabTab.js +70 -0
- package/VerticalTab/VerticalTab.js +41 -0
- package/VerticalTab/index.js +16 -0
- package/VerticalTab/subComponent/TabContext.js +9 -0
- package/alert/Alert.js +29 -0
- package/alert/index.js +13 -0
- package/animate/Collapse.js +71 -0
- package/animate/Loader.js +58 -0
- package/animate/NumberCounter.js +51 -0
- package/animate/PulseRing.js +35 -0
- package/animate/Spinner.js +18 -0
- package/animate/index.js +41 -0
- package/assets/css/autocomplete.css +16 -0
- package/assets/css/font.css +4 -0
- package/assets/css/global.css +2 -0
- package/assets/font/helvetica/Helvetica.ttf +0 -0
- package/assets/font/nanumGothic/NanumGothic-Bold.ttf +0 -0
- package/assets/font/nanumGothic/NanumGothic-ExtraBold.ttf +0 -0
- package/assets/font/nanumGothic/NanumGothic-Regular.ttf +0 -0
- package/assets/icons/app-management.png +0 -0
- package/assets/icons/burger-black.png +0 -0
- package/assets/icons/burger-white.png +0 -0
- package/assets/icons/burger.png +0 -0
- package/assets/icons/file.svg +1 -0
- package/assets/icons/map_icon1.png +0 -0
- package/assets/icons/map_icon4.png +0 -0
- package/assets/images/bg-aside.png +0 -0
- package/assets/images/bg-chart-circle.png +0 -0
- package/assets/images/bg-chart-triangle.png +0 -0
- package/assets/images/cashub-logo-only.png +0 -0
- package/assets/images/default-user.jpg +0 -0
- package/assets/images/logo-cashub.png +0 -0
- package/assets/images/map.png +0 -0
- package/assets/images/qrcode.png +0 -0
- package/backdrop/BaseBackdrop.js +18 -0
- package/backdrop/LoadingBackdrop.js +17 -0
- package/backdrop/ModalBackdrop.js +15 -0
- package/backdrop/index.js +27 -0
- package/badge/Badge.js +26 -0
- package/badge/BadgeDot.js +18 -0
- package/badge/BadgeFill.js +49 -0
- package/badge/BadgeFillTriangle.js +147 -0
- package/badge/BadgeWithText.js +31 -0
- package/badge/index.js +41 -0
- package/billing/BarChart.js +51 -0
- package/billing/Grid.js +45 -0
- package/billing/Header2.js +25 -0
- package/billing/Header3.js +37 -0
- package/billing/Paragraph.js +33 -0
- package/billing/ParagraphGroup.js +22 -0
- package/billing/ParagraphText.js +26 -0
- package/billing/Section.js +50 -0
- package/billing/SectionBody.js +17 -0
- package/billing/SectionHeader.js +26 -0
- package/billing/__stories__/BarChart.stories.js_bak +46 -0
- package/billing/__stories__/Grid.stories.js_bak +57 -0
- package/billing/__stories__/Header2.stories.js_bak +62 -0
- package/billing/__stories__/Header3.stories.js_bak +69 -0
- package/billing/__stories__/Paragraph.stories.js_bak +84 -0
- package/billing/__stories__/ParagraphGroup.stories.js_bak +68 -0
- package/billing/__stories__/ParagraphText.stories.js_bak +64 -0
- package/billing/__stories__/Section.stories.js_bak +115 -0
- package/billing/__stories__/SectionBody.stories.js_bak +62 -0
- package/billing/__stories__/SectionHeader.stories.js-bak +68 -0
- package/breadcrumb/Breadcrumb.js +78 -0
- package/breadcrumb/index.js +13 -0
- package/button/Button.js +154 -0
- package/button/ButtonGroup.js +61 -0
- package/button/IconButton.js +72 -0
- package/button/ScrollToTopButton.js +54 -0
- package/button/index.js +34 -0
- package/callout/Callout.js +52 -0
- package/callout/index.js +13 -0
- package/chart/BarChart.js +148 -0
- package/chart/DoughnutChart.js +118 -0
- package/chart/LineChart.js +146 -0
- package/chart/SingleBarChart.js +42 -0
- package/chart/index.js +52 -0
- package/chart/utils/centerTextPlugin.js +62 -0
- package/chart/utils/customTooltip.js +94 -0
- package/chart/utils/htmlLegendPlugin.js +89 -0
- package/chart/utils/index.js +27 -0
- package/chart/utils/padEmptyChartBar.js +53 -0
- package/chart/utils/yAxisTopTitlePlugin.js +49 -0
- package/container/FlexContainer.js +40 -0
- package/container/index.js +13 -0
- package/cropper/Cropper.js +54 -0
- package/cropper/CropperModalHandler.js +41 -0
- package/cropper/index.js +20 -0
- package/cropper/subComponent/CropImageModal.js +79 -0
- package/datetimePicker/DatePicker.js +363 -0
- package/datetimePicker/DatePickerV2.js +407 -0
- package/datetimePicker/DatetimePicker.js +240 -0
- package/datetimePicker/DatetimePickerV2.js +395 -0
- package/datetimePicker/DatetimePickerV3.js +279 -0
- package/datetimePicker/TimeInput.js +56 -0
- package/datetimePicker/TimePicker.js +317 -0
- package/datetimePicker/TimePickerStyle.js +64 -0
- package/datetimePicker/TimePickerV2.js +208 -0
- package/datetimePicker/accordion/Month.js +254 -0
- package/datetimePicker/accordion/Year.js +284 -0
- package/datetimePicker/hooks/index.js +27 -0
- package/datetimePicker/hooks/useChangeNumber.js +42 -0
- package/datetimePicker/hooks/useDecrease.js +38 -0
- package/datetimePicker/hooks/useIncrease.js +38 -0
- package/datetimePicker/index.js +69 -0
- package/datetimePicker/provider/constant.js +43 -0
- package/datetimePicker/subComponent/Accordion.js +373 -0
- package/datetimePicker/subComponent/CustomTimeInput.js +47 -0
- package/datetimePicker/subComponent/DateTimePickerContext.js +9 -0
- package/datetimePicker/utils/GMTDate.js +15 -0
- package/datetimePicker/utils/pad.js +13 -0
- package/datetimePicker/utils/toUTC0.js +13 -0
- package/descriptionList/DescriptionDetail.js +28 -0
- package/descriptionList/DescriptionList.js +25 -0
- package/descriptionList/DescriptionTerm.js +14 -0
- package/descriptionList/index.js +27 -0
- package/divider/Divider.js +31 -0
- package/divider/index.js +13 -0
- package/dropdown/Dropdown.js +55 -0
- package/dropdown/DropdownButtonOption.js +43 -0
- package/dropdown/DropdownContent.js +90 -0
- package/dropdown/DropdownDivOption.js +26 -0
- package/dropdown/DropdownItem.js +26 -0
- package/dropdown/DropdownLinkOption.js +24 -0
- package/dropdown/DropdownToggle.js +38 -0
- package/dropdown/index.js +42 -0
- package/dropdown/subComponent/DropdownContext.js +9 -0
- package/dropzone/FileDropzone.js +479 -0
- package/dropzone/ImageDropzone.js +334 -0
- package/dropzone/index.js +20 -0
- package/dropzone/subComponent/Message.js +26 -0
- package/figure/IconFigure.js +42 -0
- package/figure/ImageFigure.js +38 -0
- package/figure/index.js +20 -0
- package/file/HiddenFileInput.js +15 -0
- package/file/index.js +13 -0
- package/form/Checkbox.js +166 -0
- package/form/Fieldset.js +18 -0
- package/form/FormItem.js +22 -0
- package/form/Input.js +66 -0
- package/form/Label.js +61 -0
- package/form/MutedText.js +21 -0
- package/form/PasswordInput.js +47 -0
- package/form/RadioButton.js +103 -0
- package/form/SearchSelect.js +181 -0
- package/form/Searchbox.js +98 -0
- package/form/Slider.js +46 -0
- package/form/SwitchButton.js +105 -0
- package/form/Textarea.js +41 -0
- package/form/TreeView.js +73 -0
- package/form/index.js +104 -0
- package/grid/Column.js +46 -0
- package/grid/Grid.js +35 -0
- package/grid/index.js +20 -0
- package/heading/Heading1.js +21 -0
- package/heading/Heading2.js +28 -0
- package/heading/Heading3.js +49 -0
- package/heading/index.js +27 -0
- package/helmet/Helmet.js +23 -0
- package/helmet/index.js +20 -0
- package/iconbox/ApplicationIconBox.js +81 -0
- package/iconbox/IconBox.js +67 -0
- package/iconbox/IconBoxV2.js +72 -0
- package/iconbox/index.js +27 -0
- package/iconbox/subComponent/IconBoxFigure.js +50 -0
- package/iconbox/subComponent/IconBoxImage.js +42 -0
- package/image/ImageFluid.js +17 -0
- package/image/UploadImage.js +250 -0
- package/image/index.js +20 -0
- package/index.js +568 -0
- package/jsoneditor/JsonEditor.js +142 -0
- package/jsoneditor/index.js +13 -0
- package/keyframe/Pulse.js +21 -0
- package/keyframe/Spin.js +13 -0
- package/layout/Aside.js +48 -0
- package/layout/AsideHeader.jsx +27 -0
- package/layout/Backdrop.js +23 -0
- package/layout/Container.js +39 -0
- package/layout/Footer.js +45 -0
- package/layout/Header.jsx +55 -0
- package/layout/Layout.jsx +84 -0
- package/layout/Logo.jsx +17 -0
- package/layout/MenuIcon.jsx +27 -0
- package/layout/Sidebar.jsx +271 -0
- package/layout/index.js +13 -0
- package/link/LinkSpan.js +69 -0
- package/link/index.js +13 -0
- package/map/GoogleMap.js +448 -0
- package/map/GoogleReverseGeolocation.js +200 -0
- package/map/LeafletMap.js +231 -0
- package/map/LeafletReverseGeolocation.js +101 -0
- package/map/index.js +34 -0
- package/map/subComponent/BasicLeafletMap.js +34 -0
- package/map/subComponent/GoogleMapContainer.js +29 -0
- package/map/subComponent/GoogleMapPopup.js +109 -0
- package/map/subComponent/GoogleMapWrapper.js +40 -0
- package/map/subComponent/LeafletDrawControl.js +127 -0
- package/map/subComponent/LeafletMapContainer.js +173 -0
- package/map/subComponent/MapSearchBoxControl.js +54 -0
- package/modal/StateModal.js +178 -0
- package/modal/TitleModal.js +250 -0
- package/modal/index.js +20 -0
- package/package.json +54 -0
- package/page/Disclaimer.js +128 -0
- package/page/index.js +13 -0
- package/paginate/Paginate.js +137 -0
- package/paginate/index.js +13 -0
- package/popover/Popover.js +91 -0
- package/popover/index.js +13 -0
- package/qrcode/QRCode.js +58 -0
- package/qrcode/QRCodeContainter.js +34 -0
- package/qrcode/index.js +20 -0
- package/ribbon/Ribbon.js +42 -0
- package/ribbon/index.js +13 -0
- package/section/Section.js +133 -0
- package/section/SectionBody.js +52 -0
- package/section/SectionHeader.js +70 -0
- package/section/SectionToolbar.js +18 -0
- package/section/SectionToolbarItem.js +17 -0
- package/section/index.js +41 -0
- package/select/InputSelect.js +270 -0
- package/select/Select.js +818 -0
- package/select/index.js +20 -0
- package/select/subComponent/Checkbox.js +48 -0
- package/select/subComponent/Footer.js +13 -0
- package/select/subComponent/ListBox.js +30 -0
- package/select/subComponent/Option.js +45 -0
- package/select/subComponent/OptionGroup.js +23 -0
- package/select/subComponent/Options.js +32 -0
- package/select/subComponent/SearchBox.js +58 -0
- package/select/subComponent/SelectedMultipleCount.js +39 -0
- package/select/subComponent/SelectedMultipleTags.js +54 -0
- package/select/subComponent/SelectedMultipleText.js +70 -0
- package/select/subComponent/SelectedSingle.js +17 -0
- package/styles/GlobalStyle.js +334 -0
- package/styles/config/breakpoint.style.js +13 -0
- package/styles/config/header.style.js +10 -0
- package/styles/config/sidebar.style.js +17 -0
- package/styles/index.js +20 -0
- package/styles/mixin/backgroundColor.js +44 -0
- package/styles/mixin/borderColor.js +37 -0
- package/styles/mixin/color.js +37 -0
- package/styles/mixin/colorOnBackground.js +37 -0
- package/styles/mixin/inputPlaceholder.js +30 -0
- package/styles/mixin/media.js +21 -0
- package/styles/mixin/rounded.js +30 -0
- package/styles/mixin/scrollbar.js +32 -0
- package/styles/theme/dark.theme.js +97 -0
- package/styles/theme/light.theme.js +97 -0
- package/styles/theme/white.theme.js +97 -0
- package/styles/themes.js +16 -0
- package/table/GridTable.js +336 -0
- package/table/ImageBox.js +45 -0
- package/table/InfiniteGridTable.js +403 -0
- package/table/PermissionTable.js +64 -0
- package/table/SimpleGridTable.js +143 -0
- package/table/Table.js +568 -0
- package/table/__mock__/columns.js +70 -0
- package/table/__mock__/data.js +536 -0
- package/table/hooks/index.js +20 -0
- package/table/hooks/useCalculateDataRange.js +28 -0
- package/table/hooks/useGenerateSort.js +39 -0
- package/table/index.js +48 -0
- package/table/subComponent/BaseTableHeadCell.js +62 -0
- package/table/subComponent/GridTableFooter.js +24 -0
- package/table/subComponent/GridTableHeadCell.js +20 -0
- package/table/subComponent/Resizer.js +77 -0
- package/table/subComponent/TableFooter.js +31 -0
- package/table/subComponent/TableFooterInfo.js +13 -0
- package/table/subComponent/TableFooterPager.js +33 -0
- package/table/subComponent/TableHeadCell.js +19 -0
- package/table/subComponent/TableSort.js +38 -0
- package/tagify/TagifyStyle.js +60 -0
- package/tagify/Tags.js +56 -0
- package/tagify/index.js +27 -0
- package/tagify/templates/getCreateButtonTemplate.js +18 -0
- package/text/Paragraph.js +86 -0
- package/text/index.js +13 -0
- package/timeline/Timeline.js +139 -0
- package/timeline/index.js +13 -0
- package/toast/CustomToastContainer.js +45 -0
- package/toast/MessageContainer.js +51 -0
- package/toast/index.js +36 -0
- package/toast/show.js +39 -0
- package/toast/style.css +1 -0
- package/tooltip/Tooltip.js +140 -0
- package/tooltip/index.js +13 -0
- package/treeView/TreeViewV2.js +38 -0
- package/treeView/TreeflexStyle.js +49 -0
- package/treeView/index.js +20 -0
- package/wizard/Wizard.js +251 -0
- package/wizard/index.js +13 -0
package/select/Select.js
ADDED
|
@@ -0,0 +1,818 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _reactDom = require("react-dom");
|
|
9
|
+
var _reactI18next = require("react-i18next");
|
|
10
|
+
var _reactOutsideClickHandler = _interopRequireDefault(require("react-outside-click-handler"));
|
|
11
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
12
|
+
var _lodash = _interopRequireDefault(require("lodash.uniqueid"));
|
|
13
|
+
var _ti = require("react-icons/ti");
|
|
14
|
+
var _md = require("react-icons/md");
|
|
15
|
+
var _hooks = require("@cashub/hooks");
|
|
16
|
+
var _utils = require("@cashub/utils");
|
|
17
|
+
var _media = _interopRequireDefault(require("../styles/mixin/media"));
|
|
18
|
+
var _SelectedSingle = _interopRequireDefault(require("./subComponent/SelectedSingle"));
|
|
19
|
+
var _SelectedMultipleTags = _interopRequireDefault(require("./subComponent/SelectedMultipleTags"));
|
|
20
|
+
var _SelectedMultipleText = _interopRequireDefault(require("./subComponent/SelectedMultipleText"));
|
|
21
|
+
var _SelectedMultipleCount = _interopRequireDefault(require("./subComponent/SelectedMultipleCount"));
|
|
22
|
+
var _ListBox = _interopRequireDefault(require("./subComponent/ListBox"));
|
|
23
|
+
var _SearchBox = _interopRequireDefault(require("./subComponent/SearchBox"));
|
|
24
|
+
var _Options = _interopRequireDefault(require("./subComponent/Options"));
|
|
25
|
+
var _OptionGroup = _interopRequireDefault(require("./subComponent/OptionGroup"));
|
|
26
|
+
var _Option = _interopRequireDefault(require("./subComponent/Option"));
|
|
27
|
+
var _Checkbox = _interopRequireDefault(require("./subComponent/Checkbox"));
|
|
28
|
+
var _Footer = _interopRequireDefault(require("./subComponent/Footer"));
|
|
29
|
+
var _figure = require("../figure");
|
|
30
|
+
var _image = require("../image");
|
|
31
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
32
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
33
|
+
const Select = _ref => {
|
|
34
|
+
let {
|
|
35
|
+
options,
|
|
36
|
+
enableSelectAll = false,
|
|
37
|
+
selected,
|
|
38
|
+
onSelect,
|
|
39
|
+
onDeselect,
|
|
40
|
+
multiple = false,
|
|
41
|
+
displayMode = 'tags',
|
|
42
|
+
allowClear = false,
|
|
43
|
+
allowSearch = true,
|
|
44
|
+
disabled,
|
|
45
|
+
placeholder = '',
|
|
46
|
+
fullWidth,
|
|
47
|
+
large,
|
|
48
|
+
fill,
|
|
49
|
+
fillReverse,
|
|
50
|
+
onBlur,
|
|
51
|
+
onSearch,
|
|
52
|
+
flexGrow,
|
|
53
|
+
footer
|
|
54
|
+
} = _ref;
|
|
55
|
+
const {
|
|
56
|
+
t
|
|
57
|
+
} = (0, _reactI18next.useTranslation)();
|
|
58
|
+
const [id] = (0, _react.useState)((0, _lodash.default)('select-'));
|
|
59
|
+
const [allOptionId] = (0, _react.useState)((0, _lodash.default)('allOptons-'));
|
|
60
|
+
const [display, setDisplay] = (0, _react.useState)(false);
|
|
61
|
+
const [comboboxElement, setComboboxElement] = (0, _react.useState)(null);
|
|
62
|
+
const [listBoxElement, setListBoxElement] = (0, _react.useState)(null);
|
|
63
|
+
const optionsElementRef = (0, _react.useRef)(null);
|
|
64
|
+
const searchBoxElement = (0, _react.useRef)(null);
|
|
65
|
+
const [listBoxWidth, setListBoxWidth] = (0, _react.useState)(0);
|
|
66
|
+
const [optionList, setOptionList] = (0, _react.useState)([]);
|
|
67
|
+
const [focusedOption, setFocusedOption] = (0, _react.useState)(null);
|
|
68
|
+
const [isFocusCombobox, setIsFocusCombobox] = (0, _react.useState)(false);
|
|
69
|
+
const [selectedOptions, setSelectedOptions] = (0, _react.useState)([]);
|
|
70
|
+
const [filteredOptions, setFilteredOptions] = (0, _react.useState)(options);
|
|
71
|
+
const [search, setSearch] = (0, _react.useState)('');
|
|
72
|
+
const {
|
|
73
|
+
styles,
|
|
74
|
+
attributes,
|
|
75
|
+
state,
|
|
76
|
+
update
|
|
77
|
+
} = (0, _hooks.useCustomPopper)(comboboxElement, listBoxElement);
|
|
78
|
+
const newOptions = (0, _react.useMemo)(() => {
|
|
79
|
+
if (!options) return;
|
|
80
|
+
const newOptions = options.map(item => {
|
|
81
|
+
return {
|
|
82
|
+
isDisable: false,
|
|
83
|
+
...item
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
if (options.length > 0 && multiple && enableSelectAll) {
|
|
87
|
+
newOptions.unshift({
|
|
88
|
+
id: allOptionId,
|
|
89
|
+
text: t('All')
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return newOptions;
|
|
93
|
+
}, [options, multiple, enableSelectAll, allOptionId]);
|
|
94
|
+
const enabledOptions = (0, _react.useMemo)(() => {
|
|
95
|
+
return newOptions.filter(item => !item.isDisable);
|
|
96
|
+
}, [newOptions]);
|
|
97
|
+
|
|
98
|
+
// parse all value to string
|
|
99
|
+
// for subsequently determine whether it is a selected item
|
|
100
|
+
const parsedSelected = (0, _react.useMemo)(() => {
|
|
101
|
+
if (selected || selected === 0) {
|
|
102
|
+
// multiple value
|
|
103
|
+
if (Array.isArray(selected)) {
|
|
104
|
+
return selected.map(value => value.toString());
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// single value
|
|
108
|
+
return selected.toString();
|
|
109
|
+
}
|
|
110
|
+
return '';
|
|
111
|
+
}, [selected]);
|
|
112
|
+
const selectedAllOptions = (0, _react.useMemo)(() => {
|
|
113
|
+
if (multiple && enableSelectAll && parsedSelected.length + 1 === enabledOptions.length) {
|
|
114
|
+
const selectedAllOptions = [...parsedSelected];
|
|
115
|
+
selectedAllOptions.unshift(allOptionId);
|
|
116
|
+
return selectedAllOptions;
|
|
117
|
+
}
|
|
118
|
+
return parsedSelected;
|
|
119
|
+
}, [multiple, enableSelectAll, enabledOptions.length, parsedSelected, allOptionId]);
|
|
120
|
+
const showCheckbox = (0, _react.useMemo)(() => {
|
|
121
|
+
if (multiple && displayMode === 'text') {
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
return false;
|
|
125
|
+
}, [displayMode, multiple]);
|
|
126
|
+
const getOptionText = (0, _react.useCallback)(option => {
|
|
127
|
+
return [option.text, option.suffix].filter(text => text || text === 0).join(' ');
|
|
128
|
+
}, []);
|
|
129
|
+
const renderOptionContent = (0, _react.useCallback)(option => {
|
|
130
|
+
const text = getOptionText(option);
|
|
131
|
+
const highlightText = option.highlightText?.toString();
|
|
132
|
+
if (highlightText && text.includes(highlightText)) {
|
|
133
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(OptionLabel, {
|
|
134
|
+
children: text.split(highlightText).map((textPart, index, textParts) => {
|
|
135
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react.Fragment, {
|
|
136
|
+
children: [textPart, index < textParts.length - 1 && /*#__PURE__*/(0, _jsxRuntime.jsx)(OptionHighlight, {
|
|
137
|
+
$color: option.highlightColor,
|
|
138
|
+
children: highlightText
|
|
139
|
+
})]
|
|
140
|
+
}, `${highlightText}-${index}`);
|
|
141
|
+
})
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(OptionLabel, {
|
|
145
|
+
children: [option.text, option.suffix && /*#__PURE__*/(0, _jsxRuntime.jsxs)(OptionBadge, {
|
|
146
|
+
children: ["\xA0", option.suffix]
|
|
147
|
+
})]
|
|
148
|
+
});
|
|
149
|
+
}, [getOptionText]);
|
|
150
|
+
|
|
151
|
+
// set focused option
|
|
152
|
+
const handleFocusItem = (0, _react.useCallback)(element => {
|
|
153
|
+
if (!optionsElementRef.current) return;
|
|
154
|
+
setFocusedOption(element);
|
|
155
|
+
const container = optionsElementRef.current;
|
|
156
|
+
if (container.scrollHeight > container.clientHeight) {
|
|
157
|
+
const scrollBottom = container.clientHeight + container.scrollTop;
|
|
158
|
+
const elementBottom = element.offsetTop + element.offsetHeight;
|
|
159
|
+
if (elementBottom > scrollBottom) {
|
|
160
|
+
container.scrollTop = elementBottom - container.clientHeight;
|
|
161
|
+
} else if (element.offsetTop < container.scrollTop) {
|
|
162
|
+
container.scrollTop = element.offsetTop;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}, []);
|
|
166
|
+
const focusFirstItem = (0, _react.useCallback)(() => {
|
|
167
|
+
const firstItem = listBoxElement.querySelector('[role="option"]');
|
|
168
|
+
if (firstItem) {
|
|
169
|
+
handleFocusItem(firstItem);
|
|
170
|
+
}
|
|
171
|
+
}, [listBoxElement, handleFocusItem]);
|
|
172
|
+
const setupFocus = (0, _react.useCallback)(() => {
|
|
173
|
+
if (!listBoxElement) return;
|
|
174
|
+
const selectedItem = listBoxElement.querySelector('[aria-selected="true"]');
|
|
175
|
+
if (selectedItem) {
|
|
176
|
+
handleFocusItem(selectedItem);
|
|
177
|
+
} else if (optionList.length > 0) {
|
|
178
|
+
focusFirstItem();
|
|
179
|
+
} else {
|
|
180
|
+
setFocusedOption(null);
|
|
181
|
+
}
|
|
182
|
+
}, [listBoxElement, handleFocusItem, focusFirstItem, optionList]);
|
|
183
|
+
const findPreviousItem = (0, _react.useCallback)(currentItem => {
|
|
184
|
+
const allItem = [...listBoxElement.querySelectorAll('[role="option"]')];
|
|
185
|
+
const currentItemIndex = allItem.indexOf(currentItem);
|
|
186
|
+
let previousItem = null;
|
|
187
|
+
if (currentItemIndex !== -1 && currentItemIndex > 0) {
|
|
188
|
+
previousItem = allItem[currentItemIndex - 1];
|
|
189
|
+
}
|
|
190
|
+
return previousItem;
|
|
191
|
+
}, [listBoxElement]);
|
|
192
|
+
const findNextItem = (0, _react.useCallback)(currentItem => {
|
|
193
|
+
const allItem = [...listBoxElement.querySelectorAll('[role="option"]')];
|
|
194
|
+
const currentItemIndex = allItem.indexOf(currentItem);
|
|
195
|
+
let nextItem = null;
|
|
196
|
+
if (currentItemIndex !== -1 && currentItemIndex < allItem.length - 1) {
|
|
197
|
+
nextItem = allItem[currentItemIndex + 1];
|
|
198
|
+
}
|
|
199
|
+
return nextItem;
|
|
200
|
+
}, [listBoxElement]);
|
|
201
|
+
const handleOnSelect = (0, _react.useCallback)((event, value) => {
|
|
202
|
+
event.stopPropagation();
|
|
203
|
+
if (disabled === true) return;
|
|
204
|
+
const targetOption = newOptions.find(_ref2 => {
|
|
205
|
+
let {
|
|
206
|
+
id,
|
|
207
|
+
child
|
|
208
|
+
} = _ref2;
|
|
209
|
+
return id === value || child && child.find(_ref3 => {
|
|
210
|
+
let {
|
|
211
|
+
id
|
|
212
|
+
} = _ref3;
|
|
213
|
+
return id === value;
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
const actualOpt = targetOption?.child ? targetOption.child.find(_ref4 => {
|
|
217
|
+
let {
|
|
218
|
+
id
|
|
219
|
+
} = _ref4;
|
|
220
|
+
return id === value;
|
|
221
|
+
}) : targetOption;
|
|
222
|
+
if (actualOpt?.isDisable) return;
|
|
223
|
+
|
|
224
|
+
// 選取選項
|
|
225
|
+
// 點選 all 全選
|
|
226
|
+
if (multiple) {
|
|
227
|
+
if (value.toString() === allOptionId && selectedAllOptions.length < enabledOptions.length) {
|
|
228
|
+
for (let index = 1; index < enabledOptions.length; index += 1) {
|
|
229
|
+
onSelect(enabledOptions[index].id);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (value.toString() !== allOptionId && !selectedAllOptions.includes(value.toString())) {
|
|
233
|
+
// 選取一個選項,變成全選
|
|
234
|
+
if (selectedAllOptions.length + 2 === enabledOptions.length) {
|
|
235
|
+
onSelect(value);
|
|
236
|
+
} else {
|
|
237
|
+
// 選取特定選項
|
|
238
|
+
onSelect(value);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// 刪除選項
|
|
243
|
+
// 點選 all 刪除全選
|
|
244
|
+
if (value.toString() === allOptionId && selectedAllOptions.length === enabledOptions.length) {
|
|
245
|
+
for (let index = 0; index < enabledOptions.length; index += 1) {
|
|
246
|
+
onDeselect(enabledOptions[index].id);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
if (value.toString() !== allOptionId && selectedAllOptions.includes(value.toString())) {
|
|
250
|
+
// 原本是 all 全選後來刪除其中一個選項
|
|
251
|
+
if (selectedAllOptions.length === enabledOptions.length) {
|
|
252
|
+
onDeselect(value);
|
|
253
|
+
} else {
|
|
254
|
+
// 刪除特定選項
|
|
255
|
+
onDeselect(value);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
setDisplay(true);
|
|
259
|
+
} else {
|
|
260
|
+
onSelect(value);
|
|
261
|
+
setDisplay(false);
|
|
262
|
+
}
|
|
263
|
+
comboboxElement.focus();
|
|
264
|
+
setSearch('');
|
|
265
|
+
}, [disabled, onSelect, comboboxElement, selectedAllOptions, onDeselect, newOptions, allOptionId, multiple, enabledOptions]);
|
|
266
|
+
const handleOnDeselect = (0, _react.useCallback)((event, value) => {
|
|
267
|
+
event.stopPropagation();
|
|
268
|
+
if (disabled === true) return;
|
|
269
|
+
if (multiple) {
|
|
270
|
+
if (value.toString() === allOptionId) {
|
|
271
|
+
for (let index = 0; index < optionList.length; index += 1) {
|
|
272
|
+
onDeselect(optionList[index].id);
|
|
273
|
+
}
|
|
274
|
+
} else {
|
|
275
|
+
onDeselect(value);
|
|
276
|
+
}
|
|
277
|
+
} else {
|
|
278
|
+
onDeselect(value);
|
|
279
|
+
}
|
|
280
|
+
}, [disabled, onDeselect, optionList, allOptionId, multiple]);
|
|
281
|
+
|
|
282
|
+
// list all selected option
|
|
283
|
+
const selectedItem = (0, _react.useMemo)(() => {
|
|
284
|
+
if (selectedOptions.length > 0) {
|
|
285
|
+
if (multiple) {
|
|
286
|
+
if (displayMode === 'text') {
|
|
287
|
+
let text;
|
|
288
|
+
if (selectedOptions[0].id === allOptionId) {
|
|
289
|
+
[{
|
|
290
|
+
text
|
|
291
|
+
}] = selectedOptions;
|
|
292
|
+
} else {
|
|
293
|
+
text = selectedOptions.map(value => {
|
|
294
|
+
return getOptionText(value);
|
|
295
|
+
}).join(', ');
|
|
296
|
+
}
|
|
297
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_SelectedMultipleText.default, {
|
|
298
|
+
children: text
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
if (displayMode === 'count') {
|
|
302
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_SelectedMultipleCount.default, {
|
|
303
|
+
placeholder: placeholder,
|
|
304
|
+
count: selectedOptions.length
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
if (selectedOptions[0].id === allOptionId) {
|
|
308
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_SelectedMultipleTags.default, {
|
|
309
|
+
content: renderOptionContent(selectedOptions[0]),
|
|
310
|
+
onClick: event => handleOnDeselect(event, selectedOptions[0].id),
|
|
311
|
+
disabled: disabled
|
|
312
|
+
}, selectedOptions[0].id);
|
|
313
|
+
}
|
|
314
|
+
return selectedOptions.map(value => {
|
|
315
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_SelectedMultipleTags.default, {
|
|
316
|
+
content: renderOptionContent(value),
|
|
317
|
+
onClick: event => handleOnDeselect(event, value.id),
|
|
318
|
+
disabled: disabled || value.isDisable
|
|
319
|
+
}, value.id);
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_SelectedSingle.default, {
|
|
323
|
+
children: [selectedOptions[0].icon && /*#__PURE__*/(0, _jsxRuntime.jsx)(Icon, {
|
|
324
|
+
src: selectedOptions[0].icon
|
|
325
|
+
}), renderOptionContent(selectedOptions[0])]
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
return placeholder;
|
|
329
|
+
}, [placeholder, handleOnDeselect, multiple, displayMode, selectedOptions, disabled, allOptionId, getOptionText, renderOptionContent]);
|
|
330
|
+
const optionItem = (0, _react.useMemo)(() => {
|
|
331
|
+
if (optionList.length <= 0) return null;
|
|
332
|
+
return optionList.map(option => {
|
|
333
|
+
if (option.child && option.child.length > 0) {
|
|
334
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_OptionGroup.default, {
|
|
335
|
+
"aria-labelledby": option.text,
|
|
336
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Option.default, {
|
|
337
|
+
role: "presentation",
|
|
338
|
+
id: option.text,
|
|
339
|
+
children: option.text
|
|
340
|
+
}), option.child.map(option => {
|
|
341
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Option.default, {
|
|
342
|
+
role: "option",
|
|
343
|
+
tabIndex: option.isDisable ? '-1' : '0',
|
|
344
|
+
id: option.id,
|
|
345
|
+
onClick: event => !option.isDisable && handleOnSelect(event, option.id),
|
|
346
|
+
focus: focusedOption && focusedOption.id === option.id.toString(),
|
|
347
|
+
selected: option.selected,
|
|
348
|
+
"aria-selected": option.selected,
|
|
349
|
+
"aria-disabled": option.isDisable,
|
|
350
|
+
disabled: option.isDisable,
|
|
351
|
+
children: [showCheckbox && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Checkbox.default, {
|
|
352
|
+
selected: option.selected,
|
|
353
|
+
disabled: option.isDisable
|
|
354
|
+
}), renderOptionContent(option)]
|
|
355
|
+
}, option.id);
|
|
356
|
+
})]
|
|
357
|
+
}, option.text);
|
|
358
|
+
}
|
|
359
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Option.default, {
|
|
360
|
+
role: "option",
|
|
361
|
+
tabIndex: option.isDisable ? '-1' : '0',
|
|
362
|
+
id: option.id,
|
|
363
|
+
onClick: event => !option.isDisable && handleOnSelect(event, option.id),
|
|
364
|
+
focus: focusedOption && focusedOption.id === option.id.toString(),
|
|
365
|
+
selected: option.selected,
|
|
366
|
+
"aria-selected": option.selected,
|
|
367
|
+
"aria-disabled": option.isDisable,
|
|
368
|
+
disabled: option.isDisable,
|
|
369
|
+
children: [showCheckbox && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Checkbox.default, {
|
|
370
|
+
selected: option.selected,
|
|
371
|
+
disabled: option.isDisable
|
|
372
|
+
}), option.icon && /*#__PURE__*/(0, _jsxRuntime.jsx)(Icon, {
|
|
373
|
+
src: option.icon
|
|
374
|
+
}), renderOptionContent(option)]
|
|
375
|
+
}, option.id);
|
|
376
|
+
});
|
|
377
|
+
}, [optionList, focusedOption, handleOnSelect, showCheckbox, renderOptionContent]);
|
|
378
|
+
|
|
379
|
+
// show or hide listbox
|
|
380
|
+
// and set listbox width according to combobox current width
|
|
381
|
+
const handleToggle = () => {
|
|
382
|
+
if (disabled === true) return;
|
|
383
|
+
const tmpDisplay = !display;
|
|
384
|
+
if (!tmpDisplay) {
|
|
385
|
+
setFocusedOption(null);
|
|
386
|
+
}
|
|
387
|
+
setDisplay(tmpDisplay);
|
|
388
|
+
update();
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
// handle keyboard interaction
|
|
392
|
+
const handleKeyUp = event => {
|
|
393
|
+
const key = event.keyCode;
|
|
394
|
+
switch (key) {
|
|
395
|
+
case _utils.KEY_CODE.ENTER:
|
|
396
|
+
if (!display) {
|
|
397
|
+
handleToggle();
|
|
398
|
+
} else if (focusedOption) {
|
|
399
|
+
if (focusedOption.getAttribute('aria-disabled') === 'true') return;
|
|
400
|
+
handleOnSelect(event, focusedOption.id);
|
|
401
|
+
}
|
|
402
|
+
break;
|
|
403
|
+
case _utils.KEY_CODE.ESCAPE:
|
|
404
|
+
if (display) {
|
|
405
|
+
handleToggle();
|
|
406
|
+
}
|
|
407
|
+
break;
|
|
408
|
+
case _utils.KEY_CODE.UP:
|
|
409
|
+
{
|
|
410
|
+
if (!focusedOption) {
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
let previousItem = findPreviousItem(focusedOption);
|
|
414
|
+
while (previousItem && previousItem.getAttribute('aria-disabled') === 'true') {
|
|
415
|
+
previousItem = findPreviousItem(previousItem);
|
|
416
|
+
}
|
|
417
|
+
if (previousItem) {
|
|
418
|
+
handleFocusItem(previousItem);
|
|
419
|
+
}
|
|
420
|
+
break;
|
|
421
|
+
}
|
|
422
|
+
case _utils.KEY_CODE.DOWN:
|
|
423
|
+
{
|
|
424
|
+
if (!focusedOption) {
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
let nextItem = findNextItem(focusedOption);
|
|
428
|
+
while (nextItem && nextItem.getAttribute('aria-disabled') === 'true') {
|
|
429
|
+
nextItem = findNextItem(nextItem);
|
|
430
|
+
}
|
|
431
|
+
if (nextItem) {
|
|
432
|
+
handleFocusItem(nextItem);
|
|
433
|
+
}
|
|
434
|
+
break;
|
|
435
|
+
}
|
|
436
|
+
case _utils.KEY_CODE.END:
|
|
437
|
+
{
|
|
438
|
+
event.preventDefault();
|
|
439
|
+
const itemList = listBoxElement.querySelectorAll('[role="option"]');
|
|
440
|
+
if (itemList.length) {
|
|
441
|
+
handleFocusItem(itemList[itemList.length - 1]);
|
|
442
|
+
}
|
|
443
|
+
break;
|
|
444
|
+
}
|
|
445
|
+
case _utils.KEY_CODE.HOME:
|
|
446
|
+
event.preventDefault();
|
|
447
|
+
focusFirstItem();
|
|
448
|
+
break;
|
|
449
|
+
default:
|
|
450
|
+
break;
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
const handleKeyDown = event => {
|
|
454
|
+
const key = event.keyCode;
|
|
455
|
+
switch (key) {
|
|
456
|
+
case _utils.KEY_CODE.ENTER:
|
|
457
|
+
case _utils.KEY_CODE.ESCAPE:
|
|
458
|
+
case _utils.KEY_CODE.UP:
|
|
459
|
+
case _utils.KEY_CODE.DOWN:
|
|
460
|
+
case _utils.KEY_CODE.END:
|
|
461
|
+
case _utils.KEY_CODE.HOME:
|
|
462
|
+
event.preventDefault();
|
|
463
|
+
break;
|
|
464
|
+
default:
|
|
465
|
+
break;
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
// handle search keyword change
|
|
470
|
+
const handleSearchChange = event => {
|
|
471
|
+
if (onSearch) {
|
|
472
|
+
onSearch(event.target.value);
|
|
473
|
+
}
|
|
474
|
+
setSearch(event.target.value);
|
|
475
|
+
};
|
|
476
|
+
const handleFocus = event => {
|
|
477
|
+
event.preventDefault();
|
|
478
|
+
event.stopPropagation();
|
|
479
|
+
setIsFocusCombobox(true);
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
// determine selected option(s)
|
|
483
|
+
(0, _react.useEffect)(() => {
|
|
484
|
+
if (!newOptions) return;
|
|
485
|
+
const tmpSelectedOptions = [];
|
|
486
|
+
newOptions.forEach(option => {
|
|
487
|
+
if (option.child && option.child.length > 0) {
|
|
488
|
+
option.child.forEach(option => {
|
|
489
|
+
if (multiple && selectedAllOptions.includes(option.id.toString())) {
|
|
490
|
+
tmpSelectedOptions.push(option);
|
|
491
|
+
} else if (selectedAllOptions === option.id.toString()) {
|
|
492
|
+
tmpSelectedOptions.push(option);
|
|
493
|
+
}
|
|
494
|
+
});
|
|
495
|
+
} else {
|
|
496
|
+
if (multiple && selectedAllOptions.includes(option.id.toString())) {
|
|
497
|
+
tmpSelectedOptions.push(option);
|
|
498
|
+
} else if (selectedAllOptions === option.id.toString()) {
|
|
499
|
+
tmpSelectedOptions.push(option);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
return false;
|
|
503
|
+
});
|
|
504
|
+
setSelectedOptions(tmpSelectedOptions);
|
|
505
|
+
}, [newOptions, selectedAllOptions, multiple]);
|
|
506
|
+
(0, _react.useEffect)(() => {
|
|
507
|
+
if (update) {
|
|
508
|
+
setTimeout(() => {
|
|
509
|
+
update();
|
|
510
|
+
}, 100);
|
|
511
|
+
}
|
|
512
|
+
}, [update, listBoxWidth]);
|
|
513
|
+
|
|
514
|
+
// observe element resized
|
|
515
|
+
(0, _react.useEffect)(() => {
|
|
516
|
+
if (!comboboxElement) return;
|
|
517
|
+
const resizeObserverInstance = new ResizeObserver(entries => {
|
|
518
|
+
for (const entry of entries) {
|
|
519
|
+
if (entry.target) {
|
|
520
|
+
const borderBoxSize = entry.target.clientWidth;
|
|
521
|
+
setListBoxWidth(borderBoxSize);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
});
|
|
525
|
+
resizeObserverInstance.observe(comboboxElement);
|
|
526
|
+
return () => {
|
|
527
|
+
// unobserve element
|
|
528
|
+
resizeObserverInstance.unobserve(comboboxElement);
|
|
529
|
+
};
|
|
530
|
+
}, [comboboxElement]);
|
|
531
|
+
|
|
532
|
+
// re-setup focus when option list changed and update popper position
|
|
533
|
+
(0, _react.useEffect)(() => {
|
|
534
|
+
setupFocus();
|
|
535
|
+
if (update) update();
|
|
536
|
+
}, [setupFocus, optionList, update]);
|
|
537
|
+
|
|
538
|
+
// parse option list when filtered options change
|
|
539
|
+
(0, _react.useEffect)(() => {
|
|
540
|
+
if (!filteredOptions) return;
|
|
541
|
+
setOptionList(filteredOptions.map(option => {
|
|
542
|
+
if (option.child && option.child.length > 0) {
|
|
543
|
+
return {
|
|
544
|
+
...option,
|
|
545
|
+
child: option.child.map(option => {
|
|
546
|
+
let selected = false;
|
|
547
|
+
if (multiple && selectedAllOptions.includes(option.id.toString())) {
|
|
548
|
+
selected = true;
|
|
549
|
+
} else if (selectedAllOptions === option.id.toString()) {
|
|
550
|
+
selected = true;
|
|
551
|
+
}
|
|
552
|
+
return {
|
|
553
|
+
...option,
|
|
554
|
+
selected
|
|
555
|
+
};
|
|
556
|
+
})
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
let selected = false;
|
|
560
|
+
if (multiple && selectedAllOptions.includes(option.id.toString())) {
|
|
561
|
+
selected = true;
|
|
562
|
+
} else if (selectedAllOptions === option.id.toString()) {
|
|
563
|
+
selected = true;
|
|
564
|
+
}
|
|
565
|
+
return {
|
|
566
|
+
...option,
|
|
567
|
+
selected
|
|
568
|
+
};
|
|
569
|
+
}));
|
|
570
|
+
}, [filteredOptions, multiple, selectedAllOptions]);
|
|
571
|
+
|
|
572
|
+
// filter options on search keyword changed
|
|
573
|
+
(0, _react.useEffect)(() => {
|
|
574
|
+
const tmpFilteredOptions = [];
|
|
575
|
+
newOptions.forEach(option => {
|
|
576
|
+
if (option.child && option.child.length > 0) {
|
|
577
|
+
const tmpFilteredChildOptions = option.child.filter(option => getOptionText(option).toLowerCase().indexOf(search.toLowerCase().trim()) !== -1);
|
|
578
|
+
if (tmpFilteredChildOptions.length > 0) {
|
|
579
|
+
tmpFilteredOptions.push({
|
|
580
|
+
...option,
|
|
581
|
+
child: tmpFilteredChildOptions
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
} else if (getOptionText(option).toLowerCase().indexOf(search.toLowerCase().trim()) !== -1) {
|
|
585
|
+
tmpFilteredOptions.push(option);
|
|
586
|
+
}
|
|
587
|
+
});
|
|
588
|
+
setFilteredOptions(tmpFilteredOptions);
|
|
589
|
+
}, [search, newOptions, getOptionText]);
|
|
590
|
+
(0, _react.useEffect)(() => {
|
|
591
|
+
if (display) {
|
|
592
|
+
setupFocus();
|
|
593
|
+
if (allowSearch) {
|
|
594
|
+
searchBoxElement.current.focus();
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
}, [setupFocus, display, allowSearch]);
|
|
598
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
599
|
+
style: {
|
|
600
|
+
flexGrow: flexGrow ? 1 : 0
|
|
601
|
+
},
|
|
602
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactOutsideClickHandler.default, {
|
|
603
|
+
onOutsideClick: () => {
|
|
604
|
+
setDisplay(false);
|
|
605
|
+
if (onBlur) onBlur();
|
|
606
|
+
setIsFocusCombobox(false);
|
|
607
|
+
},
|
|
608
|
+
disabled: !isFocusCombobox,
|
|
609
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(Combobox, {
|
|
610
|
+
flexGrow: flexGrow,
|
|
611
|
+
role: "combobox",
|
|
612
|
+
tabIndex: "0",
|
|
613
|
+
"aria-haspopup": "listbox",
|
|
614
|
+
"aria-expanded": display,
|
|
615
|
+
"aria-owns": id,
|
|
616
|
+
ref: setComboboxElement,
|
|
617
|
+
onClick: handleToggle,
|
|
618
|
+
onKeyUp: handleKeyUp,
|
|
619
|
+
onKeyDown: handleKeyDown,
|
|
620
|
+
$display: display,
|
|
621
|
+
disabled: disabled,
|
|
622
|
+
fullWidth: fullWidth,
|
|
623
|
+
large: large,
|
|
624
|
+
$fill: fill,
|
|
625
|
+
fillReverse: fillReverse,
|
|
626
|
+
onFocus: handleFocus,
|
|
627
|
+
placeholder: placeholder,
|
|
628
|
+
children: [selectedItem, selectedOptions.length > 0 && !multiple && !disabled && allowClear && /*#__PURE__*/(0, _jsxRuntime.jsx)(CloseButton, {
|
|
629
|
+
onClick: () => {
|
|
630
|
+
onSelect('');
|
|
631
|
+
}
|
|
632
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(ExpandArrow, {
|
|
633
|
+
"aria-haspopup": "listbox",
|
|
634
|
+
"aria-expanded": display
|
|
635
|
+
})]
|
|
636
|
+
}), /*#__PURE__*/(0, _reactDom.createPortal)(/*#__PURE__*/(0, _jsxRuntime.jsxs)(_ListBox.default, {
|
|
637
|
+
role: "listbox",
|
|
638
|
+
tabIndex: "0",
|
|
639
|
+
id: id,
|
|
640
|
+
ref: setListBoxElement,
|
|
641
|
+
onKeyUp: handleKeyUp,
|
|
642
|
+
onKeyDown: handleKeyDown,
|
|
643
|
+
width: listBoxWidth,
|
|
644
|
+
$display: display,
|
|
645
|
+
style: styles.popper,
|
|
646
|
+
...attributes.popper,
|
|
647
|
+
placement: state && state.placement,
|
|
648
|
+
children: [allowSearch && /*#__PURE__*/(0, _jsxRuntime.jsx)(_SearchBox.default, {
|
|
649
|
+
ref: searchBoxElement,
|
|
650
|
+
placeholder: "Search",
|
|
651
|
+
onChange: handleSearchChange,
|
|
652
|
+
value: search
|
|
653
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Options.default, {
|
|
654
|
+
ref: optionsElementRef,
|
|
655
|
+
allowSearch: allowSearch,
|
|
656
|
+
children: optionItem || /*#__PURE__*/(0, _jsxRuntime.jsx)(Message, {
|
|
657
|
+
children: "No results found"
|
|
658
|
+
})
|
|
659
|
+
}), footer && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Footer.default, {
|
|
660
|
+
children: footer
|
|
661
|
+
})]
|
|
662
|
+
}), document.body)]
|
|
663
|
+
})
|
|
664
|
+
});
|
|
665
|
+
};
|
|
666
|
+
const Icon = _ref5 => {
|
|
667
|
+
let {
|
|
668
|
+
src
|
|
669
|
+
} = _ref5;
|
|
670
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
671
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_figure.IconFigure, {
|
|
672
|
+
size: "medium",
|
|
673
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_image.ImageFluid, {
|
|
674
|
+
crossOrigin: "anonymous",
|
|
675
|
+
src: src,
|
|
676
|
+
alt: "",
|
|
677
|
+
roundedS: true
|
|
678
|
+
})
|
|
679
|
+
}), "\xA0"]
|
|
680
|
+
});
|
|
681
|
+
};
|
|
682
|
+
const Combobox = _styledComponents.default.div`
|
|
683
|
+
display: flex;
|
|
684
|
+
flex-wrap: wrap;
|
|
685
|
+
align-items: center;
|
|
686
|
+
min-height: 36px;
|
|
687
|
+
cursor: pointer;
|
|
688
|
+
position: relative;
|
|
689
|
+
background: transparent;
|
|
690
|
+
color: var(--font-on-background);
|
|
691
|
+
font-size: var(--font-body1);
|
|
692
|
+
border: var(--border-width) solid var(--border-color);
|
|
693
|
+
border-radius: var(--border-radius-l);
|
|
694
|
+
padding: 0 calc(var(--spacing-s) * 2 + 8px) 0 var(--spacing-s);
|
|
695
|
+
|
|
696
|
+
&:focus {
|
|
697
|
+
${_ref6 => {
|
|
698
|
+
let {
|
|
699
|
+
disabled
|
|
700
|
+
} = _ref6;
|
|
701
|
+
return !disabled && `
|
|
702
|
+
border-color: var(--color-primary);
|
|
703
|
+
outline: none;
|
|
704
|
+
`;
|
|
705
|
+
}};
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
${_ref7 => {
|
|
709
|
+
let {
|
|
710
|
+
flexGrow
|
|
711
|
+
} = _ref7;
|
|
712
|
+
return !flexGrow && 'min-width: 160px;';
|
|
713
|
+
}}
|
|
714
|
+
|
|
715
|
+
${_ref8 => {
|
|
716
|
+
let {
|
|
717
|
+
$display
|
|
718
|
+
} = _ref8;
|
|
719
|
+
return $display && `
|
|
720
|
+
border-color: var(--color-primary);
|
|
721
|
+
outline: none;
|
|
722
|
+
`;
|
|
723
|
+
}}
|
|
724
|
+
|
|
725
|
+
${_ref9 => {
|
|
726
|
+
let {
|
|
727
|
+
disabled
|
|
728
|
+
} = _ref9;
|
|
729
|
+
return disabled && 'cursor: not-allowed;opacity: 0.5;';
|
|
730
|
+
}}
|
|
731
|
+
${_ref10 => {
|
|
732
|
+
let {
|
|
733
|
+
placeholder
|
|
734
|
+
} = _ref10;
|
|
735
|
+
return placeholder && 'color: var(--font-on-mute);';
|
|
736
|
+
}}
|
|
737
|
+
|
|
738
|
+
${_ref11 => {
|
|
739
|
+
let {
|
|
740
|
+
fullWidth
|
|
741
|
+
} = _ref11;
|
|
742
|
+
return fullWidth ? 'width: 100%' : 'max-width: 320px';
|
|
743
|
+
}};
|
|
744
|
+
|
|
745
|
+
${_ref12 => {
|
|
746
|
+
let {
|
|
747
|
+
large
|
|
748
|
+
} = _ref12;
|
|
749
|
+
return large && `
|
|
750
|
+
height: 40px;
|
|
751
|
+
padding: 12px calc(var(--spacing-s) * 2 + 8px) 12px var(--spacing-s);
|
|
752
|
+
`;
|
|
753
|
+
}}
|
|
754
|
+
|
|
755
|
+
${_ref13 => {
|
|
756
|
+
let {
|
|
757
|
+
$fill
|
|
758
|
+
} = _ref13;
|
|
759
|
+
return $fill && `
|
|
760
|
+
background: var(--color-background2);
|
|
761
|
+
border-color: transparent;
|
|
762
|
+
`;
|
|
763
|
+
}}
|
|
764
|
+
|
|
765
|
+
${_ref14 => {
|
|
766
|
+
let {
|
|
767
|
+
fillReverse
|
|
768
|
+
} = _ref14;
|
|
769
|
+
return fillReverse && `
|
|
770
|
+
background: var(--color-background1);
|
|
771
|
+
border-color: transparent;
|
|
772
|
+
`;
|
|
773
|
+
}}
|
|
774
|
+
`;
|
|
775
|
+
Combobox.displayName = 'Combobox';
|
|
776
|
+
const CloseButton = (0, _styledComponents.default)(_md.MdClose)`
|
|
777
|
+
position: absolute;
|
|
778
|
+
top: 50%;
|
|
779
|
+
transform: translateY(-50%);
|
|
780
|
+
color: var(--color-primary);
|
|
781
|
+
font-size: var(--font-body1);
|
|
782
|
+
right: var(--spacing-l);
|
|
783
|
+
|
|
784
|
+
${_media.default.tablet`
|
|
785
|
+
right: calc(var(--spacing) + var(--spacing-s));
|
|
786
|
+
`};
|
|
787
|
+
`;
|
|
788
|
+
CloseButton.displayName = 'CloseButton';
|
|
789
|
+
const ExpandArrow = (0, _styledComponents.default)(_ti.TiArrowSortedDown)`
|
|
790
|
+
position: absolute;
|
|
791
|
+
top: 50%;
|
|
792
|
+
transform: translateY(-50%);
|
|
793
|
+
color: var(--color-primary);
|
|
794
|
+
font-size: var(--font-body1);
|
|
795
|
+
right: var(--spacing-s);
|
|
796
|
+
`;
|
|
797
|
+
ExpandArrow.displayName = 'ExpandArrow';
|
|
798
|
+
const Message = _styledComponents.default.p`
|
|
799
|
+
margin: 0;
|
|
800
|
+
padding: 12px var(--spacing-s);
|
|
801
|
+
`;
|
|
802
|
+
Message.displayName = 'Message';
|
|
803
|
+
const OptionBadge = _styledComponents.default.span`
|
|
804
|
+
color: var(--color-danger);
|
|
805
|
+
font-style: italic;
|
|
806
|
+
`;
|
|
807
|
+
const OptionLabel = _styledComponents.default.div`
|
|
808
|
+
min-width: 0;
|
|
809
|
+
`;
|
|
810
|
+
const OptionHighlight = _styledComponents.default.span`
|
|
811
|
+
color: ${_ref15 => {
|
|
812
|
+
let {
|
|
813
|
+
$color
|
|
814
|
+
} = _ref15;
|
|
815
|
+
return $color || 'var(--color-danger)';
|
|
816
|
+
}};
|
|
817
|
+
`;
|
|
818
|
+
var _default = exports.default = Select;
|