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