@zohodesk/components 1.2.4 → 1.2.6
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/README.md +8 -0
- package/coverage/Button/Button.js.html +1 -1
- package/coverage/Button/css/Button.module.css.html +1 -1
- package/coverage/Button/css/cssJSLogic.js.html +1 -1
- package/coverage/Button/css/index.html +1 -1
- package/coverage/Button/index.html +1 -1
- package/coverage/Button/props/defaultProps.js.html +1 -1
- package/coverage/Button/props/index.html +1 -1
- package/coverage/Button/props/propTypes.js.html +1 -1
- package/coverage/Buttongroup/Buttongroup.js.html +1 -1
- package/coverage/Buttongroup/Buttongroup.module.css.html +1 -1
- package/coverage/Buttongroup/index.html +1 -1
- package/coverage/Buttongroup/props/defaultProps.js.html +1 -1
- package/coverage/Buttongroup/props/index.html +1 -1
- package/coverage/Buttongroup/props/propTypes.js.html +1 -1
- package/coverage/index.html +1 -1
- package/coverage/utils/dummyFunction.js.html +1 -1
- package/coverage/utils/index.html +1 -1
- package/es/AppContainer/AppContainer.js +3 -0
- package/es/v1/Accordion/Accordion.js +65 -0
- package/es/v1/Accordion/AccordionItem.js +57 -0
- package/es/v1/Accordion/index.js +2 -0
- package/es/v1/Animation/Animation.js +127 -0
- package/es/v1/AppContainer/AppContainer.js +137 -0
- package/es/v1/Avatar/Avatar.js +189 -0
- package/es/v1/AvatarTeam/AvatarTeam.js +70 -0
- package/es/v1/Button/Button.js +68 -0
- package/es/v1/Buttongroup/Buttongroup.js +31 -0
- package/es/v1/Card/Card.js +271 -0
- package/es/v1/CheckBox/CheckBox.js +155 -0
- package/es/v1/DateTime/CalendarView.js +218 -0
- package/es/v1/DateTime/DateTime.js +783 -0
- package/es/v1/DateTime/DateTimePopupFooter.js +47 -0
- package/es/v1/DateTime/DateTimePopupHeader.js +105 -0
- package/es/v1/DateTime/DateWidget.js +1098 -0
- package/es/v1/DateTime/DaysRow.js +31 -0
- package/es/v1/DateTime/Time.js +166 -0
- package/es/v1/DateTime/YearView.js +264 -0
- package/es/v1/DateTime/index.js +1 -0
- package/es/v1/DropBox/DropBox.js +91 -0
- package/es/v1/DropBox/DropBoxElement/DropBoxElement.js +132 -0
- package/es/v1/DropDown/DropDown.js +73 -0
- package/es/v1/DropDown/DropDownHeading.js +44 -0
- package/es/v1/DropDown/DropDownItem.js +76 -0
- package/es/v1/DropDown/DropDownSearch.js +63 -0
- package/es/v1/DropDown/DropDownSeparator.js +15 -0
- package/es/v1/Heading/Heading.js +32 -0
- package/es/v1/Label/Label.js +40 -0
- package/es/v1/Layout/Box.js +115 -0
- package/es/v1/Layout/Container.js +132 -0
- package/es/v1/Layout/index.js +2 -0
- package/es/v1/ListItem/ListContainer.js +102 -0
- package/es/v1/ListItem/ListItem.js +124 -0
- package/es/v1/ListItem/ListItemWithAvatar.js +145 -0
- package/es/v1/ListItem/ListItemWithCheckBox.js +104 -0
- package/es/v1/ListItem/ListItemWithIcon.js +127 -0
- package/es/v1/ListItem/ListItemWithRadio.js +105 -0
- package/es/v1/ListItem/index.js +6 -0
- package/es/v1/Modal/Modal.js +154 -0
- package/es/v1/MultiSelect/AdvancedGroupMultiSelect.js +1079 -0
- package/es/v1/MultiSelect/AdvancedMultiSelect.js +568 -0
- package/es/v1/MultiSelect/EmptyState.js +64 -0
- package/es/v1/MultiSelect/MobileHeader/MobileHeader.js +50 -0
- package/es/v1/MultiSelect/MultiSelect.js +1120 -0
- package/es/v1/MultiSelect/MultiSelectHeader.js +32 -0
- package/es/v1/MultiSelect/MultiSelectWithAvatar.js +216 -0
- package/es/v1/MultiSelect/SelectedOptions.js +82 -0
- package/es/v1/MultiSelect/Suggestions.js +142 -0
- package/es/v1/MultiSelect/index.js +4 -0
- package/es/v1/PopOver/PopOver.js +211 -0
- package/es/v1/Popup/Popup.js +645 -0
- package/es/v1/Radio/Radio.js +115 -0
- package/es/v1/Responsive/CustomResponsive.js +195 -0
- package/es/v1/Responsive/RefWrapper.js +39 -0
- package/es/v1/Responsive/ResizeComponent.js +197 -0
- package/es/v1/Responsive/ResizeObserver.js +140 -0
- package/es/v1/Responsive/Responsive.js +194 -0
- package/es/v1/Responsive/index.js +9 -0
- package/es/v1/ResponsiveDropBox/ResponsiveDropBox.js +58 -0
- package/es/v1/Ribbon/Ribbon.js +33 -0
- package/es/v1/RippleEffect/RippleEffect.js +24 -0
- package/es/v1/Select/GroupSelect.js +803 -0
- package/es/v1/Select/Select.js +969 -0
- package/es/v1/Select/SelectWithAvatar.js +344 -0
- package/es/v1/Select/SelectWithIcon.js +535 -0
- package/es/v1/Select/index.js +4 -0
- package/es/v1/Stencils/Stencils.js +26 -0
- package/es/v1/Switch/Switch.js +94 -0
- package/es/v1/Tab/Tab.js +108 -0
- package/es/v1/Tab/TabContent.js +30 -0
- package/es/v1/Tab/TabContentWrapper.js +29 -0
- package/es/v1/Tab/TabWrapper.js +57 -0
- package/es/v1/Tab/Tabs.js +612 -0
- package/es/v1/Tab/index.js +5 -0
- package/es/v1/Tag/Tag.js +134 -0
- package/es/v1/TextBox/TextBox.js +154 -0
- package/es/v1/TextBoxIcon/TextBoxIcon.js +158 -0
- package/es/v1/Textarea/Textarea.js +102 -0
- package/es/v1/Tooltip/Tooltip.js +518 -0
- package/es/v1/Typography/Typography.js +38 -0
- package/es/v1/Typography/css/Typography.module.css +376 -0
- package/es/v1/Typography/css/cssJSLogic.js +46 -0
- package/es/v1/Typography/css/letterSpacingMap.js +12 -0
- package/es/v1/Typography/props/defaultProps.js +8 -0
- package/es/v1/Typography/props/propTypes.js +24 -0
- package/es/v1/VelocityAnimation/VelocityAnimation/VelocityAnimation.js +69 -0
- package/es/v1/VelocityAnimation/VelocityAnimationGroup/VelocityAnimationGroup.js +100 -0
- package/es/v1/semantic/Button/Button.js +53 -0
- package/es/v1/semantic/index.js +1 -0
- package/lib/AppContainer/AppContainer.js +5 -0
- package/lib/v1/Accordion/Accordion.js +96 -0
- package/lib/v1/Accordion/AccordionItem.js +68 -0
- package/lib/v1/Accordion/index.js +23 -0
- package/lib/v1/Animation/Animation.js +143 -0
- package/lib/v1/AppContainer/AppContainer.js +209 -0
- package/lib/v1/Avatar/Avatar.js +246 -0
- package/lib/v1/AvatarTeam/AvatarTeam.js +81 -0
- package/lib/v1/Button/Button.js +82 -0
- package/lib/v1/Buttongroup/Buttongroup.js +44 -0
- package/lib/v1/Card/Card.js +365 -0
- package/lib/v1/CheckBox/CheckBox.js +166 -0
- package/lib/v1/DateTime/CalendarView.js +285 -0
- package/lib/v1/DateTime/DateTime.js +872 -0
- package/lib/v1/DateTime/DateTimePopupFooter.js +96 -0
- package/lib/v1/DateTime/DateTimePopupHeader.js +166 -0
- package/lib/v1/DateTime/DateWidget.js +1125 -0
- package/lib/v1/DateTime/DaysRow.js +80 -0
- package/lib/v1/DateTime/Time.js +254 -0
- package/lib/v1/DateTime/YearView.js +325 -0
- package/lib/v1/DateTime/index.js +15 -0
- package/lib/v1/DropBox/DropBox.js +119 -0
- package/lib/v1/DropBox/DropBoxElement/DropBoxElement.js +145 -0
- package/lib/v1/DropDown/DropDown.js +170 -0
- package/lib/v1/DropDown/DropDownHeading.js +93 -0
- package/lib/v1/DropDown/DropDownItem.js +127 -0
- package/lib/v1/DropDown/DropDownSearch.js +113 -0
- package/lib/v1/DropDown/DropDownSeparator.js +64 -0
- package/lib/v1/Heading/Heading.js +49 -0
- package/lib/v1/Label/Label.js +51 -0
- package/lib/v1/Layout/Box.js +128 -0
- package/lib/v1/Layout/Container.js +145 -0
- package/lib/v1/Layout/index.js +23 -0
- package/lib/v1/ListItem/ListContainer.js +120 -0
- package/lib/v1/ListItem/ListItem.js +138 -0
- package/lib/v1/ListItem/ListItemWithAvatar.js +162 -0
- package/lib/v1/ListItem/ListItemWithCheckBox.js +125 -0
- package/lib/v1/ListItem/ListItemWithIcon.js +143 -0
- package/lib/v1/ListItem/ListItemWithRadio.js +126 -0
- package/lib/v1/ListItem/index.js +55 -0
- package/lib/v1/Modal/Modal.js +212 -0
- package/lib/v1/MultiSelect/AdvancedGroupMultiSelect.js +1167 -0
- package/lib/v1/MultiSelect/AdvancedMultiSelect.js +634 -0
- package/lib/v1/MultiSelect/EmptyState.js +112 -0
- package/lib/v1/MultiSelect/MobileHeader/MobileHeader.js +62 -0
- package/lib/v1/MultiSelect/MultiSelect.js +1201 -0
- package/lib/v1/MultiSelect/MultiSelectHeader.js +78 -0
- package/lib/v1/MultiSelect/MultiSelectWithAvatar.js +270 -0
- package/lib/v1/MultiSelect/SelectedOptions.js +126 -0
- package/lib/v1/MultiSelect/Suggestions.js +195 -0
- package/lib/v1/MultiSelect/index.js +39 -0
- package/lib/v1/PopOver/PopOver.js +293 -0
- package/lib/v1/Popup/Popup.js +715 -0
- package/lib/v1/Radio/Radio.js +126 -0
- package/lib/v1/Responsive/CustomResponsive.js +242 -0
- package/lib/v1/Responsive/RefWrapper.js +57 -0
- package/lib/v1/Responsive/ResizeComponent.js +268 -0
- package/lib/v1/Responsive/ResizeObserver.js +168 -0
- package/lib/v1/Responsive/Responsive.js +274 -0
- package/lib/v1/Responsive/index.js +55 -0
- package/lib/v1/ResponsiveDropBox/ResponsiveDropBox.js +79 -0
- package/lib/v1/Ribbon/Ribbon.js +44 -0
- package/lib/v1/RippleEffect/RippleEffect.js +39 -0
- package/lib/v1/Select/GroupSelect.js +877 -0
- package/lib/v1/Select/Select.js +1013 -0
- package/lib/v1/Select/SelectWithAvatar.js +394 -0
- package/lib/v1/Select/SelectWithIcon.js +597 -0
- package/lib/v1/Select/index.js +39 -0
- package/lib/v1/Stencils/Stencils.js +43 -0
- package/lib/v1/Switch/Switch.js +108 -0
- package/lib/v1/Tab/Tab.js +132 -0
- package/lib/v1/Tab/TabContent.js +42 -0
- package/lib/v1/Tab/TabContentWrapper.js +42 -0
- package/lib/v1/Tab/TabWrapper.js +89 -0
- package/lib/v1/Tab/Tabs.js +680 -0
- package/lib/v1/Tab/index.js +47 -0
- package/lib/v1/Tag/Tag.js +154 -0
- package/lib/v1/TextBox/TextBox.js +168 -0
- package/lib/v1/TextBoxIcon/TextBoxIcon.js +196 -0
- package/lib/v1/Textarea/Textarea.js +118 -0
- package/lib/v1/Tooltip/Tooltip.js +586 -0
- package/lib/v1/Typography/Typography.js +56 -0
- package/lib/v1/Typography/css/Typography.module.css +376 -0
- package/lib/v1/Typography/css/cssJSLogic.js +41 -0
- package/lib/v1/Typography/css/letterSpacingMap.js +20 -0
- package/lib/v1/Typography/props/defaultProps.js +15 -0
- package/lib/v1/Typography/props/propTypes.js +35 -0
- package/lib/v1/VelocityAnimation/VelocityAnimation/VelocityAnimation.js +90 -0
- package/lib/v1/VelocityAnimation/VelocityAnimationGroup/VelocityAnimationGroup.js +126 -0
- package/lib/v1/semantic/Button/Button.js +63 -0
- package/lib/v1/semantic/index.js +15 -0
- package/package.json +1 -1
- package/result.json +1 -1
|
@@ -0,0 +1,535 @@
|
|
|
1
|
+
import React, { Component } from 'react';
|
|
2
|
+
import { SelectWithIcon_defaultProps } from '../../Select/props/defaultProps';
|
|
3
|
+
import { SelectWithIcon_propTypes } from '../../Select/props/propTypes';
|
|
4
|
+
/**** Components ****/
|
|
5
|
+
|
|
6
|
+
import Popup from '../Popup/Popup';
|
|
7
|
+
import TextBoxIcon from '../TextBoxIcon/TextBoxIcon';
|
|
8
|
+
import { Icon } from '@zohodesk/icons';
|
|
9
|
+
import ListItemWithIcon from '../ListItem/ListItemWithIcon';
|
|
10
|
+
import Card, { CardHeader, CardContent } from '../Card/Card';
|
|
11
|
+
import EmptyState from '../MultiSelect/EmptyState';
|
|
12
|
+
import { Container, Box } from '../Layout';
|
|
13
|
+
import { getUniqueId } from '../../Provider/IdProvider';
|
|
14
|
+
import ResponsiveDropBox from '../ResponsiveDropBox/ResponsiveDropBox';
|
|
15
|
+
import { ResponsiveReceiver } from '../Responsive/CustomResponsive';
|
|
16
|
+
import Loader from '@zohodesk/svg/lib/Loader/Loader';
|
|
17
|
+
/**** Methods ****/
|
|
18
|
+
|
|
19
|
+
import { scrollTo, findScrollEnd } from '../../utils/Common.js';
|
|
20
|
+
/**** CSS ****/
|
|
21
|
+
|
|
22
|
+
import style from '../../Select/Select.module.css';
|
|
23
|
+
|
|
24
|
+
class SelectWithIcon extends Component {
|
|
25
|
+
constructor(props) {
|
|
26
|
+
super(props);
|
|
27
|
+
this.state = {
|
|
28
|
+
searchValue: '',
|
|
29
|
+
selectedIndex: 0,
|
|
30
|
+
options: props.options,
|
|
31
|
+
isFetchingOptions: false
|
|
32
|
+
};
|
|
33
|
+
this._isMounted = false;
|
|
34
|
+
this.onSearchClear = this.onSearchClear.bind(this);
|
|
35
|
+
this.onSearch = this.onSearch.bind(this);
|
|
36
|
+
this.togglePopup = this.togglePopup.bind(this);
|
|
37
|
+
this.handleChange = this.handleChange.bind(this);
|
|
38
|
+
this.handleKeyDown = this.handleKeyDown.bind(this);
|
|
39
|
+
this.handleMouseEnter = this.handleMouseEnter.bind(this);
|
|
40
|
+
this.scrollContentRef = this.scrollContentRef.bind(this);
|
|
41
|
+
this.itemRef = this.itemRef.bind(this);
|
|
42
|
+
this.searchInputRef = this.searchInputRef.bind(this);
|
|
43
|
+
this.inputRef = this.inputRef.bind(this);
|
|
44
|
+
this.handleScroll = this.handleScroll.bind(this);
|
|
45
|
+
this.getNextAriaId = getUniqueId(this);
|
|
46
|
+
this.handleGetNextOptions = this.handleGetNextOptions.bind(this);
|
|
47
|
+
this.handleFetchOptions = this.handleFetchOptions.bind(this);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
componentDidMount() {
|
|
51
|
+
this._isMounted = true;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
componentWillUnmount() {
|
|
55
|
+
this._isMounted = false;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
inputRef(el) {
|
|
59
|
+
this.input = el;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
itemRef(ele, index, id) {
|
|
63
|
+
this[`suggestion_${id}`] = ele;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
searchInputRef(el) {
|
|
67
|
+
this.searchInput = el;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
scrollContentRef(el) {
|
|
71
|
+
let {
|
|
72
|
+
isPopupOpen
|
|
73
|
+
} = this.props;
|
|
74
|
+
|
|
75
|
+
if (isPopupOpen) {
|
|
76
|
+
this.optionsContainer = el;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
handleMouseEnter(id, value, index, e) {
|
|
81
|
+
this.setState({
|
|
82
|
+
selectedIndex: index
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
handleKeyDown(e) {
|
|
87
|
+
let {
|
|
88
|
+
keyCode
|
|
89
|
+
} = e;
|
|
90
|
+
let {
|
|
91
|
+
selectedIndex,
|
|
92
|
+
options
|
|
93
|
+
} = this.state;
|
|
94
|
+
let {
|
|
95
|
+
idKey,
|
|
96
|
+
valueKey,
|
|
97
|
+
isPopupOpen,
|
|
98
|
+
selectedId
|
|
99
|
+
} = this.props;
|
|
100
|
+
|
|
101
|
+
if (isPopupOpen && (keyCode === 38 || keyCode === 40) && e.preventDefault) {
|
|
102
|
+
e.preventDefault(); //prevent body scroll
|
|
103
|
+
} else if (!isPopupOpen && (keyCode === 40 || keyCode === 13)) {
|
|
104
|
+
e.preventDefault(); //prevent body scroll
|
|
105
|
+
|
|
106
|
+
this.togglePopup(e);
|
|
107
|
+
options.map((list, index) => {
|
|
108
|
+
if (list.id === selectedId) {
|
|
109
|
+
this.setState({
|
|
110
|
+
selectedIndex: index
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (isPopupOpen) {
|
|
117
|
+
switch (keyCode) {
|
|
118
|
+
case 40:
|
|
119
|
+
if (selectedIndex === options.length - 1) {
|
|
120
|
+
this.setState({
|
|
121
|
+
selectedIndex: 0
|
|
122
|
+
});
|
|
123
|
+
} else {
|
|
124
|
+
if (selectedIndex === options.length - 3) {
|
|
125
|
+
this.handleGetNextOptions();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
this.setState({
|
|
129
|
+
selectedIndex: selectedIndex + 1
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
break;
|
|
134
|
+
|
|
135
|
+
case 38:
|
|
136
|
+
if (selectedIndex === 0) {
|
|
137
|
+
this.setState({
|
|
138
|
+
selectedIndex: options.length - 1
|
|
139
|
+
});
|
|
140
|
+
} else {
|
|
141
|
+
this.setState({
|
|
142
|
+
selectedIndex: selectedIndex - 1
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
break;
|
|
147
|
+
|
|
148
|
+
case 13:
|
|
149
|
+
{
|
|
150
|
+
let option = options[selectedIndex];
|
|
151
|
+
this.handleChange && this.handleChange(option[idKey], option[valueKey], selectedIndex, e);
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
componentDidUpdate(prevProps) {
|
|
159
|
+
let {
|
|
160
|
+
idKey,
|
|
161
|
+
isPopupOpen,
|
|
162
|
+
needSearch
|
|
163
|
+
} = this.props;
|
|
164
|
+
let {
|
|
165
|
+
selectedIndex,
|
|
166
|
+
options
|
|
167
|
+
} = this.state;
|
|
168
|
+
|
|
169
|
+
if (prevProps.isPopupOpen != isPopupOpen) {
|
|
170
|
+
setTimeout(() => {
|
|
171
|
+
isPopupOpen ? needSearch ? this.searchInput.focus({
|
|
172
|
+
preventScroll: true
|
|
173
|
+
}) : this.input.focus({
|
|
174
|
+
preventScroll: true
|
|
175
|
+
}) : this.input.focus({
|
|
176
|
+
preventScroll: true
|
|
177
|
+
});
|
|
178
|
+
}, 10);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
let option = options[selectedIndex];
|
|
182
|
+
let id = option && option[idKey] || {};
|
|
183
|
+
let selSuggestion = this[`suggestion_${id}`];
|
|
184
|
+
|
|
185
|
+
if (isPopupOpen) {
|
|
186
|
+
this.optionsContainer && scrollTo(this.optionsContainer, selSuggestion);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
searchList(searchValue) {
|
|
191
|
+
let datas = [];
|
|
192
|
+
let {
|
|
193
|
+
options,
|
|
194
|
+
valueKey
|
|
195
|
+
} = this.props;
|
|
196
|
+
|
|
197
|
+
if (options.length) {
|
|
198
|
+
datas = options.filter(obj => obj[valueKey].toLowerCase().includes(searchValue.toLowerCase()));
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return datas;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
onSearchClear() {
|
|
205
|
+
let options = this.searchList(''); // this.searchInput.focus({preventScroll:false});
|
|
206
|
+
|
|
207
|
+
this.setState({
|
|
208
|
+
searchValue: '',
|
|
209
|
+
options
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
onSearch(searchValue) {
|
|
214
|
+
let options = this.searchList(searchValue);
|
|
215
|
+
this.setState({
|
|
216
|
+
searchValue,
|
|
217
|
+
selectedIndex: -1,
|
|
218
|
+
options
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
togglePopup(e) {
|
|
223
|
+
let {
|
|
224
|
+
togglePopup,
|
|
225
|
+
isReadOnly,
|
|
226
|
+
boxPosition
|
|
227
|
+
} = this.props;
|
|
228
|
+
!isReadOnly && togglePopup(e, boxPosition);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
handleChange(id, value, index, e) {
|
|
232
|
+
let {
|
|
233
|
+
onChange,
|
|
234
|
+
isReadOnly
|
|
235
|
+
} = this.props;
|
|
236
|
+
!isReadOnly && onChange && onChange(id, value, index, e);
|
|
237
|
+
this.togglePopup(e);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
handleScroll(e) {
|
|
241
|
+
let ele = e.target;
|
|
242
|
+
let isScrollReachedBottom = findScrollEnd(ele);
|
|
243
|
+
isScrollReachedBottom && this.handleGetNextOptions();
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
UNSAFE_componentWillReceiveProps(nextProps) {
|
|
247
|
+
if (nextProps.options.length != this.props.options.length) {
|
|
248
|
+
this.setState({
|
|
249
|
+
options: nextProps.options
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
handleGetNextOptions() {
|
|
255
|
+
let {
|
|
256
|
+
isNextOptions,
|
|
257
|
+
getNextOptions
|
|
258
|
+
} = this.props;
|
|
259
|
+
let {
|
|
260
|
+
searchValue
|
|
261
|
+
} = this.state;
|
|
262
|
+
isNextOptions && getNextOptions && this.handleFetchOptions(getNextOptions, searchValue);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
handleFetchOptions(APICall) {
|
|
266
|
+
let searchValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
267
|
+
let {
|
|
268
|
+
isFetchingOptions = false
|
|
269
|
+
} = this.state;
|
|
270
|
+
let {
|
|
271
|
+
_isMounted
|
|
272
|
+
} = this;
|
|
273
|
+
|
|
274
|
+
if (!isFetchingOptions && APICall) {
|
|
275
|
+
this.setState({
|
|
276
|
+
isFetchingOptions: true
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
try {
|
|
280
|
+
return APICall(searchValue).then(() => {
|
|
281
|
+
_isMounted && this.setState({
|
|
282
|
+
isFetchingOptions: false
|
|
283
|
+
});
|
|
284
|
+
}, () => {
|
|
285
|
+
_isMounted && this.setState({
|
|
286
|
+
isFetchingOptions: false
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
} catch (e) {
|
|
290
|
+
_isMounted && this.setState({
|
|
291
|
+
isFetchingOptions: false
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
responsiveFunc(_ref) {
|
|
298
|
+
let {
|
|
299
|
+
mediaQueryOR
|
|
300
|
+
} = _ref;
|
|
301
|
+
return {
|
|
302
|
+
tabletMode: mediaQueryOR([{
|
|
303
|
+
maxWidth: 700
|
|
304
|
+
}])
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
render() {
|
|
309
|
+
let {
|
|
310
|
+
animationStyle,
|
|
311
|
+
removeClose,
|
|
312
|
+
selectedValue,
|
|
313
|
+
searchBoxPlaceHolder,
|
|
314
|
+
needSearch,
|
|
315
|
+
searchEmptyMessage,
|
|
316
|
+
dataId,
|
|
317
|
+
maxLength,
|
|
318
|
+
isDisabled,
|
|
319
|
+
isReadOnly,
|
|
320
|
+
placeHolder,
|
|
321
|
+
textBoxSize,
|
|
322
|
+
textBoxVariant,
|
|
323
|
+
selectedId,
|
|
324
|
+
isPopupOpen,
|
|
325
|
+
isPopupReady,
|
|
326
|
+
position,
|
|
327
|
+
getContainerRef,
|
|
328
|
+
valueKey,
|
|
329
|
+
idKey,
|
|
330
|
+
needListBorder,
|
|
331
|
+
needTick,
|
|
332
|
+
size,
|
|
333
|
+
borderColor,
|
|
334
|
+
title,
|
|
335
|
+
className,
|
|
336
|
+
needBorder,
|
|
337
|
+
searchBoxSize,
|
|
338
|
+
getTargetRef,
|
|
339
|
+
needResponsive,
|
|
340
|
+
boxSize,
|
|
341
|
+
dropBoxSize,
|
|
342
|
+
emptyMessage,
|
|
343
|
+
needIcon,
|
|
344
|
+
iconName,
|
|
345
|
+
iconSize,
|
|
346
|
+
iconClass,
|
|
347
|
+
i18nKeys,
|
|
348
|
+
htmlId,
|
|
349
|
+
isLoading,
|
|
350
|
+
dataSelectorId
|
|
351
|
+
} = this.props;
|
|
352
|
+
i18nKeys = Object.assign({}, i18nKeys, {
|
|
353
|
+
emptyText: i18nKeys.emptyText || emptyMessage,
|
|
354
|
+
searchEmptyText: i18nKeys.searchEmptyText || searchEmptyMessage
|
|
355
|
+
});
|
|
356
|
+
let {
|
|
357
|
+
searchValue,
|
|
358
|
+
selectedIndex,
|
|
359
|
+
options,
|
|
360
|
+
isFetchingOptions
|
|
361
|
+
} = this.state;
|
|
362
|
+
let setAriaId = this.getNextAriaId();
|
|
363
|
+
let ariaErrorId = this.getNextAriaId();
|
|
364
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
365
|
+
className: `${style.container} ${style[`box_${size}`]} ${isReadOnly ? style.readonly : ''} ${borderColor === 'transparent' ? style.transparentContainer : ''}`,
|
|
366
|
+
"data-title": isDisabled ? title : null,
|
|
367
|
+
"data-selector-id": dataSelectorId
|
|
368
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
369
|
+
className: `${className ? className : ''}`,
|
|
370
|
+
onClick: isDisabled || isReadOnly ? null : this.togglePopup,
|
|
371
|
+
ref: getTargetRef,
|
|
372
|
+
"data-id": `${isDisabled ? `${dataId}_disabled` : isReadOnly ? `${dataId}_readOnly` : dataId}`,
|
|
373
|
+
"data-test-id": `${isDisabled ? `${dataId}_disabled` : isReadOnly ? `${dataId}_readOnly` : dataId}`
|
|
374
|
+
}, /*#__PURE__*/React.createElement(Container, {
|
|
375
|
+
alignBox: "row"
|
|
376
|
+
}, needIcon ? /*#__PURE__*/React.createElement(Container, {
|
|
377
|
+
align: "both",
|
|
378
|
+
className: `${style.leftIcon} ${isDisabled ? style.disable : ''}`
|
|
379
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
380
|
+
name: iconName,
|
|
381
|
+
size: iconSize,
|
|
382
|
+
iconClass: iconClass
|
|
383
|
+
})) : null, /*#__PURE__*/React.createElement(Box, {
|
|
384
|
+
flexible: true
|
|
385
|
+
}, /*#__PURE__*/React.createElement(TextBoxIcon, {
|
|
386
|
+
a11y: {
|
|
387
|
+
role: 'combobox',
|
|
388
|
+
ariaLabel: 'click to select options',
|
|
389
|
+
ariaControls: setAriaId,
|
|
390
|
+
ariaExpanded: !isReadOnly && !isDisabled && isPopupOpen ? true : false,
|
|
391
|
+
ariaHaspopup: true,
|
|
392
|
+
ariaReadonly: true,
|
|
393
|
+
ariaActivedescendant: selectedId,
|
|
394
|
+
ariaOwns: setAriaId
|
|
395
|
+
},
|
|
396
|
+
htmlId: htmlId,
|
|
397
|
+
value: selectedValue,
|
|
398
|
+
isReadOnly: true,
|
|
399
|
+
needReadOnlyStyle: isReadOnly ? true : false,
|
|
400
|
+
dataId: `${dataId}_textBox`,
|
|
401
|
+
maxLength: maxLength,
|
|
402
|
+
needBorder: needBorder,
|
|
403
|
+
isDisabled: isDisabled,
|
|
404
|
+
placeHolder: placeHolder,
|
|
405
|
+
size: textBoxSize,
|
|
406
|
+
variant: textBoxVariant,
|
|
407
|
+
iconRotated: isPopupOpen,
|
|
408
|
+
inputRef: this.inputRef,
|
|
409
|
+
onKeyDown: this.handleKeyDown,
|
|
410
|
+
isClickable: isReadOnly || isDisabled ? false : true,
|
|
411
|
+
customClass: {
|
|
412
|
+
customTBoxWrap: `${isReadOnly || isDisabled ? '' : style.input} ${needIcon ? style.iconSelect : ''}`
|
|
413
|
+
},
|
|
414
|
+
needEffect: isReadOnly || isDisabled ? false : true,
|
|
415
|
+
borderColor: borderColor,
|
|
416
|
+
autoComplete: false,
|
|
417
|
+
isFocus: isPopupReady
|
|
418
|
+
}, /*#__PURE__*/React.createElement(Container, {
|
|
419
|
+
align: "both",
|
|
420
|
+
dataId: `${dataId}_downIcon`
|
|
421
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
422
|
+
name: "ZD-down",
|
|
423
|
+
size: "7"
|
|
424
|
+
})))))), !isReadOnly && !isDisabled && isPopupOpen ? /*#__PURE__*/React.createElement(ResponsiveReceiver, {
|
|
425
|
+
query: this.responsiveFunc,
|
|
426
|
+
responsiveId: "Helmet"
|
|
427
|
+
}, _ref2 => {
|
|
428
|
+
let {
|
|
429
|
+
tabletMode
|
|
430
|
+
} = _ref2;
|
|
431
|
+
return /*#__PURE__*/React.createElement(ResponsiveDropBox, {
|
|
432
|
+
animationStyle: animationStyle,
|
|
433
|
+
boxPosition: position,
|
|
434
|
+
isActive: isPopupReady,
|
|
435
|
+
isAnimate: true,
|
|
436
|
+
isArrow: false,
|
|
437
|
+
onClick: removeClose,
|
|
438
|
+
getRef: getContainerRef,
|
|
439
|
+
needResponsive: needResponsive,
|
|
440
|
+
dataId: `${dataId}_suggestions`,
|
|
441
|
+
size: boxSize,
|
|
442
|
+
isPadding: false,
|
|
443
|
+
isResponsivePadding: true,
|
|
444
|
+
alignBox: "row"
|
|
445
|
+
}, isLoading ? /*#__PURE__*/React.createElement(Container, {
|
|
446
|
+
align: "both",
|
|
447
|
+
className: style.loader
|
|
448
|
+
}, /*#__PURE__*/React.createElement(Loader, null)) : /*#__PURE__*/React.createElement(Box, {
|
|
449
|
+
flexible: true
|
|
450
|
+
}, /*#__PURE__*/React.createElement(Card, {
|
|
451
|
+
onScroll: this.handleScroll,
|
|
452
|
+
htmlId: setAriaId,
|
|
453
|
+
a11y: {
|
|
454
|
+
role: 'listbox'
|
|
455
|
+
}
|
|
456
|
+
}, needSearch ? /*#__PURE__*/React.createElement(CardHeader, null, /*#__PURE__*/React.createElement("div", {
|
|
457
|
+
className: `${style.search} ${style[size]}`
|
|
458
|
+
}, /*#__PURE__*/React.createElement(TextBoxIcon, {
|
|
459
|
+
onClear: this.onSearchClear,
|
|
460
|
+
onChange: this.onSearch,
|
|
461
|
+
placeHolder: searchBoxPlaceHolder,
|
|
462
|
+
value: searchValue,
|
|
463
|
+
maxLength: maxLength,
|
|
464
|
+
onKeyDown: this.handleKeyDown,
|
|
465
|
+
inputRef: this.searchInputRef,
|
|
466
|
+
size: searchBoxSize,
|
|
467
|
+
dataId: `${dataId}_search`,
|
|
468
|
+
a11y: {
|
|
469
|
+
ariaDescribedby: ariaErrorId
|
|
470
|
+
},
|
|
471
|
+
autoComplete: false
|
|
472
|
+
}))) : null, /*#__PURE__*/React.createElement(CardContent, {
|
|
473
|
+
customClass: `${tabletMode ? style.responsivedropBoxList : style.dropBoxList} ${!tabletMode && dropBoxSize ? style[dropBoxSize] : ''}`,
|
|
474
|
+
shrink: true,
|
|
475
|
+
eleRef: this.scrollContentRef
|
|
476
|
+
}, options.length ? /*#__PURE__*/React.createElement(React.Fragment, null, options.map((options, i) => {
|
|
477
|
+
let {
|
|
478
|
+
iconName,
|
|
479
|
+
iconSize,
|
|
480
|
+
iconColor
|
|
481
|
+
} = options;
|
|
482
|
+
return /*#__PURE__*/React.createElement(ListItemWithIcon, {
|
|
483
|
+
key: options[idKey],
|
|
484
|
+
value: options[valueKey],
|
|
485
|
+
size: "medium",
|
|
486
|
+
onClick: this.handleChange,
|
|
487
|
+
id: options[idKey],
|
|
488
|
+
index: i,
|
|
489
|
+
title: options[valueKey],
|
|
490
|
+
palette: "default",
|
|
491
|
+
dataId: options[idKey],
|
|
492
|
+
iconName: iconName,
|
|
493
|
+
iconSize: iconSize,
|
|
494
|
+
iconClass: iconColor,
|
|
495
|
+
active: selectedId === options[idKey],
|
|
496
|
+
needBorder: needListBorder,
|
|
497
|
+
needTick: needTick,
|
|
498
|
+
onMouseEnter: this.handleMouseEnter,
|
|
499
|
+
highlight: selectedIndex === i,
|
|
500
|
+
getRef: this.itemRef,
|
|
501
|
+
a11y: {
|
|
502
|
+
role: 'option',
|
|
503
|
+
ariaSelected: selectedId === options[idKey],
|
|
504
|
+
ariaLabel: options[valueKey]
|
|
505
|
+
}
|
|
506
|
+
});
|
|
507
|
+
})) : /*#__PURE__*/React.createElement(EmptyState, {
|
|
508
|
+
isLoading: isFetchingOptions,
|
|
509
|
+
options: options,
|
|
510
|
+
searchString: searchValue,
|
|
511
|
+
suggestions: options,
|
|
512
|
+
dataId: dataId,
|
|
513
|
+
i18nKeys: i18nKeys,
|
|
514
|
+
htmlId: ariaErrorId
|
|
515
|
+
}), isFetchingOptions && /*#__PURE__*/React.createElement(Container, {
|
|
516
|
+
isCover: false,
|
|
517
|
+
align: "both"
|
|
518
|
+
}, /*#__PURE__*/React.createElement(Loader, null))))));
|
|
519
|
+
}) : null);
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
SelectWithIcon.propTypes = SelectWithIcon_propTypes;
|
|
525
|
+
SelectWithIcon.defaultProps = SelectWithIcon_defaultProps;
|
|
526
|
+
const SelectWithIconComponent = Popup(SelectWithIcon);
|
|
527
|
+
SelectWithIconComponent.defaultProps = SelectWithIcon.defaultProps;
|
|
528
|
+
SelectWithIconComponent.propTypes = SelectWithIcon.propTypes; // if (__DOCS__) {
|
|
529
|
+
// SelectWithIcon.docs = {
|
|
530
|
+
// componentGroup: 'Form Elements',
|
|
531
|
+
// folderName: 'Style Guide'
|
|
532
|
+
// };
|
|
533
|
+
// }
|
|
534
|
+
|
|
535
|
+
export default SelectWithIconComponent;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React, { memo } from 'react';
|
|
2
|
+
import { defaultProps } from '../../Stencils/props/defaultProps';
|
|
3
|
+
import { propTypes } from '../../Stencils/props/propTypes';
|
|
4
|
+
import style from '../../Stencils/Stencils.module.css';
|
|
5
|
+
|
|
6
|
+
function Stencils(props) {
|
|
7
|
+
let {
|
|
8
|
+
shape,
|
|
9
|
+
size,
|
|
10
|
+
palette,
|
|
11
|
+
customClass
|
|
12
|
+
} = props;
|
|
13
|
+
size = shape === 'rect' ? style[size] : style[`c${size}`];
|
|
14
|
+
shape = shape === 'rect' ? style.rectangular : style.circle;
|
|
15
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
16
|
+
className: `${style.container} ${shape} ${size} ${style[palette]} ${customClass}`
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
Stencils.propTypes = propTypes;
|
|
21
|
+
Stencils.defaultProps = defaultProps;
|
|
22
|
+
const MemoizedStencils = /*#__PURE__*/memo(Stencils);
|
|
23
|
+
MemoizedStencils.propTypes = propTypes;
|
|
24
|
+
MemoizedStencils.defaultProps = defaultProps;
|
|
25
|
+
MemoizedStencils.displayName = 'Stencils';
|
|
26
|
+
export default MemoizedStencils;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
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); }
|
|
2
|
+
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { defaultProps } from '../../Switch/props/defaultProps';
|
|
5
|
+
import { propTypes } from '../../Switch/props/propTypes';
|
|
6
|
+
import { Container, Box } from '../Layout';
|
|
7
|
+
import Label from '../Label/Label';
|
|
8
|
+
import style from '../../Switch/Switch.module.css';
|
|
9
|
+
|
|
10
|
+
const Switch = props => {
|
|
11
|
+
let {
|
|
12
|
+
id,
|
|
13
|
+
name,
|
|
14
|
+
value,
|
|
15
|
+
checked,
|
|
16
|
+
disabled,
|
|
17
|
+
isReadOnly,
|
|
18
|
+
size,
|
|
19
|
+
text,
|
|
20
|
+
labelSize,
|
|
21
|
+
labelPalette,
|
|
22
|
+
title,
|
|
23
|
+
disableTitle,
|
|
24
|
+
dataId,
|
|
25
|
+
dataSelectorId,
|
|
26
|
+
customClass,
|
|
27
|
+
customProps
|
|
28
|
+
} = props;
|
|
29
|
+
|
|
30
|
+
function onChange(e) {
|
|
31
|
+
const {
|
|
32
|
+
onChange
|
|
33
|
+
} = props;
|
|
34
|
+
onChange && onChange(!checked, e);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let {
|
|
38
|
+
SwitchProps = {},
|
|
39
|
+
LabelProps = {}
|
|
40
|
+
} = customProps;
|
|
41
|
+
let {
|
|
42
|
+
customSwitchWrap = '',
|
|
43
|
+
customSwitch = '',
|
|
44
|
+
customSwitchSize = '',
|
|
45
|
+
customLabel = ''
|
|
46
|
+
} = customClass;
|
|
47
|
+
size !== 'small' ? size = 'switch_medium' : size = 'switch_small';
|
|
48
|
+
return /*#__PURE__*/React.createElement(Container, _extends({
|
|
49
|
+
align: "vertical",
|
|
50
|
+
isCover: false,
|
|
51
|
+
alignBox: "row",
|
|
52
|
+
isInline: true,
|
|
53
|
+
className: `${style.container} ${customSwitchWrap} ${disabled ? style.disabled : isReadOnly ? style.readonly : style.effect}`,
|
|
54
|
+
"data-title": disabled ? disableTitle : title,
|
|
55
|
+
"aria-checked": checked,
|
|
56
|
+
role: "switch",
|
|
57
|
+
tabIndex: isReadOnly || disabled ? '-1' : '0',
|
|
58
|
+
dataSelectorId: dataSelectorId
|
|
59
|
+
}, SwitchProps), /*#__PURE__*/React.createElement(Box, {
|
|
60
|
+
className: `${style[size]} ${customSwitchSize}`
|
|
61
|
+
}, /*#__PURE__*/React.createElement("input", {
|
|
62
|
+
type: "checkbox",
|
|
63
|
+
id: id,
|
|
64
|
+
className: `${style.input} ${checked ? style.checked : ''}`,
|
|
65
|
+
name: name,
|
|
66
|
+
value: value,
|
|
67
|
+
checked: checked,
|
|
68
|
+
disabled: disabled,
|
|
69
|
+
readOnly: isReadOnly,
|
|
70
|
+
onClick: !disabled || !isReadOnly ? onChange : null
|
|
71
|
+
}), /*#__PURE__*/React.createElement("label", {
|
|
72
|
+
htmlFor: id,
|
|
73
|
+
"data-id": dataId,
|
|
74
|
+
"data-test-id": dataId,
|
|
75
|
+
className: `${style.label} ${style[`${size}Label`]} ${customSwitch}`
|
|
76
|
+
})), text && /*#__PURE__*/React.createElement(Label, _extends({
|
|
77
|
+
text: text,
|
|
78
|
+
palette: labelPalette,
|
|
79
|
+
id: id,
|
|
80
|
+
size: labelSize,
|
|
81
|
+
type: "subtitle",
|
|
82
|
+
onClick: !disabled || !isReadOnly ? onChange : null,
|
|
83
|
+
customClass: customLabel
|
|
84
|
+
}, LabelProps)));
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
Switch.defaultProps = defaultProps;
|
|
88
|
+
Switch.propTypes = propTypes;
|
|
89
|
+
export default Switch; // if (__DOCS__) {
|
|
90
|
+
// Switch.docs = {
|
|
91
|
+
// componentGroup: 'Form Elements',
|
|
92
|
+
// folderName: 'Style Guide'
|
|
93
|
+
// };
|
|
94
|
+
// }
|