@zendeskgarden/react-dropdowns.legacy 9.0.0-next.7 → 9.0.0-next.9
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/dist/esm/elements/Autocomplete/Autocomplete.js +144 -0
- package/dist/esm/elements/Combobox/Combobox.js +106 -0
- package/dist/esm/elements/Dropdown/Dropdown.js +178 -0
- package/dist/esm/elements/Fields/Field.js +35 -0
- package/dist/esm/elements/Fields/Hint.js +15 -0
- package/dist/esm/elements/Fields/Label.js +46 -0
- package/dist/esm/elements/Fields/Message.js +19 -0
- package/dist/esm/elements/Menu/Items/AddItem.js +66 -0
- package/dist/esm/elements/Menu/Items/HeaderIcon.js +44 -0
- package/dist/esm/elements/Menu/Items/HeaderItem.js +44 -0
- package/dist/esm/elements/Menu/Items/Item.js +140 -0
- package/dist/esm/elements/Menu/Items/ItemMeta.js +49 -0
- package/dist/esm/elements/Menu/Items/MediaBody.js +44 -0
- package/dist/esm/elements/Menu/Items/MediaFigure.js +42 -0
- package/dist/esm/elements/Menu/Items/MediaItem.js +44 -0
- package/dist/esm/elements/Menu/Items/NextItem.js +90 -0
- package/dist/esm/elements/Menu/Items/PreviousItem.js +87 -0
- package/dist/esm/elements/Menu/Menu.js +160 -0
- package/dist/esm/elements/Menu/Separator.js +37 -0
- package/dist/esm/elements/Multiselect/Multiselect.js +316 -0
- package/dist/esm/elements/Select/Select.js +195 -0
- package/dist/esm/elements/Trigger/Trigger.js +185 -0
- package/dist/esm/index.js +29 -0
- package/dist/esm/node_modules/@zendeskgarden/svg-icons/src/16/check-lg-stroke.svg.js +28 -0
- package/dist/esm/node_modules/@zendeskgarden/svg-icons/src/16/chevron-down-stroke.svg.js +25 -0
- package/dist/esm/node_modules/@zendeskgarden/svg-icons/src/16/chevron-left-stroke.svg.js +25 -0
- package/dist/esm/node_modules/@zendeskgarden/svg-icons/src/16/chevron-right-stroke.svg.js +25 -0
- package/dist/esm/node_modules/@zendeskgarden/svg-icons/src/16/plus-stroke.svg.js +26 -0
- package/dist/esm/styled/items/StyledAddItem.js +23 -0
- package/dist/esm/styled/items/StyledItem.js +44 -0
- package/dist/esm/styled/items/StyledItemIcon.js +27 -0
- package/dist/esm/styled/items/StyledItemMeta.js +22 -0
- package/dist/esm/styled/items/StyledNextIcon.js +31 -0
- package/dist/esm/styled/items/StyledNextItem.js +24 -0
- package/dist/esm/styled/items/StyledPreviousIcon.js +31 -0
- package/dist/esm/styled/items/StyledPreviousItem.js +23 -0
- package/dist/esm/styled/items/header/StyledHeaderIcon.js +22 -0
- package/dist/esm/styled/items/header/StyledHeaderItem.js +29 -0
- package/dist/esm/styled/items/media/StyledMediaBody.js +22 -0
- package/dist/esm/styled/items/media/StyledMediaFigure.js +34 -0
- package/dist/esm/styled/items/media/StyledMediaItem.js +23 -0
- package/dist/esm/styled/menu/StyledMenu.js +28 -0
- package/dist/esm/styled/menu/StyledMenuWrapper.js +30 -0
- package/dist/esm/styled/menu/StyledSeparator.js +23 -0
- package/dist/esm/styled/multiselect/StyledMultiselectInput.js +33 -0
- package/dist/esm/styled/multiselect/StyledMultiselectItemWrapper.js +22 -0
- package/dist/esm/styled/multiselect/StyledMultiselectItemsContainer.js +34 -0
- package/dist/esm/styled/multiselect/StyledMultiselectMoreAnchor.js +22 -0
- package/dist/esm/styled/select/StyledFauxInput.js +25 -0
- package/dist/esm/styled/select/StyledInput.js +25 -0
- package/dist/esm/styled/select/StyledSelect.js +22 -0
- package/dist/esm/types/index.js +10 -0
- package/dist/esm/utils/garden-placements.js +77 -0
- package/dist/esm/utils/useDropdownContext.js +18 -0
- package/dist/esm/utils/useFieldContext.js +18 -0
- package/dist/esm/utils/useItemContext.js +18 -0
- package/dist/esm/utils/useMenuContext.js +18 -0
- package/dist/index.cjs.js +51 -67
- package/dist/typings/styled/select/StyledFauxInput.d.ts +2 -2
- package/package.json +6 -6
- package/dist/index.esm.js +0 -2032
|
@@ -0,0 +1,195 @@
|
|
|
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
|
+
import React__default, { useState, useRef, useEffect, useCallback } from 'react';
|
|
8
|
+
import { KEY_CODES, composeEventHandlers } from '@zendeskgarden/container-utilities';
|
|
9
|
+
import SvgChevronDownStroke from '../../node_modules/@zendeskgarden/svg-icons/src/16/chevron-down-stroke.svg.js';
|
|
10
|
+
import { VALIDATION } from '@zendeskgarden/react-forms';
|
|
11
|
+
import PropTypes from 'prop-types';
|
|
12
|
+
import { Reference } from 'react-popper';
|
|
13
|
+
import { mergeRefs } from 'react-merge-refs';
|
|
14
|
+
import '../../styled/menu/StyledMenu.js';
|
|
15
|
+
import '../../styled/menu/StyledMenuWrapper.js';
|
|
16
|
+
import '../../styled/menu/StyledSeparator.js';
|
|
17
|
+
import '../../styled/items/StyledAddItem.js';
|
|
18
|
+
import '../../styled/items/StyledItem.js';
|
|
19
|
+
import '../../styled/items/StyledItemMeta.js';
|
|
20
|
+
import '../../styled/items/StyledNextItem.js';
|
|
21
|
+
import '../../styled/items/StyledNextIcon.js';
|
|
22
|
+
import '../../styled/items/StyledPreviousItem.js';
|
|
23
|
+
import '../../styled/items/StyledPreviousIcon.js';
|
|
24
|
+
import '../../styled/items/StyledItemIcon.js';
|
|
25
|
+
import '../../styled/items/header/StyledHeaderIcon.js';
|
|
26
|
+
import '../../styled/items/header/StyledHeaderItem.js';
|
|
27
|
+
import '../../styled/items/media/StyledMediaBody.js';
|
|
28
|
+
import '../../styled/items/media/StyledMediaFigure.js';
|
|
29
|
+
import '../../styled/items/media/StyledMediaItem.js';
|
|
30
|
+
import { StyledFauxInput } from '../../styled/select/StyledFauxInput.js';
|
|
31
|
+
import { StyledInput } from '../../styled/select/StyledInput.js';
|
|
32
|
+
import { StyledSelect } from '../../styled/select/StyledSelect.js';
|
|
33
|
+
import '../../styled/multiselect/StyledMultiselectInput.js';
|
|
34
|
+
import '../../styled/multiselect/StyledMultiselectItemsContainer.js';
|
|
35
|
+
import '../../styled/multiselect/StyledMultiselectItemWrapper.js';
|
|
36
|
+
import '../../styled/multiselect/StyledMultiselectMoreAnchor.js';
|
|
37
|
+
import useDropdownContext from '../../utils/useDropdownContext.js';
|
|
38
|
+
import useFieldContext from '../../utils/useFieldContext.js';
|
|
39
|
+
|
|
40
|
+
const Select = React__default.forwardRef((_ref, ref) => {
|
|
41
|
+
let {
|
|
42
|
+
children,
|
|
43
|
+
start,
|
|
44
|
+
...props
|
|
45
|
+
} = _ref;
|
|
46
|
+
const {
|
|
47
|
+
popperReferenceElementRef,
|
|
48
|
+
itemSearchRegistry,
|
|
49
|
+
downshift: {
|
|
50
|
+
getToggleButtonProps,
|
|
51
|
+
getInputProps,
|
|
52
|
+
isOpen,
|
|
53
|
+
highlightedIndex,
|
|
54
|
+
setHighlightedIndex,
|
|
55
|
+
selectItemAtIndex,
|
|
56
|
+
closeMenu
|
|
57
|
+
}
|
|
58
|
+
} = useDropdownContext();
|
|
59
|
+
const {
|
|
60
|
+
isLabelHovered
|
|
61
|
+
} = useFieldContext();
|
|
62
|
+
const [isHovered, setIsHovered] = useState(false);
|
|
63
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
64
|
+
const hiddenInputRef = useRef();
|
|
65
|
+
const triggerRef = useRef();
|
|
66
|
+
const previousIsOpenRef = useRef(undefined);
|
|
67
|
+
const [searchString, setSearchString] = useState('');
|
|
68
|
+
const searchTimeoutRef = useRef();
|
|
69
|
+
const currentSearchIndexRef = useRef(0);
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
if (hiddenInputRef.current && isOpen && !previousIsOpenRef.current) {
|
|
72
|
+
hiddenInputRef.current.focus();
|
|
73
|
+
}
|
|
74
|
+
if (triggerRef.current && !isOpen && previousIsOpenRef.current) {
|
|
75
|
+
triggerRef.current.focus();
|
|
76
|
+
}
|
|
77
|
+
previousIsOpenRef.current = isOpen;
|
|
78
|
+
}, [isOpen, triggerRef]);
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
if (searchTimeoutRef.current) {
|
|
81
|
+
clearTimeout(searchTimeoutRef.current);
|
|
82
|
+
}
|
|
83
|
+
searchTimeoutRef.current = window.setTimeout(() => {
|
|
84
|
+
setSearchString('');
|
|
85
|
+
}, 500);
|
|
86
|
+
return () => {
|
|
87
|
+
clearTimeout(searchTimeoutRef.current);
|
|
88
|
+
};
|
|
89
|
+
}, [searchString]);
|
|
90
|
+
const searchItems = useCallback((searchValue, startIndex, endIndex) => {
|
|
91
|
+
for (let index = startIndex; index < endIndex; index++) {
|
|
92
|
+
const itemTextValue = itemSearchRegistry.current[index];
|
|
93
|
+
if (itemTextValue && itemTextValue.toUpperCase().indexOf(searchValue.toUpperCase()) === 0) {
|
|
94
|
+
return index;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return undefined;
|
|
98
|
+
}, [itemSearchRegistry]);
|
|
99
|
+
const onInputKeyDown = useCallback(e => {
|
|
100
|
+
if (e.keyCode === KEY_CODES.SPACE) {
|
|
101
|
+
if (searchString) {
|
|
102
|
+
e.preventDefault();
|
|
103
|
+
e.stopPropagation();
|
|
104
|
+
} else if (highlightedIndex !== null && highlightedIndex !== undefined) {
|
|
105
|
+
e.preventDefault();
|
|
106
|
+
e.stopPropagation();
|
|
107
|
+
selectItemAtIndex(highlightedIndex);
|
|
108
|
+
closeMenu();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if ((e.keyCode < 48 || e.keyCode > 57) && (e.keyCode < 65 || e.keyCode > 90) && e.keyCode !== KEY_CODES.SPACE) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const character = String.fromCharCode(e.which || e.keyCode);
|
|
115
|
+
if (!character || character.length === 0) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (!searchString) {
|
|
119
|
+
if (highlightedIndex === null || highlightedIndex === undefined) {
|
|
120
|
+
currentSearchIndexRef.current = -1;
|
|
121
|
+
} else {
|
|
122
|
+
currentSearchIndexRef.current = highlightedIndex;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const newSearchString = searchString + character;
|
|
126
|
+
setSearchString(newSearchString);
|
|
127
|
+
let matchingIndex = searchItems(newSearchString, currentSearchIndexRef.current + 1, itemSearchRegistry.current.length);
|
|
128
|
+
if (matchingIndex === undefined) {
|
|
129
|
+
matchingIndex = searchItems(newSearchString, 0, currentSearchIndexRef.current);
|
|
130
|
+
}
|
|
131
|
+
if (matchingIndex !== undefined) {
|
|
132
|
+
setHighlightedIndex(matchingIndex);
|
|
133
|
+
}
|
|
134
|
+
}, [searchString, searchItems, itemSearchRegistry, highlightedIndex, selectItemAtIndex, closeMenu, setHighlightedIndex]);
|
|
135
|
+
const {
|
|
136
|
+
type,
|
|
137
|
+
...selectProps
|
|
138
|
+
} = getToggleButtonProps({
|
|
139
|
+
tabIndex: props.disabled ? undefined : 0,
|
|
140
|
+
onMouseEnter: composeEventHandlers(props.onMouseEnter, () => setIsHovered(true)),
|
|
141
|
+
onMouseLeave: composeEventHandlers(props.onMouseLeave, () => setIsHovered(false)),
|
|
142
|
+
onFocus: composeEventHandlers(props.onFocus, () => setIsFocused(true)),
|
|
143
|
+
onBlur: composeEventHandlers(props.onBlur, () => setIsFocused(false)),
|
|
144
|
+
...props
|
|
145
|
+
});
|
|
146
|
+
const isContainerHovered = isLabelHovered && !isOpen;
|
|
147
|
+
const isContainerFocused = isFocused || isOpen;
|
|
148
|
+
return React__default.createElement(Reference, null, _ref2 => {
|
|
149
|
+
let {
|
|
150
|
+
ref: popperReference
|
|
151
|
+
} = _ref2;
|
|
152
|
+
return React__default.createElement(StyledFauxInput, Object.assign({
|
|
153
|
+
isHovered: isContainerHovered,
|
|
154
|
+
isFocused: isContainerFocused
|
|
155
|
+
}, selectProps, {
|
|
156
|
+
role: "none",
|
|
157
|
+
ref: selectRef => {
|
|
158
|
+
popperReference(selectRef);
|
|
159
|
+
mergeRefs([triggerRef, ref, popperReferenceElementRef])(selectRef);
|
|
160
|
+
}
|
|
161
|
+
}), start && React__default.createElement(StyledFauxInput.StartIcon, {
|
|
162
|
+
isHovered: isHovered || isLabelHovered && !isOpen,
|
|
163
|
+
isFocused: isContainerFocused,
|
|
164
|
+
isDisabled: props.disabled
|
|
165
|
+
}, start), React__default.createElement(StyledSelect, null, children), React__default.createElement(StyledInput, getInputProps({
|
|
166
|
+
readOnly: true,
|
|
167
|
+
isHidden: true,
|
|
168
|
+
tabIndex: -1,
|
|
169
|
+
ref: hiddenInputRef,
|
|
170
|
+
value: '',
|
|
171
|
+
onClick: e => {
|
|
172
|
+
if (isOpen) {
|
|
173
|
+
e.nativeEvent.preventDownshiftDefault = true;
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
onKeyDown: onInputKeyDown
|
|
177
|
+
})), !props.isBare && React__default.createElement(StyledFauxInput.EndIcon, {
|
|
178
|
+
isHovered: isHovered || isLabelHovered && !isOpen,
|
|
179
|
+
isFocused: isContainerFocused,
|
|
180
|
+
isDisabled: props.disabled,
|
|
181
|
+
isRotated: isOpen
|
|
182
|
+
}, React__default.createElement(SvgChevronDownStroke, null)));
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
Select.displayName = 'Select';
|
|
186
|
+
Select.propTypes = {
|
|
187
|
+
isCompact: PropTypes.bool,
|
|
188
|
+
isBare: PropTypes.bool,
|
|
189
|
+
disabled: PropTypes.bool,
|
|
190
|
+
focusInset: PropTypes.bool,
|
|
191
|
+
validation: PropTypes.oneOf(VALIDATION),
|
|
192
|
+
start: PropTypes.any
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
export { Select };
|
|
@@ -0,0 +1,185 @@
|
|
|
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
|
+
import React__default, { useRef, useState, useEffect, useCallback } from 'react';
|
|
8
|
+
import PropTypes from 'prop-types';
|
|
9
|
+
import { Reference } from 'react-popper';
|
|
10
|
+
import { KEY_CODES } from '@zendeskgarden/container-utilities';
|
|
11
|
+
import '../../styled/menu/StyledMenu.js';
|
|
12
|
+
import '../../styled/menu/StyledMenuWrapper.js';
|
|
13
|
+
import '../../styled/menu/StyledSeparator.js';
|
|
14
|
+
import '../../styled/items/StyledAddItem.js';
|
|
15
|
+
import '../../styled/items/StyledItem.js';
|
|
16
|
+
import '../../styled/items/StyledItemMeta.js';
|
|
17
|
+
import '../../styled/items/StyledNextItem.js';
|
|
18
|
+
import '../../styled/items/StyledNextIcon.js';
|
|
19
|
+
import '../../styled/items/StyledPreviousItem.js';
|
|
20
|
+
import '../../styled/items/StyledPreviousIcon.js';
|
|
21
|
+
import '../../styled/items/StyledItemIcon.js';
|
|
22
|
+
import '../../styled/items/header/StyledHeaderIcon.js';
|
|
23
|
+
import '../../styled/items/header/StyledHeaderItem.js';
|
|
24
|
+
import '../../styled/items/media/StyledMediaBody.js';
|
|
25
|
+
import '../../styled/items/media/StyledMediaFigure.js';
|
|
26
|
+
import '../../styled/items/media/StyledMediaItem.js';
|
|
27
|
+
import '../../styled/select/StyledFauxInput.js';
|
|
28
|
+
import { StyledInput } from '../../styled/select/StyledInput.js';
|
|
29
|
+
import '../../styled/select/StyledSelect.js';
|
|
30
|
+
import '../../styled/multiselect/StyledMultiselectInput.js';
|
|
31
|
+
import '../../styled/multiselect/StyledMultiselectItemsContainer.js';
|
|
32
|
+
import '../../styled/multiselect/StyledMultiselectItemWrapper.js';
|
|
33
|
+
import '../../styled/multiselect/StyledMultiselectMoreAnchor.js';
|
|
34
|
+
import useDropdownContext from '../../utils/useDropdownContext.js';
|
|
35
|
+
|
|
36
|
+
const Trigger = _ref => {
|
|
37
|
+
let {
|
|
38
|
+
children,
|
|
39
|
+
refKey,
|
|
40
|
+
...triggerProps
|
|
41
|
+
} = _ref;
|
|
42
|
+
const {
|
|
43
|
+
hasMenuRef,
|
|
44
|
+
itemSearchRegistry,
|
|
45
|
+
downshift: {
|
|
46
|
+
getRootProps,
|
|
47
|
+
getToggleButtonProps,
|
|
48
|
+
getInputProps,
|
|
49
|
+
isOpen,
|
|
50
|
+
highlightedIndex,
|
|
51
|
+
selectItemAtIndex,
|
|
52
|
+
setHighlightedIndex
|
|
53
|
+
}
|
|
54
|
+
} = useDropdownContext();
|
|
55
|
+
const hiddenInputRef = useRef(null);
|
|
56
|
+
const triggerRef = useRef(null);
|
|
57
|
+
const previousIsOpenRef = useRef(undefined);
|
|
58
|
+
const [searchString, setSearchString] = useState('');
|
|
59
|
+
const searchTimeoutRef = useRef();
|
|
60
|
+
const currentSearchIndexRef = useRef(0);
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (hiddenInputRef.current && isOpen && !previousIsOpenRef.current) {
|
|
63
|
+
hiddenInputRef.current.focus();
|
|
64
|
+
}
|
|
65
|
+
if (triggerRef.current && !isOpen && previousIsOpenRef.current) {
|
|
66
|
+
triggerRef.current.focus();
|
|
67
|
+
}
|
|
68
|
+
previousIsOpenRef.current = isOpen;
|
|
69
|
+
}, [isOpen, hasMenuRef]);
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
if (hasMenuRef.current === false) {
|
|
72
|
+
hasMenuRef.current = true;
|
|
73
|
+
}
|
|
74
|
+
}, [hasMenuRef]);
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (searchTimeoutRef.current) {
|
|
77
|
+
clearTimeout(searchTimeoutRef.current);
|
|
78
|
+
}
|
|
79
|
+
searchTimeoutRef.current = window.setTimeout(() => {
|
|
80
|
+
setSearchString('');
|
|
81
|
+
}, 500);
|
|
82
|
+
return () => {
|
|
83
|
+
clearTimeout(searchTimeoutRef.current);
|
|
84
|
+
};
|
|
85
|
+
}, [searchString]);
|
|
86
|
+
const searchItems = useCallback((searchValue, startIndex, endIndex) => {
|
|
87
|
+
for (let index = startIndex; index < endIndex; index++) {
|
|
88
|
+
const itemTextValue = itemSearchRegistry.current[index];
|
|
89
|
+
if (itemTextValue && itemTextValue.toUpperCase().indexOf(searchValue.toUpperCase()) === 0) {
|
|
90
|
+
return index;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return undefined;
|
|
94
|
+
}, [itemSearchRegistry]);
|
|
95
|
+
const onInputKeyDown = useCallback(e => {
|
|
96
|
+
if (e.keyCode === KEY_CODES.SPACE) {
|
|
97
|
+
if (searchString) {
|
|
98
|
+
e.preventDefault();
|
|
99
|
+
e.stopPropagation();
|
|
100
|
+
} else if (highlightedIndex !== null && highlightedIndex !== undefined) {
|
|
101
|
+
e.preventDefault();
|
|
102
|
+
e.stopPropagation();
|
|
103
|
+
selectItemAtIndex(highlightedIndex);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if ((e.keyCode < 48 || e.keyCode > 57) && (e.keyCode < 65 || e.keyCode > 90) && e.keyCode !== KEY_CODES.SPACE) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const character = String.fromCharCode(e.which || e.keyCode);
|
|
110
|
+
if (!character || character.length === 0) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (!searchString) {
|
|
114
|
+
if (highlightedIndex === null || highlightedIndex === undefined) {
|
|
115
|
+
currentSearchIndexRef.current = -1;
|
|
116
|
+
} else {
|
|
117
|
+
currentSearchIndexRef.current = highlightedIndex;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const newSearchString = searchString + character;
|
|
121
|
+
setSearchString(newSearchString);
|
|
122
|
+
let matchingIndex = searchItems(newSearchString, currentSearchIndexRef.current + 1, itemSearchRegistry.current.length);
|
|
123
|
+
if (matchingIndex === undefined) {
|
|
124
|
+
matchingIndex = searchItems(newSearchString, 0, currentSearchIndexRef.current);
|
|
125
|
+
}
|
|
126
|
+
if (matchingIndex !== undefined) {
|
|
127
|
+
setHighlightedIndex(matchingIndex);
|
|
128
|
+
}
|
|
129
|
+
}, [searchString, searchItems, itemSearchRegistry, highlightedIndex, selectItemAtIndex, setHighlightedIndex]);
|
|
130
|
+
const renderChildren = popperRef => {
|
|
131
|
+
const {
|
|
132
|
+
ref: rootPropsRefCallback,
|
|
133
|
+
...rootProps
|
|
134
|
+
} = getRootProps();
|
|
135
|
+
const listboxToggleProps = getToggleButtonProps({
|
|
136
|
+
...rootProps,
|
|
137
|
+
role: null,
|
|
138
|
+
'aria-labelledby': undefined,
|
|
139
|
+
...triggerProps,
|
|
140
|
+
...children.props
|
|
141
|
+
});
|
|
142
|
+
const menuToggleProps = {
|
|
143
|
+
...listboxToggleProps,
|
|
144
|
+
'aria-haspopup': 'true',
|
|
145
|
+
'aria-controls': listboxToggleProps['aria-owns'],
|
|
146
|
+
'aria-owns': null
|
|
147
|
+
};
|
|
148
|
+
const toggleButtonProps = hasMenuRef.current ? menuToggleProps : listboxToggleProps;
|
|
149
|
+
return React__default.cloneElement(React__default.Children.only(children), {
|
|
150
|
+
...toggleButtonProps,
|
|
151
|
+
[refKey]: childRef => {
|
|
152
|
+
popperRef(childRef);
|
|
153
|
+
triggerRef.current = childRef;
|
|
154
|
+
rootPropsRefCallback(childRef);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
return React__default.createElement(Reference, null, _ref2 => {
|
|
159
|
+
let {
|
|
160
|
+
ref: popperReference
|
|
161
|
+
} = _ref2;
|
|
162
|
+
return React__default.createElement(React__default.Fragment, null, renderChildren(popperReference), React__default.createElement(StyledInput, getInputProps({
|
|
163
|
+
readOnly: true,
|
|
164
|
+
isHidden: true,
|
|
165
|
+
tabIndex: -1,
|
|
166
|
+
ref: hiddenInputRef,
|
|
167
|
+
value: '',
|
|
168
|
+
onClick: e => {
|
|
169
|
+
if (isOpen) {
|
|
170
|
+
e.nativeEvent.preventDownshiftDefault = true;
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
onKeyDown: onInputKeyDown
|
|
174
|
+
})));
|
|
175
|
+
});
|
|
176
|
+
};
|
|
177
|
+
Trigger.propTypes = {
|
|
178
|
+
children: PropTypes.any,
|
|
179
|
+
refKey: PropTypes.string
|
|
180
|
+
};
|
|
181
|
+
Trigger.defaultProps = {
|
|
182
|
+
refKey: 'ref'
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
export { Trigger };
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
export { Dropdown } from './elements/Dropdown/Dropdown.js';
|
|
8
|
+
export { Trigger } from './elements/Trigger/Trigger.js';
|
|
9
|
+
export { Autocomplete } from './elements/Autocomplete/Autocomplete.js';
|
|
10
|
+
export { Combobox } from './elements/Combobox/Combobox.js';
|
|
11
|
+
export { Multiselect } from './elements/Multiselect/Multiselect.js';
|
|
12
|
+
export { Select } from './elements/Select/Select.js';
|
|
13
|
+
export { Field } from './elements/Fields/Field.js';
|
|
14
|
+
export { Hint } from './elements/Fields/Hint.js';
|
|
15
|
+
export { Label } from './elements/Fields/Label.js';
|
|
16
|
+
export { Message } from './elements/Fields/Message.js';
|
|
17
|
+
export { Menu } from './elements/Menu/Menu.js';
|
|
18
|
+
export { Separator } from './elements/Menu/Separator.js';
|
|
19
|
+
export { AddItem } from './elements/Menu/Items/AddItem.js';
|
|
20
|
+
export { HeaderIcon } from './elements/Menu/Items/HeaderIcon.js';
|
|
21
|
+
export { HeaderItem } from './elements/Menu/Items/HeaderItem.js';
|
|
22
|
+
export { Item } from './elements/Menu/Items/Item.js';
|
|
23
|
+
export { ItemMeta } from './elements/Menu/Items/ItemMeta.js';
|
|
24
|
+
export { MediaBody } from './elements/Menu/Items/MediaBody.js';
|
|
25
|
+
export { MediaFigure } from './elements/Menu/Items/MediaFigure.js';
|
|
26
|
+
export { MediaItem } from './elements/Menu/Items/MediaItem.js';
|
|
27
|
+
export { NextItem } from './elements/Menu/Items/NextItem.js';
|
|
28
|
+
export { PreviousItem } from './elements/Menu/Items/PreviousItem.js';
|
|
29
|
+
export { resetIdCounter } from 'downshift';
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
import * as React from 'react';
|
|
8
|
+
|
|
9
|
+
var _path;
|
|
10
|
+
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); }
|
|
11
|
+
var SvgCheckLgStroke = function SvgCheckLgStroke(props) {
|
|
12
|
+
return /*#__PURE__*/React.createElement("svg", _extends({
|
|
13
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
14
|
+
width: 16,
|
|
15
|
+
height: 16,
|
|
16
|
+
focusable: "false",
|
|
17
|
+
viewBox: "0 0 16 16",
|
|
18
|
+
"aria-hidden": "true"
|
|
19
|
+
}, props), _path || (_path = /*#__PURE__*/React.createElement("path", {
|
|
20
|
+
fill: "none",
|
|
21
|
+
stroke: "currentColor",
|
|
22
|
+
strokeLinecap: "round",
|
|
23
|
+
strokeLinejoin: "round",
|
|
24
|
+
d: "M1 9l4 4L15 3"
|
|
25
|
+
})));
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export { SvgCheckLgStroke as default };
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
import * as React from 'react';
|
|
8
|
+
|
|
9
|
+
var _path;
|
|
10
|
+
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); }
|
|
11
|
+
var SvgChevronDownStroke = function SvgChevronDownStroke(props) {
|
|
12
|
+
return /*#__PURE__*/React.createElement("svg", _extends({
|
|
13
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
14
|
+
width: 16,
|
|
15
|
+
height: 16,
|
|
16
|
+
focusable: "false",
|
|
17
|
+
viewBox: "0 0 16 16",
|
|
18
|
+
"aria-hidden": "true"
|
|
19
|
+
}, props), _path || (_path = /*#__PURE__*/React.createElement("path", {
|
|
20
|
+
fill: "currentColor",
|
|
21
|
+
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"
|
|
22
|
+
})));
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export { SvgChevronDownStroke as default };
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
import * as React from 'react';
|
|
8
|
+
|
|
9
|
+
var _path;
|
|
10
|
+
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); }
|
|
11
|
+
var SvgChevronLeftStroke = function SvgChevronLeftStroke(props) {
|
|
12
|
+
return /*#__PURE__*/React.createElement("svg", _extends({
|
|
13
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
14
|
+
width: 16,
|
|
15
|
+
height: 16,
|
|
16
|
+
focusable: "false",
|
|
17
|
+
viewBox: "0 0 16 16",
|
|
18
|
+
"aria-hidden": "true"
|
|
19
|
+
}, props), _path || (_path = /*#__PURE__*/React.createElement("path", {
|
|
20
|
+
fill: "currentColor",
|
|
21
|
+
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"
|
|
22
|
+
})));
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export { SvgChevronLeftStroke as default };
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
import * as React from 'react';
|
|
8
|
+
|
|
9
|
+
var _path;
|
|
10
|
+
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); }
|
|
11
|
+
var SvgChevronRightStroke = function SvgChevronRightStroke(props) {
|
|
12
|
+
return /*#__PURE__*/React.createElement("svg", _extends({
|
|
13
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
14
|
+
width: 16,
|
|
15
|
+
height: 16,
|
|
16
|
+
focusable: "false",
|
|
17
|
+
viewBox: "0 0 16 16",
|
|
18
|
+
"aria-hidden": "true"
|
|
19
|
+
}, props), _path || (_path = /*#__PURE__*/React.createElement("path", {
|
|
20
|
+
fill: "currentColor",
|
|
21
|
+
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"
|
|
22
|
+
})));
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export { SvgChevronRightStroke as default };
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
import * as React from 'react';
|
|
8
|
+
|
|
9
|
+
var _path;
|
|
10
|
+
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); }
|
|
11
|
+
var SvgPlusStroke = function SvgPlusStroke(props) {
|
|
12
|
+
return /*#__PURE__*/React.createElement("svg", _extends({
|
|
13
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
14
|
+
width: 16,
|
|
15
|
+
height: 16,
|
|
16
|
+
focusable: "false",
|
|
17
|
+
viewBox: "0 0 16 16",
|
|
18
|
+
"aria-hidden": "true"
|
|
19
|
+
}, props), _path || (_path = /*#__PURE__*/React.createElement("path", {
|
|
20
|
+
stroke: "currentColor",
|
|
21
|
+
strokeLinecap: "round",
|
|
22
|
+
d: "M7.5 2.5v12m6-6h-12"
|
|
23
|
+
})));
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { SvgPlusStroke as default };
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
import styled from 'styled-components';
|
|
8
|
+
import { getColorV8, retrieveComponentStyles, DEFAULT_THEME } from '@zendeskgarden/react-theming';
|
|
9
|
+
import { StyledItem } from './StyledItem.js';
|
|
10
|
+
|
|
11
|
+
const COMPONENT_ID = 'dropdowns.add_item';
|
|
12
|
+
const StyledAddItem = styled(StyledItem).attrs({
|
|
13
|
+
'data-garden-id': COMPONENT_ID,
|
|
14
|
+
'data-garden-version': '9.0.0-next.9'
|
|
15
|
+
}).withConfig({
|
|
16
|
+
displayName: "StyledAddItem",
|
|
17
|
+
componentId: "sc-mlto71-0"
|
|
18
|
+
})(["color:", ";", ";"], props => !props.disabled && getColorV8('primaryHue', 600, props.theme), props => retrieveComponentStyles(COMPONENT_ID, props));
|
|
19
|
+
StyledAddItem.defaultProps = {
|
|
20
|
+
theme: DEFAULT_THEME
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export { StyledAddItem };
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
import styled, { css } from 'styled-components';
|
|
8
|
+
import { retrieveComponentStyles, DEFAULT_THEME, getColorV8 } from '@zendeskgarden/react-theming';
|
|
9
|
+
import { rgba } from 'polished';
|
|
10
|
+
|
|
11
|
+
const COMPONENT_ID = 'dropdowns.item';
|
|
12
|
+
const getItemPaddingVertical = props => {
|
|
13
|
+
if (props.isCompact) {
|
|
14
|
+
return `${props.theme.space.base}px`;
|
|
15
|
+
}
|
|
16
|
+
return `${props.theme.space.base * 2}px`;
|
|
17
|
+
};
|
|
18
|
+
const getColorStyles = props => {
|
|
19
|
+
let foregroundColor;
|
|
20
|
+
let backgroundColor;
|
|
21
|
+
if (props.disabled) {
|
|
22
|
+
foregroundColor = getColorV8('neutralHue', 400, props.theme);
|
|
23
|
+
} else if (props.isDanger) {
|
|
24
|
+
foregroundColor = getColorV8('dangerHue', 600, props.theme);
|
|
25
|
+
backgroundColor = props.isFocused ? rgba(foregroundColor, 0.08) : 'inherit';
|
|
26
|
+
} else {
|
|
27
|
+
foregroundColor = getColorV8('foreground', 600 , props.theme);
|
|
28
|
+
backgroundColor = props.isFocused ? getColorV8('primaryHue', 600, props.theme, 0.08) : 'inherit';
|
|
29
|
+
}
|
|
30
|
+
return css(["background-color:", ";color:", ";& a,& a:hover,& a:focus,& a:active{color:inherit;}"], backgroundColor, foregroundColor);
|
|
31
|
+
};
|
|
32
|
+
const StyledItem = styled.li.attrs(props => ({
|
|
33
|
+
'data-garden-id': COMPONENT_ID,
|
|
34
|
+
'data-garden-version': '9.0.0-next.9',
|
|
35
|
+
'aria-disabled': props.disabled
|
|
36
|
+
})).withConfig({
|
|
37
|
+
displayName: "StyledItem",
|
|
38
|
+
componentId: "sc-x4h8aw-0"
|
|
39
|
+
})(["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, props));
|
|
40
|
+
StyledItem.defaultProps = {
|
|
41
|
+
theme: DEFAULT_THEME
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export { StyledItem, getItemPaddingVertical };
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
import styled, { css } from 'styled-components';
|
|
8
|
+
import { math } from 'polished';
|
|
9
|
+
import { getColorV8, DEFAULT_THEME } from '@zendeskgarden/react-theming';
|
|
10
|
+
import { getItemPaddingVertical } from './StyledItem.js';
|
|
11
|
+
|
|
12
|
+
const COMPONENT_ID = 'dropdowns.item_icon';
|
|
13
|
+
const getSizeStyles = props => {
|
|
14
|
+
return css(["width:", ";height:calc(", "px + ", ");"], props.theme.iconSizes.md, props.theme.space.base * 5, math(`${getItemPaddingVertical(props)} * 2`));
|
|
15
|
+
};
|
|
16
|
+
const StyledItemIcon = styled.div.attrs({
|
|
17
|
+
'data-garden-id': COMPONENT_ID,
|
|
18
|
+
'data-garden-version': '9.0.0-next.9'
|
|
19
|
+
}).withConfig({
|
|
20
|
+
displayName: "StyledItemIcon",
|
|
21
|
+
componentId: "sc-pspm80-0"
|
|
22
|
+
})(["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);
|
|
23
|
+
StyledItemIcon.defaultProps = {
|
|
24
|
+
theme: DEFAULT_THEME
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export { StyledItemIcon };
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
import styled from 'styled-components';
|
|
8
|
+
import { getColorV8, retrieveComponentStyles, DEFAULT_THEME } from '@zendeskgarden/react-theming';
|
|
9
|
+
|
|
10
|
+
const COMPONENT_ID = 'dropdowns.item_meta';
|
|
11
|
+
const StyledItemMeta = styled.span.attrs({
|
|
12
|
+
'data-garden-id': COMPONENT_ID,
|
|
13
|
+
'data-garden-version': '9.0.0-next.9'
|
|
14
|
+
}).withConfig({
|
|
15
|
+
displayName: "StyledItemMeta",
|
|
16
|
+
componentId: "sc-1m3x8m1-0"
|
|
17
|
+
})(["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, props));
|
|
18
|
+
StyledItemMeta.defaultProps = {
|
|
19
|
+
theme: DEFAULT_THEME
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { StyledItemMeta };
|