@hipay/hipay-material-ui 2.0.0-beta.74 → 2.0.0-beta.76
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.
- package/CHANGELOG.md +153 -0
- package/HiAlertModal/HiAlertModal.js +1 -1
- package/HiChip/HiChip.js +17 -1
- package/HiDatePicker/HiDatePicker.js +130 -125
- package/HiDatePicker/HiDatePickerMobile.js +127 -0
- package/HiDatePicker/HiDateRangePicker.js +53 -11
- package/HiDatePicker/HiDateRangeSelector.js +3 -1
- package/HiDatePicker/stylesheet.js +16 -0
- package/HiNotice/HiKPI.js +14 -8
- package/HiPaymentMeans/HiPaymentMeans.js +2 -1
- package/HiSelect/HiSelect.js +115 -37
- package/HiSelect/HiSelectInput.js +6 -1
- package/HiSelect/HiSelectMobile.js +198 -0
- package/es/HiAlertModal/HiAlertModal.js +1 -1
- package/es/HiChip/HiChip.js +17 -1
- package/es/HiDatePicker/HiDatePicker.js +149 -133
- package/es/HiDatePicker/HiDatePickerMobile.js +89 -0
- package/es/HiDatePicker/HiDateRangePicker.js +47 -9
- package/es/HiDatePicker/HiDateRangeSelector.js +2 -1
- package/es/HiDatePicker/stylesheet.js +16 -0
- package/es/HiNotice/HiKPI.js +13 -8
- package/es/HiPaymentMeans/HiPaymentMeans.js +2 -1
- package/es/HiSelect/HiSelect.js +110 -39
- package/es/HiSelect/HiSelectInput.js +6 -1
- package/es/HiSelect/HiSelectMobile.js +149 -0
- package/es/styles/createPalette.js +1 -1
- package/index.es.js +1 -1
- package/index.js +1 -1
- package/package.json +2 -1
- package/styles/createPalette.js +1 -1
@@ -19,6 +19,8 @@ import Weekday from './Weekday';
|
|
19
19
|
import { HiTextField } from '../HiForm';
|
20
20
|
import styles from './stylesheet';
|
21
21
|
import HiFormControl from '../HiForm/HiFormControl';
|
22
|
+
import { isMobile } from 'react-device-detect';
|
23
|
+
import HiDatePickerMobile from './HiDatePickerMobile';
|
22
24
|
|
23
25
|
class HiDateRangePicker extends React.Component {
|
24
26
|
constructor(props) {
|
@@ -136,6 +138,16 @@ class HiDateRangePicker extends React.Component {
|
|
136
138
|
this.props.onChange(`${name}Error`, error);
|
137
139
|
};
|
138
140
|
|
141
|
+
this.handleChangeMobile = inputName => event => {
|
142
|
+
let date;
|
143
|
+
|
144
|
+
if (event.target.value) {
|
145
|
+
date = new Date(event.target.value);
|
146
|
+
}
|
147
|
+
|
148
|
+
this.props.onChange(inputName, date);
|
149
|
+
};
|
150
|
+
|
139
151
|
this.handleCurrentMonthChange = day => {
|
140
152
|
this.setState({
|
141
153
|
currentMonth: day,
|
@@ -441,16 +453,16 @@ class HiDateRangePicker extends React.Component {
|
|
441
453
|
});
|
442
454
|
|
443
455
|
const toClass = classNames(classes.toInput, {
|
444
|
-
[classes.absolute]: staticPosition === true && this.state.focusedInput === 'from',
|
445
|
-
[classes.right4]: staticPosition === true && this.state.focusedInput === 'from'
|
456
|
+
[classes.absolute]: !isMobile && staticPosition === true && this.state.focusedInput === 'from',
|
457
|
+
[classes.right4]: !isMobile && staticPosition === true && this.state.focusedInput === 'from'
|
446
458
|
});
|
447
459
|
let content = React.createElement("div", {
|
448
460
|
className: classNames(classes.root, classes.rangePickerContainer)
|
449
461
|
}, React.createElement("div", {
|
450
462
|
className: classes.fromInput,
|
451
|
-
onFocus: () => this.handleDayPickerFocus('from'),
|
452
|
-
onKeyDown: this.handleKeyDown('from')
|
453
|
-
}, React.createElement("div", null, React.createElement(DayPickerInput, {
|
463
|
+
onFocus: !isMobile ? () => this.handleDayPickerFocus('from') : undefined,
|
464
|
+
onKeyDown: !isMobile ? this.handleKeyDown('from') : undefined
|
465
|
+
}, React.createElement("div", null, !isMobile ? React.createElement(DayPickerInput, {
|
454
466
|
key: '1',
|
455
467
|
ref: el => {
|
456
468
|
this.fromInput = el;
|
@@ -466,12 +478,25 @@ class HiDateRangePicker extends React.Component {
|
|
466
478
|
parseDate: MomentLocaleUtils.parseDate,
|
467
479
|
onDayChange: day => this.handleDayChange('from', day),
|
468
480
|
placeholder: ''
|
481
|
+
}) : React.createElement(HiDatePickerMobile, {
|
482
|
+
id: this.props.id,
|
483
|
+
label: labelFrom,
|
484
|
+
range: true,
|
485
|
+
required: this.props.required,
|
486
|
+
enableTime: enableTime,
|
487
|
+
value: from,
|
488
|
+
onChange: this.handleChangeMobile('from'),
|
489
|
+
disablePastDays: this.props.disablePastDays,
|
490
|
+
disableFutureDays: disableFutureDays,
|
491
|
+
today: today,
|
492
|
+
minimumDate: minimumDate,
|
493
|
+
format: enableTime ? `${format} HH:mm` : format
|
469
494
|
}))), React.createElement("div", {
|
470
495
|
className: toClass,
|
471
|
-
onFocus: () => this.handleDayPickerFocus('to'),
|
472
|
-
onBlur: () => this.handleDayPickerBlur('to'),
|
473
|
-
onKeyDown: this.handleKeyDown('to')
|
474
|
-
}, React.createElement(DayPickerInput, {
|
496
|
+
onFocus: !isMobile ? () => this.handleDayPickerFocus('to') : undefined,
|
497
|
+
onBlur: !isMobile ? () => this.handleDayPickerBlur('to') : undefined,
|
498
|
+
onKeyDown: !isMobile ? this.handleKeyDown('to') : undefined
|
499
|
+
}, !isMobile ? React.createElement(DayPickerInput, {
|
475
500
|
key: '1',
|
476
501
|
ref: el => {
|
477
502
|
this.toInput = el;
|
@@ -486,6 +511,19 @@ class HiDateRangePicker extends React.Component {
|
|
486
511
|
formatDate: MomentLocaleUtils.formatDate,
|
487
512
|
parseDate: MomentLocaleUtils.parseDate,
|
488
513
|
placeholder: ''
|
514
|
+
}) : React.createElement(HiDatePickerMobile, {
|
515
|
+
id: this.props.id,
|
516
|
+
label: labelTo,
|
517
|
+
range: true,
|
518
|
+
required: this.props.required,
|
519
|
+
enableTime: enableTime,
|
520
|
+
value: to,
|
521
|
+
onChange: this.handleChangeMobile('to'),
|
522
|
+
disablePastDays: this.props.disablePastDays,
|
523
|
+
disableFutureDays: disableFutureDays,
|
524
|
+
today: today,
|
525
|
+
minimumDate: minimumDate,
|
526
|
+
format: enableTime ? `${format} HH:mm` : format
|
489
527
|
})));
|
490
528
|
|
491
529
|
if (!hasSelector) {
|
@@ -9,6 +9,7 @@ import withStyles from '../styles/withStyles';
|
|
9
9
|
import HiSelectField from '../HiSelect/HiSelectField';
|
10
10
|
import HiDateRangePicker from './HiDateRangePicker';
|
11
11
|
import HiFormControl from '../HiForm/HiFormControl';
|
12
|
+
import { isMobile } from 'react-device-detect';
|
12
13
|
export function findSeparator(format) {
|
13
14
|
let str = '';
|
14
15
|
|
@@ -311,7 +312,7 @@ class HiDateRangeSelector extends React.Component {
|
|
311
312
|
},
|
312
313
|
staticPosition: staticPosition,
|
313
314
|
onSubmit: this.props.onSubmit
|
314
|
-
}, selectProps))), React.createElement(Grid, {
|
315
|
+
}, selectProps))), (isMobile && selectedPreset === 'custom' || !isMobile) && React.createElement(Grid, {
|
315
316
|
item: true,
|
316
317
|
xs: 12,
|
317
318
|
sm: 8,
|
@@ -8,6 +8,22 @@ export default (theme => ({
|
|
8
8
|
minWidth: 252,
|
9
9
|
maxWidth: 500
|
10
10
|
},
|
11
|
+
rootMobile: _objectSpread({}, theme.typography.b1, {
|
12
|
+
backgroundColor: theme.palette.background2,
|
13
|
+
borderBottom: '1px solid #E0E0E0',
|
14
|
+
borderLeft: 'none',
|
15
|
+
borderRight: 'none',
|
16
|
+
borderTop: 'none',
|
17
|
+
height: 40,
|
18
|
+
paddingLeft: 8,
|
19
|
+
paddingTop: 10,
|
20
|
+
position: 'absolute',
|
21
|
+
marginTop: -40,
|
22
|
+
opacity: 0
|
23
|
+
}),
|
24
|
+
mobileRangeRoot: {
|
25
|
+
minWidth: '100%'
|
26
|
+
},
|
11
27
|
fromInput: {
|
12
28
|
position: 'relative',
|
13
29
|
display: 'inline-block',
|
package/es/HiNotice/HiKPI.js
CHANGED
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
|
|
3
3
|
import classNames from 'classnames';
|
4
4
|
import { withStyles } from '../styles';
|
5
5
|
import ButtonBase from '@material-ui/core/ButtonBase';
|
6
|
+
import Collapse from '@material-ui/core/Collapse';
|
6
7
|
export const styles = theme => ({
|
7
8
|
root: {
|
8
9
|
background: theme.palette.background3,
|
@@ -45,32 +46,32 @@ export const styles = theme => ({
|
|
45
46
|
boxShadow: 'none'
|
46
47
|
},
|
47
48
|
body: {
|
48
|
-
height: '100%',
|
49
49
|
margin: 0,
|
50
50
|
display: 'inline-grid',
|
51
51
|
alignItems: 'center',
|
52
52
|
fontSize: 20,
|
53
|
-
fontWeight: theme.typography.fontWeightLight
|
53
|
+
fontWeight: theme.typography.fontWeightLight,
|
54
|
+
flex: '1 1 auto'
|
54
55
|
},
|
55
56
|
title: {
|
56
|
-
height: '100%',
|
57
57
|
maxHeight: 16,
|
58
58
|
maxWidth: '100%',
|
59
59
|
margin: '7px 0px',
|
60
60
|
whiteSpace: 'nowrap',
|
61
61
|
overflow: 'hidden',
|
62
62
|
fontSize: 14,
|
63
|
-
fontWeight: theme.typography.fontWeightLight
|
63
|
+
fontWeight: theme.typography.fontWeightLight,
|
64
|
+
flex: '0 1 16px'
|
64
65
|
},
|
65
66
|
subtitle: {
|
66
|
-
height: '100%',
|
67
67
|
maxHeight: 28,
|
68
68
|
margin: '2px 0px',
|
69
69
|
maxWidth: '100%',
|
70
70
|
color: theme.palette.neutral.main,
|
71
71
|
fontSize: 11,
|
72
72
|
lineHeight: '13px',
|
73
|
-
fontWeight: theme.typography.fontWeightMedium
|
73
|
+
fontWeight: theme.typography.fontWeightMedium,
|
74
|
+
flex: '0 1 28px'
|
74
75
|
},
|
75
76
|
minify: {
|
76
77
|
height: 72
|
@@ -110,7 +111,11 @@ class HiKPI extends React.Component {
|
|
110
111
|
[classes.active]: active,
|
111
112
|
[classes.minify]: minify
|
112
113
|
});
|
113
|
-
return React.createElement(
|
114
|
+
return React.createElement(Collapse, {
|
115
|
+
in: !minify,
|
116
|
+
timeout: "auto",
|
117
|
+
collapsedHeight: "88px"
|
118
|
+
}, React.createElement(ButtonBase, {
|
114
119
|
className: rootclass,
|
115
120
|
onClick: !disable ? this.handleClick(id) : undefined,
|
116
121
|
title: tooltip
|
@@ -120,7 +125,7 @@ class HiKPI extends React.Component {
|
|
120
125
|
className: classes.body
|
121
126
|
}, minify && bodyMinify ? bodyMinify : body), subtitle && minify === false && React.createElement("div", {
|
122
127
|
className: classes.subtitle
|
123
|
-
}, subtitle));
|
128
|
+
}, subtitle)));
|
124
129
|
}
|
125
130
|
|
126
131
|
}
|
@@ -308,6 +308,7 @@ class HiPaymentMeans extends React.Component {
|
|
308
308
|
username = `${translations.gender_male} ${cardUser}`;
|
309
309
|
}
|
310
310
|
|
311
|
+
const creditDebit = translations.credit && translations.debit && (credit ? translations.credit : translations.debit).toUpperCase();
|
311
312
|
let cardLayout;
|
312
313
|
|
313
314
|
switch (type) {
|
@@ -427,7 +428,7 @@ class HiPaymentMeans extends React.Component {
|
|
427
428
|
className: classNames(classes.labelLarge, classes.userNameSepa)
|
428
429
|
}, username), React.createElement("div", {
|
429
430
|
className: classNames(classes.labelLarge, classes.labelDebitCredit)
|
430
|
-
},
|
431
|
+
}, creditDebit));
|
431
432
|
break;
|
432
433
|
|
433
434
|
case 'prepaid-card':
|
package/es/HiSelect/HiSelect.js
CHANGED
@@ -11,10 +11,14 @@ import HiSelectableList from '../HiSelectableList';
|
|
11
11
|
import HiInput from '../HiForm/HiInput';
|
12
12
|
import HiSelectInput from './HiSelectInput';
|
13
13
|
import withStyles from '../styles/withStyles';
|
14
|
-
import {
|
14
|
+
import { foldAccents } from '../utils/helpers';
|
15
15
|
import HiIcon from '../HiIcon';
|
16
16
|
import keycode from 'keycode';
|
17
17
|
import classNames from 'classnames';
|
18
|
+
import HiAlertModal from '../HiAlertModal';
|
19
|
+
import { isMobile } from 'react-device-detect';
|
20
|
+
import HiSelectMobile from './HiSelectMobile';
|
21
|
+
import { findDOMNode } from 'react-dom';
|
18
22
|
export const styles = theme => ({
|
19
23
|
root: {
|
20
24
|
backgroundColor: theme.palette.background2,
|
@@ -200,28 +204,46 @@ class HiSelect extends React.PureComponent {
|
|
200
204
|
this.handleClick = () => {
|
201
205
|
if (this.state.open) {
|
202
206
|
this.handleClose();
|
207
|
+
} else if (this.props.alert && !this.state.alertOpen) {
|
208
|
+
this.setState({
|
209
|
+
open: false,
|
210
|
+
alertOpen: true
|
211
|
+
});
|
203
212
|
} else {
|
204
213
|
this.setState({
|
205
|
-
open: true
|
214
|
+
open: true,
|
215
|
+
alertOpen: false
|
206
216
|
});
|
207
217
|
this.handleSuggestions(this.props.options);
|
208
218
|
if (this.props.onClick) this.props.onClick(); // Gestion du focus
|
209
219
|
|
210
|
-
|
211
|
-
|
220
|
+
setTimeout(() => {
|
221
|
+
if (!this.props.searchable) {
|
212
222
|
// Sinon focus sur l'élément sélectionné
|
213
223
|
this.focusOnSelectedItem(this.props.value);
|
214
|
-
}, 1);
|
215
|
-
} else {
|
216
|
-
if (this.searchField) {
|
217
|
-
setTimeout(() => {
|
218
|
-
this.searchField.focus();
|
219
|
-
}, 1);
|
220
224
|
}
|
221
|
-
}
|
225
|
+
}, 1);
|
222
226
|
}
|
223
227
|
};
|
224
228
|
|
229
|
+
this.handleSubmitAlert = () => {
|
230
|
+
this.handleClick();
|
231
|
+
};
|
232
|
+
|
233
|
+
this.handleCancelAlert = () => {
|
234
|
+
this.handleClose();
|
235
|
+
};
|
236
|
+
|
237
|
+
this.handleExitedAlert = () => {
|
238
|
+
if (this.searchField) {
|
239
|
+
this.searchField.focus();
|
240
|
+
}
|
241
|
+
};
|
242
|
+
|
243
|
+
this.handleCloseAlert = () => {
|
244
|
+
this.handleClose();
|
245
|
+
};
|
246
|
+
|
225
247
|
this.focusOnSelectedItem = selectedValue => {
|
226
248
|
if (this.overlay && this.overlay.getElementsByTagName('li')[0]) {
|
227
249
|
setTimeout(() => {
|
@@ -253,7 +275,8 @@ class HiSelect extends React.PureComponent {
|
|
253
275
|
this.handleClose = () => {
|
254
276
|
this.handleSearchReset();
|
255
277
|
this.setState({
|
256
|
-
open: false
|
278
|
+
open: false,
|
279
|
+
alertOpen: false
|
257
280
|
});
|
258
281
|
|
259
282
|
if (this.props.onClose) {
|
@@ -287,31 +310,22 @@ class HiSelect extends React.PureComponent {
|
|
287
310
|
this.handleKeyDown = event => {
|
288
311
|
const key = keycode(event);
|
289
312
|
|
290
|
-
if (
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
if (
|
295
|
-
if (this.
|
296
|
-
this.
|
297
|
-
|
298
|
-
|
299
|
-
} else if (key === 'space' && event.target !== this.searchField) {
|
300
|
-
event.preventDefault();
|
301
|
-
|
302
|
-
if (this.state.open) {
|
303
|
-
if (!this.props.multiple) {
|
304
|
-
this.setState({
|
305
|
-
open: false
|
306
|
-
});
|
313
|
+
if (!this.state.alertOpen) {
|
314
|
+
if (key === 'esc') {
|
315
|
+
event.preventDefault();
|
316
|
+
this.handleClose();
|
317
|
+
} else if (key === 'enter') {
|
318
|
+
if (this.state.open) {
|
319
|
+
if (this.props.multiple) {
|
320
|
+
this.handleClose();
|
321
|
+
}
|
307
322
|
}
|
308
|
-
} else {
|
309
|
-
|
310
|
-
|
311
|
-
|
323
|
+
} else if (key === 'space' && event.target !== this.searchField) {
|
324
|
+
event.preventDefault();
|
325
|
+
this.handleClick();
|
326
|
+
} else if (key === 'tab') {
|
327
|
+
this.handleClose();
|
312
328
|
}
|
313
|
-
} else if (key === 'tab') {
|
314
|
-
this.handleClose();
|
315
329
|
}
|
316
330
|
};
|
317
331
|
|
@@ -357,6 +371,9 @@ class HiSelect extends React.PureComponent {
|
|
357
371
|
// select _all options
|
358
372
|
onChange(event, options.map(option => option.id), item);
|
359
373
|
}
|
374
|
+
} else if (isMobile && multiple) {
|
375
|
+
// Array of selected values
|
376
|
+
onChange(event, item.map(option => option.id), item);
|
360
377
|
} else if (value.includes(item.id)) {
|
361
378
|
// unselect item
|
362
379
|
onChange(event, value.filter(id => id !== item.id), item);
|
@@ -419,11 +436,13 @@ class HiSelect extends React.PureComponent {
|
|
419
436
|
};
|
420
437
|
|
421
438
|
this.state = {
|
439
|
+
alertOpen: false,
|
422
440
|
open: false,
|
423
441
|
focused: false,
|
424
442
|
searchValue: props.searchValue ? undefined : '',
|
425
443
|
suggestions: props.options,
|
426
|
-
openDown: true
|
444
|
+
openDown: true,
|
445
|
+
overlayWidth: 0
|
427
446
|
};
|
428
447
|
this.handleBlur = this.handleBlur.bind(this);
|
429
448
|
this.handleClick = this.handleClick.bind(this);
|
@@ -441,6 +460,12 @@ class HiSelect extends React.PureComponent {
|
|
441
460
|
if (this.props.autoFocus) {
|
442
461
|
this.inputEl.focus();
|
443
462
|
}
|
463
|
+
|
464
|
+
if (this.overlay) {
|
465
|
+
this.setState({
|
466
|
+
overlayWidth: findDOMNode(this.overlay).clientWidth
|
467
|
+
});
|
468
|
+
}
|
444
469
|
}
|
445
470
|
|
446
471
|
static getDerivedStateFromProps(nextProps, prevState) {
|
@@ -478,6 +503,7 @@ class HiSelect extends React.PureComponent {
|
|
478
503
|
|
479
504
|
render() {
|
480
505
|
const {
|
506
|
+
alert,
|
481
507
|
classes,
|
482
508
|
disabled,
|
483
509
|
error,
|
@@ -503,6 +529,7 @@ class HiSelect extends React.PureComponent {
|
|
503
529
|
|
504
530
|
} = this.props;
|
505
531
|
const {
|
532
|
+
alertOpen,
|
506
533
|
open,
|
507
534
|
focused
|
508
535
|
} = this.state;
|
@@ -608,14 +635,24 @@ class HiSelect extends React.PureComponent {
|
|
608
635
|
}, hiSelectableListProps))), this.placement && this.placement.indexOf('top') >= 0 && !staticPosition && searchInput('top'))));
|
609
636
|
};
|
610
637
|
|
611
|
-
return React.createElement("div", {
|
638
|
+
return !isMobile ? React.createElement("div", {
|
612
639
|
className: classes.root,
|
613
640
|
ref: el => {
|
614
641
|
this.overlay = el;
|
615
642
|
},
|
616
643
|
onKeyDown: this.handleKeyDown,
|
617
644
|
onKeyDownCapture: this.handleKeyDownCapture
|
618
|
-
}, React.createElement(
|
645
|
+
}, alert && React.createElement(HiAlertModal, {
|
646
|
+
open: alertOpen,
|
647
|
+
title: alert.title,
|
648
|
+
content: alert.content,
|
649
|
+
onSubmitClick: this.handleSubmitAlert,
|
650
|
+
onCancelClick: this.handleCancelAlert,
|
651
|
+
onClose: this.handleCloseAlert,
|
652
|
+
onExited: this.handleExitedAlert,
|
653
|
+
labelSubmitButton: alert.submitButton,
|
654
|
+
labelCancelButton: alert.cancelButton
|
655
|
+
}), React.createElement(HiSelectInput, _extends({
|
619
656
|
id: id,
|
620
657
|
value: inputValue,
|
621
658
|
open: open,
|
@@ -646,7 +683,37 @@ class HiSelect extends React.PureComponent {
|
|
646
683
|
className: popperClass,
|
647
684
|
disablePortal: true,
|
648
685
|
style: popperStyle
|
649
|
-
}, content))
|
686
|
+
}, content)) : React.createElement("div", {
|
687
|
+
ref: el => {
|
688
|
+
this.overlay = el;
|
689
|
+
}
|
690
|
+
}, React.createElement(HiSelectInput, _extends({
|
691
|
+
id: id,
|
692
|
+
value: inputValue,
|
693
|
+
open: open,
|
694
|
+
focused: focused,
|
695
|
+
type: type,
|
696
|
+
disabled: disabled,
|
697
|
+
noButton: displayAsChip,
|
698
|
+
error: error,
|
699
|
+
onFocus: this.handleFocus,
|
700
|
+
onBlur: this.handleBlur,
|
701
|
+
onMouseEnter: this.props.onMouseEnter,
|
702
|
+
onMouseLeave: this.props.onMouseLeave,
|
703
|
+
onReset: this.props.onReset,
|
704
|
+
placeholder: placeholder
|
705
|
+
}, hiSelectInputProps, {
|
706
|
+
refElement: el => {
|
707
|
+
this.inputEl = el;
|
708
|
+
}
|
709
|
+
})), React.createElement(HiSelectMobile, {
|
710
|
+
onChange: this.handleSelect,
|
711
|
+
multiple: multiple,
|
712
|
+
id: id,
|
713
|
+
itemList: itemList,
|
714
|
+
value: value,
|
715
|
+
width: this.state.overlayWidth
|
716
|
+
}));
|
650
717
|
}
|
651
718
|
|
652
719
|
}
|
@@ -678,6 +745,10 @@ HiSelect.defaultProps = {
|
|
678
745
|
filterFunc: filterValue
|
679
746
|
};
|
680
747
|
HiSelect.propTypes = process.env.NODE_ENV !== "production" ? {
|
748
|
+
/**
|
749
|
+
* Affiche une alerte à l'ouverture de la liste
|
750
|
+
*/
|
751
|
+
alert: PropTypes.object,
|
681
752
|
align: PropTypes.oneOf(['left', 'right']),
|
682
753
|
|
683
754
|
/**
|
@@ -8,6 +8,7 @@ import Icon from '@material-ui/core/Icon';
|
|
8
8
|
import HiIcon from '../HiIcon';
|
9
9
|
import withStyles from '../styles/withStyles';
|
10
10
|
import keycode from 'keycode';
|
11
|
+
import { isMobile } from 'react-device-detect';
|
11
12
|
export const styles = theme => ({
|
12
13
|
root: {
|
13
14
|
width: '100%',
|
@@ -18,6 +19,9 @@ export const styles = theme => ({
|
|
18
19
|
padding: 8,
|
19
20
|
cursor: 'pointer'
|
20
21
|
},
|
22
|
+
rootMobile: {
|
23
|
+
backgroundColor: theme.palette.background2
|
24
|
+
},
|
21
25
|
underline: {
|
22
26
|
'&:before': {
|
23
27
|
backgroundColor: theme.palette.input.bottomLine,
|
@@ -207,7 +211,8 @@ class HiSelectInput extends React.PureComponent {
|
|
207
211
|
const rootClass = classNames(classes.root, classes.inkbar, classes.underline, {
|
208
212
|
[classes.disabled]: disabled,
|
209
213
|
[classes.focused]: focused,
|
210
|
-
[classes.error]: error && !focused
|
214
|
+
[classes.error]: error && !focused,
|
215
|
+
[classes.rootMobile]: isMobile
|
211
216
|
});
|
212
217
|
const iconClass = classNames(classes.icon, {
|
213
218
|
[classes.iconOpen]: open,
|
@@ -0,0 +1,149 @@
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
2
|
+
import _objectSpread from "@babel/runtime/helpers/objectSpread";
|
3
|
+
import React from 'react';
|
4
|
+
import PropTypes from 'prop-types';
|
5
|
+
import withStyles from '../styles/withStyles';
|
6
|
+
export const styles = theme => ({
|
7
|
+
root: {
|
8
|
+
position: 'absolute',
|
9
|
+
opacity: '0',
|
10
|
+
marginTop: -40,
|
11
|
+
height: 40
|
12
|
+
}
|
13
|
+
});
|
14
|
+
|
15
|
+
class HiSelectMobile extends React.Component {
|
16
|
+
constructor(...args) {
|
17
|
+
super(...args);
|
18
|
+
|
19
|
+
this.buildOptionList = itemList => {
|
20
|
+
let optionList = [];
|
21
|
+
|
22
|
+
if (itemList.length) {
|
23
|
+
let parentId;
|
24
|
+
let groupList = [];
|
25
|
+
itemList.forEach(item => {
|
26
|
+
if (item.id !== '_all' && item.displayed !== false) {
|
27
|
+
if (item.hasChildren) {
|
28
|
+
if (groupList.length) {
|
29
|
+
optionList.push(this.buildChildrenList(groupList));
|
30
|
+
groupList = [];
|
31
|
+
}
|
32
|
+
|
33
|
+
parentId = item.id;
|
34
|
+
groupList.push(item);
|
35
|
+
} else if (parentId) {
|
36
|
+
groupList.push(item);
|
37
|
+
} else if (item.children) {
|
38
|
+
optionList.push(this.buildChildrenList([item, ...item.children]));
|
39
|
+
} else {
|
40
|
+
optionList.push(React.createElement("option", {
|
41
|
+
key: item.id,
|
42
|
+
"data-item": JSON.stringify(item),
|
43
|
+
value: item.id
|
44
|
+
}, item.label));
|
45
|
+
}
|
46
|
+
}
|
47
|
+
});
|
48
|
+
|
49
|
+
if (groupList.length) {
|
50
|
+
optionList.push(this.buildChildrenList(groupList));
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
return optionList;
|
55
|
+
};
|
56
|
+
|
57
|
+
this.buildChildrenList = itemList => {
|
58
|
+
const group = itemList.shift();
|
59
|
+
return React.createElement("optgroup", {
|
60
|
+
key: group.id,
|
61
|
+
label: group.label
|
62
|
+
}, itemList.map(item => {
|
63
|
+
return React.createElement("option", {
|
64
|
+
key: item.id,
|
65
|
+
"data-item": JSON.stringify(item),
|
66
|
+
value: item.id
|
67
|
+
}, item.label);
|
68
|
+
}));
|
69
|
+
};
|
70
|
+
|
71
|
+
this.handleChange = event => {
|
72
|
+
if (!this.props.multiple) {
|
73
|
+
const itemSelected = event.target[event.target.selectedIndex];
|
74
|
+
this.props.onChange(event, JSON.parse(itemSelected.getAttribute('data-item')));
|
75
|
+
} else {
|
76
|
+
// Multiple on mobile trigger on change with all selected items
|
77
|
+
let optionsSelected = [];
|
78
|
+
Array.prototype.forEach.call(event.target.options, option => {
|
79
|
+
if (option.selected) {
|
80
|
+
optionsSelected.push(JSON.parse(option.getAttribute('data-item')));
|
81
|
+
}
|
82
|
+
});
|
83
|
+
this.props.onChange(event, optionsSelected);
|
84
|
+
}
|
85
|
+
};
|
86
|
+
}
|
87
|
+
|
88
|
+
render() {
|
89
|
+
const {
|
90
|
+
classes,
|
91
|
+
id,
|
92
|
+
itemList,
|
93
|
+
multiple,
|
94
|
+
value
|
95
|
+
} = this.props;
|
96
|
+
|
97
|
+
const additionalProps = _objectSpread({}, multiple && {
|
98
|
+
multiple: 'multiple'
|
99
|
+
});
|
100
|
+
|
101
|
+
return React.createElement("select", _extends({
|
102
|
+
value: value,
|
103
|
+
style: {
|
104
|
+
width: this.props.width
|
105
|
+
},
|
106
|
+
onChange: this.handleChange,
|
107
|
+
className: classes.root,
|
108
|
+
name: id,
|
109
|
+
id: id
|
110
|
+
}, additionalProps), this.buildOptionList(itemList));
|
111
|
+
}
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
HiSelectMobile.defaultProps = {
|
116
|
+
itemList: []
|
117
|
+
};
|
118
|
+
HiSelectMobile.propTypes = process.env.NODE_ENV !== "production" ? {
|
119
|
+
/**
|
120
|
+
* Identifiant du select
|
121
|
+
*/
|
122
|
+
id: PropTypes.string,
|
123
|
+
|
124
|
+
/**
|
125
|
+
* Liste des options du select
|
126
|
+
*/
|
127
|
+
itemList: PropTypes.array.isRequired,
|
128
|
+
|
129
|
+
/**
|
130
|
+
* True s'il est possible de sélectionner plusieurs options
|
131
|
+
*/
|
132
|
+
multiple: PropTypes.bool,
|
133
|
+
|
134
|
+
/**
|
135
|
+
* Fonction appelée lors de la sélection/désélection
|
136
|
+
*/
|
137
|
+
onChange: PropTypes.func.isRequired,
|
138
|
+
|
139
|
+
/**
|
140
|
+
* Valeur(s) sélectionnée(s)
|
141
|
+
*/
|
142
|
+
value: PropTypes.any,
|
143
|
+
|
144
|
+
/**
|
145
|
+
* Largeur du select
|
146
|
+
*/
|
147
|
+
width: PropTypes.number
|
148
|
+
} : {};
|
149
|
+
export default withStyles(styles)(HiSelectMobile);
|
@@ -47,7 +47,7 @@ export const light = {
|
|
47
47
|
// The color of a selected action.
|
48
48
|
selected: '#F8F9FB',
|
49
49
|
// The color of a disabled action.
|
50
|
-
disabled: '
|
50
|
+
disabled: 'rgba(0, 0, 0, 0.24)',
|
51
51
|
// The background color of a disabled action.
|
52
52
|
disabledBackground: 'rgba(0, 0, 0, 0.12)'
|
53
53
|
},
|
package/index.es.js
CHANGED
package/index.js
CHANGED