@hipay/hipay-material-ui 2.0.0-beta.59 → 2.0.0-beta.61
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 +118 -0
- package/HiCell/CellNumeric.js +1 -1
- package/HiDatePicker/HiDatePicker.js +48 -14
- package/HiDatePicker/HiDateRangePicker.js +119 -64
- package/HiDatePicker/HiDateRangeSelector.js +70 -47
- package/HiDatePicker/Overlays/YearPickerOverlay.js +8 -3
- package/HiDatePicker/stylesheet.js +32 -17
- package/HiForm/HiFormControl.js +26 -11
- package/HiForm/HiFormLabel.js +3 -1
- package/HiForm/HiInput.js +20 -1
- package/HiForm/HiUpload.js +290 -45
- package/HiForm/HiUploadField.js +19 -51
- package/HiForm/HiUploadInput.js +18 -7
- package/HiSelectNew/HiSelect.js +15 -16
- package/HiSelectableList/HiSelectableList.js +9 -0
- package/HiSelectableList/HiSelectableListItem.js +3 -7
- package/README.md +1 -1
- package/es/HiCell/CellNumeric.js +1 -1
- package/es/HiDatePicker/HiDatePicker.js +41 -12
- package/es/HiDatePicker/HiDateRangePicker.js +79 -28
- package/es/HiDatePicker/HiDateRangeSelector.js +59 -37
- package/es/HiDatePicker/Overlays/YearPickerOverlay.js +8 -3
- package/es/HiDatePicker/stylesheet.js +32 -17
- package/es/HiForm/HiFormControl.js +27 -11
- package/es/HiForm/HiFormLabel.js +3 -1
- package/es/HiForm/HiInput.js +19 -1
- package/es/HiForm/HiUpload.js +276 -35
- package/es/HiForm/HiUploadField.js +19 -43
- package/es/HiForm/HiUploadInput.js +16 -7
- package/es/HiSelectNew/HiSelect.js +15 -16
- package/es/HiSelectableList/HiSelectableList.js +9 -0
- package/es/HiSelectableList/HiSelectableListItem.js +3 -7
- package/es/styles/createPalette.js +1 -1
- package/es/utils/helpers.js +15 -6
- package/index.es.js +1 -1
- package/index.js +1 -1
- package/package.json +4 -4
- package/styles/createPalette.js +1 -1
- package/umd/hipay-material-ui.development.js +6301 -383
- package/umd/hipay-material-ui.production.min.js +2 -2
- package/utils/helpers.js +15 -5
|
@@ -172,23 +172,22 @@ export default (theme => ({
|
|
|
172
172
|
|
|
173
173
|
/* default modifiers */
|
|
174
174
|
// Added to the day's cell for the current day
|
|
175
|
-
today: {
|
|
176
|
-
//
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
'
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
175
|
+
today: {// color: theme.palette.primary.light,
|
|
176
|
+
// position: 'relative',
|
|
177
|
+
// borderRadius: '50%',
|
|
178
|
+
// color: `${theme.palette.neutral.dark} !important`,
|
|
179
|
+
// fontWeight: theme.typography.fontWeightMedium,
|
|
180
|
+
// '&:before': {
|
|
181
|
+
// content: '""',
|
|
182
|
+
// position: 'absolute',
|
|
183
|
+
// top: 0,
|
|
184
|
+
// left: 0,
|
|
185
|
+
// display: 'inline-block',
|
|
186
|
+
// width: '100%',
|
|
187
|
+
// height: '100%',
|
|
188
|
+
// borderRadius: '50%',
|
|
189
|
+
// boxShadow: `inset 0 0 0 2px ${theme.palette.neutral.main}`,
|
|
190
|
+
// },
|
|
192
191
|
},
|
|
193
192
|
// Added to the day's cell outside the current month
|
|
194
193
|
outside: {
|
|
@@ -216,5 +215,21 @@ export default (theme => ({
|
|
|
216
215
|
color: theme.palette.primary.contrastText,
|
|
217
216
|
borderRadius: '0%',
|
|
218
217
|
border: 'none'
|
|
218
|
+
},
|
|
219
|
+
currentDay: {
|
|
220
|
+
position: 'relative',
|
|
221
|
+
color: `${theme.palette.neutral.dark} !important`,
|
|
222
|
+
fontWeight: theme.typography.fontWeightMedium,
|
|
223
|
+
'&:before': {
|
|
224
|
+
content: '""',
|
|
225
|
+
position: 'absolute',
|
|
226
|
+
top: 0,
|
|
227
|
+
left: 0,
|
|
228
|
+
display: 'inline-block',
|
|
229
|
+
width: '100%',
|
|
230
|
+
height: '100%',
|
|
231
|
+
borderRadius: '50%',
|
|
232
|
+
boxShadow: `inset 0 0 0 2px ${theme.palette.neutral.main}`
|
|
233
|
+
}
|
|
219
234
|
}
|
|
220
235
|
}));
|
|
@@ -22,13 +22,11 @@ export const styles = theme => ({
|
|
|
22
22
|
marginTop: 2
|
|
23
23
|
},
|
|
24
24
|
iconButton: {
|
|
25
|
-
position: 'absolute',
|
|
26
|
-
right: 5,
|
|
27
25
|
cursor: 'pointer',
|
|
28
26
|
zIndex: 1,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
height: 20,
|
|
28
|
+
width: 20,
|
|
29
|
+
marginLeft: 3,
|
|
32
30
|
'&$iconButtonError': {
|
|
33
31
|
color: theme.palette.negative.main
|
|
34
32
|
},
|
|
@@ -37,11 +35,18 @@ export const styles = theme => ({
|
|
|
37
35
|
},
|
|
38
36
|
'&$iconButtonInfoActive': {
|
|
39
37
|
color: theme.palette.primary.main
|
|
38
|
+
},
|
|
39
|
+
'&$iconFullWidth': {
|
|
40
|
+
position: 'absolute',
|
|
41
|
+
right: 5,
|
|
42
|
+
marginLeft: 0,
|
|
43
|
+
bottom: 0
|
|
40
44
|
}
|
|
41
45
|
},
|
|
42
46
|
iconButtonError: {},
|
|
43
47
|
iconButtonInfo: {},
|
|
44
48
|
iconButtonInfoActive: {},
|
|
49
|
+
iconFullWidth: {},
|
|
45
50
|
errorDiv: _objectSpread({}, theme.typography.b3, {
|
|
46
51
|
backgroundColor: theme.palette.negative.main,
|
|
47
52
|
color: '#FFFFFF',
|
|
@@ -60,8 +65,15 @@ export const styles = theme => ({
|
|
|
60
65
|
borderTop: '4px solid #000',
|
|
61
66
|
position: 'absolute',
|
|
62
67
|
bottom: -4,
|
|
63
|
-
|
|
68
|
+
'&$arrowNotFullWidth': {
|
|
69
|
+
left: 8
|
|
70
|
+
},
|
|
71
|
+
'&$arrowFullWidth': {
|
|
72
|
+
right: 13
|
|
73
|
+
}
|
|
64
74
|
},
|
|
75
|
+
arrowNotFullWidth: {},
|
|
76
|
+
arrowFullWidth: {},
|
|
65
77
|
errorDivArrowDown: {
|
|
66
78
|
borderTopColor: theme.palette.negative.main
|
|
67
79
|
},
|
|
@@ -81,7 +93,8 @@ export const styles = theme => ({
|
|
|
81
93
|
borderTopColor: '#ffffff'
|
|
82
94
|
},
|
|
83
95
|
icon: {
|
|
84
|
-
position: 'absolute'
|
|
96
|
+
position: 'absolute',
|
|
97
|
+
fontSize: 19
|
|
85
98
|
}
|
|
86
99
|
});
|
|
87
100
|
/**
|
|
@@ -176,7 +189,7 @@ class HiFormControl extends React.PureComponent {
|
|
|
176
189
|
}, others), error && errorText && helperOpen && React.createElement("div", {
|
|
177
190
|
className: classes.errorDiv
|
|
178
191
|
}, React.createElement("div", {
|
|
179
|
-
className: classNames(classes.arrowDown, classes.errorDivArrowDown)
|
|
192
|
+
className: classNames(classes.arrowDown, classes.errorDivArrowDown, fullWidth ? [classes.arrowFullWidth] : [classes.arrowNotFullWidth])
|
|
180
193
|
}), React.createElement("span", {
|
|
181
194
|
// eslint-disable-next-line react/no-danger
|
|
182
195
|
dangerouslySetInnerHTML: {
|
|
@@ -185,7 +198,7 @@ class HiFormControl extends React.PureComponent {
|
|
|
185
198
|
})), helperIcon && helperText && !error && helperOpen && React.createElement("div", {
|
|
186
199
|
className: classes.helperDiv
|
|
187
200
|
}, React.createElement("div", {
|
|
188
|
-
className: classNames(classes.arrowDown, classes.helperDivArrowDown)
|
|
201
|
+
className: classNames(classes.arrowDown, classes.helperDivArrowDown, fullWidth ? [classes.arrowFullWidth] : [classes.arrowNotFullWidth])
|
|
189
202
|
}), React.createElement("span", {
|
|
190
203
|
// eslint-disable-next-line react/no-danger
|
|
191
204
|
dangerouslySetInnerHTML: {
|
|
@@ -198,13 +211,16 @@ class HiFormControl extends React.PureComponent {
|
|
|
198
211
|
disabled: disabled,
|
|
199
212
|
focused: !disabled && (focused || hovered)
|
|
200
213
|
}, InputLabelProps), error && errorText && React.createElement(HiIconButton, {
|
|
201
|
-
className: classNames(classes.iconButton, classes.iconButtonError
|
|
214
|
+
className: classNames(classes.iconButton, classes.iconButtonError, {
|
|
215
|
+
[classes.iconFullWidth]: fullWidth
|
|
216
|
+
}),
|
|
202
217
|
onClick: this.handleHelperClick
|
|
203
218
|
}, React.createElement(Warning, {
|
|
204
219
|
className: classNames(classes.icon)
|
|
205
220
|
})), helperIcon && helperText && !error && React.createElement(HiIconButton, {
|
|
206
221
|
className: classNames(classes.iconButton, classes.iconButtonInfo, {
|
|
207
|
-
[classes.iconButtonInfoActive]: helperOpen
|
|
222
|
+
[classes.iconButtonInfoActive]: helperOpen,
|
|
223
|
+
[classes.iconFullWidth]: fullWidth
|
|
208
224
|
}),
|
|
209
225
|
onClick: this.handleHelperClick
|
|
210
226
|
}, React.createElement(Info, {
|
package/es/HiForm/HiFormLabel.js
CHANGED
package/es/HiForm/HiInput.js
CHANGED
|
@@ -2,6 +2,7 @@ import _objectSpread from "@babel/runtime/helpers/objectSpread";
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
import classNames from 'classnames';
|
|
5
|
+
import keycode from 'keycode/index';
|
|
5
6
|
import Input from '@material-ui/core/Input';
|
|
6
7
|
import HiIcon from '../HiIcon';
|
|
7
8
|
import HiIconButton from '../HiIconButton';
|
|
@@ -128,6 +129,18 @@ class HiInput extends React.PureComponent {
|
|
|
128
129
|
constructor() {
|
|
129
130
|
super();
|
|
130
131
|
|
|
132
|
+
this.handleKeyDown = event => {
|
|
133
|
+
const key = keycode(event);
|
|
134
|
+
|
|
135
|
+
if (this.props.onKeyDown) {
|
|
136
|
+
this.props.onKeyDown(event);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (key === 'enter' && this.props.onSubmit) {
|
|
140
|
+
this.props.onSubmit(event);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
|
|
131
144
|
this.handleClick = () => {
|
|
132
145
|
if (this.props.onClick) {
|
|
133
146
|
this.props.onClick();
|
|
@@ -353,7 +366,7 @@ class HiInput extends React.PureComponent {
|
|
|
353
366
|
value: value,
|
|
354
367
|
placeholder: placeholder,
|
|
355
368
|
onFocus: this.handleFocus,
|
|
356
|
-
onKeyDown: this.
|
|
369
|
+
onKeyDown: this.handleKeyDown,
|
|
357
370
|
onClick: this.handleClick,
|
|
358
371
|
onBlur: this.handleBlur,
|
|
359
372
|
inputRef: this.getInputElement,
|
|
@@ -519,6 +532,11 @@ HiInput.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
|
519
532
|
*/
|
|
520
533
|
onRightIconClick: PropTypes.func,
|
|
521
534
|
|
|
535
|
+
/**
|
|
536
|
+
* Fonction de callback appelée lorsque l'utilisateur tape sur "Entrée"
|
|
537
|
+
*/
|
|
538
|
+
onSubmit: PropTypes.func,
|
|
539
|
+
|
|
522
540
|
/**
|
|
523
541
|
* Passe une ref callback au composant div parent
|
|
524
542
|
*/
|
package/es/HiForm/HiUpload.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
2
1
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
2
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import PropTypes from 'prop-types';
|
|
5
5
|
import classNames from 'classnames';
|
|
6
|
+
import keycode from 'keycode/index';
|
|
6
7
|
import withStyles from '../styles/withStyles';
|
|
7
8
|
import HiUploadInput from './HiUploadInput';
|
|
8
9
|
import HiIcon from '../HiIcon';
|
|
9
10
|
export const styles = theme => ({
|
|
10
11
|
flexContainer: {
|
|
11
|
-
display: '
|
|
12
|
+
display: 'flex',
|
|
12
13
|
alignItems: 'center'
|
|
13
14
|
},
|
|
14
15
|
statusIcon: {
|
|
@@ -22,8 +23,10 @@ export const styles = theme => ({
|
|
|
22
23
|
color: `${theme.palette.middle.main} !important`,
|
|
23
24
|
fontSize: '80px'
|
|
24
25
|
},
|
|
26
|
+
dragOver: {},
|
|
25
27
|
inputContainer: {
|
|
26
|
-
flex: '1'
|
|
28
|
+
flex: '1',
|
|
29
|
+
width: 'calc(100% - 88px)'
|
|
27
30
|
},
|
|
28
31
|
empty: {
|
|
29
32
|
border: `1px solid ${theme.palette.input.bottomLine}`,
|
|
@@ -37,39 +40,249 @@ export const styles = theme => ({
|
|
|
37
40
|
error: {
|
|
38
41
|
border: `1px solid ${theme.palette.negative.main}`,
|
|
39
42
|
color: `${theme.palette.negative.main} !important`
|
|
40
|
-
}
|
|
43
|
+
},
|
|
44
|
+
fileButton: {
|
|
45
|
+
marginRight: 8,
|
|
46
|
+
'&$focusable': {
|
|
47
|
+
cursor: 'pointer',
|
|
48
|
+
'&:hover, &:focus, &$dragOver': {
|
|
49
|
+
border: `1px solid ${theme.palette.primary.main}`,
|
|
50
|
+
color: `${theme.palette.primary.main} !important`
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
focusable: {}
|
|
41
55
|
});
|
|
42
56
|
|
|
43
57
|
class HiUpload extends React.PureComponent {
|
|
58
|
+
constructor() {
|
|
59
|
+
super();
|
|
60
|
+
|
|
61
|
+
this.handleDrop = event => {
|
|
62
|
+
if (event.path[0].id === this.uploadIconRef.props.id) {
|
|
63
|
+
event.preventDefault();
|
|
64
|
+
event.stopPropagation();
|
|
65
|
+
|
|
66
|
+
if (this.state.droppable) {
|
|
67
|
+
const index = this.getNextInputIndex();
|
|
68
|
+
const param = this.handleFile(event.dataTransfer.files, index);
|
|
69
|
+
this.setState({
|
|
70
|
+
dragOver: false
|
|
71
|
+
});
|
|
72
|
+
this.props.onChange(param, 0);
|
|
73
|
+
} else {
|
|
74
|
+
this.setState({
|
|
75
|
+
dragOver: false
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
this.handleDragEnter = event => {
|
|
82
|
+
event.preventDefault();
|
|
83
|
+
event.stopPropagation();
|
|
84
|
+
|
|
85
|
+
if (event.path[0].id === this.uploadIconRef.props.id) {
|
|
86
|
+
if (event.dataTransfer.items.length !== 1) {
|
|
87
|
+
event.dataTransfer.dropEffect = 'none';
|
|
88
|
+
this.props.onChange({
|
|
89
|
+
errorMessage: this.props.translations.errorDragEnter,
|
|
90
|
+
value: null
|
|
91
|
+
}, 0);
|
|
92
|
+
this.setState({
|
|
93
|
+
dragOver: true
|
|
94
|
+
});
|
|
95
|
+
} else {
|
|
96
|
+
this.setState({
|
|
97
|
+
droppable: true,
|
|
98
|
+
dragOver: true
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
this.handleDragLeave = event => {
|
|
105
|
+
event.preventDefault();
|
|
106
|
+
event.stopPropagation();
|
|
107
|
+
|
|
108
|
+
if (event.path[0].id === this.uploadIconRef.props.id && event.relatedTarget.parentElement !== this.uploadFieldRef) {
|
|
109
|
+
this.props.onChange({
|
|
110
|
+
errorMessage: '',
|
|
111
|
+
value: null
|
|
112
|
+
}, 0);
|
|
113
|
+
this.setState({
|
|
114
|
+
droppable: false,
|
|
115
|
+
dragOver: false
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
this.handleChange = event => {
|
|
121
|
+
const index = this.getNextInputIndex();
|
|
122
|
+
const param = this.handleFile(event.target.files, index);
|
|
123
|
+
this.props.onChange(param, index);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
this.handleEmptyField = event => {
|
|
127
|
+
event.target.value = '';
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
this.handleKeyPress = event => {
|
|
131
|
+
const key = keycode(event);
|
|
132
|
+
|
|
133
|
+
if (key === 'enter' || key === 'space') {
|
|
134
|
+
event.preventDefault();
|
|
135
|
+
this.uploadInput.click();
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
this.handleFile = (files, index) => {
|
|
140
|
+
let error = false;
|
|
141
|
+
let errorMessage = '';
|
|
142
|
+
let file = null;
|
|
143
|
+
|
|
144
|
+
if (files.length === 1) {
|
|
145
|
+
file = files[0];
|
|
146
|
+
|
|
147
|
+
if (this.props.inputs[index] && file.size > this.props.inputs[index].maxSize) {
|
|
148
|
+
errorMessage += this.props.translations.errorSize.replace('maxSize', this.props.inputs[index].maxSize / 1000000);
|
|
149
|
+
error = true;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (this.props.inputs[index] && this.props.inputs[index].acceptedTypes && this.props.inputs[index].acceptedTypes.length !== 0 && this.props.inputs[index].acceptedTypes.indexOf(file.type) === -1) {
|
|
153
|
+
errorMessage += this.props.translations.errorType;
|
|
154
|
+
error = true;
|
|
155
|
+
}
|
|
156
|
+
} else {
|
|
157
|
+
errorMessage = this.props.translations.errorDropMultiple;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return {
|
|
161
|
+
errorMessage,
|
|
162
|
+
error,
|
|
163
|
+
value: file
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
this.createInputs = others => {
|
|
168
|
+
const {
|
|
169
|
+
inputs,
|
|
170
|
+
values
|
|
171
|
+
} = this.props;
|
|
172
|
+
let files = inputs; // unlimited number of files
|
|
173
|
+
|
|
174
|
+
if (inputs.length === 0) {
|
|
175
|
+
files = values;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const inputComponents = [];
|
|
179
|
+
|
|
180
|
+
for (let i = 0; i < files.length; i += 1) {
|
|
181
|
+
if (files.length > 1 || values[i] && values[i].value) {
|
|
182
|
+
inputComponents.push(React.createElement(HiUploadInput, _extends({
|
|
183
|
+
maxSize: inputs[i] ? inputs[i].maxSize : undefined,
|
|
184
|
+
acceptedTypes: inputs[i] ? inputs[i].acceptedTypes : undefined,
|
|
185
|
+
placeholder: inputs[i] ? inputs[i].placeholder : undefined,
|
|
186
|
+
value: values[i] ? values[i].value : null,
|
|
187
|
+
error: values[i] ? values[i].error : null,
|
|
188
|
+
errorMessage: values[i] ? values[i].errorMessage : null,
|
|
189
|
+
onSeeFile: this.handleSeeFile,
|
|
190
|
+
onDeleteFile: this.props.onDeleteFile,
|
|
191
|
+
onChange: this.props.onChange,
|
|
192
|
+
index: i,
|
|
193
|
+
key: inputs[i] ? inputs[i].id : `doc-${i}`
|
|
194
|
+
}, others)));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return inputComponents;
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
this.uploadFieldRef = void 0;
|
|
202
|
+
this.state = {
|
|
203
|
+
dragOver: false,
|
|
204
|
+
droppable: false
|
|
205
|
+
};
|
|
206
|
+
} // When component mounts, we add eventListeners to handle the file drag and drop
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
componentDidMount() {
|
|
210
|
+
this.uploadFieldRef.addEventListener('dragenter', this.handleDragEnter, false);
|
|
211
|
+
this.uploadFieldRef.addEventListener('dragleave', this.handleDragLeave, false);
|
|
212
|
+
this.uploadFieldRef.addEventListener('dragover', event => {
|
|
213
|
+
event.preventDefault();
|
|
214
|
+
}, false);
|
|
215
|
+
this.uploadFieldRef.addEventListener('drop', this.handleDrop, false);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
componentWillUnmount() {
|
|
219
|
+
this.uploadFieldRef.removeEventListener('dragenter', this.handleDragEnter, false);
|
|
220
|
+
this.uploadFieldRef.removeEventListener('dragleave', this.handleDragLeave, false);
|
|
221
|
+
this.uploadFieldRef.removeEventListener('dragover', event => {
|
|
222
|
+
event.preventDefault();
|
|
223
|
+
}, false);
|
|
224
|
+
this.uploadFieldRef.removeEventListener('drop', this.handleDrop, false);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
getNextInputIndex() {
|
|
228
|
+
let index = 0; // Add an input at the end
|
|
229
|
+
|
|
230
|
+
if (!this.props.inputs.length) {
|
|
231
|
+
index = this.props.values.length + 1;
|
|
232
|
+
} else {
|
|
233
|
+
// First empty input
|
|
234
|
+
for (let i = 0; i < this.props.values.length; i += 1) {
|
|
235
|
+
if (!this.props.values[i] || this.props.values[i].error || !this.props.values[i].value) {
|
|
236
|
+
index = i;
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return index;
|
|
243
|
+
} // Action when files are dropped on the field
|
|
244
|
+
|
|
245
|
+
|
|
44
246
|
render() {
|
|
45
247
|
const _this$props = this.props,
|
|
46
248
|
{
|
|
249
|
+
id,
|
|
47
250
|
inputs,
|
|
48
251
|
classes,
|
|
49
|
-
values
|
|
252
|
+
values,
|
|
253
|
+
focused
|
|
50
254
|
} = _this$props,
|
|
51
|
-
others = _objectWithoutProperties(_this$props, ["inputs", "classes", "values"]);
|
|
255
|
+
others = _objectWithoutProperties(_this$props, ["id", "inputs", "classes", "values", "focused"]);
|
|
52
256
|
|
|
257
|
+
const {
|
|
258
|
+
dragOver,
|
|
259
|
+
droppable
|
|
260
|
+
} = this.state;
|
|
53
261
|
let complete = true;
|
|
54
262
|
let empty = true;
|
|
55
|
-
let error = false;
|
|
263
|
+
let error = false; // For unlimited inputs: always grey
|
|
56
264
|
|
|
57
|
-
|
|
58
|
-
|
|
265
|
+
if (!inputs.length) {
|
|
266
|
+
complete = false;
|
|
267
|
+
} else if (values.length === 0 || inputs.length > 0 && inputs.length !== values.length) {
|
|
268
|
+
complete = false;
|
|
269
|
+
} else {
|
|
270
|
+
for (let i = 0, len = values.length; i < len; i += 1) {
|
|
271
|
+
const value = values[i];
|
|
59
272
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
273
|
+
if (value !== undefined) {
|
|
274
|
+
complete = value.value === null || value.error ? false : complete;
|
|
275
|
+
empty = value.value !== null && !value.error ? false : empty;
|
|
276
|
+
error = value.error || error;
|
|
277
|
+
} else {
|
|
278
|
+
complete = false;
|
|
279
|
+
}
|
|
66
280
|
}
|
|
67
281
|
}
|
|
68
282
|
|
|
69
283
|
const statusClass = classNames(classes.statusIcon, {
|
|
70
284
|
[classes.empty]: empty,
|
|
71
|
-
[classes.complete]: complete
|
|
72
|
-
[classes.error]: error
|
|
285
|
+
[classes.complete]: complete
|
|
73
286
|
});
|
|
74
287
|
let icon;
|
|
75
288
|
|
|
@@ -81,27 +294,49 @@ class HiUpload extends React.PureComponent {
|
|
|
81
294
|
icon = 'file_upload';
|
|
82
295
|
}
|
|
83
296
|
|
|
297
|
+
let focusable = true;
|
|
298
|
+
|
|
299
|
+
if (complete && values.length > 1) {
|
|
300
|
+
focusable = false;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const iconClass = classNames(statusClass, classes.fileButton, {
|
|
304
|
+
[classes.dragOver]: dragOver,
|
|
305
|
+
[classes.droppable]: droppable,
|
|
306
|
+
[classes.focused]: focused,
|
|
307
|
+
[classes.error]: error && !focused,
|
|
308
|
+
[classes.focusable]: focusable
|
|
309
|
+
});
|
|
84
310
|
return React.createElement("div", {
|
|
85
311
|
className: classes.flexContainer
|
|
86
|
-
}, React.createElement(
|
|
87
|
-
|
|
312
|
+
}, React.createElement("label", {
|
|
313
|
+
htmlFor: "flat-button-file",
|
|
314
|
+
ref: label => {
|
|
315
|
+
this.uploadFieldRef = label;
|
|
316
|
+
},
|
|
317
|
+
tabIndex: "-1"
|
|
318
|
+
}, React.createElement("input", {
|
|
319
|
+
hidden: true,
|
|
320
|
+
id: "flat-button-file",
|
|
321
|
+
type: !complete || values.length === 1 ? 'file' : 'hidden',
|
|
322
|
+
onChange: this.handleChange,
|
|
323
|
+
onClick: focusable ? this.handleEmptyField : undefined,
|
|
324
|
+
ref: el => {
|
|
325
|
+
this.uploadInput = el;
|
|
326
|
+
}
|
|
327
|
+
}), React.createElement(HiIcon, {
|
|
328
|
+
ref: uploadIcon => {
|
|
329
|
+
this.uploadIconRef = uploadIcon;
|
|
330
|
+
},
|
|
331
|
+
id: `iconUpload-${id}`,
|
|
332
|
+
className: iconClass,
|
|
88
333
|
icon: icon,
|
|
89
|
-
size: 32
|
|
90
|
-
|
|
334
|
+
size: 32,
|
|
335
|
+
tabIndex: focusable ? '0' : '-1',
|
|
336
|
+
onKeyPress: this.handleKeyPress
|
|
337
|
+
})), React.createElement("div", {
|
|
91
338
|
className: classes.inputContainer
|
|
92
|
-
},
|
|
93
|
-
maxSize: item.maxSize,
|
|
94
|
-
acceptedTypes: item.acceptedTypes,
|
|
95
|
-
placeholder: item.placeholder,
|
|
96
|
-
value: values[index] ? values[index].value : null,
|
|
97
|
-
error: values[index] ? values[index].error : null,
|
|
98
|
-
errorMessage: values[index] ? values[index].errorMessage : null,
|
|
99
|
-
onSeeFile: this.handleSeeFile,
|
|
100
|
-
onDeleteFile: this.props.onDeleteFile,
|
|
101
|
-
onChange: this.props.onChange,
|
|
102
|
-
index: index,
|
|
103
|
-
key: item.id
|
|
104
|
-
}, others)))));
|
|
339
|
+
}, this.createInputs(others)));
|
|
105
340
|
}
|
|
106
341
|
|
|
107
342
|
}
|
|
@@ -127,8 +362,14 @@ HiUpload.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
|
127
362
|
*/
|
|
128
363
|
helperText: PropTypes.string,
|
|
129
364
|
|
|
365
|
+
/**
|
|
366
|
+
* id du composant
|
|
367
|
+
*/
|
|
368
|
+
id: PropTypes.string.isRequired,
|
|
369
|
+
|
|
130
370
|
/**
|
|
131
371
|
* Array containing each of the inputs the component has to show (represented by an object).
|
|
372
|
+
* If empty => unlimited number of files accepted
|
|
132
373
|
*/
|
|
133
374
|
inputs: PropTypes.array.isRequired,
|
|
134
375
|
|
|
@@ -148,7 +389,7 @@ HiUpload.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
|
148
389
|
onSeeFile: PropTypes.func,
|
|
149
390
|
|
|
150
391
|
/**
|
|
151
|
-
*
|
|
392
|
+
* True if can upload an unlimited number of files
|
|
152
393
|
*/
|
|
153
394
|
values: PropTypes.array
|
|
154
395
|
} : {};
|