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