@hipay/hipay-material-ui 2.0.0-beta.54 → 2.0.0-beta.56
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +57 -0
- package/HiBreadcrumb/HiBreadcrumb.js +14 -4
- package/HiBreadcrumb/HiStep.js +4 -1
- package/HiBreadcrumb/HiStepContent.js +0 -1
- package/HiBreadcrumb/HiStepLabel.js +12 -4
- package/HiBreadcrumb/HiStepper.js +1 -1
- package/HiButton/HiButton.js +7 -1
- package/HiCell/CellIcon.js +4 -4
- package/HiCell/CellImage.js +28 -4
- package/HiCell/CellNumeric.js +1 -2
- package/HiCell/CellRate.js +6 -3
- package/HiCell/CellSentinel.js +7 -10
- package/HiCell/CellSentinelScore.js +4 -4
- package/HiCell/CellTextStyled.js +99 -0
- package/HiCell/index.js +9 -1
- package/HiChip/HiChip.js +1 -0
- package/HiDatePicker/Caption.js +8 -9
- package/HiDatePicker/HiDateRangePicker.js +37 -19
- package/HiDatePicker/HiDateRangeSelector.js +24 -22
- package/HiDatePicker/Overlays/CustomOverlayLayout.js +26 -17
- package/HiDatePicker/Overlays/MonthPickerOverlay.spec.js +1 -0
- package/HiDatePicker/Overlays/Overlay.js +15 -8
- package/HiDatePicker/Overlays/Overlay.spec.js +1 -0
- package/HiDatePicker/Overlays/TimePickerOverlay.js +2 -2
- package/HiDatePicker/Overlays/TimePickerOverlay.spec.js +1 -0
- package/HiDatePicker/Overlays/YearPickerOverlay.js +2 -4
- package/HiDatePicker/Overlays/YearPickerOverlay.spec.js +1 -0
- package/HiDatePicker/stylesheet.js +3 -2
- package/HiDotsStepper/HiDot.js +108 -0
- package/HiDotsStepper/HiDotsStepper.js +121 -0
- package/HiExpansionPanel/HiExpansionPanel.js +1 -1
- package/HiForm/HiAddressField.js +176 -0
- package/HiForm/HiSlider.js +352 -0
- package/HiForm/HiUpload.js +204 -0
- package/HiForm/HiUploadField.js +182 -0
- package/HiForm/HiUploadInput.js +459 -0
- package/HiForm/index.js +16 -0
- package/HiMap/HiMap.js +345 -0
- package/HiMap/HiMapExpand.js +210 -0
- package/HiMap/index.js +23 -0
- package/HiNotice/HiKPI.js +238 -0
- package/HiNotice/HiKPINotice.js +93 -0
- package/HiNotice/index.js +23 -0
- package/HiPdfReader/HiPdfReader.js +269 -0
- package/HiPdfReader/index.js +15 -0
- package/HiRadio/HiRadio.js +74 -0
- package/HiRadio/index.js +15 -0
- package/HiSelect/HiSelect.js +73 -84
- package/HiSelect/HiSuggestSelect.js +32 -5
- package/HiSelect/SelectInput.js +5 -0
- package/HiSelectNew/HiNestedSelectContent.js +5 -1
- package/HiSelectNew/HiSelect.js +174 -137
- package/HiSelectNew/HiSelectContent.js +0 -8
- package/HiSelectNew/HiSelectInput.js +8 -9
- package/HiSelectableList/HiSelectableList.js +32 -4
- package/HiSelectableList/HiSelectableListItem.js +62 -24
- package/HiTable/HiCellBuilder.js +42 -32
- package/HiTable/HiTableHeader.js +28 -21
- package/HiTable/constants.js +3 -1
- package/README.md +249 -98
- package/es/HiBreadcrumb/HiBreadcrumb.js +14 -4
- package/es/HiBreadcrumb/HiStep.js +4 -1
- package/es/HiBreadcrumb/HiStepContent.js +0 -1
- package/es/HiBreadcrumb/HiStepLabel.js +13 -4
- package/es/HiBreadcrumb/HiStepper.js +1 -1
- package/es/HiButton/HiButton.js +7 -0
- package/es/HiCell/CellIcon.js +5 -5
- package/es/HiCell/CellImage.js +25 -2
- package/es/HiCell/CellNumeric.js +1 -2
- package/es/HiCell/CellRate.js +6 -3
- package/es/HiCell/CellSentinel.js +7 -10
- package/es/HiCell/CellSentinelScore.js +4 -4
- package/es/HiCell/CellTextStyled.js +84 -0
- package/es/HiCell/index.js +2 -1
- package/es/HiChip/HiChip.js +1 -0
- package/es/HiDatePicker/Caption.js +7 -9
- package/es/HiDatePicker/HiDateRangePicker.js +41 -25
- package/es/HiDatePicker/HiDateRangeSelector.js +24 -22
- package/es/HiDatePicker/ListPicker.js +1 -1
- package/es/HiDatePicker/Overlays/CustomOverlayLayout.js +30 -19
- package/es/HiDatePicker/Overlays/MonthPickerOverlay.js +2 -2
- package/es/HiDatePicker/Overlays/MonthPickerOverlay.spec.js +1 -0
- package/es/HiDatePicker/Overlays/Overlay.js +16 -9
- package/es/HiDatePicker/Overlays/Overlay.spec.js +1 -0
- package/es/HiDatePicker/Overlays/TimePickerOverlay.js +2 -2
- package/es/HiDatePicker/Overlays/TimePickerOverlay.spec.js +1 -0
- package/es/HiDatePicker/Overlays/YearPickerOverlay.js +2 -4
- package/es/HiDatePicker/Overlays/YearPickerOverlay.spec.js +1 -0
- package/es/HiDatePicker/stylesheet.js +3 -2
- package/es/HiDotsStepper/HiDot.js +66 -0
- package/es/HiDotsStepper/HiDotsStepper.js +73 -0
- package/es/HiExpansionPanel/HiExpansionPanel.js +1 -1
- package/es/HiForm/HiAddressField.js +134 -0
- package/es/HiForm/HiSlider.js +302 -0
- package/es/HiForm/HiUpload.js +158 -0
- package/es/HiForm/HiUploadField.js +140 -0
- package/es/HiForm/HiUploadInput.js +411 -0
- package/es/HiForm/index.js +2 -0
- package/es/HiMap/HiMap.js +290 -0
- package/es/HiMap/HiMapExpand.js +162 -0
- package/es/HiMap/index.js +2 -0
- package/es/HiNotice/HiKPI.js +196 -0
- package/es/HiNotice/HiKPINotice.js +77 -0
- package/es/HiNotice/index.js +2 -0
- package/es/HiPdfReader/HiPdfReader.js +214 -0
- package/es/HiPdfReader/index.js +1 -0
- package/es/HiRadio/HiRadio.js +55 -0
- package/es/HiRadio/index.js +1 -0
- package/es/HiSelect/HiSelect.js +68 -78
- package/es/HiSelect/HiSuggestSelect.js +27 -6
- package/es/HiSelect/SelectInput.js +5 -0
- package/es/HiSelectNew/HiNestedSelectContent.js +5 -1
- package/es/HiSelectNew/HiSelect.js +156 -120
- package/es/HiSelectNew/HiSelectContent.js +0 -7
- package/es/HiSelectNew/HiSelectInput.js +8 -9
- package/es/HiSelectableList/HiSelectableList.js +28 -6
- package/es/HiSelectableList/HiSelectableListItem.js +71 -24
- package/es/HiTable/HiCellBuilder.js +140 -136
- package/es/HiTable/HiTableHeader.js +26 -18
- package/es/HiTable/constants.js +1 -0
- package/es/index.js +7 -0
- package/es/utils/helpers.js +1 -1
- package/index.es.js +8 -1
- package/index.js +57 -1
- package/package.json +6 -3
- package/umd/hipay-material-ui.development.js +42114 -35120
- package/umd/hipay-material-ui.production.min.js +2 -2
- package/utils/helpers.js +1 -1
package/es/HiSelect/HiSelect.js
CHANGED
@@ -70,28 +70,6 @@ class HiSelect extends React.PureComponent {
|
|
70
70
|
constructor(_props) {
|
71
71
|
super(_props);
|
72
72
|
|
73
|
-
this.handleClick = () => {
|
74
|
-
if (this.state.open) {
|
75
|
-
this.handleClose();
|
76
|
-
} else {
|
77
|
-
this.setState({
|
78
|
-
open: true
|
79
|
-
});
|
80
|
-
const options = this.props.options.slice();
|
81
|
-
this.handleSuggestions(options);
|
82
|
-
|
83
|
-
if (this.props.onClick) {
|
84
|
-
this.props.onClick();
|
85
|
-
} // Gestion du focus
|
86
|
-
|
87
|
-
|
88
|
-
if (!this.props.searchable) {
|
89
|
-
// sinon focus sur le dernier élément selectionné
|
90
|
-
this.focusOnSelectedItem();
|
91
|
-
}
|
92
|
-
}
|
93
|
-
};
|
94
|
-
|
95
73
|
this.buildHierarchyTrees = props => {
|
96
74
|
// Construct two associative arrays
|
97
75
|
// hierarchy[parentId] => children
|
@@ -153,6 +131,61 @@ class HiSelect extends React.PureComponent {
|
|
153
131
|
}, 1);
|
154
132
|
};
|
155
133
|
|
134
|
+
this.handleBlur = () => {
|
135
|
+
this.setState({
|
136
|
+
focused: false
|
137
|
+
});
|
138
|
+
};
|
139
|
+
|
140
|
+
this.handleClick = () => {
|
141
|
+
if (this.state.open) {
|
142
|
+
this.handleClose();
|
143
|
+
} else {
|
144
|
+
this.setState({
|
145
|
+
open: true
|
146
|
+
});
|
147
|
+
const options = this.props.options.slice();
|
148
|
+
this.handleSuggestions(options);
|
149
|
+
|
150
|
+
if (this.props.onClick) {
|
151
|
+
this.props.onClick();
|
152
|
+
} // Gestion du focus
|
153
|
+
|
154
|
+
|
155
|
+
if (!this.props.searchable) {
|
156
|
+
// sinon focus sur le dernier élément selectionné
|
157
|
+
this.focusOnSelectedItem();
|
158
|
+
}
|
159
|
+
}
|
160
|
+
};
|
161
|
+
|
162
|
+
this.handleClickAway = event => {
|
163
|
+
// Au clic sur le bouton, on laisse le handleClick fermer le select
|
164
|
+
if (!this.selectInputElement.contains(event.target)) {
|
165
|
+
this.handleClose(event);
|
166
|
+
}
|
167
|
+
};
|
168
|
+
|
169
|
+
this.handleClose = () => {
|
170
|
+
if (this.props.onClose) {
|
171
|
+
this.props.onClose();
|
172
|
+
}
|
173
|
+
|
174
|
+
if (this.selectInputElement) {
|
175
|
+
this.selectInputElement.focus();
|
176
|
+
}
|
177
|
+
|
178
|
+
this.setState({
|
179
|
+
open: false
|
180
|
+
});
|
181
|
+
};
|
182
|
+
|
183
|
+
this.handleFocus = () => {
|
184
|
+
this.setState({
|
185
|
+
focused: true
|
186
|
+
});
|
187
|
+
};
|
188
|
+
|
156
189
|
this.handleKeyDown = event => {
|
157
190
|
let nextItem;
|
158
191
|
|
@@ -186,36 +219,24 @@ class HiSelect extends React.PureComponent {
|
|
186
219
|
}
|
187
220
|
};
|
188
221
|
|
189
|
-
this.
|
190
|
-
|
191
|
-
|
192
|
-
});
|
193
|
-
};
|
194
|
-
|
195
|
-
this.handleBlur = () => {
|
196
|
-
this.setState({
|
197
|
-
focused: false
|
198
|
-
});
|
222
|
+
this.handleRequestDelete = event => {
|
223
|
+
event.stopPropagation();
|
224
|
+
this.props.onChange(this.props.name, []);
|
199
225
|
};
|
200
226
|
|
201
|
-
this.
|
202
|
-
if (this.props.
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
if (this.selectInputElement) {
|
207
|
-
this.selectInputElement.focus();
|
227
|
+
this.handleReset = event => {
|
228
|
+
if (this.props.onReset) {
|
229
|
+
event.stopPropagation();
|
230
|
+
this.props.onReset(event);
|
208
231
|
}
|
209
|
-
|
210
|
-
this.setState({
|
211
|
-
open: false
|
212
|
-
});
|
213
232
|
};
|
214
233
|
|
215
|
-
this.
|
216
|
-
|
217
|
-
|
218
|
-
this.
|
234
|
+
this.handleScroll = event => {
|
235
|
+
if (!this.props.loadingMoreResults && this.props.hasMore && event.target.scrollHeight - event.target.clientHeight - event.target.scrollTop < 15) {
|
236
|
+
this.props.loadMoreResults(this.state.resultsPageNumber + 1);
|
237
|
+
this.setState(prevState => ({
|
238
|
+
resultsPageNumber: prevState.resultsPageNumber + 1
|
239
|
+
}));
|
219
240
|
}
|
220
241
|
};
|
221
242
|
|
@@ -386,20 +407,6 @@ class HiSelect extends React.PureComponent {
|
|
386
407
|
});
|
387
408
|
};
|
388
409
|
|
389
|
-
this.handleRequestDelete = evt => {
|
390
|
-
evt.stopPropagation();
|
391
|
-
this.props.onChange(this.props.name, []);
|
392
|
-
};
|
393
|
-
|
394
|
-
this.handleScroll = event => {
|
395
|
-
if (!this.props.loadingMoreResults && this.props.hasMore && event.target.scrollHeight - event.target.clientHeight - event.target.scrollTop < 15) {
|
396
|
-
this.props.loadMoreResults(this.state.resultsPageNumber + 1);
|
397
|
-
this.setState(prevState => ({
|
398
|
-
resultsPageNumber: prevState.resultsPageNumber + 1
|
399
|
-
}));
|
400
|
-
}
|
401
|
-
};
|
402
|
-
|
403
410
|
this.state = {
|
404
411
|
open: false,
|
405
412
|
focused: false,
|
@@ -455,16 +462,6 @@ class HiSelect extends React.PureComponent {
|
|
455
462
|
} else if (!_props.dynamic) {
|
456
463
|
this.state.dynamic = true;
|
457
464
|
}
|
458
|
-
|
459
|
-
this.handleSelect = this.handleSelect.bind(this);
|
460
|
-
this.handleClick = this.handleClick.bind(this);
|
461
|
-
this.handleClose = this.handleClose.bind(this);
|
462
|
-
this.handleClickAway = this.handleClickAway.bind(this);
|
463
|
-
this.handleRequestDelete = this.handleRequestDelete.bind(this);
|
464
|
-
this.handleSuggestions = this.handleSuggestions.bind(this);
|
465
|
-
this.handleFocus = this.handleFocus.bind(this);
|
466
|
-
this.handleBlur = this.handleBlur.bind(this);
|
467
|
-
this.handleScroll = this.handleScroll.bind(this);
|
468
465
|
}
|
469
466
|
|
470
467
|
componentWillReceiveProps(nextProps) {
|
@@ -490,13 +487,6 @@ class HiSelect extends React.PureComponent {
|
|
490
487
|
}
|
491
488
|
}
|
492
489
|
|
493
|
-
handleReset(event) {
|
494
|
-
if (this.props.onReset) {
|
495
|
-
event.stopPropagation();
|
496
|
-
this.props.onReset(event);
|
497
|
-
}
|
498
|
-
}
|
499
|
-
|
500
490
|
render() {
|
501
491
|
const _this$props = this.props,
|
502
492
|
{
|
@@ -6,11 +6,13 @@ import PropTypes from 'prop-types';
|
|
6
6
|
import { findDOMNode } from 'react-dom';
|
7
7
|
import Grow from '@material-ui/core/Grow';
|
8
8
|
import Paper from '@material-ui/core/Paper';
|
9
|
+
import classNames from 'classnames';
|
9
10
|
import HiSelectableList from '../HiSelectableList';
|
10
11
|
import HiInput from '../HiForm/HiInput';
|
11
12
|
import { withStyles } from '../styles';
|
12
13
|
import Popper from '@material-ui/core/Popper';
|
13
14
|
import { getNextItemSelectable } from '../utils/helpers';
|
15
|
+
import keycode from 'keycode';
|
14
16
|
export const styles = theme => ({
|
15
17
|
root: {
|
16
18
|
backgroundColor: theme.palette.background2,
|
@@ -28,6 +30,9 @@ export const styles = theme => ({
|
|
28
30
|
borderRadius: '0px 2px',
|
29
31
|
maxHeight: 440,
|
30
32
|
transition: 'none'
|
33
|
+
},
|
34
|
+
alignRight: {
|
35
|
+
right: 0
|
31
36
|
}
|
32
37
|
});
|
33
38
|
|
@@ -60,13 +65,20 @@ class HiSuggestSelect extends React.PureComponent {
|
|
60
65
|
|
61
66
|
this.handleKeyDown = event => {
|
62
67
|
let nextItem;
|
68
|
+
const key = keycode(event);
|
63
69
|
|
64
|
-
if (
|
70
|
+
if (key === 'down') {
|
71
|
+
event.preventDefault();
|
65
72
|
nextItem = getNextItemSelectable(document.activeElement, 'down');
|
66
|
-
} else if (
|
73
|
+
} else if (key === 'up') {
|
74
|
+
event.preventDefault();
|
67
75
|
nextItem = getNextItemSelectable(document.activeElement, 'up');
|
68
|
-
} else if (
|
76
|
+
} else if (key === 'tab') {
|
69
77
|
document.body.style.overflow = 'auto';
|
78
|
+
} else if (key === 'escape' || 'enter') {
|
79
|
+
event.preventDefault();
|
80
|
+
const item = this.props.options.find(elem => String(elem.id) === event.target.id);
|
81
|
+
this.handleSelect(null, item);
|
70
82
|
}
|
71
83
|
|
72
84
|
if (nextItem) {
|
@@ -139,9 +151,10 @@ class HiSuggestSelect extends React.PureComponent {
|
|
139
151
|
showMinLength,
|
140
152
|
showNoResults,
|
141
153
|
onSearch,
|
142
|
-
translations
|
154
|
+
translations,
|
155
|
+
align
|
143
156
|
} = _this$props,
|
144
|
-
otherProps = _objectWithoutProperties(_this$props, ["classes", "id", "loading", "showMinLength", "showNoResults", "onSearch", "translations"]);
|
157
|
+
otherProps = _objectWithoutProperties(_this$props, ["classes", "id", "loading", "showMinLength", "showNoResults", "onSearch", "translations", "align"]);
|
145
158
|
|
146
159
|
const {
|
147
160
|
focused,
|
@@ -188,7 +201,9 @@ class HiSuggestSelect extends React.PureComponent {
|
|
188
201
|
disablePortal: true,
|
189
202
|
anchorEl: this.textInput,
|
190
203
|
placement: "bottom-start",
|
191
|
-
className: classes.popper,
|
204
|
+
className: classNames(classes.popper, {
|
205
|
+
[classes.alignRight]: align === 'right'
|
206
|
+
}),
|
192
207
|
open: true
|
193
208
|
}, React.createElement(Grow, {
|
194
209
|
in: open,
|
@@ -211,6 +226,7 @@ class HiSuggestSelect extends React.PureComponent {
|
|
211
226
|
}
|
212
227
|
|
213
228
|
HiSuggestSelect.defaultProps = {
|
229
|
+
align: 'left',
|
214
230
|
showMinLength: false,
|
215
231
|
showNoResults: false,
|
216
232
|
translations: {
|
@@ -220,6 +236,11 @@ HiSuggestSelect.defaultProps = {
|
|
220
236
|
options: []
|
221
237
|
};
|
222
238
|
HiSuggestSelect.propTypes = process.env.NODE_ENV !== "production" ? {
|
239
|
+
/**
|
240
|
+
* Align popper on right or left of container
|
241
|
+
*/
|
242
|
+
align: PropTypes.oneOf(['left', 'right']),
|
243
|
+
|
223
244
|
/**
|
224
245
|
* Useful to extend the style applied to components.
|
225
246
|
*/
|
@@ -175,7 +175,6 @@ class HiNestedSelectContent extends React.PureComponent {
|
|
175
175
|
|
176
176
|
this.buildSelectProps = (options, value = [], search = '', loading = false) => {
|
177
177
|
const {
|
178
|
-
classes,
|
179
178
|
disabledParent,
|
180
179
|
hasAll,
|
181
180
|
iconAll,
|
@@ -291,6 +290,11 @@ HiNestedSelectContent.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
291
290
|
*/
|
292
291
|
hasAll: PropTypes.bool,
|
293
292
|
|
293
|
+
/**
|
294
|
+
* Propriétés du composant HiSelectableList
|
295
|
+
*/
|
296
|
+
hiSelectableListProps: PropTypes.object,
|
297
|
+
|
294
298
|
/**
|
295
299
|
* id du select
|
296
300
|
*/
|
@@ -15,7 +15,7 @@ import withStyles from '../styles/withStyles';
|
|
15
15
|
import { getNextItemSelectable, foldAccents } from '../utils/helpers';
|
16
16
|
import HiIcon from '../HiIcon';
|
17
17
|
import keycode from 'keycode';
|
18
|
-
import classNames from
|
18
|
+
import classNames from 'classnames';
|
19
19
|
export const styles = theme => ({
|
20
20
|
root: {
|
21
21
|
backgroundColor: theme.palette.background2,
|
@@ -85,6 +85,97 @@ class HiSelect extends React.PureComponent {
|
|
85
85
|
constructor(props) {
|
86
86
|
super(props);
|
87
87
|
|
88
|
+
this.buildSelectProps = (options, value = [], search = '', loading = false) => {
|
89
|
+
// build item list
|
90
|
+
const itemList = [...(loading ? [{
|
91
|
+
id: '_loading',
|
92
|
+
type: 'loader',
|
93
|
+
disabled: true,
|
94
|
+
centered: true,
|
95
|
+
hideCheckbox: true,
|
96
|
+
label: 'loading'
|
97
|
+
}] : []), // simple one level filter on label
|
98
|
+
...(search !== '' ? [...options.filter(item => item.label && foldAccents(item.label.toString().toLowerCase()).search(foldAccents(search.toLowerCase())) !== -1)] : [...(this.props.hasAll ? [_objectSpread({
|
99
|
+
id: '_all',
|
100
|
+
label: this.props.translations.all
|
101
|
+
}, this.props.iconAll && {
|
102
|
+
type: 'icon',
|
103
|
+
icon: this.props.iconAll
|
104
|
+
})] : []), ...options])];
|
105
|
+
return {
|
106
|
+
itemList,
|
107
|
+
inputValue: this.buildInputValue(options, value, loading)
|
108
|
+
};
|
109
|
+
};
|
110
|
+
|
111
|
+
this.buildInputValue = (options, value = [], loading = false) => {
|
112
|
+
const {
|
113
|
+
classes,
|
114
|
+
hasAll,
|
115
|
+
translations,
|
116
|
+
type
|
117
|
+
} = this.props; // build input value
|
118
|
+
|
119
|
+
let inputValue;
|
120
|
+
|
121
|
+
if (loading && value.length === 1) {
|
122
|
+
inputValue = translations.one_item_selected;
|
123
|
+
} else if (hasAll && options.length === value.length) {
|
124
|
+
inputValue = translations.all;
|
125
|
+
value.unshift('_all');
|
126
|
+
} else if (value.length > 1) {
|
127
|
+
inputValue = translations.n_items_selected.replace('%s', value.length);
|
128
|
+
} else if (value.length === 1) {
|
129
|
+
const item = options.find(o => o.id === value[0]);
|
130
|
+
|
131
|
+
if (item === undefined) {
|
132
|
+
inputValue = translations.one_item_selected;
|
133
|
+
} else if (type === 'icon' || item.type === 'icon') {
|
134
|
+
inputValue = React.createElement("span", {
|
135
|
+
className: classes.selectIconLabel
|
136
|
+
}, React.createElement(HiIcon, {
|
137
|
+
className: classes.labelIcon,
|
138
|
+
icon: item.icon
|
139
|
+
}), item.label);
|
140
|
+
} else if (type === 'image' || item.type === 'image') {
|
141
|
+
inputValue = React.createElement("span", {
|
142
|
+
className: classes.selectIconLabel
|
143
|
+
}, React.createElement("img", {
|
144
|
+
className: classes.labelImg,
|
145
|
+
src: item.img,
|
146
|
+
alt: item.label
|
147
|
+
}), item.label);
|
148
|
+
} else {
|
149
|
+
inputValue = item.label;
|
150
|
+
}
|
151
|
+
}
|
152
|
+
|
153
|
+
return inputValue;
|
154
|
+
};
|
155
|
+
|
156
|
+
this.focusOnFirstItem = () => {
|
157
|
+
const overlay = findDOMNode(this.overlay);
|
158
|
+
setTimeout(() => {
|
159
|
+
const item = overlay.getElementsByTagName('li')[0];
|
160
|
+
item.focus();
|
161
|
+
}, 1);
|
162
|
+
};
|
163
|
+
|
164
|
+
this.getInputElement = el => {
|
165
|
+
this.searchField = el;
|
166
|
+
|
167
|
+
if (this.props.inputRef) {
|
168
|
+
this.props.inputRef(this.searchField);
|
169
|
+
}
|
170
|
+
};
|
171
|
+
|
172
|
+
this.handleBlur = () => {
|
173
|
+
this.handleSearchReset();
|
174
|
+
this.setState({
|
175
|
+
focused: false
|
176
|
+
});
|
177
|
+
};
|
178
|
+
|
88
179
|
this.handleClick = () => {
|
89
180
|
if (this.state.open) {
|
90
181
|
this.handleClose();
|
@@ -96,20 +187,58 @@ class HiSelect extends React.PureComponent {
|
|
96
187
|
if (this.props.onClick) this.props.onClick(); // Gestion du focus
|
97
188
|
|
98
189
|
if (!this.props.searchable) {
|
99
|
-
//
|
100
|
-
this.
|
190
|
+
// Sinon focus sur l'élément sélectionné
|
191
|
+
this.focusOnSelectedItem(this.props.value);
|
101
192
|
}
|
102
193
|
}
|
103
194
|
};
|
104
195
|
|
105
|
-
this.
|
196
|
+
this.focusOnSelectedItem = selectedValue => {
|
106
197
|
const overlay = findDOMNode(this.overlay);
|
107
198
|
setTimeout(() => {
|
108
|
-
|
109
|
-
item.
|
199
|
+
// On initialise au premier élément pour être sûr de ne pas se retrouver avec un focus of undefined
|
200
|
+
let item = overlay.getElementsByTagName('li')[0];
|
201
|
+
|
202
|
+
if (selectedValue && typeof selectedValue === 'string') {
|
203
|
+
item = overlay.getElementsByTagName('li')[selectedValue];
|
204
|
+
} else if (selectedValue && typeof selectedValue === 'number') {
|
205
|
+
item = overlay.getElementsByTagName('li')[selectedValue - 1];
|
206
|
+
}
|
207
|
+
|
208
|
+
if (item) {
|
209
|
+
item.focus();
|
210
|
+
}
|
110
211
|
}, 1);
|
111
212
|
};
|
112
213
|
|
214
|
+
this.handleClickAway = event => {
|
215
|
+
// Au clic sur le bouton, on laisse le handleClick fermer le select
|
216
|
+
if (!this.inputEl.contains(event.target)) {
|
217
|
+
this.handleClose(event);
|
218
|
+
}
|
219
|
+
};
|
220
|
+
|
221
|
+
this.handleClose = () => {
|
222
|
+
this.handleSearchReset();
|
223
|
+
this.setState({
|
224
|
+
open: false
|
225
|
+
});
|
226
|
+
|
227
|
+
if (this.props.onClose) {
|
228
|
+
this.props.onClose();
|
229
|
+
}
|
230
|
+
|
231
|
+
if (this.inputEl) {
|
232
|
+
this.inputEl.focus();
|
233
|
+
}
|
234
|
+
};
|
235
|
+
|
236
|
+
this.handleFocus = () => {
|
237
|
+
this.setState({
|
238
|
+
focused: true
|
239
|
+
});
|
240
|
+
};
|
241
|
+
|
113
242
|
this.handleKeyDown = event => {
|
114
243
|
let nextItem;
|
115
244
|
const key = keycode(event);
|
@@ -149,36 +278,9 @@ class HiSelect extends React.PureComponent {
|
|
149
278
|
}
|
150
279
|
};
|
151
280
|
|
152
|
-
this.
|
153
|
-
|
154
|
-
|
155
|
-
});
|
156
|
-
};
|
157
|
-
|
158
|
-
this.handleBlur = () => {
|
159
|
-
this.setState({
|
160
|
-
focused: false
|
161
|
-
});
|
162
|
-
};
|
163
|
-
|
164
|
-
this.handleClose = () => {
|
165
|
-
this.setState({
|
166
|
-
open: false
|
167
|
-
});
|
168
|
-
|
169
|
-
if (this.props.onClose) {
|
170
|
-
this.props.onClose();
|
171
|
-
}
|
172
|
-
|
173
|
-
if (this.inputEl) {
|
174
|
-
this.inputEl.focus();
|
175
|
-
}
|
176
|
-
};
|
177
|
-
|
178
|
-
this.handleClickAway = event => {
|
179
|
-
// Au clic sur le bouton, on laisse le handleClick fermer le select
|
180
|
-
if (!this.inputEl.contains(event.target)) {
|
181
|
-
this.handleClose(event);
|
281
|
+
this.handleScroll = e => {
|
282
|
+
if (e.target.scrollHeight - e.target.clientHeight - e.target.scrollTop < 15) {
|
283
|
+
this.props.onScrollReachBottom();
|
182
284
|
}
|
183
285
|
};
|
184
286
|
|
@@ -244,12 +346,6 @@ class HiSelect extends React.PureComponent {
|
|
244
346
|
}
|
245
347
|
};
|
246
348
|
|
247
|
-
this.handleScroll = e => {
|
248
|
-
if (e.target.scrollHeight - e.target.clientHeight - e.target.scrollTop < 15) {
|
249
|
-
this.props.onScrollReachBottom();
|
250
|
-
}
|
251
|
-
};
|
252
|
-
|
253
349
|
this.handleSearch = (e, inputValue) => {
|
254
350
|
const searchValue = inputValue && e.target.value ? inputValue : e.target.value;
|
255
351
|
|
@@ -270,74 +366,6 @@ class HiSelect extends React.PureComponent {
|
|
270
366
|
}, '');
|
271
367
|
};
|
272
368
|
|
273
|
-
this.buildSelectProps = (options, value = [], search = '', loading = false) => {
|
274
|
-
// build item list
|
275
|
-
const itemList = [...(loading ? [{
|
276
|
-
id: '_loading',
|
277
|
-
type: 'loader',
|
278
|
-
disabled: true,
|
279
|
-
centered: true,
|
280
|
-
hideCheckbox: true,
|
281
|
-
label: 'loading'
|
282
|
-
}] : []), // simple one level filter on label
|
283
|
-
...(search !== '' ? [...options.filter(item => item.label && foldAccents(item.label.toString().toLowerCase()).search(foldAccents(search.toLowerCase())) !== -1)] : [...(this.props.hasAll ? [_objectSpread({
|
284
|
-
id: '_all',
|
285
|
-
label: this.props.translations.all
|
286
|
-
}, this.props.iconAll && {
|
287
|
-
type: 'icon',
|
288
|
-
icon: this.props.iconAll
|
289
|
-
})] : []), ...options])];
|
290
|
-
return {
|
291
|
-
itemList,
|
292
|
-
inputValue: this.buildInputValue(options, value, loading)
|
293
|
-
};
|
294
|
-
};
|
295
|
-
|
296
|
-
this.buildInputValue = (options, value = [], loading = false) => {
|
297
|
-
const {
|
298
|
-
classes,
|
299
|
-
hasAll,
|
300
|
-
translations,
|
301
|
-
type
|
302
|
-
} = this.props; // build input value
|
303
|
-
|
304
|
-
let inputValue;
|
305
|
-
|
306
|
-
if (loading && value.length === 1) {
|
307
|
-
inputValue = translations.one_item_selected;
|
308
|
-
} else if (hasAll && options.length === value.length) {
|
309
|
-
inputValue = translations.all;
|
310
|
-
value.unshift('_all');
|
311
|
-
} else if (value.length > 1) {
|
312
|
-
inputValue = translations.n_items_selected.replace('%s', value.length);
|
313
|
-
} else if (value.length === 1) {
|
314
|
-
const item = options.find(o => o.id === value[0]);
|
315
|
-
|
316
|
-
if (item === undefined) {
|
317
|
-
inputValue = translations.one_item_selected;
|
318
|
-
} else if (type === 'icon' || item.type === 'icon') {
|
319
|
-
inputValue = React.createElement("span", {
|
320
|
-
className: classes.selectIconLabel
|
321
|
-
}, React.createElement(HiIcon, {
|
322
|
-
className: classes.labelIcon,
|
323
|
-
icon: item.icon
|
324
|
-
}), item.label);
|
325
|
-
} else if (type === 'image' || item.type === 'image') {
|
326
|
-
inputValue = React.createElement("span", {
|
327
|
-
className: classes.selectIconLabel
|
328
|
-
}, React.createElement("img", {
|
329
|
-
className: classes.labelImg,
|
330
|
-
src: item.img,
|
331
|
-
alt: item.label
|
332
|
-
}), item.label);
|
333
|
-
} else {
|
334
|
-
inputValue = item.label;
|
335
|
-
}
|
336
|
-
}
|
337
|
-
|
338
|
-
return inputValue;
|
339
|
-
};
|
340
|
-
|
341
369
|
this.state = {
|
342
370
|
open: false,
|
343
371
|
focused: false,
|
@@ -365,14 +393,15 @@ class HiSelect extends React.PureComponent {
|
|
365
393
|
|
366
394
|
return null;
|
367
395
|
}
|
396
|
+
/**
|
397
|
+
* Build itemList & inputValue from select props
|
398
|
+
* @param options
|
399
|
+
* @param value
|
400
|
+
* @param search
|
401
|
+
* @param loading
|
402
|
+
* @returns {{itemList: *[], inputValue: *}}
|
403
|
+
*/
|
368
404
|
|
369
|
-
getInputElement(el) {
|
370
|
-
this.searchField = el;
|
371
|
-
|
372
|
-
if (this.props.inputRef) {
|
373
|
-
this.props.inputRef(this.searchField);
|
374
|
-
}
|
375
|
-
}
|
376
405
|
|
377
406
|
render() {
|
378
407
|
const {
|
@@ -387,6 +416,7 @@ class HiSelect extends React.PureComponent {
|
|
387
416
|
value,
|
388
417
|
multiple,
|
389
418
|
translations,
|
419
|
+
hiSearchInputProps,
|
390
420
|
hiSelectableListProps,
|
391
421
|
hiSelectInputProps,
|
392
422
|
id,
|
@@ -446,7 +476,7 @@ class HiSelect extends React.PureComponent {
|
|
446
476
|
}
|
447
477
|
}, React.createElement(Paper, {
|
448
478
|
className: classes.paper
|
449
|
-
}, !!searchable && React.createElement(HiInput, {
|
479
|
+
}, !!searchable && React.createElement(HiInput, _extends({
|
450
480
|
value: searchValue,
|
451
481
|
autoFocus: true,
|
452
482
|
inputRef: this.getInputElement,
|
@@ -456,7 +486,7 @@ class HiSelect extends React.PureComponent {
|
|
456
486
|
placeholder: translations.search,
|
457
487
|
startAdornment: 'search',
|
458
488
|
tabIndex: 0
|
459
|
-
}), startAdornment, React.createElement(Scrollbars, _extends({
|
489
|
+
}, hiSearchInputProps)), startAdornment, React.createElement(Scrollbars, _extends({
|
460
490
|
ref: contentEl => {
|
461
491
|
this.optionsContent = contentEl;
|
462
492
|
},
|
@@ -522,6 +552,7 @@ HiSelect.defaultProps = {
|
|
522
552
|
hasAll: false,
|
523
553
|
hiSelectableListProps: {},
|
524
554
|
hiSelectInputProps: {},
|
555
|
+
hiSearchInputProps: {},
|
525
556
|
multiple: false,
|
526
557
|
placeholder: '',
|
527
558
|
searchable: false,
|
@@ -576,7 +607,12 @@ HiSelect.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
576
607
|
hasAll: PropTypes.bool,
|
577
608
|
|
578
609
|
/**
|
579
|
-
* Override
|
610
|
+
* Override HiInput props (for search)
|
611
|
+
*/
|
612
|
+
hiSearchInputProps: PropTypes.object,
|
613
|
+
|
614
|
+
/**
|
615
|
+
* Override HiSelectableList props
|
580
616
|
*/
|
581
617
|
hiSelectableListProps: PropTypes.object,
|
582
618
|
|
@@ -7,7 +7,6 @@ import HiSelectableList from '../HiSelectableList';
|
|
7
7
|
import HiInput from '../HiForm/HiInput';
|
8
8
|
import withStyles from '../styles/withStyles';
|
9
9
|
import { getNextItemSelectable, foldAccents } from '../utils/helpers';
|
10
|
-
import HiIcon from '../HiIcon';
|
11
10
|
import keycode from 'keycode';
|
12
11
|
export const styles = theme => ({
|
13
12
|
labelIcon: {
|
@@ -243,9 +242,6 @@ class HiSelectContent extends React.PureComponent {
|
|
243
242
|
|
244
243
|
render() {
|
245
244
|
const {
|
246
|
-
classes,
|
247
|
-
disabled,
|
248
|
-
error,
|
249
245
|
loading,
|
250
246
|
options,
|
251
247
|
searchable,
|
@@ -254,10 +250,7 @@ class HiSelectContent extends React.PureComponent {
|
|
254
250
|
multiple,
|
255
251
|
translations,
|
256
252
|
hiSelectableListProps,
|
257
|
-
hiSelectInputProps,
|
258
|
-
id,
|
259
253
|
onScrollReachBottom,
|
260
|
-
onSubmit,
|
261
254
|
startAdornment,
|
262
255
|
searchValue = this.state.searchValue,
|
263
256
|
buildSelectProps = this.buildSelectProps,
|