@hipay/hipay-material-ui 2.0.0-beta.61 → 2.0.0-beta.62
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +66 -0
- package/HiDatePicker/HiDateRangeSelector.js +1 -1
- package/{HiSelectNew → HiSelect}/HiDynamicSelect.js +3 -3
- package/{HiSelectNew → HiSelect}/HiNestedSelect.js +9 -9
- package/{HiSelectNew → HiSelect}/HiNestedSelectContent.js +9 -9
- package/HiSelect/HiSelect.js +489 -607
- package/{HiSelectNew → HiSelect}/HiSelectContent.js +7 -7
- package/HiSelect/index.js +41 -3
- package/HiSelectableList/HiSelectableList.js +59 -3
- package/HiSelectableList/HiSelectableListItem.js +22 -10
- package/README.md +15 -0
- package/es/HiDatePicker/HiDateRangeSelector.js +1 -1
- package/es/{HiSelectNew → HiSelect}/HiNestedSelect.js +1 -1
- package/es/{HiSelectNew → HiSelect}/HiNestedSelectContent.js +1 -1
- package/es/HiSelect/HiSelect.js +441 -564
- package/es/{HiSelectNew → HiSelect}/HiSelectContent.js +1 -1
- package/es/HiSelect/index.js +4 -1
- package/es/HiSelectableList/HiSelectableList.js +56 -4
- package/es/HiSelectableList/HiSelectableListItem.js +18 -10
- package/index.es.js +1 -1
- package/index.js +1 -1
- package/package.json +3 -2
- package/umd/hipay-material-ui.development.js +41669 -39595
- package/umd/hipay-material-ui.production.min.js +2 -2
- package/HiSelect/SelectInput.js +0 -369
- package/HiSelectNew/HiSelect.js +0 -929
- package/HiSelectNew/HiSelectField.js +0 -146
- package/HiSelectNew/index.js +0 -69
- package/es/HiSelect/SelectInput.js +0 -321
- package/es/HiSelectNew/HiSelect.js +0 -852
- package/es/HiSelectNew/HiSelectField.js +0 -111
- package/es/HiSelectNew/index.js +0 -6
- /package/{HiSelectNew → HiSelect}/HiDynamicSelectField.js +0 -0
- /package/{HiSelectNew → HiSelect}/HiNestedSelectField.js +0 -0
- /package/{HiSelectNew → HiSelect}/HiSelectInput.js +0 -0
- /package/es/{HiSelectNew → HiSelect}/HiDynamicSelect.js +0 -0
- /package/es/{HiSelectNew → HiSelect}/HiDynamicSelectField.js +0 -0
- /package/es/{HiSelectNew → HiSelect}/HiNestedSelectField.js +0 -0
- /package/es/{HiSelectNew → HiSelect}/HiSelectInput.js +0 -0
package/HiSelect/HiSelect.js
CHANGED
@@ -5,14 +5,12 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
6
6
|
value: true
|
7
7
|
});
|
8
|
-
exports.default = exports.styles =
|
8
|
+
exports.default = exports.styles = void 0;
|
9
9
|
|
10
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
11
11
|
|
12
12
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
13
13
|
|
14
|
-
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
15
|
-
|
16
14
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
17
15
|
|
18
16
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
@@ -23,43 +21,39 @@ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/ge
|
|
23
21
|
|
24
22
|
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
25
23
|
|
24
|
+
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
25
|
+
|
26
26
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
27
27
|
|
28
28
|
var _react = _interopRequireDefault(require("react"));
|
29
29
|
|
30
30
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
31
31
|
|
32
|
-
var
|
32
|
+
var _reactCustomScrollbars = _interopRequireDefault(require("react-custom-scrollbars"));
|
33
33
|
|
34
34
|
var _Grow = _interopRequireDefault(require("@material-ui/core/Grow"));
|
35
35
|
|
36
|
-
var _reactDom = require("react-dom");
|
37
|
-
|
38
|
-
var _reactCustomScrollbars = _interopRequireDefault(require("react-custom-scrollbars"));
|
39
|
-
|
40
36
|
var _Paper = _interopRequireDefault(require("@material-ui/core/Paper"));
|
41
37
|
|
42
|
-
var _ClickAwayListener = _interopRequireDefault(require("@material-ui/core/ClickAwayListener"));
|
43
|
-
|
44
38
|
var _Popper = _interopRequireDefault(require("@material-ui/core/Popper"));
|
45
39
|
|
46
|
-
var
|
40
|
+
var _ClickAwayListener = _interopRequireDefault(require("@material-ui/core/ClickAwayListener"));
|
47
41
|
|
48
|
-
var
|
42
|
+
var _HiSelectableList = _interopRequireDefault(require("../HiSelectableList"));
|
49
43
|
|
50
|
-
var
|
44
|
+
var _HiInput = _interopRequireDefault(require("../HiForm/HiInput"));
|
51
45
|
|
52
|
-
var
|
46
|
+
var _HiSelectInput = _interopRequireDefault(require("./HiSelectInput"));
|
53
47
|
|
54
|
-
var
|
48
|
+
var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
|
55
49
|
|
56
50
|
var _helpers = require("../utils/helpers");
|
57
51
|
|
58
52
|
var _HiIcon = _interopRequireDefault(require("../HiIcon"));
|
59
53
|
|
60
|
-
|
61
|
-
|
62
|
-
|
54
|
+
var _keycode = _interopRequireDefault(require("keycode"));
|
55
|
+
|
56
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
63
57
|
|
64
58
|
var styles = function styles(theme) {
|
65
59
|
return {
|
@@ -75,14 +69,24 @@ var styles = function styles(theme) {
|
|
75
69
|
popperWidth: {
|
76
70
|
width: '100% !important'
|
77
71
|
},
|
72
|
+
popperRightAlign: {
|
73
|
+
right: 0,
|
74
|
+
left: 'unset!important'
|
75
|
+
},
|
78
76
|
paper: {
|
79
77
|
borderRadius: '0px 2px',
|
80
|
-
maxHeight:
|
78
|
+
maxHeight: 480,
|
81
79
|
transition: 'none !important'
|
82
80
|
},
|
83
81
|
labelIcon: {
|
84
82
|
marginRight: 10
|
85
83
|
},
|
84
|
+
labelImg: {
|
85
|
+
height: 18,
|
86
|
+
width: 'auto',
|
87
|
+
margin: '0 4px',
|
88
|
+
verticalAlign: 'middle'
|
89
|
+
},
|
86
90
|
selectIconLabel: (0, _extends2.default)({
|
87
91
|
whiteSpace: 'nowrap',
|
88
92
|
overflow: 'hidden',
|
@@ -91,9 +95,27 @@ var styles = function styles(theme) {
|
|
91
95
|
}, theme.typography.b1, {
|
92
96
|
display: 'inline-flex',
|
93
97
|
width: '100%'
|
94
|
-
})
|
98
|
+
}),
|
99
|
+
selectImgLabel: (0, _extends2.default)({
|
100
|
+
whiteSpace: 'nowrap',
|
101
|
+
overflow: 'hidden',
|
102
|
+
textOverflow: 'ellipsis',
|
103
|
+
paddingRight: 16
|
104
|
+
}, theme.typography.b1, {
|
105
|
+
display: 'inline-flex',
|
106
|
+
width: '100%'
|
107
|
+
}),
|
108
|
+
separator: {
|
109
|
+
borderTop: "1px solid ".concat(theme.palette.input.bottomLine)
|
110
|
+
}
|
95
111
|
};
|
96
112
|
};
|
113
|
+
|
114
|
+
exports.styles = styles;
|
115
|
+
|
116
|
+
function filterValue(item, search) {
|
117
|
+
return search === '' || (0, _helpers.foldAccents)(item.label.toString().toLowerCase()).search((0, _helpers.foldAccents)(search.toLowerCase())) !== -1;
|
118
|
+
}
|
97
119
|
/**
|
98
120
|
*
|
99
121
|
* Utilisé pour tous types de selects dans les formulaires.
|
@@ -102,90 +124,129 @@ var styles = function styles(theme) {
|
|
102
124
|
* - avec / sans barre de recherche
|
103
125
|
* - avec / sans option "All"
|
104
126
|
* - prise en compte du type des éléments (text, image, icon, ...)
|
127
|
+
* - les actions du clavier son capturés avec KeyDown
|
105
128
|
*
|
106
129
|
* Ce composant réuni les sous-composants
|
107
|
-
* -
|
108
|
-
* - HiSearchField : intègre une barre de recherche dans le Popper,
|
109
|
-
* il filtre la liste des suggestions
|
130
|
+
* - HiSelectInput : affiche l'élément dans le formulaire
|
131
|
+
* - HiSearchField : intègre une barre de recherche dans le Popper, il filtre la liste des suggestions
|
110
132
|
* - HiSelectableList : affiche la liste des suggestions selon le type des éléments
|
111
133
|
*/
|
112
134
|
|
113
135
|
|
114
|
-
exports.styles = styles;
|
115
|
-
|
116
136
|
var HiSelect =
|
117
137
|
/*#__PURE__*/
|
118
138
|
function (_React$PureComponent) {
|
119
139
|
(0, _inherits2.default)(HiSelect, _React$PureComponent);
|
120
140
|
|
121
|
-
function HiSelect(
|
141
|
+
function HiSelect(props) {
|
122
142
|
var _this;
|
123
143
|
|
124
144
|
(0, _classCallCheck2.default)(this, HiSelect);
|
125
|
-
_this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(HiSelect).call(this,
|
126
|
-
|
127
|
-
_this.
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
var
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
145
|
+
_this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(HiSelect).call(this, props));
|
146
|
+
|
147
|
+
_this.buildSelectProps = function (options) {
|
148
|
+
var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
149
|
+
var search = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
150
|
+
var loading = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
151
|
+
// build item list
|
152
|
+
var itemList = [].concat((0, _toConsumableArray2.default)(loading ? [{
|
153
|
+
id: '_loading',
|
154
|
+
type: 'loader',
|
155
|
+
disabled: true,
|
156
|
+
centered: true,
|
157
|
+
hideCheckbox: true,
|
158
|
+
label: 'loading'
|
159
|
+
}] : []), (0, _toConsumableArray2.default)(search !== '' ? (0, _toConsumableArray2.default)(options.filter(function (item) {
|
160
|
+
return _this.props.filterFunc(item, search);
|
161
|
+
})) : [].concat((0, _toConsumableArray2.default)(_this.props.hasAll ? [(0, _extends2.default)({
|
162
|
+
id: '_all',
|
163
|
+
label: _this.props.translations.all
|
164
|
+
}, _this.props.iconAll && {
|
165
|
+
type: 'icon',
|
166
|
+
icon: _this.props.iconAll
|
167
|
+
})] : []), (0, _toConsumableArray2.default)(options))));
|
147
168
|
return {
|
148
|
-
|
149
|
-
|
169
|
+
itemList: itemList,
|
170
|
+
inputValue: _this.buildInputValue(options, value, loading)
|
150
171
|
};
|
151
172
|
};
|
152
173
|
|
153
|
-
_this.
|
154
|
-
|
155
|
-
var
|
156
|
-
var
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
174
|
+
_this.buildInputValue = function (options) {
|
175
|
+
var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
176
|
+
var loading = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
177
|
+
var _this$props = _this.props,
|
178
|
+
classes = _this$props.classes,
|
179
|
+
hasAll = _this$props.hasAll,
|
180
|
+
translations = _this$props.translations,
|
181
|
+
type = _this$props.type; // build input value
|
182
|
+
|
183
|
+
var inputValue;
|
184
|
+
|
185
|
+
if (loading && value.length === 1) {
|
186
|
+
inputValue = translations.one_item_selected;
|
187
|
+
} else if (hasAll && options.length === value.length) {
|
188
|
+
inputValue = translations.all;
|
189
|
+
value.unshift('_all');
|
190
|
+
} else if (value.length > 1) {
|
191
|
+
inputValue = translations.n_items_selected.replace('%s', value.length);
|
192
|
+
} else if (value.length === 1) {
|
193
|
+
var item = options.find(function (o) {
|
194
|
+
return o.id === value[0];
|
195
|
+
});
|
170
196
|
|
197
|
+
if (item === undefined) {
|
198
|
+
inputValue = translations.one_item_selected;
|
199
|
+
} else if (type === 'icon' || item.type === 'icon') {
|
200
|
+
inputValue = _react.default.createElement("span", {
|
201
|
+
className: classes.selectIconLabel
|
202
|
+
}, _react.default.createElement(_HiIcon.default, {
|
203
|
+
className: classes.labelIcon,
|
204
|
+
icon: item.icon
|
205
|
+
}), item.label);
|
206
|
+
} else if (type === 'image' || item.type === 'image') {
|
207
|
+
inputValue = _react.default.createElement("span", {
|
208
|
+
className: classes.selectIconLabel
|
209
|
+
}, _react.default.createElement("img", {
|
210
|
+
className: classes.labelImg,
|
211
|
+
src: item.img,
|
212
|
+
alt: item.label,
|
213
|
+
onError: function onError(e) {
|
214
|
+
if (item.fallbackImage) {
|
215
|
+
e.target.src = "".concat(item.fallbackImage);
|
216
|
+
} else {
|
217
|
+
e.target.style.display = 'none';
|
218
|
+
}
|
219
|
+
}
|
220
|
+
}), item.label);
|
221
|
+
} else {
|
222
|
+
inputValue = item.label;
|
223
|
+
}
|
224
|
+
}
|
171
225
|
|
172
|
-
|
173
|
-
|
174
|
-
var items = overlay.getElementsByTagName('li');
|
175
|
-
var itemToFocus = items[0]; // Si select multiple, et qu'au moins un selectionné, focus sur le 2e item
|
226
|
+
return inputValue;
|
227
|
+
};
|
176
228
|
|
177
|
-
|
178
|
-
|
179
|
-
|
229
|
+
_this.focusOnFirstItem = function () {
|
230
|
+
if (_this.overlay && _this.overlay.getElementsByTagName('li')[0]) {
|
231
|
+
setTimeout(function () {
|
232
|
+
var item = _this.overlay.getElementsByTagName('li')[0];
|
180
233
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
234
|
+
item.focus();
|
235
|
+
}, 1);
|
236
|
+
}
|
237
|
+
};
|
238
|
+
|
239
|
+
_this.getInputElement = function (el) {
|
240
|
+
_this.searchField = el;
|
241
|
+
|
242
|
+
if (_this.props.inputRef) {
|
243
|
+
_this.props.inputRef(_this.searchField);
|
244
|
+
}
|
186
245
|
};
|
187
246
|
|
188
247
|
_this.handleBlur = function () {
|
248
|
+
_this.handleSearchReset();
|
249
|
+
|
189
250
|
_this.setState({
|
190
251
|
focused: false
|
191
252
|
});
|
@@ -199,41 +260,57 @@ function (_React$PureComponent) {
|
|
199
260
|
open: true
|
200
261
|
});
|
201
262
|
|
202
|
-
|
203
|
-
|
204
|
-
_this.handleSuggestions(options);
|
205
|
-
|
206
|
-
if (_this.props.onClick) {
|
207
|
-
_this.props.onClick();
|
208
|
-
} // Gestion du focus
|
263
|
+
_this.handleSuggestions(_this.props.options);
|
209
264
|
|
265
|
+
if (_this.props.onClick) _this.props.onClick(); // Gestion du focus
|
210
266
|
|
211
267
|
if (!_this.props.searchable) {
|
212
|
-
//
|
213
|
-
_this.focusOnSelectedItem();
|
268
|
+
// Sinon focus sur l'élément sélectionné
|
269
|
+
_this.focusOnSelectedItem(_this.props.value);
|
214
270
|
}
|
215
271
|
}
|
216
272
|
};
|
217
273
|
|
274
|
+
_this.focusOnSelectedItem = function (selectedValue) {
|
275
|
+
if (_this.overlay && _this.overlay.getElementsByTagName('li')[0]) {
|
276
|
+
setTimeout(function () {
|
277
|
+
// On initialise au premier élément pour être sûr de ne pas se retrouver avec un focus of undefined
|
278
|
+
var item = _this.overlay.getElementsByTagName('li')[0];
|
279
|
+
|
280
|
+
if (selectedValue && typeof selectedValue === 'string') {
|
281
|
+
item = _this.overlay.getElementsByTagName('li')[selectedValue];
|
282
|
+
} else if (selectedValue && typeof selectedValue === 'number') {
|
283
|
+
item = _this.overlay.getElementsByTagName('li')[selectedValue - 1];
|
284
|
+
}
|
285
|
+
|
286
|
+
if (item) {
|
287
|
+
item.focus();
|
288
|
+
}
|
289
|
+
}, 1);
|
290
|
+
}
|
291
|
+
};
|
292
|
+
|
218
293
|
_this.handleClickAway = function (event) {
|
219
294
|
// Au clic sur le bouton, on laisse le handleClick fermer le select
|
220
|
-
if (!_this.
|
295
|
+
if (!_this.inputEl.contains(event.target)) {
|
221
296
|
_this.handleClose(event);
|
222
297
|
}
|
223
298
|
};
|
224
299
|
|
225
300
|
_this.handleClose = function () {
|
301
|
+
_this.handleSearchReset();
|
302
|
+
|
303
|
+
_this.setState({
|
304
|
+
open: false
|
305
|
+
});
|
306
|
+
|
226
307
|
if (_this.props.onClose) {
|
227
308
|
_this.props.onClose();
|
228
309
|
}
|
229
310
|
|
230
|
-
if (_this.
|
231
|
-
_this.
|
311
|
+
if (_this.inputEl) {
|
312
|
+
_this.inputEl.focus();
|
232
313
|
}
|
233
|
-
|
234
|
-
_this.setState({
|
235
|
-
open: false
|
236
|
-
});
|
237
314
|
};
|
238
315
|
|
239
316
|
_this.handleFocus = function () {
|
@@ -242,428 +319,238 @@ function (_React$PureComponent) {
|
|
242
319
|
});
|
243
320
|
};
|
244
321
|
|
245
|
-
_this.
|
246
|
-
var
|
247
|
-
|
248
|
-
if (event.key === 'ArrowDown') {
|
249
|
-
nextItem = (0, _helpers.getNextItemSelectable)(document.activeElement, 'down');
|
250
|
-
} else if (event.key === 'ArrowUp') {
|
251
|
-
nextItem = (0, _helpers.getNextItemSelectable)(document.activeElement, 'up');
|
252
|
-
} else if (event.key === 'Tab' || event.key === 'Escape') {
|
253
|
-
/* if (!this.props.staticPosition) {
|
254
|
-
document.body.style.overflow = 'auto';
|
255
|
-
} */
|
256
|
-
_this.setState({
|
257
|
-
open: false
|
258
|
-
});
|
259
|
-
}
|
322
|
+
_this.handleKeyDownCapture = function (event) {
|
323
|
+
var key = (0, _keycode.default)(event);
|
260
324
|
|
261
|
-
if (
|
262
|
-
|
263
|
-
|
264
|
-
|
325
|
+
if (key === 'enter') {
|
326
|
+
if (_this.state.open) {
|
327
|
+
if (_this.props.multiple) {
|
328
|
+
event.stopPropagation();
|
265
329
|
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
} else if (event.key === 'Enter' && _this.props.onSubmit) {
|
270
|
-
_this.props.onSubmit(event);
|
271
|
-
} else if (event.key === 'Tab' || event.key === 'Escape') {
|
272
|
-
_this.setState({
|
273
|
-
open: false
|
274
|
-
});
|
330
|
+
_this.handleClose();
|
331
|
+
}
|
332
|
+
}
|
275
333
|
}
|
276
334
|
};
|
277
335
|
|
278
|
-
_this.
|
279
|
-
|
336
|
+
_this.handleKeyDown = function (event) {
|
337
|
+
var key = (0, _keycode.default)(event);
|
280
338
|
|
281
|
-
|
282
|
-
|
339
|
+
if (key === 'esc') {
|
340
|
+
event.preventDefault();
|
283
341
|
|
284
|
-
|
285
|
-
if (
|
286
|
-
|
342
|
+
_this.handleClose();
|
343
|
+
} else if (key === 'enter') {
|
344
|
+
if (_this.state.open) {
|
345
|
+
if (_this.props.multiple) {
|
346
|
+
_this.handleClose();
|
347
|
+
}
|
348
|
+
}
|
349
|
+
} else if (key === 'space') {
|
350
|
+
event.preventDefault();
|
287
351
|
|
288
|
-
_this.
|
352
|
+
if (_this.state.open) {
|
353
|
+
if (!_this.props.multiple) {
|
354
|
+
_this.setState({
|
355
|
+
open: false
|
356
|
+
});
|
357
|
+
}
|
358
|
+
} else {
|
359
|
+
_this.setState({
|
360
|
+
open: true
|
361
|
+
});
|
362
|
+
}
|
363
|
+
} else if (key === 'tab') {
|
364
|
+
_this.handleClose();
|
289
365
|
}
|
290
366
|
};
|
291
367
|
|
292
|
-
_this.
|
293
|
-
|
294
|
-
_this.props.loadMoreResults(_this.state.resultsPageNumber + 1);
|
368
|
+
_this.handleKeyDownSearch = function (event) {
|
369
|
+
var key = (0, _keycode.default)(event);
|
295
370
|
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
371
|
+
if (_this.overlay && (key === 'down' || key === 'up')) {
|
372
|
+
_this.focusOnFirstItem();
|
373
|
+
} else if (_this.overlay && key === 'esc' || key === 'enter') {
|
374
|
+
event.preventDefault();
|
375
|
+
|
376
|
+
_this.handleClose();
|
377
|
+
} else if (key === 'tab') {
|
378
|
+
_this.setState({
|
379
|
+
open: false
|
300
380
|
});
|
301
381
|
}
|
302
382
|
};
|
303
383
|
|
304
|
-
_this.
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
options = _this$props.options,
|
310
|
-
hierarchic = _this$props.hierarchic,
|
311
|
-
pinnedItem = _this$props.pinnedItem;
|
312
|
-
var _this$state = _this.state,
|
313
|
-
hierarchySelected = _this$state.hierarchySelected,
|
314
|
-
hierarchy = _this$state.hierarchy,
|
315
|
-
nbOptions = _this$state.nbOptions;
|
316
|
-
var hiSelected = (0, _extends2.default)({}, hierarchySelected);
|
317
|
-
|
318
|
-
if (multiple) {
|
319
|
-
var valueList = value;
|
384
|
+
_this.handleScroll = function (e) {
|
385
|
+
if (e.target.scrollHeight - e.target.clientHeight - e.target.scrollTop < 15) {
|
386
|
+
_this.props.onScrollReachBottom();
|
387
|
+
}
|
388
|
+
};
|
320
389
|
|
321
|
-
|
322
|
-
|
323
|
-
|
390
|
+
_this.handleSelect = function (event, item) {
|
391
|
+
var _this$props2 = _this.props,
|
392
|
+
hasAll = _this$props2.hasAll,
|
393
|
+
multiple = _this$props2.multiple,
|
394
|
+
onChange = _this$props2.onChange,
|
395
|
+
options = _this$props2.options,
|
396
|
+
value = _this$props2.value;
|
324
397
|
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
hiSelected[key] = [];
|
329
|
-
});
|
330
|
-
}
|
331
|
-
} else {
|
332
|
-
options.forEach(function (option) {
|
333
|
-
if (option.hasChildren !== true && !valueList.includes(option.id) && option.id !== '_all') {
|
334
|
-
valueList.push(option.id);
|
335
|
-
} else if (option.hasChildren === true) {
|
336
|
-
// if hierarchic select => fill associative array of selected children
|
337
|
-
hiSelected[option.id] = hierarchy[option.id];
|
338
|
-
}
|
339
|
-
});
|
340
|
-
}
|
341
|
-
} else if (valueList.includes(item.id) || item.hasChildren === true && hierarchySelected[item.id].length === hierarchy[item.id].length) {
|
342
|
-
// item déjà sélectionné => on le déselectionne
|
343
|
-
if (item.hasChildren !== true) {
|
344
|
-
valueList = valueList.filter(function (val) {
|
345
|
-
return val !== item.id;
|
346
|
-
});
|
347
|
-
}
|
398
|
+
if (!multiple) {
|
399
|
+
// single value
|
400
|
+
_this.handleClose();
|
348
401
|
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
hiSelected[item.id] = [];
|
355
|
-
} else if (item.hasOwnProperty('parentId')) {
|
356
|
-
// Si item est un enfant on l'enlève du tableau associatif des
|
357
|
-
// elmts sélectionnés
|
358
|
-
hiSelected[item.parentId].splice(hiSelected[item.parentId].indexOf(item.id), 1);
|
359
|
-
}
|
402
|
+
onChange(event, item.id, item);
|
403
|
+
} else if (hasAll && item.id === '_all') {
|
404
|
+
if (value.length === options.length) {
|
405
|
+
// unselect _all options
|
406
|
+
onChange(event, [], item);
|
360
407
|
} else {
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
});
|
366
|
-
valueList = [item.id];
|
367
|
-
} else {
|
368
|
-
// item non sélectionné => on le sélectionne
|
369
|
-
if (item.hasChildren !== true) valueList.push(item.id);
|
370
|
-
|
371
|
-
if (pinnedItem && valueList.includes(pinnedItem.id)) {
|
372
|
-
valueList.splice(valueList.indexOf(pinnedItem.id), 1);
|
373
|
-
}
|
374
|
-
}
|
375
|
-
|
376
|
-
if (item.hasChildren === true) {
|
377
|
-
// Si item parent => on ajoute tous les enfants
|
378
|
-
// Ou on les supprime s'ils sont déjà tous sélectionnés (dans une liste filtrée)
|
379
|
-
var idsInSuggestions = [];
|
380
|
-
|
381
|
-
_this.state.suggestions.forEach(function (suggestion) {
|
382
|
-
if (_this.state.hierarchy[item.id].includes(suggestion.id)) {
|
383
|
-
idsInSuggestions.push(suggestion.id);
|
384
|
-
}
|
385
|
-
}); // if(hierarchySelected[item.id].length > 0) {}
|
386
|
-
|
387
|
-
|
388
|
-
var allChildrenSuggestionsSelected = true;
|
389
|
-
idsInSuggestions.forEach(function (id) {
|
390
|
-
if (!hierarchySelected[item.id].includes(id)) {
|
391
|
-
allChildrenSuggestionsSelected = false;
|
392
|
-
}
|
393
|
-
});
|
394
|
-
|
395
|
-
if (allChildrenSuggestionsSelected === true) {
|
396
|
-
// On supprime les enfants car déjà tous sélectionnés
|
397
|
-
idsInSuggestions.forEach(function (id) {
|
398
|
-
valueList.splice(valueList.indexOf(id), 1);
|
399
|
-
hiSelected[item.id].splice(hiSelected[item.id].indexOf(id), 1);
|
400
|
-
});
|
401
|
-
} else {
|
402
|
-
// On ajoute tous les enfants filtrés au éléments sélectionnés
|
403
|
-
valueList = (0, _helpers.arrayUnique)(valueList.concat(idsInSuggestions));
|
404
|
-
hiSelected[item.id] = (0, _helpers.arrayUnique)(hiSelected[item.id].concat(idsInSuggestions));
|
405
|
-
}
|
406
|
-
|
407
|
-
_this.setState({
|
408
|
-
hierarchySelected: hiSelected
|
409
|
-
});
|
410
|
-
} else if (item.hasOwnProperty('parentId')) {
|
411
|
-
// Si item est un enfant on l'ajoute du tableau associatif des
|
412
|
-
// elmts sélectionnés
|
413
|
-
hiSelected[item.parentId].push(item.id);
|
414
|
-
}
|
408
|
+
// select _all options
|
409
|
+
onChange(event, options.map(function (option) {
|
410
|
+
return option.id;
|
411
|
+
}), item);
|
415
412
|
}
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
onChange(event, valueList, item);
|
413
|
+
} else if (value.includes(item.id)) {
|
414
|
+
// unselect item
|
415
|
+
onChange(event, value.filter(function (id) {
|
416
|
+
return id !== item.id;
|
417
|
+
}), item);
|
422
418
|
} else {
|
423
|
-
onChange(event, item.id, item);
|
424
|
-
|
425
|
-
_this.handleClose();
|
419
|
+
onChange(event, [].concat((0, _toConsumableArray2.default)(value), [item.id]), item);
|
426
420
|
}
|
427
421
|
};
|
428
422
|
|
429
423
|
_this.handleSuggestions = function (suggestions) {
|
430
|
-
var _this$
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
translations = _this$props2.translations,
|
435
|
-
multiple = _this$props2.multiple;
|
424
|
+
var _this$props3 = _this.props,
|
425
|
+
hasAll = _this$props3.hasAll,
|
426
|
+
iconAll = _this$props3.iconAll,
|
427
|
+
translations = _this$props3.translations;
|
436
428
|
|
437
429
|
if (suggestions.length === 0) {
|
438
|
-
//
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
430
|
+
// Add '_no_result' suggestion
|
431
|
+
_this.setState(function (prevState) {
|
432
|
+
return (0, _extends2.default)({}, prevState, {
|
433
|
+
suggestions: [{
|
434
|
+
id: '_no_result',
|
435
|
+
type: 'text',
|
436
|
+
disabled: true,
|
437
|
+
centered: true,
|
438
|
+
hideCheckbox: true,
|
439
|
+
label: translations.no_result_match
|
440
|
+
}]
|
441
|
+
});
|
448
442
|
});
|
449
|
-
} else
|
450
|
-
|
451
|
-
|
452
|
-
return suggestion.id === '_all';
|
453
|
-
}).length === 0) {
|
454
|
-
var allItem = {
|
443
|
+
} else {
|
444
|
+
_this.setState({
|
445
|
+
suggestions: [].concat((0, _toConsumableArray2.default)(hasAll ? [(0, _extends2.default)({
|
455
446
|
id: '_all',
|
456
|
-
icon: iconAll,
|
457
447
|
label: translations.all
|
458
|
-
}
|
448
|
+
}, iconAll && {
|
449
|
+
type: 'icon',
|
450
|
+
icon: iconAll
|
451
|
+
})] : []), (0, _toConsumableArray2.default)(suggestions))
|
452
|
+
});
|
453
|
+
}
|
454
|
+
};
|
459
455
|
|
460
|
-
|
461
|
-
|
462
|
-
}
|
456
|
+
_this.handleSearch = function (e, inputValue) {
|
457
|
+
var searchValue = inputValue && e.target.value ? inputValue : e.target.value;
|
463
458
|
|
464
|
-
|
465
|
-
|
459
|
+
if (_this.props.onSearch) {
|
460
|
+
_this.props.onSearch(e, searchValue);
|
461
|
+
} else {
|
462
|
+
_this.setState({
|
463
|
+
searchValue: searchValue
|
464
|
+
});
|
466
465
|
}
|
466
|
+
};
|
467
467
|
|
468
|
-
|
469
|
-
|
470
|
-
|
468
|
+
_this.handleSearchReset = function () {
|
469
|
+
_this.handleSearch({
|
470
|
+
target: {
|
471
|
+
value: ''
|
472
|
+
}
|
473
|
+
}, '');
|
471
474
|
};
|
472
475
|
|
473
476
|
_this.state = {
|
474
477
|
open: false,
|
475
478
|
focused: false,
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
// Check if an option match value prop.
|
491
|
-
_props.options.forEach(function (item) {
|
492
|
-
if (!valueInOptions && _val.indexOf(item.id) !== -1) {
|
493
|
-
valueInOptions = true;
|
494
|
-
}
|
495
|
-
});
|
496
|
-
|
497
|
-
if (!valueInOptions && _props.pinnedItem) {
|
498
|
-
if (_props.value.indexOf(_props.pinnedItem.id) >= 0) {
|
499
|
-
valueInOptions = true;
|
500
|
-
}
|
501
|
-
}
|
502
|
-
}
|
503
|
-
|
504
|
-
if (!valueInOptions) {
|
505
|
-
throw new Error('prop value provided does not match any option.');
|
506
|
-
}
|
507
|
-
|
508
|
-
if (_props.hierarchic === true && _props.options.length > 1) {
|
509
|
-
var hierarchyTrees = _this.buildHierarchyTrees(_props);
|
510
|
-
|
511
|
-
_this.state.hierarchy = hierarchyTrees.hierarchy;
|
512
|
-
_this.state.hierarchySelected = hierarchyTrees.hierarchySelected;
|
513
|
-
}
|
514
|
-
|
515
|
-
if (_props.options.length > 0) {
|
516
|
-
// Get real options number (parent & _all are not real options)
|
517
|
-
var optionsLength = 0;
|
518
|
-
|
519
|
-
_props.options.forEach(function (option) {
|
520
|
-
if (option.hasChildren !== true && option.id !== '_all') {
|
521
|
-
optionsLength += 1;
|
522
|
-
}
|
523
|
-
});
|
524
|
-
|
525
|
-
_this.state.nbOptions = optionsLength;
|
526
|
-
} else if (!_props.dynamic) {
|
527
|
-
_this.state.dynamic = true;
|
528
|
-
}
|
529
|
-
|
479
|
+
searchValue: props.searchValue ? undefined : '',
|
480
|
+
suggestions: props.options,
|
481
|
+
openDown: true
|
482
|
+
};
|
483
|
+
_this.handleBlur = _this.handleBlur.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
|
484
|
+
_this.handleClick = _this.handleClick.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
|
485
|
+
_this.handleClose = _this.handleClose.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
|
486
|
+
_this.handleClickAway = _this.handleClickAway.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
|
487
|
+
_this.handleFocus = _this.handleFocus.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
|
488
|
+
_this.handleSearch = _this.handleSearch.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
|
489
|
+
_this.handleSearchReset = _this.handleSearchReset.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
|
490
|
+
_this.handleSelect = _this.handleSelect.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
|
491
|
+
_this.handleSuggestions = _this.handleSuggestions.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
|
492
|
+
_this.getInputElement = _this.getInputElement.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
|
530
493
|
return _this;
|
531
494
|
}
|
532
495
|
|
533
496
|
(0, _createClass2.default)(HiSelect, [{
|
534
|
-
key: "
|
535
|
-
value: function
|
536
|
-
if (
|
537
|
-
this.
|
538
|
-
var optionsLength = 0;
|
539
|
-
nextProps.options.forEach(function (option) {
|
540
|
-
if (option.hasChildren !== true && option.id !== '_all') {
|
541
|
-
optionsLength += 1;
|
542
|
-
}
|
543
|
-
});
|
544
|
-
this.setState({
|
545
|
-
nbOptions: optionsLength
|
546
|
-
});
|
547
|
-
}
|
548
|
-
|
549
|
-
if (nextProps.hierarchic === true && nextProps.options.length > 1) {
|
550
|
-
var hierarchyTrees = this.buildHierarchyTrees(nextProps);
|
551
|
-
this.setState({
|
552
|
-
hierarchy: hierarchyTrees.hierarchy,
|
553
|
-
hierarchySelected: hierarchyTrees.hierarchySelected
|
554
|
-
});
|
497
|
+
key: "componentDidMount",
|
498
|
+
value: function componentDidMount() {
|
499
|
+
if (this.props.autoFocus) {
|
500
|
+
this.inputEl.focus();
|
555
501
|
}
|
556
502
|
}
|
557
503
|
}, {
|
558
504
|
key: "render",
|
559
505
|
value: function render() {
|
560
|
-
var
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
id = _this$
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
focused = _this$
|
591
|
-
dynamic = _this$state2.dynamic;
|
592
|
-
var display = '';
|
593
|
-
var selectedIdList;
|
594
|
-
|
595
|
-
if (Array.isArray(value)) {
|
596
|
-
selectedIdList = value;
|
597
|
-
} else if (value) {
|
598
|
-
selectedIdList = [value];
|
599
|
-
} else {
|
600
|
-
selectedIdList = [];
|
601
|
-
}
|
602
|
-
|
603
|
-
var suggestions = (0, _toConsumableArray2.default)(stateSuggestions);
|
604
|
-
|
605
|
-
if (pinnedItem) {
|
606
|
-
suggestions.unshift(pinnedItem);
|
607
|
-
} // If loading
|
506
|
+
var _classNames,
|
507
|
+
_this2 = this;
|
508
|
+
|
509
|
+
var _this$props4 = this.props,
|
510
|
+
classes = _this$props4.classes,
|
511
|
+
disabled = _this$props4.disabled,
|
512
|
+
error = _this$props4.error,
|
513
|
+
loading = _this$props4.loading,
|
514
|
+
options = _this$props4.options,
|
515
|
+
searchable = _this$props4.searchable,
|
516
|
+
displayAsChip = _this$props4.displayAsChip,
|
517
|
+
type = _this$props4.type,
|
518
|
+
value = _this$props4.value,
|
519
|
+
multiple = _this$props4.multiple,
|
520
|
+
translations = _this$props4.translations,
|
521
|
+
hiSearchInputProps = _this$props4.hiSearchInputProps,
|
522
|
+
hiSelectableListProps = _this$props4.hiSelectableListProps,
|
523
|
+
hiSelectInputProps = _this$props4.hiSelectInputProps,
|
524
|
+
id = _this$props4.id,
|
525
|
+
onScrollReachBottom = _this$props4.onScrollReachBottom,
|
526
|
+
onSubmit = _this$props4.onSubmit,
|
527
|
+
placeholder = _this$props4.placeholder,
|
528
|
+
startAdornment = _this$props4.startAdornment,
|
529
|
+
staticPosition = _this$props4.staticPosition,
|
530
|
+
_this$props4$searchVa = _this$props4.searchValue,
|
531
|
+
searchValue = _this$props4$searchVa === void 0 ? this.state.searchValue : _this$props4$searchVa,
|
532
|
+
_this$props4$buildSel = _this$props4.buildSelectProps,
|
533
|
+
buildSelectProps = _this$props4$buildSel === void 0 ? this.buildSelectProps : _this$props4$buildSel;
|
534
|
+
var _this$state = this.state,
|
535
|
+
open = _this$state.open,
|
536
|
+
focused = _this$state.focused;
|
608
537
|
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
id: '_loading',
|
613
|
-
type: 'loader',
|
614
|
-
disabled: true,
|
615
|
-
centered: true,
|
616
|
-
checkbox: false,
|
617
|
-
label: 'loading'
|
618
|
-
});
|
619
|
-
}
|
620
|
-
|
621
|
-
if ((dynamic || loading) && selectedIdList.length === 1) {
|
622
|
-
display = translations.one_item_selected;
|
623
|
-
} else if ((this.state.nbOptions !== selectedIdList.length || !hasAll) && selectedIdList.length > 1) {
|
624
|
-
display = translations.n_items_selected.replace('%s', selectedIdList.length);
|
625
|
-
} else if (this.state.nbOptions === selectedIdList.length && this.state.nbOptions > 1) {
|
626
|
-
display = translations.all;
|
627
|
-
} else if (selectedIdList.length === 1) {
|
628
|
-
var item = options.find(function (o) {
|
629
|
-
return o.id === selectedIdList[0];
|
630
|
-
});
|
631
|
-
|
632
|
-
if (item === undefined) {
|
633
|
-
display = translations.one_item_selected;
|
634
|
-
} else if (type !== 'icon') {
|
635
|
-
if (pinnedItem) {
|
636
|
-
item = pinnedItem;
|
637
|
-
}
|
638
|
-
|
639
|
-
display = item.label;
|
640
|
-
} else {
|
641
|
-
display = _react.default.createElement("span", {
|
642
|
-
className: classes.selectIconLabel
|
643
|
-
}, _react.default.createElement(_HiIcon.default, {
|
644
|
-
icon: item.icon,
|
645
|
-
className: classes.labelIcon
|
646
|
-
}), item.label);
|
538
|
+
if (multiple) {
|
539
|
+
if (!Array.isArray(value)) {
|
540
|
+
throw new Error('HiPay Material-UI: the `value` property must be an array ' + 'when using the `HiSelect` component with `multiple`.');
|
647
541
|
}
|
648
542
|
}
|
649
543
|
|
650
|
-
|
651
|
-
var chipFilter = _react.default.createElement(_HiChip.default, {
|
652
|
-
label: placeholder || display,
|
653
|
-
onDelete: this.handleRequestDelete
|
654
|
-
});
|
544
|
+
var selectedItemIdList = [];
|
655
545
|
|
656
|
-
|
657
|
-
|
658
|
-
}
|
546
|
+
if (value) {
|
547
|
+
selectedItemIdList = multiple ? (0, _toConsumableArray2.default)(value) : [value];
|
659
548
|
}
|
660
549
|
|
661
|
-
var
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
allSelected = true;
|
666
|
-
}
|
550
|
+
var _buildSelectProps = buildSelectProps(options, selectedItemIdList, searchValue, loading),
|
551
|
+
itemList = _buildSelectProps.itemList,
|
552
|
+
_buildSelectProps$inp = _buildSelectProps.inputValue,
|
553
|
+
inputValue = _buildSelectProps$inp === void 0 ? this.buildInputValue(options, selectedItemIdList, loading) : _buildSelectProps$inp;
|
667
554
|
|
668
555
|
var popperStyle = {};
|
669
556
|
|
@@ -677,70 +564,82 @@ function (_React$PureComponent) {
|
|
677
564
|
}
|
678
565
|
}
|
679
566
|
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
567
|
+
var popperClass = (0, _classnames.default)(classes.popper, (_classNames = {}, (0, _defineProperty2.default)(_classNames, classes.popperWidth, !this.props.containerWidth), (0, _defineProperty2.default)(_classNames, classes.popperRightAlign, this.props.containerWidth && this.props.align === 'right'), _classNames));
|
568
|
+
|
569
|
+
var searchInput = function searchInput(position) {
|
570
|
+
if (searchable) {
|
571
|
+
return _react.default.createElement(_HiInput.default, (0, _extends2.default)({
|
572
|
+
value: searchValue,
|
573
|
+
autoFocus: true,
|
574
|
+
inputRef: _this2.getInputElement,
|
575
|
+
onKeyDown: _this2.handleKeyDownSearch,
|
576
|
+
onChange: _this2.handleSearch,
|
577
|
+
onReset: _this2.handleSearchReset,
|
578
|
+
placeholder: translations.search,
|
579
|
+
startAdornment: 'search',
|
580
|
+
tabIndex: 0,
|
581
|
+
className: (0, _classnames.default)((0, _defineProperty2.default)({}, classes.separator, position === 'top'))
|
582
|
+
}, hiSearchInputProps));
|
583
|
+
}
|
584
|
+
|
585
|
+
return null;
|
586
|
+
}; // Replace popper onSearch when popper displayed on top of selectButton
|
587
|
+
|
588
|
+
|
589
|
+
if (this.placement && this.placement.indexOf('top') >= 0 && !!searchable) {
|
590
|
+
// +1 for search input
|
591
|
+
var nbItems = itemList.length <= 10 ? itemList.length + 1 : 11;
|
592
|
+
popperStyle.transform = "translate3d(-1px, -".concat(nbItems * 40 + 2, "px, 0px)");
|
593
|
+
} else if (this.placement && this.placement.indexOf('top') < 0 && !!searchable) {
|
594
|
+
popperStyle.transform = 'translate3d(-1px, 40px, 0px)';
|
689
595
|
}
|
690
596
|
|
691
|
-
var content =
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
style: {
|
697
|
-
transformOrigin: '0 0 0'
|
597
|
+
var content = function content(_ref) {
|
598
|
+
var placement = _ref.placement;
|
599
|
+
|
600
|
+
if (placement !== _this2.placement) {
|
601
|
+
_this2.placement = placement;
|
698
602
|
}
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
},
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
parentIcon: parentIcon,
|
729
|
-
hoverIcon: hoverIcon,
|
730
|
-
checkedIcon: checkedIcon,
|
731
|
-
allSelected: allSelected,
|
732
|
-
value: value,
|
733
|
-
onKeyDown: this.handleKeyDown
|
734
|
-
}, other))))));
|
603
|
+
|
604
|
+
return _react.default.createElement(_ClickAwayListener.default, {
|
605
|
+
onClickAway: _this2.handleClickAway
|
606
|
+
}, _react.default.createElement(_Grow.default, {
|
607
|
+
in: open,
|
608
|
+
id: "menu-list",
|
609
|
+
style: {
|
610
|
+
transformOrigin: '0 0 0'
|
611
|
+
}
|
612
|
+
}, _react.default.createElement(_Paper.default, {
|
613
|
+
className: classes.paper
|
614
|
+
}, (_this2.placement && _this2.placement.indexOf('bottom') >= 0 || staticPosition) && searchInput('bottom'), startAdornment, _react.default.createElement(_reactCustomScrollbars.default, (0, _extends2.default)({
|
615
|
+
ref: function ref(contentEl) {
|
616
|
+
_this2.optionsContent = contentEl;
|
617
|
+
},
|
618
|
+
autoHeight: true,
|
619
|
+
autoHeightMax: 430
|
620
|
+
}, onScrollReachBottom && {
|
621
|
+
onScroll: _this2.handleScroll
|
622
|
+
}), _react.default.createElement(_HiSelectableList.default, (0, _extends2.default)({
|
623
|
+
type: type,
|
624
|
+
itemList: itemList,
|
625
|
+
onSelect: _this2.handleSelect,
|
626
|
+
selectedItemIdList: selectedItemIdList,
|
627
|
+
fallbackImage: _this2.props.fallbackImage,
|
628
|
+
overlay: _this2.overlay,
|
629
|
+
value: value
|
630
|
+
}, hiSelectableListProps))), _this2.placement && _this2.placement.indexOf('top') >= 0 && !staticPosition && searchInput('top'))));
|
631
|
+
};
|
735
632
|
|
736
633
|
return _react.default.createElement("div", {
|
737
634
|
className: classes.root,
|
738
635
|
ref: function ref(el) {
|
739
636
|
_this2.overlay = el;
|
740
|
-
}
|
741
|
-
|
637
|
+
},
|
638
|
+
onKeyDown: this.handleKeyDown,
|
639
|
+
onKeyDownCapture: this.handleKeyDownCapture
|
640
|
+
}, _react.default.createElement(_HiSelectInput.default, (0, _extends2.default)({
|
742
641
|
id: id,
|
743
|
-
value:
|
642
|
+
value: inputValue,
|
744
643
|
open: open,
|
745
644
|
focused: focused,
|
746
645
|
type: type,
|
@@ -750,43 +649,65 @@ function (_React$PureComponent) {
|
|
750
649
|
onClick: this.handleClick,
|
751
650
|
onFocus: this.handleFocus,
|
752
651
|
onBlur: this.handleBlur,
|
753
|
-
|
652
|
+
onSubmit: onSubmit,
|
754
653
|
onMouseEnter: this.props.onMouseEnter,
|
755
654
|
onMouseLeave: this.props.onMouseLeave,
|
655
|
+
onReset: this.props.onReset,
|
656
|
+
placeholder: placeholder
|
657
|
+
}, hiSelectInputProps, {
|
756
658
|
refElement: function refElement(el) {
|
757
|
-
_this2.
|
758
|
-
}
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
}, content) : _react.default.createElement(_Popper.default, {
|
659
|
+
_this2.inputEl = el;
|
660
|
+
}
|
661
|
+
})), open && staticPosition ? _react.default.createElement("div", {
|
662
|
+
style: popperStyle,
|
663
|
+
className: popperClass
|
664
|
+
}, content({})) : _react.default.createElement(_Popper.default, {
|
763
665
|
anchorEl: this.inputEl,
|
764
666
|
placement: "bottom-start",
|
765
667
|
open: open,
|
766
668
|
className: popperClass,
|
767
|
-
|
768
|
-
|
669
|
+
disablePortal: true,
|
670
|
+
style: popperStyle
|
769
671
|
}, content));
|
770
672
|
}
|
673
|
+
}], [{
|
674
|
+
key: "getDerivedStateFromProps",
|
675
|
+
value: function getDerivedStateFromProps(nextProps, prevState) {
|
676
|
+
if (nextProps.options !== prevState.suggestions) {
|
677
|
+
return (0, _extends2.default)({}, prevState, {
|
678
|
+
suggestions: nextProps.options
|
679
|
+
});
|
680
|
+
}
|
681
|
+
|
682
|
+
return null;
|
683
|
+
}
|
684
|
+
/**
|
685
|
+
* Build itemList & inputValue from select props
|
686
|
+
* @param options
|
687
|
+
* @param value
|
688
|
+
* @param search
|
689
|
+
* @param loading
|
690
|
+
* @returns {{itemList: *[], inputValue: *}}
|
691
|
+
*/
|
692
|
+
|
771
693
|
}]);
|
772
694
|
return HiSelect;
|
773
695
|
}(_react.default.PureComponent);
|
774
696
|
|
775
697
|
HiSelect.defaultProps = {
|
776
|
-
|
698
|
+
align: 'left',
|
699
|
+
autoFocus: false,
|
777
700
|
disabled: false,
|
778
701
|
displayAsChip: false,
|
779
|
-
dynamic: false,
|
780
702
|
error: false,
|
781
703
|
hasAll: false,
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
infiniteScroll: false,
|
786
|
-
loadingMoreResults: false,
|
704
|
+
hiSelectableListProps: {},
|
705
|
+
hiSelectInputProps: {},
|
706
|
+
hiSearchInputProps: {},
|
787
707
|
multiple: false,
|
788
|
-
|
789
|
-
|
708
|
+
placeholder: '',
|
709
|
+
searchable: false,
|
710
|
+
staticPosition: false,
|
790
711
|
translations: {
|
791
712
|
all: 'All',
|
792
713
|
no_result_match: 'No result match',
|
@@ -796,14 +717,16 @@ HiSelect.defaultProps = {
|
|
796
717
|
n_children: '%s items',
|
797
718
|
one_child: '%s item'
|
798
719
|
},
|
799
|
-
|
800
|
-
|
720
|
+
type: 'text',
|
721
|
+
filterFunc: filterValue
|
801
722
|
};
|
802
723
|
HiSelect.propTypes = process.env.NODE_ENV !== "production" ? {
|
724
|
+
align: _propTypes.default.oneOf(['left', 'right']),
|
725
|
+
|
803
726
|
/**
|
804
|
-
*
|
727
|
+
* Permet de forcer le focus sur le composant
|
805
728
|
*/
|
806
|
-
|
729
|
+
autoFocus: _propTypes.default.bool,
|
807
730
|
|
808
731
|
/**
|
809
732
|
* Useful to extend the style applied to components.
|
@@ -825,77 +748,56 @@ HiSelect.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
825
748
|
*/
|
826
749
|
displayAsChip: _propTypes.default.bool,
|
827
750
|
|
828
|
-
/**
|
829
|
-
* Option permettant de définir si les options du select sont dynamiques.
|
830
|
-
* Si les options du select sont initialisées à vide, alors ce sera mis à true
|
831
|
-
* automatiquement.
|
832
|
-
*/
|
833
|
-
dynamic: _propTypes.default.bool,
|
834
|
-
|
835
751
|
/**
|
836
752
|
* Applique le style error
|
837
753
|
*/
|
838
754
|
error: _propTypes.default.bool,
|
839
755
|
|
840
756
|
/**
|
841
|
-
*
|
757
|
+
* Chemin vers l'image à afficher par défaut si une image n'est pas trouvée
|
842
758
|
*/
|
843
|
-
|
759
|
+
fallbackImage: _propTypes.default.string,
|
760
|
+
|
761
|
+
/*
|
762
|
+
* Fonction de filtrage custom
|
763
|
+
*/
|
764
|
+
filterFunc: _propTypes.default.func,
|
844
765
|
|
845
766
|
/**
|
846
|
-
*
|
767
|
+
* Affiche l'élément 'All'
|
847
768
|
*/
|
848
|
-
|
769
|
+
hasAll: _propTypes.default.bool,
|
849
770
|
|
850
771
|
/**
|
851
|
-
*
|
772
|
+
* Override HiInput props (for search)
|
852
773
|
*/
|
853
|
-
|
774
|
+
hiSearchInputProps: _propTypes.default.object,
|
854
775
|
|
855
776
|
/**
|
856
|
-
*
|
777
|
+
* Override HiSelectableList props
|
857
778
|
*/
|
858
|
-
|
779
|
+
hiSelectableListProps: _propTypes.default.object,
|
859
780
|
|
860
781
|
/**
|
861
|
-
*
|
782
|
+
* Override HiSelectInput props
|
862
783
|
*/
|
863
|
-
|
784
|
+
hiSelectInputProps: _propTypes.default.object,
|
864
785
|
|
865
786
|
/**
|
866
787
|
* Nom de l'icône
|
867
788
|
*/
|
868
|
-
iconAll: _propTypes.default.
|
789
|
+
iconAll: _propTypes.default.string,
|
869
790
|
|
870
791
|
/**
|
871
792
|
* id du select
|
872
793
|
*/
|
873
794
|
id: _propTypes.default.string,
|
874
795
|
|
875
|
-
/**
|
876
|
-
* Infinite scroll dans le select dans le cas où il y a beaucoup de résultats à afficher
|
877
|
-
* afin d'éviter un lag du navigateur
|
878
|
-
*/
|
879
|
-
infiniteScroll: _propTypes.default.bool,
|
880
|
-
|
881
796
|
/**
|
882
797
|
* Ajoute un loader
|
883
798
|
*/
|
884
799
|
loading: _propTypes.default.bool,
|
885
800
|
|
886
|
-
/**
|
887
|
-
* Ajoute un loader en bas pour l'infiniteScroll
|
888
|
-
*/
|
889
|
-
loadingMoreResults: _propTypes.default.bool,
|
890
|
-
|
891
|
-
/**
|
892
|
-
* Fonction de callback appelée lorsque l'utilisateur arrive en bas de la liste des options
|
893
|
-
* afin de charger les nouvelles options
|
894
|
-
*
|
895
|
-
* @param {int} pageNumber
|
896
|
-
*/
|
897
|
-
loadMoreResults: _propTypes.default.func,
|
898
|
-
|
899
801
|
/**
|
900
802
|
* Autorise la sélection de plusieurs valeurs
|
901
803
|
*/
|
@@ -914,11 +816,6 @@ HiSelect.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
914
816
|
*/
|
915
817
|
onChange: _propTypes.default.func.isRequired,
|
916
818
|
|
917
|
-
/**
|
918
|
-
* Fonction de callback appelée click dans l'input
|
919
|
-
*/
|
920
|
-
onClick: _propTypes.default.func,
|
921
|
-
|
922
819
|
/**
|
923
820
|
* Fonction de callback appelée lorsqu'on ferme le select
|
924
821
|
*/
|
@@ -940,18 +837,14 @@ HiSelect.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
940
837
|
onReset: _propTypes.default.func,
|
941
838
|
|
942
839
|
/**
|
943
|
-
* Fonction de callback appelée
|
944
|
-
* A utiliser pour les selects avec des données dynamiques
|
945
|
-
*
|
946
|
-
* @param {object} event
|
947
|
-
* @param {string} value
|
840
|
+
* Fonction de callback appelée lorsque le scroll atteint le bas de la liste
|
948
841
|
*/
|
949
|
-
|
842
|
+
onScrollReachBottom: _propTypes.default.func,
|
950
843
|
|
951
844
|
/**
|
952
|
-
* Fonction de callback
|
845
|
+
* Fonction de callback appelée lorsque le champs de recherche est utilisé
|
953
846
|
*/
|
954
|
-
|
847
|
+
onSearch: _propTypes.default.func,
|
955
848
|
|
956
849
|
/**
|
957
850
|
* Listes des options du select
|
@@ -959,23 +852,7 @@ HiSelect.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
959
852
|
options: _propTypes.default.array.isRequired,
|
960
853
|
|
961
854
|
/**
|
962
|
-
*
|
963
|
-
*/
|
964
|
-
parentIcon: _propTypes.default.node,
|
965
|
-
|
966
|
-
/**
|
967
|
-
* Les items parents sont sélectionnables
|
968
|
-
*/
|
969
|
-
parentItemSelectable: _propTypes.default.bool,
|
970
|
-
|
971
|
-
/**
|
972
|
-
* Item épinglé en début de liste
|
973
|
-
*/
|
974
|
-
pinnedItem: _propTypes.default.object,
|
975
|
-
|
976
|
-
/**
|
977
|
-
* Placeholder affiché lorsque le select est fermé
|
978
|
-
* Surcharge le placeholder par défaut
|
855
|
+
* Placeholder affiché lorsque l'input est vide
|
979
856
|
*/
|
980
857
|
placeholder: _propTypes.default.string,
|
981
858
|
|
@@ -985,7 +862,12 @@ HiSelect.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
985
862
|
searchable: _propTypes.default.bool,
|
986
863
|
|
987
864
|
/**
|
988
|
-
*
|
865
|
+
* Node qui s'ajoute entre la barre de recherche et la liste de résultats
|
866
|
+
*/
|
867
|
+
startAdornment: _propTypes.default.object,
|
868
|
+
|
869
|
+
/**
|
870
|
+
* Si true, le contenu du select sera dans une div static plutôt que dans une popper absolute
|
989
871
|
*/
|
990
872
|
staticPosition: _propTypes.default.bool,
|
991
873
|
|
@@ -1005,7 +887,7 @@ HiSelect.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
1005
887
|
value: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string, _propTypes.default.array])
|
1006
888
|
} : {};
|
1007
889
|
|
1008
|
-
var _default = (0,
|
890
|
+
var _default = (0, _withStyles.default)(styles, {
|
1009
891
|
hiComponent: true,
|
1010
892
|
name: 'HmuiHiSelect'
|
1011
893
|
})(HiSelect);
|