@semcore/select 16.1.12 → 17.0.0-prerelease.18
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/CHANGELOG.md +10 -0
- package/README.md +4 -4
- package/lib/cjs/InputSearch.js +109 -114
- package/lib/cjs/InputSearch.js.map +1 -1
- package/lib/cjs/Select.js +361 -362
- package/lib/cjs/Select.js.map +1 -1
- package/lib/cjs/context.js +2 -2
- package/lib/cjs/context.js.map +1 -1
- package/lib/cjs/index.d.js.map +1 -1
- package/lib/cjs/index.js +7 -7
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/translations/__intergalactic-dynamic-locales.js +16 -16
- package/lib/cjs/translations/__intergalactic-dynamic-locales.js.map +1 -1
- package/lib/es6/InputSearch.js +101 -106
- package/lib/es6/InputSearch.js.map +1 -1
- package/lib/es6/Select.js +339 -341
- package/lib/es6/Select.js.map +1 -1
- package/lib/es6/context.js +1 -1
- package/lib/es6/context.js.map +1 -1
- package/lib/es6/index.d.js.map +1 -1
- package/lib/es6/translations/__intergalactic-dynamic-locales.js +15 -15
- package/lib/es6/translations/__intergalactic-dynamic-locales.js.map +1 -1
- package/lib/esm/InputSearch.mjs +104 -98
- package/lib/esm/Select.mjs +325 -275
- package/lib/esm/context.mjs +1 -1
- package/lib/esm/translations/__intergalactic-dynamic-locales.mjs +1 -1
- package/lib/types/index.d.ts +4 -25
- package/package.json +14 -15
package/lib/es6/Select.js
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
3
|
-
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
|
-
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
|
5
|
-
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
6
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
7
|
-
import _callSuper from "@babel/runtime/helpers/callSuper";
|
|
8
|
-
import _superPropGet from "@babel/runtime/helpers/superPropGet";
|
|
9
|
-
import _inherits from "@babel/runtime/helpers/inherits";
|
|
10
2
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
11
3
|
import { sstyled as _sstyled } from "@semcore/core";
|
|
12
4
|
import { assignProps as _assignProps6 } from "@semcore/core";
|
|
@@ -15,8 +7,7 @@ import { assignProps as _assignProps4 } from "@semcore/core";
|
|
|
15
7
|
import { assignProps as _assignProps3 } from "@semcore/core";
|
|
16
8
|
import { assignProps as _assignProps2 } from "@semcore/core";
|
|
17
9
|
import { assignProps as _assignProps } from "@semcore/core";
|
|
18
|
-
|
|
19
|
-
import { hideScrollBarsFromScreenReadersContext } from '@semcore/base-components';
|
|
10
|
+
import { hideScrollBarsFromScreenReadersContext, useBox, isInputTriggerTag } from '@semcore/base-components';
|
|
20
11
|
import { ButtonTrigger } from '@semcore/base-trigger';
|
|
21
12
|
import { createComponent, Root, sstyled, lastInteraction } from '@semcore/core';
|
|
22
13
|
import addonTextChildren from '@semcore/core/lib/utils/addonTextChildren';
|
|
@@ -27,23 +18,22 @@ import logger from '@semcore/core/lib/utils/logger';
|
|
|
27
18
|
import Divider from '@semcore/divider';
|
|
28
19
|
import Dropdown, { AbstractDropdown, enhance, selectedIndexContext } from '@semcore/dropdown';
|
|
29
20
|
import DropdownMenu from '@semcore/dropdown-menu';
|
|
30
|
-
import {
|
|
31
|
-
import { isInputTriggerTag } from '@semcore/popper';
|
|
21
|
+
import { Text } from '@semcore/typography';
|
|
32
22
|
import cn from 'classnames';
|
|
33
23
|
import React from 'react';
|
|
34
24
|
import { selectContext } from './context';
|
|
35
25
|
import InputSearch from './InputSearch';
|
|
36
26
|
/*!__reshadow-styles__:"./style/select.shadow.css"*/
|
|
37
|
-
|
|
27
|
+
const style = (/*__reshadow_css_start__*/_sstyled.insert(/*__inner_css_start__*/".___SOptionCheckbox_ggett_gg_{margin-top:var(--intergalactic-spacing-05x, 2px);margin-right:var(--intergalactic-spacing-2x, 8px);margin-bottom:auto;position:relative;flex-shrink:0;width:16px;height:16px}.___SOptionCheckbox_ggett_gg_::before{content:\"\";position:absolute;top:0;left:0;right:0;bottom:0;background:var(--intergalactic-bg-primary-neutral, #ffffff);border:1px solid;border-radius:var(--intergalactic-addon-rounded, 4px);border-color:var(--intergalactic-border-primary, #c4c7cf)}.___SOptionCheckbox_ggett_gg_::after{content:\"\";position:absolute;top:0;left:0;right:0;bottom:0;margin:0 var(--intergalactic-spacing-05x, 2px);background-repeat:no-repeat;background-position:center center}.___SOptionCheckbox_ggett_gg_.__selected_ggett_gg_::after{background-image:url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAiIGhlaWdodD0iNyIgdmlld0JveD0iMCAwIDEwIDciIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxwYXRoIGQ9Ik04LjI1IDFMNCA1LjI1TDEuNzUgMyIgc3Ryb2tlPSJ3aGl0ZSIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz4KPC9zdmc+Cg==)}.___SOptionCheckbox_ggett_gg_._size_l_ggett_gg_{width:20px;height:20px}.___SOptionCheckbox_ggett_gg_._size_l_ggett_gg_.__selected_ggett_gg_::after{background-image:url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTIiIGhlaWdodD0iOSIgdmlld0JveD0iMCAwIDEyIDkiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxwYXRoIGQ9Ik0xMSAxLjVMNC43NSA3Ljc1TDEgNCIgc3Ryb2tlPSJ3aGl0ZSIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz4KPC9zdmc+Cg==)}.___SOptionCheckbox_ggett_gg_.__indeterminate_ggett_gg_:before,.___SOptionCheckbox_ggett_gg_.__selected_ggett_gg_:before{background-color:var(--intergalactic-control-primary-info, #008ff8);border-color:var(--intergalactic-control-primary-info, #008ff8)}.___SOptionCheckbox_ggett_gg_.__theme_ggett_gg_:before{border-color:var(--theme_ggett)}.___SOptionCheckbox_ggett_gg_.__theme_ggett_gg_.__indeterminate_ggett_gg_:before,.___SOptionCheckbox_ggett_gg_.__theme_ggett_gg_.__selected_ggett_gg_:before{background-color:var(--theme_ggett);border-color:var(--theme_ggett)}.___SOptionCheckbox_ggett_gg_.__selected_ggett_gg_{background-color:var(--intergalactic-dropdown-menu-item-selected, rgba(196, 229, 254, 0.7))}@media (hover:hover){.___SOptionCheckbox_ggett_gg_.__selected_ggett_gg_:hover{background-color:var(--intergalactic-dropdown-menu-item-selected-hover, #c4e5fe)}}.___SOptionCheckbox_ggett_gg_.__indeterminate_ggett_gg_:after{background-color:#fff;background-image:none;margin:auto;border-radius:1px}.___SOptionCheckbox_ggett_gg_.__indeterminate_ggett_gg_._size_l_ggett_gg_:after{width:12px;height:2px}.___SOptionCheckbox_ggett_gg_.__indeterminate_ggett_gg_._size_m_ggett_gg_:after{width:8px;height:2px}", /*__inner_css_end__*/"ggett_gg_"),
|
|
38
28
|
/*__reshadow_css_end__*/
|
|
39
29
|
{
|
|
40
|
-
"__SOptionCheckbox": "
|
|
41
|
-
"_selected": "
|
|
42
|
-
"_size_l": "
|
|
43
|
-
"_indeterminate": "
|
|
44
|
-
"_theme": "
|
|
45
|
-
"--theme": "--
|
|
46
|
-
"_size_m": "
|
|
30
|
+
"__SOptionCheckbox": "___SOptionCheckbox_ggett_gg_",
|
|
31
|
+
"_selected": "__selected_ggett_gg_",
|
|
32
|
+
"_size_l": "_size_l_ggett_gg_",
|
|
33
|
+
"_indeterminate": "__indeterminate_ggett_gg_",
|
|
34
|
+
"_theme": "__theme_ggett_gg_",
|
|
35
|
+
"--theme": "--theme_ggett",
|
|
36
|
+
"_size_m": "_size_m_ggett_gg_"
|
|
47
37
|
});
|
|
48
38
|
import { localizedMessages } from './translations/__intergalactic-dynamic-locales';
|
|
49
39
|
function isSelectedOption(value, valueOption) {
|
|
@@ -55,297 +45,271 @@ function isEmptyValue(value) {
|
|
|
55
45
|
function getEmptyValue(multiselect) {
|
|
56
46
|
return multiselect ? [] : null;
|
|
57
47
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
multiselect = _this$asProps.multiselect;
|
|
79
|
-
if (Array.isArray(value)) {
|
|
80
|
-
if (value.includes(optionValue)) {
|
|
81
|
-
newValue = value.filter(function (v) {
|
|
82
|
-
return v !== optionValue;
|
|
83
|
-
});
|
|
84
|
-
} else {
|
|
85
|
-
newValue = value.concat(optionValue);
|
|
86
|
-
}
|
|
48
|
+
const ListBoxContextProvider = ({
|
|
49
|
+
children
|
|
50
|
+
}) => /*#__PURE__*/React.createElement(hideScrollBarsFromScreenReadersContext.Provider, {
|
|
51
|
+
value: true
|
|
52
|
+
}, children);
|
|
53
|
+
class RootSelect extends AbstractDropdown {
|
|
54
|
+
constructor(...args) {
|
|
55
|
+
super(...args);
|
|
56
|
+
_defineProperty(this, "role", 'listbox');
|
|
57
|
+
_defineProperty(this, "bindHandlerOptionClick", (optionValue, index) => e => {
|
|
58
|
+
let newValue = optionValue;
|
|
59
|
+
const {
|
|
60
|
+
value,
|
|
61
|
+
multiselect
|
|
62
|
+
} = this.asProps;
|
|
63
|
+
if (Array.isArray(value)) {
|
|
64
|
+
if (value.includes(optionValue)) {
|
|
65
|
+
newValue = value.filter(v => v !== optionValue);
|
|
66
|
+
} else {
|
|
67
|
+
newValue = value.concat(optionValue);
|
|
87
68
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
69
|
+
}
|
|
70
|
+
this.handlers.highlightedIndex(index);
|
|
71
|
+
this.handlers.value(newValue, e);
|
|
72
|
+
if (!multiselect) {
|
|
73
|
+
this.handlers.visible(false);
|
|
74
|
+
e.preventDefault();
|
|
75
|
+
}
|
|
95
76
|
});
|
|
96
|
-
_defineProperty(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
77
|
+
_defineProperty(this, "handlerClear", e => {
|
|
78
|
+
const {
|
|
79
|
+
value
|
|
80
|
+
} = this.asProps;
|
|
81
|
+
const emptyValue = getEmptyValue(Array.isArray(value));
|
|
82
|
+
this.handlers.value(emptyValue, e);
|
|
83
|
+
this.handlers.visible(false);
|
|
101
84
|
});
|
|
102
|
-
return _this;
|
|
103
85
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
this.scrollToNode(node);
|
|
113
|
-
}
|
|
86
|
+
itemRef(props, index, node) {
|
|
87
|
+
super.itemRef(props, index, node);
|
|
88
|
+
const {
|
|
89
|
+
highlightedIndex
|
|
90
|
+
} = this.asProps;
|
|
91
|
+
const isHighlighted = index === highlightedIndex;
|
|
92
|
+
if (isHighlighted) {
|
|
93
|
+
this.scrollToNode(node);
|
|
114
94
|
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
visible
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
_this2.handlers.highlightedIndex(i);
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
95
|
+
}
|
|
96
|
+
uncontrolledProps() {
|
|
97
|
+
return {
|
|
98
|
+
...super.uncontrolledProps(),
|
|
99
|
+
visible: [null, visible => {
|
|
100
|
+
if (visible === true) {
|
|
101
|
+
const hasInputSearch = isAdvanceMode(this.asProps.Children, [Select.InputSearch.displayName, InputSearch.displayName], true);
|
|
102
|
+
const defaultIndex = hasInputSearch || lastInteraction.isMouse() ? null : this.props.defaultHighlightedIndex;
|
|
103
|
+
this.handlers.highlightedIndex(defaultIndex);
|
|
104
|
+
setTimeout(() => {
|
|
105
|
+
const options = this.menuRef.current?.querySelectorAll('[role="option"]');
|
|
106
|
+
const selected = this.menuRef.current?.querySelector('[aria-selected="true"]');
|
|
107
|
+
if (selected && options) {
|
|
108
|
+
this.scrollToNode(selected);
|
|
109
|
+
for (let i = 0; i < options.length; i++) {
|
|
110
|
+
if (options[i] === selected) {
|
|
111
|
+
this.handlers.highlightedIndex(i);
|
|
112
|
+
break;
|
|
136
113
|
}
|
|
137
114
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
115
|
+
}
|
|
116
|
+
// for some reason, Google Chrome optimizes this timeout with 0 value with previous render (when we set aria-selected)
|
|
117
|
+
// and that's why its skip scrollToNodes. We selected the appropriate timeout manually.
|
|
118
|
+
}, 30);
|
|
119
|
+
}
|
|
120
|
+
}],
|
|
121
|
+
value: null
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
getTriggerProps() {
|
|
125
|
+
const {
|
|
126
|
+
disabled,
|
|
127
|
+
visible,
|
|
128
|
+
state,
|
|
129
|
+
placeholder,
|
|
130
|
+
value,
|
|
131
|
+
options,
|
|
132
|
+
forwardRef,
|
|
133
|
+
name,
|
|
134
|
+
multiselect,
|
|
135
|
+
getI18nText,
|
|
136
|
+
highlightedIndex,
|
|
137
|
+
uid,
|
|
138
|
+
Children,
|
|
139
|
+
children: hasChildren
|
|
140
|
+
} = this.asProps;
|
|
141
|
+
const isMenu = isAdvanceMode(Children, [Select.Menu.displayName], true) || !hasChildren;
|
|
142
|
+
const ariaControls = isMenu ? `igc-${uid}-list` : `igc-${uid}-popper`;
|
|
143
|
+
return {
|
|
144
|
+
...super.getTriggerProps(),
|
|
145
|
+
'onKeyDown': callAllEventHandlers(this.handlePreventCommonKeyDown.bind(this), this.handleOpenKeyDown.bind(this), this.handleArrowKeyDown.bind(this)),
|
|
146
|
+
'aria-controls': visible ? ariaControls : undefined,
|
|
147
|
+
'aria-haspopup': isMenu ? 'listbox' : 'dialog',
|
|
148
|
+
'aria-disabled': disabled ? 'true' : 'false',
|
|
149
|
+
'aria-activedescendant': visible && highlightedIndex !== null && this.itemRefs[highlightedIndex] ? `igc-${uid}-option-${highlightedIndex}` : undefined,
|
|
150
|
+
'empty': isEmptyValue(value),
|
|
151
|
+
value,
|
|
152
|
+
name,
|
|
153
|
+
'$hiddenRef': forwardRef,
|
|
154
|
+
multiselect,
|
|
155
|
+
state,
|
|
156
|
+
placeholder,
|
|
157
|
+
disabled,
|
|
158
|
+
'active': visible,
|
|
159
|
+
'onClear': this.handlerClear,
|
|
160
|
+
'children': this.renderChildrenTrigger(value, options),
|
|
161
|
+
getI18nText,
|
|
162
|
+
'onBlur': () => {
|
|
163
|
+
// if popper is opened and we moved from the trigger in select - it means we moved on some controls in popper and should hide highlighted for the option
|
|
164
|
+
if (this.asProps.visible) {
|
|
165
|
+
this.prevHighlightedIndex = this.asProps.highlightedIndex;
|
|
166
|
+
this.handlers.highlightedIndex(null);
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
'onFocus': () => {
|
|
170
|
+
// if popper is opened and we moved to the trigger in select - it means we moved from some controls in popper and should highlight the last highlighted option
|
|
171
|
+
if (this.asProps.visible) {
|
|
172
|
+
const index = this.prevHighlightedIndex;
|
|
173
|
+
this.handlers.highlightedIndex(index);
|
|
198
174
|
}
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
}, {
|
|
202
|
-
key: "getListProps",
|
|
203
|
-
value: function getListProps() {
|
|
204
|
-
var multiselect = this.asProps.multiselect;
|
|
205
|
-
return _objectSpread(_objectSpread({}, _superPropGet(RootSelect, "getListProps", this, 3)([])), {}, {
|
|
206
|
-
'aria-multiselectable': multiselect ? 'true' : undefined
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
}, {
|
|
210
|
-
key: "getPopperProps",
|
|
211
|
-
value: function getPopperProps() {
|
|
212
|
-
return _objectSpread(_objectSpread({}, _superPropGet(RootSelect, "getPopperProps", this, 3)([])), {}, {
|
|
213
|
-
onKeyDown: callAllEventHandlers(this.handlePreventCommonKeyDown.bind(this), this.handlePreventPopperKeyDown.bind(this), this.handleArrowKeyDown.bind(this))
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
}, {
|
|
217
|
-
key: "getOptionProps",
|
|
218
|
-
value: function getOptionProps(props, index) {
|
|
219
|
-
var _props$selected,
|
|
220
|
-
_this4 = this;
|
|
221
|
-
var _this$asProps3 = this.asProps,
|
|
222
|
-
value = _this$asProps3.value,
|
|
223
|
-
highlightedIndex = _this$asProps3.highlightedIndex,
|
|
224
|
-
_this$asProps3$size = _this$asProps3.size,
|
|
225
|
-
size = _this$asProps3$size === void 0 ? 'm' : _this$asProps3$size;
|
|
226
|
-
var highlighted = index === highlightedIndex && lastInteraction.isKeyboard() && !props.disabled;
|
|
227
|
-
var selected = (_props$selected = props.selected) !== null && _props$selected !== void 0 ? _props$selected : isSelectedOption(value, props.value);
|
|
228
|
-
return _objectSpread(_objectSpread({}, _superPropGet(RootSelect, "getItemProps", this, 3)([props, index])), {}, {
|
|
229
|
-
highlighted: highlighted,
|
|
230
|
-
selected: selected,
|
|
231
|
-
'aria-selected': selected ? 'true' : 'false',
|
|
232
|
-
'aria-disabled': props.disabled ? 'true' : 'false',
|
|
233
|
-
'role': 'option',
|
|
234
|
-
'onClick': this.bindHandlerOptionClick(props.value, index),
|
|
235
|
-
'ref': function ref(node) {
|
|
236
|
-
return _this4.itemRef(props, index, node);
|
|
237
|
-
},
|
|
238
|
-
size: size
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
}, {
|
|
242
|
-
key: "getOptionCheckboxProps",
|
|
243
|
-
value: function getOptionCheckboxProps() {
|
|
244
|
-
var _this$asProps4 = this.asProps,
|
|
245
|
-
size = _this$asProps4.size,
|
|
246
|
-
resolveColor = _this$asProps4.resolveColor;
|
|
247
|
-
return {
|
|
248
|
-
size: size,
|
|
249
|
-
resolveColor: resolveColor
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
}, {
|
|
253
|
-
key: "getDividerProps",
|
|
254
|
-
value: function getDividerProps() {
|
|
255
|
-
return {
|
|
256
|
-
'my': 1,
|
|
257
|
-
'aria-disabled': 'true'
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
}, {
|
|
261
|
-
key: "renderChildrenTrigger",
|
|
262
|
-
value: function renderChildrenTrigger(value, options) {
|
|
263
|
-
if (options) {
|
|
264
|
-
return [].concat(value).reduce(function (acc, value) {
|
|
265
|
-
var selectedOption = options.find(function (o) {
|
|
266
|
-
return isSelectedOption(value, o.value);
|
|
267
|
-
});
|
|
268
|
-
if (!selectedOption) return acc;
|
|
269
|
-
if (acc.length) acc.push(', ');
|
|
270
|
-
acc.push(selectedOption.label || selectedOption.value);
|
|
271
|
-
return acc;
|
|
272
|
-
}, []);
|
|
273
175
|
}
|
|
274
|
-
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
getListProps() {
|
|
179
|
+
const {
|
|
180
|
+
multiselect
|
|
181
|
+
} = this.asProps;
|
|
182
|
+
return {
|
|
183
|
+
...super.getListProps(),
|
|
184
|
+
'aria-multiselectable': multiselect ? 'true' : undefined
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
getPopperProps() {
|
|
188
|
+
return {
|
|
189
|
+
...super.getPopperProps(),
|
|
190
|
+
onKeyDown: callAllEventHandlers(this.handlePreventCommonKeyDown.bind(this), this.handlePreventPopperKeyDown.bind(this), this.handleArrowKeyDown.bind(this))
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
getOptionProps(props, index) {
|
|
194
|
+
const {
|
|
195
|
+
value,
|
|
196
|
+
highlightedIndex,
|
|
197
|
+
size = 'm'
|
|
198
|
+
} = this.asProps;
|
|
199
|
+
const highlighted = index === highlightedIndex && lastInteraction.isKeyboard() && !props.disabled;
|
|
200
|
+
const selected = props.selected ?? isSelectedOption(value, props.value);
|
|
201
|
+
return {
|
|
202
|
+
...super.getItemProps(props, index),
|
|
203
|
+
highlighted,
|
|
204
|
+
selected,
|
|
205
|
+
'aria-selected': selected ? 'true' : 'false',
|
|
206
|
+
'aria-disabled': props.disabled ? 'true' : 'false',
|
|
207
|
+
'role': 'option',
|
|
208
|
+
'onClick': this.bindHandlerOptionClick(props.value, index),
|
|
209
|
+
'ref': node => this.itemRef(props, index, node),
|
|
210
|
+
size
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
getOptionCheckboxProps() {
|
|
214
|
+
const {
|
|
215
|
+
size,
|
|
216
|
+
resolveColor
|
|
217
|
+
} = this.asProps;
|
|
218
|
+
return {
|
|
219
|
+
size,
|
|
220
|
+
resolveColor
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
getDividerProps() {
|
|
224
|
+
return {
|
|
225
|
+
'my': 1,
|
|
226
|
+
'aria-disabled': 'true'
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
renderChildrenTrigger(value, options) {
|
|
230
|
+
if (options) {
|
|
231
|
+
return [].concat(value).reduce((acc, value) => {
|
|
232
|
+
const selectedOption = options.find(o => isSelectedOption(value, o.value));
|
|
233
|
+
if (!selectedOption) return acc;
|
|
275
234
|
if (acc.length) acc.push(', ');
|
|
276
|
-
acc.push(value);
|
|
235
|
+
acc.push(selectedOption.label || selectedOption.value);
|
|
277
236
|
return acc;
|
|
278
|
-
}, [])
|
|
237
|
+
}, []);
|
|
279
238
|
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
239
|
+
return Array.isArray(value) ? value.reduce((acc, value) => {
|
|
240
|
+
if (acc.length) acc.push(', ');
|
|
241
|
+
acc.push(value);
|
|
242
|
+
return acc;
|
|
243
|
+
}, []) : value;
|
|
244
|
+
}
|
|
245
|
+
render() {
|
|
246
|
+
var _ref2 = this.asProps;
|
|
247
|
+
const {
|
|
248
|
+
Children,
|
|
249
|
+
options,
|
|
250
|
+
multiselect,
|
|
251
|
+
value: _value,
|
|
252
|
+
uid,
|
|
253
|
+
forcedAdvancedMode,
|
|
254
|
+
...other
|
|
255
|
+
} = this.asProps;
|
|
256
|
+
const advancedMode = forcedAdvancedMode || findComponent(Children, [Select.Trigger.displayName, Select.Popper.displayName]);
|
|
257
|
+
logger.warn(options && advancedMode, 'Don\'t use at the same time \'options\' property and \'<Select.Trigger/>/<Select.Popper/>\'', other['data-ui-name'] || Select.displayName);
|
|
258
|
+
this.itemProps = [];
|
|
259
|
+
if (options) {
|
|
260
|
+
var _ref = this.asProps;
|
|
261
|
+
return /*#__PURE__*/React.createElement(DropdownMenu, _assignProps({}, _ref), /*#__PURE__*/React.createElement(Select.Trigger, other), /*#__PURE__*/React.createElement(Select.Menu, null, options.map((option, index) => {
|
|
262
|
+
return /*#__PURE__*/React.createElement(Select.Option, _extends({
|
|
263
|
+
key: option.value,
|
|
264
|
+
id: `igc-${uid}-option-${index}`
|
|
265
|
+
}, option), multiselect && /*#__PURE__*/React.createElement(Select.Option.Checkbox, null), option.children);
|
|
266
|
+
})));
|
|
305
267
|
}
|
|
306
|
-
|
|
307
|
-
}
|
|
268
|
+
return /*#__PURE__*/React.createElement(DropdownMenu, _assignProps2({}, _ref2), /*#__PURE__*/React.createElement(Children, null));
|
|
269
|
+
}
|
|
270
|
+
}
|
|
308
271
|
_defineProperty(RootSelect, "displayName", 'Select');
|
|
309
272
|
_defineProperty(RootSelect, "style", style);
|
|
310
273
|
_defineProperty(RootSelect, "enhance", Object.values(enhance).concat([resolveColorEnhance()]));
|
|
311
|
-
_defineProperty(RootSelect, "defaultProps",
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
var defaultIndex = hasInputSearch ? null : 0;
|
|
274
|
+
_defineProperty(RootSelect, "defaultProps", props => {
|
|
275
|
+
const hasInputSearch = props.children && isAdvanceMode(props.children, [Select.InputSearch.displayName, InputSearch.displayName], true);
|
|
276
|
+
const defaultIndex = hasInputSearch ? null : 0;
|
|
315
277
|
return {
|
|
316
278
|
placeholder: props.multiselect ? 'Select options' : 'Select option',
|
|
317
279
|
size: 'm',
|
|
318
280
|
defaultValue: getEmptyValue(props.multiselect),
|
|
319
281
|
defaultVisible: false,
|
|
320
|
-
defaultHighlightedIndex:
|
|
321
|
-
defaultSelectedIndex:
|
|
282
|
+
defaultHighlightedIndex: props.highlightedIndex ?? defaultIndex,
|
|
283
|
+
defaultSelectedIndex: props.selectedIndex ?? defaultIndex,
|
|
322
284
|
scrollToSelected: true,
|
|
323
285
|
i18n: localizedMessages,
|
|
324
286
|
locale: 'en',
|
|
325
|
-
interaction:
|
|
287
|
+
interaction: props.interaction ?? 'click',
|
|
326
288
|
inlineActions: false,
|
|
327
|
-
timeout:
|
|
289
|
+
timeout: props.timeout ?? 0
|
|
328
290
|
};
|
|
329
291
|
});
|
|
330
|
-
function Trigger(
|
|
292
|
+
function Trigger({
|
|
293
|
+
Children,
|
|
294
|
+
name,
|
|
295
|
+
value,
|
|
296
|
+
styles,
|
|
297
|
+
$hiddenRef,
|
|
298
|
+
tag: Tag = ButtonTrigger,
|
|
299
|
+
getI18nText
|
|
300
|
+
}) {
|
|
331
301
|
var _ref3 = arguments[0],
|
|
332
302
|
_ref7;
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
return _ref7 = sstyled(styles), /*#__PURE__*/React.createElement(SSelectTrigger, _ref7.cn("SSelectTrigger", _objectSpread({}, _assignProps3({
|
|
344
|
-
"tag": Tag,
|
|
345
|
-
"placeholder": getI18nText('selectPlaceholder'),
|
|
346
|
-
"role": 'combobox',
|
|
347
|
-
"aria-autocomplete": hasInputTrigger && 'list' || undefined
|
|
348
|
-
}, _ref3))), addonTextChildren(Children, Tag.Text || Tag.Value || ButtonTrigger.Text, Tag.Addon || ButtonTrigger.Addon, true), name && /*#__PURE__*/React.createElement("input", _ref7.cn("input", {
|
|
303
|
+
const hasInputTrigger = isInputTriggerTag(Tag);
|
|
304
|
+
const SSelectTrigger = Dropdown.Trigger;
|
|
305
|
+
return _ref7 = sstyled(styles), /*#__PURE__*/React.createElement(SSelectTrigger, _ref7.cn("SSelectTrigger", {
|
|
306
|
+
..._assignProps3({
|
|
307
|
+
"tag": Tag,
|
|
308
|
+
"placeholder": getI18nText('selectPlaceholder'),
|
|
309
|
+
"role": 'combobox',
|
|
310
|
+
"aria-autocomplete": hasInputTrigger && 'list' || undefined
|
|
311
|
+
}, _ref3)
|
|
312
|
+
}), addonTextChildren(Children, Tag.Text || Tag.Value || ButtonTrigger.Text, Tag.Addon || ButtonTrigger.Addon, true), name && /*#__PURE__*/React.createElement("input", _ref7.cn("input", {
|
|
349
313
|
"type": 'hidden',
|
|
350
314
|
"defaultValue": value,
|
|
351
315
|
"name": name,
|
|
@@ -354,77 +318,114 @@ function Trigger(_ref0) {
|
|
|
354
318
|
}
|
|
355
319
|
function Menu(props) {
|
|
356
320
|
var _ref4 = arguments[0];
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
321
|
+
const {
|
|
322
|
+
visible,
|
|
323
|
+
disablePortal,
|
|
324
|
+
ignorePortalsStacking,
|
|
325
|
+
disableEnforceFocus,
|
|
326
|
+
interaction,
|
|
327
|
+
autoFocus,
|
|
328
|
+
animationsDisabled
|
|
329
|
+
} = props;
|
|
330
|
+
const popperProps = {
|
|
331
|
+
visible,
|
|
332
|
+
disablePortal,
|
|
333
|
+
ignorePortalsStacking,
|
|
334
|
+
disableEnforceFocus,
|
|
335
|
+
interaction,
|
|
336
|
+
autoFocus,
|
|
337
|
+
animationsDisabled
|
|
372
338
|
};
|
|
373
339
|
return /*#__PURE__*/React.createElement(ListBoxContextProvider, null, /*#__PURE__*/React.createElement(Select.Popper, _extends({}, popperProps, {
|
|
374
340
|
role: null
|
|
375
341
|
}), /*#__PURE__*/React.createElement(Select.List, _assignProps4({}, _ref4))));
|
|
376
342
|
}
|
|
377
|
-
|
|
343
|
+
const optionPropsContext = /*#__PURE__*/React.createContext({});
|
|
378
344
|
function Option(props) {
|
|
379
345
|
var _ref5 = arguments[0],
|
|
380
346
|
_ref8;
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
347
|
+
const SSelectOption = Dropdown.Item;
|
|
348
|
+
const {
|
|
349
|
+
styles,
|
|
350
|
+
Children,
|
|
351
|
+
highlighted
|
|
352
|
+
} = props;
|
|
353
|
+
const itemRef = React.useRef(null);
|
|
354
|
+
const hasCheckbox = isAdvanceMode(Children, [Select.Option.Checkbox.displayName]);
|
|
355
|
+
const hasContent = isAdvanceMode(Children, [Select.Option.Content.displayName]);
|
|
356
|
+
const optionPropsContextValue = {
|
|
357
|
+
...props,
|
|
358
|
+
itemRef,
|
|
359
|
+
highlighted
|
|
360
|
+
};
|
|
361
|
+
return _ref8 = sstyled(styles), /*#__PURE__*/React.createElement(SSelectOption, _ref8.cn("SSelectOption", {
|
|
362
|
+
..._assignProps5({
|
|
363
|
+
"ref": itemRef
|
|
364
|
+
}, _ref5)
|
|
365
|
+
}), /*#__PURE__*/React.createElement(optionPropsContext.Provider, {
|
|
366
|
+
value: optionPropsContextValue
|
|
388
367
|
}, hasCheckbox && !hasContent ? /*#__PURE__*/React.createElement(Select.Option.Content, null, /*#__PURE__*/React.createElement(Children, _ref8.cn("Children", {}))) : /*#__PURE__*/React.createElement(Children, _ref8.cn("Children", {}))));
|
|
389
368
|
}
|
|
390
369
|
function Checkbox(providedProps) {
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
style = _styles$cn.style;
|
|
370
|
+
const optionProps = React.useContext(optionPropsContext);
|
|
371
|
+
const props = React.useMemo(() => ({
|
|
372
|
+
selected: optionProps?.selected,
|
|
373
|
+
disabled: optionProps?.disabled,
|
|
374
|
+
size: optionProps?.size,
|
|
375
|
+
...(providedProps || {})
|
|
376
|
+
}), [providedProps, optionProps]);
|
|
377
|
+
const [SOptionCheckbox, componentProps] = useBox(props, props.forwardRef);
|
|
378
|
+
const {
|
|
379
|
+
size,
|
|
380
|
+
theme,
|
|
381
|
+
selected,
|
|
382
|
+
resolveColor,
|
|
383
|
+
indeterminate
|
|
384
|
+
} = props;
|
|
385
|
+
const styles = sstyled(props.styles);
|
|
386
|
+
const {
|
|
387
|
+
className,
|
|
388
|
+
style
|
|
389
|
+
} = styles.cn('SOptionCheckbox', {
|
|
390
|
+
size,
|
|
391
|
+
'use:theme': resolveColor(theme),
|
|
392
|
+
indeterminate,
|
|
393
|
+
selected
|
|
394
|
+
});
|
|
417
395
|
return /*#__PURE__*/React.createElement(SOptionCheckbox, _extends({}, componentProps, {
|
|
418
396
|
className: cn(className, componentProps.className) || undefined,
|
|
419
|
-
style:
|
|
397
|
+
style: {
|
|
398
|
+
...style,
|
|
399
|
+
...componentProps.style
|
|
400
|
+
},
|
|
420
401
|
tabIndex: -1
|
|
421
402
|
}));
|
|
422
403
|
}
|
|
423
|
-
|
|
404
|
+
function OptionText(providedProps) {
|
|
405
|
+
var _ref9;
|
|
406
|
+
const optionProps = React.useContext(optionPropsContext);
|
|
407
|
+
const selectedIndex = React.useContext(selectedIndexContext);
|
|
408
|
+
const props = React.useMemo(() => ({
|
|
409
|
+
key: optionProps?.id,
|
|
410
|
+
selected: optionProps?.selected,
|
|
411
|
+
disabled: optionProps?.disabled,
|
|
412
|
+
size: optionProps?.size,
|
|
413
|
+
hintProps: optionProps?.hintProps ?? {},
|
|
414
|
+
...(providedProps || {})
|
|
415
|
+
}), [providedProps, optionProps]);
|
|
416
|
+
if (optionProps.itemRef) {
|
|
417
|
+
props.hintProps.triggerRef = optionProps.itemRef;
|
|
418
|
+
}
|
|
419
|
+
props.hintProps.visible = selectedIndex === optionProps.index;
|
|
420
|
+
return _ref9 = sstyled(props.styles), /*#__PURE__*/React.createElement(Text, _ref9.cn("Text", {
|
|
421
|
+
...props
|
|
422
|
+
}));
|
|
423
|
+
}
|
|
424
|
+
const InputSearchWrapper = function () {
|
|
424
425
|
var _ref6 = arguments[0];
|
|
425
426
|
return /*#__PURE__*/React.createElement(InputSearch, _assignProps6({}, _ref6));
|
|
426
427
|
};
|
|
427
|
-
|
|
428
|
+
const Select = createComponent(RootSelect, {
|
|
428
429
|
Trigger: [Trigger, {
|
|
429
430
|
Addon: ButtonTrigger.Addon,
|
|
430
431
|
Text: ButtonTrigger.Text
|
|
@@ -435,22 +436,19 @@ var Select = createComponent(RootSelect, {
|
|
|
435
436
|
Option: [Option, {
|
|
436
437
|
Addon: DropdownMenu.Item.Addon,
|
|
437
438
|
Content: DropdownMenu.Item.Content,
|
|
439
|
+
Text: OptionText,
|
|
438
440
|
Hint: DropdownMenu.Item.Hint,
|
|
439
|
-
Checkbox
|
|
441
|
+
Checkbox
|
|
440
442
|
}],
|
|
441
443
|
Group: Dropdown.Group,
|
|
442
|
-
|
|
443
|
-
OptionHint: DropdownMenu.ItemHint,
|
|
444
|
-
Divider: Divider,
|
|
444
|
+
Divider,
|
|
445
445
|
InputSearch: [InputSearchWrapper, InputSearch._______childrenComponents],
|
|
446
446
|
Input: [InputSearchWrapper, InputSearch._______childrenComponents]
|
|
447
447
|
}, {
|
|
448
448
|
parent: DropdownMenu,
|
|
449
449
|
context: selectContext
|
|
450
450
|
});
|
|
451
|
-
export
|
|
452
|
-
return wrapper;
|
|
453
|
-
};
|
|
451
|
+
export const wrapSelect = wrapper => wrapper;
|
|
454
452
|
Select.selectedIndexContext = selectedIndexContext;
|
|
455
453
|
export default Select;
|
|
456
454
|
//# sourceMappingURL=Select.js.map
|