@hipay/hipay-material-ui 3.7.4 → 3.7.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -263,7 +263,8 @@ var HiDatePicker = /*#__PURE__*/function (_React$Component) {
263
263
  translations = _this$props.translations,
264
264
  value = _this$props.value,
265
265
  hideOnDayClick = _this$props.hideOnDayClick,
266
- props = (0, _objectWithoutProperties2.default)(_this$props, ["classes", "disabledDays", "disablePastDays", "disableFutureDays", "enableTime", "format", "locale", "minimumDate", "onReset", "translations", "value", "hideOnDayClick"]);
266
+ HiInputProps = _this$props.HiInputProps,
267
+ props = (0, _objectWithoutProperties2.default)(_this$props, ["classes", "disabledDays", "disablePastDays", "disableFutureDays", "enableTime", "format", "locale", "minimumDate", "onReset", "translations", "value", "hideOnDayClick", "HiInputProps"]);
267
268
  var currentMonth = this.state.currentMonth;
268
269
  var today = (0, _momentTimezone.default)();
269
270
  var effectiveDisabledDays = (0, _objectSpread2.default)({}, disablePastDays && {
@@ -312,6 +313,11 @@ var HiDatePicker = /*#__PURE__*/function (_React$Component) {
312
313
  onSubmit: this.props.onSubmit
313
314
  }
314
315
  });
316
+
317
+ if (typeof HiInputProps !== "undefined") {
318
+ inputProps.HiInputProps = (0, _objectSpread2.default)({}, inputProps.HiInputProps, {}, HiInputProps);
319
+ }
320
+
315
321
  return /*#__PURE__*/_react.default.createElement("div", {
316
322
  className: classes.root,
317
323
  onKeyDown: this.handleKeyDown()
@@ -48,6 +48,8 @@ var _Calendar = _interopRequireDefault(require("mdi-material-ui/Calendar"));
48
48
 
49
49
  var _CalendarBlank = _interopRequireDefault(require("mdi-material-ui/CalendarBlank"));
50
50
 
51
+ var _CalendarArrowRight = _interopRequireDefault(require("mdi-material-ui/CalendarArrowRight"));
52
+
51
53
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
52
54
 
53
55
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
@@ -104,12 +106,23 @@ function buildDateRangeInfo(t, from, to, format) {
104
106
  prefix = _options$prefix === void 0 ? null : _options$prefix,
105
107
  _options$toNow = options.toNow,
106
108
  toNow = _options$toNow === void 0 ? false : _options$toNow,
109
+ _options$toToday = options.toToday,
110
+ toToday = _options$toToday === void 0 ? false : _options$toToday,
107
111
  _options$displayDays = options.displayDays,
108
- displayDays = _options$displayDays === void 0 ? true : _options$displayDays; // From
112
+ displayDays = _options$displayDays === void 0 ? true : _options$displayDays,
113
+ _options$displayDayNa = options.displayDayName,
114
+ displayDayName = _options$displayDayNa === void 0 ? false : _options$displayDayNa; // From
115
+
116
+ var info = "".concat(t.from, " ").concat(from.format(format), " "); // Display day name
117
+
118
+ if (displayDayName) {
119
+ info = "".concat(t.from, " ").concat(from.format('dddd'), " ").concat(from.format(format), " ");
120
+ } // To
109
121
 
110
- var info = "".concat(t.from, " ").concat(from.format(format), " "); // To
111
122
 
112
- if (toNow) {
123
+ if (toToday) {
124
+ info += "".concat(t.to_today);
125
+ } else if (toNow) {
113
126
  info += "".concat(t.to_now);
114
127
  } else {
115
128
  info += "".concat(t.to, " ").concat(to.format(format));
@@ -132,7 +145,7 @@ function buildDateRangeInfo(t, from, to, format) {
132
145
 
133
146
  if (displayDays) {
134
147
  var days = Math.ceil(to.diff(from, 'days', true));
135
- info = "".concat(days, " ").concat(t.days, ", ").concat(info);
148
+ info = "".concat(days, " ").concat(days === 1 ? t.day : t.days, ", ").concat(info);
136
149
  }
137
150
 
138
151
  return info;
@@ -143,6 +156,7 @@ function buildDateRangeOptionByKey(key, t, format) {
143
156
  var label;
144
157
  var info;
145
158
  var to;
159
+ var days;
146
160
 
147
161
  switch (key) {
148
162
  case 'custom':
@@ -203,7 +217,8 @@ function buildDateRangeOptionByKey(key, t, format) {
203
217
  label = t.previous_month;
204
218
  from = (0, _momentTimezone.default)().subtract(1, 'month').startOf('month');
205
219
  to = (0, _momentTimezone.default)().subtract(1, 'month').endOf('month');
206
- info = "".concat(from.daysInMonth(), " ").concat(t.days, ", ").concat(yearAndMonth(format, from));
220
+ days = from.daysInMonth();
221
+ info = "".concat(days, " ").concat(days === 1 ? t.day : t.days, ", ").concat(yearAndMonth(format, from));
207
222
  break;
208
223
 
209
224
  case 'cq':
@@ -239,18 +254,27 @@ function buildDateRangeOptionByKey(key, t, format) {
239
254
  });
240
255
  break;
241
256
 
242
- case 'yy':
243
- label = t.year_on_year;
244
- from = (0, _momentTimezone.default)().subtract(1, 'years');
257
+ case "1":
258
+ label = "24h";
259
+ from = (0, _momentTimezone.default)().subtract(1, 'day');
245
260
  to = (0, _momentTimezone.default)();
246
- info = buildDateRangeInfo(t, from, to, format, {
247
- prefix: null,
248
- toNow: true,
249
- displayDays: true
250
- });
261
+ info = "".concat(t.from, " ").concat(from.format("HH:mm"), " ").concat(t.yesterday.toLowerCase(), " ").concat(t.to_now);
251
262
  break;
252
263
 
253
264
  default:
265
+ if (parseInt(key) > 0) {
266
+ label = "".concat(key, " ").concat(key === 1 ? t.day : t.days);
267
+ from = (0, _momentTimezone.default)().subtract(parseInt(key), 'day');
268
+ to = (0, _momentTimezone.default)();
269
+ info = buildDateRangeInfo(t, from, to, format, {
270
+ prefix: null,
271
+ toNow: true,
272
+ toToday: key === 1,
273
+ displayDays: false,
274
+ displayDayName: true
275
+ });
276
+ }
277
+
254
278
  break;
255
279
  }
256
280
 
@@ -307,12 +331,15 @@ var styles = function styles(theme) {
307
331
  };
308
332
 
309
333
  exports.styles = styles;
310
- var PRESET_PERIOD_LIST = ['cd', 'pd', 'cw', 'pw', 'cm', 'pm', 'cq', 'pq', 'cy', 'yy'];
334
+ var PRESET_PERIOD_LIST = ['cd', 'pd', 'cw', 'pw', 'cm', 'pm', 'cq', 'pq', 'cy'];
335
+ var SLIDING_PERIOD_LIST = ['1', '7', '30', '365'];
311
336
  var CUSTOM_PERIOD_LIST = ['custom'];
312
337
 
313
338
  var _ref2 = /*#__PURE__*/_react.default.createElement(_Calendar.default, null);
314
339
 
315
- var _ref3 = /*#__PURE__*/_react.default.createElement(_CalendarBlank.default, null);
340
+ var _ref3 = /*#__PURE__*/_react.default.createElement(_CalendarArrowRight.default, null);
341
+
342
+ var _ref4 = /*#__PURE__*/_react.default.createElement(_CalendarBlank.default, null);
316
343
 
317
344
  var HiDateRangeSelector = /*#__PURE__*/function (_React$Component) {
318
345
  (0, _inherits2.default)(HiDateRangeSelector, _React$Component);
@@ -395,8 +422,6 @@ var HiDateRangeSelector = /*#__PURE__*/function (_React$Component) {
395
422
  }, {
396
423
  key: "buildOptions",
397
424
  value: function buildOptions() {
398
- var _this2 = this;
399
-
400
425
  var _this$props = this.props,
401
426
  availableOptionKeys = _this$props.availableOptionKeys,
402
427
  translations = _this$props.translations;
@@ -405,39 +430,49 @@ var HiDateRangeSelector = /*#__PURE__*/function (_React$Component) {
405
430
  var presetOptionsAvailable = availableOptionKeys.filter(function (option) {
406
431
  return PRESET_PERIOD_LIST.includes(option);
407
432
  });
433
+ var slidingOptionsAvailable = availableOptionKeys.filter(function (option) {
434
+ return SLIDING_PERIOD_LIST.includes(option);
435
+ });
408
436
  var customOptionsAvailable = availableOptionKeys.filter(function (option) {
409
437
  return CUSTOM_PERIOD_LIST.includes(option);
410
438
  });
411
439
 
412
- if (presetOptionsAvailable) {
440
+ if (presetOptionsAvailable.length) {
413
441
  options.push({
414
442
  id: "preset_periods_subheader",
415
443
  type: PRESET_PERIOD_LIST.includes(selectedPreset) ? "primary-highlight" : "highlight",
416
- pinned: true,
417
444
  icon: _ref2,
418
445
  label: translations.preset_periods,
419
- selectable: false
446
+ children: this.options.filter(function (o) {
447
+ return presetOptionsAvailable.includes(o.id);
448
+ }),
449
+ collapseParent: true
420
450
  });
421
- presetOptionsAvailable.forEach(function (option) {
422
- options.push(_this2.options.find(function (_option) {
423
- return _option.id === option;
424
- }));
451
+ }
452
+
453
+ if (slidingOptionsAvailable.length) {
454
+ options.push({
455
+ id: "sliding_periods_subheader",
456
+ type: SLIDING_PERIOD_LIST.includes(selectedPreset) ? "primary-highlight" : "highlight",
457
+ icon: _ref3,
458
+ label: translations.sliding_periods,
459
+ children: this.options.filter(function (o) {
460
+ return slidingOptionsAvailable.includes(o.id);
461
+ }),
462
+ collapseParent: true
425
463
  });
426
464
  }
427
465
 
428
- if (customOptionsAvailable) {
466
+ if (customOptionsAvailable.length) {
429
467
  options.push({
430
468
  id: "custom_periods_subheader",
431
469
  type: CUSTOM_PERIOD_LIST.includes(selectedPreset) ? "primary-highlight" : "highlight",
432
- pinned: true,
433
- icon: _ref3,
470
+ icon: _ref4,
434
471
  label: translations.custom_periods,
435
- selectable: false
436
- });
437
- customOptionsAvailable.forEach(function (option) {
438
- options.push(_this2.options.find(function (_option) {
439
- return _option.id === option;
440
- }));
472
+ children: this.options.filter(function (o) {
473
+ return customOptionsAvailable.includes(o.id);
474
+ }),
475
+ collapseParent: true
441
476
  });
442
477
  }
443
478
 
@@ -446,7 +481,7 @@ var HiDateRangeSelector = /*#__PURE__*/function (_React$Component) {
446
481
  }, {
447
482
  key: "render",
448
483
  value: function render() {
449
- var _this3 = this;
484
+ var _this2 = this;
450
485
 
451
486
  var _this$props2 = this.props,
452
487
  availableOptionKeys = _this$props2.availableOptionKeys,
@@ -477,7 +512,9 @@ var HiDateRangeSelector = /*#__PURE__*/function (_React$Component) {
477
512
  var hiSelectableListProps = {
478
513
  secondaryInline: false,
479
514
  hideCheckbox: true,
480
- lazy: false
515
+ lazy: false,
516
+ collapseParent: true,
517
+ noPadding: true
481
518
  };
482
519
  var options = this.buildOptions();
483
520
  return /*#__PURE__*/_react.default.createElement(_HiFormControl.default, {
@@ -497,7 +534,7 @@ var HiDateRangeSelector = /*#__PURE__*/function (_React$Component) {
497
534
  flexDirection: 'column'
498
535
  } : {},
499
536
  ref: function ref(container) {
500
- _this3.container = container;
537
+ _this2.container = container;
501
538
  }
502
539
  }, /*#__PURE__*/_react.default.createElement("div", {
503
540
  className: classes.select,
@@ -584,12 +621,14 @@ HiDateRangeSelector.defaultProps = {
584
621
  yearAndMonth: 'YYYY[-]MM',
585
622
  yearAndQuarter: 'YYYY[-Q]Q',
586
623
  year: 'Year',
624
+ day: 'day',
587
625
  days: 'days',
588
626
  custom_period: 'Custom Period',
589
627
  yesterday: 'Yesterday',
590
628
  from: 'from',
591
629
  to: 'to',
592
630
  to_now: 'to now',
631
+ to_today: 'to today',
593
632
  current_week: 'Current Week',
594
633
  previous_week: 'Previous Week',
595
634
  current_month: 'Current Month',
@@ -606,7 +645,8 @@ HiDateRangeSelector.defaultProps = {
606
645
  missing_date_to: 'Missing date to',
607
646
  preset_periods: 'Preset periods',
608
647
  custom_periods: 'Custom periods',
609
- custom_period_info: "Select a custom period"
648
+ custom_period_info: "Select a custom period",
649
+ sliding_periods: 'Sliding periods'
610
650
  }
611
651
  };
612
652
 
@@ -52,7 +52,8 @@ var HiDialog = function HiDialog(props) {
52
52
  id = props.id,
53
53
  onClose = props.onClose,
54
54
  open = props.open,
55
- title = props.title;
55
+ title = props.title,
56
+ closeBtn = props.closeBtn;
56
57
  var classes = useStyles(props);
57
58
  var handleClose = (0, _react.useCallback)(function () {
58
59
  if (onClose) {
@@ -68,9 +69,9 @@ var HiDialog = function HiDialog(props) {
68
69
  open: open
69
70
  }, /*#__PURE__*/_react.default.createElement("div", {
70
71
  className: classes.header
71
- }, /*#__PURE__*/_react.default.createElement("p", {
72
+ }, typeof title === "string" ? /*#__PURE__*/_react.default.createElement("p", {
72
73
  className: classes.title
73
- }, title), /*#__PURE__*/_react.default.createElement("div", {
74
+ }, title) : title, closeBtn !== false && /*#__PURE__*/_react.default.createElement("div", {
74
75
  className: classes.closeDiv
75
76
  }, /*#__PURE__*/_react.default.createElement(_HiIconButton.default, {
76
77
  id: "close-dialog-btn",
@@ -185,6 +185,18 @@ var HiSelect = /*#__PURE__*/function (_React$PureComponent) {
185
185
  };
186
186
  };
187
187
 
188
+ _this.findRecursively = function (arr, id) {
189
+ for (var i = 0; i < arr.length; i++) {
190
+ if (arr[i].id === id) {
191
+ return arr[i];
192
+ } else if (arr[i].children && arr[i].children.length) {
193
+ var found = _this.findRecursively(arr[i].children, id);
194
+
195
+ if (found) return found;
196
+ }
197
+ }
198
+ };
199
+
188
200
  _this.buildInputValue = function (options) {
189
201
  var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
190
202
  var loading = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
@@ -204,9 +216,7 @@ var HiSelect = /*#__PURE__*/function (_React$PureComponent) {
204
216
  } else if (value.length > 1) {
205
217
  inputValue = translations.n_items_selected.replace('%s', value.length);
206
218
  } else if (value.length === 1) {
207
- var item = options.find(function (o) {
208
- return o.id === value[0];
209
- });
219
+ var item = _this.findRecursively(options, value[0]);
210
220
 
211
221
  if (item === undefined) {
212
222
  inputValue = translations.one_item_selected;
@@ -282,7 +292,7 @@ var HiSelect = /*#__PURE__*/function (_React$PureComponent) {
282
292
  }
283
293
  };
284
294
 
285
- _this.handleClick = function () {
295
+ _this.handleClick = function (event) {
286
296
  if (_this.state.open) {
287
297
  _this.handleClose();
288
298
  } else if (_this.props.alert && !_this.state.alertOpen) {
@@ -368,7 +378,9 @@ var HiSelect = /*#__PURE__*/function (_React$PureComponent) {
368
378
  }
369
379
 
370
380
  if (_this.inputEl) {
371
- _this.inputEl.focus();
381
+ setTimeout(function () {
382
+ _this.inputEl.focus();
383
+ }, 100);
372
384
  }
373
385
  };
374
386
 
@@ -396,7 +408,16 @@ var HiSelect = /*#__PURE__*/function (_React$PureComponent) {
396
408
  var key = (0, _keycode.default)(event);
397
409
 
398
410
  if (!_this.state.alertOpen) {
399
- if (key === 'esc' && _this.state.open) {
411
+ if (event.target === _this.inputEl && _this.state.open && key === 'down') {
412
+ // Focus on list 1st item
413
+ event.stopPropagation();
414
+ event.preventDefault();
415
+ var firstLi = document.querySelector("#".concat(_this.props.id, " + div ul > li"));
416
+
417
+ if (!!firstLi) {
418
+ firstLi.focus();
419
+ }
420
+ } else if (key === 'esc' && _this.state.open) {
400
421
  event.stopPropagation();
401
422
  event.preventDefault();
402
423
 
@@ -409,10 +430,32 @@ var HiSelect = /*#__PURE__*/function (_React$PureComponent) {
409
430
  }
410
431
  } else if (key === 'space' && event.target !== _this.searchField) {
411
432
  event.preventDefault();
433
+ } else if (key === 'tab' && (_this.state.open || _this.state.alertOpen)) {
434
+ event.stopPropagation();
412
435
 
413
- _this.handleClick();
414
- } else if (key === 'tab') {
415
436
  _this.handleClose();
437
+ } else if (key === "down" && event.target.id.includes("_subheader")) {
438
+ // Focus on parent, next item is child
439
+ if (document.querySelector("#group-".concat(event.target.id, " li:nth-child(1)"))) {
440
+ document.querySelector("#group-".concat(event.target.id, " li:nth-child(1)")).focus();
441
+ }
442
+ } else if (key === "down" && !event.target.nextSibling) {
443
+ var _document$getElementB, _document$getElementB2;
444
+
445
+ // Focus on parent, next item is child
446
+ if ((_document$getElementB = document.getElementById(event.target.dataset.group)) === null || _document$getElementB === void 0 ? void 0 : (_document$getElementB2 = _document$getElementB.nextSibling) === null || _document$getElementB2 === void 0 ? void 0 : _document$getElementB2.nextSibling) {
447
+ document.getElementById(event.target.dataset.group).nextSibling.nextSibling.focus();
448
+ }
449
+ } else if (key === "up") {
450
+ if (event.target.previousSibling === null && !!event.target.dataset.group) {
451
+ // Previous item is parent item
452
+ document.getElementById(event.target.dataset.group).focus();
453
+ } else if (!!event.target.previousSibling && !event.target.dataset.group) {
454
+ // On parent, go to previous (last) child
455
+ if (event.target.previousSibling.querySelector("li:last-child")) {
456
+ event.target.previousSibling.querySelector("li:last-child").focus();
457
+ }
458
+ }
416
459
  }
417
460
  }
418
461
  };
@@ -448,9 +491,11 @@ var HiSelect = /*#__PURE__*/function (_React$PureComponent) {
448
491
  value = _this$props2.value;
449
492
 
450
493
  if (!multiple) {
451
- // single value
452
- _this.handleClose();
453
-
494
+ // This is a fix to prevent select open after select => TODO improve ?
495
+ setTimeout(function () {
496
+ // single value
497
+ _this.handleClose();
498
+ }, 1);
454
499
  onChange(event, item.id, item);
455
500
  } else if (hasAll && item.id === '_all') {
456
501
  if (value.length === options.length) {
@@ -13,8 +13,6 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/es
13
13
 
14
14
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/createClass"));
15
15
 
16
- var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/assertThisInitialized"));
17
-
18
16
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/inherits"));
19
17
 
20
18
  var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/possibleConstructorReturn"));
@@ -167,19 +165,22 @@ var HiSelectInput = /*#__PURE__*/function (_React$PureComponent) {
167
165
 
168
166
  var _super = _createSuper(HiSelectInput);
169
167
 
170
- function HiSelectInput(props) {
168
+ function HiSelectInput() {
171
169
  var _this;
172
170
 
173
171
  (0, _classCallCheck2.default)(this, HiSelectInput);
174
- _this = _super.call(this, props);
172
+
173
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
174
+ args[_key] = arguments[_key];
175
+ }
176
+
177
+ _this = _super.call.apply(_super, [this].concat(args));
175
178
 
176
179
  _this.handleKeyDown = function (event) {
177
180
  var key = (0, _keycode.default)(event);
178
181
 
179
182
  if (_this.props.onKeyDown) {
180
183
  _this.props.onKeyDown(event);
181
- } else if (key === 'down' || key === 'up') {
182
- _this.props.onClick();
183
184
  } else if (key === 'enter' && _this.props.onSubmit) {
184
185
  event.preventDefault();
185
186
 
@@ -234,11 +235,6 @@ var HiSelectInput = /*#__PURE__*/function (_React$PureComponent) {
234
235
  }
235
236
  };
236
237
 
237
- _this.handleKeyDown = _this.handleKeyDown.bind((0, _assertThisInitialized2.default)(_this));
238
- _this.handleClick = _this.handleClick.bind((0, _assertThisInitialized2.default)(_this));
239
- _this.handleBlur = _this.handleBlur.bind((0, _assertThisInitialized2.default)(_this));
240
- _this.ref = _this.ref.bind((0, _assertThisInitialized2.default)(_this));
241
- _this.handleReset = _this.handleReset.bind((0, _assertThisInitialized2.default)(_this));
242
238
  return _this;
243
239
  }
244
240
 
@@ -27,6 +27,8 @@ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/es
27
27
 
28
28
  var _react = _interopRequireDefault(require("react"));
29
29
 
30
+ var _Collapse = _interopRequireDefault(require("@material-ui/core/Collapse"));
31
+
30
32
  var _List = _interopRequireDefault(require("@material-ui/core/List"));
31
33
 
32
34
  var _styles = require("@material-ui/core/styles");
@@ -54,9 +56,32 @@ var styles = function styles(theme) {
54
56
  suggestionFocus: {
55
57
  backgroundColor: theme.palette.action.hover,
56
58
  fontWeight: theme.typography.fontWeightMedium
59
+ },
60
+ parentRoot: {
61
+ "&:focus": {
62
+ backgroundColor: theme.palette.action.hover,
63
+ fontWeight: theme.typography.fontWeightMedium
64
+ }
57
65
  }
58
66
  };
59
67
  };
68
+
69
+ exports.styles = styles;
70
+
71
+ var findSelectedItemParent = function findSelectedItemParent(arr, id) {
72
+ if (id) {
73
+ var res = arr.find(function (p) {
74
+ var _p$children;
75
+
76
+ return (_p$children = p.children) === null || _p$children === void 0 ? void 0 : _p$children.map(function (o) {
77
+ return o.id;
78
+ }).includes(id);
79
+ });
80
+ if (res) return res.id;
81
+ }
82
+
83
+ return null;
84
+ };
60
85
  /**
61
86
  * Construit une liste d'item sélectionnable (avec checkbox)
62
87
  * - la navigation au clavier est gérée par l'event KeyDown
@@ -64,27 +89,28 @@ var styles = function styles(theme) {
64
89
  */
65
90
 
66
91
 
67
- exports.styles = styles;
68
-
69
92
  var HiSelectableList = /*#__PURE__*/function (_React$PureComponent) {
70
93
  (0, _inherits2.default)(HiSelectableList, _React$PureComponent);
71
94
 
72
95
  var _super = _createSuper(HiSelectableList);
73
96
 
74
- function HiSelectableList() {
97
+ function HiSelectableList(props) {
75
98
  var _this;
76
99
 
77
100
  (0, _classCallCheck2.default)(this, HiSelectableList);
78
-
79
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
80
- args[_key] = arguments[_key];
81
- }
82
-
83
- _this = _super.call.apply(_super, [this].concat(args));
101
+ _this = _super.call(this, props);
84
102
 
85
103
  _this.handleSelect = function (item) {
86
104
  return function (event) {
87
- _this.props.onSelect(event, item);
105
+ if (_this.props.collapseParent && item.children) {
106
+ _this.setState(function (prevState) {
107
+ return {
108
+ openedParent: prevState.openedParent === item.id ? null : item.id
109
+ };
110
+ });
111
+ } else {
112
+ _this.props.onSelect(event, item);
113
+ }
88
114
  };
89
115
  };
90
116
 
@@ -111,6 +137,7 @@ var HiSelectableList = /*#__PURE__*/function (_React$PureComponent) {
111
137
 
112
138
  _this.buildRecursiveListItem = function (item, index) {
113
139
  var level = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
140
+ var group = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
114
141
  var _this$props = _this.props,
115
142
  checkedIcon = _this$props.checkedIcon,
116
143
  disabled = _this$props.disabled,
@@ -125,7 +152,8 @@ var HiSelectableList = /*#__PURE__*/function (_React$PureComponent) {
125
152
  onKeyUp = _this$props.onKeyUp,
126
153
  suggestionFocusIndex = _this$props.suggestionFocusIndex,
127
154
  classes = _this$props.classes,
128
- others = (0, _objectWithoutProperties2.default)(_this$props, ["checkedIcon", "disabled", "disabledItemIdList", "hideCheckbox", "hoverIcon", "icon", "lazy", "selectedItemIdList", "sort", "onKeyDown", "onKeyUp", "suggestionFocusIndex", "classes"]);
155
+ noPadding = _this$props.noPadding,
156
+ others = (0, _objectWithoutProperties2.default)(_this$props, ["checkedIcon", "disabled", "disabledItemIdList", "hideCheckbox", "hoverIcon", "icon", "lazy", "selectedItemIdList", "sort", "onKeyDown", "onKeyUp", "suggestionFocusIndex", "classes", "noPadding"]);
129
157
 
130
158
  if (sort && item.children) {
131
159
  item.children.sort(_this.compareItem);
@@ -148,6 +176,12 @@ var HiSelectableList = /*#__PURE__*/function (_React$PureComponent) {
148
176
  }
149
177
  }));
150
178
 
179
+ var handleKeyDown = function handleKeyDown() {
180
+ if (onKeyDown) {
181
+ onKeyDown();
182
+ }
183
+ };
184
+
151
185
  var itemComponent = /*#__PURE__*/_react.default.createElement(_react.default.Fragment, {
152
186
  key: item.id
153
187
  }, /*#__PURE__*/_react.default.createElement(_HiSelectableListItem.default, (0, _extends2.default)({}, others, {
@@ -156,21 +190,34 @@ var HiSelectableList = /*#__PURE__*/function (_React$PureComponent) {
156
190
  hideCheckbox: hideCheckbox,
157
191
  hoverIcon: hoverIcon,
158
192
  icon: icon,
159
- level: level,
193
+ level: noPadding ? 0 : level,
160
194
  onSelect: item.selectable !== false ? _this.handleSelect(item) : undefined,
161
- onKeyDown: item.selectable !== false ? onKeyDown : undefined,
195
+ onKeyDown: item.selectable !== false ? handleKeyDown : undefined,
162
196
  onKeyUp: onKeyUp,
163
197
  selected: selectedItemIdList.includes(item.id) // item props override upper props (disabled, hideCheckbox, icon, level...)
164
198
  ,
165
199
  item: item,
166
200
  classes: {
201
+ root: classes.parentRoot,
167
202
  listItem: (0, _classnames.default)((0, _defineProperty2.default)({}, classes.suggestionFocus, index === suggestionFocusIndex))
168
- }
169
- }, item)), item.children && item.children.length > 0 && item.children.filter(function (subItem) {
203
+ },
204
+ collapseHeader: _this.props.collapseParent && item.children && item.children.length > 0,
205
+ opened: _this.state.openedParent === item.id,
206
+ group: group
207
+ }, item)), item.children && item.children.length > 0 && (_this.props.collapseParent && level === 0 ? /*#__PURE__*/_react.default.createElement(_Collapse.default, {
208
+ id: "group-".concat(item.id),
209
+ in: _this.state.openedParent === item.id,
210
+ timeout: "auto",
211
+ unmountOnExit: true
212
+ }, item.children.filter(function (subItem) {
213
+ return !(subItem.displayed === false);
214
+ }).map(function (subItem) {
215
+ return _this.buildRecursiveListItem(subItem, index, level + 1, item.id);
216
+ })) : item.children.filter(function (subItem) {
170
217
  return !(subItem.displayed === false);
171
218
  }).map(function (subItem) {
172
219
  return _this.buildRecursiveListItem(subItem, index, level + 1);
173
- }));
220
+ })));
174
221
 
175
222
  if (lazy) {
176
223
  return /*#__PURE__*/_react.default.createElement(_reactLazyload.default, {
@@ -208,6 +255,19 @@ var HiSelectableList = /*#__PURE__*/function (_React$PureComponent) {
208
255
  return (0, _helpers.foldAccents)(a.label.toString().toLowerCase()) > (0, _helpers.foldAccents)(b.label.toString().toLowerCase()) ? 1 : -1;
209
256
  };
210
257
 
258
+ var openedParent;
259
+
260
+ if (props.collapseParent) {
261
+ if (props.selectedItemIdList[0]) {
262
+ openedParent = findSelectedItemParent(props.itemList, props.selectedItemIdList[0]);
263
+ } else {
264
+ openedParent = props.itemList[0].id;
265
+ }
266
+ }
267
+
268
+ _this.state = {
269
+ openedParent: openedParent
270
+ };
211
271
  return _this;
212
272
  }
213
273
 
@@ -289,7 +349,8 @@ HiSelectableList.defaultProps = {
289
349
  lazy: true,
290
350
  selectedItemIdList: [],
291
351
  sort: false,
292
- sortAppendList: ['_all']
352
+ sortAppendList: ['_all'],
353
+ collapseParent: false
293
354
  };
294
355
 
295
356
  var _default = (0, _styles.withStyles)(styles, {