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

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.
@@ -112,9 +112,10 @@ function HiColoredLabel(props) {
112
112
  color,
113
113
  active,
114
114
  fontWeight,
115
+ style,
115
116
  theme
116
117
  } = props,
117
- other = _objectWithoutProperties(props, ["classes", "className", "label", "color", "active", "fontWeight", "theme"]);
118
+ other = _objectWithoutProperties(props, ["classes", "className", "label", "color", "active", "fontWeight", "style", "theme"]);
118
119
 
119
120
  const isHiColor = ['primary', 'secondary', 'positive', 'negative', 'middle', 'neutral'].includes(color);
120
121
  const isHexColor = !isHiColor && /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(color);
@@ -125,7 +126,7 @@ function HiColoredLabel(props) {
125
126
  [classes[`activeColor${capitalize(color)}`]]: active && isHiColor,
126
127
  [classes[`color${capitalize(color)}`]]: !active && isHiColor
127
128
  }, className),
128
- style: _objectSpread({}, isHexColor && {
129
+ style: _objectSpread({}, style, isHexColor && {
129
130
  backgroundColor: active ? color : fade(color, 0.08),
130
131
  color: active ? theme.palette.getContrastText(color) : color
131
132
  }, fontWeight && {
@@ -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
 
@@ -0,0 +1,347 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
+ import _objectSpread from "@babel/runtime/helpers/objectSpread";
4
+ // @inheritedComponent HiSelectContent
5
+ import React from 'react';
6
+ import PropTypes from 'prop-types';
7
+ import HiSelectContent from './HiSelectContent';
8
+ import { foldAccents } from '../utils/helpers';
9
+ /**
10
+ * Return array of final item id in nested list (via props children)
11
+ * @param itemList
12
+ * @param finalItemIdList
13
+ * @returns {*[]}
14
+ */
15
+
16
+ export function getRecursiveFinalItemIdList(itemList, finalItemIdList = []) {
17
+ return [...finalItemIdList, ...itemList.reduce((memo, item) => {
18
+ if (item.children) {
19
+ return getRecursiveFinalItemIdList(item.children, memo);
20
+ }
21
+
22
+ return [...memo, item.id];
23
+ }, [])];
24
+ }
25
+ /**
26
+ * Find item by id in nested list (via props children)
27
+ * @param itemList
28
+ * @param searchId
29
+ * @returns {boolean}
30
+ */
31
+
32
+ export function findFinalItemRecursively(itemList, searchId) {
33
+ let foundItem = false;
34
+ itemList.some(item => {
35
+ if (item.id === searchId) {
36
+ foundItem = item;
37
+ } else if (item.children && !foundItem) {
38
+ foundItem = findFinalItemRecursively(item.children, searchId);
39
+ }
40
+
41
+ return foundItem !== false;
42
+ });
43
+ return foundItem;
44
+ }
45
+ /**
46
+ * Build item list by settings item props relative to the nested parent/child situation
47
+ * Reduce the item list to build specified items (displayed, pinned, disabled, selected, indeterminate)
48
+ * Parent item is selected if each children item is include in selectedItemIdList (s stay to true)
49
+ * Parent item is indeterminate if it is not selected & not unselected (s goes false & u goes false)
50
+ *
51
+ * @param itemList - initial list of item
52
+ * @param selectedItemIdList - global list of selected id
53
+ * @param searchValue - search value on which filter item
54
+ * @param visibleParent - visibility of the list parent item (default false)
55
+ * @param pinnedParent - parent will be displayed as pinned items
56
+ * @param disabledParent - parent will not be selectable
57
+ * @param nbChildrenAsInfo - Show children number as info
58
+ * @param translations - Translations
59
+ * @returns {*}
60
+ */
61
+
62
+ function buildFilteredItemList(itemList, selectedItemIdList = [], searchValue = '', visibleParent = false, pinnedParent = false, disabledParent = false, nbChildrenAsInfo = false, translations) {
63
+ return itemList.reduce(({
64
+ l: memoItemList,
65
+ s: memoSelected,
66
+ u: memoUnselected,
67
+ v: memoVisible
68
+ }, item) => {
69
+ const itemVisible = searchValue === '' || foldAccents(item.label.toString().toLowerCase()).search(foldAccents(searchValue.toLowerCase())) !== -1; // Parent item
70
+
71
+ if (item.children) {
72
+ const {
73
+ l: customizedChildren,
74
+ s: selected,
75
+ u: unselected,
76
+ v: visible
77
+ } = buildFilteredItemList(item.children, selectedItemIdList, searchValue, itemVisible, pinnedParent, disabledParent);
78
+
79
+ if (nbChildrenAsInfo) {
80
+ item.info = translations.n_children.replace('%s', item.children.length);
81
+ }
82
+
83
+ return {
84
+ l: [...memoItemList, _objectSpread({}, item, disabledParent && {
85
+ disabled: true,
86
+ hideCheckbox: true // don't display checkbox on disabled parent
87
+
88
+ }, {
89
+ pinned: pinnedParent,
90
+ children: customizedChildren,
91
+ selected,
92
+ indeterminate: !selected && !unselected,
93
+ displayed: itemVisible || visible
94
+ })],
95
+ s: memoSelected && selected,
96
+ u: memoUnselected && unselected,
97
+ v: memoVisible || itemVisible || visible
98
+ };
99
+ }
100
+
101
+ const itemSelected = selectedItemIdList.includes(item.id);
102
+ return {
103
+ l: [...memoItemList, _objectSpread({
104
+ displayed: itemVisible || visibleParent
105
+ }, item)],
106
+ s: itemSelected && memoSelected,
107
+ u: !itemSelected && memoUnselected,
108
+ v: itemVisible || visibleParent || memoVisible
109
+ };
110
+ }, {
111
+ l: [],
112
+ s: true,
113
+ u: true,
114
+ v: visibleParent
115
+ });
116
+ }
117
+ /**
118
+ * HiNestedSelectContent hérite du composant HiSelectContent
119
+ *
120
+ * Sa fonction buildSelectProps construit la liste des options selon le comportement d'un object nested
121
+ * (association parent/child via la prop children). Le composant accepte des props spécifique à cet utilisation,
122
+ * comme disableParent ou pinnedParent. Uniquement les ids des enfants finaux (n'ayant pas d'enfants) sont considérés.
123
+ * Comportement:
124
+ * - si un parent est sélectionné, on ajoute tous ses enfants dans la liste des éléments sélectionné (mais pas le parent)
125
+ * - si tous les enfants sont sélectionnés, le parent est affiché "selected".
126
+ * - si une partie des enfants sont sélectionné, le parent est affiché "indeterminate".
127
+ * - si aucun enfant n'est sélectionné, le parent est affiché "unselected".
128
+ */
129
+
130
+
131
+ class HiNestedSelectContent extends React.PureComponent {
132
+ constructor(...args) {
133
+ super(...args);
134
+
135
+ this.handleSelect = (event, item) => {
136
+ const {
137
+ hasAll,
138
+ multiple,
139
+ onChange,
140
+ options,
141
+ value
142
+ } = this.props;
143
+
144
+ if (!multiple) {
145
+ // single value
146
+ onChange(event, item.id, item);
147
+ } else if (hasAll && item.id === '_all') {
148
+ // ALL
149
+ const selectableItemIdList = getRecursiveFinalItemIdList(options);
150
+
151
+ if (value.length === selectableItemIdList.length) {
152
+ // unselect _all options
153
+ onChange(event, [], item);
154
+ } else {
155
+ // select _all options
156
+ onChange(event, selectableItemIdList, item);
157
+ }
158
+ } else if (item.children) {
159
+ // PARENT
160
+ const parentSelectableItemIdList = getRecursiveFinalItemIdList(item.children); // deselect parent if every selectable child id is includes in value.
161
+
162
+ if (parentSelectableItemIdList.every(pid => value.includes(pid))) {
163
+ onChange(event, value.filter(vid => !parentSelectableItemIdList.includes(vid)), item);
164
+ } else {
165
+ // select parent > add each selectable child without duplicates.
166
+ onChange(event, [...value.filter(vid => !parentSelectableItemIdList.includes(vid)), ...parentSelectableItemIdList], item);
167
+ }
168
+ } else if (value.includes(item.id)) {
169
+ // unselect item
170
+ onChange(event, value.filter(id => id !== item.id), item);
171
+ } else {
172
+ onChange(event, [...value, item.id], item);
173
+ }
174
+ };
175
+
176
+ this.buildSelectProps = (options, value = [], search = '', loading = false) => {
177
+ const {
178
+ classes,
179
+ disabledParent,
180
+ hasAll,
181
+ iconAll,
182
+ multiple,
183
+ nbChildrenAsInfo,
184
+ pinnedParent,
185
+ translations
186
+ } = this.props; // build item list
187
+
188
+ const {
189
+ l: filteredItemList,
190
+ s: allSelected,
191
+ u: allUnselected,
192
+ v: visible
193
+ } = buildFilteredItemList(options, value, search, false, pinnedParent, disabledParent || !multiple, nbChildrenAsInfo, translations);
194
+ const itemList = !visible ? [...(loading ? [{
195
+ id: '_loading',
196
+ type: 'loader',
197
+ disabled: true,
198
+ centered: true,
199
+ hideCheckbox: true,
200
+ label: 'loading'
201
+ }] : [{
202
+ id: '_no_result',
203
+ type: 'text',
204
+ disabled: true,
205
+ centered: true,
206
+ hideCheckbox: true,
207
+ label: translations.no_result_match
208
+ }])] : [...(loading ? [{
209
+ id: '_loading',
210
+ type: 'loader',
211
+ disabled: true,
212
+ centered: true,
213
+ hideCheckbox: true,
214
+ label: 'loading'
215
+ }] : []), ...(hasAll ? [{
216
+ id: '_all',
217
+ iconAll,
218
+ label: translations.all,
219
+ selected: allSelected,
220
+ indeterminate: !allSelected && !allUnselected,
221
+ displayed: search === ''
222
+ }] : []), ...filteredItemList];
223
+ return {
224
+ itemList
225
+ };
226
+ };
227
+ }
228
+
229
+ render() {
230
+ const _this$props = this.props,
231
+ {
232
+ hasAll,
233
+ hiSelectableListProps,
234
+ multiple,
235
+ options,
236
+ searchable,
237
+ translations,
238
+ value
239
+ } = _this$props,
240
+ other = _objectWithoutProperties(_this$props, ["hasAll", "hiSelectableListProps", "multiple", "options", "searchable", "translations", "value"]);
241
+
242
+ if (multiple) {
243
+ if (!Array.isArray(value)) {
244
+ throw new Error('HiPay Material-UI: the `value` property must be an array ' + 'when using the `HiSelect` component with `multiple`.');
245
+ }
246
+ }
247
+
248
+ return React.createElement(HiSelectContent, _extends({
249
+ buildSelectProps: this.buildSelectProps,
250
+ hasAll: hasAll,
251
+ hiSelectableListProps: _objectSpread({
252
+ onSelect: this.handleSelect
253
+ }, hiSelectableListProps),
254
+ multiple: multiple,
255
+ options: options,
256
+ searchable: searchable,
257
+ translations: translations,
258
+ value: value
259
+ }, other));
260
+ }
261
+
262
+ }
263
+
264
+ HiNestedSelectContent.defaultProps = {
265
+ disabledParent: false,
266
+ hasAll: false,
267
+ multiple: false,
268
+ pinnedParent: false,
269
+ searchable: false,
270
+ translations: {
271
+ all: 'All',
272
+ no_result_match: 'No result match',
273
+ search: 'Search',
274
+ n_children: '%s',
275
+ one_child: '%s item'
276
+ }
277
+ };
278
+ HiNestedSelectContent.propTypes = process.env.NODE_ENV !== "production" ? {
279
+ /**
280
+ * Useful to extend the style applied to components.
281
+ */
282
+ classes: PropTypes.object,
283
+
284
+ /**
285
+ * Parent items are not selectable
286
+ */
287
+ disabledParent: PropTypes.bool,
288
+
289
+ /**
290
+ * Affiche l'élément 'All'
291
+ */
292
+ hasAll: PropTypes.bool,
293
+
294
+ /**
295
+ * id du select
296
+ */
297
+ id: PropTypes.string,
298
+
299
+ /**
300
+ * Ajoute un loader
301
+ */
302
+ loading: PropTypes.bool,
303
+
304
+ /**
305
+ * Autorise la sélection de plusieurs valeurs
306
+ */
307
+ multiple: PropTypes.bool,
308
+
309
+ /**
310
+ * Définit si l'on doit afficher le nombre d'enfants du parent dans son champ info
311
+ */
312
+ nbChildrenAsInfo: PropTypes.bool,
313
+
314
+ /**
315
+ * Fonction de callback qui renvoit la/les valeurs sélectionnées
316
+ *
317
+ * @param {object} event
318
+ * @param {string || array} value
319
+ */
320
+ onChange: PropTypes.func.isRequired,
321
+
322
+ /**
323
+ * Listes des options du select
324
+ */
325
+ options: PropTypes.array.isRequired,
326
+
327
+ /**
328
+ * Parent items are pinned, with sticky behavior (hide checkboxes but still selectable)
329
+ */
330
+ pinnedParent: PropTypes.bool,
331
+
332
+ /**
333
+ * Affiche un input de recherche permettant de filtrer les options
334
+ */
335
+ searchable: PropTypes.bool,
336
+
337
+ /**
338
+ * Traductions (par défaut en anglais)
339
+ */
340
+ translations: PropTypes.object,
341
+
342
+ /**
343
+ * Value(s) du select
344
+ */
345
+ value: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array])
346
+ } : {};
347
+ export default HiNestedSelectContent;