@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/esm/Select.mjs
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
-
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
4
|
-
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
5
|
-
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
6
|
-
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
7
|
-
import _callSuper from "@babel/runtime/helpers/esm/callSuper";
|
|
8
|
-
import _superPropGet from "@babel/runtime/helpers/esm/superPropGet";
|
|
9
|
-
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
10
2
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
11
3
|
import { sstyled, createComponent, lastInteraction, assignProps } from "@semcore/core";
|
|
12
|
-
import { hideScrollBarsFromScreenReadersContext } from "@semcore/base-components";
|
|
4
|
+
import { useBox, isInputTriggerTag, hideScrollBarsFromScreenReadersContext } from "@semcore/base-components";
|
|
13
5
|
import { ButtonTrigger } from "@semcore/base-trigger";
|
|
14
6
|
import addonTextChildren from "@semcore/core/lib/utils/addonTextChildren";
|
|
15
7
|
import { callAllEventHandlers } from "@semcore/core/lib/utils/assignProps";
|
|
@@ -19,31 +11,29 @@ import logger from "@semcore/core/lib/utils/logger";
|
|
|
19
11
|
import Divider from "@semcore/divider";
|
|
20
12
|
import Dropdown, { enhance, selectedIndexContext, AbstractDropdown } from "@semcore/dropdown";
|
|
21
13
|
import DropdownMenu from "@semcore/dropdown-menu";
|
|
22
|
-
import {
|
|
23
|
-
import { isInputTriggerTag } from "@semcore/popper";
|
|
14
|
+
import { Text } from "@semcore/typography";
|
|
24
15
|
import cn from "classnames";
|
|
25
16
|
import React from "react";
|
|
26
17
|
import { selectContext } from "./context.mjs";
|
|
27
18
|
import InputSearch from "./InputSearch.mjs";
|
|
28
19
|
import { localizedMessages } from "./translations/__intergalactic-dynamic-locales.mjs";
|
|
29
|
-
var _excluded = ["Children", "options", "multiselect", "value", "uid", "forcedAdvancedMode"];
|
|
30
20
|
/*!__reshadow-styles__:"./style/select.shadow.css"*/
|
|
31
|
-
|
|
21
|
+
const style = (
|
|
32
22
|
/*__reshadow_css_start__*/
|
|
33
23
|
(sstyled.insert(
|
|
34
24
|
/*__inner_css_start__*/
|
|
35
|
-
'.
|
|
25
|
+
'.___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}',
|
|
36
26
|
/*__inner_css_end__*/
|
|
37
|
-
"
|
|
27
|
+
"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
|
);
|
|
49
39
|
function isSelectedOption(value, valueOption) {
|
|
@@ -55,257 +45,267 @@ 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
|
-
if (value.includes(optionValue)) {
|
|
79
|
-
newValue = value.filter(function(v) {
|
|
80
|
-
return v !== optionValue;
|
|
81
|
-
});
|
|
82
|
-
} else {
|
|
83
|
-
newValue = value.concat(optionValue);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
_this.handlers.highlightedIndex(index);
|
|
87
|
-
_this.handlers.value(newValue, e);
|
|
88
|
-
if (!multiselect) {
|
|
89
|
-
_this.handlers.visible(false);
|
|
90
|
-
e.preventDefault();
|
|
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);
|
|
91
68
|
}
|
|
92
|
-
}
|
|
69
|
+
}
|
|
70
|
+
this.handlers.highlightedIndex(index);
|
|
71
|
+
this.handlers.value(newValue, e);
|
|
72
|
+
if (!multiselect) {
|
|
73
|
+
this.handlers.visible(false);
|
|
74
|
+
e.preventDefault();
|
|
75
|
+
}
|
|
93
76
|
});
|
|
94
|
-
_defineProperty(
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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);
|
|
99
84
|
});
|
|
100
|
-
return _this;
|
|
101
85
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
this.scrollToNode(node);
|
|
111
|
-
}
|
|
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);
|
|
112
94
|
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
visible
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
break;
|
|
133
|
-
}
|
|
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
|
+
var _a, _b;
|
|
106
|
+
const options = (_a = this.menuRef.current) == null ? void 0 : _a.querySelectorAll('[role="option"]');
|
|
107
|
+
const selected = (_b = this.menuRef.current) == null ? void 0 : _b.querySelector('[aria-selected="true"]');
|
|
108
|
+
if (selected && options) {
|
|
109
|
+
this.scrollToNode(selected);
|
|
110
|
+
for (let i = 0; i < options.length; i++) {
|
|
111
|
+
if (options[i] === selected) {
|
|
112
|
+
this.handlers.highlightedIndex(i);
|
|
113
|
+
break;
|
|
134
114
|
}
|
|
135
115
|
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
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
|
-
|
|
116
|
+
}
|
|
117
|
+
}, 30);
|
|
118
|
+
}
|
|
119
|
+
}],
|
|
120
|
+
value: null
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
getTriggerProps() {
|
|
124
|
+
const {
|
|
125
|
+
disabled,
|
|
126
|
+
visible,
|
|
127
|
+
state,
|
|
128
|
+
placeholder,
|
|
129
|
+
value,
|
|
130
|
+
options,
|
|
131
|
+
forwardRef,
|
|
132
|
+
name,
|
|
133
|
+
multiselect,
|
|
134
|
+
getI18nText,
|
|
135
|
+
highlightedIndex,
|
|
136
|
+
uid,
|
|
137
|
+
Children,
|
|
138
|
+
children: hasChildren
|
|
139
|
+
} = this.asProps;
|
|
140
|
+
const isMenu = isAdvanceMode(Children, [Select.Menu.displayName], true) || !hasChildren;
|
|
141
|
+
const ariaControls = isMenu ? `igc-${uid}-list` : `igc-${uid}-popper`;
|
|
142
|
+
return {
|
|
143
|
+
...super.getTriggerProps(),
|
|
144
|
+
"onKeyDown": callAllEventHandlers(this.handlePreventCommonKeyDown.bind(this), this.handleOpenKeyDown.bind(this), this.handleArrowKeyDown.bind(this)),
|
|
145
|
+
"aria-controls": visible ? ariaControls : void 0,
|
|
146
|
+
"aria-haspopup": isMenu ? "listbox" : "dialog",
|
|
147
|
+
"aria-disabled": disabled ? "true" : "false",
|
|
148
|
+
"aria-activedescendant": visible && highlightedIndex !== null && this.itemRefs[highlightedIndex] ? `igc-${uid}-option-${highlightedIndex}` : void 0,
|
|
149
|
+
"empty": isEmptyValue(value),
|
|
150
|
+
value,
|
|
151
|
+
name,
|
|
152
|
+
"$hiddenRef": forwardRef,
|
|
153
|
+
multiselect,
|
|
154
|
+
state,
|
|
155
|
+
placeholder,
|
|
156
|
+
disabled,
|
|
157
|
+
"active": visible,
|
|
158
|
+
"onClear": this.handlerClear,
|
|
159
|
+
"children": this.renderChildrenTrigger(value, options),
|
|
160
|
+
getI18nText,
|
|
161
|
+
"onBlur": () => {
|
|
162
|
+
if (this.asProps.visible) {
|
|
163
|
+
this.prevHighlightedIndex = this.asProps.highlightedIndex;
|
|
164
|
+
this.handlers.highlightedIndex(null);
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
"onFocus": () => {
|
|
168
|
+
if (this.asProps.visible) {
|
|
169
|
+
const index = this.prevHighlightedIndex;
|
|
170
|
+
this.handlers.highlightedIndex(index);
|
|
178
171
|
}
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
}, {
|
|
182
|
-
key: "getListProps",
|
|
183
|
-
value: function getListProps() {
|
|
184
|
-
var multiselect = this.asProps.multiselect;
|
|
185
|
-
return _objectSpread(_objectSpread({}, _superPropGet(RootSelect2, "getListProps", this, 3)([])), {}, {
|
|
186
|
-
"aria-multiselectable": multiselect ? "true" : void 0
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
}, {
|
|
190
|
-
key: "getPopperProps",
|
|
191
|
-
value: function getPopperProps() {
|
|
192
|
-
return _objectSpread(_objectSpread({}, _superPropGet(RootSelect2, "getPopperProps", this, 3)([])), {}, {
|
|
193
|
-
onKeyDown: callAllEventHandlers(this.handlePreventCommonKeyDown.bind(this), this.handlePreventPopperKeyDown.bind(this), this.handleArrowKeyDown.bind(this))
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
}, {
|
|
197
|
-
key: "getOptionProps",
|
|
198
|
-
value: function getOptionProps(props, index) {
|
|
199
|
-
var _props$selected, _this4 = this;
|
|
200
|
-
var _this$asProps3 = this.asProps, value = _this$asProps3.value, highlightedIndex = _this$asProps3.highlightedIndex, _this$asProps3$size = _this$asProps3.size, size = _this$asProps3$size === void 0 ? "m" : _this$asProps3$size;
|
|
201
|
-
var highlighted = index === highlightedIndex && lastInteraction.isKeyboard() && !props.disabled;
|
|
202
|
-
var selected = (_props$selected = props.selected) !== null && _props$selected !== void 0 ? _props$selected : isSelectedOption(value, props.value);
|
|
203
|
-
return _objectSpread(_objectSpread({}, _superPropGet(RootSelect2, "getItemProps", this, 3)([props, index])), {}, {
|
|
204
|
-
highlighted,
|
|
205
|
-
selected,
|
|
206
|
-
"aria-selected": selected ? "true" : "false",
|
|
207
|
-
"aria-disabled": props.disabled ? "true" : "false",
|
|
208
|
-
"role": "option",
|
|
209
|
-
"onClick": this.bindHandlerOptionClick(props.value, index),
|
|
210
|
-
"ref": function ref(node) {
|
|
211
|
-
return _this4.itemRef(props, index, node);
|
|
212
|
-
},
|
|
213
|
-
size
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
}, {
|
|
217
|
-
key: "getOptionCheckboxProps",
|
|
218
|
-
value: function getOptionCheckboxProps() {
|
|
219
|
-
var _this$asProps4 = this.asProps, size = _this$asProps4.size, resolveColor = _this$asProps4.resolveColor;
|
|
220
|
-
return {
|
|
221
|
-
size,
|
|
222
|
-
resolveColor
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
}, {
|
|
226
|
-
key: "getDividerProps",
|
|
227
|
-
value: function getDividerProps() {
|
|
228
|
-
return {
|
|
229
|
-
"my": 1,
|
|
230
|
-
"aria-disabled": "true"
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
}, {
|
|
234
|
-
key: "renderChildrenTrigger",
|
|
235
|
-
value: function renderChildrenTrigger(value, options) {
|
|
236
|
-
if (options) {
|
|
237
|
-
return [].concat(value).reduce(function(acc, value2) {
|
|
238
|
-
var selectedOption = options.find(function(o) {
|
|
239
|
-
return isSelectedOption(value2, o.value);
|
|
240
|
-
});
|
|
241
|
-
if (!selectedOption) return acc;
|
|
242
|
-
if (acc.length) acc.push(", ");
|
|
243
|
-
acc.push(selectedOption.label || selectedOption.value);
|
|
244
|
-
return acc;
|
|
245
|
-
}, []);
|
|
246
172
|
}
|
|
247
|
-
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
getListProps() {
|
|
176
|
+
const {
|
|
177
|
+
multiselect
|
|
178
|
+
} = this.asProps;
|
|
179
|
+
return {
|
|
180
|
+
...super.getListProps(),
|
|
181
|
+
"aria-multiselectable": multiselect ? "true" : void 0
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
getPopperProps() {
|
|
185
|
+
return {
|
|
186
|
+
...super.getPopperProps(),
|
|
187
|
+
onKeyDown: callAllEventHandlers(this.handlePreventCommonKeyDown.bind(this), this.handlePreventPopperKeyDown.bind(this), this.handleArrowKeyDown.bind(this))
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
getOptionProps(props, index) {
|
|
191
|
+
const {
|
|
192
|
+
value,
|
|
193
|
+
highlightedIndex,
|
|
194
|
+
size = "m"
|
|
195
|
+
} = this.asProps;
|
|
196
|
+
const highlighted = index === highlightedIndex && lastInteraction.isKeyboard() && !props.disabled;
|
|
197
|
+
const selected = props.selected ?? isSelectedOption(value, props.value);
|
|
198
|
+
return {
|
|
199
|
+
...super.getItemProps(props, index),
|
|
200
|
+
highlighted,
|
|
201
|
+
selected,
|
|
202
|
+
"aria-selected": selected ? "true" : "false",
|
|
203
|
+
"aria-disabled": props.disabled ? "true" : "false",
|
|
204
|
+
"role": "option",
|
|
205
|
+
"onClick": this.bindHandlerOptionClick(props.value, index),
|
|
206
|
+
"ref": (node) => this.itemRef(props, index, node),
|
|
207
|
+
size
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
getOptionCheckboxProps() {
|
|
211
|
+
const {
|
|
212
|
+
size,
|
|
213
|
+
resolveColor
|
|
214
|
+
} = this.asProps;
|
|
215
|
+
return {
|
|
216
|
+
size,
|
|
217
|
+
resolveColor
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
getDividerProps() {
|
|
221
|
+
return {
|
|
222
|
+
"my": 1,
|
|
223
|
+
"aria-disabled": "true"
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
renderChildrenTrigger(value, options) {
|
|
227
|
+
if (options) {
|
|
228
|
+
return [].concat(value).reduce((acc, value2) => {
|
|
229
|
+
const selectedOption = options.find((o) => isSelectedOption(value2, o.value));
|
|
230
|
+
if (!selectedOption) return acc;
|
|
248
231
|
if (acc.length) acc.push(", ");
|
|
249
|
-
acc.push(
|
|
232
|
+
acc.push(selectedOption.label || selectedOption.value);
|
|
250
233
|
return acc;
|
|
251
|
-
}, [])
|
|
234
|
+
}, []);
|
|
252
235
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
236
|
+
return Array.isArray(value) ? value.reduce((acc, value2) => {
|
|
237
|
+
if (acc.length) acc.push(", ");
|
|
238
|
+
acc.push(value2);
|
|
239
|
+
return acc;
|
|
240
|
+
}, []) : value;
|
|
241
|
+
}
|
|
242
|
+
render() {
|
|
243
|
+
var _ref2 = this.asProps;
|
|
244
|
+
const {
|
|
245
|
+
Children,
|
|
246
|
+
options,
|
|
247
|
+
multiselect,
|
|
248
|
+
value: _value,
|
|
249
|
+
uid,
|
|
250
|
+
forcedAdvancedMode,
|
|
251
|
+
...other
|
|
252
|
+
} = this.asProps;
|
|
253
|
+
const advancedMode = forcedAdvancedMode || findComponent(Children, [Select.Trigger.displayName, Select.Popper.displayName]);
|
|
254
|
+
logger.warn(options && advancedMode, "Don't use at the same time 'options' property and '<Select.Trigger/>/<Select.Popper/>'", other["data-ui-name"] || Select.displayName);
|
|
255
|
+
this.itemProps = [];
|
|
256
|
+
if (options) {
|
|
257
|
+
var _ref = this.asProps;
|
|
258
|
+
return /* @__PURE__ */ React.createElement(DropdownMenu, assignProps({}, _ref), /* @__PURE__ */ React.createElement(Select.Trigger, other), /* @__PURE__ */ React.createElement(Select.Menu, null, options.map((option, index) => {
|
|
259
|
+
return /* @__PURE__ */ React.createElement(Select.Option, _extends({
|
|
260
|
+
key: option.value,
|
|
261
|
+
id: `igc-${uid}-option-${index}`
|
|
262
|
+
}, option), multiselect && /* @__PURE__ */ React.createElement(Select.Option.Checkbox, null), option.children);
|
|
263
|
+
})));
|
|
273
264
|
}
|
|
274
|
-
|
|
275
|
-
}
|
|
265
|
+
return /* @__PURE__ */ React.createElement(DropdownMenu, assignProps({}, _ref2), /* @__PURE__ */ React.createElement(Children, null));
|
|
266
|
+
}
|
|
267
|
+
}
|
|
276
268
|
_defineProperty(RootSelect, "displayName", "Select");
|
|
277
269
|
_defineProperty(RootSelect, "style", style);
|
|
278
270
|
_defineProperty(RootSelect, "enhance", Object.values(enhance).concat([resolveColorEnhance()]));
|
|
279
|
-
_defineProperty(RootSelect, "defaultProps",
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
var defaultIndex = hasInputSearch ? null : 0;
|
|
271
|
+
_defineProperty(RootSelect, "defaultProps", (props) => {
|
|
272
|
+
const hasInputSearch = props.children && isAdvanceMode(props.children, [Select.InputSearch.displayName, InputSearch.displayName], true);
|
|
273
|
+
const defaultIndex = hasInputSearch ? null : 0;
|
|
283
274
|
return {
|
|
284
275
|
placeholder: props.multiselect ? "Select options" : "Select option",
|
|
285
276
|
size: "m",
|
|
286
277
|
defaultValue: getEmptyValue(props.multiselect),
|
|
287
278
|
defaultVisible: false,
|
|
288
|
-
defaultHighlightedIndex:
|
|
289
|
-
defaultSelectedIndex:
|
|
279
|
+
defaultHighlightedIndex: props.highlightedIndex ?? defaultIndex,
|
|
280
|
+
defaultSelectedIndex: props.selectedIndex ?? defaultIndex,
|
|
290
281
|
scrollToSelected: true,
|
|
291
282
|
i18n: localizedMessages,
|
|
292
283
|
locale: "en",
|
|
293
|
-
interaction:
|
|
284
|
+
interaction: props.interaction ?? "click",
|
|
294
285
|
inlineActions: false,
|
|
295
|
-
timeout:
|
|
286
|
+
timeout: props.timeout ?? 0
|
|
296
287
|
};
|
|
297
288
|
});
|
|
298
|
-
function Trigger(
|
|
289
|
+
function Trigger({
|
|
290
|
+
Children,
|
|
291
|
+
name,
|
|
292
|
+
value,
|
|
293
|
+
styles,
|
|
294
|
+
$hiddenRef,
|
|
295
|
+
tag: Tag = ButtonTrigger,
|
|
296
|
+
getI18nText
|
|
297
|
+
}) {
|
|
299
298
|
var _ref3 = arguments[0], _ref7;
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
299
|
+
const hasInputTrigger = isInputTriggerTag(Tag);
|
|
300
|
+
const SSelectTrigger = Dropdown.Trigger;
|
|
301
|
+
return _ref7 = sstyled(styles), /* @__PURE__ */ React.createElement(SSelectTrigger, _ref7.cn("SSelectTrigger", {
|
|
302
|
+
...assignProps({
|
|
303
|
+
"tag": Tag,
|
|
304
|
+
"placeholder": getI18nText("selectPlaceholder"),
|
|
305
|
+
"role": "combobox",
|
|
306
|
+
"aria-autocomplete": hasInputTrigger && "list" || void 0
|
|
307
|
+
}, _ref3)
|
|
308
|
+
}), addonTextChildren(Children, Tag.Text || Tag.Value || ButtonTrigger.Text, Tag.Addon || ButtonTrigger.Addon, true), name && /* @__PURE__ */ React.createElement("input", _ref7.cn("input", {
|
|
309
309
|
"type": "hidden",
|
|
310
310
|
"defaultValue": value,
|
|
311
311
|
"name": name,
|
|
@@ -314,8 +314,16 @@ function Trigger(_ref0) {
|
|
|
314
314
|
}
|
|
315
315
|
function Menu(props) {
|
|
316
316
|
var _ref4 = arguments[0];
|
|
317
|
-
|
|
318
|
-
|
|
317
|
+
const {
|
|
318
|
+
visible,
|
|
319
|
+
disablePortal,
|
|
320
|
+
ignorePortalsStacking,
|
|
321
|
+
disableEnforceFocus,
|
|
322
|
+
interaction,
|
|
323
|
+
autoFocus,
|
|
324
|
+
animationsDisabled
|
|
325
|
+
} = props;
|
|
326
|
+
const popperProps = {
|
|
319
327
|
visible,
|
|
320
328
|
disablePortal,
|
|
321
329
|
ignorePortalsStacking,
|
|
@@ -328,46 +336,91 @@ function Menu(props) {
|
|
|
328
336
|
role: null
|
|
329
337
|
}), /* @__PURE__ */ React.createElement(Select.List, assignProps({}, _ref4))));
|
|
330
338
|
}
|
|
331
|
-
|
|
339
|
+
const optionPropsContext = /* @__PURE__ */ React.createContext({});
|
|
332
340
|
function Option(props) {
|
|
333
341
|
var _ref5 = arguments[0], _ref8;
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
342
|
+
const SSelectOption = Dropdown.Item;
|
|
343
|
+
const {
|
|
344
|
+
styles,
|
|
345
|
+
Children,
|
|
346
|
+
highlighted
|
|
347
|
+
} = props;
|
|
348
|
+
const itemRef = React.useRef(null);
|
|
349
|
+
const hasCheckbox = isAdvanceMode(Children, [Select.Option.Checkbox.displayName]);
|
|
350
|
+
const hasContent = isAdvanceMode(Children, [Select.Option.Content.displayName]);
|
|
351
|
+
const optionPropsContextValue = {
|
|
352
|
+
...props,
|
|
353
|
+
itemRef,
|
|
354
|
+
highlighted
|
|
355
|
+
};
|
|
356
|
+
return _ref8 = sstyled(styles), /* @__PURE__ */ React.createElement(SSelectOption, _ref8.cn("SSelectOption", {
|
|
357
|
+
...assignProps({
|
|
358
|
+
"ref": itemRef
|
|
359
|
+
}, _ref5)
|
|
360
|
+
}), /* @__PURE__ */ React.createElement(optionPropsContext.Provider, {
|
|
361
|
+
value: optionPropsContextValue
|
|
340
362
|
}, hasCheckbox && !hasContent ? /* @__PURE__ */ React.createElement(Select.Option.Content, null, /* @__PURE__ */ React.createElement(Children, _ref8.cn("Children", {}))) : /* @__PURE__ */ React.createElement(Children, _ref8.cn("Children", {}))));
|
|
341
363
|
}
|
|
342
364
|
function Checkbox(providedProps) {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
365
|
+
const optionProps = React.useContext(optionPropsContext);
|
|
366
|
+
const props = React.useMemo(() => ({
|
|
367
|
+
selected: optionProps == null ? void 0 : optionProps.selected,
|
|
368
|
+
disabled: optionProps == null ? void 0 : optionProps.disabled,
|
|
369
|
+
size: optionProps == null ? void 0 : optionProps.size,
|
|
370
|
+
...providedProps || {}
|
|
371
|
+
}), [providedProps, optionProps]);
|
|
372
|
+
const [SOptionCheckbox, componentProps] = useBox(props, props.forwardRef);
|
|
373
|
+
const {
|
|
374
|
+
size,
|
|
375
|
+
theme,
|
|
376
|
+
selected,
|
|
377
|
+
resolveColor,
|
|
378
|
+
indeterminate
|
|
379
|
+
} = props;
|
|
380
|
+
const styles = sstyled(props.styles);
|
|
381
|
+
const {
|
|
382
|
+
className,
|
|
383
|
+
style: style2
|
|
384
|
+
} = styles.cn("SOptionCheckbox", {
|
|
355
385
|
size,
|
|
356
386
|
"use:theme": resolveColor(theme),
|
|
357
387
|
indeterminate,
|
|
358
388
|
selected
|
|
359
|
-
})
|
|
389
|
+
});
|
|
360
390
|
return /* @__PURE__ */ React.createElement(SOptionCheckbox, _extends({}, componentProps, {
|
|
361
391
|
className: cn(className, componentProps.className) || void 0,
|
|
362
|
-
style:
|
|
392
|
+
style: {
|
|
393
|
+
...style2,
|
|
394
|
+
...componentProps.style
|
|
395
|
+
},
|
|
363
396
|
tabIndex: -1
|
|
364
397
|
}));
|
|
365
398
|
}
|
|
366
|
-
|
|
399
|
+
function OptionText(providedProps) {
|
|
400
|
+
var _ref9;
|
|
401
|
+
const optionProps = React.useContext(optionPropsContext);
|
|
402
|
+
const selectedIndex = React.useContext(selectedIndexContext);
|
|
403
|
+
const props = React.useMemo(() => ({
|
|
404
|
+
key: optionProps == null ? void 0 : optionProps.id,
|
|
405
|
+
selected: optionProps == null ? void 0 : optionProps.selected,
|
|
406
|
+
disabled: optionProps == null ? void 0 : optionProps.disabled,
|
|
407
|
+
size: optionProps == null ? void 0 : optionProps.size,
|
|
408
|
+
hintProps: (optionProps == null ? void 0 : optionProps.hintProps) ?? {},
|
|
409
|
+
...providedProps || {}
|
|
410
|
+
}), [providedProps, optionProps]);
|
|
411
|
+
if (optionProps.itemRef) {
|
|
412
|
+
props.hintProps.triggerRef = optionProps.itemRef;
|
|
413
|
+
}
|
|
414
|
+
props.hintProps.visible = selectedIndex === optionProps.index;
|
|
415
|
+
return _ref9 = sstyled(props.styles), /* @__PURE__ */ React.createElement(Text, _ref9.cn("Text", {
|
|
416
|
+
...props
|
|
417
|
+
}));
|
|
418
|
+
}
|
|
419
|
+
const InputSearchWrapper = function() {
|
|
367
420
|
var _ref6 = arguments[0];
|
|
368
421
|
return /* @__PURE__ */ React.createElement(InputSearch, assignProps({}, _ref6));
|
|
369
422
|
};
|
|
370
|
-
|
|
423
|
+
const Select = createComponent(RootSelect, {
|
|
371
424
|
Trigger: [Trigger, {
|
|
372
425
|
Addon: ButtonTrigger.Addon,
|
|
373
426
|
Text: ButtonTrigger.Text
|
|
@@ -378,12 +431,11 @@ var Select = createComponent(RootSelect, {
|
|
|
378
431
|
Option: [Option, {
|
|
379
432
|
Addon: DropdownMenu.Item.Addon,
|
|
380
433
|
Content: DropdownMenu.Item.Content,
|
|
434
|
+
Text: OptionText,
|
|
381
435
|
Hint: DropdownMenu.Item.Hint,
|
|
382
436
|
Checkbox
|
|
383
437
|
}],
|
|
384
438
|
Group: Dropdown.Group,
|
|
385
|
-
OptionTitle: DropdownMenu.ItemTitle,
|
|
386
|
-
OptionHint: DropdownMenu.ItemHint,
|
|
387
439
|
Divider,
|
|
388
440
|
InputSearch: [InputSearchWrapper, InputSearch._______childrenComponents],
|
|
389
441
|
Input: [InputSearchWrapper, InputSearch._______childrenComponents]
|
|
@@ -391,9 +443,7 @@ var Select = createComponent(RootSelect, {
|
|
|
391
443
|
parent: DropdownMenu,
|
|
392
444
|
context: selectContext
|
|
393
445
|
});
|
|
394
|
-
|
|
395
|
-
return wrapper;
|
|
396
|
-
};
|
|
446
|
+
const wrapSelect = (wrapper) => wrapper;
|
|
397
447
|
Select.selectedIndexContext = selectedIndexContext;
|
|
398
448
|
export {
|
|
399
449
|
Select as default,
|