@hipay/hipay-material-ui 2.0.0-beta.59 → 2.0.0-beta.61
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -112,6 +112,10 @@ function (_React$PureComponent) {
|
|
112
112
|
};
|
113
113
|
|
114
114
|
_this.compareItem = function (a, b) {
|
115
|
+
if (_this.props.comparItemFunc) {
|
116
|
+
return _this.props.comparItemFunc(a, b);
|
117
|
+
}
|
118
|
+
|
115
119
|
if (a.label === undefined || b.label === undefined) {
|
116
120
|
return 0;
|
117
121
|
}
|
@@ -184,6 +188,11 @@ HiSelectableList.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
184
188
|
*/
|
185
189
|
classes: _propTypes.default.object,
|
186
190
|
|
191
|
+
/**
|
192
|
+
* Fonction de comparaison utilisée pour les tris
|
193
|
+
*/
|
194
|
+
comparItemFunc: _propTypes.default.func,
|
195
|
+
|
187
196
|
/**
|
188
197
|
* Désactive la listes
|
189
198
|
*/
|
@@ -71,7 +71,7 @@ var styles = function styles(theme) {
|
|
71
71
|
display: 'block'
|
72
72
|
},
|
73
73
|
'&$inline': {
|
74
|
-
|
74
|
+
minHeight: 40,
|
75
75
|
'& $secondaryLabel': {
|
76
76
|
display: 'inline-block'
|
77
77
|
}
|
@@ -128,7 +128,7 @@ var styles = function styles(theme) {
|
|
128
128
|
'& strong': {
|
129
129
|
fontWeight: theme.typography.fontWeightMedium
|
130
130
|
},
|
131
|
-
display: '
|
131
|
+
display: 'contents'
|
132
132
|
}),
|
133
133
|
listItemContentSelected: {},
|
134
134
|
label: {
|
@@ -158,7 +158,6 @@ var styles = function styles(theme) {
|
|
158
158
|
fontSize: 12,
|
159
159
|
textOverflow: 'ellipsis',
|
160
160
|
textAlign: 'right',
|
161
|
-
padding: '4px 0px 4px 8px',
|
162
161
|
alignSelf: 'center'
|
163
162
|
}),
|
164
163
|
img: {
|
@@ -172,7 +171,7 @@ var styles = function styles(theme) {
|
|
172
171
|
verticalAlign: 'middle'
|
173
172
|
},
|
174
173
|
labelContent: {
|
175
|
-
display: 'flex',
|
174
|
+
display: '-webkit-flex',
|
176
175
|
alignItems: 'center',
|
177
176
|
maxWidth: '85%',
|
178
177
|
'&$labelWithoutSecondaryInline': {
|
@@ -190,9 +189,6 @@ var styles = function styles(theme) {
|
|
190
189
|
},
|
191
190
|
'&$infosWithoutSecondaryInline': {
|
192
191
|
paddingLeft: 28
|
193
|
-
},
|
194
|
-
'&$infosWithSecondaryInline': {
|
195
|
-
marginTop: -8
|
196
192
|
}
|
197
193
|
},
|
198
194
|
infosInlineWithoutSecondary: {},
|
package/README.md
CHANGED
@@ -226,7 +226,7 @@ npm install -g conventional-changelog-cli
|
|
226
226
|
npm install -g cz-conventional-changelog
|
227
227
|
```
|
228
228
|
|
229
|
-
1. Changer la version dans packages/hipay-material-ui/package.json
|
229
|
+
1. Changer la version dans package.json et dans packages/hipay-material-ui/package.json
|
230
230
|
2. Générer le fichier HI-CHANGELOG.md : ```npm run changelog```
|
231
231
|
3. Commiter la release : ```git ci -am "chore(release): VERSION DATE```
|
232
232
|
4. Build : ```npm run build```
|
package/es/HiCell/CellNumeric.js
CHANGED
@@ -25,7 +25,7 @@ class CellNumeric extends React.PureComponent {
|
|
25
25
|
let title = '';
|
26
26
|
|
27
27
|
if (currency) {
|
28
|
-
displayedValue = formatCurrencyAmount(value, view, locale, currency);
|
28
|
+
displayedValue = formatCurrencyAmount(value, view, locale, currency, precision);
|
29
29
|
title = formatCurrencyAmount(value, 'l', locale, currency);
|
30
30
|
} else {
|
31
31
|
displayedValue = formatNumber(value, view, locale, precision);
|
@@ -3,6 +3,7 @@ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProper
|
|
3
3
|
import _extends from "@babel/runtime/helpers/extends";
|
4
4
|
import React from 'react';
|
5
5
|
import PropTypes from 'prop-types';
|
6
|
+
import moment from 'moment-timezone';
|
6
7
|
import MomentLocaleUtils from 'react-day-picker/moment';
|
7
8
|
import HiLocaleUtils from './hiLocaleUtils';
|
8
9
|
import DayPickerInput from 'react-day-picker/DayPickerInput';
|
@@ -20,9 +21,18 @@ import styles from './stylesheet';
|
|
20
21
|
class HiDatePicker extends React.Component {
|
21
22
|
constructor(props) {
|
22
23
|
super();
|
24
|
+
|
25
|
+
this.handleKeyDown = name => event => {
|
26
|
+
if (event.key === 'Escape' && !event.shiftKey) {
|
27
|
+
this.datePickerInput.hideDayPicker();
|
28
|
+
event.stopPropagation();
|
29
|
+
}
|
30
|
+
};
|
31
|
+
|
32
|
+
const today = moment().tz(props.timezoneName);
|
23
33
|
this.state = {
|
24
34
|
openedPanel: 'calendar',
|
25
|
-
currentMonth: props.value ? props.value : new Date()
|
35
|
+
currentMonth: props.value ? props.value : new Date(today.year(), today.month(), today.date(), today.hours(), today.minutes(), today.seconds(), today.milliseconds())
|
26
36
|
}; // this.formatDate = this.formatDate.bind(this);
|
27
37
|
|
28
38
|
this.handleCalendarClick = this.handleCalendarClick.bind(this);
|
@@ -46,15 +56,16 @@ class HiDatePicker extends React.Component {
|
|
46
56
|
clearTimeout(this.timeout);
|
47
57
|
}
|
48
58
|
|
49
|
-
handleReset() {
|
50
|
-
this.handleCurrentMonthChange(new Date());
|
51
|
-
this.props.onReset();
|
52
|
-
}
|
53
|
-
|
54
59
|
handleInputChange(event) {
|
55
60
|
this.props.onChange(event.target.value);
|
56
61
|
}
|
57
62
|
|
63
|
+
handleReset() {
|
64
|
+
const today = moment().tz(this.props.timezoneName);
|
65
|
+
this.handleCurrentMonthChange(new Date(today.year(), today.month(), today.date(), today.hours(), today.minutes(), today.seconds(), today.milliseconds()));
|
66
|
+
this.props.onReset();
|
67
|
+
}
|
68
|
+
|
58
69
|
handleDayChange(day, modifiers) {
|
59
70
|
if (day) {
|
60
71
|
if (modifiers.selected) {
|
@@ -169,7 +180,8 @@ class HiDatePicker extends React.Component {
|
|
169
180
|
renderYearPickerOverlay(propsOverlay) {
|
170
181
|
const yearPickerProps = {
|
171
182
|
value: this.state.currentMonth,
|
172
|
-
onChange: this.handleCurrentMonthChange
|
183
|
+
onChange: this.handleCurrentMonthChange,
|
184
|
+
disableFutureDays: this.props.disableFutureDays
|
173
185
|
};
|
174
186
|
return React.createElement(YearPickerOverlay, _extends({
|
175
187
|
key: 'year-picker-overlay'
|
@@ -197,11 +209,12 @@ class HiDatePicker extends React.Component {
|
|
197
209
|
const {
|
198
210
|
currentMonth
|
199
211
|
} = this.state;
|
212
|
+
const today = moment().tz(this.props.timezoneName);
|
200
213
|
|
201
214
|
const effectiveDisabledDays = _objectSpread({}, disablePastDays && {
|
202
|
-
before: new Date()
|
215
|
+
before: new Date(today.year(), today.month(), today.date(), today.hours(), today.minutes(), today.seconds(), today.milliseconds())
|
203
216
|
}, disableFutureDays && {
|
204
|
-
after: new Date()
|
217
|
+
after: new Date(today.year(), today.month(), today.date(), today.hours(), today.minutes(), today.seconds(), today.milliseconds())
|
205
218
|
}, disabledDays);
|
206
219
|
|
207
220
|
const modifiersStyles = {
|
@@ -228,7 +241,8 @@ class HiDatePicker extends React.Component {
|
|
228
241
|
fromMonth: minimumDate,
|
229
242
|
modifiers: {
|
230
243
|
disabled: effectiveDisabledDays,
|
231
|
-
selected: value
|
244
|
+
selected: value,
|
245
|
+
[classes.currentDay]: new Date(today.year(), today.month(), today.date(), today.hours(), today.minutes(), today.seconds(), today.milliseconds())
|
232
246
|
},
|
233
247
|
modifiersStyles,
|
234
248
|
month: currentMonth
|
@@ -240,11 +254,15 @@ class HiDatePicker extends React.Component {
|
|
240
254
|
const inputProps = _objectSpread({}, onReset && {
|
241
255
|
onReset: this.handleReset
|
242
256
|
}, props, {
|
243
|
-
onChange: this.handleInputChange
|
257
|
+
onChange: this.handleInputChange,
|
258
|
+
HiInputProps: {
|
259
|
+
onSubmit: this.props.onSubmit
|
260
|
+
}
|
244
261
|
});
|
245
262
|
|
246
263
|
return React.createElement("div", {
|
247
|
-
className: classes.root
|
264
|
+
className: classes.root,
|
265
|
+
onKeyDown: this.handleKeyDown()
|
248
266
|
}, React.createElement(DayPickerInput, {
|
249
267
|
ref: el => {
|
250
268
|
this.datePickerInput = el;
|
@@ -275,6 +293,7 @@ HiDatePicker.defaultProps = {
|
|
275
293
|
locale: 'fr-FR',
|
276
294
|
minimumDate: new Date(2013, 4, 1),
|
277
295
|
// by default 1 May 2013
|
296
|
+
timezoneName: 'Europe/Paris',
|
278
297
|
translations: {
|
279
298
|
today: 'today'
|
280
299
|
}
|
@@ -338,6 +357,16 @@ HiDatePicker.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
338
357
|
*/
|
339
358
|
onReset: PropTypes.func,
|
340
359
|
|
360
|
+
/**
|
361
|
+
* Callback lorsque l'utilisateur tape sur "Entrée"
|
362
|
+
*/
|
363
|
+
onSubmit: PropTypes.func,
|
364
|
+
|
365
|
+
/**
|
366
|
+
* Timezone de l'utilisateur
|
367
|
+
*/
|
368
|
+
timezoneName: PropTypes.string,
|
369
|
+
|
341
370
|
/**
|
342
371
|
* Traductions
|
343
372
|
*/
|
@@ -3,6 +3,7 @@ import _objectSpread from "@babel/runtime/helpers/objectSpread";
|
|
3
3
|
import _extends from "@babel/runtime/helpers/extends";
|
4
4
|
import React from 'react';
|
5
5
|
import PropTypes from 'prop-types';
|
6
|
+
import moment from 'moment-timezone';
|
6
7
|
import MomentLocaleUtils from 'react-day-picker/moment';
|
7
8
|
import HiLocaleUtils from './hiLocaleUtils';
|
8
9
|
import DayPickerInput from 'react-day-picker/DayPickerInput';
|
@@ -17,7 +18,6 @@ import NavBar from './NavBar';
|
|
17
18
|
import Weekday from './Weekday';
|
18
19
|
import { HiTextField } from '../HiForm';
|
19
20
|
import styles from './stylesheet';
|
20
|
-
import moment from 'moment';
|
21
21
|
import HiFormControl from '../HiForm/HiFormControl';
|
22
22
|
|
23
23
|
class HiDateRangePicker extends React.Component {
|
@@ -58,8 +58,10 @@ class HiDateRangePicker extends React.Component {
|
|
58
58
|
|
59
59
|
this.onDayToClick = day => {
|
60
60
|
let change = moment(day) >= moment(this.props.from);
|
61
|
+
const today = moment().tz(this.props.timezoneName);
|
62
|
+
const todayDate = new Date(today.year(), today.month(), today.date(), 23, 59, 59);
|
61
63
|
|
62
|
-
if (change &&
|
64
|
+
if (change && day > todayDate) {
|
63
65
|
change = false;
|
64
66
|
}
|
65
67
|
|
@@ -85,11 +87,13 @@ class HiDateRangePicker extends React.Component {
|
|
85
87
|
|
86
88
|
this.handleChange = (name, day) => {
|
87
89
|
const {
|
88
|
-
translations
|
90
|
+
translations,
|
91
|
+
timezoneName
|
89
92
|
} = this.props;
|
90
93
|
let date;
|
91
94
|
let error;
|
92
|
-
const
|
95
|
+
const today = moment().tz(timezoneName);
|
96
|
+
const now = new Date(today.year(), today.month(), today.date(), 23, 59, 59);
|
93
97
|
const {
|
94
98
|
minimumDate,
|
95
99
|
disableFutureDays,
|
@@ -115,8 +119,8 @@ class HiDateRangePicker extends React.Component {
|
|
115
119
|
error = translations.to_superior_from;
|
116
120
|
} else if (moment(date).utc() < moment(minimumDate).utc().startOf('day')) {
|
117
121
|
error = translations.date_inferior_min_date.replace('%s', moment(minimumDate).format(format));
|
118
|
-
} else if (disableFutureDays &&
|
119
|
-
error = translations.date_superior_max_date.replace('%s', moment().format(format));
|
122
|
+
} else if (disableFutureDays && date > now) {
|
123
|
+
error = translations.date_superior_max_date.replace('%s', moment().tz(timezoneName).format(format));
|
120
124
|
}
|
121
125
|
|
122
126
|
if (!this.props.enableTime) {
|
@@ -165,10 +169,37 @@ class HiDateRangePicker extends React.Component {
|
|
165
169
|
|
166
170
|
this.handleReset = name => {
|
167
171
|
this.handleChange(name, undefined);
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
+
};
|
173
|
+
|
174
|
+
this.handleKeyDown = name => event => {
|
175
|
+
if (event.key === 'Tab' && !event.shiftKey) {
|
176
|
+
const nodeName = document.activeElement.nodeName;
|
177
|
+
|
178
|
+
if (this.props[name] && nodeName === 'INPUT' && document.activeElement.nextSibling.children.length > 0) {
|
179
|
+
document.activeElement.nextSibling.focus();
|
180
|
+
} else if (name === 'from') {
|
181
|
+
this.handleDayPickerBlur('from');
|
182
|
+
this.handleDayPickerFocus('to');
|
183
|
+
this.toInput.handleInputFocus();
|
184
|
+
setTimeout(() => {
|
185
|
+
document.getElementById(`${this.props.id}-to`).focus();
|
186
|
+
}, 1);
|
187
|
+
} else if (name === 'to') {
|
188
|
+
this.handleDayPickerBlur('to');
|
189
|
+
this.toInput.handleInputBlur(event);
|
190
|
+
setTimeout(() => {
|
191
|
+
document.activeElement.blur();
|
192
|
+
}, 1);
|
193
|
+
}
|
194
|
+
} else if (event.key === 'Escape' && !event.shiftKey) {
|
195
|
+
if (name === 'from') {
|
196
|
+
this.fromInput.hideDayPicker();
|
197
|
+
} else if (name === 'to') {
|
198
|
+
this.toInput.hideDayPicker();
|
199
|
+
}
|
200
|
+
|
201
|
+
event.stopPropagation();
|
202
|
+
}
|
172
203
|
};
|
173
204
|
|
174
205
|
this.openPanel = panel => {
|
@@ -246,19 +277,19 @@ class HiDateRangePicker extends React.Component {
|
|
246
277
|
const yearPickerProps = {
|
247
278
|
value: this.state.currentMonth,
|
248
279
|
onChange: this.handleCurrentMonthChange,
|
249
|
-
|
280
|
+
disableFutureDays: this.props.disableFutureDays
|
250
281
|
};
|
251
282
|
return React.createElement(YearPickerOverlay, _extends({
|
252
283
|
key: `${name}-year-picker-overlay`
|
253
284
|
}, yearPickerProps, propsOverlay));
|
254
285
|
};
|
255
286
|
|
287
|
+
const _today = moment().tz(this.props.timezoneName);
|
288
|
+
|
256
289
|
this.state = {
|
257
|
-
currentMonth: new Date(),
|
290
|
+
currentMonth: new Date(_today.year(), _today.month(), _today.date()),
|
258
291
|
focusedInput: '',
|
259
|
-
openedPanel: 'calendar'
|
260
|
-
keyFrom: 1,
|
261
|
-
keyTo: 1
|
292
|
+
openedPanel: 'calendar'
|
262
293
|
};
|
263
294
|
}
|
264
295
|
|
@@ -290,14 +321,17 @@ class HiDateRangePicker extends React.Component {
|
|
290
321
|
errorText,
|
291
322
|
hasSelector,
|
292
323
|
helperIcon,
|
293
|
-
helperText
|
324
|
+
helperText,
|
325
|
+
timezoneName
|
294
326
|
} = _this$props,
|
295
|
-
props = _objectWithoutProperties(_this$props, ["classes", "disabled", "disabledDays", "disableFutureDays", "enableTime", "labelFrom", "labelTo", "locale", "format", "from", "fromError", "minimumDate", "onReset", "to", "toError", "translations", "id", "staticPosition", "errorText", "hasSelector", "helperIcon", "helperText"]);
|
327
|
+
props = _objectWithoutProperties(_this$props, ["classes", "disabled", "disabledDays", "disableFutureDays", "enableTime", "labelFrom", "labelTo", "locale", "format", "from", "fromError", "minimumDate", "onReset", "to", "toError", "translations", "id", "staticPosition", "errorText", "hasSelector", "helperIcon", "helperText", "timezoneName"]);
|
296
328
|
|
297
|
-
const
|
329
|
+
const today = moment().tz(timezoneName);
|
330
|
+
const now = new Date(today.year(), today.month(), today.date(), 23, 59, 59, 999);
|
298
331
|
const modifiers = {
|
299
332
|
start: from,
|
300
|
-
end: to
|
333
|
+
end: to,
|
334
|
+
[classes.currentDay]: new Date(today.year(), today.month(), today.date())
|
301
335
|
};
|
302
336
|
const modifiersStyles = {
|
303
337
|
start: {
|
@@ -385,7 +419,10 @@ class HiDateRangePicker extends React.Component {
|
|
385
419
|
}, {
|
386
420
|
id: `${id}-from`,
|
387
421
|
onChange: this.handleInputChange('from'),
|
388
|
-
disabled
|
422
|
+
disabled,
|
423
|
+
HiInputProps: {
|
424
|
+
onSubmit: this.props.onSubmit
|
425
|
+
}
|
389
426
|
});
|
390
427
|
|
391
428
|
const toInputProps = _objectSpread({}, onReset && {
|
@@ -397,7 +434,10 @@ class HiDateRangePicker extends React.Component {
|
|
397
434
|
}, {
|
398
435
|
id: `${id}-to`,
|
399
436
|
onChange: this.handleInputChange('to'),
|
400
|
-
disabled
|
437
|
+
disabled,
|
438
|
+
HiInputProps: {
|
439
|
+
onSubmit: this.props.onSubmit
|
440
|
+
}
|
401
441
|
});
|
402
442
|
|
403
443
|
const toClass = classNames(classes.toInput, {
|
@@ -408,10 +448,10 @@ class HiDateRangePicker extends React.Component {
|
|
408
448
|
className: classNames(classes.root, classes.rangePickerContainer)
|
409
449
|
}, React.createElement("div", {
|
410
450
|
className: classes.fromInput,
|
411
|
-
onFocus: () => this.handleDayPickerFocus('from')
|
412
|
-
|
451
|
+
onFocus: () => this.handleDayPickerFocus('from'),
|
452
|
+
onKeyDown: this.handleKeyDown('from')
|
413
453
|
}, React.createElement("div", null, React.createElement(DayPickerInput, {
|
414
|
-
key:
|
454
|
+
key: '1',
|
415
455
|
ref: el => {
|
416
456
|
this.fromInput = el;
|
417
457
|
},
|
@@ -429,9 +469,10 @@ class HiDateRangePicker extends React.Component {
|
|
429
469
|
}))), React.createElement("div", {
|
430
470
|
className: toClass,
|
431
471
|
onFocus: () => this.handleDayPickerFocus('to'),
|
432
|
-
onBlur: () => this.handleDayPickerBlur('to')
|
472
|
+
onBlur: () => this.handleDayPickerBlur('to'),
|
473
|
+
onKeyDown: this.handleKeyDown('to')
|
433
474
|
}, React.createElement(DayPickerInput, {
|
434
|
-
key:
|
475
|
+
key: '1',
|
435
476
|
ref: el => {
|
436
477
|
this.toInput = el;
|
437
478
|
},
|
@@ -443,8 +484,7 @@ class HiDateRangePicker extends React.Component {
|
|
443
484
|
inputProps: toInputProps,
|
444
485
|
format: enableTime ? `${format} HH:mm` : format,
|
445
486
|
formatDate: MomentLocaleUtils.formatDate,
|
446
|
-
parseDate: MomentLocaleUtils.parseDate
|
447
|
-
,
|
487
|
+
parseDate: MomentLocaleUtils.parseDate,
|
448
488
|
placeholder: ''
|
449
489
|
})));
|
450
490
|
|
@@ -476,6 +516,7 @@ HiDateRangePicker.defaultProps = {
|
|
476
516
|
locale: 'fr-FR',
|
477
517
|
minimumDate: new Date(2013, 4, 1),
|
478
518
|
// by default 1 May 2013
|
519
|
+
timezoneName: 'Europe/Paris',
|
479
520
|
translations: {
|
480
521
|
today: 'today',
|
481
522
|
hour: 'Hour',
|
@@ -597,11 +638,21 @@ HiDateRangePicker.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
597
638
|
*/
|
598
639
|
onReset: PropTypes.func,
|
599
640
|
|
641
|
+
/**
|
642
|
+
* Callback lorsque l'utilisateur tape sur "Entrée"
|
643
|
+
*/
|
644
|
+
onSubmit: PropTypes.func,
|
645
|
+
|
600
646
|
/**
|
601
647
|
* Si true, le calendrier sera dans une div static plutot que dans une popper absolute
|
602
648
|
*/
|
603
649
|
staticPosition: PropTypes.bool,
|
604
650
|
|
651
|
+
/**
|
652
|
+
* Timezone de l'utilisateur
|
653
|
+
*/
|
654
|
+
timezoneName: PropTypes.string,
|
655
|
+
|
605
656
|
/**
|
606
657
|
* Date de fin sélectionnée
|
607
658
|
*/
|
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
3
3
|
import React from 'react';
|
4
4
|
import PropTypes from 'prop-types';
|
5
|
-
import moment from 'moment';
|
5
|
+
import moment from 'moment-timezone';
|
6
6
|
import { findDOMNode } from 'react-dom';
|
7
7
|
import Grid from '@material-ui/core/Grid';
|
8
8
|
import withStyles from '../styles/withStyles';
|
@@ -52,7 +52,7 @@ export function yearAndQuarter(format, date, t) {
|
|
52
52
|
const indexM = split.findIndex(findM);
|
53
53
|
return indexY < indexM ? date.format(`${split[indexY]}${s}[${t.short_quarter}]Q`) : date.format(`[${t.short_quarter}]Q${s}${split[indexY]}`);
|
54
54
|
}
|
55
|
-
export function buildDateRangeOptionByKey(key, t, format) {
|
55
|
+
export function buildDateRangeOptionByKey(key, t, format, timezoneName) {
|
56
56
|
let from;
|
57
57
|
let label;
|
58
58
|
let info;
|
@@ -67,71 +67,71 @@ export function buildDateRangeOptionByKey(key, t, format) {
|
|
67
67
|
switch (key) {
|
68
68
|
case 'custom':
|
69
69
|
label = t.custom_period;
|
70
|
-
from = moment().subtract(15, 'day').startOf('day');
|
71
|
-
to = moment().endOf('day');
|
70
|
+
from = moment().tz(timezoneName).subtract(15, 'day').startOf('day');
|
71
|
+
to = moment().tz(timezoneName).endOf('day');
|
72
72
|
type = 'primary-highlight';
|
73
73
|
break;
|
74
74
|
|
75
75
|
case 'cd':
|
76
76
|
label = t.today;
|
77
|
-
from = moment().startOf('day');
|
78
|
-
to = moment().endOf('day');
|
77
|
+
from = moment().tz(timezoneName).startOf('day');
|
78
|
+
to = moment().tz(timezoneName).endOf('day');
|
79
79
|
info = `${from.format(format)}`;
|
80
80
|
break;
|
81
81
|
|
82
82
|
case 'pd':
|
83
83
|
label = t.yesterday;
|
84
|
-
from = moment().subtract(1, 'day').startOf('day');
|
85
|
-
to = moment().subtract(1, 'day').endOf('day');
|
84
|
+
from = moment().tz(timezoneName).subtract(1, 'day').startOf('day');
|
85
|
+
to = moment().tz(timezoneName).subtract(1, 'day').endOf('day');
|
86
86
|
info = `${from.format(format)}`;
|
87
87
|
break;
|
88
88
|
|
89
89
|
case 'cw':
|
90
90
|
label = t.current_week;
|
91
|
-
from = moment().startOf('week');
|
92
|
-
to = moment();
|
91
|
+
from = moment().tz(timezoneName).startOf('week');
|
92
|
+
to = moment().tz(timezoneName);
|
93
93
|
info = `${t.short_week}${from.format('w')}, \n ${from.format(format)} ${t.to_now}`;
|
94
94
|
break;
|
95
95
|
|
96
96
|
case 'pw':
|
97
97
|
label = t.previous_week;
|
98
|
-
from = moment().subtract(1, 'week').startOf('week');
|
99
|
-
to = moment().subtract(1, 'week').endOf('week');
|
98
|
+
from = moment().tz(timezoneName).subtract(1, 'week').startOf('week');
|
99
|
+
to = moment().tz(timezoneName).subtract(1, 'week').endOf('week');
|
100
100
|
info = `${t.short_week}${from.format('w')}, ${from.format(format)} ${t.to} ${to.format(format)}`;
|
101
101
|
break;
|
102
102
|
|
103
103
|
case 'cm':
|
104
104
|
label = t.current_month;
|
105
|
-
from = moment().startOf('month');
|
106
|
-
to = moment();
|
105
|
+
from = moment().tz(timezoneName).startOf('month');
|
106
|
+
to = moment().tz(timezoneName);
|
107
107
|
info = `${from.format(format)} ${t.to_now}, ${to.diff(from, 'days') + 1} ${t.days}`;
|
108
108
|
break;
|
109
109
|
|
110
110
|
case 'pm':
|
111
111
|
label = t.previous_month;
|
112
|
-
from = moment().subtract(1, 'month').startOf('month');
|
113
|
-
to = moment().subtract(1, 'month').endOf('month');
|
112
|
+
from = moment().tz(timezoneName).subtract(1, 'month').startOf('month');
|
113
|
+
to = moment().tz(timezoneName).subtract(1, 'month').endOf('month');
|
114
114
|
info = `${yearAndMonth(format, from)}, ${from.daysInMonth()} ${t.days}`;
|
115
115
|
break;
|
116
116
|
|
117
117
|
case 'cq':
|
118
118
|
label = t.current_quarter;
|
119
|
-
from = moment().startOf('quarter');
|
120
|
-
to = moment();
|
119
|
+
from = moment().tz(timezoneName).startOf('quarter');
|
120
|
+
to = moment().tz(timezoneName);
|
121
121
|
info = `${yearAndQuarter(format, from, t)}, ${from.format(format)} ${t.to_now}, ${to.diff(from, 'days') + 1} ${t.days}`;
|
122
122
|
break;
|
123
123
|
|
124
124
|
case 'pq':
|
125
125
|
label = t.previous_quarter;
|
126
|
-
from = moment().subtract(1, 'quarter').startOf('quarter');
|
127
|
-
to = moment().subtract(1, 'quarter').endOf('quarter');
|
126
|
+
from = moment().tz(timezoneName).subtract(1, 'quarter').startOf('quarter');
|
127
|
+
to = moment().tz(timezoneName).subtract(1, 'quarter').endOf('quarter');
|
128
128
|
info = `${yearAndQuarter(format, from, t)}, ${to.diff(from, 'days') + 1} ${t.days}`;
|
129
129
|
break;
|
130
130
|
|
131
131
|
case 'cy':
|
132
132
|
label = t.current_year;
|
133
|
-
from = moment().startOf('year');
|
134
|
-
to = moment();
|
133
|
+
from = moment().tz(timezoneName).startOf('year');
|
134
|
+
to = moment().tz(timezoneName);
|
135
135
|
info = `${from.format(format)} ${t.to_now}, ${to.diff(from, 'days') + 1} ${t.days}`;
|
136
136
|
break;
|
137
137
|
|
@@ -187,22 +187,10 @@ class HiDateRangeSelector extends React.Component {
|
|
187
187
|
[name]: value,
|
188
188
|
key: prevState.key === 1 ? 2 : 1
|
189
189
|
}));
|
190
|
-
|
191
|
-
|
192
|
-
if (selectedOption) {
|
193
|
-
this.props.onChange('from', selectedOption.from.toDate());
|
194
|
-
this.props.onChange('to', selectedOption.to.toDate());
|
195
|
-
this.props.onChange('fromError', false);
|
196
|
-
this.props.onChange('toError', false);
|
197
|
-
}
|
198
|
-
|
199
|
-
if (this.props.returnSelectValue === true) {
|
200
|
-
this.props.onChange('period', value);
|
201
|
-
}
|
190
|
+
this.updateDates(value);
|
202
191
|
};
|
203
192
|
|
204
|
-
this.
|
205
|
-
this.options = props.availableOptionKeys.map(key => buildDateRangeOptionByKey(key, props.translations, props.format));
|
193
|
+
this.options = props.availableOptionKeys.map(key => buildDateRangeOptionByKey(key, props.translations, props.format, props.timezoneName));
|
206
194
|
this.state = {
|
207
195
|
selectedPreset: props.defaultPreset,
|
208
196
|
containerWidth: 0
|
@@ -227,10 +215,32 @@ class HiDateRangeSelector extends React.Component {
|
|
227
215
|
}
|
228
216
|
}
|
229
217
|
|
218
|
+
componentDidUpdate(prevProps) {
|
219
|
+
if (prevProps.timezoneName !== this.props.timezoneName) {
|
220
|
+
this.options = this.props.availableOptionKeys.map(key => buildDateRangeOptionByKey(key, this.props.translations, this.props.format, this.props.timezoneName));
|
221
|
+
this.updateDates(this.state.selectedPreset);
|
222
|
+
}
|
223
|
+
}
|
224
|
+
|
230
225
|
componentWillUnmount() {
|
231
226
|
clearTimeout(this.timeout); // TODO : supprimer ?
|
232
227
|
}
|
233
228
|
|
229
|
+
updateDates(value) {
|
230
|
+
const selectedOption = this.options.find(option => option.id === value);
|
231
|
+
|
232
|
+
if (selectedOption) {
|
233
|
+
this.props.onChange('from', new Date(selectedOption.from.format('YYYY-MM-DD HH:mm:ss')));
|
234
|
+
this.props.onChange('to', new Date(selectedOption.to.format('YYYY-MM-DD HH:mm:ss')));
|
235
|
+
this.props.onChange('fromError', false);
|
236
|
+
this.props.onChange('toError', false);
|
237
|
+
}
|
238
|
+
|
239
|
+
if (this.props.returnSelectValue === true) {
|
240
|
+
this.props.onChange('period', value);
|
241
|
+
}
|
242
|
+
}
|
243
|
+
|
234
244
|
render() {
|
235
245
|
const _this$props = this.props,
|
236
246
|
{
|
@@ -299,7 +309,8 @@ class HiDateRangeSelector extends React.Component {
|
|
299
309
|
classes: {
|
300
310
|
root: classes.dateSelect
|
301
311
|
},
|
302
|
-
staticPosition: staticPosition
|
312
|
+
staticPosition: staticPosition,
|
313
|
+
onSubmit: this.props.onSubmit
|
303
314
|
}, selectProps))), React.createElement(Grid, {
|
304
315
|
item: true,
|
305
316
|
xs: 12,
|
@@ -341,6 +352,7 @@ HiDateRangeSelector.defaultProps = {
|
|
341
352
|
format: 'YYYY-DD-MM',
|
342
353
|
minimumDate: new Date(2013, 4, 1),
|
343
354
|
// by default 1 May 2013
|
355
|
+
timezoneName: 'Europe/Paris',
|
344
356
|
translations: {
|
345
357
|
today: 'Today',
|
346
358
|
hour: 'Hour',
|
@@ -459,6 +471,11 @@ HiDateRangeSelector.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
459
471
|
*/
|
460
472
|
onChange: PropTypes.func.isRequired,
|
461
473
|
|
474
|
+
/**
|
475
|
+
* Callback lorsque l'utilisateur tape sur "Entrée"
|
476
|
+
*/
|
477
|
+
onSubmit: PropTypes.func,
|
478
|
+
|
462
479
|
/**
|
463
480
|
* true si champs obligatoire
|
464
481
|
*/
|
@@ -479,6 +496,11 @@ HiDateRangeSelector.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
479
496
|
*/
|
480
497
|
staticPosition: PropTypes.bool,
|
481
498
|
|
499
|
+
/**
|
500
|
+
* Timezone de l'utilisateur
|
501
|
+
*/
|
502
|
+
timezoneName: PropTypes.string,
|
503
|
+
|
482
504
|
/**
|
483
505
|
* Date de fin sélectionnée
|
484
506
|
*/
|
@@ -10,8 +10,15 @@ class YearPickerOverlay extends React.Component {
|
|
10
10
|
super(props);
|
11
11
|
this.years = [];
|
12
12
|
this.handleYearClick = this.handleYearClick.bind(this);
|
13
|
+
let minDate = props.minimumDate;
|
14
|
+
|
15
|
+
if (!minDate) {
|
16
|
+
let today = new Date();
|
17
|
+
minDate = new Date(today.getFullYear() - 5, today.getMonth(), today.getDate()); // by default 5 years from now
|
18
|
+
}
|
19
|
+
|
13
20
|
const currentYear = new Date().getFullYear();
|
14
|
-
const minimumYear =
|
21
|
+
const minimumYear = minDate.getFullYear();
|
15
22
|
this.years = [currentYear]; // get years from minimum date to now
|
16
23
|
|
17
24
|
if (!props.disablePastDays && currentYear > minimumYear) {
|
@@ -55,8 +62,6 @@ class YearPickerOverlay extends React.Component {
|
|
55
62
|
}
|
56
63
|
|
57
64
|
YearPickerOverlay.defaultProps = {
|
58
|
-
minimumDate: new Date(2013, 4, 1),
|
59
|
-
// by default 1 May 2013
|
60
65
|
translations: {
|
61
66
|
year: 'Year'
|
62
67
|
}
|