@zendeskgarden/react-dropdowns.legacy 9.0.0-next.6 → 9.0.0-next.8

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.
Files changed (60) hide show
  1. package/dist/esm/elements/Autocomplete/Autocomplete.js +144 -0
  2. package/dist/esm/elements/Combobox/Combobox.js +106 -0
  3. package/dist/esm/elements/Dropdown/Dropdown.js +178 -0
  4. package/dist/esm/elements/Fields/Field.js +35 -0
  5. package/dist/esm/elements/Fields/Hint.js +15 -0
  6. package/dist/esm/elements/Fields/Label.js +46 -0
  7. package/dist/esm/elements/Fields/Message.js +19 -0
  8. package/dist/esm/elements/Menu/Items/AddItem.js +66 -0
  9. package/dist/esm/elements/Menu/Items/HeaderIcon.js +44 -0
  10. package/dist/esm/elements/Menu/Items/HeaderItem.js +44 -0
  11. package/dist/esm/elements/Menu/Items/Item.js +140 -0
  12. package/dist/esm/elements/Menu/Items/ItemMeta.js +49 -0
  13. package/dist/esm/elements/Menu/Items/MediaBody.js +44 -0
  14. package/dist/esm/elements/Menu/Items/MediaFigure.js +42 -0
  15. package/dist/esm/elements/Menu/Items/MediaItem.js +44 -0
  16. package/dist/esm/elements/Menu/Items/NextItem.js +90 -0
  17. package/dist/esm/elements/Menu/Items/PreviousItem.js +87 -0
  18. package/dist/esm/elements/Menu/Menu.js +160 -0
  19. package/dist/esm/elements/Menu/Separator.js +37 -0
  20. package/dist/esm/elements/Multiselect/Multiselect.js +316 -0
  21. package/dist/esm/elements/Select/Select.js +195 -0
  22. package/dist/esm/elements/Trigger/Trigger.js +185 -0
  23. package/dist/esm/index.js +29 -0
  24. package/dist/esm/node_modules/@zendeskgarden/svg-icons/src/16/check-lg-stroke.svg.js +28 -0
  25. package/dist/esm/node_modules/@zendeskgarden/svg-icons/src/16/chevron-down-stroke.svg.js +25 -0
  26. package/dist/esm/node_modules/@zendeskgarden/svg-icons/src/16/chevron-left-stroke.svg.js +25 -0
  27. package/dist/esm/node_modules/@zendeskgarden/svg-icons/src/16/chevron-right-stroke.svg.js +25 -0
  28. package/dist/esm/node_modules/@zendeskgarden/svg-icons/src/16/plus-stroke.svg.js +26 -0
  29. package/dist/esm/styled/items/StyledAddItem.js +23 -0
  30. package/dist/esm/styled/items/StyledItem.js +44 -0
  31. package/dist/esm/styled/items/StyledItemIcon.js +27 -0
  32. package/dist/esm/styled/items/StyledItemMeta.js +22 -0
  33. package/dist/esm/styled/items/StyledNextIcon.js +31 -0
  34. package/dist/esm/styled/items/StyledNextItem.js +24 -0
  35. package/dist/esm/styled/items/StyledPreviousIcon.js +31 -0
  36. package/dist/esm/styled/items/StyledPreviousItem.js +23 -0
  37. package/dist/esm/styled/items/header/StyledHeaderIcon.js +22 -0
  38. package/dist/esm/styled/items/header/StyledHeaderItem.js +29 -0
  39. package/dist/esm/styled/items/media/StyledMediaBody.js +22 -0
  40. package/dist/esm/styled/items/media/StyledMediaFigure.js +34 -0
  41. package/dist/esm/styled/items/media/StyledMediaItem.js +23 -0
  42. package/dist/esm/styled/menu/StyledMenu.js +28 -0
  43. package/dist/esm/styled/menu/StyledMenuWrapper.js +30 -0
  44. package/dist/esm/styled/menu/StyledSeparator.js +23 -0
  45. package/dist/esm/styled/multiselect/StyledMultiselectInput.js +33 -0
  46. package/dist/esm/styled/multiselect/StyledMultiselectItemWrapper.js +22 -0
  47. package/dist/esm/styled/multiselect/StyledMultiselectItemsContainer.js +34 -0
  48. package/dist/esm/styled/multiselect/StyledMultiselectMoreAnchor.js +22 -0
  49. package/dist/esm/styled/select/StyledFauxInput.js +25 -0
  50. package/dist/esm/styled/select/StyledInput.js +25 -0
  51. package/dist/esm/styled/select/StyledSelect.js +22 -0
  52. package/dist/esm/types/index.js +10 -0
  53. package/dist/esm/utils/garden-placements.js +77 -0
  54. package/dist/esm/utils/useDropdownContext.js +18 -0
  55. package/dist/esm/utils/useFieldContext.js +18 -0
  56. package/dist/esm/utils/useItemContext.js +18 -0
  57. package/dist/esm/utils/useMenuContext.js +18 -0
  58. package/dist/index.cjs.js +51 -67
  59. package/package.json +6 -6
  60. package/dist/index.esm.js +0 -2032
package/dist/index.esm.js DELETED
@@ -1,2032 +0,0 @@
1
- /**
2
- * Copyright Zendesk, Inc.
3
- *
4
- * Use of this source code is governed under the Apache License, Version 2.0
5
- * found at http://www.apache.org/licenses/LICENSE-2.0.
6
- */
7
-
8
- import * as React from 'react';
9
- import React__default, { useContext, useRef, useState, Children, useEffect, useCallback, forwardRef, useMemo } from 'react';
10
- import PropTypes from 'prop-types';
11
- import styled, { ThemeContext, css } from 'styled-components';
12
- import Downshift from 'downshift';
13
- export { resetIdCounter } from 'downshift';
14
- import { Manager, Reference, Popper } from 'react-popper';
15
- import { composeEventHandlers, KEY_CODES } from '@zendeskgarden/container-utilities';
16
- import { arrowStyles, retrieveComponentStyles, DEFAULT_THEME, menuStyles, getColorV8, getLineHeight, useDocument } from '@zendeskgarden/react-theming';
17
- import { rgba, math } from 'polished';
18
- import { FauxInput, Input, VALIDATION, MediaInput, Field as Field$1, Hint as Hint$1, Label as Label$1, Message as Message$1 } from '@zendeskgarden/react-forms';
19
- import { mergeRefs } from 'react-merge-refs';
20
- import { useSelection } from '@zendeskgarden/container-selection';
21
- import { createPortal } from 'react-dom';
22
-
23
- function _extends$5() {
24
- _extends$5 = Object.assign ? Object.assign.bind() : function (target) {
25
- for (var i = 1; i < arguments.length; i++) {
26
- var source = arguments[i];
27
- for (var key in source) {
28
- if (Object.prototype.hasOwnProperty.call(source, key)) {
29
- target[key] = source[key];
30
- }
31
- }
32
- }
33
- return target;
34
- };
35
- return _extends$5.apply(this, arguments);
36
- }
37
-
38
- const DropdownContext = React__default.createContext(undefined);
39
- const useDropdownContext = () => {
40
- const dropdownContext = useContext(DropdownContext);
41
- if (!dropdownContext) {
42
- throw new Error('This component must be rendered within a `Dropdown` component.');
43
- }
44
- return dropdownContext;
45
- };
46
-
47
- const REMOVE_ITEM_STATE_TYPE = 'REMOVE_ITEM';
48
- const Dropdown = props => {
49
- const {
50
- children,
51
- isOpen,
52
- selectedItem,
53
- selectedItems,
54
- highlightedIndex,
55
- inputValue,
56
- onSelect,
57
- onStateChange,
58
- onInputValueChange,
59
- downshiftProps
60
- } = props;
61
- const itemIndexRef = useRef(0);
62
- const previousItemRef = useRef(undefined);
63
- const previousIndexRef = useRef(undefined);
64
- const nextItemsHashRef = useRef({});
65
- const containsMultiselectRef = useRef(false);
66
- const itemSearchRegistry = useRef([]);
67
- const [dropdownType, setDropdownType] = useState('');
68
- const {
69
- rtl
70
- } = useContext(ThemeContext);
71
- const hasMenuRef = useRef(false);
72
- const popperReferenceElementRef = useRef(null);
73
- const customGetInputProps = (_ref, downshift) => {
74
- let {
75
- onKeyDown,
76
- ...other
77
- } = _ref;
78
- return {
79
- onKeyDown: composeEventHandlers(onKeyDown, e => {
80
- const PREVIOUS_KEY = rtl ? KEY_CODES.RIGHT : KEY_CODES.LEFT;
81
- const NEXT_KEY = rtl ? KEY_CODES.LEFT : KEY_CODES.RIGHT;
82
- if (downshift.isOpen) {
83
- if (e.keyCode === PREVIOUS_KEY && previousIndexRef.current !== null && previousIndexRef.current !== undefined && !downshift.inputValue) {
84
- e.preventDefault();
85
- e.stopPropagation();
86
- downshift.selectItemAtIndex(previousIndexRef.current);
87
- }
88
- if (e.keyCode === NEXT_KEY) {
89
- const nextItemIndexes = Object.values(nextItemsHashRef.current);
90
- if (nextItemIndexes.includes(downshift.highlightedIndex)) {
91
- e.preventDefault();
92
- e.stopPropagation();
93
- downshift.selectItemAtIndex(downshift.highlightedIndex);
94
- }
95
- }
96
- } else if ((e.keyCode === KEY_CODES.ENTER || e.keyCode === KEY_CODES.SPACE) && !downshift.isOpen && dropdownType !== 'combobox') {
97
- e.preventDefault();
98
- e.stopPropagation();
99
- downshift.openMenu();
100
- }
101
- }),
102
- ...other
103
- };
104
- };
105
- const transformDownshift = _ref2 => {
106
- let {
107
- getInputProps,
108
- getToggleButtonProps,
109
- ...downshift
110
- } = _ref2;
111
- return {
112
- getInputProps: p => getInputProps(customGetInputProps(p, downshift)),
113
- getToggleButtonProps: p => getToggleButtonProps({
114
- 'aria-label': undefined,
115
- ...p
116
- }),
117
- ...downshift
118
- };
119
- };
120
- return React__default.createElement(Manager, null, React__default.createElement(Downshift, _extends$5({
121
- suppressRefError: true
122
- ,
123
- isOpen: isOpen,
124
- highlightedIndex: highlightedIndex,
125
- selectedItem: selectedItem || null
126
- ,
127
- inputValue: inputValue,
128
- onInputValueChange: (inputVal, stateAndHelpers) => {
129
- if (onInputValueChange) {
130
- if (stateAndHelpers.isOpen) {
131
- onInputValueChange(inputVal, stateAndHelpers);
132
- } else if (dropdownType === 'multiselect') {
133
- onInputValueChange('', stateAndHelpers);
134
- }
135
- }
136
- },
137
- onStateChange: (changes, stateAndHelpers) => {
138
- if (dropdownType === 'autocomplete' && changes.isOpen === false && !changes.selectedItem) {
139
- onSelect && onSelect(selectedItem, stateAndHelpers);
140
- }
141
- if (Object.prototype.hasOwnProperty.call(changes, 'selectedItem') && changes.selectedItem !== null) {
142
- if (selectedItems) {
143
- const {
144
- itemToString
145
- } = stateAndHelpers;
146
- const existingItemIndex = selectedItems.findIndex(item => {
147
- return itemToString(item) === itemToString(changes.selectedItem);
148
- });
149
- const updatedSelectedItems = Array.from(selectedItems);
150
- if (existingItemIndex === -1) {
151
- updatedSelectedItems.splice(updatedSelectedItems.length, 0, changes.selectedItem);
152
- } else {
153
- updatedSelectedItems.splice(existingItemIndex, 1);
154
- }
155
- changes.selectedItems = updatedSelectedItems;
156
- delete changes.selectedItem;
157
- onSelect && onSelect(updatedSelectedItems, stateAndHelpers);
158
- } else {
159
- onSelect && onSelect(changes.selectedItem, stateAndHelpers);
160
- }
161
- if (dropdownType === 'multiselect') {
162
- stateAndHelpers.setState({
163
- inputValue: ''
164
- });
165
- }
166
- }
167
- onStateChange && onStateChange(changes, stateAndHelpers);
168
- },
169
- stateReducer: (_state, changes) => {
170
- switch (changes.type) {
171
- case Downshift.stateChangeTypes.changeInput:
172
- if (changes.inputValue === '' && dropdownType === 'combobox') {
173
- return {
174
- ...changes,
175
- isOpen: false
176
- };
177
- }
178
- return changes;
179
- default:
180
- return changes;
181
- }
182
- }
183
- }, downshiftProps), downshift => React__default.createElement(DropdownContext.Provider, {
184
- value: {
185
- hasMenuRef,
186
- itemIndexRef,
187
- previousItemRef,
188
- previousIndexRef,
189
- nextItemsHashRef,
190
- popperReferenceElementRef,
191
- selectedItems,
192
- downshift: transformDownshift(downshift),
193
- containsMultiselectRef,
194
- itemSearchRegistry,
195
- setDropdownType
196
- }
197
- }, children)));
198
- };
199
- Dropdown.propTypes = {
200
- isOpen: PropTypes.bool,
201
- selectedItem: PropTypes.any,
202
- selectedItems: PropTypes.arrayOf(PropTypes.any),
203
- highlightedIndex: PropTypes.number,
204
- inputValue: PropTypes.string,
205
- onSelect: PropTypes.func,
206
- onStateChange: PropTypes.func,
207
- downshiftProps: PropTypes.object
208
- };
209
-
210
- function getPopperPlacement(gardenPlacement) {
211
- switch (gardenPlacement) {
212
- case 'end':
213
- return 'right';
214
- case 'end-top':
215
- return 'right-start';
216
- case 'end-bottom':
217
- return 'right-end';
218
- case 'start':
219
- return 'left';
220
- case 'start-top':
221
- return 'left-start';
222
- case 'start-bottom':
223
- return 'left-end';
224
- default:
225
- return gardenPlacement;
226
- }
227
- }
228
- function getRtlPopperPlacement(gardenPlacement) {
229
- const popperPlacement = getPopperPlacement(gardenPlacement);
230
- switch (popperPlacement) {
231
- case 'left':
232
- return 'right';
233
- case 'left-start':
234
- return 'right-start';
235
- case 'left-end':
236
- return 'right-end';
237
- case 'top-start':
238
- return 'top-end';
239
- case 'top-end':
240
- return 'top-start';
241
- case 'right':
242
- return 'left';
243
- case 'right-start':
244
- return 'left-start';
245
- case 'right-end':
246
- return 'left-end';
247
- case 'bottom-start':
248
- return 'bottom-end';
249
- case 'bottom-end':
250
- return 'bottom-start';
251
- default:
252
- return popperPlacement;
253
- }
254
- }
255
- function getArrowPosition(popperPlacement) {
256
- const arrowPositionMappings = {
257
- auto: 'top',
258
- top: 'bottom',
259
- 'top-start': 'bottom-left',
260
- 'top-end': 'bottom-right',
261
- right: 'left',
262
- 'right-start': 'left-top',
263
- 'right-end': 'left-bottom',
264
- bottom: 'top',
265
- 'bottom-start': 'top-left',
266
- 'bottom-end': 'top-right',
267
- left: 'right',
268
- 'left-start': 'right-top',
269
- 'left-end': 'right-bottom'
270
- };
271
- return popperPlacement ? arrowPositionMappings[popperPlacement] : 'top';
272
- }
273
- function getMenuPosition(popperPlacement) {
274
- if (popperPlacement === 'auto') {
275
- return 'bottom';
276
- }
277
- return popperPlacement ? popperPlacement.split('-')[0] : 'bottom';
278
- }
279
-
280
- const COMPONENT_ID$m = 'dropdowns.menu';
281
- const StyledMenu = styled.ul.attrs(props => ({
282
- 'data-garden-id': COMPONENT_ID$m,
283
- 'data-garden-version': '9.0.0-next.6',
284
- className: props.isAnimated && 'is-animated'
285
- })).withConfig({
286
- displayName: "StyledMenu",
287
- componentId: "sc-lzt5u6-0"
288
- })(["position:static !important;max-height:", ";overflow-y:auto;", ";", ";"], props => props.maxHeight, props => props.hasArrow && arrowStyles(getArrowPosition(props.placement), {
289
- size: `${props.theme.space.base * 2}px`,
290
- inset: '2px',
291
- animationModifier: props.isAnimated ? '.is-animated' : undefined
292
- }), props => retrieveComponentStyles(COMPONENT_ID$m, props));
293
- StyledMenu.defaultProps = {
294
- theme: DEFAULT_THEME
295
- };
296
-
297
- const COMPONENT_ID$l = 'dropdowns.menu_wrapper';
298
- const StyledMenuWrapper = styled.div.attrs(props => ({
299
- 'data-garden-id': COMPONENT_ID$l,
300
- 'data-garden-version': '9.0.0-next.6',
301
- className: props.isAnimated && 'is-animated'
302
- })).withConfig({
303
- displayName: "StyledMenuWrapper",
304
- componentId: "sc-u70fn3-0"
305
- })(["", ";", ";"], props => menuStyles(getMenuPosition(props.placement), {
306
- theme: props.theme,
307
- hidden: props.isHidden,
308
- margin: `${props.theme.space.base * (props.hasArrow ? 2 : 1)}px`,
309
- zIndex: props.zIndex,
310
- animationModifier: props.isAnimated ? '.is-animated' : undefined
311
- }), props => retrieveComponentStyles(COMPONENT_ID$l, props));
312
- StyledMenuWrapper.defaultProps = {
313
- theme: DEFAULT_THEME
314
- };
315
-
316
- const COMPONENT_ID$k = 'dropdowns.separator';
317
- const StyledSeparator = styled.li.attrs({
318
- 'data-garden-id': COMPONENT_ID$k,
319
- 'data-garden-version': '9.0.0-next.6',
320
- role: 'separator'
321
- }).withConfig({
322
- displayName: "StyledSeparator",
323
- componentId: "sc-oncsf0-0"
324
- })(["display:block;margin:", "px 0;border-bottom:", ";", ";"], props => props.theme.space.base, props => `${props.theme.borders.sm} ${getColorV8('neutralHue', 200, props.theme)}`, props => retrieveComponentStyles(COMPONENT_ID$k, props));
325
- StyledSeparator.defaultProps = {
326
- theme: DEFAULT_THEME
327
- };
328
-
329
- const COMPONENT_ID$j = 'dropdowns.item';
330
- const getItemPaddingVertical = props => {
331
- if (props.isCompact) {
332
- return `${props.theme.space.base}px`;
333
- }
334
- return `${props.theme.space.base * 2}px`;
335
- };
336
- const getColorStyles = props => {
337
- let foregroundColor;
338
- let backgroundColor;
339
- if (props.disabled) {
340
- foregroundColor = getColorV8('neutralHue', 400, props.theme);
341
- } else if (props.isDanger) {
342
- foregroundColor = getColorV8('dangerHue', 600, props.theme);
343
- backgroundColor = props.isFocused ? rgba(foregroundColor, 0.08) : 'inherit';
344
- } else {
345
- foregroundColor = getColorV8('foreground', 600 , props.theme);
346
- backgroundColor = props.isFocused ? getColorV8('primaryHue', 600, props.theme, 0.08) : 'inherit';
347
- }
348
- return css(["background-color:", ";color:", ";& a,& a:hover,& a:focus,& a:active{color:inherit;}"], backgroundColor, foregroundColor);
349
- };
350
- const StyledItem = styled.li.attrs(props => ({
351
- 'data-garden-id': COMPONENT_ID$j,
352
- 'data-garden-version': '9.0.0-next.6',
353
- 'aria-disabled': props.disabled
354
- })).withConfig({
355
- displayName: "StyledItem",
356
- componentId: "sc-x4h8aw-0"
357
- })(["display:block;position:relative;z-index:0;cursor:", ";padding:", " ", "px;text-decoration:none;line-height:", "px;word-wrap:break-word;user-select:none;&:first-child{margin-top:", "px;}&:last-child{margin-bottom:", "px;}&:focus{outline:none;}& a,& a:hover,& a:focus,& a:active{text-decoration:none;}", ";", ";"], props => props.disabled ? 'default' : 'pointer', props => getItemPaddingVertical(props), props => props.theme.space.base * 9, props => props.theme.space.base * 5, props => props.theme.space.base, props => props.theme.space.base, props => getColorStyles(props), props => retrieveComponentStyles(COMPONENT_ID$j, props));
358
- StyledItem.defaultProps = {
359
- theme: DEFAULT_THEME
360
- };
361
-
362
- const COMPONENT_ID$i = 'dropdowns.add_item';
363
- const StyledAddItem = styled(StyledItem).attrs({
364
- 'data-garden-id': COMPONENT_ID$i,
365
- 'data-garden-version': '9.0.0-next.6'
366
- }).withConfig({
367
- displayName: "StyledAddItem",
368
- componentId: "sc-mlto71-0"
369
- })(["color:", ";", ";"], props => !props.disabled && getColorV8('primaryHue', 600, props.theme), props => retrieveComponentStyles(COMPONENT_ID$i, props));
370
- StyledAddItem.defaultProps = {
371
- theme: DEFAULT_THEME
372
- };
373
-
374
- const COMPONENT_ID$h = 'dropdowns.item_meta';
375
- const StyledItemMeta = styled.span.attrs({
376
- 'data-garden-id': COMPONENT_ID$h,
377
- 'data-garden-version': '9.0.0-next.6'
378
- }).withConfig({
379
- displayName: "StyledItemMeta",
380
- componentId: "sc-1m3x8m1-0"
381
- })(["display:block;line-height:", "px;color:", ";font-size:", ";", ";"], props => props.theme.space.base * (props.isCompact ? 3 : 4), props => getColorV8('neutralHue', props.isDisabled ? 400 : 600, props.theme), props => props.theme.fontSizes.sm, props => retrieveComponentStyles(COMPONENT_ID$h, props));
382
- StyledItemMeta.defaultProps = {
383
- theme: DEFAULT_THEME
384
- };
385
-
386
- const COMPONENT_ID$g = 'dropdowns.item_icon';
387
- const getSizeStyles = props => {
388
- return css(["width:", ";height:calc(", "px + ", ");"], props.theme.iconSizes.md, props.theme.space.base * 5, math(`${getItemPaddingVertical(props)} * 2`));
389
- };
390
- const StyledItemIcon = styled.div.attrs({
391
- 'data-garden-id': COMPONENT_ID$g,
392
- 'data-garden-version': '9.0.0-next.6'
393
- }).withConfig({
394
- displayName: "StyledItemIcon",
395
- componentId: "sc-pspm80-0"
396
- })(["display:flex;position:absolute;top:0;", ":", "px;align-items:center;justify-content:center;transition:opacity 0.1s ease-in-out;opacity:", ";color:", ";", ";& > *{width:", ";height:", ";}"], props => props.theme.rtl ? 'right' : 'left', props => props.theme.space.base * 3, props => props.isVisible ? '1' : '0', props => props.isDisabled ? 'inherit' : getColorV8('primaryHue', 600, props.theme), props => getSizeStyles(props), props => props.theme.iconSizes.md, props => props.theme.iconSizes.md);
397
- StyledItemIcon.defaultProps = {
398
- theme: DEFAULT_THEME
399
- };
400
-
401
- const COMPONENT_ID$f = 'dropdowns.next_item';
402
- const StyledNextItem = styled(StyledItem).attrs({
403
- 'data-garden-id': COMPONENT_ID$f,
404
- 'data-garden-version': '9.0.0-next.6'
405
- }).withConfig({
406
- displayName: "StyledNextItem",
407
- componentId: "sc-1wrjlge-0"
408
- })(["", "{right:", ";left:", ";}", ";"], StyledItemIcon, props => props.theme.rtl ? 'auto' : `${props.theme.space.base * 3}px`, props => props.theme.rtl ? `${props.theme.space.base * 3}px` : 'auto', props => retrieveComponentStyles(COMPONENT_ID$f, props));
409
- StyledNextItem.defaultProps = {
410
- theme: DEFAULT_THEME
411
- };
412
-
413
- var _path$4;
414
- function _extends$4() { _extends$4 = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$4.apply(this, arguments); }
415
- var SvgChevronRightStroke = function SvgChevronRightStroke(props) {
416
- return /*#__PURE__*/React.createElement("svg", _extends$4({
417
- xmlns: "http://www.w3.org/2000/svg",
418
- width: 16,
419
- height: 16,
420
- focusable: "false",
421
- viewBox: "0 0 16 16",
422
- "aria-hidden": "true"
423
- }, props), _path$4 || (_path$4 = /*#__PURE__*/React.createElement("path", {
424
- fill: "currentColor",
425
- d: "M5.61 3.312a.5.5 0 01.718-.69l.062.066 4 5a.5.5 0 01.054.542l-.054.082-4 5a.5.5 0 01-.83-.55l.05-.074L9.359 8l-3.75-4.688z"
426
- })));
427
- };
428
-
429
- const COMPONENT_ID$e = 'dropdowns.next_item_icon';
430
- const NextIconComponent = _ref => {
431
- let {
432
- className
433
- } = _ref;
434
- return React__default.createElement(SvgChevronRightStroke, {
435
- "data-garden-id": COMPONENT_ID$e,
436
- "data-garden-version": '9.0.0-next.6',
437
- className: className
438
- });
439
- };
440
- const StyledNextIcon = styled(NextIconComponent).withConfig({
441
- displayName: "StyledNextIcon",
442
- componentId: "sc-1nzkdnq-0"
443
- })(["transform:", ";color:", ";", ";"], props => props.theme.rtl && 'rotate(180deg)', props => props.isDisabled ? 'inherit' : getColorV8('neutralHue', 600, props.theme), props => retrieveComponentStyles(COMPONENT_ID$e, props));
444
- StyledNextIcon.defaultProps = {
445
- theme: DEFAULT_THEME
446
- };
447
-
448
- const COMPONENT_ID$d = 'dropdowns.previous_item';
449
- const StyledPreviousItem = styled(StyledItem).attrs({
450
- 'data-garden-id': COMPONENT_ID$d,
451
- 'data-garden-version': '9.0.0-next.6'
452
- }).withConfig({
453
- displayName: "StyledPreviousItem",
454
- componentId: "sc-1qv9jwe-0"
455
- })(["font-weight:", ";", ";"], props => props.theme.fontWeights.semibold, props => retrieveComponentStyles(COMPONENT_ID$d, props));
456
- StyledPreviousItem.defaultProps = {
457
- theme: DEFAULT_THEME
458
- };
459
-
460
- var _path$3;
461
- function _extends$3() { _extends$3 = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$3.apply(this, arguments); }
462
- var SvgChevronLeftStroke = function SvgChevronLeftStroke(props) {
463
- return /*#__PURE__*/React.createElement("svg", _extends$3({
464
- xmlns: "http://www.w3.org/2000/svg",
465
- width: 16,
466
- height: 16,
467
- focusable: "false",
468
- viewBox: "0 0 16 16",
469
- "aria-hidden": "true"
470
- }, props), _path$3 || (_path$3 = /*#__PURE__*/React.createElement("path", {
471
- fill: "currentColor",
472
- d: "M10.39 12.688a.5.5 0 01-.718.69l-.062-.066-4-5a.5.5 0 01-.054-.542l.054-.082 4-5a.5.5 0 01.83.55l-.05.074L6.641 8l3.75 4.688z"
473
- })));
474
- };
475
-
476
- const COMPONENT_ID$c = 'dropdowns.previous_item_icon';
477
- const PreviousIconComponent = _ref => {
478
- let {
479
- className
480
- } = _ref;
481
- return React__default.createElement(SvgChevronLeftStroke, {
482
- "data-garden-id": COMPONENT_ID$c,
483
- "data-garden-version": '9.0.0-next.6',
484
- className: className
485
- });
486
- };
487
- const StyledPreviousIcon = styled(PreviousIconComponent).withConfig({
488
- displayName: "StyledPreviousIcon",
489
- componentId: "sc-1n1t07s-0"
490
- })(["transform:", ";color:", ";", ";"], props => props.theme.rtl && 'rotate(180deg)', props => props.isDisabled ? 'inherit' : getColorV8('neutralHue', 600, props.theme), props => retrieveComponentStyles(COMPONENT_ID$c, props));
491
- StyledPreviousIcon.defaultProps = {
492
- theme: DEFAULT_THEME
493
- };
494
-
495
- const COMPONENT_ID$b = 'dropdowns.header_icon';
496
- const StyledHeaderIcon = styled.div.attrs({
497
- 'data-garden-id': COMPONENT_ID$b,
498
- 'data-garden-version': '9.0.0-next.6'
499
- }).withConfig({
500
- displayName: "StyledHeaderIcon",
501
- componentId: "sc-ow8s45-0"
502
- })(["display:flex;position:absolute;top:0;bottom:0;align-items:center;justify-content:center;", ":", "px;color:", ";& > *{width:", ";height:", ";}", ";"], props => props.theme.rtl ? 'right' : 'left', props => props.theme.space.base * 3, props => getColorV8('neutralHue', 600, props.theme), props => props.theme.iconSizes.md, props => props.theme.iconSizes.md, props => retrieveComponentStyles(COMPONENT_ID$b, props));
503
- StyledHeaderIcon.defaultProps = {
504
- theme: DEFAULT_THEME
505
- };
506
-
507
- const COMPONENT_ID$a = 'dropdowns.header_item';
508
- const getHorizontalPadding = props => {
509
- if (props.hasIcon) {
510
- return undefined;
511
- }
512
- return `${props.theme.space.base * 3}px`;
513
- };
514
- const StyledHeaderItem = styled(StyledItem).attrs({
515
- 'data-garden-id': COMPONENT_ID$a,
516
- 'data-garden-version': '9.0.0-next.6'
517
- }).withConfig({
518
- displayName: "StyledHeaderItem",
519
- componentId: "sc-1xosinr-0"
520
- })(["cursor:default;padding-right:", ";padding-left:", ";font-weight:", ";", ";"], props => getHorizontalPadding(props), props => getHorizontalPadding(props), props => props.theme.fontWeights.semibold, props => retrieveComponentStyles(COMPONENT_ID$a, props));
521
- StyledHeaderItem.defaultProps = {
522
- theme: DEFAULT_THEME
523
- };
524
-
525
- const COMPONENT_ID$9 = 'dropdowns.media_body';
526
- const StyledMediaBody = styled.div.attrs({
527
- 'data-garden-id': COMPONENT_ID$9,
528
- 'data-garden-version': '9.0.0-next.6'
529
- }).withConfig({
530
- displayName: "StyledMediaBody",
531
- componentId: "sc-133sssc-0"
532
- })(["display:block;overflow:hidden;padding-", ":", "px;", ";"], props => props.theme.rtl ? 'right' : 'left', props => props.theme.space.base * 2, props => retrieveComponentStyles(COMPONENT_ID$9, props));
533
- StyledMediaBody.defaultProps = {
534
- theme: DEFAULT_THEME
535
- };
536
-
537
- const COMPONENT_ID$8 = 'dropdowns.media_figure';
538
- const StyledMediaFigure = styled(
539
- _ref => {
540
- let {
541
- children,
542
- isCompact,
543
- theme,
544
- ...props
545
- } = _ref;
546
- return (
547
- React__default.cloneElement(Children.only(children), props)
548
- );
549
- }).attrs({
550
- 'data-garden-id': COMPONENT_ID$8,
551
- 'data-garden-version': '9.0.0-next.6'
552
- }).withConfig({
553
- displayName: "StyledMediaFigure",
554
- componentId: "sc-16vz3xj-0"
555
- })(["float:", ";margin-top:", "px !important;width:", ";height:", ";", ";"], props => props.theme.rtl ? 'right' : 'left', props => props.theme.space.base * 0.5, props => props.theme.iconSizes.md, props => props.theme.iconSizes.md, props => retrieveComponentStyles(COMPONENT_ID$8, props));
556
- StyledMediaFigure.defaultProps = {
557
- theme: DEFAULT_THEME
558
- };
559
-
560
- const COMPONENT_ID$7 = 'dropdowns.media_item';
561
- const StyledMediaItem = styled(StyledItem).attrs({
562
- 'data-garden-id': COMPONENT_ID$7,
563
- 'data-garden-version': '9.0.0-next.6'
564
- }).withConfig({
565
- displayName: "StyledMediaItem",
566
- componentId: "sc-af4509-0"
567
- })(["", ";"], props => retrieveComponentStyles(COMPONENT_ID$7, props));
568
- StyledMediaItem.defaultProps = {
569
- theme: DEFAULT_THEME
570
- };
571
-
572
- const COMPONENT_ID$6 = 'dropdowns.faux_input';
573
- const StyledFauxInput = styled(FauxInput).attrs(props => ({
574
- 'data-garden-id': COMPONENT_ID$6,
575
- 'data-garden-version': '9.0.0-next.6',
576
- mediaLayout: true,
577
- theme: props.theme
578
- })).withConfig({
579
- displayName: "StyledFauxInput",
580
- componentId: "sc-bk8odf-0"
581
- })(["cursor:", ";min-width:", "px;", ";"], props => !props.disabled && 'pointer', props => props.theme.space.base * (props.isCompact ? 25 : 36), props => retrieveComponentStyles(COMPONENT_ID$6, props));
582
- StyledFauxInput.defaultProps = {
583
- theme: DEFAULT_THEME
584
- };
585
-
586
- const COMPONENT_ID$5 = 'dropdowns.input';
587
- const hiddenStyling = css(["position:fixed;border:0;clip:rect(1px,1px,1px,1px);padding:0;width:1px;height:1px;overflow:hidden;white-space:nowrap;"]);
588
- const StyledInput = styled(Input).attrs({
589
- 'data-garden-id': COMPONENT_ID$5,
590
- 'data-garden-version': '9.0.0-next.6',
591
- isBare: true
592
- }).withConfig({
593
- displayName: "StyledInput",
594
- componentId: "sc-kykaw8-0"
595
- })(["", ";", ";"], props => props.isHidden && hiddenStyling, props => retrieveComponentStyles(COMPONENT_ID$5, props));
596
- StyledInput.defaultProps = {
597
- theme: DEFAULT_THEME
598
- };
599
-
600
- const COMPONENT_ID$4 = 'dropdowns.select';
601
- const StyledSelect = styled.div.attrs({
602
- 'data-garden-id': COMPONENT_ID$4,
603
- 'data-garden-version': '9.0.0-next.6'
604
- }).withConfig({
605
- displayName: "StyledSelect",
606
- componentId: "sc-xf4qjv-0"
607
- })(["flex-grow:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;", ";"], props => retrieveComponentStyles(COMPONENT_ID$4, props));
608
- StyledSelect.defaultProps = {
609
- theme: DEFAULT_THEME
610
- };
611
-
612
- const COMPONENT_ID$3 = 'dropdowns.multiselect_input';
613
- const visibleStyling = props => {
614
- const margin = props.isVisible ? `${props.theme.space.base / 2}px` : 0;
615
- const minWidth = props.isVisible ? `${props.theme.space.base * 15}px` : 0;
616
- let height = '0';
617
- if (props.isVisible) {
618
- height = `${props.theme.space.base * (props.isCompact ? 5 : 8)}px`;
619
- }
620
- return css(["opacity:", ";margin:", ";width:", ";min-width:", ";height:", ";"], !props.isVisible && 0, margin, !props.isVisible && 0, minWidth, height);
621
- };
622
- const StyledMultiselectInput = styled(StyledInput).attrs({
623
- 'data-garden-id': COMPONENT_ID$3,
624
- 'data-garden-version': '9.0.0-next.6',
625
- isBare: true
626
- }).withConfig({
627
- displayName: "StyledMultiselectInput",
628
- componentId: "sc-iiow29-0"
629
- })(["flex-basis:", "px;flex-grow:1;align-self:center;min-height:0;", ";", ";"], props => props.theme.space.base * 15, props => visibleStyling(props), props => retrieveComponentStyles(COMPONENT_ID$3, props));
630
- StyledMultiselectInput.defaultProps = {
631
- theme: DEFAULT_THEME
632
- };
633
-
634
- const COMPONENT_ID$2 = 'dropdowns.multiselect_items_container';
635
- const sizeStyles = props => {
636
- let margin;
637
- let padding;
638
- if (!props.isBare) {
639
- const marginVertical = props.isCompact ? `-${props.theme.space.base * 1.5}px` : `-${props.theme.space.base * 2.5}px`;
640
- margin = `${marginVertical} 0`;
641
- const paddingVertical = props.isCompact ? '3px' : '1px';
642
- const paddingEnd = `${props.theme.space.base}px`;
643
- padding = `${paddingVertical} ${props.theme.rtl ? 0 : paddingEnd} ${paddingVertical} ${props.theme.rtl ? paddingEnd : 0}`;
644
- }
645
- return css(["margin:", ";padding:", ";"], margin, padding);
646
- };
647
- const StyledMultiselectItemsContainer = styled.div.attrs({
648
- 'data-garden-id': COMPONENT_ID$2,
649
- 'data-garden-version': '9.0.0-next.6'
650
- }).withConfig({
651
- displayName: "StyledMultiselectItemsContainer",
652
- componentId: "sc-1dxwjyz-0"
653
- })(["display:inline-flex;flex-grow:1;flex-wrap:wrap;min-width:0;", ";", ";"], props => sizeStyles(props), props => retrieveComponentStyles(COMPONENT_ID$2, props));
654
- StyledMultiselectItemsContainer.defaultProps = {
655
- theme: DEFAULT_THEME
656
- };
657
-
658
- const COMPONENT_ID$1 = 'dropdowns.multiselect_item_wrapper';
659
- const StyledMultiselectItemWrapper = styled.div.attrs({
660
- 'data-garden-id': COMPONENT_ID$1,
661
- 'data-garden-version': '9.0.0-next.6'
662
- }).withConfig({
663
- displayName: "StyledMultiselectItemWrapper",
664
- componentId: "sc-vgr7nd-0"
665
- })(["display:inline-flex;align-items:center;margin:", "px;max-width:100%;", ";"], props => props.theme.space.base / 2, props => retrieveComponentStyles(COMPONENT_ID$1, props));
666
- StyledMultiselectItemWrapper.defaultProps = {
667
- theme: DEFAULT_THEME
668
- };
669
-
670
- const COMPONENT_ID = 'dropdowns.multiselect_more_anchor';
671
- const StyledMultiselectMoreAnchor = styled.div.attrs({
672
- 'data-garden-id': COMPONENT_ID,
673
- 'data-garden-version': '9.0.0-next.6'
674
- }).withConfig({
675
- displayName: "StyledMultiselectMoreAnchor",
676
- componentId: "sc-pkakky-0"
677
- })(["display:inline-block;cursor:", ";padding:", "px 0;overflow:hidden;user-select:none;text-overflow:ellipsis;line-height:", ";white-space:nowrap;color:", ";:hover{text-decoration:", ";}", ";"], props => props.isDisabled ? 'default' : 'pointer', props => props.theme.space.base * (props.isCompact ? 0.75 : 1.5), props => props.isCompact ? '1em' : getLineHeight(props.theme.space.base * 5, props.theme.fontSizes.md), props => props.isDisabled ? getColorV8('neutralHue', 400, props.theme) : getColorV8('primaryHue', 600, props.theme), props => !props.isDisabled && 'underline', props => retrieveComponentStyles(COMPONENT_ID, props));
678
- StyledMultiselectMoreAnchor.defaultProps = {
679
- theme: DEFAULT_THEME
680
- };
681
-
682
- const Trigger = _ref => {
683
- let {
684
- children,
685
- refKey,
686
- ...triggerProps
687
- } = _ref;
688
- const {
689
- hasMenuRef,
690
- itemSearchRegistry,
691
- downshift: {
692
- getRootProps,
693
- getToggleButtonProps,
694
- getInputProps,
695
- isOpen,
696
- highlightedIndex,
697
- selectItemAtIndex,
698
- setHighlightedIndex
699
- }
700
- } = useDropdownContext();
701
- const hiddenInputRef = useRef(null);
702
- const triggerRef = useRef(null);
703
- const previousIsOpenRef = useRef(undefined);
704
- const [searchString, setSearchString] = useState('');
705
- const searchTimeoutRef = useRef();
706
- const currentSearchIndexRef = useRef(0);
707
- useEffect(() => {
708
- if (hiddenInputRef.current && isOpen && !previousIsOpenRef.current) {
709
- hiddenInputRef.current.focus();
710
- }
711
- if (triggerRef.current && !isOpen && previousIsOpenRef.current) {
712
- triggerRef.current.focus();
713
- }
714
- previousIsOpenRef.current = isOpen;
715
- }, [isOpen, hasMenuRef]);
716
- useEffect(() => {
717
- if (hasMenuRef.current === false) {
718
- hasMenuRef.current = true;
719
- }
720
- }, [hasMenuRef]);
721
- useEffect(() => {
722
- if (searchTimeoutRef.current) {
723
- clearTimeout(searchTimeoutRef.current);
724
- }
725
- searchTimeoutRef.current = window.setTimeout(() => {
726
- setSearchString('');
727
- }, 500);
728
- return () => {
729
- clearTimeout(searchTimeoutRef.current);
730
- };
731
- }, [searchString]);
732
- const searchItems = useCallback((searchValue, startIndex, endIndex) => {
733
- for (let index = startIndex; index < endIndex; index++) {
734
- const itemTextValue = itemSearchRegistry.current[index];
735
- if (itemTextValue && itemTextValue.toUpperCase().indexOf(searchValue.toUpperCase()) === 0) {
736
- return index;
737
- }
738
- }
739
- return undefined;
740
- }, [itemSearchRegistry]);
741
- const onInputKeyDown = useCallback(e => {
742
- if (e.keyCode === KEY_CODES.SPACE) {
743
- if (searchString) {
744
- e.preventDefault();
745
- e.stopPropagation();
746
- } else if (highlightedIndex !== null && highlightedIndex !== undefined) {
747
- e.preventDefault();
748
- e.stopPropagation();
749
- selectItemAtIndex(highlightedIndex);
750
- }
751
- }
752
- if ((e.keyCode < 48 || e.keyCode > 57) && (e.keyCode < 65 || e.keyCode > 90) && e.keyCode !== KEY_CODES.SPACE) {
753
- return;
754
- }
755
- const character = String.fromCharCode(e.which || e.keyCode);
756
- if (!character || character.length === 0) {
757
- return;
758
- }
759
- if (!searchString) {
760
- if (highlightedIndex === null || highlightedIndex === undefined) {
761
- currentSearchIndexRef.current = -1;
762
- } else {
763
- currentSearchIndexRef.current = highlightedIndex;
764
- }
765
- }
766
- const newSearchString = searchString + character;
767
- setSearchString(newSearchString);
768
- let matchingIndex = searchItems(newSearchString, currentSearchIndexRef.current + 1, itemSearchRegistry.current.length);
769
- if (matchingIndex === undefined) {
770
- matchingIndex = searchItems(newSearchString, 0, currentSearchIndexRef.current);
771
- }
772
- if (matchingIndex !== undefined) {
773
- setHighlightedIndex(matchingIndex);
774
- }
775
- }, [searchString, searchItems, itemSearchRegistry, highlightedIndex, selectItemAtIndex, setHighlightedIndex]);
776
- const renderChildren = popperRef => {
777
- const {
778
- ref: rootPropsRefCallback,
779
- ...rootProps
780
- } = getRootProps();
781
- const listboxToggleProps = getToggleButtonProps({
782
- ...rootProps,
783
- role: null,
784
- 'aria-labelledby': undefined,
785
- ...triggerProps,
786
- ...children.props
787
- });
788
- const menuToggleProps = {
789
- ...listboxToggleProps,
790
- 'aria-haspopup': 'true',
791
- 'aria-controls': listboxToggleProps['aria-owns'],
792
- 'aria-owns': null
793
- };
794
- const toggleButtonProps = hasMenuRef.current ? menuToggleProps : listboxToggleProps;
795
- return React__default.cloneElement(React__default.Children.only(children), {
796
- ...toggleButtonProps,
797
- [refKey]: childRef => {
798
- popperRef(childRef);
799
- triggerRef.current = childRef;
800
- rootPropsRefCallback(childRef);
801
- }
802
- });
803
- };
804
- return React__default.createElement(Reference, null, _ref2 => {
805
- let {
806
- ref: popperReference
807
- } = _ref2;
808
- return React__default.createElement(React__default.Fragment, null, renderChildren(popperReference), React__default.createElement(StyledInput, getInputProps({
809
- readOnly: true,
810
- isHidden: true,
811
- tabIndex: -1,
812
- ref: hiddenInputRef,
813
- value: '',
814
- onClick: e => {
815
- if (isOpen) {
816
- e.nativeEvent.preventDownshiftDefault = true;
817
- }
818
- },
819
- onKeyDown: onInputKeyDown
820
- })));
821
- });
822
- };
823
- Trigger.propTypes = {
824
- children: PropTypes.any,
825
- refKey: PropTypes.string
826
- };
827
- Trigger.defaultProps = {
828
- refKey: 'ref'
829
- };
830
-
831
- var _path$2;
832
- function _extends$2() { _extends$2 = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$2.apply(this, arguments); }
833
- var SvgChevronDownStroke = function SvgChevronDownStroke(props) {
834
- return /*#__PURE__*/React.createElement("svg", _extends$2({
835
- xmlns: "http://www.w3.org/2000/svg",
836
- width: 16,
837
- height: 16,
838
- focusable: "false",
839
- viewBox: "0 0 16 16",
840
- "aria-hidden": "true"
841
- }, props), _path$2 || (_path$2 = /*#__PURE__*/React.createElement("path", {
842
- fill: "currentColor",
843
- d: "M12.688 5.61a.5.5 0 01.69.718l-.066.062-5 4a.5.5 0 01-.542.054l-.082-.054-5-4a.5.5 0 01.55-.83l.074.05L8 9.359l4.688-3.75z"
844
- })));
845
- };
846
-
847
- const FieldContext = React__default.createContext(undefined);
848
- const useFieldContext = () => {
849
- const fieldContext = useContext(FieldContext);
850
- if (!fieldContext) {
851
- throw new Error('This component must be rendered within a `Field` component.');
852
- }
853
- return fieldContext;
854
- };
855
-
856
- const Autocomplete = forwardRef((_ref, ref) => {
857
- let {
858
- children,
859
- inputRef: controlledInputRef,
860
- start,
861
- ...props
862
- } = _ref;
863
- const {
864
- popperReferenceElementRef,
865
- downshift: {
866
- getToggleButtonProps,
867
- getInputProps,
868
- getRootProps,
869
- isOpen
870
- },
871
- setDropdownType
872
- } = useDropdownContext();
873
- const {
874
- isLabelHovered
875
- } = useFieldContext();
876
- const inputRef = useRef();
877
- const triggerRef = useRef();
878
- const previousIsOpenRef = useRef(isOpen);
879
- const [isHovered, setIsHovered] = useState(false);
880
- const [isFocused, setIsFocused] = useState(false);
881
- useEffect(() => {
882
- if (inputRef.current && isOpen !== previousIsOpenRef.current) {
883
- inputRef.current.focus();
884
- }
885
- previousIsOpenRef.current = isOpen;
886
- }, [inputRef, isOpen]);
887
- const {
888
- type,
889
- onKeyDown,
890
- ...selectProps
891
- } = getToggleButtonProps(getRootProps({
892
- role: null,
893
- ...props,
894
- onKeyDown: e => {
895
- if (isOpen) {
896
- e.nativeEvent.preventDownshiftDefault = true;
897
- }
898
- },
899
- onMouseEnter: composeEventHandlers(props.onMouseEnter, () => setIsHovered(true)),
900
- onMouseLeave: composeEventHandlers(props.onMouseLeave, () => setIsHovered(false))
901
- }));
902
- const onSelectKeyDown = composeEventHandlers(props.onKeyDown, onKeyDown);
903
- const isContainerHovered = isLabelHovered && !isOpen;
904
- const isContainerFocused = isOpen || isFocused;
905
- useEffect(() => {
906
- setDropdownType('autocomplete');
907
- }, [setDropdownType]);
908
- return React__default.createElement(Reference, null, _ref2 => {
909
- let {
910
- ref: popperReference
911
- } = _ref2;
912
- return React__default.createElement(StyledFauxInput, _extends$5({
913
- isHovered: isContainerHovered,
914
- isFocused: isContainerFocused,
915
- tabIndex: null,
916
- onKeyDown: onSelectKeyDown
917
- }, selectProps, {
918
- ref: selectRef => {
919
- popperReference(selectRef);
920
- mergeRefs([triggerRef, ref])(selectRef);
921
- popperReferenceElementRef.current = selectRef;
922
- }
923
- }), start && React__default.createElement(StyledFauxInput.StartIcon, {
924
- isHovered: isHovered || isLabelHovered && !isOpen,
925
- isFocused: isContainerFocused,
926
- isDisabled: props.disabled
927
- }, start), !isOpen && React__default.createElement(StyledSelect, null, children), React__default.createElement(StyledInput, getInputProps({
928
- isHidden: !isOpen,
929
- disabled: props.disabled,
930
- onFocus: () => {
931
- setIsFocused(true);
932
- },
933
- onBlur: () => {
934
- setIsFocused(false);
935
- },
936
- onClick: e => {
937
- if (isOpen) {
938
- e.nativeEvent.preventDownshiftDefault = true;
939
- }
940
- },
941
- role: 'combobox',
942
- ref: mergeRefs([inputRef, controlledInputRef || null])
943
- })), !props.isBare && React__default.createElement(StyledFauxInput.EndIcon, {
944
- isHovered: isHovered || isLabelHovered && !isOpen,
945
- isFocused: isContainerFocused,
946
- isDisabled: props.disabled,
947
- isRotated: isOpen
948
- }, React__default.createElement(SvgChevronDownStroke, null)));
949
- });
950
- });
951
- Autocomplete.displayName = 'Autocomplete';
952
- Autocomplete.propTypes = {
953
- isCompact: PropTypes.bool,
954
- isBare: PropTypes.bool,
955
- disabled: PropTypes.bool,
956
- focusInset: PropTypes.bool,
957
- validation: PropTypes.oneOf(VALIDATION)
958
- };
959
-
960
- const Combobox = forwardRef((_ref, ref) => {
961
- let {
962
- isCompact,
963
- isBare,
964
- disabled,
965
- focusInset,
966
- placeholder,
967
- validation,
968
- inputRef: inputRefProp = null,
969
- start,
970
- end,
971
- ...props
972
- } = _ref;
973
- const {
974
- popperReferenceElementRef,
975
- downshift: {
976
- getToggleButtonProps,
977
- getInputProps,
978
- getRootProps,
979
- isOpen
980
- },
981
- setDropdownType
982
- } = useDropdownContext();
983
- const wrapperRef = useRef();
984
- const inputRef = useRef();
985
- const isOpenRef = useRef(isOpen);
986
- const wrapperProps = getToggleButtonProps(getRootProps({
987
- role: null,
988
- type: null,
989
- onClick: event => {
990
- event.nativeEvent.preventDownshiftDefault = true;
991
- },
992
- ...props,
993
- onKeyDown: event => {
994
- event.nativeEvent.preventDownshiftDefault = true;
995
- }
996
- }));
997
- const inputProps = getInputProps({
998
- isCompact,
999
- isBare,
1000
- disabled,
1001
- focusInset,
1002
- placeholder,
1003
- validation,
1004
- start,
1005
- end,
1006
- role: 'combobox',
1007
- onKeyDown: event => {
1008
- if (event.keyCode === KEY_CODES.SPACE || !isOpen && [KEY_CODES.DOWN, KEY_CODES.UP].includes(event.keyCode)) {
1009
- event.nativeEvent.preventDownshiftDefault = true;
1010
- }
1011
- },
1012
- onClick: event => {
1013
- event.nativeEvent.preventDownshiftDefault = true;
1014
- }
1015
- });
1016
- useEffect(() => {
1017
- if (inputRef.current && isOpen !== isOpenRef.current) {
1018
- inputRef.current.focus();
1019
- }
1020
- isOpenRef.current = isOpen;
1021
- }, [inputRef, isOpen]);
1022
- useEffect(() => {
1023
- setDropdownType('combobox');
1024
- }, [setDropdownType]);
1025
- return React__default.createElement(Reference, null, _ref2 => {
1026
- let {
1027
- ref: popperReference
1028
- } = _ref2;
1029
- const wrapperRefProp = element => {
1030
- popperReference(element);
1031
- mergeRefs([wrapperRef, ref])(element);
1032
- popperReferenceElementRef.current = element;
1033
- };
1034
- return React__default.createElement(MediaInput, _extends$5({}, inputProps, {
1035
- wrapperProps: wrapperProps,
1036
- wrapperRef: wrapperRefProp,
1037
- ref: mergeRefs([inputRef, inputRefProp])
1038
- }));
1039
- });
1040
- });
1041
- Combobox.displayName = 'Combobox';
1042
- Combobox.propTypes = {
1043
- isCompact: PropTypes.bool,
1044
- isBare: PropTypes.bool,
1045
- disabled: PropTypes.bool,
1046
- focusInset: PropTypes.bool,
1047
- placeholder: PropTypes.string,
1048
- validation: PropTypes.oneOf(VALIDATION)
1049
- };
1050
-
1051
- const Multiselect = React__default.forwardRef((_ref, ref) => {
1052
- let {
1053
- renderItem,
1054
- placeholder,
1055
- maxItems,
1056
- renderShowMore,
1057
- inputRef: externalInputRef = null,
1058
- start,
1059
- onKeyDown,
1060
- ...props
1061
- } = _ref;
1062
- const {
1063
- popperReferenceElementRef,
1064
- selectedItems = [],
1065
- containsMultiselectRef,
1066
- previousIndexRef,
1067
- downshift: {
1068
- getToggleButtonProps,
1069
- getRootProps,
1070
- getInputProps,
1071
- isOpen,
1072
- closeMenu,
1073
- inputValue,
1074
- setState: setDownshiftState,
1075
- itemToString
1076
- },
1077
- setDropdownType
1078
- } = useDropdownContext();
1079
- const {
1080
- isLabelHovered
1081
- } = useFieldContext();
1082
- const inputRef = useRef();
1083
- const triggerRef = useRef();
1084
- const blurTimeoutRef = useRef();
1085
- const previousIsOpenRef = useRef(undefined);
1086
- const previousIsFocusedRef = useRef(undefined);
1087
- const [isHovered, setIsHovered] = useState(false);
1088
- const [isFocused, setIsFocused] = useState(false);
1089
- const [focusedItem, setFocusedItem] = useState(undefined);
1090
- const themeContext = useContext(ThemeContext);
1091
- const environment = useDocument(themeContext);
1092
- const {
1093
- getContainerProps,
1094
- getItemProps
1095
- } = useSelection({
1096
- rtl: themeContext.rtl,
1097
- focusedItem,
1098
- selectedItem: undefined,
1099
- onFocus: item => {
1100
- setFocusedItem(item);
1101
- }
1102
- });
1103
- useEffect(() => {
1104
- containsMultiselectRef.current = true;
1105
- const tempRef = blurTimeoutRef;
1106
- return () => {
1107
- clearTimeout(tempRef.current);
1108
- };
1109
- }, []);
1110
- useEffect(() => {
1111
- if (inputRef.current) {
1112
- if (isOpen && !previousIsOpenRef.current) {
1113
- inputRef.current.focus();
1114
- } else if (isFocused && !previousIsFocusedRef.current && focusedItem === undefined) {
1115
- inputRef.current.focus();
1116
- }
1117
- }
1118
- previousIsOpenRef.current = isOpen;
1119
- previousIsFocusedRef.current = isFocused;
1120
- }, [isOpen, inputRef, isFocused, focusedItem]);
1121
- useEffect(() => {
1122
- if (focusedItem !== undefined && isOpen) {
1123
- closeMenu();
1124
- }
1125
- }, [focusedItem, isOpen, closeMenu]);
1126
- const {
1127
- type,
1128
- ...selectProps
1129
- } = getToggleButtonProps(getRootProps({
1130
- tabIndex: props.disabled ? undefined : -1,
1131
- onKeyDown: composeEventHandlers(onKeyDown, e => {
1132
- if (isOpen) {
1133
- e.nativeEvent.preventDownshiftDefault = true;
1134
- } else if (!inputValue && e.keyCode === KEY_CODES.HOME) {
1135
- setFocusedItem(selectedItems[0]);
1136
- e.preventDefault();
1137
- }
1138
- }),
1139
- onFocus: () => {
1140
- setIsFocused(true);
1141
- },
1142
- onBlur: e => {
1143
- const currentTarget = e.currentTarget;
1144
- blurTimeoutRef.current = setTimeout(() => {
1145
- if (environment && !currentTarget.contains(environment.activeElement)) {
1146
- setIsFocused(false);
1147
- }
1148
- }, 0);
1149
- },
1150
- onMouseEnter: composeEventHandlers(props.onMouseEnter, () => setIsHovered(true)),
1151
- onMouseLeave: composeEventHandlers(props.onMouseLeave, () => setIsHovered(false)),
1152
- role: null,
1153
- ...props
1154
- }));
1155
- const renderSelectableItem = useCallback((item, index) => {
1156
- const removeValue = () => {
1157
- setDownshiftState({
1158
- type: REMOVE_ITEM_STATE_TYPE,
1159
- selectedItem: item
1160
- });
1161
- inputRef.current && inputRef.current.focus();
1162
- };
1163
- const renderedItem = renderItem({
1164
- value: item,
1165
- removeValue
1166
- });
1167
- const focusRef = React__default.createRef();
1168
- const clonedChild = React__default.cloneElement(renderedItem, {
1169
- ...getItemProps({
1170
- item,
1171
- focusRef,
1172
- onKeyDown: e => {
1173
- if (e.keyCode === KEY_CODES.DELETE || e.keyCode === KEY_CODES.BACKSPACE) {
1174
- e.preventDefault();
1175
- removeValue();
1176
- }
1177
- if (e.keyCode === KEY_CODES.END && !inputValue) {
1178
- inputRef.current && inputRef.current.focus();
1179
- e.preventDefault();
1180
- }
1181
- if (themeContext.rtl) {
1182
- if (e.keyCode === KEY_CODES.RIGHT && index === 0) {
1183
- e.preventDefault();
1184
- }
1185
- if (e.keyCode === KEY_CODES.LEFT && index === selectedItems.length - 1) {
1186
- e.preventDefault();
1187
- inputRef.current && inputRef.current.focus();
1188
- }
1189
- } else {
1190
- if (e.keyCode === KEY_CODES.LEFT && index === 0) {
1191
- e.preventDefault();
1192
- }
1193
- if (e.keyCode === KEY_CODES.RIGHT && index === selectedItems.length - 1) {
1194
- e.preventDefault();
1195
- inputRef.current && inputRef.current.focus();
1196
- }
1197
- }
1198
- },
1199
- onClick: e => {
1200
- e.nativeEvent.preventDownshiftDefault = true;
1201
- },
1202
- tabIndex: -1
1203
- }),
1204
- size: props.isCompact ? 'medium' : 'large'
1205
- });
1206
- const key = `${itemToString(item)}-${index}`;
1207
- return React__default.createElement(StyledMultiselectItemWrapper, {
1208
- key: key
1209
- }, clonedChild);
1210
- }, [getItemProps, inputValue, renderItem, setDownshiftState, itemToString, selectedItems, props, inputRef, themeContext.rtl]);
1211
- const items = useMemo(() => {
1212
- const itemValues = selectedItems || [];
1213
- const output = [];
1214
- for (let x = 0; x < itemValues.length; x++) {
1215
- const item = itemValues[x];
1216
- if (x < maxItems) {
1217
- if (props.disabled) {
1218
- const renderedItem = React__default.cloneElement(renderItem({
1219
- value: item,
1220
- removeValue: () => {
1221
- return undefined;
1222
- }
1223
- }), {
1224
- size: props.isCompact ? 'medium' : 'large'
1225
- });
1226
- output.push( React__default.createElement(StyledMultiselectItemWrapper, {
1227
- key: x
1228
- }, renderedItem));
1229
- } else {
1230
- output.push(renderSelectableItem(item, x));
1231
- }
1232
- } else if (!isFocused && !inputValue || props.disabled) {
1233
- output.push( React__default.createElement(StyledMultiselectItemWrapper, {
1234
- key: "more-anchor"
1235
- }, React__default.createElement(StyledMultiselectMoreAnchor, {
1236
- isCompact: props.isCompact,
1237
- isDisabled: props.disabled
1238
- }, renderShowMore ? renderShowMore(itemValues.length - x) : `+ ${itemValues.length - x} more`)));
1239
- break;
1240
- } else {
1241
- output.push(renderSelectableItem(item, x));
1242
- }
1243
- }
1244
- return output;
1245
- }, [isFocused, props.disabled, renderSelectableItem, selectedItems, renderItem, inputValue, maxItems, renderShowMore, props.isCompact]);
1246
- const isContainerHovered = isLabelHovered && !isOpen;
1247
- const isContainerFocused = isOpen || isFocused;
1248
- useEffect(() => {
1249
- setDropdownType('multiselect');
1250
- }, [setDropdownType]);
1251
- return React__default.createElement(Reference, null, _ref2 => {
1252
- let {
1253
- ref: popperReference
1254
- } = _ref2;
1255
- return React__default.createElement(StyledFauxInput, getContainerProps({
1256
- ...selectProps,
1257
- isHovered: isContainerHovered,
1258
- isFocused: isContainerFocused,
1259
- ref: selectRef => {
1260
- popperReference(selectRef);
1261
- mergeRefs([triggerRef, popperReferenceElementRef, ref])(selectRef);
1262
- }
1263
- }), start && React__default.createElement(StyledFauxInput.StartIcon, {
1264
- isHovered: isHovered || isLabelHovered && !isOpen,
1265
- isFocused: isContainerFocused,
1266
- isDisabled: props.disabled
1267
- }, start), React__default.createElement(StyledMultiselectItemsContainer, {
1268
- isBare: props.isBare,
1269
- isCompact: props.isCompact
1270
- }, items, React__default.createElement(StyledMultiselectInput, getInputProps({
1271
- disabled: props.disabled,
1272
- onFocus: () => {
1273
- setFocusedItem(undefined);
1274
- },
1275
- onClick: e => {
1276
- if (inputValue && inputValue.length > 0 && isOpen) {
1277
- e.nativeEvent.preventDownshiftDefault = true;
1278
- }
1279
- },
1280
- onKeyDown: e => {
1281
- if (!inputValue) {
1282
- if (themeContext.rtl && e.keyCode === KEY_CODES.RIGHT && selectedItems.length > 0 && previousIndexRef.current === undefined) {
1283
- setFocusedItem(selectedItems[selectedItems.length - 1]);
1284
- } else if (!themeContext.rtl && e.keyCode === KEY_CODES.LEFT && selectedItems.length > 0 && previousIndexRef.current === undefined) {
1285
- setFocusedItem(selectedItems[selectedItems.length - 1]);
1286
- } else if (e.keyCode === KEY_CODES.BACKSPACE && selectedItems.length > 0) {
1287
- setDownshiftState({
1288
- type: REMOVE_ITEM_STATE_TYPE,
1289
- selectedItem: selectedItems[selectedItems.length - 1]
1290
- });
1291
- e.nativeEvent.preventDownshiftDefault = true;
1292
- e.preventDefault();
1293
- e.stopPropagation();
1294
- }
1295
- }
1296
- },
1297
- isVisible: isFocused || inputValue || selectedItems.length === 0,
1298
- isCompact: props.isCompact,
1299
- role: 'combobox',
1300
- ref: mergeRefs([inputRef, externalInputRef]),
1301
- placeholder: selectedItems.length === 0 ? placeholder : undefined
1302
- }))), !props.isBare && React__default.createElement(StyledFauxInput.EndIcon, {
1303
- isHovered: isHovered || isLabelHovered && !isOpen,
1304
- isFocused: isContainerFocused,
1305
- isDisabled: props.disabled,
1306
- isRotated: isOpen
1307
- }, React__default.createElement(SvgChevronDownStroke, null)));
1308
- });
1309
- });
1310
- Multiselect.propTypes = {
1311
- isCompact: PropTypes.bool,
1312
- isBare: PropTypes.bool,
1313
- disabled: PropTypes.bool,
1314
- focusInset: PropTypes.bool,
1315
- renderItem: PropTypes.func.isRequired,
1316
- maxItems: PropTypes.number,
1317
- validation: PropTypes.oneOf(['success', 'warning', 'error'])
1318
- };
1319
- Multiselect.defaultProps = {
1320
- maxItems: 4
1321
- };
1322
- Multiselect.displayName = 'Multiselect';
1323
-
1324
- const Select = React__default.forwardRef((_ref, ref) => {
1325
- let {
1326
- children,
1327
- start,
1328
- ...props
1329
- } = _ref;
1330
- const {
1331
- popperReferenceElementRef,
1332
- itemSearchRegistry,
1333
- downshift: {
1334
- getToggleButtonProps,
1335
- getInputProps,
1336
- isOpen,
1337
- highlightedIndex,
1338
- setHighlightedIndex,
1339
- selectItemAtIndex,
1340
- closeMenu
1341
- }
1342
- } = useDropdownContext();
1343
- const {
1344
- isLabelHovered
1345
- } = useFieldContext();
1346
- const [isHovered, setIsHovered] = useState(false);
1347
- const [isFocused, setIsFocused] = useState(false);
1348
- const hiddenInputRef = useRef();
1349
- const triggerRef = useRef();
1350
- const previousIsOpenRef = useRef(undefined);
1351
- const [searchString, setSearchString] = useState('');
1352
- const searchTimeoutRef = useRef();
1353
- const currentSearchIndexRef = useRef(0);
1354
- useEffect(() => {
1355
- if (hiddenInputRef.current && isOpen && !previousIsOpenRef.current) {
1356
- hiddenInputRef.current.focus();
1357
- }
1358
- if (triggerRef.current && !isOpen && previousIsOpenRef.current) {
1359
- triggerRef.current.focus();
1360
- }
1361
- previousIsOpenRef.current = isOpen;
1362
- }, [isOpen, triggerRef]);
1363
- useEffect(() => {
1364
- if (searchTimeoutRef.current) {
1365
- clearTimeout(searchTimeoutRef.current);
1366
- }
1367
- searchTimeoutRef.current = window.setTimeout(() => {
1368
- setSearchString('');
1369
- }, 500);
1370
- return () => {
1371
- clearTimeout(searchTimeoutRef.current);
1372
- };
1373
- }, [searchString]);
1374
- const searchItems = useCallback((searchValue, startIndex, endIndex) => {
1375
- for (let index = startIndex; index < endIndex; index++) {
1376
- const itemTextValue = itemSearchRegistry.current[index];
1377
- if (itemTextValue && itemTextValue.toUpperCase().indexOf(searchValue.toUpperCase()) === 0) {
1378
- return index;
1379
- }
1380
- }
1381
- return undefined;
1382
- }, [itemSearchRegistry]);
1383
- const onInputKeyDown = useCallback(e => {
1384
- if (e.keyCode === KEY_CODES.SPACE) {
1385
- if (searchString) {
1386
- e.preventDefault();
1387
- e.stopPropagation();
1388
- } else if (highlightedIndex !== null && highlightedIndex !== undefined) {
1389
- e.preventDefault();
1390
- e.stopPropagation();
1391
- selectItemAtIndex(highlightedIndex);
1392
- closeMenu();
1393
- }
1394
- }
1395
- if ((e.keyCode < 48 || e.keyCode > 57) && (e.keyCode < 65 || e.keyCode > 90) && e.keyCode !== KEY_CODES.SPACE) {
1396
- return;
1397
- }
1398
- const character = String.fromCharCode(e.which || e.keyCode);
1399
- if (!character || character.length === 0) {
1400
- return;
1401
- }
1402
- if (!searchString) {
1403
- if (highlightedIndex === null || highlightedIndex === undefined) {
1404
- currentSearchIndexRef.current = -1;
1405
- } else {
1406
- currentSearchIndexRef.current = highlightedIndex;
1407
- }
1408
- }
1409
- const newSearchString = searchString + character;
1410
- setSearchString(newSearchString);
1411
- let matchingIndex = searchItems(newSearchString, currentSearchIndexRef.current + 1, itemSearchRegistry.current.length);
1412
- if (matchingIndex === undefined) {
1413
- matchingIndex = searchItems(newSearchString, 0, currentSearchIndexRef.current);
1414
- }
1415
- if (matchingIndex !== undefined) {
1416
- setHighlightedIndex(matchingIndex);
1417
- }
1418
- }, [searchString, searchItems, itemSearchRegistry, highlightedIndex, selectItemAtIndex, closeMenu, setHighlightedIndex]);
1419
- const {
1420
- type,
1421
- ...selectProps
1422
- } = getToggleButtonProps({
1423
- tabIndex: props.disabled ? undefined : 0,
1424
- onMouseEnter: composeEventHandlers(props.onMouseEnter, () => setIsHovered(true)),
1425
- onMouseLeave: composeEventHandlers(props.onMouseLeave, () => setIsHovered(false)),
1426
- onFocus: composeEventHandlers(props.onFocus, () => setIsFocused(true)),
1427
- onBlur: composeEventHandlers(props.onBlur, () => setIsFocused(false)),
1428
- ...props
1429
- });
1430
- const isContainerHovered = isLabelHovered && !isOpen;
1431
- const isContainerFocused = isFocused || isOpen;
1432
- return React__default.createElement(Reference, null, _ref2 => {
1433
- let {
1434
- ref: popperReference
1435
- } = _ref2;
1436
- return React__default.createElement(StyledFauxInput, _extends$5({
1437
- isHovered: isContainerHovered,
1438
- isFocused: isContainerFocused
1439
- }, selectProps, {
1440
- role: "none",
1441
- ref: selectRef => {
1442
- popperReference(selectRef);
1443
- mergeRefs([triggerRef, ref, popperReferenceElementRef])(selectRef);
1444
- }
1445
- }), start && React__default.createElement(StyledFauxInput.StartIcon, {
1446
- isHovered: isHovered || isLabelHovered && !isOpen,
1447
- isFocused: isContainerFocused,
1448
- isDisabled: props.disabled
1449
- }, start), React__default.createElement(StyledSelect, null, children), React__default.createElement(StyledInput, getInputProps({
1450
- readOnly: true,
1451
- isHidden: true,
1452
- tabIndex: -1,
1453
- ref: hiddenInputRef,
1454
- value: '',
1455
- onClick: e => {
1456
- if (isOpen) {
1457
- e.nativeEvent.preventDownshiftDefault = true;
1458
- }
1459
- },
1460
- onKeyDown: onInputKeyDown
1461
- })), !props.isBare && React__default.createElement(StyledFauxInput.EndIcon, {
1462
- isHovered: isHovered || isLabelHovered && !isOpen,
1463
- isFocused: isContainerFocused,
1464
- isDisabled: props.disabled,
1465
- isRotated: isOpen
1466
- }, React__default.createElement(SvgChevronDownStroke, null)));
1467
- });
1468
- });
1469
- Select.displayName = 'Select';
1470
- Select.propTypes = {
1471
- isCompact: PropTypes.bool,
1472
- isBare: PropTypes.bool,
1473
- disabled: PropTypes.bool,
1474
- focusInset: PropTypes.bool,
1475
- validation: PropTypes.oneOf(VALIDATION),
1476
- start: PropTypes.any
1477
- };
1478
-
1479
- const Field = forwardRef((props, fieldRef) => {
1480
- const {
1481
- downshift: {
1482
- getRootProps
1483
- }
1484
- } = useDropdownContext();
1485
- const [isLabelHovered, setIsLabelHovered] = useState(false);
1486
- const {
1487
- ref
1488
- } = getRootProps();
1489
- const value = useMemo(() => ({
1490
- isLabelHovered,
1491
- setIsLabelHovered
1492
- }), [isLabelHovered, setIsLabelHovered]);
1493
- return React__default.createElement(FieldContext.Provider, {
1494
- value: value
1495
- }, React__default.createElement(Field$1, _extends$5({
1496
- ref: mergeRefs([ref, fieldRef])
1497
- }, props)));
1498
- });
1499
- Field.displayName = 'Field';
1500
-
1501
- const Hint = React__default.forwardRef((props, ref) => React__default.createElement(Hint$1, _extends$5({
1502
- ref: ref
1503
- }, props)));
1504
- Hint.displayName = 'Hint';
1505
-
1506
- const Label = React__default.forwardRef((_ref, ref) => {
1507
- let {
1508
- onMouseEnter,
1509
- onMouseLeave,
1510
- ...other
1511
- } = _ref;
1512
- const {
1513
- downshift: {
1514
- getLabelProps
1515
- }
1516
- } = useDropdownContext();
1517
- const {
1518
- setIsLabelHovered
1519
- } = useFieldContext();
1520
- const labelProps = getLabelProps({
1521
- onMouseEnter: composeEventHandlers(onMouseEnter, () => {
1522
- setIsLabelHovered(true);
1523
- }),
1524
- onMouseLeave: composeEventHandlers(onMouseLeave, () => {
1525
- setIsLabelHovered(false);
1526
- }),
1527
- ...other
1528
- });
1529
- return React__default.createElement(Label$1, _extends$5({
1530
- ref: ref
1531
- }, labelProps));
1532
- });
1533
- Label.displayName = 'Label';
1534
- Label.propTypes = {
1535
- isRegular: PropTypes.bool
1536
- };
1537
-
1538
- const Message = React__default.forwardRef((props, ref) => React__default.createElement(Message$1, _extends$5({
1539
- ref: ref
1540
- }, props)));
1541
- Message.displayName = 'Message';
1542
- Message.propTypes = {
1543
- validation: PropTypes.oneOf(VALIDATION)
1544
- };
1545
-
1546
- const SHARED_PLACEMENT = ['auto', 'top', 'top-start', 'top-end', 'bottom', 'bottom-start', 'bottom-end'];
1547
- const PLACEMENT = [...SHARED_PLACEMENT, 'end', 'end-top', 'end-bottom', 'start', 'start-top', 'start-bottom'];
1548
-
1549
- const MenuContext = React__default.createContext(undefined);
1550
- const useMenuContext = () => {
1551
- const menuContext = useContext(MenuContext);
1552
- if (!menuContext) {
1553
- throw new Error('This component must be rendered within a `Menu` component.');
1554
- }
1555
- return menuContext;
1556
- };
1557
-
1558
- const Menu = forwardRef((props, menuRef) => {
1559
- const {
1560
- placement,
1561
- popperModifiers,
1562
- eventsEnabled,
1563
- isAnimated,
1564
- maxHeight,
1565
- style: menuStyle,
1566
- zIndex,
1567
- isCompact,
1568
- children,
1569
- appendToNode,
1570
- ...otherProps
1571
- } = props;
1572
- const {
1573
- hasMenuRef,
1574
- itemIndexRef,
1575
- previousIndexRef,
1576
- nextItemsHashRef,
1577
- popperReferenceElementRef,
1578
- itemSearchRegistry,
1579
- downshift: {
1580
- isOpen,
1581
- getMenuProps
1582
- }
1583
- } = useDropdownContext();
1584
- const scheduleUpdateRef = useRef(undefined);
1585
- useEffect(() => {
1586
- if (scheduleUpdateRef.current && isOpen) {
1587
- scheduleUpdateRef.current();
1588
- }
1589
- });
1590
- const [isVisible, setIsVisible] = useState(isOpen);
1591
- useEffect(() => {
1592
- let timeout;
1593
- if (isOpen) {
1594
- setIsVisible(true);
1595
- } else if (isAnimated) {
1596
- timeout = setTimeout(() => setIsVisible(false), 200);
1597
- } else {
1598
- setIsVisible(false);
1599
- }
1600
- return () => clearTimeout(timeout);
1601
- }, [isOpen, isAnimated]);
1602
- const themeContext = useContext(ThemeContext);
1603
- itemIndexRef.current = 0;
1604
- nextItemsHashRef.current = {};
1605
- previousIndexRef.current = undefined;
1606
- itemSearchRegistry.current = [];
1607
- const popperPlacement = themeContext.rtl ? getRtlPopperPlacement(placement) : getPopperPlacement(placement);
1608
- return (
1609
- React__default.createElement(MenuContext.Provider, {
1610
- value: {
1611
- itemIndexRef,
1612
- isCompact
1613
- }
1614
- }, React__default.createElement(Popper, {
1615
- placement: popperPlacement,
1616
- modifiers: popperModifiers
1617
- ,
1618
- eventsEnabled: isOpen && eventsEnabled
1619
- }, _ref => {
1620
- let {
1621
- ref,
1622
- style,
1623
- scheduleUpdate,
1624
- placement: currentPlacement
1625
- } = _ref;
1626
- let computedStyle = menuStyle;
1627
- scheduleUpdateRef.current = scheduleUpdate;
1628
- if ((isOpen || isVisible) && popperReferenceElementRef.current && popperReferenceElementRef.current.getBoundingClientRect) {
1629
- computedStyle = {
1630
- width: popperReferenceElementRef.current.getBoundingClientRect().width,
1631
- ...menuStyle
1632
- };
1633
- }
1634
- const menuProps = getMenuProps({
1635
- role: hasMenuRef.current ? 'menu' : 'listbox',
1636
- placement: currentPlacement,
1637
- isAnimated: isAnimated && (isOpen || isVisible),
1638
- ...otherProps
1639
- });
1640
- const menu = React__default.createElement(StyledMenuWrapper, {
1641
- ref: isOpen ? ref : undefined,
1642
- hasArrow: menuProps.hasArrow,
1643
- placement: menuProps.placement,
1644
- style: style,
1645
- isHidden: !isOpen,
1646
- isAnimated: menuProps.isAnimated,
1647
- zIndex: zIndex
1648
- }, React__default.createElement(StyledMenu, _extends$5({
1649
- ref: menuRef,
1650
- isCompact: isCompact,
1651
- maxHeight: maxHeight,
1652
- style: computedStyle
1653
- }, menuProps), (isOpen || isVisible) && children));
1654
- return appendToNode ? createPortal(menu, appendToNode) : menu;
1655
- }))
1656
- );
1657
- });
1658
- Menu.displayName = 'Menu';
1659
- Menu.propTypes = {
1660
- popperModifiers: PropTypes.any,
1661
- eventsEnabled: PropTypes.bool,
1662
- zIndex: PropTypes.number,
1663
- style: PropTypes.object,
1664
- placement: PropTypes.oneOf(PLACEMENT),
1665
- isAnimated: PropTypes.bool,
1666
- isCompact: PropTypes.bool,
1667
- hasArrow: PropTypes.bool,
1668
- maxHeight: PropTypes.string
1669
- };
1670
- Menu.defaultProps = {
1671
- placement: 'bottom-start',
1672
- isAnimated: true,
1673
- eventsEnabled: true,
1674
- maxHeight: '400px',
1675
- zIndex: 1000
1676
- };
1677
-
1678
- const Separator = React__default.forwardRef((props, ref) => React__default.createElement(StyledSeparator, _extends$5({
1679
- ref: ref
1680
- }, props)));
1681
- Separator.displayName = 'Separator';
1682
-
1683
- var _path$1;
1684
- function _extends$1() { _extends$1 = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$1.apply(this, arguments); }
1685
- var SvgPlusStroke = function SvgPlusStroke(props) {
1686
- return /*#__PURE__*/React.createElement("svg", _extends$1({
1687
- xmlns: "http://www.w3.org/2000/svg",
1688
- width: 16,
1689
- height: 16,
1690
- focusable: "false",
1691
- viewBox: "0 0 16 16",
1692
- "aria-hidden": "true"
1693
- }, props), _path$1 || (_path$1 = /*#__PURE__*/React.createElement("path", {
1694
- stroke: "currentColor",
1695
- strokeLinecap: "round",
1696
- d: "M7.5 2.5v12m6-6h-12"
1697
- })));
1698
- };
1699
-
1700
- var _path;
1701
- function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
1702
- var SvgCheckLgStroke = function SvgCheckLgStroke(props) {
1703
- return /*#__PURE__*/React.createElement("svg", _extends({
1704
- xmlns: "http://www.w3.org/2000/svg",
1705
- width: 16,
1706
- height: 16,
1707
- focusable: "false",
1708
- viewBox: "0 0 16 16",
1709
- "aria-hidden": "true"
1710
- }, props), _path || (_path = /*#__PURE__*/React.createElement("path", {
1711
- fill: "none",
1712
- stroke: "currentColor",
1713
- strokeLinecap: "round",
1714
- strokeLinejoin: "round",
1715
- d: "M1 9l4 4L15 3"
1716
- })));
1717
- };
1718
-
1719
- const ItemContext = React__default.createContext(undefined);
1720
- const useItemContext = () => {
1721
- const context = useContext(ItemContext);
1722
- if (!context) {
1723
- throw new Error('This component must be rendered within an `Item` component.');
1724
- }
1725
- return context;
1726
- };
1727
-
1728
- const Item = React__default.forwardRef((_ref, forwardRef) => {
1729
- let {
1730
- value,
1731
- disabled,
1732
- isDanger,
1733
- component = StyledItem,
1734
- hasIcon,
1735
- children,
1736
- ...props
1737
- } = _ref;
1738
- const {
1739
- selectedItems,
1740
- hasMenuRef,
1741
- itemSearchRegistry,
1742
- downshift: {
1743
- isOpen,
1744
- selectedItem,
1745
- highlightedIndex,
1746
- getItemProps,
1747
- setHighlightedIndex,
1748
- itemToString
1749
- }
1750
- } = useDropdownContext();
1751
- const {
1752
- itemIndexRef,
1753
- isCompact
1754
- } = useMenuContext();
1755
- const itemRef = useRef();
1756
- const Component = component;
1757
- if ((value === undefined || value === null) && !disabled) {
1758
- throw new Error('All Item components require a `value` prop');
1759
- }
1760
- const currentIndex = itemIndexRef.current;
1761
- const isFocused = highlightedIndex === currentIndex;
1762
- let isSelected;
1763
- useEffect(() => {
1764
- if (!disabled && itemRef.current) {
1765
- const itemTextValue = itemRef.current.innerText;
1766
- if (itemTextValue) {
1767
- itemSearchRegistry.current[currentIndex] = itemTextValue;
1768
- }
1769
- }
1770
- });
1771
- if (value) {
1772
- if (selectedItems) {
1773
- isSelected = selectedItems.some(item => {
1774
- return itemToString(item) === itemToString(value);
1775
- });
1776
- } else {
1777
- isSelected = itemToString(selectedItem) === itemToString(value);
1778
- }
1779
- } else {
1780
- isSelected = false;
1781
- }
1782
- useEffect(() => {
1783
- if (isOpen && !disabled && !selectedItems && isSelected) {
1784
- setHighlightedIndex(currentIndex);
1785
- }
1786
- }, [currentIndex, disabled, isOpen, isSelected, selectedItems, setHighlightedIndex]);
1787
- const contextValue = useMemo(() => ({
1788
- isDisabled: disabled
1789
- }), [disabled]);
1790
- const ref = mergeRefs([itemRef, forwardRef]);
1791
- if (disabled) {
1792
- return React__default.createElement(ItemContext.Provider, {
1793
- value: contextValue
1794
- }, React__default.createElement(Component, _extends$5({
1795
- ref: ref,
1796
- disabled: disabled,
1797
- isDanger: isDanger,
1798
- isCompact: isCompact
1799
- }, props), isSelected && !hasIcon && React__default.createElement(StyledItemIcon, {
1800
- isCompact: isCompact,
1801
- isVisible: isSelected,
1802
- isDisabled: disabled
1803
- }, React__default.createElement(SvgCheckLgStroke, null)), children));
1804
- }
1805
- itemIndexRef.current++;
1806
- return React__default.createElement(ItemContext.Provider, {
1807
- value: contextValue
1808
- }, React__default.createElement(Component, getItemProps({
1809
- item: value,
1810
- isFocused,
1811
- ref,
1812
- isCompact,
1813
- isDanger,
1814
- ...(hasMenuRef.current && {
1815
- role: 'menuitem',
1816
- 'aria-selected': null
1817
- }),
1818
- ...props
1819
- }), isSelected && !hasIcon && React__default.createElement(StyledItemIcon, {
1820
- isCompact: isCompact,
1821
- isVisible: isSelected
1822
- }, React__default.createElement(SvgCheckLgStroke, null)), children));
1823
- });
1824
- Item.displayName = 'Item';
1825
- Item.propTypes = {
1826
- value: PropTypes.any,
1827
- disabled: PropTypes.bool
1828
- };
1829
-
1830
- const AddItemComponent = React__default.forwardRef((_ref, ref) => {
1831
- let {
1832
- children,
1833
- disabled,
1834
- ...props
1835
- } = _ref;
1836
- const {
1837
- isCompact
1838
- } = useMenuContext();
1839
- return React__default.createElement(StyledAddItem, _extends$5({
1840
- ref: ref,
1841
- disabled: disabled
1842
- }, props), React__default.createElement(StyledItemIcon, {
1843
- isCompact: isCompact,
1844
- isVisible: true,
1845
- isDisabled: disabled
1846
- }, React__default.createElement(SvgPlusStroke, null)), children);
1847
- });
1848
- const AddItem = React__default.forwardRef((props, ref) => React__default.createElement(Item, _extends$5({
1849
- component: AddItemComponent,
1850
- ref: ref
1851
- }, props, {
1852
- hasIcon: true
1853
- })));
1854
- AddItem.displayName = 'AddItem';
1855
- AddItem.propTypes = {
1856
- value: PropTypes.any,
1857
- disabled: PropTypes.bool
1858
- };
1859
-
1860
- const HeaderIcon = React__default.forwardRef((props, ref) => {
1861
- const {
1862
- isCompact
1863
- } = useMenuContext();
1864
- return React__default.createElement(StyledHeaderIcon, _extends$5({
1865
- ref: ref,
1866
- isCompact: isCompact
1867
- }, props));
1868
- });
1869
- HeaderIcon.displayName = 'HeaderIcon';
1870
-
1871
- const HeaderItem = React__default.forwardRef((props, ref) => {
1872
- const {
1873
- isCompact
1874
- } = useMenuContext();
1875
- return React__default.createElement(StyledHeaderItem, _extends$5({
1876
- ref: ref,
1877
- isCompact: isCompact
1878
- }, props));
1879
- });
1880
- HeaderItem.displayName = 'HeaderItem';
1881
-
1882
- const ItemMeta = React__default.forwardRef((props, ref) => {
1883
- const {
1884
- isCompact
1885
- } = useMenuContext();
1886
- const {
1887
- isDisabled
1888
- } = useItemContext();
1889
- return React__default.createElement(StyledItemMeta, _extends$5({
1890
- ref: ref,
1891
- isCompact: isCompact,
1892
- isDisabled: isDisabled
1893
- }, props));
1894
- });
1895
- ItemMeta.displayName = 'ItemMeta';
1896
-
1897
- const MediaBody = React__default.forwardRef((props, ref) => {
1898
- const {
1899
- isCompact
1900
- } = useMenuContext();
1901
- return React__default.createElement(StyledMediaBody, _extends$5({
1902
- ref: ref,
1903
- isCompact: isCompact
1904
- }, props));
1905
- });
1906
- MediaBody.displayName = 'MediaBody';
1907
-
1908
- const MediaFigure = props => {
1909
- const {
1910
- isCompact
1911
- } = useMenuContext();
1912
- return React__default.createElement(StyledMediaFigure, _extends$5({
1913
- isCompact: isCompact
1914
- }, props));
1915
- };
1916
-
1917
- const MediaItem = React__default.forwardRef((props, ref) => React__default.createElement(Item, _extends$5({
1918
- component: StyledMediaItem,
1919
- ref: ref
1920
- }, props)));
1921
- MediaItem.displayName = 'MediaItem';
1922
- MediaItem.propTypes = {
1923
- value: PropTypes.any,
1924
- disabled: PropTypes.bool
1925
- };
1926
-
1927
- const NextItemComponent = React__default.forwardRef((_ref, ref) => {
1928
- let {
1929
- children,
1930
- disabled,
1931
- ...props
1932
- } = _ref;
1933
- const {
1934
- isCompact
1935
- } = useMenuContext();
1936
- return React__default.createElement(StyledNextItem, _extends$5({
1937
- ref: ref,
1938
- disabled: disabled
1939
- }, props), React__default.createElement(StyledItemIcon, {
1940
- isCompact: isCompact,
1941
- isDisabled: disabled,
1942
- isVisible: true
1943
- }, React__default.createElement(StyledNextIcon, {
1944
- isDisabled: disabled
1945
- })), children);
1946
- });
1947
- const NextItem = React__default.forwardRef((_ref2, ref) => {
1948
- let {
1949
- value,
1950
- disabled,
1951
- ...props
1952
- } = _ref2;
1953
- const {
1954
- nextItemsHashRef,
1955
- downshift: {
1956
- itemToString
1957
- }
1958
- } = useDropdownContext();
1959
- const {
1960
- itemIndexRef
1961
- } = useMenuContext();
1962
- if (!disabled) {
1963
- nextItemsHashRef.current[itemToString(value)] = itemIndexRef.current;
1964
- }
1965
- return React__default.createElement(Item, _extends$5({
1966
- component: NextItemComponent,
1967
- "aria-expanded": true,
1968
- disabled: disabled,
1969
- value: value,
1970
- ref: ref
1971
- }, props, {
1972
- hasIcon: true
1973
- }));
1974
- });
1975
- NextItem.displayName = 'NextItem';
1976
- NextItem.propTypes = {
1977
- value: PropTypes.any,
1978
- disabled: PropTypes.bool
1979
- };
1980
-
1981
- const PreviousItemComponent = React__default.forwardRef((_ref, ref) => {
1982
- let {
1983
- children,
1984
- disabled,
1985
- ...props
1986
- } = _ref;
1987
- const {
1988
- isCompact
1989
- } = useMenuContext();
1990
- return React__default.createElement(StyledPreviousItem, _extends$5({
1991
- ref: ref,
1992
- disabled: disabled
1993
- }, props), React__default.createElement(StyledItemIcon, {
1994
- isCompact: isCompact,
1995
- isDisabled: disabled,
1996
- isVisible: true
1997
- }, React__default.createElement(StyledPreviousIcon, {
1998
- isDisabled: disabled
1999
- })), children);
2000
- });
2001
- const PreviousItem = React__default.forwardRef((_ref2, ref) => {
2002
- let {
2003
- value,
2004
- disabled,
2005
- ...props
2006
- } = _ref2;
2007
- const {
2008
- previousIndexRef
2009
- } = useDropdownContext();
2010
- const {
2011
- itemIndexRef
2012
- } = useMenuContext();
2013
- if (!disabled) {
2014
- previousIndexRef.current = itemIndexRef.current;
2015
- }
2016
- return React__default.createElement(Item, _extends$5({
2017
- component: PreviousItemComponent,
2018
- "aria-expanded": true,
2019
- value: value,
2020
- disabled: disabled
2021
- }, props, {
2022
- ref: ref,
2023
- hasIcon: true
2024
- }));
2025
- });
2026
- PreviousItem.displayName = 'PreviousItem';
2027
- PreviousItem.propTypes = {
2028
- value: PropTypes.any,
2029
- disabled: PropTypes.bool
2030
- };
2031
-
2032
- export { AddItem, Autocomplete, Combobox, Dropdown, Field, HeaderIcon, HeaderItem, Hint, Item, ItemMeta, Label, MediaBody, MediaFigure, MediaItem, Menu, Message, Multiselect, NextItem, PreviousItem, Select, Separator, Trigger };