@hipay/hipay-material-ui 2.0.0-beta.50 → 2.0.0-beta.51

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,525 @@
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 _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
+
12
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
13
+
14
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
15
+
16
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
17
+
18
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
19
+
20
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
21
+
22
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
23
+
24
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
25
+
26
+ var _react = _interopRequireDefault(require("react"));
27
+
28
+ var _propTypes = _interopRequireDefault(require("prop-types"));
29
+
30
+ var _reactCustomScrollbars = _interopRequireDefault(require("react-custom-scrollbars"));
31
+
32
+ var _HiSelectableList = _interopRequireDefault(require("../HiSelectableList"));
33
+
34
+ var _HiInput = _interopRequireDefault(require("../HiForm/HiInput"));
35
+
36
+ var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
37
+
38
+ var _helpers = require("../utils/helpers");
39
+
40
+ var _HiIcon = _interopRequireDefault(require("../HiIcon"));
41
+
42
+ var _keycode = _interopRequireDefault(require("keycode"));
43
+
44
+ var styles = function styles(theme) {
45
+ return {
46
+ labelIcon: {
47
+ marginRight: 10
48
+ },
49
+ labelImg: {
50
+ height: 18,
51
+ width: 'auto',
52
+ margin: '0 4px',
53
+ verticalAlign: 'middle'
54
+ },
55
+ selectIconLabel: (0, _extends2.default)({
56
+ whiteSpace: 'nowrap',
57
+ overflow: 'hidden',
58
+ textOverflow: 'ellipsis',
59
+ paddingRight: 16
60
+ }, theme.typography.b1, {
61
+ display: 'inline-flex',
62
+ width: '100%'
63
+ }),
64
+ selectImgLabel: (0, _extends2.default)({
65
+ whiteSpace: 'nowrap',
66
+ overflow: 'hidden',
67
+ textOverflow: 'ellipsis',
68
+ paddingRight: 16
69
+ }, theme.typography.b1, {
70
+ display: 'inline-flex',
71
+ width: '100%'
72
+ })
73
+ };
74
+ };
75
+ /**
76
+ *
77
+ * Utilisé pour tous types de selects dans les formulaires.
78
+ * - single / multiple ( multi-select )
79
+ * - avec / sans checkboxes
80
+ * - avec / sans barre de recherche
81
+ * - avec / sans option "All"
82
+ * - prise en compte du type des éléments (text, image, icon, ...)
83
+ *
84
+ * Ce composant réuni les sous-composants
85
+ * - HiSelectInput : affiche l'élément dans le formulaire
86
+ * - HiSearchField : intègre une barre de recherche dans le Popper, il filtre la liste des suggestions
87
+ * - HiSelectableList : affiche la liste des suggestions selon le type des éléments
88
+ */
89
+
90
+
91
+ exports.styles = styles;
92
+
93
+ var HiSelectContent =
94
+ /*#__PURE__*/
95
+ function (_React$PureComponent) {
96
+ (0, _inherits2.default)(HiSelectContent, _React$PureComponent);
97
+
98
+ function HiSelectContent(props) {
99
+ var _this;
100
+
101
+ (0, _classCallCheck2.default)(this, HiSelectContent);
102
+ _this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(HiSelectContent).call(this, props));
103
+
104
+ _this.handleKeyDown = function (event) {
105
+ var nextItem;
106
+ var key = (0, _keycode.default)(event);
107
+
108
+ if (key === 'down') {
109
+ event.preventDefault();
110
+ nextItem = (0, _helpers.getNextItemSelectable)(document.activeElement, 'down');
111
+ } else if (key === 'up') {
112
+ event.preventDefault();
113
+ nextItem = (0, _helpers.getNextItemSelectable)(document.activeElement, 'up');
114
+ } else if (key === 'tab' || key === 'esc') {
115
+ _this.setState({
116
+ open: false
117
+ });
118
+ } else if (key === 'space' || key === 'enter' && !_this.props.multiple) {
119
+ event.preventDefault();
120
+
121
+ var item = _this.props.options.find(function (elem) {
122
+ return String(elem.id) === event.target.id;
123
+ });
124
+
125
+ _this.handleSelect(null, item);
126
+ } else if (key === 'enter' && _this.props.multiple) {
127
+ event.preventDefault();
128
+
129
+ _this.handleClose();
130
+ }
131
+
132
+ if (nextItem) {
133
+ nextItem.focus();
134
+ }
135
+ };
136
+
137
+ _this.handleKeyDownSearch = function (event) {
138
+ var key = (0, _keycode.default)(event);
139
+
140
+ if (_this.overlay && (key === 'down' || key === 'up')) {
141
+ _this.focusOnFirstItem();
142
+ } else if (_this.overlay && key === 'esc' || key === 'enter') {
143
+ event.preventDefault();
144
+
145
+ _this.handleClose();
146
+ }
147
+ };
148
+
149
+ _this.handleSelect = function (event, item) {
150
+ var _this$props = _this.props,
151
+ hasAll = _this$props.hasAll,
152
+ multiple = _this$props.multiple,
153
+ onChange = _this$props.onChange,
154
+ options = _this$props.options,
155
+ value = _this$props.value;
156
+
157
+ if (!multiple) {
158
+ // single value
159
+ _this.handleClose();
160
+
161
+ onChange(event, item.id, item);
162
+ } else if (hasAll && item.id === '_all') {
163
+ if (value.length === options.length) {
164
+ // unselect _all options
165
+ onChange(event, [], item);
166
+ } else {
167
+ // select _all options
168
+ onChange(event, options.map(function (option) {
169
+ return option.id;
170
+ }), item);
171
+ }
172
+ } else if (value.includes(item.id)) {
173
+ // unselect item
174
+ onChange(event, value.filter(function (id) {
175
+ return id !== item.id;
176
+ }), item);
177
+ } else {
178
+ onChange(event, (0, _toConsumableArray2.default)(value).concat([item.id]), item);
179
+ }
180
+ };
181
+
182
+ _this.handleClose = function () {
183
+ if (_this.props.onClose) _this.props.onClose();
184
+ };
185
+
186
+ _this.handleSuggestions = function (suggestions) {
187
+ var _this$props2 = _this.props,
188
+ hasAll = _this$props2.hasAll,
189
+ iconAll = _this$props2.iconAll,
190
+ translations = _this$props2.translations;
191
+
192
+ if (suggestions.length === 0) {
193
+ // Add '_no_result' suggestion
194
+ _this.setState(function (prevState) {
195
+ return (0, _extends2.default)({}, prevState, {
196
+ suggestions: [{
197
+ id: '_no_result',
198
+ type: 'text',
199
+ disabled: true,
200
+ centered: true,
201
+ hideCheckbox: true,
202
+ label: translations.no_result_match
203
+ }]
204
+ });
205
+ });
206
+ } else {
207
+ _this.setState({
208
+ suggestions: (0, _toConsumableArray2.default)(hasAll ? [(0, _extends2.default)({
209
+ id: '_all',
210
+ label: translations.all
211
+ }, iconAll && {
212
+ type: 'icon',
213
+ icon: iconAll
214
+ })] : []).concat((0, _toConsumableArray2.default)(suggestions))
215
+ });
216
+ }
217
+ };
218
+
219
+ _this.handleScroll = function (e) {
220
+ if (e.target.scrollHeight - e.target.clientHeight - e.target.scrollTop < 15) {
221
+ _this.props.onScrollReachBottom();
222
+ }
223
+ };
224
+
225
+ _this.handleSearch = function (e, inputValue) {
226
+ var searchValue = inputValue && e.target.value ? inputValue : e.target.value;
227
+
228
+ if (_this.props.onSearch) {
229
+ _this.props.onSearch(e, searchValue);
230
+ } else {
231
+ _this.setState({
232
+ searchValue: searchValue
233
+ });
234
+ }
235
+ };
236
+
237
+ _this.handleSearchReset = function () {
238
+ _this.handleSearch({
239
+ target: {
240
+ value: ''
241
+ }
242
+ }, '');
243
+ };
244
+
245
+ _this.buildSelectProps = function (options) {
246
+ var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
247
+ var search = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
248
+ var loading = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
249
+ // build item list
250
+ var itemList = (0, _toConsumableArray2.default)(loading ? [{
251
+ id: '_loading',
252
+ type: 'loader',
253
+ disabled: true,
254
+ centered: true,
255
+ hideCheckbox: true,
256
+ label: 'loading'
257
+ }] : []).concat((0, _toConsumableArray2.default)(search !== '' ? (0, _toConsumableArray2.default)(options.filter(function (item) {
258
+ return item.label && (0, _helpers.foldAccents)(item.label.toString().toLowerCase()).search((0, _helpers.foldAccents)(search.toLowerCase())) !== -1;
259
+ })) : (0, _toConsumableArray2.default)(_this.props.hasAll ? [(0, _extends2.default)({
260
+ id: '_all',
261
+ label: _this.props.translations.all
262
+ }, _this.props.iconAll && {
263
+ type: 'icon',
264
+ icon: _this.props.iconAll
265
+ })] : []).concat((0, _toConsumableArray2.default)(options))));
266
+ return {
267
+ itemList: itemList
268
+ };
269
+ };
270
+
271
+ _this.getInputElement = function (el) {
272
+ _this.searchField = el;
273
+
274
+ if (_this.props.inputRef) {
275
+ _this.props.inputRef(_this.searchField);
276
+ }
277
+ };
278
+
279
+ _this.state = {
280
+ open: false,
281
+ focused: false,
282
+ searchValue: props.searchValue ? undefined : '',
283
+ suggestions: props.options
284
+ };
285
+ _this.handleSearch = _this.handleSearch.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
286
+ _this.handleSearchReset = _this.handleSearchReset.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
287
+ _this.handleSelect = _this.handleSelect.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
288
+ _this.handleSuggestions = _this.handleSuggestions.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
289
+ return _this;
290
+ }
291
+
292
+ (0, _createClass2.default)(HiSelectContent, [{
293
+ key: "render",
294
+ value: function render() {
295
+ var _this2 = this;
296
+
297
+ var _this$props3 = this.props,
298
+ classes = _this$props3.classes,
299
+ disabled = _this$props3.disabled,
300
+ error = _this$props3.error,
301
+ loading = _this$props3.loading,
302
+ options = _this$props3.options,
303
+ searchable = _this$props3.searchable,
304
+ type = _this$props3.type,
305
+ value = _this$props3.value,
306
+ multiple = _this$props3.multiple,
307
+ translations = _this$props3.translations,
308
+ hiSelectableListProps = _this$props3.hiSelectableListProps,
309
+ hiSelectInputProps = _this$props3.hiSelectInputProps,
310
+ id = _this$props3.id,
311
+ onScrollReachBottom = _this$props3.onScrollReachBottom,
312
+ onSubmit = _this$props3.onSubmit,
313
+ startAdornment = _this$props3.startAdornment,
314
+ _this$props3$searchVa = _this$props3.searchValue,
315
+ searchValue = _this$props3$searchVa === void 0 ? this.state.searchValue : _this$props3$searchVa,
316
+ _this$props3$buildSel = _this$props3.buildSelectProps,
317
+ buildSelectProps = _this$props3$buildSel === void 0 ? this.buildSelectProps : _this$props3$buildSel,
318
+ autoHeight = _this$props3.autoHeight,
319
+ height = _this$props3.height;
320
+
321
+ if (multiple) {
322
+ if (!Array.isArray(value)) {
323
+ throw new Error('HiPay Material-UI: the `value` property must be an array ' + 'when using the `HiSelect` component with `multiple`.');
324
+ }
325
+ }
326
+
327
+ var selectedItemIdList = [];
328
+
329
+ if (value) {
330
+ selectedItemIdList = multiple ? (0, _toConsumableArray2.default)(value) : [value];
331
+ }
332
+
333
+ var _buildSelectProps = buildSelectProps(options, selectedItemIdList, searchValue, loading),
334
+ itemList = _buildSelectProps.itemList;
335
+
336
+ return _react.default.createElement(_react.default.Fragment, null, !!searchable && _react.default.createElement(_HiInput.default, {
337
+ value: searchValue,
338
+ autoFocus: true,
339
+ inputRef: this.getInputElement,
340
+ onKeyDown: this.handleKeyDownSearch,
341
+ onChange: this.handleSearch,
342
+ onReset: this.handleSearchReset,
343
+ placeholder: translations.search,
344
+ startAdornment: 'search',
345
+ tabIndex: 0
346
+ }), startAdornment, _react.default.createElement(_reactCustomScrollbars.default, (0, _extends2.default)({
347
+ ref: function ref(contentEl) {
348
+ _this2.optionsContent = contentEl;
349
+ }
350
+ }, autoHeight ? {
351
+ autoHeight: true,
352
+ autoHeightMax: height
353
+ } : {
354
+ autoHeightMax: height,
355
+ autoHeightMin: height
356
+ }, {
357
+ autoHeight: true,
358
+ autoHeightMax: height // TODO ?
359
+
360
+ }, onScrollReachBottom && {
361
+ onScroll: this.handleScroll
362
+ }), _react.default.createElement(_HiSelectableList.default, (0, _extends2.default)({
363
+ type: type,
364
+ itemList: itemList,
365
+ onKeyDown: this.handleKeyDown,
366
+ onSelect: this.handleSelect,
367
+ selectedItemIdList: selectedItemIdList,
368
+ fallbackImage: this.props.fallbackImage
369
+ }, hiSelectableListProps))));
370
+ }
371
+ }], [{
372
+ key: "getDerivedStateFromProps",
373
+ value: function getDerivedStateFromProps(nextProps, prevState) {
374
+ if (nextProps.options !== prevState.suggestions) {
375
+ return (0, _extends2.default)({}, prevState, {
376
+ suggestions: nextProps.options
377
+ });
378
+ }
379
+
380
+ return null;
381
+ } // Key down on list items
382
+
383
+ }]);
384
+ return HiSelectContent;
385
+ }(_react.default.PureComponent);
386
+
387
+ HiSelectContent.defaultProps = {
388
+ autoHeight: true,
389
+ height: 400,
390
+ disabled: false,
391
+ error: false,
392
+ hasAll: false,
393
+ hiSelectableListProps: {},
394
+ hiSelectInputProps: {},
395
+ multiple: false,
396
+ searchable: false,
397
+ translations: {
398
+ all: 'All',
399
+ no_result_match: 'No result match',
400
+ search: 'Search',
401
+ n_items_selected: '%s items selected',
402
+ one_item_selected: '%s item selected',
403
+ n_children: '%s items',
404
+ one_child: '%s item'
405
+ },
406
+ type: 'text'
407
+ };
408
+ HiSelectContent.propTypes = process.env.NODE_ENV !== "production" ? {
409
+ autoHeight: _propTypes.default.bool,
410
+
411
+ /**
412
+ * Useful to extend the style applied to components.
413
+ */
414
+ classes: _propTypes.default.object,
415
+
416
+ /**
417
+ * Inactif
418
+ */
419
+ disabled: _propTypes.default.bool,
420
+
421
+ /**
422
+ * Applique le style error
423
+ */
424
+ error: _propTypes.default.bool,
425
+
426
+ /**
427
+ * Chemin vers l'image à afficher par défaut si une image n'est pas trouvée
428
+ */
429
+ fallbackImage: _propTypes.default.string,
430
+
431
+ /**
432
+ * Affiche l'élément 'All'
433
+ */
434
+ hasAll: _propTypes.default.bool,
435
+
436
+ /**
437
+ * Hauteur du container scrollable
438
+ */
439
+ height: _propTypes.default.number,
440
+
441
+ /**
442
+ * Override HiSelectableList props (
443
+ */
444
+ hiSelectableListProps: _propTypes.default.object,
445
+
446
+ /**
447
+ * Override HiSelectInput props
448
+ */
449
+ hiSelectInputProps: _propTypes.default.object,
450
+
451
+ /**
452
+ * Nom de l'icône
453
+ */
454
+ iconAll: _propTypes.default.string,
455
+
456
+ /**
457
+ * id du select
458
+ */
459
+ id: _propTypes.default.string,
460
+
461
+ /**
462
+ * Ajoute un loader
463
+ */
464
+ loading: _propTypes.default.bool,
465
+
466
+ /**
467
+ * Autorise la sélection de plusieurs valeurs
468
+ */
469
+ multiple: _propTypes.default.bool,
470
+
471
+ /**
472
+ * Fonction de callback qui renvoit la/les valeurs sélectionnées
473
+ *
474
+ * @param {object} event
475
+ * @param {string || array} value
476
+ */
477
+ onChange: _propTypes.default.func.isRequired,
478
+
479
+ /**
480
+ * Fonction de callback appelée lorsque le scroll atteint le bas de la liste
481
+ */
482
+ onScrollReachBottom: _propTypes.default.func,
483
+
484
+ /**
485
+ * Fonction de callback appelée lorsque le champs de recherche est utilisé
486
+ */
487
+ onSearch: _propTypes.default.func,
488
+
489
+ /**
490
+ * Listes des options du select
491
+ */
492
+ options: _propTypes.default.array.isRequired,
493
+
494
+ /**
495
+ * Affiche un input de recherche permettant de filtrer les options
496
+ */
497
+ searchable: _propTypes.default.bool,
498
+
499
+ /**
500
+ * Node qui s'ajoute entre la barre de recherche et la liste de résultats
501
+ */
502
+ startAdornment: _propTypes.default.object,
503
+
504
+ /**
505
+ * Traductions (par défaut en anglais)
506
+ */
507
+ translations: _propTypes.default.object,
508
+
509
+ /**
510
+ * Type des éléments du select, définit le rendu d'un élément
511
+ */
512
+ type: _propTypes.default.oneOf(['icon', 'text', 'image', 'primary-highlight']),
513
+
514
+ /**
515
+ * Value(s) du select
516
+ */
517
+ value: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string, _propTypes.default.array])
518
+ } : {};
519
+
520
+ var _default = (0, _withStyles.default)(styles, {
521
+ hiComponent: true,
522
+ name: 'HmuiHiSelectContent'
523
+ })(HiSelectContent);
524
+
525
+ exports.default = _default;
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
+
3
5
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
6
 
5
7
  Object.defineProperty(exports, "__esModule", {
@@ -29,6 +31,30 @@ Object.defineProperty(exports, "HiSelectInput", {
29
31
  return _HiSelectInput.default;
30
32
  }
31
33
  });
34
+ Object.defineProperty(exports, "HiSelectContent", {
35
+ enumerable: true,
36
+ get: function get() {
37
+ return _HiSelectContent.default;
38
+ }
39
+ });
40
+ Object.defineProperty(exports, "HiNestedSelectContent", {
41
+ enumerable: true,
42
+ get: function get() {
43
+ return _HiNestedSelectContent.default;
44
+ }
45
+ });
46
+ Object.defineProperty(exports, "findFinalItemRecursively", {
47
+ enumerable: true,
48
+ get: function get() {
49
+ return _HiNestedSelectContent.findFinalItemRecursively;
50
+ }
51
+ });
52
+ Object.defineProperty(exports, "getRecursiveFinalItemIdList", {
53
+ enumerable: true,
54
+ get: function get() {
55
+ return _HiNestedSelectContent.getRecursiveFinalItemIdList;
56
+ }
57
+ });
32
58
 
33
59
  var _HiSelect = _interopRequireDefault(require("./HiSelect"));
34
60
 
@@ -36,4 +62,8 @@ var _HiNestedSelect = _interopRequireDefault(require("./HiNestedSelect"));
36
62
 
37
63
  var _HiSelectField = _interopRequireDefault(require("./HiSelectField"));
38
64
 
39
- var _HiSelectInput = _interopRequireDefault(require("./HiSelectInput"));
65
+ var _HiSelectInput = _interopRequireDefault(require("./HiSelectInput"));
66
+
67
+ var _HiSelectContent = _interopRequireDefault(require("./HiSelectContent"));
68
+
69
+ var _HiNestedSelectContent = _interopRequireWildcard(require("./HiNestedSelectContent"));
@@ -141,8 +141,7 @@ var styles = function styles(theme) {
141
141
  textOverflow: 'ellipsis',
142
142
  textAlign: 'right',
143
143
  margin: '4px 12px 4px 8px',
144
- alignSelf: 'center',
145
- width: '100%'
144
+ alignSelf: 'center'
146
145
  }),
147
146
  checkbox: {
148
147
  marginTop: 3
@@ -3,7 +3,6 @@ import PropTypes from 'prop-types';
3
3
  import withStyles from '../styles/withStyles';
4
4
  export const styles = () => ({
5
5
  rightEllipsisSpan: {
6
- display: 'inline-block',
7
6
  overflow: 'hidden',
8
7
  textOverflow: 'ellipsis',
9
8
  whiteSpace: 'pre',
@@ -160,12 +160,8 @@ class HiInput extends React.PureComponent {
160
160
  }
161
161
 
162
162
  handleChange(event) {
163
- const authorizedChar = '1234567890TOto<>';
164
-
165
163
  if (this.props.onChange) {
166
- if (authorizedChar.indexOf(event.target.value.charAt(event.target.value.length - 1)) >= 0 && this.props.onlyNumbers === true || this.props.onlyNumbers !== true) {
167
- this.props.onChange(event);
168
- }
164
+ this.props.onChange(event);
169
165
  }
170
166
  }
171
167