@redsift/design-system-legacy 8.0.1 → 8.0.2
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/package.json +3 -2
- package/dist/package.json +0 -65
- package/rollup.config.js +0 -70
- package/src/components/Alert/Alert.jsx +0 -94
- package/src/components/Alert/index.ts +0 -1
- package/src/components/Alert/readme.md +0 -114
- package/src/components/Button/Button.jsx +0 -161
- package/src/components/Button/index.ts +0 -1
- package/src/components/Button/readme.md +0 -173
- package/src/components/Card/Card.jsx +0 -34
- package/src/components/Card/index.ts +0 -1
- package/src/components/Card/readme.md +0 -54
- package/src/components/CardHeader/CardHeader.jsx +0 -40
- package/src/components/CardHeader/index.ts +0 -1
- package/src/components/Checkbox/Checkbox.jsx +0 -123
- package/src/components/Checkbox/index.ts +0 -1
- package/src/components/Checkbox/readme.md +0 -54
- package/src/components/CheckboxTree/CheckboxTree.jsx +0 -167
- package/src/components/CheckboxTree/CheckboxTree.styles.ts +0 -49
- package/src/components/CheckboxTree/index.ts +0 -1
- package/src/components/CheckboxTree/readme.md +0 -60
- package/src/components/IconContainer/IconContainer.jsx +0 -51
- package/src/components/IconContainer/index.ts +0 -1
- package/src/components/Input/Input.jsx +0 -27
- package/src/components/Input/OutlineInput/OutlineInput.jsx +0 -188
- package/src/components/Input/RegularInput/RegularInput.jsx +0 -55
- package/src/components/Input/RegularInput/RegularInput.styles.ts +0 -98
- package/src/components/Input/index.ts +0 -1
- package/src/components/Input/readme.md +0 -82
- package/src/components/Pagination/Pagination.jsx +0 -111
- package/src/components/Pagination/index.ts +0 -1
- package/src/components/Pagination/readme.md +0 -34
- package/src/components/Radio/Radio.jsx +0 -121
- package/src/components/Radio/index.ts +0 -1
- package/src/components/Radio/readme.md +0 -90
- package/src/components/Select/Select.jsx +0 -360
- package/src/components/Select/SelectComponents.jsx +0 -342
- package/src/components/Select/index.ts +0 -1
- package/src/components/Select/readme.md +0 -2507
- package/src/components/Switch/Switch.jsx +0 -130
- package/src/components/Switch/index.ts +0 -1
- package/src/components/Switch/readme.md +0 -55
- package/src/components/Table/ExportCSVButton.jsx +0 -34
- package/src/components/Table/Table.jsx +0 -872
- package/src/components/Table/TableComponents.jsx +0 -239
- package/src/components/Table/TableFilters.jsx +0 -23
- package/src/components/Table/TableStyles.jsx +0 -514
- package/src/components/Table/index.ts +0 -1
- package/src/components/Table/readme.md +0 -2190
- package/src/components/Tabs/Tabs.jsx +0 -116
- package/src/components/Tabs/TabsComponents.jsx +0 -124
- package/src/components/Tabs/index.ts +0 -1
- package/src/components/Tabs/readme.md +0 -171
- package/src/components/Typography/Typography.jsx +0 -77
- package/src/components/Typography/index.ts +0 -1
- package/src/components/Typography/readme.md +0 -88
- package/src/components/icons/ActionsIcon.jsx +0 -24
- package/src/components/icons/AddIcon.jsx +0 -8
- package/src/components/icons/Arrow.jsx +0 -39
- package/src/components/icons/ArrowDown.jsx +0 -8
- package/src/components/icons/ArrowIcon.jsx +0 -25
- package/src/components/icons/ArrowUp.jsx +0 -8
- package/src/components/icons/BarchartHorizontal.jsx +0 -18
- package/src/components/icons/BellIcon.jsx +0 -19
- package/src/components/icons/BimiSetupIcon.jsx +0 -25
- package/src/components/icons/Chevron.jsx +0 -42
- package/src/components/icons/ChevronLeft.jsx +0 -8
- package/src/components/icons/ChevronRight.jsx +0 -8
- package/src/components/icons/ClearIcon.jsx +0 -8
- package/src/components/icons/Cloud.jsx +0 -34
- package/src/components/icons/Cross.jsx +0 -25
- package/src/components/icons/DeleteIcon.jsx +0 -19
- package/src/components/icons/DynamicDmarcIcon.jsx +0 -43
- package/src/components/icons/EditOutline.jsx +0 -8
- package/src/components/icons/Email.jsx +0 -68
- package/src/components/icons/EmailSourcesIcon.jsx +0 -36
- package/src/components/icons/ExpandLayoutIcon.jsx +0 -38
- package/src/components/icons/ExportIcon.jsx +0 -7
- package/src/components/icons/Eye.jsx +0 -28
- package/src/components/icons/Facebook.jsx +0 -31
- package/src/components/icons/FilterList.jsx +0 -8
- package/src/components/icons/FindOutHowIcon.jsx +0 -49
- package/src/components/icons/FlatArrow.jsx +0 -33
- package/src/components/icons/ForwardArrowIcon.jsx +0 -54
- package/src/components/icons/Github.jsx +0 -41
- package/src/components/icons/Globe.jsx +0 -29
- package/src/components/icons/Hand.jsx +0 -21
- package/src/components/icons/InfinityLoop.jsx +0 -22
- package/src/components/icons/InfinityLoopBreak.jsx +0 -35
- package/src/components/icons/IngrainIcon.jsx +0 -33
- package/src/components/icons/LanguageIcon.jsx +0 -44
- package/src/components/icons/Linkedin.jsx +0 -37
- package/src/components/icons/LocationPin.jsx +0 -34
- package/src/components/icons/MicrosoftShield.jsx +0 -44
- package/src/components/icons/News.jsx +0 -65
- package/src/components/icons/Nodes.jsx +0 -17
- package/src/components/icons/OnDmarcIcon.jsx +0 -29
- package/src/components/icons/OnDmarcLogo.jsx +0 -74
- package/src/components/icons/OnDomainIcon.jsx +0 -27
- package/src/components/icons/OnInboxIcon.jsx +0 -42
- package/src/components/icons/OnInboxLogo.jsx +0 -97
- package/src/components/icons/OnInboxManagerIcon.jsx +0 -46
- package/src/components/icons/OpenInNewTabIcon.jsx +0 -28
- package/src/components/icons/Padlock.jsx +0 -37
- package/src/components/icons/PlusIcon.jsx +0 -16
- package/src/components/icons/Question.jsx +0 -19
- package/src/components/icons/Recruiting.jsx +0 -34
- package/src/components/icons/ReportsIcon.jsx +0 -25
- package/src/components/icons/SearchIcon.jsx +0 -7
- package/src/components/icons/Shield.jsx +0 -17
- package/src/components/icons/ShieldPassIcon.jsx +0 -23
- package/src/components/icons/ShieldSolid.jsx +0 -33
- package/src/components/icons/ShieldWarningIcon.jsx +0 -40
- package/src/components/icons/ShieldWarningInvertedIcon.jsx +0 -36
- package/src/components/icons/Spinner.jsx +0 -100
- package/src/components/icons/Team.jsx +0 -164
- package/src/components/icons/ThreeDotsIcon.jsx +0 -18
- package/src/components/icons/Thumb.jsx +0 -17
- package/src/components/icons/Traffic.jsx +0 -22
- package/src/components/icons/Twitter.jsx +0 -47
- package/src/components/icons/Upload.jsx +0 -12
- package/src/components/icons/VerticalDots.jsx +0 -28
- package/src/components/icons/Warning.jsx +0 -36
- package/src/components/icons/WarningTriangle.jsx +0 -44
- package/src/components/icons/Youtube.jsx +0 -28
- package/src/components/icons/index.ts +0 -69
- package/src/hooks/useDebouncedValue.jsx +0 -19
- package/src/hooks/useFetch.jsx +0 -26
- package/src/hooks/useIsMobile.jsx +0 -25
- package/src/hooks/useOnClickOutside.jsx +0 -14
- package/src/hooks/useToggle.jsx +0 -8
- package/src/index.ts +0 -23
- package/tsconfig.json +0 -3
- /package/{dist/CONTRIBUTING.md → CONTRIBUTING.md} +0 -0
- /package/{dist/index.js → index.js} +0 -0
- /package/{dist/index.js.map → index.js.map} +0 -0
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
### Accessibility
|
|
2
|
-
|
|
3
|
-
- Ensure label is provided
|
|
4
|
-
|
|
5
|
-
### Props
|
|
6
|
-
|
|
7
|
-
| Prop | Default | Options |
|
|
8
|
-
| :------------: | :-----------------: | -----------------------------------------------: |
|
|
9
|
-
| name | | required for grouping the radio buttons together |
|
|
10
|
-
| color | '#000' | Color |
|
|
11
|
-
| borderColor | rgba(0, 0, 0 , .54) | Color |
|
|
12
|
-
| label | | string |
|
|
13
|
-
| checked | false | true, false |
|
|
14
|
-
| defaultChecked | false | true, false |
|
|
15
|
-
| disabled | false | true, false |
|
|
16
|
-
| onChange | | Function |
|
|
17
|
-
| checkProps | | Passes props to the Check Indicator |
|
|
18
|
-
| inputProps | | Passes props to the Input |
|
|
19
|
-
| ...rest | | Passes props to the Wrapper |
|
|
20
|
-
|
|
21
|
-
### Examples
|
|
22
|
-
|
|
23
|
-
```js
|
|
24
|
-
<div
|
|
25
|
-
style={{
|
|
26
|
-
display: "flex",
|
|
27
|
-
flexWrap: "wrap",
|
|
28
|
-
flexDirection: "row",
|
|
29
|
-
alignItems: "center",
|
|
30
|
-
justifyContent: "space-evenly"
|
|
31
|
-
}}
|
|
32
|
-
>
|
|
33
|
-
<Radio
|
|
34
|
-
name="ondmarc"
|
|
35
|
-
color="#02ac61"
|
|
36
|
-
borderColor="#02ac61"
|
|
37
|
-
label="OnDMARC 1"
|
|
38
|
-
/>
|
|
39
|
-
<Radio
|
|
40
|
-
name="ondmarc"
|
|
41
|
-
color="#02ac61"
|
|
42
|
-
borderColor="#02ac61"
|
|
43
|
-
label="OnDMARC 2"
|
|
44
|
-
defaultChecked
|
|
45
|
-
/>
|
|
46
|
-
<Radio
|
|
47
|
-
name="oninbox"
|
|
48
|
-
color="#33b222"
|
|
49
|
-
borderColor="#33b222"
|
|
50
|
-
label="OnINBOX 1"
|
|
51
|
-
/>
|
|
52
|
-
<Radio
|
|
53
|
-
name="oninbox"
|
|
54
|
-
color="#33b222"
|
|
55
|
-
borderColor="#33b222"
|
|
56
|
-
label="OnINBOX 2"
|
|
57
|
-
defaultChecked
|
|
58
|
-
/>
|
|
59
|
-
<Radio
|
|
60
|
-
name="ingrain"
|
|
61
|
-
color="#53C3EB"
|
|
62
|
-
borderColor="#53C3EB"
|
|
63
|
-
label="InGRAIN 1"
|
|
64
|
-
/>
|
|
65
|
-
<Radio
|
|
66
|
-
name="ingrain"
|
|
67
|
-
color="#53C3EB"
|
|
68
|
-
borderColor="#53C3EB"
|
|
69
|
-
label="InGRAIN 2"
|
|
70
|
-
defaultChecked
|
|
71
|
-
/>
|
|
72
|
-
</div>
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
```js
|
|
76
|
-
<div
|
|
77
|
-
style={{
|
|
78
|
-
display: "flex",
|
|
79
|
-
flexWrap: "wrap",
|
|
80
|
-
flexDirection: "row",
|
|
81
|
-
alignItems: "center",
|
|
82
|
-
justifyContent: "space-evenly"
|
|
83
|
-
}}
|
|
84
|
-
>
|
|
85
|
-
<Radio name="default" label="Default 1" />
|
|
86
|
-
<Radio name="default" label="Default 2" defaultChecked />
|
|
87
|
-
<Radio name="disabled" label="Disabled 1" disabled />
|
|
88
|
-
<Radio name="disabled" label="Disabled 2" disabled defaultChecked />
|
|
89
|
-
</div>
|
|
90
|
-
```
|
|
@@ -1,360 +0,0 @@
|
|
|
1
|
-
import React, { createRef, useState, useEffect, useRef } from 'react';
|
|
2
|
-
import { useOnClickOutside } from '../../hooks/useOnClickOutside';
|
|
3
|
-
import { FlatArrow } from '../icons';
|
|
4
|
-
import {
|
|
5
|
-
colors,
|
|
6
|
-
IconAndTextContainer,
|
|
7
|
-
IconAndSelectedValueRenderContainer,
|
|
8
|
-
SelectOuterContainer,
|
|
9
|
-
SelectContainer,
|
|
10
|
-
SelectLegendText,
|
|
11
|
-
SelectValueContainer,
|
|
12
|
-
SelectedValueText,
|
|
13
|
-
SelectSearchTextInput,
|
|
14
|
-
OptionsContainerWindowedComponent,
|
|
15
|
-
OptionsContainerComponent,
|
|
16
|
-
} from "./SelectComponents";
|
|
17
|
-
|
|
18
|
-
const WINDOWED_ITEM_SIZE = 40;
|
|
19
|
-
const WINDOWED_MAX_HEIGHT = 400;
|
|
20
|
-
const USE_WINDOWED_SELECT_THRESHOLD = 500;
|
|
21
|
-
|
|
22
|
-
const selectedText = (options, selected, defaultValue) => {
|
|
23
|
-
if (selected) {
|
|
24
|
-
const { label, value } = selected;
|
|
25
|
-
return !label ? value : typeof label === "string" ? label : label(value);
|
|
26
|
-
}
|
|
27
|
-
if (!selected && defaultValue) {
|
|
28
|
-
const item = options.find((i) => i.value === defaultValue);
|
|
29
|
-
return item && item.label ? item.label : defaultValue;
|
|
30
|
-
}
|
|
31
|
-
return null;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export const Select = ({
|
|
35
|
-
disabled,
|
|
36
|
-
icon,
|
|
37
|
-
id,
|
|
38
|
-
isSearchable,
|
|
39
|
-
label,
|
|
40
|
-
onChange = () => {},
|
|
41
|
-
options = [],
|
|
42
|
-
tintColor = "#000",
|
|
43
|
-
useWindowed = false,
|
|
44
|
-
value,
|
|
45
|
-
variant = "outlined",
|
|
46
|
-
...rest
|
|
47
|
-
}) => {
|
|
48
|
-
const isMinimal = variant === "minimal";
|
|
49
|
-
const isBasic = variant === "basic";
|
|
50
|
-
const [selectedIndex, setSelectedIndex] = useState(-1);
|
|
51
|
-
const selectOptionIndex = (index) => {
|
|
52
|
-
if (disabled || !options[index] || options[index].disabled) return;
|
|
53
|
-
setSelectedIndex(index);
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const [isOptionVisibleForIndex, setIsOptionVisibleForIndex] = useState(
|
|
57
|
-
options.map(() => true)
|
|
58
|
-
);
|
|
59
|
-
const [displayOptions, setDisplayOptions] = useState(false);
|
|
60
|
-
const outsideClickRef = useOnClickOutside(() => setDisplayOptions(false));
|
|
61
|
-
|
|
62
|
-
const optionRefs = useRef([]);
|
|
63
|
-
const selectedOption = options[selectedIndex];
|
|
64
|
-
|
|
65
|
-
const [searchInputRef, setSearchInput] = useState(null);
|
|
66
|
-
const [search, setSearch] = useState("");
|
|
67
|
-
|
|
68
|
-
const [focusInputRef, setFocusInput] = useState(null);
|
|
69
|
-
const selectWindowedRef = React.createRef();
|
|
70
|
-
|
|
71
|
-
useEffect(() => {
|
|
72
|
-
if (displayOptions) {
|
|
73
|
-
setIsOptionVisibleForIndex(options.map(() => true));
|
|
74
|
-
}
|
|
75
|
-
if (
|
|
76
|
-
selectedIndex > -1 &&
|
|
77
|
-
(!options[selectedIndex] || options[selectedIndex].disabled)
|
|
78
|
-
) {
|
|
79
|
-
setSelectedIndex(-1);
|
|
80
|
-
}
|
|
81
|
-
}, [displayOptions, options]);
|
|
82
|
-
|
|
83
|
-
useEffect(() => {
|
|
84
|
-
if (!isSearchable || !searchInputRef) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
const setSearchResults = () => {
|
|
88
|
-
const searchResults = options.map((option) => {
|
|
89
|
-
const { value, label } = option;
|
|
90
|
-
const text = typeof label === "string" ? label : value;
|
|
91
|
-
return !search || text.toLowerCase().startsWith(search.toLowerCase());
|
|
92
|
-
});
|
|
93
|
-
setIsOptionVisibleForIndex(searchResults);
|
|
94
|
-
};
|
|
95
|
-
const handleKeyUp = () => {
|
|
96
|
-
setSearchResults();
|
|
97
|
-
};
|
|
98
|
-
const handleKeyDown = (e) => {
|
|
99
|
-
if (
|
|
100
|
-
e.keyCode === 13 || // enter
|
|
101
|
-
e.keyCode === 40 || // down arrow
|
|
102
|
-
(e.keyCode === 9 && !e.shiftKey) // tab without shift
|
|
103
|
-
) {
|
|
104
|
-
e.preventDefault();
|
|
105
|
-
const firstEnabledOptionIndex = isOptionVisibleForIndex.findIndex(
|
|
106
|
-
(i) => i
|
|
107
|
-
);
|
|
108
|
-
if (e.keyCode === 13) {
|
|
109
|
-
searchInputRef.blur();
|
|
110
|
-
selectOptionIndex(firstEnabledOptionIndex);
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
optionRefs.current[firstEnabledOptionIndex].current.focus();
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
searchInputRef.addEventListener("keyup", handleKeyUp);
|
|
117
|
-
searchInputRef.addEventListener("keydown", handleKeyDown);
|
|
118
|
-
return () => {
|
|
119
|
-
searchInputRef.removeEventListener("keyup", handleKeyUp);
|
|
120
|
-
searchInputRef.removeEventListener("keydown", handleKeyDown);
|
|
121
|
-
};
|
|
122
|
-
}, [searchInputRef, isOptionVisibleForIndex, options, isSearchable, search]);
|
|
123
|
-
|
|
124
|
-
// keyboard focus only
|
|
125
|
-
useEffect(() => {
|
|
126
|
-
if (focusInputRef === null) {
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
const handleKeyPress = (e) => {
|
|
130
|
-
//TODO: accessibility: when up/down is pressed, the 'focused' item should be the top/bottom item in the options list, and not always the top item
|
|
131
|
-
// up
|
|
132
|
-
if (e.keyCode === 38) {
|
|
133
|
-
e.preventDefault();
|
|
134
|
-
setDisplayOptions(true);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// down
|
|
138
|
-
if (e.keyCode === 40) {
|
|
139
|
-
e.preventDefault();
|
|
140
|
-
setDisplayOptions(true);
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
focusInputRef.addEventListener("keydown", handleKeyPress);
|
|
144
|
-
return () => {
|
|
145
|
-
focusInputRef.removeEventListener("keydown", handleKeyPress);
|
|
146
|
-
};
|
|
147
|
-
}, [focusInputRef, options, selectedOption]);
|
|
148
|
-
|
|
149
|
-
useEffect(() => {
|
|
150
|
-
// pass the selected value to parent component
|
|
151
|
-
if (selectedIndex >= 0 && onChange) {
|
|
152
|
-
onChange(options[selectedIndex].value);
|
|
153
|
-
}
|
|
154
|
-
}, [selectedIndex]);
|
|
155
|
-
|
|
156
|
-
useEffect(() => {
|
|
157
|
-
// if value is defined (null is still a valid value)
|
|
158
|
-
// and we still don't have a selected index or the value is different
|
|
159
|
-
// let's update internal state's selectedIndex
|
|
160
|
-
if (
|
|
161
|
-
value !== undefined &&
|
|
162
|
-
(selectedIndex === -1 ||
|
|
163
|
-
value !== (options[selectedIndex] && options[selectedIndex].value))
|
|
164
|
-
) {
|
|
165
|
-
selectOptionIndex(options.findIndex((opt) => opt.value === value));
|
|
166
|
-
}
|
|
167
|
-
}, [value]);
|
|
168
|
-
|
|
169
|
-
useEffect(() => {
|
|
170
|
-
if (options.length !== optionRefs.current.length) {
|
|
171
|
-
optionRefs.current = options.map(
|
|
172
|
-
(_, idx) => optionRefs.current[idx] || createRef()
|
|
173
|
-
);
|
|
174
|
-
}
|
|
175
|
-
}, [options]);
|
|
176
|
-
|
|
177
|
-
// option selection and event listeners
|
|
178
|
-
useEffect(() => {
|
|
179
|
-
if (
|
|
180
|
-
displayOptions &&
|
|
181
|
-
// if we still have no reference, wait until the next cycle
|
|
182
|
-
(!isSearchable || searchInputRef !== null)
|
|
183
|
-
) {
|
|
184
|
-
const evtListenersToUnmount = [];
|
|
185
|
-
if (isSearchable) {
|
|
186
|
-
searchInputRef.focus();
|
|
187
|
-
} else {
|
|
188
|
-
optionRefs.current[
|
|
189
|
-
// select first visible
|
|
190
|
-
isOptionVisibleForIndex.findIndex((i) => i)
|
|
191
|
-
].current.focus();
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
// attach keyboard events:
|
|
195
|
-
optionRefs.current.forEach((ref, idx) => {
|
|
196
|
-
const evtListener = (e) => {
|
|
197
|
-
e.preventDefault();
|
|
198
|
-
// down arrow or tab without shift
|
|
199
|
-
if (e.keyCode === 40 || (e.keyCode === 9 && !e.shiftKey)) {
|
|
200
|
-
const nextAvailableIndex = isOptionVisibleForIndex.findIndex(
|
|
201
|
-
(isOptionVisible, itemIdx) =>
|
|
202
|
-
isOptionVisible && !options[itemIdx].disabled && itemIdx > idx
|
|
203
|
-
);
|
|
204
|
-
optionRefs.current[
|
|
205
|
-
nextAvailableIndex >= 0
|
|
206
|
-
? nextAvailableIndex
|
|
207
|
-
: optionRefs.current.length - 1
|
|
208
|
-
].current.focus({ preventScroll: true });
|
|
209
|
-
// up arrow or tab with shift
|
|
210
|
-
} else if (e.keyCode === 38 || (e.keyCode === 9 && e.shiftKey)) {
|
|
211
|
-
const previousAvailableIndex = isOptionVisibleForIndex.reduce(
|
|
212
|
-
(previousIndex, isOptionEnabled, itemIndex) => {
|
|
213
|
-
return !isOptionEnabled ||
|
|
214
|
-
options[itemIndex].disabled ||
|
|
215
|
-
itemIndex >= idx
|
|
216
|
-
? previousIndex
|
|
217
|
-
: itemIndex;
|
|
218
|
-
},
|
|
219
|
-
-1
|
|
220
|
-
);
|
|
221
|
-
optionRefs.current[
|
|
222
|
-
previousAvailableIndex >= 0 ? previousAvailableIndex : 0
|
|
223
|
-
].current.focus({
|
|
224
|
-
preventScroll: true,
|
|
225
|
-
});
|
|
226
|
-
// space space enter
|
|
227
|
-
} else if ([0, 32, 13].includes(e.keyCode)) {
|
|
228
|
-
optionRefs.current[idx].current.click();
|
|
229
|
-
} else if (e.keyCode === 27) {
|
|
230
|
-
setDisplayOptions(false);
|
|
231
|
-
}
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
// ref.current is lost if an option unmounts
|
|
235
|
-
ref.current && ref.current.addEventListener("keydown", evtListener);
|
|
236
|
-
evtListenersToUnmount.push(
|
|
237
|
-
() =>
|
|
238
|
-
ref.current &&
|
|
239
|
-
ref.current.removeEventListener("keydown", evtListener)
|
|
240
|
-
);
|
|
241
|
-
});
|
|
242
|
-
if (evtListenersToUnmount.length) {
|
|
243
|
-
return () => evtListenersToUnmount.forEach((unmount) => unmount());
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}, [displayOptions, searchInputRef, isOptionVisibleForIndex, isSearchable]);
|
|
247
|
-
|
|
248
|
-
const textColor =
|
|
249
|
-
displayOptions || isMinimal
|
|
250
|
-
? tintColor
|
|
251
|
-
: disabled
|
|
252
|
-
? colors.darkMidGrey
|
|
253
|
-
: colors.darkGrey;
|
|
254
|
-
|
|
255
|
-
const visibleItems = options.filter(
|
|
256
|
-
(_, index) => isOptionVisibleForIndex[index]
|
|
257
|
-
);
|
|
258
|
-
|
|
259
|
-
const countVisibleItems = visibleItems.length;
|
|
260
|
-
const useSelectWindowed =
|
|
261
|
-
useWindowed || options.length > USE_WINDOWED_SELECT_THRESHOLD;
|
|
262
|
-
const selectWindowedHeight = Math.floor(
|
|
263
|
-
Math.min(countVisibleItems * WINDOWED_ITEM_SIZE, WINDOWED_MAX_HEIGHT)
|
|
264
|
-
);
|
|
265
|
-
|
|
266
|
-
const optionsContainerProps = {
|
|
267
|
-
selectWindowedRef,
|
|
268
|
-
selectWindowedHeight,
|
|
269
|
-
visibleItems,
|
|
270
|
-
displayOptions,
|
|
271
|
-
disabled,
|
|
272
|
-
selectedIndex,
|
|
273
|
-
selectOptionIndex,
|
|
274
|
-
optionRefs,
|
|
275
|
-
options,
|
|
276
|
-
isOptionVisibleForIndex,
|
|
277
|
-
itemSize: WINDOWED_ITEM_SIZE,
|
|
278
|
-
};
|
|
279
|
-
|
|
280
|
-
const OptionsContainer = useSelectWindowed
|
|
281
|
-
? OptionsContainerWindowedComponent
|
|
282
|
-
: OptionsContainerComponent;
|
|
283
|
-
|
|
284
|
-
return (
|
|
285
|
-
<SelectOuterContainer
|
|
286
|
-
ref={outsideClickRef}
|
|
287
|
-
onClick={() =>
|
|
288
|
-
!disabled && setDisplayOptions((displayOptions) => !displayOptions)
|
|
289
|
-
}
|
|
290
|
-
{...rest}
|
|
291
|
-
>
|
|
292
|
-
<SelectContainer
|
|
293
|
-
variant={variant}
|
|
294
|
-
color={
|
|
295
|
-
isMinimal || isBasic || displayOptions ? tintColor : colors.midGrey
|
|
296
|
-
}
|
|
297
|
-
disabled={disabled}
|
|
298
|
-
>
|
|
299
|
-
{!isMinimal && (
|
|
300
|
-
<legend>
|
|
301
|
-
<SelectLegendText id={id} color={textColor}>
|
|
302
|
-
{label}
|
|
303
|
-
</SelectLegendText>
|
|
304
|
-
</legend>
|
|
305
|
-
)}
|
|
306
|
-
<IconAndTextContainer>
|
|
307
|
-
<SelectValueContainer
|
|
308
|
-
tabIndex="0"
|
|
309
|
-
aria-haspopup="listbox"
|
|
310
|
-
role="listbox"
|
|
311
|
-
aria-labelledby={`dropdown_${id} dropdown_${id}_button`}
|
|
312
|
-
onKeyPress={(e) => {
|
|
313
|
-
if (!disabled && e.charCode === 13) {
|
|
314
|
-
e.preventDefault();
|
|
315
|
-
setDisplayOptions((displayOptions) => !displayOptions);
|
|
316
|
-
}
|
|
317
|
-
}}
|
|
318
|
-
ref={setFocusInput}
|
|
319
|
-
>
|
|
320
|
-
{!displayOptions || isSearchable || isMinimal ? (
|
|
321
|
-
<IconAndSelectedValueRenderContainer>
|
|
322
|
-
{icon}
|
|
323
|
-
{displayOptions && isSearchable ? (
|
|
324
|
-
<SelectSearchTextInput
|
|
325
|
-
withIcon={!!icon}
|
|
326
|
-
value={search}
|
|
327
|
-
placeholder={
|
|
328
|
-
selectedOption
|
|
329
|
-
? typeof selectedOption.label === "string"
|
|
330
|
-
? selectedOption.label
|
|
331
|
-
: selectedOption.value
|
|
332
|
-
: ""
|
|
333
|
-
}
|
|
334
|
-
onChange={(evt) => !disabled && setSearch(evt.target.value)}
|
|
335
|
-
ref={setSearchInput}
|
|
336
|
-
/>
|
|
337
|
-
) : (
|
|
338
|
-
<SelectedValueText
|
|
339
|
-
withIcon={!!icon}
|
|
340
|
-
disabled={disabled}
|
|
341
|
-
color={isMinimal ? tintColor : undefined}
|
|
342
|
-
>
|
|
343
|
-
{selectedText(options, selectedOption, value)}
|
|
344
|
-
</SelectedValueText>
|
|
345
|
-
)}
|
|
346
|
-
</IconAndSelectedValueRenderContainer>
|
|
347
|
-
) : null}
|
|
348
|
-
</SelectValueContainer>
|
|
349
|
-
<FlatArrow
|
|
350
|
-
width={9}
|
|
351
|
-
direction={displayOptions ? "up" : "down"}
|
|
352
|
-
fill={textColor}
|
|
353
|
-
title="Open drop down"
|
|
354
|
-
/>
|
|
355
|
-
</IconAndTextContainer>
|
|
356
|
-
</SelectContainer>
|
|
357
|
-
<OptionsContainer {...optionsContainerProps} />
|
|
358
|
-
</SelectOuterContainer>
|
|
359
|
-
);
|
|
360
|
-
};
|