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