@hipay/hipay-material-ui 1.0.0-beta.20 → 1.0.0-beta.21
Sign up to get free protection for your applications and to get access to all the features.
- package/HiSelect/HiSelect.js +41 -11
- package/HiSelect/HiSuggestSelect.js +35 -5
- package/HiSelectableList/HiSelectableListItem.js +30 -37
- package/HiTopBar/HiTopBar.js +10 -3
- package/es/HiSelect/HiSelect.js +35 -9
- package/es/HiSelect/HiSuggestSelect.js +33 -5
- package/es/HiSelectableList/HiSelectableListItem.js +30 -37
- package/es/HiTopBar/HiTopBar.js +11 -4
- package/es/utils/hiHelpers.js +3 -3
- package/index.es.js +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/umd/hipay-material-ui.development.js +13771 -56579
- package/umd/hipay-material-ui.production.min.js +5 -5
- package/utils/hiHelpers.js +3 -3
package/HiSelect/HiSelect.js
CHANGED
@@ -13,6 +13,10 @@ var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
|
|
13
13
|
|
14
14
|
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
|
15
15
|
|
16
|
+
var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray');
|
17
|
+
|
18
|
+
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);
|
19
|
+
|
16
20
|
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
|
17
21
|
|
18
22
|
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
|
@@ -303,7 +307,8 @@ var HiSelect = function (_React$PureComponent) {
|
|
303
307
|
hierarchic = _props.hierarchic,
|
304
308
|
id = _props.id,
|
305
309
|
placeholder = _props.placeholder,
|
306
|
-
staticPosition = _props.staticPosition
|
310
|
+
staticPosition = _props.staticPosition,
|
311
|
+
pinnedItem = _props.pinnedItem;
|
307
312
|
var _state = this.state,
|
308
313
|
open = _state.open,
|
309
314
|
suggestions = _state.suggestions,
|
@@ -313,6 +318,11 @@ var HiSelect = function (_React$PureComponent) {
|
|
313
318
|
var display = '';
|
314
319
|
var selectedIdList = Array.isArray(value) ? value : value ? [value] : [];
|
315
320
|
|
321
|
+
var _suggestions = [].concat((0, _toConsumableArray3.default)(suggestions));
|
322
|
+
if (pinnedItem) {
|
323
|
+
_suggestions = [pinnedItem].concat((0, _toConsumableArray3.default)(suggestions));
|
324
|
+
}
|
325
|
+
|
316
326
|
if (this.state.dynamic && selectedIdList.length === 1) {
|
317
327
|
display = translations.one_item_selected.replace('%s', selectedIdList.length);
|
318
328
|
} else if (this.state.nbOptions !== selectedIdList.length && selectedIdList.length > 1) {
|
@@ -321,9 +331,13 @@ var HiSelect = function (_React$PureComponent) {
|
|
321
331
|
display = translations.all;
|
322
332
|
} else if (selectedIdList.length === 1) {
|
323
333
|
if (type !== 'icon') {
|
324
|
-
|
334
|
+
var item = options.find(function (o) {
|
325
335
|
return o.id === selectedIdList[0];
|
326
|
-
})
|
336
|
+
});
|
337
|
+
if (!item && pinnedItem) {
|
338
|
+
item = pinnedItem;
|
339
|
+
}
|
340
|
+
display = item.label;
|
327
341
|
} else {
|
328
342
|
var optionSelected = options.find(function (o) {
|
329
343
|
return o.id === selectedIdList[0];
|
@@ -380,7 +394,7 @@ var HiSelect = function (_React$PureComponent) {
|
|
380
394
|
_react2.default.createElement(_HiSelectableList2.default, {
|
381
395
|
type: type,
|
382
396
|
parentItemSelectable: parentItemSelectable,
|
383
|
-
itemList:
|
397
|
+
itemList: _suggestions,
|
384
398
|
onSelect: this.handleSelect,
|
385
399
|
selectedIdList: selectedIdList,
|
386
400
|
checkbox: checkbox,
|
@@ -490,7 +504,7 @@ var _initialiseProps = function _initialiseProps() {
|
|
490
504
|
_this3.handleClose();
|
491
505
|
} else {
|
492
506
|
if (!_this3.props.staticPosition) {
|
493
|
-
document.body.style.overflow = 'hidden';
|
507
|
+
//document.body.style.overflow = 'hidden';
|
494
508
|
}
|
495
509
|
_this3.setState({ open: true });
|
496
510
|
var options = _this3.props.options.slice();
|
@@ -554,7 +568,7 @@ var _initialiseProps = function _initialiseProps() {
|
|
554
568
|
nextItem = (0, _hiHelpers.getNextItemSelectable)(document.activeElement, 'up');
|
555
569
|
} else if (event.key === 'Tab') {
|
556
570
|
if (!_this3.props.staticPosition) {
|
557
|
-
document.body.style.overflow = 'auto';
|
571
|
+
//document.body.style.overflow = 'auto';
|
558
572
|
}
|
559
573
|
_this3.setState({ open: false });
|
560
574
|
}
|
@@ -579,7 +593,7 @@ var _initialiseProps = function _initialiseProps() {
|
|
579
593
|
|
580
594
|
this.handleClose = function () {
|
581
595
|
if (!_this3.props.staticPosition) {
|
582
|
-
document.body.style.overflow = 'auto';
|
596
|
+
//document.body.style.overflow = 'auto';
|
583
597
|
}
|
584
598
|
_this3.setState({
|
585
599
|
open: false
|
@@ -604,10 +618,10 @@ var _initialiseProps = function _initialiseProps() {
|
|
604
618
|
var _props2 = _this3.props,
|
605
619
|
multiple = _props2.multiple,
|
606
620
|
value = _props2.value,
|
607
|
-
name = _props2.name,
|
608
621
|
onChange = _props2.onChange,
|
609
622
|
options = _props2.options,
|
610
|
-
hierarchic = _props2.hierarchic
|
623
|
+
hierarchic = _props2.hierarchic,
|
624
|
+
pinnedItem = _props2.pinnedItem;
|
611
625
|
var _state2 = _this3.state,
|
612
626
|
hierarchySelected = _state2.hierarchySelected,
|
613
627
|
hierarchy = _state2.hierarchy,
|
@@ -656,8 +670,20 @@ var _initialiseProps = function _initialiseProps() {
|
|
656
670
|
hiSelected[item.parentId].splice(hiSelected[item.parentId].indexOf(item.id), 1);
|
657
671
|
}
|
658
672
|
} else {
|
659
|
-
|
660
|
-
|
673
|
+
if (pinnedItem && item.id === pinnedItem.id) {
|
674
|
+
(0, _keys2.default)(hiSelected).map(function (parentItemId) {
|
675
|
+
hiSelected[parentItemId] = [];
|
676
|
+
return true;
|
677
|
+
});
|
678
|
+
valueList = [item.id];
|
679
|
+
} else {
|
680
|
+
// item non sélectionné => on le sélectionne
|
681
|
+
if (item.hasChildren !== true) valueList.push(item.id);
|
682
|
+
|
683
|
+
if (pinnedItem && valueList.includes(pinnedItem.id)) {
|
684
|
+
valueList.splice(valueList.indexOf(pinnedItem.id), 1);
|
685
|
+
}
|
686
|
+
}
|
661
687
|
|
662
688
|
if (item.hasChildren === true) {
|
663
689
|
// Si item parent => on ajoute tous les enfants
|
@@ -848,6 +874,10 @@ HiSelect.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
848
874
|
* Les items parents sont sélectionnables
|
849
875
|
*/
|
850
876
|
parentItemSelectable: _propTypes2.default.bool,
|
877
|
+
/**
|
878
|
+
* Item épinglé en début de liste
|
879
|
+
*/
|
880
|
+
pinnedItem: _propTypes2.default.object,
|
851
881
|
/**
|
852
882
|
* Placeholder affiché lorsque le select est fermé
|
853
883
|
* Surcharge le placeholder par défaut
|
@@ -186,15 +186,31 @@ var HiSuggestSelect = function (_React$PureComponent) {
|
|
186
186
|
|
187
187
|
var _props = this.props,
|
188
188
|
classes = _props.classes,
|
189
|
-
translations = _props.translations,
|
190
189
|
id = _props.id,
|
190
|
+
showMinLength = _props.showMinLength,
|
191
|
+
showNoResults = _props.showNoResults,
|
191
192
|
onSearch = _props.onSearch,
|
192
|
-
|
193
|
+
translations = _props.translations,
|
194
|
+
otherProps = (0, _objectWithoutProperties3.default)(_props, ['classes', 'id', 'showMinLength', 'showNoResults', 'onSearch', 'translations']);
|
193
195
|
var _state = this.state,
|
194
196
|
focused = _state.focused,
|
195
197
|
options = _state.options;
|
196
198
|
|
197
|
-
|
199
|
+
|
200
|
+
var optionsShown = options;
|
201
|
+
|
202
|
+
// If no results match
|
203
|
+
if (options.length === 0 && (showNoResults || showMinLength)) {
|
204
|
+
optionsShown = [{
|
205
|
+
id: '_no_result',
|
206
|
+
type: 'text',
|
207
|
+
disabled: true,
|
208
|
+
centered: true,
|
209
|
+
checkbox: false,
|
210
|
+
label: showNoResults ? translations.no_result_match : translations.min_length
|
211
|
+
}];
|
212
|
+
}
|
213
|
+
var open = !!optionsShown.length && focused;
|
198
214
|
|
199
215
|
return _react2.default.createElement(
|
200
216
|
'div',
|
@@ -211,6 +227,7 @@ var HiSuggestSelect = function (_React$PureComponent) {
|
|
211
227
|
_reactPopper.Target,
|
212
228
|
null,
|
213
229
|
_react2.default.createElement(_HiInput2.default, (0, _extends3.default)({}, otherProps, {
|
230
|
+
|
214
231
|
inputId: id,
|
215
232
|
focused: focused,
|
216
233
|
inputRef: function inputRef(input) {
|
@@ -236,7 +253,7 @@ var HiSuggestSelect = function (_React$PureComponent) {
|
|
236
253
|
_Paper2.default,
|
237
254
|
{ className: classes.paper },
|
238
255
|
_react2.default.createElement(_HiSelectableList2.default, {
|
239
|
-
itemList:
|
256
|
+
itemList: optionsShown,
|
240
257
|
selectedIdList: [],
|
241
258
|
checkbox: false,
|
242
259
|
onSelect: this.handleSelect,
|
@@ -254,7 +271,12 @@ var HiSuggestSelect = function (_React$PureComponent) {
|
|
254
271
|
}(_react2.default.PureComponent);
|
255
272
|
|
256
273
|
HiSuggestSelect.defaultProps = {
|
257
|
-
|
274
|
+
showMinLength: false,
|
275
|
+
showNoResults: false,
|
276
|
+
translations: {
|
277
|
+
no_result_match: 'No result match',
|
278
|
+
min_length: 'Veuillez saisir 3 caractères minimum'
|
279
|
+
},
|
258
280
|
options: []
|
259
281
|
};
|
260
282
|
HiSuggestSelect.propTypes = process.env.NODE_ENV !== "production" ? {
|
@@ -278,6 +300,14 @@ HiSuggestSelect.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
278
300
|
* Liste de suggestions.
|
279
301
|
*/
|
280
302
|
options: _propTypes2.default.array,
|
303
|
+
/**
|
304
|
+
* Permet d'afficher un message si pas assez de caractères
|
305
|
+
*/
|
306
|
+
showMinLength: _propTypes2.default.bool,
|
307
|
+
/**
|
308
|
+
* Permet d'afficher un message si aucune options n'est présente
|
309
|
+
*/
|
310
|
+
showNoResults: _propTypes2.default.bool,
|
281
311
|
/**
|
282
312
|
* Traductions (par défaut en anglais)
|
283
313
|
*/
|
@@ -377,51 +377,44 @@ var HiSelectableListItem = function (_React$Component) {
|
|
377
377
|
listItemProps.button = false;
|
378
378
|
}
|
379
379
|
|
380
|
-
var iconAll = void 0;
|
381
|
-
if (item.id === '_all' && item.icon) {
|
382
|
-
iconAll = _react2.default.createElement(_HiIconBuilder2.default, { icon: item.icon, className: classes.checkboxIcon });
|
383
|
-
}
|
384
|
-
|
385
380
|
// calcul du padding left
|
386
381
|
var paddingLeft = 0;
|
387
382
|
|
388
383
|
if (leftPadding) {
|
389
384
|
paddingLeft = leftPadding;
|
390
|
-
} else {
|
391
|
-
// Si pas de hiérarchie, padding de 8px
|
392
|
-
if (!
|
393
|
-
|
394
|
-
|
385
|
+
} else if (!hierarchic) {
|
386
|
+
// Si pas de hiérarchie et sans checkbox, padding de 8px
|
387
|
+
if (!effectiveCheckbox) {
|
388
|
+
paddingLeft = 8;
|
389
|
+
}
|
390
|
+
} else if (selectable) {
|
391
|
+
// Si item selectionnable
|
392
|
+
// Si parent selectionnable
|
393
|
+
if (parentItemSelectable) {
|
394
|
+
// Si l'item contient une checkbox
|
395
|
+
if (effectiveCheckbox) {
|
396
|
+
paddingLeft = 16 * level;
|
397
|
+
} else {
|
398
|
+
paddingLeft = 16 * (level + 1);
|
395
399
|
}
|
396
|
-
} else if (
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
if (effectiveCheckbox) {
|
402
|
-
paddingLeft = 16 * level;
|
403
|
-
} else {
|
404
|
-
paddingLeft = 16 * (level + 1);
|
405
|
-
}
|
406
|
-
} else if (level > 0) {
|
407
|
-
if (effectiveCheckbox) {
|
408
|
-
paddingLeft = 16 * (level - 1);
|
409
|
-
} else {
|
410
|
-
paddingLeft = 16 * level;
|
411
|
-
}
|
412
|
-
} else if (!effectiveCheckbox) {
|
413
|
-
if (item.id === '_all') {
|
414
|
-
paddingLeft = 16;
|
415
|
-
} else {
|
416
|
-
paddingLeft = 16 * level;
|
417
|
-
}
|
400
|
+
} else if (level > 0) {
|
401
|
+
if (effectiveCheckbox) {
|
402
|
+
paddingLeft = 16 * (level - 1);
|
403
|
+
} else {
|
404
|
+
paddingLeft = 16 * level;
|
418
405
|
}
|
419
|
-
} else {
|
420
|
-
|
421
|
-
|
406
|
+
} else if (!effectiveCheckbox) {
|
407
|
+
if (item.id === '_all') {
|
408
|
+
paddingLeft = 16;
|
409
|
+
} else {
|
422
410
|
paddingLeft = 16 * level;
|
423
411
|
}
|
424
412
|
}
|
413
|
+
} else {
|
414
|
+
paddingLeft = 16; // Padding de 16 par défaut
|
415
|
+
if (level > 0) {
|
416
|
+
paddingLeft = 16 * level;
|
417
|
+
}
|
425
418
|
}
|
426
419
|
|
427
420
|
listItemProps.style = { paddingLeft: paddingLeft + 'px' };
|
@@ -431,8 +424,8 @@ var HiSelectableListItem = function (_React$Component) {
|
|
431
424
|
iconDisplay = hoverIcon;
|
432
425
|
} else if (item.hasChildren) {
|
433
426
|
iconDisplay = parentIcon;
|
434
|
-
} else if (item.
|
435
|
-
iconDisplay =
|
427
|
+
} else if (item.type === 'icon' && item.icon) {
|
428
|
+
iconDisplay = _react2.default.createElement(_HiIconBuilder2.default, { icon: item.icon, className: classes.checkboxIcon });
|
436
429
|
}
|
437
430
|
|
438
431
|
return _react2.default.createElement(
|
package/HiTopBar/HiTopBar.js
CHANGED
@@ -187,7 +187,7 @@ var _ref = _react2.default.createElement(_HiIconBuilder2.default, { icon: 'fa-be
|
|
187
187
|
|
188
188
|
var _ref2 = _react2.default.createElement(_mdiMaterialUi.ArrowLeft, null);
|
189
189
|
|
190
|
-
var _ref3 = _react2.default.createElement(_mdiMaterialUi.
|
190
|
+
var _ref3 = _react2.default.createElement(_mdiMaterialUi.ChevronDown, null);
|
191
191
|
|
192
192
|
var _ref4 = _react2.default.createElement(_mdiMaterialUi.ArrowLeft, null);
|
193
193
|
|
@@ -235,6 +235,9 @@ var HiTopBar = function (_React$Component) {
|
|
235
235
|
}, {
|
236
236
|
key: 'handleCollapse',
|
237
237
|
value: function handleCollapse() {
|
238
|
+
if (this.props.onCollapse) {
|
239
|
+
this.props.onCollapse(!this.state.collapsed);
|
240
|
+
}
|
238
241
|
this.setState({ collapsed: !this.state.collapsed });
|
239
242
|
}
|
240
243
|
}, {
|
@@ -362,7 +365,7 @@ var HiTopBar = function (_React$Component) {
|
|
362
365
|
(hideable || hasSettings) && _react2.default.createElement(
|
363
366
|
_IconButton2.default,
|
364
367
|
{ color: 'inherit', className: classes.iconButton },
|
365
|
-
hideable && _react2.default.createElement(_mdiMaterialUi.
|
368
|
+
hideable && _react2.default.createElement(_mdiMaterialUi.ChevronUp, { onClick: this.handleCollapse }),
|
366
369
|
hasSettings && _react2.default.createElement(_HiIconBuilder2.default, {
|
367
370
|
onClick: this.props.onClickSettings,
|
368
371
|
icon: 'fa-gear',
|
@@ -498,7 +501,7 @@ HiTopBar.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
498
501
|
*/
|
499
502
|
hasSettings: _propTypes2.default.bool,
|
500
503
|
/**
|
501
|
-
* La TopBar peut être cachée vie le bouton
|
504
|
+
* La TopBar peut être cachée vie le bouton chevron
|
502
505
|
*/
|
503
506
|
hideable: _propTypes2.default.bool,
|
504
507
|
/**
|
@@ -525,6 +528,10 @@ HiTopBar.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
525
528
|
* Fonction de callback au click sur le bouton "Settings" du menu
|
526
529
|
*/
|
527
530
|
onClickSettings: _propTypes2.default.func,
|
531
|
+
/**
|
532
|
+
* Fonction de callback au click sur le bouton chevron
|
533
|
+
*/
|
534
|
+
onCollapse: _propTypes2.default.func,
|
528
535
|
/**
|
529
536
|
* Positionement de la topBar. The behavior of the different options is described
|
530
537
|
* [here](https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Positioning).
|
package/es/HiSelect/HiSelect.js
CHANGED
@@ -216,7 +216,8 @@ class HiSelect extends React.PureComponent {
|
|
216
216
|
hierarchic,
|
217
217
|
id,
|
218
218
|
placeholder,
|
219
|
-
staticPosition
|
219
|
+
staticPosition,
|
220
|
+
pinnedItem
|
220
221
|
} = this.props;
|
221
222
|
|
222
223
|
const { open, suggestions, focused } = this.state;
|
@@ -224,6 +225,11 @@ class HiSelect extends React.PureComponent {
|
|
224
225
|
let display = '';
|
225
226
|
const selectedIdList = Array.isArray(value) ? value : value ? [value] : [];
|
226
227
|
|
228
|
+
let _suggestions = [...suggestions];
|
229
|
+
if (pinnedItem) {
|
230
|
+
_suggestions = [pinnedItem, ...suggestions];
|
231
|
+
}
|
232
|
+
|
227
233
|
if (this.state.dynamic && selectedIdList.length === 1) {
|
228
234
|
display = translations.one_item_selected.replace('%s', selectedIdList.length);
|
229
235
|
} else if (this.state.nbOptions !== selectedIdList.length && selectedIdList.length > 1) {
|
@@ -232,7 +238,11 @@ class HiSelect extends React.PureComponent {
|
|
232
238
|
display = translations.all;
|
233
239
|
} else if (selectedIdList.length === 1) {
|
234
240
|
if (type !== 'icon') {
|
235
|
-
|
241
|
+
let item = options.find(o => o.id === selectedIdList[0]);
|
242
|
+
if (!item && pinnedItem) {
|
243
|
+
item = pinnedItem;
|
244
|
+
}
|
245
|
+
display = item.label;
|
236
246
|
} else {
|
237
247
|
const optionSelected = options.find(o => o.id === selectedIdList[0]);
|
238
248
|
display = React.createElement(
|
@@ -289,7 +299,7 @@ class HiSelect extends React.PureComponent {
|
|
289
299
|
React.createElement(HiSelectableList, {
|
290
300
|
type: type,
|
291
301
|
parentItemSelectable: parentItemSelectable,
|
292
|
-
itemList:
|
302
|
+
itemList: _suggestions,
|
293
303
|
onSelect: this.handleSelect,
|
294
304
|
selectedIdList: selectedIdList,
|
295
305
|
checkbox: checkbox,
|
@@ -395,7 +405,7 @@ var _initialiseProps = function () {
|
|
395
405
|
this.handleClose();
|
396
406
|
} else {
|
397
407
|
if (!this.props.staticPosition) {
|
398
|
-
document.body.style.overflow = 'hidden';
|
408
|
+
//document.body.style.overflow = 'hidden';
|
399
409
|
}
|
400
410
|
this.setState({ open: true });
|
401
411
|
const options = this.props.options.slice();
|
@@ -459,7 +469,7 @@ var _initialiseProps = function () {
|
|
459
469
|
nextItem = getNextItemSelectable(document.activeElement, 'up');
|
460
470
|
} else if (event.key === 'Tab') {
|
461
471
|
if (!this.props.staticPosition) {
|
462
|
-
document.body.style.overflow = 'auto';
|
472
|
+
//document.body.style.overflow = 'auto';
|
463
473
|
}
|
464
474
|
this.setState({ open: false });
|
465
475
|
}
|
@@ -484,7 +494,7 @@ var _initialiseProps = function () {
|
|
484
494
|
|
485
495
|
this.handleClose = () => {
|
486
496
|
if (!this.props.staticPosition) {
|
487
|
-
document.body.style.overflow = 'auto';
|
497
|
+
//document.body.style.overflow = 'auto';
|
488
498
|
}
|
489
499
|
this.setState({
|
490
500
|
open: false
|
@@ -506,7 +516,7 @@ var _initialiseProps = function () {
|
|
506
516
|
};
|
507
517
|
|
508
518
|
this.handleSelect = (event, item) => {
|
509
|
-
const { multiple, value,
|
519
|
+
const { multiple, value, onChange, options, hierarchic, pinnedItem } = this.props;
|
510
520
|
const { hierarchySelected, hierarchy, nbOptions } = this.state;
|
511
521
|
const hiSelected = _extends({}, hierarchySelected);
|
512
522
|
|
@@ -551,8 +561,20 @@ var _initialiseProps = function () {
|
|
551
561
|
hiSelected[item.parentId].splice(hiSelected[item.parentId].indexOf(item.id), 1);
|
552
562
|
}
|
553
563
|
} else {
|
554
|
-
|
555
|
-
|
564
|
+
if (pinnedItem && item.id === pinnedItem.id) {
|
565
|
+
_Object$keys(hiSelected).map(parentItemId => {
|
566
|
+
hiSelected[parentItemId] = [];
|
567
|
+
return true;
|
568
|
+
});
|
569
|
+
valueList = [item.id];
|
570
|
+
} else {
|
571
|
+
// item non sélectionné => on le sélectionne
|
572
|
+
if (item.hasChildren !== true) valueList.push(item.id);
|
573
|
+
|
574
|
+
if (pinnedItem && valueList.includes(pinnedItem.id)) {
|
575
|
+
valueList.splice(valueList.indexOf(pinnedItem.id), 1);
|
576
|
+
}
|
577
|
+
}
|
556
578
|
|
557
579
|
if (item.hasChildren === true) {
|
558
580
|
// Si item parent => on ajoute tous les enfants
|
@@ -735,6 +757,10 @@ HiSelect.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
735
757
|
* Les items parents sont sélectionnables
|
736
758
|
*/
|
737
759
|
parentItemSelectable: PropTypes.bool,
|
760
|
+
/**
|
761
|
+
* Item épinglé en début de liste
|
762
|
+
*/
|
763
|
+
pinnedItem: PropTypes.object,
|
738
764
|
/**
|
739
765
|
* Placeholder affiché lorsque le select est fermé
|
740
766
|
* Surcharge le placeholder par défaut
|
@@ -116,11 +116,25 @@ class HiSuggestSelect extends React.PureComponent {
|
|
116
116
|
|
117
117
|
render() {
|
118
118
|
const _props = this.props,
|
119
|
-
{ classes,
|
120
|
-
otherProps = _objectWithoutProperties(_props, ['classes', '
|
119
|
+
{ classes, id, showMinLength, showNoResults, onSearch, translations } = _props,
|
120
|
+
otherProps = _objectWithoutProperties(_props, ['classes', 'id', 'showMinLength', 'showNoResults', 'onSearch', 'translations']);
|
121
121
|
|
122
122
|
const { focused, options } = this.state;
|
123
|
-
|
123
|
+
|
124
|
+
let optionsShown = options;
|
125
|
+
|
126
|
+
// If no results match
|
127
|
+
if (options.length === 0 && (showNoResults || showMinLength)) {
|
128
|
+
optionsShown = [{
|
129
|
+
id: '_no_result',
|
130
|
+
type: 'text',
|
131
|
+
disabled: true,
|
132
|
+
centered: true,
|
133
|
+
checkbox: false,
|
134
|
+
label: showNoResults ? translations.no_result_match : translations.min_length
|
135
|
+
}];
|
136
|
+
}
|
137
|
+
const open = !!optionsShown.length && focused;
|
124
138
|
|
125
139
|
return React.createElement(
|
126
140
|
'div',
|
@@ -137,6 +151,7 @@ class HiSuggestSelect extends React.PureComponent {
|
|
137
151
|
Target,
|
138
152
|
null,
|
139
153
|
React.createElement(HiInput, _extends({}, otherProps, {
|
154
|
+
|
140
155
|
inputId: id,
|
141
156
|
focused: focused,
|
142
157
|
inputRef: input => {
|
@@ -162,7 +177,7 @@ class HiSuggestSelect extends React.PureComponent {
|
|
162
177
|
Paper,
|
163
178
|
{ className: classes.paper },
|
164
179
|
React.createElement(HiSelectableList, {
|
165
|
-
itemList:
|
180
|
+
itemList: optionsShown,
|
166
181
|
selectedIdList: [],
|
167
182
|
checkbox: false,
|
168
183
|
onSelect: this.handleSelect,
|
@@ -178,7 +193,12 @@ class HiSuggestSelect extends React.PureComponent {
|
|
178
193
|
}
|
179
194
|
|
180
195
|
HiSuggestSelect.defaultProps = {
|
181
|
-
|
196
|
+
showMinLength: false,
|
197
|
+
showNoResults: false,
|
198
|
+
translations: {
|
199
|
+
no_result_match: 'No result match',
|
200
|
+
min_length: 'Veuillez saisir 3 caractères minimum'
|
201
|
+
},
|
182
202
|
options: []
|
183
203
|
};
|
184
204
|
HiSuggestSelect.propTypes = process.env.NODE_ENV !== "production" ? {
|
@@ -202,6 +222,14 @@ HiSuggestSelect.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
202
222
|
* Liste de suggestions.
|
203
223
|
*/
|
204
224
|
options: PropTypes.array,
|
225
|
+
/**
|
226
|
+
* Permet d'afficher un message si pas assez de caractères
|
227
|
+
*/
|
228
|
+
showMinLength: PropTypes.bool,
|
229
|
+
/**
|
230
|
+
* Permet d'afficher un message si aucune options n'est présente
|
231
|
+
*/
|
232
|
+
showNoResults: PropTypes.bool,
|
205
233
|
/**
|
206
234
|
* Traductions (par défaut en anglais)
|
207
235
|
*/
|
@@ -295,51 +295,44 @@ class HiSelectableListItem extends React.Component {
|
|
295
295
|
listItemProps.button = false;
|
296
296
|
}
|
297
297
|
|
298
|
-
let iconAll;
|
299
|
-
if (item.id === '_all' && item.icon) {
|
300
|
-
iconAll = React.createElement(HiIconBuilder, { icon: item.icon, className: classes.checkboxIcon });
|
301
|
-
}
|
302
|
-
|
303
298
|
// calcul du padding left
|
304
299
|
let paddingLeft = 0;
|
305
300
|
|
306
301
|
if (leftPadding) {
|
307
302
|
paddingLeft = leftPadding;
|
308
|
-
} else {
|
309
|
-
// Si pas de hiérarchie, padding de 8px
|
310
|
-
if (!
|
311
|
-
|
312
|
-
|
303
|
+
} else if (!hierarchic) {
|
304
|
+
// Si pas de hiérarchie et sans checkbox, padding de 8px
|
305
|
+
if (!effectiveCheckbox) {
|
306
|
+
paddingLeft = 8;
|
307
|
+
}
|
308
|
+
} else if (selectable) {
|
309
|
+
// Si item selectionnable
|
310
|
+
// Si parent selectionnable
|
311
|
+
if (parentItemSelectable) {
|
312
|
+
// Si l'item contient une checkbox
|
313
|
+
if (effectiveCheckbox) {
|
314
|
+
paddingLeft = 16 * level;
|
315
|
+
} else {
|
316
|
+
paddingLeft = 16 * (level + 1);
|
313
317
|
}
|
314
|
-
} else if (
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
if (effectiveCheckbox) {
|
320
|
-
paddingLeft = 16 * level;
|
321
|
-
} else {
|
322
|
-
paddingLeft = 16 * (level + 1);
|
323
|
-
}
|
324
|
-
} else if (level > 0) {
|
325
|
-
if (effectiveCheckbox) {
|
326
|
-
paddingLeft = 16 * (level - 1);
|
327
|
-
} else {
|
328
|
-
paddingLeft = 16 * level;
|
329
|
-
}
|
330
|
-
} else if (!effectiveCheckbox) {
|
331
|
-
if (item.id === '_all') {
|
332
|
-
paddingLeft = 16;
|
333
|
-
} else {
|
334
|
-
paddingLeft = 16 * level;
|
335
|
-
}
|
318
|
+
} else if (level > 0) {
|
319
|
+
if (effectiveCheckbox) {
|
320
|
+
paddingLeft = 16 * (level - 1);
|
321
|
+
} else {
|
322
|
+
paddingLeft = 16 * level;
|
336
323
|
}
|
337
|
-
} else {
|
338
|
-
|
339
|
-
|
324
|
+
} else if (!effectiveCheckbox) {
|
325
|
+
if (item.id === '_all') {
|
326
|
+
paddingLeft = 16;
|
327
|
+
} else {
|
340
328
|
paddingLeft = 16 * level;
|
341
329
|
}
|
342
330
|
}
|
331
|
+
} else {
|
332
|
+
paddingLeft = 16; // Padding de 16 par défaut
|
333
|
+
if (level > 0) {
|
334
|
+
paddingLeft = 16 * level;
|
335
|
+
}
|
343
336
|
}
|
344
337
|
|
345
338
|
listItemProps.style = { paddingLeft: `${paddingLeft}px` };
|
@@ -349,8 +342,8 @@ class HiSelectableListItem extends React.Component {
|
|
349
342
|
iconDisplay = hoverIcon;
|
350
343
|
} else if (item.hasChildren) {
|
351
344
|
iconDisplay = parentIcon;
|
352
|
-
} else if (item.
|
353
|
-
iconDisplay =
|
345
|
+
} else if (item.type === 'icon' && item.icon) {
|
346
|
+
iconDisplay = React.createElement(HiIconBuilder, { icon: item.icon, className: classes.checkboxIcon });
|
354
347
|
}
|
355
348
|
|
356
349
|
return React.createElement(
|