@redsift/pickers 11.5.0 → 11.6.0-alpha.0
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/_internal/Combobox2.js +150 -0
- package/_internal/Combobox2.js.map +1 -0
- package/_internal/ComboboxContent.js +70 -0
- package/_internal/ComboboxContent.js.map +1 -0
- package/_internal/ComboboxContentFooter.js +36 -0
- package/_internal/ComboboxContentFooter.js.map +1 -0
- package/_internal/ComboboxContentHeader.js +36 -0
- package/_internal/ComboboxContentHeader.js.map +1 -0
- package/_internal/ComboboxContentListbox.js +123 -0
- package/_internal/ComboboxContentListbox.js.map +1 -0
- package/_internal/ComboboxTrigger.js +377 -0
- package/_internal/ComboboxTrigger.js.map +1 -0
- package/_internal/Item2.js +199 -0
- package/_internal/Item2.js.map +1 -0
- package/_internal/MenuButton.js +75 -0
- package/_internal/MenuButton.js.map +1 -0
- package/_internal/MenuButtonContent.js +68 -0
- package/_internal/MenuButtonContent.js.map +1 -0
- package/_internal/MenuButtonContentFooter.js +36 -0
- package/_internal/MenuButtonContentFooter.js.map +1 -0
- package/_internal/MenuButtonContentHeader.js +36 -0
- package/_internal/MenuButtonContentHeader.js.map +1 -0
- package/_internal/MenuButtonContentMenu.js +41 -0
- package/_internal/MenuButtonContentMenu.js.map +1 -0
- package/_internal/MenuButtonTrigger.js +168 -0
- package/_internal/MenuButtonTrigger.js.map +1 -0
- package/_internal/Select2.js +115 -0
- package/_internal/Select2.js.map +1 -0
- package/_internal/SelectContent.js +62 -0
- package/_internal/SelectContent.js.map +1 -0
- package/_internal/SelectTrigger.js +250 -0
- package/_internal/SelectTrigger.js.map +1 -0
- package/_internal/_rollupPluginBabelHelpers.js +93 -0
- package/_internal/_rollupPluginBabelHelpers.js.map +1 -0
- package/_internal/combobox-content-footer.js +2 -0
- package/_internal/combobox-content-footer.js.map +1 -0
- package/_internal/combobox-content-header.js +2 -0
- package/_internal/combobox-content-header.js.map +1 -0
- package/_internal/combobox-content-listbox.js +2 -0
- package/_internal/combobox-content-listbox.js.map +1 -0
- package/_internal/combobox-content.js +2 -0
- package/_internal/combobox-content.js.map +1 -0
- package/_internal/combobox-trigger.js +2 -0
- package/_internal/combobox-trigger.js.map +1 -0
- package/_internal/combobox.js +3 -0
- package/_internal/combobox.js.map +1 -0
- package/_internal/item.js +2 -0
- package/_internal/item.js.map +1 -0
- package/_internal/menu-button-content-footer.js +2 -0
- package/_internal/menu-button-content-footer.js.map +1 -0
- package/_internal/menu-button-content-header.js +2 -0
- package/_internal/menu-button-content-header.js.map +1 -0
- package/_internal/menu-button-content-menu.js +2 -0
- package/_internal/menu-button-content-menu.js.map +1 -0
- package/_internal/menu-button-content.js +2 -0
- package/_internal/menu-button-content.js.map +1 -0
- package/_internal/menu-button-trigger.js +2 -0
- package/_internal/menu-button-trigger.js.map +1 -0
- package/_internal/menu-button.js +2 -0
- package/_internal/menu-button.js.map +1 -0
- package/_internal/select-content.js +2 -0
- package/_internal/select-content.js.map +1 -0
- package/_internal/select-trigger.js +2 -0
- package/_internal/select-trigger.js.map +1 -0
- package/_internal/select.js +2 -0
- package/_internal/select.js.map +1 -0
- package/_internal/types.js +26 -0
- package/_internal/types.js.map +1 -0
- package/index.js +17 -1822
- package/index.js.map +1 -1
- package/package.json +8 -8
package/index.js
CHANGED
|
@@ -1,1823 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
function _objectSpread2(target) {
|
|
19
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
20
|
-
var source = null != arguments[i] ? arguments[i] : {};
|
|
21
|
-
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
|
|
22
|
-
_defineProperty(target, key, source[key]);
|
|
23
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
|
|
24
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
return target;
|
|
28
|
-
}
|
|
29
|
-
function _defineProperty(obj, key, value) {
|
|
30
|
-
key = _toPropertyKey(key);
|
|
31
|
-
if (key in obj) {
|
|
32
|
-
Object.defineProperty(obj, key, {
|
|
33
|
-
value: value,
|
|
34
|
-
enumerable: true,
|
|
35
|
-
configurable: true,
|
|
36
|
-
writable: true
|
|
37
|
-
});
|
|
38
|
-
} else {
|
|
39
|
-
obj[key] = value;
|
|
40
|
-
}
|
|
41
|
-
return obj;
|
|
42
|
-
}
|
|
43
|
-
function _extends() {
|
|
44
|
-
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
45
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
46
|
-
var source = arguments[i];
|
|
47
|
-
for (var key in source) {
|
|
48
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
49
|
-
target[key] = source[key];
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return target;
|
|
54
|
-
};
|
|
55
|
-
return _extends.apply(this, arguments);
|
|
56
|
-
}
|
|
57
|
-
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
58
|
-
if (source == null) return {};
|
|
59
|
-
var target = {};
|
|
60
|
-
var sourceKeys = Object.keys(source);
|
|
61
|
-
var key, i;
|
|
62
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
|
63
|
-
key = sourceKeys[i];
|
|
64
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
65
|
-
target[key] = source[key];
|
|
66
|
-
}
|
|
67
|
-
return target;
|
|
68
|
-
}
|
|
69
|
-
function _objectWithoutProperties(source, excluded) {
|
|
70
|
-
if (source == null) return {};
|
|
71
|
-
var target = _objectWithoutPropertiesLoose(source, excluded);
|
|
72
|
-
var key, i;
|
|
73
|
-
if (Object.getOwnPropertySymbols) {
|
|
74
|
-
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
|
75
|
-
for (i = 0; i < sourceSymbolKeys.length; i++) {
|
|
76
|
-
key = sourceSymbolKeys[i];
|
|
77
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
78
|
-
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
79
|
-
target[key] = source[key];
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return target;
|
|
83
|
-
}
|
|
84
|
-
function _toPrimitive(input, hint) {
|
|
85
|
-
if (typeof input !== "object" || input === null) return input;
|
|
86
|
-
var prim = input[Symbol.toPrimitive];
|
|
87
|
-
if (prim !== undefined) {
|
|
88
|
-
var res = prim.call(input, hint || "default");
|
|
89
|
-
if (typeof res !== "object") return res;
|
|
90
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
91
|
-
}
|
|
92
|
-
return (hint === "string" ? String : Number)(input);
|
|
93
|
-
}
|
|
94
|
-
function _toPropertyKey(arg) {
|
|
95
|
-
var key = _toPrimitive(arg, "string");
|
|
96
|
-
return typeof key === "symbol" ? key : String(key);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Component style.
|
|
101
|
-
*/
|
|
102
|
-
const StyledComboboxContentFooter = styled.div`
|
|
103
|
-
${baseContainer}
|
|
104
|
-
`;
|
|
105
|
-
|
|
106
|
-
const _excluded$7 = ["children", "className"];
|
|
107
|
-
const COMPONENT_NAME$f = 'ComboboxContentFooter';
|
|
108
|
-
const CLASSNAME$f = 'redsift-combobox-content-footer';
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* The ComboboxContentFooter component.
|
|
112
|
-
*/
|
|
113
|
-
const ComboboxContentFooter = /*#__PURE__*/forwardRef((props, ref) => {
|
|
114
|
-
const {
|
|
115
|
-
children,
|
|
116
|
-
className
|
|
117
|
-
} = props,
|
|
118
|
-
forwardedProps = _objectWithoutProperties(props, _excluded$7);
|
|
119
|
-
return /*#__PURE__*/React.createElement(StyledComboboxContentFooter, _extends({}, forwardedProps, {
|
|
120
|
-
className: classNames(ComboboxContentFooter.className, className),
|
|
121
|
-
ref: ref
|
|
122
|
-
}), children);
|
|
123
|
-
});
|
|
124
|
-
ComboboxContentFooter.className = CLASSNAME$f;
|
|
125
|
-
ComboboxContentFooter.displayName = COMPONENT_NAME$f;
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Component style.
|
|
129
|
-
*/
|
|
130
|
-
const StyledComboboxContentHeader = styled.div`
|
|
131
|
-
${baseContainer}
|
|
132
|
-
`;
|
|
133
|
-
|
|
134
|
-
const _excluded$6 = ["children", "className"];
|
|
135
|
-
const COMPONENT_NAME$e = 'ComboboxContentHeader';
|
|
136
|
-
const CLASSNAME$e = 'redsift-combobox-content-header';
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* The ComboboxContentHeader component.
|
|
140
|
-
*/
|
|
141
|
-
const ComboboxContentHeader = /*#__PURE__*/forwardRef((props, ref) => {
|
|
142
|
-
const {
|
|
143
|
-
children,
|
|
144
|
-
className
|
|
145
|
-
} = props,
|
|
146
|
-
forwardedProps = _objectWithoutProperties(props, _excluded$6);
|
|
147
|
-
return /*#__PURE__*/React.createElement(StyledComboboxContentHeader, _extends({}, forwardedProps, {
|
|
148
|
-
className: classNames(ComboboxContentHeader.className, className),
|
|
149
|
-
ref: ref
|
|
150
|
-
}), children);
|
|
151
|
-
});
|
|
152
|
-
ComboboxContentHeader.className = CLASSNAME$e;
|
|
153
|
-
ComboboxContentHeader.displayName = COMPONENT_NAME$e;
|
|
154
|
-
|
|
155
|
-
const ComboboxContext = /*#__PURE__*/React.createContext(null);
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Component variant.
|
|
159
|
-
*/
|
|
160
|
-
const ComboboxSelectionMode = {
|
|
161
|
-
single: 'single',
|
|
162
|
-
multiple: 'multiple'
|
|
163
|
-
};
|
|
164
|
-
const ComboboxVariant = {
|
|
165
|
-
options: 'options',
|
|
166
|
-
suggestions: 'suggestions'
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Context props.
|
|
171
|
-
*/
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Component props.
|
|
175
|
-
*/
|
|
176
|
-
|
|
177
|
-
const _excluded$5 = ["children", "className", "renderFreeTextItem"];
|
|
178
|
-
const COMPONENT_NAME$d = 'ComboboxContentListbox';
|
|
179
|
-
const CLASSNAME$d = 'redsift-combobox-content-listbox';
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* The ComboboxContentListbox component.
|
|
183
|
-
*/
|
|
184
|
-
const ComboboxContentListbox = /*#__PURE__*/forwardRef((props, ref) => {
|
|
185
|
-
const {
|
|
186
|
-
children,
|
|
187
|
-
className,
|
|
188
|
-
renderFreeTextItem
|
|
189
|
-
} = props,
|
|
190
|
-
forwardedProps = _objectWithoutProperties(props, _excluded$5);
|
|
191
|
-
const focusContext = useContext(FocusWithinGroupContext);
|
|
192
|
-
const listboxState = useContext(ListboxContext);
|
|
193
|
-
const comboboxState = useContext(ComboboxContext);
|
|
194
|
-
useEffect(() => {
|
|
195
|
-
if (focusContext && focusContext.state.delayedAction && focusContext.state.tabStops.length) {
|
|
196
|
-
focusContext.dispatch(focusContext.state.delayedAction);
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
const canHaveMultipleSelections = (comboboxState === null || comboboxState === void 0 ? void 0 : comboboxState.selectionMode) === ComboboxSelectionMode.multiple;
|
|
200
|
-
const canHaveFreeText = (comboboxState === null || comboboxState === void 0 ? void 0 : comboboxState.variant) === ComboboxVariant.suggestions;
|
|
201
|
-
const cloneChildAndPush = (child, array) => {
|
|
202
|
-
if (!canHaveMultipleSelections || !canHaveFreeText || canHaveMultipleSelections && canHaveFreeText && !comboboxState.value.includes(child.props.value)) {
|
|
203
|
-
array.push( /*#__PURE__*/React.cloneElement(child, {
|
|
204
|
-
key: child.props.value,
|
|
205
|
-
hasCheckbox: canHaveMultipleSelections && !canHaveFreeText
|
|
206
|
-
}));
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
const renderedChildren = [];
|
|
210
|
-
if (Array.isArray(children)) {
|
|
211
|
-
for (const child of children) {
|
|
212
|
-
if (isComponent(Item$1)(child)) {
|
|
213
|
-
if (focusContext.state.maxOptionsLength) {
|
|
214
|
-
if (renderedChildren.length < focusContext.state.maxOptionsLength) {
|
|
215
|
-
if (!focusContext.state.filter) {
|
|
216
|
-
cloneChildAndPush(child, renderedChildren);
|
|
217
|
-
} else {
|
|
218
|
-
const {
|
|
219
|
-
value: filterValue,
|
|
220
|
-
type,
|
|
221
|
-
caseSensitive
|
|
222
|
-
} = focusContext.state.filter;
|
|
223
|
-
if (!filterValue) {
|
|
224
|
-
cloneChildAndPush(child, renderedChildren);
|
|
225
|
-
} else if (caseSensitive && (type === 'startsWith' && child.props.value.startsWith(filterValue) || type === 'contains' && child.props.value.includes(filterValue) || type === 'endsWith' && child.props.value.endsWith(filterValue))) {
|
|
226
|
-
cloneChildAndPush(child, renderedChildren);
|
|
227
|
-
} else if (!caseSensitive && (type === 'startsWith' && child.props.value.toLowerCase().startsWith(filterValue.toLowerCase()) || type === 'contains' && child.props.value.toLowerCase().includes(filterValue.toLowerCase()) || type === 'endsWith' && child.props.value.toLowerCase().endsWith(filterValue.toLowerCase()))) {
|
|
228
|
-
cloneChildAndPush(child, renderedChildren);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
} else {
|
|
233
|
-
cloneChildAndPush(child, renderedChildren);
|
|
234
|
-
}
|
|
235
|
-
} else {
|
|
236
|
-
renderedChildren.push(child);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
const {
|
|
241
|
-
tabIndex,
|
|
242
|
-
isFocused,
|
|
243
|
-
isSelected,
|
|
244
|
-
isDisabled,
|
|
245
|
-
handleKeyDown,
|
|
246
|
-
handleClick
|
|
247
|
-
} = useListboxItem({
|
|
248
|
-
domElementRef: comboboxState === null || comboboxState === void 0 ? void 0 : comboboxState.freeTextItemRef,
|
|
249
|
-
value: (comboboxState === null || comboboxState === void 0 ? void 0 : comboboxState.inputValue) || '',
|
|
250
|
-
id: comboboxState === null || comboboxState === void 0 ? void 0 : comboboxState.freeTextItemId
|
|
251
|
-
});
|
|
252
|
-
const theme = useTheme();
|
|
253
|
-
const renderedFreeTextItem = comboboxState !== null && comboboxState !== void 0 && comboboxState.inputValue ? renderFreeTextItem && typeof renderFreeTextItem === 'function' ? renderFreeTextItem(comboboxState === null || comboboxState === void 0 ? void 0 : comboboxState.inputValue, comboboxState, listboxState) : comboboxState === null || comboboxState === void 0 ? void 0 : comboboxState.inputValue : null;
|
|
254
|
-
return /*#__PURE__*/React.createElement(Flexbox, _extends({
|
|
255
|
-
className: classNames(ComboboxContentListbox.className, className)
|
|
256
|
-
}, forwardedProps, {
|
|
257
|
-
ref: ref,
|
|
258
|
-
flexDirection: "column",
|
|
259
|
-
gap: "0px",
|
|
260
|
-
margin: "8px 0px",
|
|
261
|
-
style: {
|
|
262
|
-
outline: 'none'
|
|
263
|
-
},
|
|
264
|
-
width: "100%"
|
|
265
|
-
}), canHaveMultipleSelections && canHaveFreeText ? /*#__PURE__*/React.createElement(StyledItem, {
|
|
266
|
-
role: "option",
|
|
267
|
-
id: comboboxState.freeTextItemId,
|
|
268
|
-
$color: "primary",
|
|
269
|
-
$isActive: isSelected,
|
|
270
|
-
$isDisabled: isDisabled,
|
|
271
|
-
$isGradient: false,
|
|
272
|
-
$isHovered: isFocused,
|
|
273
|
-
$hasBorder: false,
|
|
274
|
-
$hasCheckbox: false,
|
|
275
|
-
$theme: theme,
|
|
276
|
-
"aria-selected": isSelected,
|
|
277
|
-
className: classNames(Item$1.className, className),
|
|
278
|
-
onClick: handleClick,
|
|
279
|
-
ref: comboboxState.freeTextItemRef,
|
|
280
|
-
onKeyDown: handleKeyDown,
|
|
281
|
-
tabIndex: tabIndex,
|
|
282
|
-
style: !comboboxState.inputValue ? {
|
|
283
|
-
height: '0',
|
|
284
|
-
visibility: 'hidden',
|
|
285
|
-
padding: '0'
|
|
286
|
-
} : undefined
|
|
287
|
-
}, renderedFreeTextItem) : null, Array.isArray(children) ? renderedChildren : children);
|
|
288
|
-
});
|
|
289
|
-
ComboboxContentListbox.className = CLASSNAME$d;
|
|
290
|
-
ComboboxContentListbox.displayName = COMPONENT_NAME$d;
|
|
291
|
-
|
|
292
|
-
const COMPONENT_NAME$c = 'ComboboxContent';
|
|
293
|
-
const CLASSNAME$c = 'redsift-combobox-content';
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* The ComboboxContent component.
|
|
297
|
-
*/
|
|
298
|
-
const BaseComboboxContent = /*#__PURE__*/forwardRef((props, ref) => {
|
|
299
|
-
var _comboboxState$inputV;
|
|
300
|
-
const {
|
|
301
|
-
children,
|
|
302
|
-
className,
|
|
303
|
-
style
|
|
304
|
-
} = props;
|
|
305
|
-
const containerProps = getContainerProps(props);
|
|
306
|
-
const {
|
|
307
|
-
getFloatingProps,
|
|
308
|
-
isOpen,
|
|
309
|
-
refs,
|
|
310
|
-
strategy,
|
|
311
|
-
x,
|
|
312
|
-
y
|
|
313
|
-
} = usePopoverContext();
|
|
314
|
-
const popoverRef = useMergeRefs([refs.setFloating, ref]);
|
|
315
|
-
const appContainerState = useContext(AppContainerContext);
|
|
316
|
-
const comboboxState = useContext(ComboboxContext);
|
|
317
|
-
const focusContext = useContext(FocusWithinGroupContext);
|
|
318
|
-
const listboxState = useContext(ListboxContext);
|
|
319
|
-
const theme = useTheme();
|
|
320
|
-
const [[header], [listbox], [footer]] = partitionComponents(React.Children.toArray(children), [isComponent('ComboboxContentHeader'), isComponent('ComboboxContentListbox'), isComponent('ComboboxContentFooter')]);
|
|
321
|
-
return /*#__PURE__*/React.createElement(FloatingPortal, {
|
|
322
|
-
root: appContainerState === null || appContainerState === void 0 ? void 0 : appContainerState.appContainerRef.current
|
|
323
|
-
}, isOpen && /*#__PURE__*/React.createElement(StyledPopoverContent, _extends({
|
|
324
|
-
$theme: theme,
|
|
325
|
-
ref: popoverRef
|
|
326
|
-
}, getFloatingProps(props), {
|
|
327
|
-
style: _objectSpread2(_objectSpread2({
|
|
328
|
-
position: strategy,
|
|
329
|
-
top: y !== null && y !== void 0 ? y : 0,
|
|
330
|
-
left: x !== null && x !== void 0 ? x : 0
|
|
331
|
-
}, style), comboboxState !== null && comboboxState !== void 0 && (_comboboxState$inputV = comboboxState.inputValue) !== null && _comboboxState$inputV !== void 0 && _comboboxState$inputV.length && focusContext.state.tabStops.length === 0 ? {
|
|
332
|
-
display: 'none'
|
|
333
|
-
} : {}),
|
|
334
|
-
className: classNames(PopoverContent.className, BaseComboboxContent.className, className),
|
|
335
|
-
"aria-disabled": listboxState.state.isDisabled
|
|
336
|
-
}), /*#__PURE__*/React.createElement(Flexbox, _extends({
|
|
337
|
-
flexDirection: "column",
|
|
338
|
-
gap: "0px",
|
|
339
|
-
width: "100%"
|
|
340
|
-
}, containerProps), header, listbox, footer)));
|
|
341
|
-
});
|
|
342
|
-
BaseComboboxContent.className = CLASSNAME$c;
|
|
343
|
-
BaseComboboxContent.displayName = COMPONENT_NAME$c;
|
|
344
|
-
const ComboboxContent = Object.assign(BaseComboboxContent, {
|
|
345
|
-
Header: ComboboxContentHeader,
|
|
346
|
-
Listbox: ComboboxContentListbox,
|
|
347
|
-
Footer: ComboboxContentFooter
|
|
348
|
-
});
|
|
349
|
-
|
|
350
|
-
var collapse$1 = "Collapse";
|
|
351
|
-
var expand$1 = "Expand";
|
|
352
|
-
var selected$1 = "{count, plural, =0 {None selected} other {# selected}}";
|
|
353
|
-
var unselect$1 = "Unselect {label}";
|
|
354
|
-
var enUS = {
|
|
355
|
-
collapse: collapse$1,
|
|
356
|
-
expand: expand$1,
|
|
357
|
-
selected: selected$1,
|
|
358
|
-
unselect: unselect$1
|
|
359
|
-
};
|
|
360
|
-
|
|
361
|
-
var collapse = "Réduire";
|
|
362
|
-
var expand = "Développer";
|
|
363
|
-
var selected = "{count, plural, =0 {Aucun sélectionné} =1 {1 sélectionné} other {# sélectionnés}}";
|
|
364
|
-
var unselect = "Déselectionner {label}";
|
|
365
|
-
var frFR = {
|
|
366
|
-
collapse: collapse,
|
|
367
|
-
expand: expand,
|
|
368
|
-
selected: selected,
|
|
369
|
-
unselect: unselect
|
|
370
|
-
};
|
|
371
|
-
|
|
372
|
-
var intlMessages = {
|
|
373
|
-
'en-US': enUS,
|
|
374
|
-
'fr-FR': frFR
|
|
375
|
-
};
|
|
376
|
-
|
|
377
|
-
const _excluded$4 = ["aria-controls", "aria-expanded", "aria-haspopup", "role"];
|
|
378
|
-
const COMPONENT_NAME$b = 'ComboboxTrigger';
|
|
379
|
-
const CLASSNAME$b = 'redsift-combobox-trigger';
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* The ComboboxTrigger component.
|
|
383
|
-
*/
|
|
384
|
-
const ComboboxTrigger = /*#__PURE__*/forwardRef((props, ref) => {
|
|
385
|
-
var _renderedChildren$pro;
|
|
386
|
-
const [id] = useId();
|
|
387
|
-
const {
|
|
388
|
-
children,
|
|
389
|
-
hideExpandButton,
|
|
390
|
-
openOnFocus,
|
|
391
|
-
hideClearButton,
|
|
392
|
-
pillProps
|
|
393
|
-
} = props;
|
|
394
|
-
const format = useMessageFormatter(intlMessages);
|
|
395
|
-
const {
|
|
396
|
-
getReferenceProps,
|
|
397
|
-
isOpen,
|
|
398
|
-
handleOpen: handleOpenPopover,
|
|
399
|
-
refs
|
|
400
|
-
} = usePopoverContext();
|
|
401
|
-
const childrenRef = children.ref;
|
|
402
|
-
const triggerRef = useMergeRefs([refs.setReference, ref, childrenRef]);
|
|
403
|
-
const focusContext = useContext(FocusWithinGroupContext);
|
|
404
|
-
const comboboxState = useContext(ComboboxContext);
|
|
405
|
-
const listboxState = useContext(ListboxContext);
|
|
406
|
-
const theme = useTheme();
|
|
407
|
-
const canHaveMultipleSelections = (comboboxState === null || comboboxState === void 0 ? void 0 : comboboxState.selectionMode) === ComboboxSelectionMode.multiple;
|
|
408
|
-
const canHaveFreeText = (comboboxState === null || comboboxState === void 0 ? void 0 : comboboxState.variant) === ComboboxVariant.suggestions;
|
|
409
|
-
const renderedChildren = typeof children === 'function' ? children({
|
|
410
|
-
value: comboboxState === null || comboboxState === void 0 ? void 0 : comboboxState.value,
|
|
411
|
-
isOpen
|
|
412
|
-
}) : children;
|
|
413
|
-
const isTextArea = isComponent('TextArea')(renderedChildren);
|
|
414
|
-
const isTextField = isComponent('TextField')(renderedChildren);
|
|
415
|
-
const hasMultipleLines = isTextArea && (comboboxState === null || comboboxState === void 0 ? void 0 : comboboxState.inputValue.includes('\n'));
|
|
416
|
-
const _inputRef = useRef();
|
|
417
|
-
const inputRef = (_renderedChildren$pro = renderedChildren.props.inputRef) !== null && _renderedChildren$pro !== void 0 ? _renderedChildren$pro : _inputRef;
|
|
418
|
-
const handleChange = value => {
|
|
419
|
-
focusContext.dispatch({
|
|
420
|
-
type: FocusWithinGroupActionType.FILTER_LIST,
|
|
421
|
-
payload: {
|
|
422
|
-
filter: _objectSpread2({
|
|
423
|
-
value: value || ''
|
|
424
|
-
}, comboboxState === null || comboboxState === void 0 ? void 0 : comboboxState.filter)
|
|
425
|
-
}
|
|
426
|
-
});
|
|
427
|
-
comboboxState === null || comboboxState === void 0 ? void 0 : comboboxState.setInputValue(value);
|
|
428
|
-
};
|
|
429
|
-
const handleKeyDown = event => {
|
|
430
|
-
const code = event.code;
|
|
431
|
-
if (code === 'Escape' || code === 'Tab') {
|
|
432
|
-
if (isOpen) {
|
|
433
|
-
handleOpenPopover(false);
|
|
434
|
-
}
|
|
435
|
-
if (canHaveMultipleSelections && canHaveFreeText && comboboxState.inputValue) {
|
|
436
|
-
listboxState.dispatch({
|
|
437
|
-
type: ListboxActionType.TOGGLE,
|
|
438
|
-
payload: {
|
|
439
|
-
value: comboboxState.inputValue,
|
|
440
|
-
activedescendant: [comboboxState.freeTextItemId, comboboxState.inputValue]
|
|
441
|
-
}
|
|
442
|
-
});
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
if ((/^.$/.test(event.key) || code === 'Backspace') && !hasMultipleLines) {
|
|
446
|
-
if (!isOpen) {
|
|
447
|
-
handleOpenPopover(true);
|
|
448
|
-
}
|
|
449
|
-
if (canHaveMultipleSelections && canHaveFreeText) {
|
|
450
|
-
focusContext.dispatch({
|
|
451
|
-
type: FocusWithinGroupActionType.DELAY_ACTION,
|
|
452
|
-
payload: {
|
|
453
|
-
type: FocusWithinGroupActionType.KEY_DOWN_ON_LIST,
|
|
454
|
-
payload: {
|
|
455
|
-
key: EventKey.Home,
|
|
456
|
-
ctrlKey: event.ctrlKey
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
});
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
if (canHaveMultipleSelections && comboboxState.inputValue === '' && code === 'Backspace') {
|
|
463
|
-
listboxState.dispatch({
|
|
464
|
-
type: ListboxActionType.SET,
|
|
465
|
-
payload: {
|
|
466
|
-
values: comboboxState.value.slice(0, comboboxState.value.length - 1),
|
|
467
|
-
activedescendant: focusContext.state.activedescendant
|
|
468
|
-
}
|
|
469
|
-
});
|
|
470
|
-
}
|
|
471
|
-
if (code === 'ArrowDown' && !hasMultipleLines) {
|
|
472
|
-
if (!isOpen) {
|
|
473
|
-
handleOpenPopover(true);
|
|
474
|
-
}
|
|
475
|
-
focusContext.dispatch({
|
|
476
|
-
type: FocusWithinGroupActionType.DELAY_ACTION,
|
|
477
|
-
payload: {
|
|
478
|
-
type: FocusWithinGroupActionType.KEY_DOWN_ON_LIST,
|
|
479
|
-
payload: {
|
|
480
|
-
key: focusContext.state.selectedId !== null ? EventKey.ArrowDown : EventKey.Home,
|
|
481
|
-
ctrlKey: event.ctrlKey
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
});
|
|
485
|
-
event.preventDefault();
|
|
486
|
-
}
|
|
487
|
-
if (code === 'ArrowUp' && !hasMultipleLines) {
|
|
488
|
-
if (!isOpen) {
|
|
489
|
-
handleOpenPopover(true);
|
|
490
|
-
}
|
|
491
|
-
focusContext.dispatch({
|
|
492
|
-
type: FocusWithinGroupActionType.DELAY_ACTION,
|
|
493
|
-
payload: {
|
|
494
|
-
type: FocusWithinGroupActionType.KEY_DOWN_ON_LIST,
|
|
495
|
-
payload: {
|
|
496
|
-
key: focusContext.state.selectedId !== null ? EventKey.ArrowUp : EventKey.End,
|
|
497
|
-
ctrlKey: event.ctrlKey
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
});
|
|
501
|
-
event.preventDefault();
|
|
502
|
-
}
|
|
503
|
-
if (code === 'Enter') {
|
|
504
|
-
var _focusContext$state$a;
|
|
505
|
-
if (isTextField || isTextArea && !event.shiftKey) {
|
|
506
|
-
event.preventDefault();
|
|
507
|
-
}
|
|
508
|
-
if (canHaveMultipleSelections && canHaveFreeText && ((_focusContext$state$a = focusContext.state.activedescendant) === null || _focusContext$state$a === void 0 ? void 0 : _focusContext$state$a[0]) === comboboxState.freeTextItemId && comboboxState.inputValue) {
|
|
509
|
-
listboxState.dispatch({
|
|
510
|
-
type: ListboxActionType.TOGGLE,
|
|
511
|
-
payload: {
|
|
512
|
-
value: comboboxState.inputValue,
|
|
513
|
-
activedescendant: [comboboxState.freeTextItemId, comboboxState.inputValue]
|
|
514
|
-
}
|
|
515
|
-
});
|
|
516
|
-
handleOpenPopover(false);
|
|
517
|
-
} else if (isOpen && focusContext.state.selectedId) {
|
|
518
|
-
if (canHaveMultipleSelections) {
|
|
519
|
-
var _focusContext$state$a2, _focusContext$state$a3;
|
|
520
|
-
listboxState.dispatch({
|
|
521
|
-
type: ListboxActionType.TOGGLE,
|
|
522
|
-
payload: {
|
|
523
|
-
value: (_focusContext$state$a2 = (_focusContext$state$a3 = focusContext.state.activedescendant) === null || _focusContext$state$a3 === void 0 ? void 0 : _focusContext$state$a3[1]) !== null && _focusContext$state$a2 !== void 0 ? _focusContext$state$a2 : '',
|
|
524
|
-
activedescendant: focusContext.state.activedescendant
|
|
525
|
-
}
|
|
526
|
-
});
|
|
527
|
-
} else {
|
|
528
|
-
var _focusContext$state$a4, _focusContext$state$a5;
|
|
529
|
-
listboxState.dispatch({
|
|
530
|
-
type: ListboxActionType.SET,
|
|
531
|
-
payload: {
|
|
532
|
-
values: [(_focusContext$state$a4 = (_focusContext$state$a5 = focusContext.state.activedescendant) === null || _focusContext$state$a5 === void 0 ? void 0 : _focusContext$state$a5[1]) !== null && _focusContext$state$a4 !== void 0 ? _focusContext$state$a4 : ''],
|
|
533
|
-
activedescendant: focusContext.state.activedescendant
|
|
534
|
-
}
|
|
535
|
-
});
|
|
536
|
-
}
|
|
537
|
-
} else if (!event.shiftKey) {
|
|
538
|
-
var _comboboxState$formRe, _comboboxState$formRe2, _comboboxState$submit, _comboboxState$submit2;
|
|
539
|
-
comboboxState === null || comboboxState === void 0 ? void 0 : (_comboboxState$formRe = comboboxState.formRef) === null || _comboboxState$formRe === void 0 ? void 0 : (_comboboxState$formRe2 = _comboboxState$formRe.current) === null || _comboboxState$formRe2 === void 0 ? void 0 : _comboboxState$formRe2.submit();
|
|
540
|
-
comboboxState === null || comboboxState === void 0 ? void 0 : (_comboboxState$submit = comboboxState.submitRef) === null || _comboboxState$submit === void 0 ? void 0 : (_comboboxState$submit2 = _comboboxState$submit.current) === null || _comboboxState$submit2 === void 0 ? void 0 : _comboboxState$submit2.click();
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
};
|
|
544
|
-
const handleOpen = () => {
|
|
545
|
-
if (isOpen) {
|
|
546
|
-
handleOpenPopover(false);
|
|
547
|
-
} else {
|
|
548
|
-
var _inputRef$current, _focusContext$state$a6;
|
|
549
|
-
handleOpenPopover(true);
|
|
550
|
-
(_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.focus();
|
|
551
|
-
focusContext.dispatch({
|
|
552
|
-
type: FocusWithinGroupActionType.DELAY_ACTION,
|
|
553
|
-
payload: {
|
|
554
|
-
type: FocusWithinGroupActionType.FOCUS_ON_LIST,
|
|
555
|
-
payload: {
|
|
556
|
-
id: (_focusContext$state$a6 = focusContext.state.activedescendant) === null || _focusContext$state$a6 === void 0 ? void 0 : _focusContext$state$a6[0],
|
|
557
|
-
filter: _objectSpread2({
|
|
558
|
-
value: ''
|
|
559
|
-
}, comboboxState === null || comboboxState === void 0 ? void 0 : comboboxState.filter)
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
});
|
|
563
|
-
}
|
|
564
|
-
};
|
|
565
|
-
const handleFocus = () => {
|
|
566
|
-
var _inputRef$current2;
|
|
567
|
-
if (openOnFocus) {
|
|
568
|
-
handleOpen();
|
|
569
|
-
}
|
|
570
|
-
(_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 ? void 0 : _inputRef$current2.select();
|
|
571
|
-
};
|
|
572
|
-
const handleBlur = () => {
|
|
573
|
-
if (canHaveMultipleSelections) {
|
|
574
|
-
if (!canHaveFreeText) {
|
|
575
|
-
comboboxState === null || comboboxState === void 0 ? void 0 : comboboxState.setInputValue('');
|
|
576
|
-
}
|
|
577
|
-
} else {
|
|
578
|
-
if (canHaveFreeText) {
|
|
579
|
-
comboboxState === null || comboboxState === void 0 ? void 0 : comboboxState.setValue(comboboxState.inputValue);
|
|
580
|
-
} else {
|
|
581
|
-
comboboxState === null || comboboxState === void 0 ? void 0 : comboboxState.setInputValue(listboxState.state.selectedValues[0]);
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
};
|
|
585
|
-
const handleClear = () => {
|
|
586
|
-
listboxState.dispatch({
|
|
587
|
-
type: ListboxActionType.SET,
|
|
588
|
-
payload: {
|
|
589
|
-
values: [],
|
|
590
|
-
activedescendant: ['', '']
|
|
591
|
-
}
|
|
592
|
-
});
|
|
593
|
-
};
|
|
594
|
-
useEffect(() => {
|
|
595
|
-
if (canHaveMultipleSelections) {
|
|
596
|
-
focusContext.dispatch({
|
|
597
|
-
type: FocusWithinGroupActionType.FILTER_LIST,
|
|
598
|
-
payload: {
|
|
599
|
-
filter: _objectSpread2({
|
|
600
|
-
value: ''
|
|
601
|
-
}, comboboxState === null || comboboxState === void 0 ? void 0 : comboboxState.filter)
|
|
602
|
-
}
|
|
603
|
-
});
|
|
604
|
-
comboboxState === null || comboboxState === void 0 ? void 0 : comboboxState.setValue(listboxState.state.selectedValues);
|
|
605
|
-
comboboxState === null || comboboxState === void 0 ? void 0 : comboboxState.setInputValue('');
|
|
606
|
-
handleOpenPopover(false);
|
|
607
|
-
} else {
|
|
608
|
-
focusContext.dispatch({
|
|
609
|
-
type: FocusWithinGroupActionType.FILTER_LIST,
|
|
610
|
-
payload: {
|
|
611
|
-
filter: _objectSpread2({
|
|
612
|
-
value: listboxState.state.selectedValues[0] || ''
|
|
613
|
-
}, comboboxState === null || comboboxState === void 0 ? void 0 : comboboxState.filter)
|
|
614
|
-
}
|
|
615
|
-
});
|
|
616
|
-
comboboxState === null || comboboxState === void 0 ? void 0 : comboboxState.setValue(listboxState.state.selectedValues[0]);
|
|
617
|
-
if (listboxState.state.selectedValues.length) {
|
|
618
|
-
comboboxState === null || comboboxState === void 0 ? void 0 : comboboxState.setInputValue(listboxState.state.selectedValues[0]);
|
|
619
|
-
}
|
|
620
|
-
handleOpenPopover(false);
|
|
621
|
-
}
|
|
622
|
-
}, [listboxState.state]);
|
|
623
|
-
if (isTextField || isTextArea) {
|
|
624
|
-
var _props$children, _focusContext$state$a7, _comboboxState$value;
|
|
625
|
-
const _getReferenceProps = getReferenceProps(_objectSpread2(_objectSpread2(_objectSpread2({
|
|
626
|
-
ref: triggerRef
|
|
627
|
-
}, props), renderedChildren.props), {}, {
|
|
628
|
-
children: (_props$children = renderedChildren.props.children) !== null && _props$children !== void 0 ? _props$children : ''
|
|
629
|
-
})),
|
|
630
|
-
{
|
|
631
|
-
'aria-controls': ariaControls,
|
|
632
|
-
'aria-expanded': ariaExpanded,
|
|
633
|
-
'aria-haspopup': ariaHaspopup,
|
|
634
|
-
role
|
|
635
|
-
} = _getReferenceProps,
|
|
636
|
-
forwardedProps = _objectWithoutProperties(_getReferenceProps, _excluded$4);
|
|
637
|
-
const inputProps = {
|
|
638
|
-
'aria-activedescendant': isOpen ? (_focusContext$state$a7 = focusContext.state.activedescendant) === null || _focusContext$state$a7 === void 0 ? void 0 : _focusContext$state$a7[0] : undefined,
|
|
639
|
-
'aria-controls': ariaControls,
|
|
640
|
-
'aria-expanded': ariaExpanded,
|
|
641
|
-
'aria-haspopup': ariaHaspopup,
|
|
642
|
-
autoComplete: 'off',
|
|
643
|
-
autoCapitalize: 'off',
|
|
644
|
-
autoCorrect: 'off',
|
|
645
|
-
spellCheck: 'false',
|
|
646
|
-
'aria-autocomplete': canHaveMultipleSelections ? 'list' : undefined,
|
|
647
|
-
'aria-description': canHaveMultipleSelections ? format('selected', {
|
|
648
|
-
count: comboboxState === null || comboboxState === void 0 ? void 0 : comboboxState.value.length
|
|
649
|
-
}) : undefined,
|
|
650
|
-
onKeyDown: handleKeyDown,
|
|
651
|
-
role
|
|
652
|
-
};
|
|
653
|
-
return /*#__PURE__*/React.cloneElement(renderedChildren, _objectSpread2(_objectSpread2({}, forwardedProps), {}, {
|
|
654
|
-
theme,
|
|
655
|
-
className: classNames(renderedChildren.props.className, comboboxState === null || comboboxState === void 0 ? void 0 : comboboxState.triggerClassName),
|
|
656
|
-
isDisabled: comboboxState === null || comboboxState === void 0 ? void 0 : comboboxState.isDisabled,
|
|
657
|
-
isInvalid: comboboxState === null || comboboxState === void 0 ? void 0 : comboboxState.isInvalid,
|
|
658
|
-
onChange: handleChange,
|
|
659
|
-
onBlur: handleBlur,
|
|
660
|
-
onFocus: handleFocus,
|
|
661
|
-
value: comboboxState === null || comboboxState === void 0 ? void 0 : comboboxState.inputValue
|
|
662
|
-
}, isTextField ? {
|
|
663
|
-
inputProps,
|
|
664
|
-
inputRef,
|
|
665
|
-
onClear: handleClear,
|
|
666
|
-
hasClearButton: hideClearButton ? false : {
|
|
667
|
-
isDisabled: (comboboxState === null || comboboxState === void 0 ? void 0 : comboboxState.isDisabled) || (comboboxState === null || comboboxState === void 0 ? void 0 : comboboxState.value) && (comboboxState === null || comboboxState === void 0 ? void 0 : (_comboboxState$value = comboboxState.value) === null || _comboboxState$value === void 0 ? void 0 : _comboboxState$value.length) === 0,
|
|
668
|
-
onClick: () => inputRef.current.focus()
|
|
669
|
-
},
|
|
670
|
-
pills: canHaveMultipleSelections ? (comboboxState === null || comboboxState === void 0 ? void 0 : comboboxState.value).map(v => _objectSpread2({
|
|
671
|
-
isDisabled: comboboxState === null || comboboxState === void 0 ? void 0 : comboboxState.isDisabled,
|
|
672
|
-
children: [v, /*#__PURE__*/React.createElement(IconButton, {
|
|
673
|
-
key: `${id}-pill-${v}-icon-button`,
|
|
674
|
-
icon: mdiClose,
|
|
675
|
-
"aria-label": format('unselect', {
|
|
676
|
-
label: v
|
|
677
|
-
}),
|
|
678
|
-
onClick: event => {
|
|
679
|
-
event.preventDefault();
|
|
680
|
-
listboxState.dispatch({
|
|
681
|
-
type: ListboxActionType.TOGGLE,
|
|
682
|
-
payload: {
|
|
683
|
-
value: v,
|
|
684
|
-
activedescendant: focusContext.state.activedescendant
|
|
685
|
-
}
|
|
686
|
-
});
|
|
687
|
-
}
|
|
688
|
-
})]
|
|
689
|
-
}, pillProps)) : undefined,
|
|
690
|
-
internal: (value, isDisabled, isInvalid, isRequired) => {
|
|
691
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, typeof renderedChildren.props.internal === 'function' ? renderedChildren.props.internal(value, isDisabled, isInvalid, isRequired) : renderedChildren.props.internal, hideExpandButton ? null : /*#__PURE__*/React.createElement(IconButton, {
|
|
692
|
-
theme: theme,
|
|
693
|
-
"aria-label": format(!isOpen ? 'expand' : 'collapse'),
|
|
694
|
-
color: "grey",
|
|
695
|
-
icon: mdiChevronDown,
|
|
696
|
-
onClick: handleOpen,
|
|
697
|
-
isDisabled: isDisabled,
|
|
698
|
-
tabIndex: -1,
|
|
699
|
-
iconProps: {
|
|
700
|
-
style: {
|
|
701
|
-
transition: 'transform 300ms ease-out',
|
|
702
|
-
transform: `rotate(${isOpen ? '-180deg' : '0'})`
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
}));
|
|
706
|
-
}
|
|
707
|
-
} : {
|
|
708
|
-
textareaProps: inputProps,
|
|
709
|
-
textareaRef: inputRef
|
|
710
|
-
}));
|
|
711
|
-
}
|
|
712
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, renderedChildren);
|
|
713
|
-
});
|
|
714
|
-
ComboboxTrigger.className = CLASSNAME$b;
|
|
715
|
-
ComboboxTrigger.displayName = COMPONENT_NAME$b;
|
|
716
|
-
|
|
717
|
-
const COMPONENT_NAME$a = 'Combobox';
|
|
718
|
-
const CLASSNAME$a = 'redsift-combobox';
|
|
719
|
-
|
|
720
|
-
/**
|
|
721
|
-
* The Combobox component.
|
|
722
|
-
*/
|
|
723
|
-
const BaseCombobox = props => {
|
|
724
|
-
const {
|
|
725
|
-
defaultValue,
|
|
726
|
-
description,
|
|
727
|
-
descriptionProps,
|
|
728
|
-
filter = {
|
|
729
|
-
type: 'startsWith',
|
|
730
|
-
caseSensitive: false
|
|
731
|
-
},
|
|
732
|
-
formRef,
|
|
733
|
-
submitRef,
|
|
734
|
-
inputValue: propsInputValue,
|
|
735
|
-
isDisabled,
|
|
736
|
-
isInvalid,
|
|
737
|
-
maxOptionsLength,
|
|
738
|
-
minWidth = 'trigger-width',
|
|
739
|
-
onChange,
|
|
740
|
-
onInputChange,
|
|
741
|
-
selectionMode = ComboboxSelectionMode.single,
|
|
742
|
-
theme: propsTheme,
|
|
743
|
-
triggerClassName,
|
|
744
|
-
value,
|
|
745
|
-
variant = ComboboxVariant.options,
|
|
746
|
-
wrapperProps
|
|
747
|
-
} = props;
|
|
748
|
-
const theme = useTheme(propsTheme);
|
|
749
|
-
const [selectedValue, setValue] = useState(value || defaultValue || (selectionMode === 'multiple' ? [] : ''));
|
|
750
|
-
const [inputValue, setInputValue] = useState(propsInputValue || '');
|
|
751
|
-
useEffect(() => {
|
|
752
|
-
if (value) {
|
|
753
|
-
state.setValue(value);
|
|
754
|
-
}
|
|
755
|
-
}, [value]);
|
|
756
|
-
useEffect(() => {
|
|
757
|
-
if (propsInputValue) {
|
|
758
|
-
state.setInputValue(propsInputValue);
|
|
759
|
-
}
|
|
760
|
-
}, [propsInputValue]);
|
|
761
|
-
|
|
762
|
-
/** Listbox context */
|
|
763
|
-
const [listboxState, listboxDispatch] = useReducer(ListboxReducer, {
|
|
764
|
-
isDisabled,
|
|
765
|
-
selectedValues: selectionMode === ComboboxSelectionMode.multiple ? selectedValue : [selectedValue],
|
|
766
|
-
selectionMode
|
|
767
|
-
});
|
|
768
|
-
const listboxContext = useMemo(() => ({
|
|
769
|
-
state: listboxState,
|
|
770
|
-
dispatch: listboxDispatch
|
|
771
|
-
}), [listboxState]);
|
|
772
|
-
useEffect(() => {
|
|
773
|
-
listboxDispatch({
|
|
774
|
-
type: ListboxActionType.UPDATE_OPTIONS,
|
|
775
|
-
payload: {
|
|
776
|
-
isDisabled: isDisabled || false
|
|
777
|
-
}
|
|
778
|
-
});
|
|
779
|
-
}, [isDisabled]);
|
|
780
|
-
const freeTextItemRef = useRef();
|
|
781
|
-
const [freeTextItemId] = useId();
|
|
782
|
-
|
|
783
|
-
/** Combobox context. */
|
|
784
|
-
const state = {
|
|
785
|
-
filter,
|
|
786
|
-
formRef,
|
|
787
|
-
submitRef,
|
|
788
|
-
value: selectedValue,
|
|
789
|
-
inputValue,
|
|
790
|
-
isDisabled: isDisabled || false,
|
|
791
|
-
isInvalid: isInvalid || false,
|
|
792
|
-
selectionMode,
|
|
793
|
-
variant,
|
|
794
|
-
freeTextItemRef: freeTextItemRef,
|
|
795
|
-
freeTextItemId,
|
|
796
|
-
triggerClassName,
|
|
797
|
-
setValue(value) {
|
|
798
|
-
if (isDisabled) {
|
|
799
|
-
return;
|
|
800
|
-
}
|
|
801
|
-
const previousValue = selectedValue;
|
|
802
|
-
setValue(value);
|
|
803
|
-
if (value !== previousValue && onChange) {
|
|
804
|
-
onChange(value);
|
|
805
|
-
}
|
|
806
|
-
},
|
|
807
|
-
setInputValue(value) {
|
|
808
|
-
if (isDisabled) {
|
|
809
|
-
return;
|
|
810
|
-
}
|
|
811
|
-
const previousValue = inputValue;
|
|
812
|
-
setInputValue(value);
|
|
813
|
-
if (value !== previousValue && onInputChange) {
|
|
814
|
-
onInputChange(value);
|
|
815
|
-
}
|
|
816
|
-
}
|
|
817
|
-
};
|
|
818
|
-
return /*#__PURE__*/React.createElement(ThemeProvider, {
|
|
819
|
-
value: {
|
|
820
|
-
theme
|
|
821
|
-
}
|
|
822
|
-
}, /*#__PURE__*/React.createElement(FocusWithinGroup, {
|
|
823
|
-
focusType: "virtual-focus",
|
|
824
|
-
focusOnInit: false,
|
|
825
|
-
maxOptionsLength: maxOptionsLength
|
|
826
|
-
}, /*#__PURE__*/React.createElement(ComboboxContext.Provider, {
|
|
827
|
-
value: state
|
|
828
|
-
}, /*#__PURE__*/React.createElement(ListboxContext.Provider, {
|
|
829
|
-
value: listboxContext
|
|
830
|
-
}, /*#__PURE__*/React.createElement(Flexbox, _extends({
|
|
831
|
-
flexDirection: "column",
|
|
832
|
-
alignItems: "flex-start",
|
|
833
|
-
gap: "0px"
|
|
834
|
-
}, wrapperProps), /*#__PURE__*/React.createElement(Popover, _extends({
|
|
835
|
-
theme: theme,
|
|
836
|
-
overrideDisplayName: {
|
|
837
|
-
content: 'ComboboxContent',
|
|
838
|
-
trigger: 'ComboboxTrigger'
|
|
839
|
-
},
|
|
840
|
-
placement: "bottom-start",
|
|
841
|
-
role: "listbox",
|
|
842
|
-
minWidth: minWidth
|
|
843
|
-
}, props)), description && typeof description === 'string' ? /*#__PURE__*/React.createElement(Text, _extends({
|
|
844
|
-
theme: theme,
|
|
845
|
-
marginTop: "8px",
|
|
846
|
-
variant: "caption",
|
|
847
|
-
color: isInvalid ? 'error' : theme === Theme.light ? 'dark-grey' : 'white'
|
|
848
|
-
}, descriptionProps), description) : /*#__PURE__*/React.isValidElement(description) ? description : null)))));
|
|
849
|
-
};
|
|
850
|
-
BaseCombobox.className = CLASSNAME$a;
|
|
851
|
-
BaseCombobox.displayName = COMPONENT_NAME$a;
|
|
852
|
-
const Combobox = Object.assign(BaseCombobox, {
|
|
853
|
-
Trigger: ComboboxTrigger,
|
|
854
|
-
Content: ComboboxContent
|
|
855
|
-
});
|
|
856
|
-
|
|
857
|
-
function useMenuItem(props) {
|
|
858
|
-
const {
|
|
859
|
-
domElementRef,
|
|
860
|
-
id,
|
|
861
|
-
isDisabled,
|
|
862
|
-
onClick,
|
|
863
|
-
isLinkMenuItem,
|
|
864
|
-
linkRef,
|
|
865
|
-
hasPopup
|
|
866
|
-
} = props;
|
|
867
|
-
const {
|
|
868
|
-
handleOpen,
|
|
869
|
-
hideInsteadOfClose,
|
|
870
|
-
setHideInsteadOfClose
|
|
871
|
-
} = usePopoverContext();
|
|
872
|
-
const {
|
|
873
|
-
tabIndex,
|
|
874
|
-
isFocused,
|
|
875
|
-
handleKeyDown: handleFocusKeyDown,
|
|
876
|
-
handleClick: handleFocusClick
|
|
877
|
-
} = useFocusOnListItem({
|
|
878
|
-
domElementRef,
|
|
879
|
-
isDisabled: isDisabled,
|
|
880
|
-
id
|
|
881
|
-
});
|
|
882
|
-
useEffect(() => {
|
|
883
|
-
if (hasPopup && !hideInsteadOfClose) {
|
|
884
|
-
setHideInsteadOfClose === null || setHideInsteadOfClose === void 0 ? void 0 : setHideInsteadOfClose(true);
|
|
885
|
-
}
|
|
886
|
-
}, [hasPopup, hideInsteadOfClose, setHideInsteadOfClose]);
|
|
887
|
-
const handleKeyDown = useCallback(event => {
|
|
888
|
-
const code = event.code;
|
|
889
|
-
if (code === 'Enter' || code === 'Space') {
|
|
890
|
-
if (isLinkMenuItem) {
|
|
891
|
-
var _linkRef$current;
|
|
892
|
-
linkRef === null || linkRef === void 0 ? void 0 : (_linkRef$current = linkRef.current) === null || _linkRef$current === void 0 ? void 0 : _linkRef$current.click();
|
|
893
|
-
} else {
|
|
894
|
-
onClick === null || onClick === void 0 ? void 0 : onClick();
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
handleFocusKeyDown(event);
|
|
898
|
-
handleOpen(false);
|
|
899
|
-
}, []);
|
|
900
|
-
const handleClick = useCallback(() => {
|
|
901
|
-
handleFocusClick();
|
|
902
|
-
onClick === null || onClick === void 0 ? void 0 : onClick();
|
|
903
|
-
handleOpen(false);
|
|
904
|
-
}, []);
|
|
905
|
-
useEffect(() => {
|
|
906
|
-
if (isFocused && domElementRef.current) {
|
|
907
|
-
var _current;
|
|
908
|
-
(_current = domElementRef.current) === null || _current === void 0 ? void 0 : _current.focus();
|
|
909
|
-
}
|
|
910
|
-
}, [isFocused]);
|
|
911
|
-
return {
|
|
912
|
-
tabIndex,
|
|
913
|
-
isFocused,
|
|
914
|
-
isDisabled,
|
|
915
|
-
handleKeyDown,
|
|
916
|
-
handleClick
|
|
917
|
-
};
|
|
918
|
-
}
|
|
919
|
-
|
|
920
|
-
const _excluded$3 = ["borderRadius", "children", "className", "color", "hasBorder", "id", "isActive", "isDisabled", "isHovered", "theme", "onClick"];
|
|
921
|
-
const COMPONENT_NAME$9 = 'Item';
|
|
922
|
-
const CLASSNAME$9 = 'redsift-item';
|
|
923
|
-
const RenderedMenuItem = /*#__PURE__*/forwardRef((props, ref) => {
|
|
924
|
-
const {
|
|
925
|
-
borderRadius = '0',
|
|
926
|
-
children,
|
|
927
|
-
className,
|
|
928
|
-
color: propsColor,
|
|
929
|
-
hasBorder,
|
|
930
|
-
id: propsId,
|
|
931
|
-
isActive,
|
|
932
|
-
isDisabled: propsIsDisabled,
|
|
933
|
-
isHovered,
|
|
934
|
-
theme: propsTheme,
|
|
935
|
-
onClick
|
|
936
|
-
} = props,
|
|
937
|
-
forwardedProps = _objectWithoutProperties(props, _excluded$3);
|
|
938
|
-
const [_id] = useId();
|
|
939
|
-
const id = propsId !== null && propsId !== void 0 ? propsId : _id;
|
|
940
|
-
const _ref = useRef();
|
|
941
|
-
const divRef = useMergeRefs([ref, _ref]);
|
|
942
|
-
const linkRef = useRef(null);
|
|
943
|
-
const isLinkMenuItem = isComponent('Link')(children);
|
|
944
|
-
const {
|
|
945
|
-
tabIndex,
|
|
946
|
-
isFocused,
|
|
947
|
-
isDisabled,
|
|
948
|
-
handleKeyDown,
|
|
949
|
-
handleClick
|
|
950
|
-
} = useMenuItem({
|
|
951
|
-
domElementRef: _ref,
|
|
952
|
-
id,
|
|
953
|
-
isDisabled: propsIsDisabled,
|
|
954
|
-
onClick: onClick,
|
|
955
|
-
isLinkMenuItem,
|
|
956
|
-
linkRef,
|
|
957
|
-
hasPopup: props['aria-haspopup'] !== undefined
|
|
958
|
-
});
|
|
959
|
-
const theme = useTheme(propsTheme);
|
|
960
|
-
const color = Object.values(ButtonsColorPalette).includes(propsColor) ? propsColor : 'primary';
|
|
961
|
-
const isGradient = color === ButtonsColorPalette.radar;
|
|
962
|
-
return /*#__PURE__*/React.createElement(ConditionalWrapper, {
|
|
963
|
-
condition: isGradient,
|
|
964
|
-
wrapper: children => /*#__PURE__*/React.createElement(StyledGradientBorder, {
|
|
965
|
-
$borderRadius: borderRadius,
|
|
966
|
-
$color: color,
|
|
967
|
-
$isActive: isActive,
|
|
968
|
-
$isDisabled: isDisabled,
|
|
969
|
-
$isHovered: isHovered,
|
|
970
|
-
$theme: theme,
|
|
971
|
-
width: "auto"
|
|
972
|
-
}, children)
|
|
973
|
-
}, /*#__PURE__*/React.createElement(StyledItem, _extends({
|
|
974
|
-
as: "li",
|
|
975
|
-
role: isLinkMenuItem ? 'none' : 'menuitem'
|
|
976
|
-
}, forwardedProps, {
|
|
977
|
-
id: id,
|
|
978
|
-
$borderRadius: borderRadius,
|
|
979
|
-
$color: color,
|
|
980
|
-
$hasBorder: hasBorder,
|
|
981
|
-
$hasCheckbox: false,
|
|
982
|
-
$isActive: isActive,
|
|
983
|
-
$isDisabled: isDisabled,
|
|
984
|
-
$isGradient: isGradient,
|
|
985
|
-
$isHovered: isHovered || isFocused,
|
|
986
|
-
$theme: theme,
|
|
987
|
-
"aria-disabled": isDisabled,
|
|
988
|
-
className: classNames(Item.className, className),
|
|
989
|
-
onClick: isDisabled ? undefined : handleClick,
|
|
990
|
-
ref: divRef,
|
|
991
|
-
onKeyDown: handleKeyDown,
|
|
992
|
-
tabIndex: tabIndex
|
|
993
|
-
}), isLinkMenuItem ? /*#__PURE__*/React.cloneElement(children, {
|
|
994
|
-
role: 'menuitem',
|
|
995
|
-
ref: linkRef
|
|
996
|
-
}) : children));
|
|
997
|
-
});
|
|
998
|
-
|
|
999
|
-
/**
|
|
1000
|
-
* The Item component.
|
|
1001
|
-
*/
|
|
1002
|
-
const Item = /*#__PURE__*/forwardRef((props, ref) => {
|
|
1003
|
-
const {
|
|
1004
|
-
value
|
|
1005
|
-
} = props;
|
|
1006
|
-
const focusContext = useContext(FocusWithinGroupContext);
|
|
1007
|
-
const isListbox = focusContext.state.listRole === 'listbox';
|
|
1008
|
-
if (!focusContext.state.filter) {
|
|
1009
|
-
return isListbox ? /*#__PURE__*/React.createElement(RenderedListboxItem, _extends({}, props, {
|
|
1010
|
-
value: props.value,
|
|
1011
|
-
ref: ref
|
|
1012
|
-
})) : /*#__PURE__*/React.createElement(RenderedMenuItem, _extends({}, props, {
|
|
1013
|
-
ref: ref
|
|
1014
|
-
}));
|
|
1015
|
-
}
|
|
1016
|
-
const {
|
|
1017
|
-
value: filterValue,
|
|
1018
|
-
type,
|
|
1019
|
-
caseSensitive
|
|
1020
|
-
} = focusContext.state.filter;
|
|
1021
|
-
if (!filterValue) {
|
|
1022
|
-
return isListbox ? /*#__PURE__*/React.createElement(RenderedListboxItem, _extends({}, props, {
|
|
1023
|
-
value: props.value,
|
|
1024
|
-
ref: ref
|
|
1025
|
-
})) : /*#__PURE__*/React.createElement(RenderedMenuItem, _extends({}, props, {
|
|
1026
|
-
ref: ref
|
|
1027
|
-
}));
|
|
1028
|
-
} else if (caseSensitive && (type === 'startsWith' && value.startsWith(filterValue) || type === 'contains' && value.includes(filterValue) || type === 'endsWith' && value.endsWith(filterValue))) {
|
|
1029
|
-
return isListbox ? /*#__PURE__*/React.createElement(RenderedListboxItem, _extends({}, props, {
|
|
1030
|
-
value: props.value,
|
|
1031
|
-
ref: ref
|
|
1032
|
-
})) : /*#__PURE__*/React.createElement(RenderedMenuItem, _extends({}, props, {
|
|
1033
|
-
ref: ref
|
|
1034
|
-
}));
|
|
1035
|
-
} else if (!caseSensitive && (type === 'startsWith' && value.toLowerCase().startsWith(filterValue.toLowerCase()) || type === 'contains' && value.toLowerCase().includes(filterValue.toLowerCase()) || type === 'endsWith' && value.toLowerCase().endsWith(filterValue.toLowerCase()))) {
|
|
1036
|
-
return isListbox ? /*#__PURE__*/React.createElement(RenderedListboxItem, _extends({}, props, {
|
|
1037
|
-
value: props.value,
|
|
1038
|
-
ref: ref
|
|
1039
|
-
})) : /*#__PURE__*/React.createElement(RenderedMenuItem, _extends({}, props, {
|
|
1040
|
-
ref: ref
|
|
1041
|
-
}));
|
|
1042
|
-
}
|
|
1043
|
-
return null;
|
|
1044
|
-
});
|
|
1045
|
-
Item.className = CLASSNAME$9;
|
|
1046
|
-
Item.displayName = COMPONENT_NAME$9;
|
|
1047
|
-
|
|
1048
|
-
/**
|
|
1049
|
-
* Component style.
|
|
1050
|
-
*/
|
|
1051
|
-
const StyledMenuButtonContentFooter = styled.div`
|
|
1052
|
-
${baseContainer}
|
|
1053
|
-
`;
|
|
1054
|
-
|
|
1055
|
-
const _excluded$2 = ["children", "className"];
|
|
1056
|
-
const COMPONENT_NAME$8 = 'MenuButtonContentFooter';
|
|
1057
|
-
const CLASSNAME$8 = 'redsift-combobox-content-footer';
|
|
1058
|
-
|
|
1059
|
-
/**
|
|
1060
|
-
* The MenuButtonContentFooter component.
|
|
1061
|
-
*/
|
|
1062
|
-
const MenuButtonContentFooter = /*#__PURE__*/forwardRef((props, ref) => {
|
|
1063
|
-
const {
|
|
1064
|
-
children,
|
|
1065
|
-
className
|
|
1066
|
-
} = props,
|
|
1067
|
-
forwardedProps = _objectWithoutProperties(props, _excluded$2);
|
|
1068
|
-
return /*#__PURE__*/React.createElement(StyledMenuButtonContentFooter, _extends({}, forwardedProps, {
|
|
1069
|
-
className: classNames(MenuButtonContentFooter.className, className),
|
|
1070
|
-
ref: ref
|
|
1071
|
-
}), children);
|
|
1072
|
-
});
|
|
1073
|
-
MenuButtonContentFooter.className = CLASSNAME$8;
|
|
1074
|
-
MenuButtonContentFooter.displayName = COMPONENT_NAME$8;
|
|
1075
|
-
|
|
1076
|
-
/**
|
|
1077
|
-
* Component style.
|
|
1078
|
-
*/
|
|
1079
|
-
const StyledMenuButtonContentHeader = styled.div`
|
|
1080
|
-
${baseContainer}
|
|
1081
|
-
`;
|
|
1082
|
-
|
|
1083
|
-
const _excluded$1 = ["children", "className"];
|
|
1084
|
-
const COMPONENT_NAME$7 = 'MenuButtonContentHeader';
|
|
1085
|
-
const CLASSNAME$7 = 'redsift-combobox-content-header';
|
|
1086
|
-
|
|
1087
|
-
/**
|
|
1088
|
-
* The MenuButtonContentHeader component.
|
|
1089
|
-
*/
|
|
1090
|
-
const MenuButtonContentHeader = /*#__PURE__*/forwardRef((props, ref) => {
|
|
1091
|
-
const {
|
|
1092
|
-
children,
|
|
1093
|
-
className
|
|
1094
|
-
} = props,
|
|
1095
|
-
forwardedProps = _objectWithoutProperties(props, _excluded$1);
|
|
1096
|
-
return /*#__PURE__*/React.createElement(StyledMenuButtonContentHeader, _extends({}, forwardedProps, {
|
|
1097
|
-
className: classNames(MenuButtonContentHeader.className, className),
|
|
1098
|
-
ref: ref
|
|
1099
|
-
}), children);
|
|
1100
|
-
});
|
|
1101
|
-
MenuButtonContentHeader.className = CLASSNAME$7;
|
|
1102
|
-
MenuButtonContentHeader.displayName = COMPONENT_NAME$7;
|
|
1103
|
-
|
|
1104
|
-
const _excluded = ["children", "className"];
|
|
1105
|
-
const COMPONENT_NAME$6 = 'MenuButtonContentMenu';
|
|
1106
|
-
const CLASSNAME$6 = 'redsift-menu-button-content-menu';
|
|
1107
|
-
|
|
1108
|
-
/**
|
|
1109
|
-
* The MenuButtonContentMenu component.
|
|
1110
|
-
*/
|
|
1111
|
-
const MenuButtonContentMenu = /*#__PURE__*/forwardRef((props, ref) => {
|
|
1112
|
-
const {
|
|
1113
|
-
children,
|
|
1114
|
-
className
|
|
1115
|
-
} = props,
|
|
1116
|
-
forwardedProps = _objectWithoutProperties(props, _excluded);
|
|
1117
|
-
const focusContext = useContext(FocusWithinGroupContext);
|
|
1118
|
-
useEffect(() => {
|
|
1119
|
-
if (focusContext && focusContext.state.delayedAction && focusContext.state.tabStops.length) {
|
|
1120
|
-
focusContext.dispatch(focusContext.state.delayedAction);
|
|
1121
|
-
}
|
|
1122
|
-
}, [focusContext.state.delayedAction, focusContext.state.tabStops.length]);
|
|
1123
|
-
return /*#__PURE__*/React.createElement(Flexbox, _extends({
|
|
1124
|
-
flexDirection: "column",
|
|
1125
|
-
gap: "8px",
|
|
1126
|
-
margin: "8px 0px",
|
|
1127
|
-
width: "100%",
|
|
1128
|
-
className: classNames(MenuButtonContentMenu.className, className),
|
|
1129
|
-
role: "menu",
|
|
1130
|
-
as: "ul"
|
|
1131
|
-
}, forwardedProps, {
|
|
1132
|
-
ref: ref
|
|
1133
|
-
}), children);
|
|
1134
|
-
});
|
|
1135
|
-
MenuButtonContentMenu.className = CLASSNAME$6;
|
|
1136
|
-
MenuButtonContentMenu.displayName = COMPONENT_NAME$6;
|
|
1137
|
-
|
|
1138
|
-
const COMPONENT_NAME$5 = 'MenuButtonContent';
|
|
1139
|
-
const CLASSNAME$5 = 'redsift-menu-button-content';
|
|
1140
|
-
|
|
1141
|
-
/**
|
|
1142
|
-
* The MenuButtonContent component.
|
|
1143
|
-
*/
|
|
1144
|
-
const BaseMenuButtonContent = /*#__PURE__*/forwardRef((props, ref) => {
|
|
1145
|
-
const {
|
|
1146
|
-
children,
|
|
1147
|
-
className,
|
|
1148
|
-
style
|
|
1149
|
-
} = props;
|
|
1150
|
-
const containerProps = getContainerProps(props);
|
|
1151
|
-
const {
|
|
1152
|
-
getFloatingProps,
|
|
1153
|
-
isOpen,
|
|
1154
|
-
refs,
|
|
1155
|
-
strategy,
|
|
1156
|
-
x,
|
|
1157
|
-
y,
|
|
1158
|
-
hideInsteadOfClose
|
|
1159
|
-
} = usePopoverContext();
|
|
1160
|
-
const popoverRef = useMergeRefs([refs.setFloating, ref]);
|
|
1161
|
-
const appContainerState = useContext(AppContainerContext);
|
|
1162
|
-
const theme = useTheme();
|
|
1163
|
-
const [[header], [menu], [footer]] = partitionComponents(React.Children.toArray(children), [isComponent('MenuButtonContentHeader'), isComponent('MenuButtonContentMenu'), isComponent('MenuButtonContentFooter')]);
|
|
1164
|
-
return /*#__PURE__*/React.createElement(FloatingPortal, {
|
|
1165
|
-
root: appContainerState === null || appContainerState === void 0 ? void 0 : appContainerState.appContainerRef.current
|
|
1166
|
-
}, isOpen || hideInsteadOfClose ? /*#__PURE__*/React.createElement(StyledPopoverContent, _extends({
|
|
1167
|
-
$theme: theme,
|
|
1168
|
-
ref: popoverRef
|
|
1169
|
-
}, getFloatingProps(props), {
|
|
1170
|
-
style: _objectSpread2({
|
|
1171
|
-
position: strategy,
|
|
1172
|
-
top: y !== null && y !== void 0 ? y : 0,
|
|
1173
|
-
left: x !== null && x !== void 0 ? x : 0,
|
|
1174
|
-
display: hideInsteadOfClose && !isOpen ? 'none' : 'flex'
|
|
1175
|
-
}, style),
|
|
1176
|
-
className: classNames(PopoverContent.className, BaseMenuButtonContent.className, className)
|
|
1177
|
-
}), !header && !menu && !footer ? /*#__PURE__*/React.createElement(Flexbox, _extends({
|
|
1178
|
-
flexDirection: "column",
|
|
1179
|
-
gap: "0px",
|
|
1180
|
-
width: "100%"
|
|
1181
|
-
}, containerProps), /*#__PURE__*/React.createElement(MenuButtonContentMenu, null, children)) : /*#__PURE__*/React.createElement(Flexbox, _extends({
|
|
1182
|
-
flexDirection: "column",
|
|
1183
|
-
gap: "0px",
|
|
1184
|
-
width: "100%"
|
|
1185
|
-
}, containerProps), header, menu, footer)) : null);
|
|
1186
|
-
});
|
|
1187
|
-
BaseMenuButtonContent.className = CLASSNAME$5;
|
|
1188
|
-
BaseMenuButtonContent.displayName = COMPONENT_NAME$5;
|
|
1189
|
-
const MenuButtonContent = Object.assign(BaseMenuButtonContent, {
|
|
1190
|
-
Header: MenuButtonContentHeader,
|
|
1191
|
-
Menu: MenuButtonContentMenu,
|
|
1192
|
-
Footer: MenuButtonContentFooter
|
|
1193
|
-
});
|
|
1194
|
-
|
|
1195
|
-
const MenuButtonContext = /*#__PURE__*/React.createContext(null);
|
|
1196
|
-
|
|
1197
|
-
const COMPONENT_NAME$4 = 'MenuButtonTrigger';
|
|
1198
|
-
const CLASSNAME$4 = 'redsift-menu-button-trigger';
|
|
1199
|
-
|
|
1200
|
-
/**
|
|
1201
|
-
* The MenuButtonTrigger component.
|
|
1202
|
-
*/
|
|
1203
|
-
const MenuButtonTrigger = /*#__PURE__*/forwardRef((props, ref) => {
|
|
1204
|
-
const {
|
|
1205
|
-
children
|
|
1206
|
-
} = props;
|
|
1207
|
-
const {
|
|
1208
|
-
getReferenceProps,
|
|
1209
|
-
isOpen,
|
|
1210
|
-
handleOpen,
|
|
1211
|
-
refs
|
|
1212
|
-
} = usePopoverContext();
|
|
1213
|
-
const childrenRef = children.ref;
|
|
1214
|
-
const triggerRef = useMergeRefs([refs.setReference, ref, childrenRef]);
|
|
1215
|
-
const focusContext = useContext(FocusWithinGroupContext);
|
|
1216
|
-
const menuButtonContext = useContext(MenuButtonContext);
|
|
1217
|
-
const theme = useTheme();
|
|
1218
|
-
const renderedChildren = typeof children === 'function' ? children({
|
|
1219
|
-
isOpen
|
|
1220
|
-
}) : children;
|
|
1221
|
-
const handleKeyDown = event => {
|
|
1222
|
-
const code = event.code;
|
|
1223
|
-
if (code === 'Escape' || code === 'Tab') {
|
|
1224
|
-
if (isOpen) {
|
|
1225
|
-
handleOpen(false);
|
|
1226
|
-
}
|
|
1227
|
-
} else if (code === 'ArrowDown') {
|
|
1228
|
-
if (!isOpen) {
|
|
1229
|
-
handleOpen(true);
|
|
1230
|
-
}
|
|
1231
|
-
if (focusContext.state.selectedId !== null) {
|
|
1232
|
-
focusContext.dispatch({
|
|
1233
|
-
type: FocusWithinGroupActionType.DELAY_ACTION,
|
|
1234
|
-
payload: {
|
|
1235
|
-
type: FocusWithinGroupActionType.KEY_DOWN_ON_LIST,
|
|
1236
|
-
payload: {
|
|
1237
|
-
key: EventKey.ArrowDown,
|
|
1238
|
-
ctrlKey: event.ctrlKey
|
|
1239
|
-
}
|
|
1240
|
-
}
|
|
1241
|
-
});
|
|
1242
|
-
} else {
|
|
1243
|
-
focusContext.dispatch({
|
|
1244
|
-
type: FocusWithinGroupActionType.DELAY_ACTION,
|
|
1245
|
-
payload: {
|
|
1246
|
-
type: FocusWithinGroupActionType.KEY_DOWN_ON_LIST,
|
|
1247
|
-
payload: {
|
|
1248
|
-
key: EventKey.Home,
|
|
1249
|
-
ctrlKey: event.ctrlKey
|
|
1250
|
-
}
|
|
1251
|
-
}
|
|
1252
|
-
});
|
|
1253
|
-
}
|
|
1254
|
-
event.preventDefault();
|
|
1255
|
-
event.stopPropagation();
|
|
1256
|
-
} else if (code === 'ArrowUp') {
|
|
1257
|
-
if (!isOpen) {
|
|
1258
|
-
handleOpen(true);
|
|
1259
|
-
}
|
|
1260
|
-
focusContext.dispatch({
|
|
1261
|
-
type: FocusWithinGroupActionType.DELAY_ACTION,
|
|
1262
|
-
payload: {
|
|
1263
|
-
type: FocusWithinGroupActionType.KEY_DOWN_ON_LIST,
|
|
1264
|
-
payload: {
|
|
1265
|
-
key: focusContext.state.selectedId !== null ? EventKey.ArrowUp : EventKey.Home,
|
|
1266
|
-
ctrlKey: event.ctrlKey
|
|
1267
|
-
}
|
|
1268
|
-
}
|
|
1269
|
-
});
|
|
1270
|
-
event.preventDefault();
|
|
1271
|
-
event.stopPropagation();
|
|
1272
|
-
} else if (code === 'Home') {
|
|
1273
|
-
if (!isOpen) {
|
|
1274
|
-
handleOpen(true);
|
|
1275
|
-
}
|
|
1276
|
-
focusContext.dispatch({
|
|
1277
|
-
type: FocusWithinGroupActionType.DELAY_ACTION,
|
|
1278
|
-
payload: {
|
|
1279
|
-
type: FocusWithinGroupActionType.KEY_DOWN_ON_LIST,
|
|
1280
|
-
payload: {
|
|
1281
|
-
key: EventKey.Home,
|
|
1282
|
-
ctrlKey: event.ctrlKey
|
|
1283
|
-
}
|
|
1284
|
-
}
|
|
1285
|
-
});
|
|
1286
|
-
event.preventDefault();
|
|
1287
|
-
event.stopPropagation();
|
|
1288
|
-
} else if (code === 'End') {
|
|
1289
|
-
if (!isOpen) {
|
|
1290
|
-
handleOpen(true);
|
|
1291
|
-
}
|
|
1292
|
-
focusContext.dispatch({
|
|
1293
|
-
type: FocusWithinGroupActionType.DELAY_ACTION,
|
|
1294
|
-
payload: {
|
|
1295
|
-
type: FocusWithinGroupActionType.KEY_DOWN_ON_LIST,
|
|
1296
|
-
payload: {
|
|
1297
|
-
key: EventKey.End,
|
|
1298
|
-
ctrlKey: event.ctrlKey
|
|
1299
|
-
}
|
|
1300
|
-
}
|
|
1301
|
-
});
|
|
1302
|
-
event.preventDefault();
|
|
1303
|
-
event.stopPropagation();
|
|
1304
|
-
} else if (code === 'Enter') {
|
|
1305
|
-
if (isOpen && focusContext.state.selectedId) {
|
|
1306
|
-
var _document$getElementB, _document$getElementB2, _document$getElementB3, _document$getElementB4;
|
|
1307
|
-
(_document$getElementB = document.getElementById(focusContext.state.selectedId)) === null || _document$getElementB === void 0 ? void 0 : _document$getElementB.click();
|
|
1308
|
-
(_document$getElementB2 = document.getElementById(focusContext.state.selectedId)) === null || _document$getElementB2 === void 0 ? void 0 : (_document$getElementB3 = _document$getElementB2.getElementsByTagName('a')) === null || _document$getElementB3 === void 0 ? void 0 : (_document$getElementB4 = _document$getElementB3[0]) === null || _document$getElementB4 === void 0 ? void 0 : _document$getElementB4.click();
|
|
1309
|
-
}
|
|
1310
|
-
}
|
|
1311
|
-
};
|
|
1312
|
-
const handleClick = event => {
|
|
1313
|
-
event.preventDefault();
|
|
1314
|
-
event.stopPropagation();
|
|
1315
|
-
if (isOpen) {
|
|
1316
|
-
handleOpen(false);
|
|
1317
|
-
} else {
|
|
1318
|
-
var _focusContext$state$a, _focusContext$state$a2;
|
|
1319
|
-
handleOpen(true);
|
|
1320
|
-
focusContext.dispatch({
|
|
1321
|
-
type: FocusWithinGroupActionType.DELAY_ACTION,
|
|
1322
|
-
payload: {
|
|
1323
|
-
type: FocusWithinGroupActionType.FOCUS_ON_LIST,
|
|
1324
|
-
payload: {
|
|
1325
|
-
id: (_focusContext$state$a = (_focusContext$state$a2 = focusContext.state.activedescendant) === null || _focusContext$state$a2 === void 0 ? void 0 : _focusContext$state$a2[0]) !== null && _focusContext$state$a !== void 0 ? _focusContext$state$a : ''
|
|
1326
|
-
}
|
|
1327
|
-
}
|
|
1328
|
-
});
|
|
1329
|
-
}
|
|
1330
|
-
};
|
|
1331
|
-
if (isComponent('Button')(renderedChildren) || isComponent('IconButton')(renderedChildren)) {
|
|
1332
|
-
var _props$children, _focusContext$state$a3, _menuButtonContext$co, _menuButtonContext$va;
|
|
1333
|
-
return /*#__PURE__*/React.cloneElement(renderedChildren, _objectSpread2(_objectSpread2({}, getReferenceProps(_objectSpread2(_objectSpread2(_objectSpread2({
|
|
1334
|
-
ref: triggerRef
|
|
1335
|
-
}, props), renderedChildren.props), {}, {
|
|
1336
|
-
children: (_props$children = renderedChildren.props.children) !== null && _props$children !== void 0 ? _props$children : ''
|
|
1337
|
-
}))), {}, {
|
|
1338
|
-
theme,
|
|
1339
|
-
'aria-activedescendant': isOpen ? (_focusContext$state$a3 = focusContext.state.activedescendant) === null || _focusContext$state$a3 === void 0 ? void 0 : _focusContext$state$a3[0] : undefined,
|
|
1340
|
-
className: classNames(renderedChildren.props.className, menuButtonContext === null || menuButtonContext === void 0 ? void 0 : menuButtonContext.triggerClassName),
|
|
1341
|
-
color: (_menuButtonContext$co = menuButtonContext === null || menuButtonContext === void 0 ? void 0 : menuButtonContext.color) !== null && _menuButtonContext$co !== void 0 ? _menuButtonContext$co : renderedChildren.props.color,
|
|
1342
|
-
isActive: isOpen,
|
|
1343
|
-
isDisabled: menuButtonContext === null || menuButtonContext === void 0 ? void 0 : menuButtonContext.isDisabled,
|
|
1344
|
-
onClick: handleClick,
|
|
1345
|
-
onKeyDown: handleKeyDown,
|
|
1346
|
-
role: 'button',
|
|
1347
|
-
variant: (_menuButtonContext$va = menuButtonContext === null || menuButtonContext === void 0 ? void 0 : menuButtonContext.variant) !== null && _menuButtonContext$va !== void 0 ? _menuButtonContext$va : renderedChildren.props.variant
|
|
1348
|
-
}));
|
|
1349
|
-
}
|
|
1350
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, renderedChildren);
|
|
1351
|
-
});
|
|
1352
|
-
MenuButtonTrigger.className = CLASSNAME$4;
|
|
1353
|
-
MenuButtonTrigger.displayName = COMPONENT_NAME$4;
|
|
1354
|
-
|
|
1355
|
-
const COMPONENT_NAME$3 = 'MenuButton';
|
|
1356
|
-
const CLASSNAME$3 = 'redsift-menu-button';
|
|
1357
|
-
|
|
1358
|
-
/**
|
|
1359
|
-
* The MenuButton component.
|
|
1360
|
-
*/
|
|
1361
|
-
const BaseMenuButton = props => {
|
|
1362
|
-
const {
|
|
1363
|
-
color,
|
|
1364
|
-
description,
|
|
1365
|
-
descriptionProps,
|
|
1366
|
-
isDisabled,
|
|
1367
|
-
label,
|
|
1368
|
-
labelProps,
|
|
1369
|
-
minWidth = 'trigger-width',
|
|
1370
|
-
theme: propsTheme,
|
|
1371
|
-
triggerClassName,
|
|
1372
|
-
variant,
|
|
1373
|
-
wrapperProps
|
|
1374
|
-
} = props;
|
|
1375
|
-
const theme = useTheme(propsTheme);
|
|
1376
|
-
|
|
1377
|
-
/** MenuButton context. */
|
|
1378
|
-
const state = {
|
|
1379
|
-
color,
|
|
1380
|
-
isDisabled: isDisabled || false,
|
|
1381
|
-
theme,
|
|
1382
|
-
triggerClassName,
|
|
1383
|
-
variant
|
|
1384
|
-
};
|
|
1385
|
-
return /*#__PURE__*/React.createElement(ThemeProvider, {
|
|
1386
|
-
value: {
|
|
1387
|
-
theme
|
|
1388
|
-
}
|
|
1389
|
-
}, /*#__PURE__*/React.createElement(FocusWithinGroup, {
|
|
1390
|
-
focusType: "virtual-focus",
|
|
1391
|
-
listRole: "menu",
|
|
1392
|
-
focusOnInit: false
|
|
1393
|
-
}, /*#__PURE__*/React.createElement(MenuButtonContext.Provider, {
|
|
1394
|
-
value: state
|
|
1395
|
-
}, /*#__PURE__*/React.createElement(Flexbox, _extends({
|
|
1396
|
-
flexDirection: "column",
|
|
1397
|
-
alignItems: "flex-start",
|
|
1398
|
-
gap: "0px"
|
|
1399
|
-
}, wrapperProps), label && typeof label === 'string' ? /*#__PURE__*/React.createElement(Text, labelProps, label) : label ? label : null, /*#__PURE__*/React.createElement(Popover, _extends({
|
|
1400
|
-
theme: theme,
|
|
1401
|
-
overrideDisplayName: {
|
|
1402
|
-
content: 'MenuButtonContent',
|
|
1403
|
-
trigger: 'MenuButtonTrigger'
|
|
1404
|
-
},
|
|
1405
|
-
placement: "bottom-end",
|
|
1406
|
-
minWidth: minWidth
|
|
1407
|
-
}, props)), description && typeof description === 'string' ? /*#__PURE__*/React.createElement(Text, _extends({
|
|
1408
|
-
theme: theme,
|
|
1409
|
-
marginTop: "8px",
|
|
1410
|
-
variant: "caption",
|
|
1411
|
-
color: theme === Theme.light ? 'dark-grey' : 'white'
|
|
1412
|
-
}, descriptionProps), description) : description ? description : null))));
|
|
1413
|
-
};
|
|
1414
|
-
BaseMenuButton.className = CLASSNAME$3;
|
|
1415
|
-
BaseMenuButton.displayName = COMPONENT_NAME$3;
|
|
1416
|
-
const MenuButton = Object.assign(BaseMenuButton, {
|
|
1417
|
-
Trigger: MenuButtonTrigger,
|
|
1418
|
-
Content: MenuButtonContent
|
|
1419
|
-
});
|
|
1420
|
-
|
|
1421
|
-
const COMPONENT_NAME$2 = 'SelectContent';
|
|
1422
|
-
const CLASSNAME$2 = 'redsift-select-content';
|
|
1423
|
-
|
|
1424
|
-
/**
|
|
1425
|
-
* The SelectContent component.
|
|
1426
|
-
*/
|
|
1427
|
-
const SelectContent = /*#__PURE__*/forwardRef((props, ref) => {
|
|
1428
|
-
const {
|
|
1429
|
-
children,
|
|
1430
|
-
className,
|
|
1431
|
-
style
|
|
1432
|
-
} = props;
|
|
1433
|
-
const containerProps = getContainerProps(props);
|
|
1434
|
-
const {
|
|
1435
|
-
getFloatingProps,
|
|
1436
|
-
isOpen,
|
|
1437
|
-
refs,
|
|
1438
|
-
strategy,
|
|
1439
|
-
x,
|
|
1440
|
-
y
|
|
1441
|
-
} = usePopoverContext();
|
|
1442
|
-
const popoverRef = useMergeRefs([refs.setFloating, ref]);
|
|
1443
|
-
const appContainerState = useContext(AppContainerContext);
|
|
1444
|
-
const focusContext = useContext(FocusWithinGroupContext);
|
|
1445
|
-
const listboxState = useContext(ListboxContext);
|
|
1446
|
-
const theme = useTheme();
|
|
1447
|
-
useEffect(() => {
|
|
1448
|
-
if (focusContext && focusContext.state.delayedAction && focusContext.state.tabStops.length) {
|
|
1449
|
-
focusContext.dispatch(focusContext.state.delayedAction);
|
|
1450
|
-
}
|
|
1451
|
-
}, [focusContext.state.delayedAction, focusContext.state.tabStops.length]);
|
|
1452
|
-
return /*#__PURE__*/React.createElement(FloatingPortal, {
|
|
1453
|
-
root: appContainerState === null || appContainerState === void 0 ? void 0 : appContainerState.appContainerRef.current
|
|
1454
|
-
}, isOpen && /*#__PURE__*/React.createElement(StyledPopoverContent, _extends({
|
|
1455
|
-
$theme: theme,
|
|
1456
|
-
ref: popoverRef
|
|
1457
|
-
}, getFloatingProps(props), {
|
|
1458
|
-
style: _objectSpread2({
|
|
1459
|
-
position: strategy,
|
|
1460
|
-
top: y !== null && y !== void 0 ? y : 0,
|
|
1461
|
-
left: x !== null && x !== void 0 ? x : 0
|
|
1462
|
-
}, style),
|
|
1463
|
-
className: classNames(PopoverContent.className, SelectContent.className, className),
|
|
1464
|
-
"aria-disabled": listboxState.state.isDisabled
|
|
1465
|
-
}), /*#__PURE__*/React.createElement(Flexbox, _extends({
|
|
1466
|
-
flexDirection: "column",
|
|
1467
|
-
gap: "0px",
|
|
1468
|
-
margin: "8px 0px",
|
|
1469
|
-
width: "100%"
|
|
1470
|
-
}, containerProps), children)));
|
|
1471
|
-
});
|
|
1472
|
-
SelectContent.className = CLASSNAME$2;
|
|
1473
|
-
SelectContent.displayName = COMPONENT_NAME$2;
|
|
1474
|
-
|
|
1475
|
-
const SelectContext = /*#__PURE__*/React.createContext(null);
|
|
1476
|
-
|
|
1477
|
-
const COMPONENT_NAME$1 = 'SelectTrigger';
|
|
1478
|
-
const CLASSNAME$1 = 'redsift-select-trigger';
|
|
1479
|
-
|
|
1480
|
-
/**
|
|
1481
|
-
* The SelectTrigger component.
|
|
1482
|
-
*/
|
|
1483
|
-
const SelectTrigger = /*#__PURE__*/forwardRef((props, ref) => {
|
|
1484
|
-
var _renderedChildren$pro;
|
|
1485
|
-
const {
|
|
1486
|
-
children,
|
|
1487
|
-
hideExpandButton
|
|
1488
|
-
} = props;
|
|
1489
|
-
const {
|
|
1490
|
-
getReferenceProps,
|
|
1491
|
-
isOpen,
|
|
1492
|
-
handleOpen,
|
|
1493
|
-
refs
|
|
1494
|
-
} = usePopoverContext();
|
|
1495
|
-
const childrenRef = children.ref;
|
|
1496
|
-
const triggerRef = useMergeRefs([refs.setReference, ref, childrenRef]);
|
|
1497
|
-
const focusContext = useContext(FocusWithinGroupContext);
|
|
1498
|
-
const selectContext = useContext(SelectContext);
|
|
1499
|
-
const listboxState = useContext(ListboxContext);
|
|
1500
|
-
const theme = useTheme();
|
|
1501
|
-
const renderedChildren = typeof children === 'function' ? children({
|
|
1502
|
-
value: selectContext === null || selectContext === void 0 ? void 0 : selectContext.value,
|
|
1503
|
-
isOpen
|
|
1504
|
-
}) : children;
|
|
1505
|
-
const _inputRef = useRef();
|
|
1506
|
-
const inputRef = (_renderedChildren$pro = renderedChildren.props.inputRef) !== null && _renderedChildren$pro !== void 0 ? _renderedChildren$pro : _inputRef;
|
|
1507
|
-
const handleKeyDown = event => {
|
|
1508
|
-
const code = event.code;
|
|
1509
|
-
if (code === 'Escape') {
|
|
1510
|
-
if (isOpen) {
|
|
1511
|
-
handleOpen(false);
|
|
1512
|
-
}
|
|
1513
|
-
} else if (code === 'ArrowDown') {
|
|
1514
|
-
var _focusContext$state$a;
|
|
1515
|
-
if (!isOpen) {
|
|
1516
|
-
handleOpen(true);
|
|
1517
|
-
}
|
|
1518
|
-
if (focusContext.state.selectedId !== null) {
|
|
1519
|
-
focusContext.dispatch({
|
|
1520
|
-
type: FocusWithinGroupActionType.DELAY_ACTION,
|
|
1521
|
-
payload: {
|
|
1522
|
-
type: FocusWithinGroupActionType.KEY_DOWN_ON_LIST,
|
|
1523
|
-
payload: {
|
|
1524
|
-
key: EventKey.ArrowDown,
|
|
1525
|
-
ctrlKey: event.ctrlKey
|
|
1526
|
-
}
|
|
1527
|
-
}
|
|
1528
|
-
});
|
|
1529
|
-
} else if (!((_focusContext$state$a = focusContext.state.activedescendant) !== null && _focusContext$state$a !== void 0 && _focusContext$state$a[0])) {
|
|
1530
|
-
focusContext.dispatch({
|
|
1531
|
-
type: FocusWithinGroupActionType.DELAY_ACTION,
|
|
1532
|
-
payload: {
|
|
1533
|
-
type: FocusWithinGroupActionType.KEY_DOWN_ON_LIST,
|
|
1534
|
-
payload: {
|
|
1535
|
-
key: EventKey.Home,
|
|
1536
|
-
ctrlKey: event.ctrlKey
|
|
1537
|
-
}
|
|
1538
|
-
}
|
|
1539
|
-
});
|
|
1540
|
-
} else {
|
|
1541
|
-
var _focusContext$state$a2, _focusContext$state$a3;
|
|
1542
|
-
focusContext.dispatch({
|
|
1543
|
-
type: FocusWithinGroupActionType.DELAY_ACTION,
|
|
1544
|
-
payload: {
|
|
1545
|
-
type: FocusWithinGroupActionType.FOCUS_ON_LIST,
|
|
1546
|
-
payload: {
|
|
1547
|
-
id: (_focusContext$state$a2 = (_focusContext$state$a3 = focusContext.state.activedescendant) === null || _focusContext$state$a3 === void 0 ? void 0 : _focusContext$state$a3[0]) !== null && _focusContext$state$a2 !== void 0 ? _focusContext$state$a2 : ''
|
|
1548
|
-
}
|
|
1549
|
-
}
|
|
1550
|
-
});
|
|
1551
|
-
}
|
|
1552
|
-
event.preventDefault();
|
|
1553
|
-
} else if (code === 'ArrowUp') {
|
|
1554
|
-
if (!isOpen) {
|
|
1555
|
-
handleOpen(true);
|
|
1556
|
-
}
|
|
1557
|
-
focusContext.dispatch({
|
|
1558
|
-
type: FocusWithinGroupActionType.DELAY_ACTION,
|
|
1559
|
-
payload: {
|
|
1560
|
-
type: FocusWithinGroupActionType.KEY_DOWN_ON_LIST,
|
|
1561
|
-
payload: {
|
|
1562
|
-
key: focusContext.state.selectedId !== null ? EventKey.ArrowUp : EventKey.Home,
|
|
1563
|
-
ctrlKey: event.ctrlKey
|
|
1564
|
-
}
|
|
1565
|
-
}
|
|
1566
|
-
});
|
|
1567
|
-
event.preventDefault();
|
|
1568
|
-
} else if (code === 'Home') {
|
|
1569
|
-
if (!isOpen) {
|
|
1570
|
-
handleOpen(true);
|
|
1571
|
-
}
|
|
1572
|
-
focusContext.dispatch({
|
|
1573
|
-
type: FocusWithinGroupActionType.DELAY_ACTION,
|
|
1574
|
-
payload: {
|
|
1575
|
-
type: FocusWithinGroupActionType.KEY_DOWN_ON_LIST,
|
|
1576
|
-
payload: {
|
|
1577
|
-
key: EventKey.Home,
|
|
1578
|
-
ctrlKey: event.ctrlKey
|
|
1579
|
-
}
|
|
1580
|
-
}
|
|
1581
|
-
});
|
|
1582
|
-
event.preventDefault();
|
|
1583
|
-
} else if (code === 'End') {
|
|
1584
|
-
if (!isOpen) {
|
|
1585
|
-
handleOpen(true);
|
|
1586
|
-
}
|
|
1587
|
-
focusContext.dispatch({
|
|
1588
|
-
type: FocusWithinGroupActionType.DELAY_ACTION,
|
|
1589
|
-
payload: {
|
|
1590
|
-
type: FocusWithinGroupActionType.KEY_DOWN_ON_LIST,
|
|
1591
|
-
payload: {
|
|
1592
|
-
key: EventKey.End,
|
|
1593
|
-
ctrlKey: event.ctrlKey
|
|
1594
|
-
}
|
|
1595
|
-
}
|
|
1596
|
-
});
|
|
1597
|
-
event.preventDefault();
|
|
1598
|
-
} else if (code === 'Enter') {
|
|
1599
|
-
if (isOpen && focusContext.state.selectedId) {
|
|
1600
|
-
var _focusContext$state$a4, _focusContext$state$a5;
|
|
1601
|
-
listboxState.dispatch({
|
|
1602
|
-
type: ListboxActionType.SET,
|
|
1603
|
-
payload: {
|
|
1604
|
-
values: [(_focusContext$state$a4 = (_focusContext$state$a5 = focusContext.state.activedescendant) === null || _focusContext$state$a5 === void 0 ? void 0 : _focusContext$state$a5[1]) !== null && _focusContext$state$a4 !== void 0 ? _focusContext$state$a4 : ''],
|
|
1605
|
-
activedescendant: focusContext.state.activedescendant
|
|
1606
|
-
}
|
|
1607
|
-
});
|
|
1608
|
-
}
|
|
1609
|
-
}
|
|
1610
|
-
};
|
|
1611
|
-
const handleClick = event => {
|
|
1612
|
-
event.preventDefault();
|
|
1613
|
-
if (isOpen) {
|
|
1614
|
-
handleOpen(false);
|
|
1615
|
-
} else {
|
|
1616
|
-
var _focusContext$state$a6, _focusContext$state$a7;
|
|
1617
|
-
handleOpen(true);
|
|
1618
|
-
focusContext.dispatch({
|
|
1619
|
-
type: FocusWithinGroupActionType.DELAY_ACTION,
|
|
1620
|
-
payload: {
|
|
1621
|
-
type: FocusWithinGroupActionType.FOCUS_ON_LIST,
|
|
1622
|
-
payload: {
|
|
1623
|
-
id: (_focusContext$state$a6 = (_focusContext$state$a7 = focusContext.state.activedescendant) === null || _focusContext$state$a7 === void 0 ? void 0 : _focusContext$state$a7[0]) !== null && _focusContext$state$a6 !== void 0 ? _focusContext$state$a6 : ''
|
|
1624
|
-
}
|
|
1625
|
-
}
|
|
1626
|
-
});
|
|
1627
|
-
}
|
|
1628
|
-
};
|
|
1629
|
-
useEffect(() => {
|
|
1630
|
-
selectContext === null || selectContext === void 0 ? void 0 : selectContext.setValue(listboxState.state.selectedValues[0]);
|
|
1631
|
-
handleOpen(false);
|
|
1632
|
-
}, [listboxState.state]);
|
|
1633
|
-
if (isComponent('TextField')(renderedChildren)) {
|
|
1634
|
-
var _props$children, _focusContext$state$a8, _selectContext$color, _selectContext$varian, _props$inputProps;
|
|
1635
|
-
return /*#__PURE__*/React.cloneElement(renderedChildren, _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, getReferenceProps(_objectSpread2(_objectSpread2(_objectSpread2({
|
|
1636
|
-
ref: triggerRef
|
|
1637
|
-
}, props), renderedChildren.props), {}, {
|
|
1638
|
-
children: (_props$children = renderedChildren.props.children) !== null && _props$children !== void 0 ? _props$children : ''
|
|
1639
|
-
}))), {}, {
|
|
1640
|
-
'aria-activedescendant': isOpen ? (_focusContext$state$a8 = focusContext.state.activedescendant) === null || _focusContext$state$a8 === void 0 ? void 0 : _focusContext$state$a8[0] : undefined,
|
|
1641
|
-
className: classNames(renderedChildren.props.className, selectContext === null || selectContext === void 0 ? void 0 : selectContext.triggerClassName),
|
|
1642
|
-
color: (_selectContext$color = selectContext === null || selectContext === void 0 ? void 0 : selectContext.color) !== null && _selectContext$color !== void 0 ? _selectContext$color : renderedChildren.props.color,
|
|
1643
|
-
inputRef,
|
|
1644
|
-
internal: (value, isDisabled, isInvalid, isRequired) => {
|
|
1645
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, typeof renderedChildren.props.internal === 'function' ? renderedChildren.props.internal(value, isDisabled, isInvalid, isRequired) : renderedChildren.props.internal, hideExpandButton ? null : /*#__PURE__*/React.createElement(Icon, {
|
|
1646
|
-
color: isDisabled ? 'no-data' : 'question',
|
|
1647
|
-
icon: mdiChevronDown,
|
|
1648
|
-
style: {
|
|
1649
|
-
transition: 'transform 300ms ease-out',
|
|
1650
|
-
transform: `rotate(${isOpen ? '-180deg' : '0'})`,
|
|
1651
|
-
cursor: 'pointer'
|
|
1652
|
-
}
|
|
1653
|
-
}));
|
|
1654
|
-
},
|
|
1655
|
-
isActive: isOpen,
|
|
1656
|
-
isDisabled: selectContext === null || selectContext === void 0 ? void 0 : selectContext.isDisabled,
|
|
1657
|
-
isReadOnly: true,
|
|
1658
|
-
theme,
|
|
1659
|
-
role: 'combobox',
|
|
1660
|
-
onClick: handleClick,
|
|
1661
|
-
onKeyDown: handleKeyDown,
|
|
1662
|
-
style: _objectSpread2(_objectSpread2({}, renderedChildren.props.style), {}, {
|
|
1663
|
-
caretColor: 'transparent',
|
|
1664
|
-
cursor: 'pointer'
|
|
1665
|
-
}),
|
|
1666
|
-
variant: (_selectContext$varian = selectContext === null || selectContext === void 0 ? void 0 : selectContext.variant) !== null && _selectContext$varian !== void 0 ? _selectContext$varian : renderedChildren.props.variant
|
|
1667
|
-
}, (selectContext === null || selectContext === void 0 ? void 0 : selectContext.isInvalid) === true && {
|
|
1668
|
-
color: 'error'
|
|
1669
|
-
}), typeof children !== 'function' && (selectContext === null || selectContext === void 0 ? void 0 : selectContext.value) && {
|
|
1670
|
-
value: selectContext.value
|
|
1671
|
-
}), {}, {
|
|
1672
|
-
inputProps: _objectSpread2(_objectSpread2({}, renderedChildren.props.inputProps), {}, {
|
|
1673
|
-
style: _objectSpread2(_objectSpread2({}, (_props$inputProps = renderedChildren.props.inputProps) === null || _props$inputProps === void 0 ? void 0 : _props$inputProps.style), {}, {
|
|
1674
|
-
cursor: 'pointer'
|
|
1675
|
-
})
|
|
1676
|
-
})
|
|
1677
|
-
}));
|
|
1678
|
-
} else if (isComponent('Button')(renderedChildren)) {
|
|
1679
|
-
var _props$children2, _focusContext$state$a9, _props$ariaLabel, _selectContext$color2, _props$rightIcon, _props$rightIconProps, _selectContext$varian2;
|
|
1680
|
-
const children = renderedChildren.props.children;
|
|
1681
|
-
const label = typeof children === 'string' ? children : children === null || children === void 0 ? void 0 : children.textContent;
|
|
1682
|
-
return /*#__PURE__*/React.cloneElement(renderedChildren, _objectSpread2(_objectSpread2(_objectSpread2({}, getReferenceProps(_objectSpread2(_objectSpread2(_objectSpread2({
|
|
1683
|
-
ref: triggerRef
|
|
1684
|
-
}, props), renderedChildren.props), {}, {
|
|
1685
|
-
children: (_props$children2 = renderedChildren.props.children) !== null && _props$children2 !== void 0 ? _props$children2 : ''
|
|
1686
|
-
}))), {}, {
|
|
1687
|
-
'aria-activedescendant': isOpen ? (_focusContext$state$a9 = focusContext.state.activedescendant) === null || _focusContext$state$a9 === void 0 ? void 0 : _focusContext$state$a9[0] : undefined,
|
|
1688
|
-
'aria-label': (_props$ariaLabel = renderedChildren.props['aria-label']) !== null && _props$ariaLabel !== void 0 ? _props$ariaLabel : label,
|
|
1689
|
-
className: classNames(renderedChildren.props.className, selectContext === null || selectContext === void 0 ? void 0 : selectContext.triggerClassName),
|
|
1690
|
-
color: (_selectContext$color2 = selectContext === null || selectContext === void 0 ? void 0 : selectContext.color) !== null && _selectContext$color2 !== void 0 ? _selectContext$color2 : renderedChildren.props.color,
|
|
1691
|
-
isActive: isOpen,
|
|
1692
|
-
isDisabled: selectContext === null || selectContext === void 0 ? void 0 : selectContext.isDisabled,
|
|
1693
|
-
onClick: handleClick,
|
|
1694
|
-
onKeyDown: handleKeyDown,
|
|
1695
|
-
rightIcon: (_props$rightIcon = renderedChildren.props.rightIcon) !== null && _props$rightIcon !== void 0 ? _props$rightIcon : mdiChevronDown,
|
|
1696
|
-
rightIconProps: renderedChildren.props.rightIcon ? renderedChildren.props.rightIconProps : (_props$rightIconProps = renderedChildren.props.rightIconProps) !== null && _props$rightIconProps !== void 0 ? _props$rightIconProps : {
|
|
1697
|
-
style: {
|
|
1698
|
-
transition: 'transform 300ms ease-out',
|
|
1699
|
-
transform: `rotate(${isOpen ? '-180deg' : '0'})`
|
|
1700
|
-
}
|
|
1701
|
-
},
|
|
1702
|
-
role: 'combobox',
|
|
1703
|
-
theme,
|
|
1704
|
-
variant: (_selectContext$varian2 = selectContext === null || selectContext === void 0 ? void 0 : selectContext.variant) !== null && _selectContext$varian2 !== void 0 ? _selectContext$varian2 : renderedChildren.props.variant
|
|
1705
|
-
}, (selectContext === null || selectContext === void 0 ? void 0 : selectContext.isInvalid) === true && {
|
|
1706
|
-
color: 'error'
|
|
1707
|
-
}), typeof children !== 'function' && (selectContext === null || selectContext === void 0 ? void 0 : selectContext.value) && {
|
|
1708
|
-
children: selectContext.value
|
|
1709
|
-
}));
|
|
1710
|
-
}
|
|
1711
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, renderedChildren);
|
|
1712
|
-
});
|
|
1713
|
-
SelectTrigger.className = CLASSNAME$1;
|
|
1714
|
-
SelectTrigger.displayName = COMPONENT_NAME$1;
|
|
1715
|
-
|
|
1716
|
-
const COMPONENT_NAME = 'Select';
|
|
1717
|
-
const CLASSNAME = 'redsift-select';
|
|
1718
|
-
|
|
1719
|
-
/**
|
|
1720
|
-
* The Select component.
|
|
1721
|
-
*/
|
|
1722
|
-
const BaseSelect = props => {
|
|
1723
|
-
const {
|
|
1724
|
-
color,
|
|
1725
|
-
defaultValue,
|
|
1726
|
-
description,
|
|
1727
|
-
descriptionProps,
|
|
1728
|
-
isDisabled,
|
|
1729
|
-
isInvalid,
|
|
1730
|
-
minWidth = 'trigger-width',
|
|
1731
|
-
onChange,
|
|
1732
|
-
theme: propsTheme,
|
|
1733
|
-
triggerClassName,
|
|
1734
|
-
value,
|
|
1735
|
-
variant,
|
|
1736
|
-
wrapperProps
|
|
1737
|
-
} = props;
|
|
1738
|
-
const theme = useTheme(propsTheme);
|
|
1739
|
-
const [selectedValue, setValue] = useState(value || defaultValue || '');
|
|
1740
|
-
useEffect(() => {
|
|
1741
|
-
if (value) {
|
|
1742
|
-
state.setValue(value);
|
|
1743
|
-
}
|
|
1744
|
-
}, [value]);
|
|
1745
|
-
|
|
1746
|
-
/** Listbox context */
|
|
1747
|
-
const [listboxState, listboxDispatch] = useReducer(ListboxReducer, {
|
|
1748
|
-
isDisabled,
|
|
1749
|
-
selectedValues: [selectedValue]
|
|
1750
|
-
});
|
|
1751
|
-
const listboxContext = useMemo(() => ({
|
|
1752
|
-
state: listboxState,
|
|
1753
|
-
dispatch: listboxDispatch
|
|
1754
|
-
}), [listboxState]);
|
|
1755
|
-
useEffect(() => {
|
|
1756
|
-
listboxDispatch({
|
|
1757
|
-
type: ListboxActionType.UPDATE_OPTIONS,
|
|
1758
|
-
payload: {
|
|
1759
|
-
isDisabled: isDisabled || false
|
|
1760
|
-
}
|
|
1761
|
-
});
|
|
1762
|
-
}, [isDisabled, theme]);
|
|
1763
|
-
|
|
1764
|
-
/** Select context. */
|
|
1765
|
-
const state = {
|
|
1766
|
-
color,
|
|
1767
|
-
isDisabled: isDisabled || false,
|
|
1768
|
-
isInvalid: isInvalid || false,
|
|
1769
|
-
setValue(value) {
|
|
1770
|
-
if (isDisabled) {
|
|
1771
|
-
return;
|
|
1772
|
-
}
|
|
1773
|
-
const previousValue = selectedValue;
|
|
1774
|
-
setValue(value);
|
|
1775
|
-
if (value !== previousValue && onChange) {
|
|
1776
|
-
onChange(value);
|
|
1777
|
-
}
|
|
1778
|
-
},
|
|
1779
|
-
theme,
|
|
1780
|
-
triggerClassName,
|
|
1781
|
-
value: selectedValue,
|
|
1782
|
-
variant
|
|
1783
|
-
};
|
|
1784
|
-
return /*#__PURE__*/React.createElement(ThemeProvider, {
|
|
1785
|
-
value: {
|
|
1786
|
-
theme
|
|
1787
|
-
}
|
|
1788
|
-
}, /*#__PURE__*/React.createElement(FocusWithinGroup, {
|
|
1789
|
-
focusType: "virtual-focus",
|
|
1790
|
-
focusOnInit: false
|
|
1791
|
-
}, /*#__PURE__*/React.createElement(SelectContext.Provider, {
|
|
1792
|
-
value: state
|
|
1793
|
-
}, /*#__PURE__*/React.createElement(ListboxContext.Provider, {
|
|
1794
|
-
value: listboxContext
|
|
1795
|
-
}, /*#__PURE__*/React.createElement(Flexbox, _extends({
|
|
1796
|
-
flexDirection: "column",
|
|
1797
|
-
alignItems: "flex-start",
|
|
1798
|
-
gap: "0px"
|
|
1799
|
-
}, wrapperProps), /*#__PURE__*/React.createElement(Popover, _extends({
|
|
1800
|
-
theme: theme,
|
|
1801
|
-
overrideDisplayName: {
|
|
1802
|
-
content: 'SelectContent',
|
|
1803
|
-
trigger: 'SelectTrigger'
|
|
1804
|
-
},
|
|
1805
|
-
placement: "bottom-start",
|
|
1806
|
-
role: "listbox",
|
|
1807
|
-
minWidth: minWidth
|
|
1808
|
-
}, props)), description && typeof description === 'string' ? /*#__PURE__*/React.createElement(Text, _extends({
|
|
1809
|
-
theme: theme,
|
|
1810
|
-
marginTop: "8px",
|
|
1811
|
-
variant: "caption",
|
|
1812
|
-
color: isInvalid ? 'error' : theme === Theme.light ? 'dark-grey' : 'white'
|
|
1813
|
-
}, descriptionProps), description) : description ? description : null)))));
|
|
1814
|
-
};
|
|
1815
|
-
BaseSelect.className = CLASSNAME;
|
|
1816
|
-
BaseSelect.displayName = COMPONENT_NAME;
|
|
1817
|
-
const Select = Object.assign(BaseSelect, {
|
|
1818
|
-
Trigger: SelectTrigger,
|
|
1819
|
-
Content: SelectContent
|
|
1820
|
-
});
|
|
1821
|
-
|
|
1822
|
-
export { BaseCombobox, BaseComboboxContent, BaseMenuButton, BaseMenuButtonContent, BaseSelect, Combobox, ComboboxContent, ComboboxContentFooter, ComboboxContentHeader, ComboboxContentListbox, ComboboxSelectionMode, ComboboxTrigger, ComboboxVariant, Item, MenuButton, MenuButtonContent, MenuButtonContentFooter, MenuButtonContentHeader, MenuButtonContentMenu, MenuButtonTrigger, Select, SelectContent, SelectTrigger };
|
|
1
|
+
export { C as ComboboxContentFooter } from './_internal/ComboboxContentFooter.js';
|
|
2
|
+
export { C as ComboboxContentHeader } from './_internal/ComboboxContentHeader.js';
|
|
3
|
+
export { C as ComboboxContentListbox } from './_internal/ComboboxContentListbox.js';
|
|
4
|
+
export { B as BaseComboboxContent, C as ComboboxContent } from './_internal/ComboboxContent.js';
|
|
5
|
+
export { C as ComboboxTrigger } from './_internal/ComboboxTrigger.js';
|
|
6
|
+
export { C as ComboboxSelectionMode, a as ComboboxVariant } from './_internal/types.js';
|
|
7
|
+
export { B as BaseCombobox, C as Combobox } from './_internal/Combobox2.js';
|
|
8
|
+
export { I as Item } from './_internal/Item2.js';
|
|
9
|
+
export { M as MenuButtonContentFooter } from './_internal/MenuButtonContentFooter.js';
|
|
10
|
+
export { M as MenuButtonContentHeader } from './_internal/MenuButtonContentHeader.js';
|
|
11
|
+
export { M as MenuButtonContentMenu } from './_internal/MenuButtonContentMenu.js';
|
|
12
|
+
export { B as BaseMenuButtonContent, M as MenuButtonContent } from './_internal/MenuButtonContent.js';
|
|
13
|
+
export { M as MenuButtonTrigger } from './_internal/MenuButtonTrigger.js';
|
|
14
|
+
export { B as BaseMenuButton, M as MenuButton } from './_internal/MenuButton.js';
|
|
15
|
+
export { S as SelectContent } from './_internal/SelectContent.js';
|
|
16
|
+
export { S as SelectTrigger } from './_internal/SelectTrigger.js';
|
|
17
|
+
export { B as BaseSelect, S as Select } from './_internal/Select2.js';
|
|
1823
18
|
//# sourceMappingURL=index.js.map
|