@hipay/hipay-material-ui 2.0.0-beta.60 → 2.0.0-beta.62
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 +126 -0
- package/HiDatePicker/HiDatePicker.js +37 -12
- package/HiDatePicker/HiDateRangePicker.js +71 -57
- package/HiDatePicker/HiDateRangeSelector.js +34 -20
- package/HiDatePicker/stylesheet.js +32 -17
- package/HiSelect/HiSelect.js +489 -607
- package/HiSelect/index.js +41 -3
- package/HiSelectableList/HiSelectableList.js +68 -3
- package/HiSelectableList/HiSelectableListItem.js +22 -10
- package/README.md +15 -0
- package/es/HiDatePicker/HiDatePicker.js +30 -10
- package/es/HiDatePicker/HiDateRangePicker.js +38 -21
- package/es/HiDatePicker/HiDateRangeSelector.js +24 -13
- package/es/HiDatePicker/stylesheet.js +32 -17
- package/es/{HiSelectNew → HiSelect}/HiNestedSelect.js +1 -1
- package/es/{HiSelectNew → HiSelect}/HiNestedSelectContent.js +1 -1
- package/es/HiSelect/HiSelect.js +441 -564
- package/es/{HiSelectNew → HiSelect}/HiSelectContent.js +1 -1
- package/es/HiSelect/index.js +4 -1
- package/es/HiSelectableList/HiSelectableList.js +65 -4
- package/es/HiSelectableList/HiSelectableListItem.js +18 -10
- package/es/styles/createPalette.js +1 -1
- package/es/utils/helpers.js +9 -1
- package/index.es.js +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/styles/createPalette.js +1 -1
- package/umd/hipay-material-ui.development.js +7860 -7749
- package/umd/hipay-material-ui.production.min.js +2 -2
- package/utils/helpers.js +9 -1
- package/HiSelect/SelectInput.js +0 -369
- package/HiSelectNew/HiSelect.js +0 -929
- package/HiSelectNew/HiSelectField.js +0 -146
- package/HiSelectNew/index.js +0 -69
- package/es/HiSelect/SelectInput.js +0 -321
- package/es/HiSelectNew/HiSelect.js +0 -852
- package/es/HiSelectNew/HiSelectField.js +0 -111
- package/es/HiSelectNew/index.js +0 -6
- /package/{HiSelectNew → HiSelect}/HiDynamicSelect.js +0 -0
- /package/{HiSelectNew → HiSelect}/HiDynamicSelectField.js +0 -0
- /package/{HiSelectNew → HiSelect}/HiNestedSelect.js +0 -0
- /package/{HiSelectNew → HiSelect}/HiNestedSelectContent.js +0 -0
- /package/{HiSelectNew → HiSelect}/HiNestedSelectField.js +0 -0
- /package/{HiSelectNew → HiSelect}/HiSelectContent.js +0 -0
- /package/{HiSelectNew → HiSelect}/HiSelectInput.js +0 -0
- /package/es/{HiSelectNew → HiSelect}/HiDynamicSelect.js +0 -0
- /package/es/{HiSelectNew → HiSelect}/HiDynamicSelectField.js +0 -0
- /package/es/{HiSelectNew → HiSelect}/HiNestedSelectField.js +0 -0
- /package/es/{HiSelectNew → HiSelect}/HiSelectInput.js +0 -0
package/HiSelect/index.js
CHANGED
@@ -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", {
|
@@ -11,16 +13,46 @@ Object.defineProperty(exports, "default", {
|
|
11
13
|
return _HiSelect.default;
|
12
14
|
}
|
13
15
|
});
|
16
|
+
Object.defineProperty(exports, "HiNestedSelect", {
|
17
|
+
enumerable: true,
|
18
|
+
get: function get() {
|
19
|
+
return _HiNestedSelect.default;
|
20
|
+
}
|
21
|
+
});
|
14
22
|
Object.defineProperty(exports, "HiSelectField", {
|
15
23
|
enumerable: true,
|
16
24
|
get: function get() {
|
17
25
|
return _HiSelectField.default;
|
18
26
|
}
|
19
27
|
});
|
20
|
-
Object.defineProperty(exports, "
|
28
|
+
Object.defineProperty(exports, "HiSelectInput", {
|
29
|
+
enumerable: true,
|
30
|
+
get: function get() {
|
31
|
+
return _HiSelectInput.default;
|
32
|
+
}
|
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", {
|
21
53
|
enumerable: true,
|
22
54
|
get: function get() {
|
23
|
-
return
|
55
|
+
return _HiNestedSelectContent.getRecursiveFinalItemIdList;
|
24
56
|
}
|
25
57
|
});
|
26
58
|
Object.defineProperty(exports, "HiSuggestSelect", {
|
@@ -38,9 +70,15 @@ Object.defineProperty(exports, "HiSuggestSelectField", {
|
|
38
70
|
|
39
71
|
var _HiSelect = _interopRequireDefault(require("./HiSelect"));
|
40
72
|
|
73
|
+
var _HiNestedSelect = _interopRequireDefault(require("./HiNestedSelect"));
|
74
|
+
|
41
75
|
var _HiSelectField = _interopRequireDefault(require("./HiSelectField"));
|
42
76
|
|
43
|
-
var
|
77
|
+
var _HiSelectInput = _interopRequireDefault(require("./HiSelectInput"));
|
78
|
+
|
79
|
+
var _HiSelectContent = _interopRequireDefault(require("./HiSelectContent"));
|
80
|
+
|
81
|
+
var _HiNestedSelectContent = _interopRequireWildcard(require("./HiNestedSelectContent"));
|
44
82
|
|
45
83
|
var _HiSuggestSelect = _interopRequireDefault(require("./HiSuggestSelect"));
|
46
84
|
|
@@ -7,6 +7,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
7
7
|
});
|
8
8
|
exports.default = exports.styles = void 0;
|
9
9
|
|
10
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
11
|
+
|
10
12
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
11
13
|
|
12
14
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
@@ -33,6 +35,8 @@ var _HiSelectableListItem = _interopRequireDefault(require("./HiSelectableListIt
|
|
33
35
|
|
34
36
|
var _helpers = require("../utils/helpers");
|
35
37
|
|
38
|
+
var _keycode = _interopRequireDefault(require("keycode"));
|
39
|
+
|
36
40
|
var styles = function styles() {
|
37
41
|
return {
|
38
42
|
root: {
|
@@ -42,6 +46,8 @@ var styles = function styles() {
|
|
42
46
|
};
|
43
47
|
/**
|
44
48
|
* Construit une liste d'item sélectionnable (avec checkbox)
|
49
|
+
* - la navigation au clavier est gérée par l'event KeyDown
|
50
|
+
* - le premier focus est géré sur le DidMount
|
45
51
|
*/
|
46
52
|
|
47
53
|
|
@@ -71,6 +77,23 @@ function (_React$PureComponent) {
|
|
71
77
|
};
|
72
78
|
};
|
73
79
|
|
80
|
+
_this.handleKeyDown = function (event) {
|
81
|
+
var nextItem;
|
82
|
+
var key = (0, _keycode.default)(event);
|
83
|
+
|
84
|
+
if (key === 'down') {
|
85
|
+
event.preventDefault();
|
86
|
+
nextItem = (0, _helpers.getNextItemSelectable)(document.activeElement, 'down');
|
87
|
+
} else if (key === 'up') {
|
88
|
+
event.preventDefault();
|
89
|
+
nextItem = (0, _helpers.getNextItemSelectable)(document.activeElement, 'up');
|
90
|
+
}
|
91
|
+
|
92
|
+
if (nextItem) {
|
93
|
+
nextItem.focus();
|
94
|
+
}
|
95
|
+
};
|
96
|
+
|
74
97
|
_this.buildRecursiveListItem = function (item) {
|
75
98
|
var level = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
76
99
|
var _this$props = _this.props,
|
@@ -103,7 +126,8 @@ function (_React$PureComponent) {
|
|
103
126
|
onKeyDown: onKeyDown,
|
104
127
|
onKeyUp: onKeyUp,
|
105
128
|
selected: selectedItemIdList.includes(item.id) // item props override upper props (disabled, hideCheckbox, icon, level...)
|
106
|
-
|
129
|
+
,
|
130
|
+
item: item
|
107
131
|
}, item)), item.children && item.children.length > 0 && item.children.filter(function (subItem) {
|
108
132
|
return !(subItem.displayed === false);
|
109
133
|
}).map(function (subItem) {
|
@@ -112,6 +136,10 @@ function (_React$PureComponent) {
|
|
112
136
|
};
|
113
137
|
|
114
138
|
_this.compareItem = function (a, b) {
|
139
|
+
if (_this.props.comparItemFunc) {
|
140
|
+
return _this.props.comparItemFunc(a, b);
|
141
|
+
}
|
142
|
+
|
115
143
|
if (a.label === undefined || b.label === undefined) {
|
116
144
|
return 0;
|
117
145
|
}
|
@@ -133,6 +161,24 @@ function (_React$PureComponent) {
|
|
133
161
|
}
|
134
162
|
|
135
163
|
(0, _createClass2.default)(HiSelectableList, [{
|
164
|
+
key: "componentDidMount",
|
165
|
+
value: function componentDidMount() {
|
166
|
+
if (this.props.overlay && this.props.overlay.getElementsByTagName('li')[0]) {
|
167
|
+
var item = this.props.overlay.getElementsByTagName('li')[0];
|
168
|
+
var value = (0, _typeof2.default)(this.props.value) === 'object' ? this.props.value[0] : this.props.value;
|
169
|
+
|
170
|
+
if (value) {
|
171
|
+
if (typeof this.props.value[0] === 'string') {
|
172
|
+
item = this.props.overlay.getElementsByTagName('li')[value];
|
173
|
+
} else if (typeof this.props.value[0] === 'number') {
|
174
|
+
item = this.props.overlay.getElementsByTagName('li')[value - 1];
|
175
|
+
}
|
176
|
+
}
|
177
|
+
|
178
|
+
item.focus();
|
179
|
+
}
|
180
|
+
}
|
181
|
+
}, {
|
136
182
|
key: "render",
|
137
183
|
value: function render() {
|
138
184
|
var _this2 = this;
|
@@ -147,7 +193,11 @@ function (_React$PureComponent) {
|
|
147
193
|
}
|
148
194
|
|
149
195
|
return _react.default.createElement(_List.default, {
|
150
|
-
className: classes.root
|
196
|
+
className: classes.root,
|
197
|
+
onKeyDown: this.handleKeyDown,
|
198
|
+
innerRef: function innerRef(el) {
|
199
|
+
_this2.el = el;
|
200
|
+
}
|
151
201
|
}, itemList.filter(function (item) {
|
152
202
|
return !(item.displayed === false);
|
153
203
|
}) // don't remove if undefined
|
@@ -184,6 +234,11 @@ HiSelectableList.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
184
234
|
*/
|
185
235
|
classes: _propTypes.default.object,
|
186
236
|
|
237
|
+
/**
|
238
|
+
* Fonction de comparaison utilisée pour les tris
|
239
|
+
*/
|
240
|
+
comparItemFunc: _propTypes.default.func,
|
241
|
+
|
187
242
|
/**
|
188
243
|
* Désactive la listes
|
189
244
|
*/
|
@@ -222,6 +277,11 @@ HiSelectableList.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
222
277
|
*/
|
223
278
|
onSelect: _propTypes.default.func.isRequired,
|
224
279
|
|
280
|
+
/**
|
281
|
+
* Overlay récupéré au niveau de la div précédant le HiSelectInput
|
282
|
+
*/
|
283
|
+
overlay: _propTypes.default.object,
|
284
|
+
|
225
285
|
/**
|
226
286
|
* Liste des id des éléments sélectionnés
|
227
287
|
*/
|
@@ -235,7 +295,12 @@ HiSelectableList.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
235
295
|
/**
|
236
296
|
* Liste des éléments à placer en premier, peu import le tri
|
237
297
|
*/
|
238
|
-
sortAppendList: _propTypes.default.array
|
298
|
+
sortAppendList: _propTypes.default.array,
|
299
|
+
|
300
|
+
/**
|
301
|
+
* Value(s) du select
|
302
|
+
*/
|
303
|
+
value: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string, _propTypes.default.array])
|
239
304
|
} : {};
|
240
305
|
|
241
306
|
var _default = (0, _withStyles.default)(styles, {
|
@@ -47,6 +47,8 @@ var _helpers = require("../utils/helpers");
|
|
47
47
|
|
48
48
|
var _pure = _interopRequireDefault(require("recompose/pure"));
|
49
49
|
|
50
|
+
var _keycode = _interopRequireDefault(require("keycode"));
|
51
|
+
|
50
52
|
var PureListSubheader = (0, _pure.default)(_ListSubheader.default);
|
51
53
|
var PureListItem = (0, _pure.default)(_ListItem.default);
|
52
54
|
|
@@ -98,9 +100,6 @@ var styles = function styles(theme) {
|
|
98
100
|
cursor: 'default',
|
99
101
|
opacity: 'inherit'
|
100
102
|
},
|
101
|
-
selected: {
|
102
|
-
backgroundColor: theme.palette.action.selected
|
103
|
-
},
|
104
103
|
pinned: {
|
105
104
|
display: 'inherit',
|
106
105
|
marginRight: 8,
|
@@ -198,6 +197,7 @@ var styles = function styles(theme) {
|
|
198
197
|
};
|
199
198
|
/**
|
200
199
|
* Construit un élément de liste sélectionnable (avec checkbox)
|
200
|
+
* - la sélection/déséclection d'un item est géré avec KeyDown
|
201
201
|
*/
|
202
202
|
|
203
203
|
|
@@ -222,6 +222,20 @@ function (_React$PureComponent) {
|
|
222
222
|
};
|
223
223
|
};
|
224
224
|
|
225
|
+
_this.handleKeyDown = function (item) {
|
226
|
+
return function (event) {
|
227
|
+
var key = (0, _keycode.default)(event);
|
228
|
+
|
229
|
+
if (key === 'space' || key === 'enter') {
|
230
|
+
event.preventDefault();
|
231
|
+
|
232
|
+
if (item) {
|
233
|
+
_this.props.onSelect(null, item);
|
234
|
+
}
|
235
|
+
}
|
236
|
+
};
|
237
|
+
};
|
238
|
+
|
225
239
|
_this.state = {
|
226
240
|
hover: false
|
227
241
|
};
|
@@ -292,8 +306,6 @@ function (_React$PureComponent) {
|
|
292
306
|
fallbackImage = _this$props2.fallbackImage,
|
293
307
|
hideCheckbox = _this$props2.hideCheckbox,
|
294
308
|
onSelect = _this$props2.onSelect,
|
295
|
-
onKeyDown = _this$props2.onKeyDown,
|
296
|
-
onKeyUp = _this$props2.onKeyUp,
|
297
309
|
indeterminate = _this$props2.indeterminate,
|
298
310
|
indeterminateIcon = _this$props2.indeterminateIcon,
|
299
311
|
icon = _this$props2.icon,
|
@@ -309,7 +321,8 @@ function (_React$PureComponent) {
|
|
309
321
|
secondaryLabel = _this$props2.secondaryLabel,
|
310
322
|
thin = _this$props2.thin,
|
311
323
|
type = _this$props2.type,
|
312
|
-
color = _this$props2.color
|
324
|
+
color = _this$props2.color,
|
325
|
+
item = _this$props2.item; // Return simple loader list item
|
313
326
|
|
314
327
|
if (type === 'loader') {
|
315
328
|
return _react.default.createElement(_ListItem.default, null, _react.default.createElement(_HiLoader.default, {
|
@@ -335,14 +348,13 @@ function (_React$PureComponent) {
|
|
335
348
|
classes: {
|
336
349
|
root: classes.root
|
337
350
|
},
|
338
|
-
className: (0, _classnames.default)(classes.listItem, classes.listItemHover, (_classNames = {}, (0, _defineProperty2.default)(_classNames, classes.disabled, disabled), (0, _defineProperty2.default)(_classNames, classes.
|
351
|
+
className: (0, _classnames.default)(classes.listItem, classes.listItemHover, (_classNames = {}, (0, _defineProperty2.default)(_classNames, classes.disabled, disabled), (0, _defineProperty2.default)(_classNames, classes.thin, thin), (0, _defineProperty2.default)(_classNames, classes.pinned, pinned), (0, _defineProperty2.default)(_classNames, classes.inline, secondaryInline), (0, _defineProperty2.default)(_classNames, classes.listItemWithoutSecondaryInline, !secondaryInline), (0, _defineProperty2.default)(_classNames, classes.listItemInlineWithInfoWithoutSecondary, secondaryInline && info && !secondaryLabel), _classNames)),
|
339
352
|
disabled: disabled
|
340
353
|
}, disabled || {
|
341
354
|
onClick: onSelect,
|
342
355
|
onMouseEnter: this.setHover(true),
|
343
356
|
onMouseLeave: this.setHover(false),
|
344
|
-
onKeyDown:
|
345
|
-
onKeyUp: onKeyUp
|
357
|
+
onKeyDown: this.handleKeyDown(item)
|
346
358
|
}, {
|
347
359
|
style: {
|
348
360
|
paddingLeft: "".concat(paddingLeft + level * 32, "px")
|
@@ -350,7 +362,7 @@ function (_React$PureComponent) {
|
|
350
362
|
}), _react.default.createElement("div", {
|
351
363
|
className: (0, _classnames.default)(classes.labelContent, (0, _defineProperty2.default)({}, classes.labelWithoutSecondaryInline, !secondaryInline || !secondaryLabel && !info))
|
352
364
|
}, !hideCheckbox && !pinned && _react.default.createElement(_HiCheckbox.default, {
|
353
|
-
tabIndex:
|
365
|
+
tabIndex: 0,
|
354
366
|
classes: {
|
355
367
|
root: !secondaryInline ? classes.checkboxWithSecondaryInline : classes.checkbox
|
356
368
|
},
|
package/README.md
CHANGED
@@ -78,6 +78,18 @@ https://reactjs.org/docs/reconciliation.html
|
|
78
78
|
- Attention aux refs et aux mutations
|
79
79
|
ex: ne pas passer une arrow fonction directement dans les props d'un composant. Même pour y inclure un index ou une valeur contextuelle !
|
80
80
|
|
81
|
+
#### Gestion des événements clavier
|
82
|
+
|
83
|
+
- **Evénement capturé** : on part sur le _KeyDown_, c'est le seul à capturer toutes les touches du clavier ([source](https://www.w3schools.com/jsref/event_onkeypress.asp))
|
84
|
+
|
85
|
+
- **Capturing** : il s'agit de la première phase par laquelle passe un événement lors de sa capture, durant celle-ci, il descend dans l’arborescence HTML en partant de l'élément racine (en React : Parent => Enfant, on peut le capturer avec _onKeyDownCapture_)
|
86
|
+
|
87
|
+
- **Bubbling** : c'est la deuxième phase par laquelle passe un événement et celle capturée par défaut lorsque l'on fait un _onKeyDown_. A ce moment, l'événement remonte vers l'élément HTML racine (en React : Enfant => Parent)
|
88
|
+
|
89
|
+
- **PreventDefault** : on l'utilisera à chaque fois qu'il faudra éviter un comportement par défaut du navigateur.
|
90
|
+
|
91
|
+
- **StopPropagation** : il permet de stopper la capture dès qu'il est appelé. Couplé au Capturing on peut, par exemple, éviter qu'un événement soit capturé dans un composant enfant.
|
92
|
+
|
81
93
|
## Contribuer
|
82
94
|
|
83
95
|
#### A savoir
|
@@ -300,3 +312,6 @@ au lieu de
|
|
300
312
|
Attention aux index.js.
|
301
313
|
La bonne syntaxe est :
|
302
314
|
export { default as MyComponente } from './MyComponente';
|
315
|
+
|
316
|
+
|
317
|
+
[source]: https://www.w3schools.com/jsref/event_onkeypress.asp
|
@@ -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) {
|
@@ -198,11 +209,12 @@ class HiDatePicker extends React.Component {
|
|
198
209
|
const {
|
199
210
|
currentMonth
|
200
211
|
} = this.state;
|
212
|
+
const today = moment().tz(this.props.timezoneName);
|
201
213
|
|
202
214
|
const effectiveDisabledDays = _objectSpread({}, disablePastDays && {
|
203
|
-
before: new Date()
|
215
|
+
before: new Date(today.year(), today.month(), today.date(), today.hours(), today.minutes(), today.seconds(), today.milliseconds())
|
204
216
|
}, disableFutureDays && {
|
205
|
-
after: new Date()
|
217
|
+
after: new Date(today.year(), today.month(), today.date(), today.hours(), today.minutes(), today.seconds(), today.milliseconds())
|
206
218
|
}, disabledDays);
|
207
219
|
|
208
220
|
const modifiersStyles = {
|
@@ -229,7 +241,8 @@ class HiDatePicker extends React.Component {
|
|
229
241
|
fromMonth: minimumDate,
|
230
242
|
modifiers: {
|
231
243
|
disabled: effectiveDisabledDays,
|
232
|
-
selected: value
|
244
|
+
selected: value,
|
245
|
+
[classes.currentDay]: new Date(today.year(), today.month(), today.date(), today.hours(), today.minutes(), today.seconds(), today.milliseconds())
|
233
246
|
},
|
234
247
|
modifiersStyles,
|
235
248
|
month: currentMonth
|
@@ -248,7 +261,8 @@ class HiDatePicker extends React.Component {
|
|
248
261
|
});
|
249
262
|
|
250
263
|
return React.createElement("div", {
|
251
|
-
className: classes.root
|
264
|
+
className: classes.root,
|
265
|
+
onKeyDown: this.handleKeyDown()
|
252
266
|
}, React.createElement(DayPickerInput, {
|
253
267
|
ref: el => {
|
254
268
|
this.datePickerInput = el;
|
@@ -279,6 +293,7 @@ HiDatePicker.defaultProps = {
|
|
279
293
|
locale: 'fr-FR',
|
280
294
|
minimumDate: new Date(2013, 4, 1),
|
281
295
|
// by default 1 May 2013
|
296
|
+
timezoneName: 'Europe/Paris',
|
282
297
|
translations: {
|
283
298
|
today: 'today'
|
284
299
|
}
|
@@ -347,6 +362,11 @@ HiDatePicker.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
347
362
|
*/
|
348
363
|
onSubmit: PropTypes.func,
|
349
364
|
|
365
|
+
/**
|
366
|
+
* Timezone de l'utilisateur
|
367
|
+
*/
|
368
|
+
timezoneName: PropTypes.string,
|
369
|
+
|
350
370
|
/**
|
351
371
|
* Traductions
|
352
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,15 +169,11 @@ class HiDateRangePicker extends React.Component {
|
|
165
169
|
|
166
170
|
this.handleReset = name => {
|
167
171
|
this.handleChange(name, undefined);
|
168
|
-
this.setState(prevState => ({
|
169
|
-
keyFrom: prevState.keyFrom === 1 ? 2 : 1,
|
170
|
-
keyTo: prevState.keyTo === 1 ? 2 : 1
|
171
|
-
}));
|
172
172
|
};
|
173
173
|
|
174
174
|
this.handleKeyDown = name => event => {
|
175
175
|
if (event.key === 'Tab' && !event.shiftKey) {
|
176
|
-
|
176
|
+
const nodeName = document.activeElement.nodeName;
|
177
177
|
|
178
178
|
if (this.props[name] && nodeName === 'INPUT' && document.activeElement.nextSibling.children.length > 0) {
|
179
179
|
document.activeElement.nextSibling.focus();
|
@@ -191,6 +191,14 @@ class HiDateRangePicker extends React.Component {
|
|
191
191
|
document.activeElement.blur();
|
192
192
|
}, 1);
|
193
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();
|
194
202
|
}
|
195
203
|
};
|
196
204
|
|
@@ -276,12 +284,12 @@ class HiDateRangePicker extends React.Component {
|
|
276
284
|
}, yearPickerProps, propsOverlay));
|
277
285
|
};
|
278
286
|
|
287
|
+
const _today = moment().tz(this.props.timezoneName);
|
288
|
+
|
279
289
|
this.state = {
|
280
|
-
currentMonth: new Date(),
|
290
|
+
currentMonth: new Date(_today.year(), _today.month(), _today.date()),
|
281
291
|
focusedInput: '',
|
282
|
-
openedPanel: 'calendar'
|
283
|
-
keyFrom: 1,
|
284
|
-
keyTo: 1
|
292
|
+
openedPanel: 'calendar'
|
285
293
|
};
|
286
294
|
}
|
287
295
|
|
@@ -313,14 +321,17 @@ class HiDateRangePicker extends React.Component {
|
|
313
321
|
errorText,
|
314
322
|
hasSelector,
|
315
323
|
helperIcon,
|
316
|
-
helperText
|
324
|
+
helperText,
|
325
|
+
timezoneName
|
317
326
|
} = _this$props,
|
318
|
-
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"]);
|
319
328
|
|
320
|
-
const
|
329
|
+
const today = moment().tz(timezoneName);
|
330
|
+
const now = new Date(today.year(), today.month(), today.date(), 23, 59, 59, 999);
|
321
331
|
const modifiers = {
|
322
332
|
start: from,
|
323
|
-
end: to
|
333
|
+
end: to,
|
334
|
+
[classes.currentDay]: new Date(today.year(), today.month(), today.date())
|
324
335
|
};
|
325
336
|
const modifiersStyles = {
|
326
337
|
start: {
|
@@ -440,7 +451,7 @@ class HiDateRangePicker extends React.Component {
|
|
440
451
|
onFocus: () => this.handleDayPickerFocus('from'),
|
441
452
|
onKeyDown: this.handleKeyDown('from')
|
442
453
|
}, React.createElement("div", null, React.createElement(DayPickerInput, {
|
443
|
-
key:
|
454
|
+
key: '1',
|
444
455
|
ref: el => {
|
445
456
|
this.fromInput = el;
|
446
457
|
},
|
@@ -461,7 +472,7 @@ class HiDateRangePicker extends React.Component {
|
|
461
472
|
onBlur: () => this.handleDayPickerBlur('to'),
|
462
473
|
onKeyDown: this.handleKeyDown('to')
|
463
474
|
}, React.createElement(DayPickerInput, {
|
464
|
-
key:
|
475
|
+
key: '1',
|
465
476
|
ref: el => {
|
466
477
|
this.toInput = el;
|
467
478
|
},
|
@@ -505,6 +516,7 @@ HiDateRangePicker.defaultProps = {
|
|
505
516
|
locale: 'fr-FR',
|
506
517
|
minimumDate: new Date(2013, 4, 1),
|
507
518
|
// by default 1 May 2013
|
519
|
+
timezoneName: 'Europe/Paris',
|
508
520
|
translations: {
|
509
521
|
today: 'today',
|
510
522
|
hour: 'Hour',
|
@@ -636,6 +648,11 @@ HiDateRangePicker.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
636
648
|
*/
|
637
649
|
staticPosition: PropTypes.bool,
|
638
650
|
|
651
|
+
/**
|
652
|
+
* Timezone de l'utilisateur
|
653
|
+
*/
|
654
|
+
timezoneName: PropTypes.string,
|
655
|
+
|
639
656
|
/**
|
640
657
|
* Date de fin sélectionnée
|
641
658
|
*/
|
@@ -6,7 +6,7 @@ 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';
|
9
|
-
import HiSelectField from '../
|
9
|
+
import HiSelectField from '../HiSelect/HiSelectField';
|
10
10
|
import HiDateRangePicker from './HiDateRangePicker';
|
11
11
|
import HiFormControl from '../HiForm/HiFormControl';
|
12
12
|
export function findSeparator(format) {
|
@@ -187,18 +187,7 @@ 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', new Date(selectedOption.from.format('YYYY-MM-DD HH:mm:ss')));
|
194
|
-
this.props.onChange('to', new Date(selectedOption.to.format('YYYY-MM-DD HH:mm:ss')));
|
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
193
|
this.options = props.availableOptionKeys.map(key => buildDateRangeOptionByKey(key, props.translations, props.format, props.timezoneName));
|
@@ -226,10 +215,32 @@ class HiDateRangeSelector extends React.Component {
|
|
226
215
|
}
|
227
216
|
}
|
228
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
|
+
|
229
225
|
componentWillUnmount() {
|
230
226
|
clearTimeout(this.timeout); // TODO : supprimer ?
|
231
227
|
}
|
232
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
|
+
|
233
244
|
render() {
|
234
245
|
const _this$props = this.props,
|
235
246
|
{
|