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