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

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.
Files changed (41) hide show
  1. package/HiCell/CellSentinel.js +33 -109
  2. package/HiCell/CellSentinelScore.js +100 -0
  3. package/HiChip/HiChip.js +11 -4
  4. package/HiColoredLabel/HiColoredLabel.js +14 -4
  5. package/HiDatePicker/HiDatePicker.js +1 -1
  6. package/HiDatePicker/HiDateRangePicker.js +339 -420
  7. package/HiDatePicker/HiDateRangeSelector.js +81 -61
  8. package/HiDatePicker/NavBar.js +2 -1
  9. package/HiDatePicker/Overlays/TimePickerOverlay.js +1 -1
  10. package/HiDatePicker/Overlays/YearPickerOverlay.js +3 -3
  11. package/HiForm/HiFormControl.js +5 -4
  12. package/HiPin/HiPin.js +1 -1
  13. package/HiSelectNew/HiSelect.js +4 -1
  14. package/HiSelectableList/HiSelectableListItem.js +9 -1
  15. package/HiSwitch/HiSwitch.js +2 -1
  16. package/HiTable/HiCellBuilder.js +14 -7
  17. package/HiTable/constants.js +7 -5
  18. package/es/HiCell/CellSentinel.js +32 -108
  19. package/es/HiCell/CellSentinelScore.js +60 -0
  20. package/es/HiChip/HiChip.js +11 -4
  21. package/es/HiColoredLabel/HiColoredLabel.js +14 -3
  22. package/es/HiDatePicker/HiDatePicker.js +1 -1
  23. package/es/HiDatePicker/HiDateRangePicker.js +304 -364
  24. package/es/HiDatePicker/HiDateRangeSelector.js +71 -55
  25. package/es/HiDatePicker/NavBar.js +2 -1
  26. package/es/HiDatePicker/Overlays/TimePickerOverlay.js +1 -1
  27. package/es/HiDatePicker/Overlays/YearPickerOverlay.js +3 -3
  28. package/es/HiForm/HiFormControl.js +5 -4
  29. package/es/HiPin/HiPin.js +1 -1
  30. package/es/HiSelectNew/HiSelect.js +4 -1
  31. package/es/HiSelectableList/HiSelectableListItem.js +9 -1
  32. package/es/HiSwitch/HiSwitch.js +2 -1
  33. package/es/HiTable/HiCellBuilder.js +13 -7
  34. package/es/HiTable/constants.js +8 -1
  35. package/es/styles/createPalette.js +3 -3
  36. package/index.es.js +1 -1
  37. package/index.js +1 -1
  38. package/package.json +3 -2
  39. package/styles/createPalette.js +3 -3
  40. package/umd/hipay-material-ui.development.js +919 -1136
  41. package/umd/hipay-material-ui.production.min.js +2 -2
@@ -7,12 +7,12 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.default = void 0;
9
9
 
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
10
12
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
11
13
 
12
14
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
15
 
14
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
15
-
16
16
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
17
17
 
18
18
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
@@ -23,8 +23,6 @@ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/ge
23
23
 
24
24
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
25
25
 
26
- var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
27
-
28
26
  var _react = _interopRequireDefault(require("react"));
29
27
 
30
28
  var _propTypes = _interopRequireDefault(require("prop-types"));
@@ -37,8 +35,6 @@ var _classnames = _interopRequireDefault(require("classnames"));
37
35
 
38
36
  var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
39
37
 
40
- var _helpers = require("../utils/helpers");
41
-
42
38
  var _Caption = _interopRequireDefault(require("./Caption"));
43
39
 
44
40
  var _Overlay = _interopRequireDefault(require("./Overlays/Overlay"));
@@ -57,6 +53,10 @@ var _HiForm = require("../HiForm");
57
53
 
58
54
  var _stylesheet = _interopRequireDefault(require("./stylesheet"));
59
55
 
56
+ var _moment2 = _interopRequireDefault(require("moment"));
57
+
58
+ var _HiFormControl = _interopRequireDefault(require("../HiForm/HiFormControl"));
59
+
60
60
  var HiDateRangePicker =
61
61
  /*#__PURE__*/
62
62
  function (_React$Component) {
@@ -68,399 +68,287 @@ function (_React$Component) {
68
68
  (0, _classCallCheck2.default)(this, HiDateRangePicker);
69
69
  _this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(HiDateRangePicker).call(this));
70
70
 
71
- _this.handleInputChange = function (inputName) {
72
- return function (event) {
73
- _this.event = event;
71
+ _this.handleDayChange = function (name, day) {
72
+ if (day) {
73
+ // if time disabled, focus TO input
74
+ // else focus current input
75
+ if (!_this.props.enableTime) {
76
+ if (day instanceof Date) {
77
+ if (name === 'from' && _this.toInput) {
78
+ _this.toInput.getInput().focus();
79
+ }
80
+ }
81
+ } else {
82
+ _this.timeout = setTimeout(function () {
83
+ if (_this["".concat(name, "Input")].getInput()) {
84
+ _this["".concat(name, "Input")].getInput().focus();
85
+ }
86
+ }, 10);
87
+ }
74
88
 
75
- _this.props.onChange(inputName, event.target.value);
76
- };
89
+ if (_this.props.onChange) {
90
+ _this.handleChange(name, day);
91
+ }
92
+
93
+ if (_this.props.enableTime) {
94
+ _this.openPanel('time');
95
+ }
96
+ }
77
97
  };
78
98
 
79
- _this.handleDayPickerFocus = function (name) {
80
- return function () {
81
- _this.setState({
82
- focusedInput: name
83
- });
99
+ _this.handleInputChange = function (inputName) {
100
+ return function (event) {
101
+ _this.handleChange(inputName, event.target.value);
84
102
  };
85
103
  };
86
104
 
87
- _this.handleDayPickerBlur = function (name) {
88
- return function () {
89
- _this.setState({
90
- focusedInput: ''
91
- });
105
+ _this.onDayToClick = function (day) {
106
+ _this.handleDayChange('to', day);
92
107
 
93
- if (_this.props.onBlur) {
94
- _this.props.onBlur(name);
95
- }
96
- };
108
+ document.activeElement.blur();
97
109
  };
98
110
 
99
- _this.state = {
100
- fromCurrentMonth: props.from ? props.from : new Date(),
101
- toCurrentMonth: props.to ? props.to : new Date(),
102
- focusedInput: ''
103
- };
104
- _this.handleReset = _this.handleReset.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
105
- _this.handleDayChange = _this.handleDayChange.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
106
- _this.handleDayChangeFrom = _this.handleDayChangeFrom.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
107
- _this.handleDayChangeTo = _this.handleDayChangeTo.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
108
- _this.handleCurrentMonthChange = _this.handleCurrentMonthChange.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
109
- _this.handleCurrentMonthChangeFrom = _this.handleCurrentMonthChangeFrom.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
110
- _this.handleCurrentMonthChangeTo = _this.handleCurrentMonthChangeTo.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
111
- _this.handleTimeChange = _this.handleTimeChange.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
112
- _this.handleCalendarClick = _this.handleCalendarClick.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
113
- _this.handleCalendarClickFrom = _this.handleCalendarClickFrom.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
114
- _this.handleCalendarClickTo = _this.handleCalendarClickTo.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
115
- _this.handleClockClick = _this.handleClockClick.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
116
- _this.handleClockClickFrom = _this.handleClockClickFrom.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
117
- _this.handleClockClickTo = _this.handleClockClickTo.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
118
- _this.handleMonthClick = _this.handleMonthClick.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
119
- _this.handleMonthClickFrom = _this.handleMonthClickFrom.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
120
- _this.handleMonthClickTo = _this.handleMonthClickTo.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
121
- _this.handleYearClick = _this.handleYearClick.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
122
- _this.handleYearClickFrom = _this.handleYearClickFrom.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
123
- _this.handleYearClickTo = _this.handleYearClickTo.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
124
- _this.handleDayPickerFocus = _this.handleDayPickerFocus.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
125
- _this.handleDayPickerBlur = _this.handleDayPickerBlur.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
126
- _this.handleInputChange = _this.handleInputChange.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
127
- _this.openPanel = _this.openPanel.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
128
- _this.renderCaption = _this.renderCaption.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
129
- _this.renderCaptionFrom = _this.renderCaptionFrom.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
130
- _this.renderCaptionTo = _this.renderCaptionTo.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
131
- _this.renderNavBar = _this.renderNavBar.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
132
- _this.renderNavBarFrom = _this.renderNavBarFrom.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
133
- _this.renderNavBarTo = _this.renderNavBarTo.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
134
- _this.renderOverlay = _this.renderOverlay.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
135
- _this.renderOverlayFrom = _this.renderOverlayFrom.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
136
- _this.renderOverlayTo = _this.renderOverlayTo.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
137
- _this.renderMonthPickerOverlay = _this.renderMonthPickerOverlay.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
138
- _this.renderTimePickerOverlay = _this.renderTimePickerOverlay.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
139
- _this.renderYearPickerOverlay = _this.renderYearPickerOverlay.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
140
- return _this;
141
- }
111
+ _this.handleTimeChange = function (name, date, precision) {
112
+ _this.handleChange(name, date);
142
113
 
143
- (0, _createClass2.default)(HiDateRangePicker, [{
144
- key: "componentDidUpdate",
145
- value: function componentDidUpdate(prevProps) {
146
- var _this2 = this;
147
-
148
- // Focus From input on enabling
149
- if (prevProps.disabled === true && this.props.disabled === false) {
150
- this.timeout = setTimeout(function () {
151
- if (_this2.fromInput.getInput()) {
152
- _this2.fromInput.getInput().focus();
153
- }
154
- }, 0);
114
+ if (name === 'from' && precision === 'minute') {
115
+ _this.fromInput.hideDayPicker();
116
+
117
+ _this.toInput.getInput().focus();
118
+
119
+ _this.toInput.showDayPicker();
120
+
121
+ _this.openPanel('calendar');
122
+ } else if (name === 'to' && precision === 'minute') {
123
+ _this.toInput.hideDayPicker();
124
+
125
+ document.activeElement.blur();
155
126
  }
156
- }
157
- }, {
158
- key: "componentWillUnmount",
159
- value: function componentWillUnmount() {
160
- clearTimeout(this.timeout);
161
- }
162
- }, {
163
- key: "handleDayChange",
164
- value: function handleDayChange(name, day, modifiers) {
165
- var _this3 = this;
127
+ };
166
128
 
167
- if (day) {
168
- // if time disabled, focus TO input
169
- // else focus current input
170
- if (!this.props.enableTime) {
171
- if (day instanceof Date) {
172
- if (name === 'from' && this.toInput) {
173
- this.toInput.getInput().focus();
174
- } else if (name === 'to') {
175
- if (typeof this.event === 'undefined' || this.event && this.event.type !== 'change') {
176
- // trigger blur only if user clicks on date into calendar
177
- // else keep focus to see day selection into calendar
178
- document.activeElement.blur();
179
- }
180
-
181
- delete this.event;
182
- }
183
- }
129
+ _this.handleChange = function (name, day) {
130
+ var translations = _this.props.translations;
131
+ var date = undefined;
132
+ var error = undefined;
133
+ var now = new Date();
134
+ var _this$props = _this.props,
135
+ minimumDate = _this$props.minimumDate,
136
+ disableFutureDays = _this$props.disableFutureDays,
137
+ format = _this$props.format;
138
+
139
+ if (day instanceof Date) {
140
+ date = day;
141
+ } else if (day) {
142
+ var parsedValue = (0, _moment2.default)(day, _this.props.format, true);
143
+
144
+ if (parsedValue.isValid()) {
145
+ date = parsedValue.toDate();
184
146
  } else {
185
- this.timeout = setTimeout(function () {
186
- if (_this3["".concat(name, "Input")].getInput()) {
187
- _this3["".concat(name, "Input")].getInput().focus();
188
- }
189
- }, 10);
147
+ error = translations.invalid_format;
190
148
  }
149
+ }
191
150
 
192
- if (this.props.onChange) {
193
- // Keep Time if set
194
- if (this.props.enableTime) {
195
- if (this.props[name]) {
196
- day.setHours(this.props[name].getHours(), this.props[name].getMinutes());
197
- } else {
198
- day.setHours(0, 0);
199
- }
200
- }
151
+ if (date) {
152
+ var comparativeDate = name === 'to' ? (0, _moment2.default)(_this.props.from) : (0, _moment2.default)(_this.props.to);
201
153
 
202
- this.props.onChange(name, day);
154
+ if (name === 'to' && comparativeDate > (0, _moment2.default)(date) || name === 'from' && comparativeDate < (0, _moment2.default)(date)) {
155
+ error = translations.to_superior_from;
156
+ } else if (date < minimumDate) {
157
+ error = translations.date_inferior_min_date.replace("%s", (0, _moment2.default)(minimumDate).format(format));
158
+ } else if (disableFutureDays && date > now) {
159
+ error = translations.date_superior_max_date.replace("%s", (0, _moment2.default)().format(format));
203
160
  }
204
161
 
205
- if (this.props.enableTime) {
206
- this.openPanel(name, 'time');
162
+ if (!_this.props.enableTime) {
163
+ if (name === 'from') {
164
+ date.setHours(0, 0);
165
+ } else {
166
+ date.setHours(23, 59);
167
+ }
207
168
  }
208
169
  }
209
- }
210
- }, {
211
- key: "handleDayChangeFrom",
212
- value: function handleDayChangeFrom(day, modifiers) {
213
- this.handleDayChange('from', day, modifiers);
214
- }
215
- }, {
216
- key: "handleDayChangeTo",
217
- value: function handleDayChangeTo(day, modifiers) {
218
- this.handleDayChange('to', day, modifiers);
219
- }
220
- }, {
221
- key: "handleCurrentMonthChange",
222
- value: function handleCurrentMonthChange(name, day) {
223
- var _this$setState;
224
170
 
225
- this.setState((_this$setState = {}, (0, _defineProperty2.default)(_this$setState, "".concat(name, "CurrentMonth"), day), (0, _defineProperty2.default)(_this$setState, "".concat(name, "OpenedPanel"), 'calendar'), _this$setState));
226
- }
227
- }, {
228
- key: "handleCurrentMonthChangeFrom",
229
- value: function handleCurrentMonthChangeFrom(day) {
230
- this.handleCurrentMonthChange('from', day);
231
- }
232
- }, {
233
- key: "handleCurrentMonthChangeTo",
234
- value: function handleCurrentMonthChangeTo(day) {
235
- this.handleCurrentMonthChange('to', day);
236
- }
237
- }, {
238
- key: "handleCalendarClick",
239
- value: function handleCalendarClick(name) {
240
- this.openPanel(name, 'calendar');
241
- }
242
- }, {
243
- key: "handleCalendarClickFrom",
244
- value: function handleCalendarClickFrom() {
245
- this.handleCalendarClick('from');
246
- }
247
- }, {
248
- key: "handleCalendarClickTo",
249
- value: function handleCalendarClickTo() {
250
- this.handleCalendarClick('to');
251
- }
252
- }, {
253
- key: "handleClockClick",
254
- value: function handleClockClick(name) {
255
- this.openPanel(name, 'time');
256
- }
257
- }, {
258
- key: "handleClockClickFrom",
259
- value: function handleClockClickFrom() {
260
- this.handleClockClick('from');
261
- }
262
- }, {
263
- key: "handleClockClickTo",
264
- value: function handleClockClickTo() {
265
- this.handleClockClick('to');
266
- }
267
- }, {
268
- key: "handleMonthClick",
269
- value: function handleMonthClick(name) {
270
- this.openPanel(name, 'months');
271
- }
272
- }, {
273
- key: "handleMonthClickFrom",
274
- value: function handleMonthClickFrom() {
275
- this.handleMonthClick('from');
276
- }
277
- }, {
278
- key: "handleMonthClickTo",
279
- value: function handleMonthClickTo() {
280
- this.handleMonthClick('to');
281
- }
282
- }, {
283
- key: "handleYearClick",
284
- value: function handleYearClick(name) {
285
- this.openPanel(name, 'years');
286
- }
287
- }, {
288
- key: "handleYearClickFrom",
289
- value: function handleYearClickFrom() {
290
- this.handleYearClick('from');
291
- }
292
- }, {
293
- key: "handleYearClickTo",
294
- value: function handleYearClickTo() {
295
- this.handleYearClick('to');
296
- }
297
- }, {
298
- key: "handleTimeChange",
299
- value: function handleTimeChange(name, date, precision) {
300
- this.props.onChange(name, date);
171
+ _this.props.onChange(name, date);
301
172
 
302
- if (name === 'from' && precision === 'minute') {
303
- this.fromInput.hideDayPicker();
304
- this.toInput.getInput().focus();
305
- this.toInput.showDayPicker();
306
- } else if (name === 'to' && precision === 'minute') {
307
- this.toInput.hideDayPicker();
308
- document.activeElement.blur();
173
+ _this.props.onChange("".concat(name, "Error"), error);
174
+ };
175
+
176
+ _this.handleCurrentMonthChange = function (day) {
177
+ _this.setState({
178
+ currentMonth: day,
179
+ openedPanel: 'calendar'
180
+ });
181
+ };
182
+
183
+ _this.handleDayPickerFocus = function (name) {
184
+ _this.setState({
185
+ focusedInput: name
186
+ });
187
+ };
188
+
189
+ _this.handleDayPickerBlur = function (name) {
190
+ _this.setState({
191
+ focusedInput: ''
192
+ });
193
+
194
+ if (_this.props.onBlur) {
195
+ _this.props.onBlur(name);
309
196
  }
310
- }
311
- }, {
312
- key: "handleReset",
313
- value: function handleReset(name) {
314
- var _this4 = this;
315
-
316
- this.handleCurrentMonthChange(name, new Date());
317
- this.timeout = setTimeout(function () {
318
- if (_this4.props.onReset) {
319
- _this4.props.onReset(name);
197
+
198
+ _this.timeout = setTimeout(function () {
199
+ if (!['from', 'to'].includes(_this.state.focusedInput)) {
200
+ _this.setState({
201
+ openedPanel: 'calendar'
202
+ });
320
203
  }
321
- }, 0);
322
- }
323
- }, {
324
- key: "openPanel",
325
- value: function openPanel(name, panel) {
326
- this.setState((0, _defineProperty2.default)({}, "".concat(name, "OpenedPanel"), panel));
327
- }
328
- }, {
329
- key: "renderCaption",
330
- value: function renderCaption(name, propsCaption) {
204
+ }, 100);
205
+ };
206
+
207
+ _this.handleReset = function (name) {
208
+ _this.handleChange(name, undefined);
209
+
210
+ _this.setState({
211
+ keyFrom: _this.state.keyFrom === 1 ? 2 : 1,
212
+ keyTo: _this.state.keyTo === 1 ? 2 : 1
213
+ });
214
+ };
215
+
216
+ _this.openPanel = function (panel) {
217
+ _this.setState({
218
+ openedPanel: panel
219
+ });
220
+ };
221
+
222
+ _this.renderCaption = function (propsCaption) {
331
223
  return _react.default.createElement(_Caption.default, (0, _extends2.default)({
332
- onMonthClick: this["handleMonthClick".concat((0, _helpers.capitalize)(name))],
333
- onYearClick: this["handleYearClick".concat((0, _helpers.capitalize)(name))]
224
+ onMonthClick: function onMonthClick() {
225
+ return _this.openPanel('months');
226
+ },
227
+ onYearClick: function onYearClick() {
228
+ return _this.openPanel('years');
229
+ }
334
230
  }, propsCaption));
335
- }
336
- }, {
337
- key: "renderCaptionFrom",
338
- value: function renderCaptionFrom(propsCaption) {
339
- return this.renderCaption('from', propsCaption);
340
- }
341
- }, {
342
- key: "renderCaptionTo",
343
- value: function renderCaptionTo(propsCaption) {
344
- return this.renderCaption('to', propsCaption);
345
- }
346
- }, {
347
- key: "renderNavBar",
348
- value: function renderNavBar(name, propsNavBar) {
231
+ };
232
+
233
+ _this.renderNavBar = function (propsNavBar) {
349
234
  return _react.default.createElement(_NavBar.default, (0, _extends2.default)({
350
- showClockButton: this.props.enableTime,
351
- onClockClick: this["handleClockClick".concat((0, _helpers.capitalize)(name))]
235
+ showClockButton: _this.props.enableTime,
236
+ onClockClick: function onClockClick() {
237
+ return _this.openPanel('time');
238
+ }
352
239
  }, propsNavBar));
353
- }
354
- }, {
355
- key: "renderNavBarFrom",
356
- value: function renderNavBarFrom(propsNavBar) {
357
- return this.renderNavBar('from', propsNavBar);
358
- }
359
- }, {
360
- key: "renderNavBarTo",
361
- value: function renderNavBarTo(propsNavBar) {
362
- return this.renderNavBar('to', propsNavBar);
363
- }
364
- }, {
365
- key: "renderOverlay",
366
- value: function renderOverlay(name, propsOverlay, staticPosition) {
240
+ };
241
+
242
+ _this.renderOverlay = function (name, propsOverlay, staticPosition) {
367
243
  var rangeOverlayProps = (0, _extends2.default)({}, propsOverlay, {
368
244
  side: name,
369
245
  staticPosition: staticPosition
370
246
  });
371
247
 
372
- switch (this.state["".concat(name, "OpenedPanel")]) {
248
+ switch (_this.state['openedPanel']) {
373
249
  case 'time':
374
- return this.renderTimePickerOverlay(name, rangeOverlayProps);
250
+ return _this.renderTimePickerOverlay(name, rangeOverlayProps);
375
251
 
376
252
  case 'months':
377
- return this.renderMonthPickerOverlay(name, rangeOverlayProps);
253
+ return _this.renderMonthPickerOverlay(name, rangeOverlayProps);
378
254
 
379
255
  case 'years':
380
- return this.renderYearPickerOverlay(name, rangeOverlayProps);
256
+ return _this.renderYearPickerOverlay(name, rangeOverlayProps);
381
257
 
382
258
  case 'calendar':
383
- default:
384
259
  return _react.default.createElement(_Overlay.default, rangeOverlayProps);
385
260
  }
386
- }
387
- }, {
388
- key: "renderOverlayFrom",
389
- value: function renderOverlayFrom(propsOverlay) {
390
- return this.renderOverlay('from', propsOverlay, this.props.staticPosition);
391
- }
392
- }, {
393
- key: "renderOverlayTo",
394
- value: function renderOverlayTo(propsOverlay) {
395
- return this.renderOverlay('to', propsOverlay, this.props.staticPosition);
396
- }
397
- }, {
398
- key: "renderMonthPickerOverlay",
399
- value: function renderMonthPickerOverlay(name, propsOverlay) {
261
+ };
262
+
263
+ _this.renderOverlayFrom = function (propsOverlay) {
264
+ return _this.renderOverlay('from', propsOverlay, _this.props.staticPosition);
265
+ };
266
+
267
+ _this.renderOverlayTo = function (propsOverlay) {
268
+ return _this.renderOverlay('to', propsOverlay, _this.props.staticPosition);
269
+ };
270
+
271
+ _this.renderMonthPickerOverlay = function (name, propsOverlay) {
400
272
  var monthPickerProps = {
401
- value: this.state["".concat(name, "CurrentMonth")],
402
- onChange: this["handleCurrentMonthChange".concat((0, _helpers.capitalize)(name))]
273
+ value: _this.state['currentMonth'],
274
+ onChange: _this.handleCurrentMonthChange
403
275
  };
404
276
  return _react.default.createElement(_MonthPickerOverlay.default, (0, _extends2.default)({
405
277
  key: "".concat(name, "-month-picker-overlay")
406
278
  }, monthPickerProps, propsOverlay));
407
- }
408
- }, {
409
- key: "renderTimePickerOverlay",
410
- value: function renderTimePickerOverlay(name, propsOverlay) {
411
- var _this5 = this;
279
+ };
412
280
 
281
+ _this.renderTimePickerOverlay = function (name, propsOverlay) {
413
282
  var timePickerProps = {
414
- value: this.props[name],
283
+ value: _this.props[name],
415
284
  onChange: function onChange(date, precision) {
416
- return _this5.handleTimeChange(name, date, precision);
285
+ return _this.handleTimeChange(name, date, precision);
417
286
  },
418
- onCalendarClick: this["handleCalendarClick".concat((0, _helpers.capitalize)(name))]
287
+ onCalendarClick: function onCalendarClick() {
288
+ return _this.openPanel('calendar');
289
+ }
419
290
  };
420
291
  return _react.default.createElement(_TimePickerOverlay.default, (0, _extends2.default)({
421
292
  key: "".concat(name, "-time-picker-overlay")
422
293
  }, timePickerProps, propsOverlay));
423
- }
424
- }, {
425
- key: "renderYearPickerOverlay",
426
- value: function renderYearPickerOverlay(name, propsOverlay) {
294
+ };
295
+
296
+ _this.renderYearPickerOverlay = function (name, propsOverlay) {
427
297
  var yearPickerProps = {
428
- value: this.state["".concat(name, "CurrentMonth")],
429
- onChange: this["handleCurrentMonthChange".concat((0, _helpers.capitalize)(name))],
430
- disabledFutureDays: this.props.disableFutureDays,
431
- disabledPastDays: this.props.disablePastDays
298
+ value: _this.state['currentMonth'],
299
+ onChange: _this.handleCurrentMonthChange,
300
+ disabledFutureDays: _this.props.disableFutureDays
432
301
  };
433
302
  return _react.default.createElement(_YearPickerOverlay.default, (0, _extends2.default)({
434
303
  key: "".concat(name, "-year-picker-overlay")
435
304
  }, yearPickerProps, propsOverlay));
305
+ };
306
+
307
+ _this.state = {
308
+ currentMonth: new Date(),
309
+ focusedInput: '',
310
+ openedPanel: 'calendar',
311
+ keyFrom: 1,
312
+ keyTo: 1
313
+ };
314
+ return _this;
315
+ }
316
+
317
+ (0, _createClass2.default)(HiDateRangePicker, [{
318
+ key: "componentWillUnmount",
319
+ value: function componentWillUnmount() {
320
+ clearTimeout(this.timeout);
436
321
  }
437
322
  }, {
438
323
  key: "render",
439
324
  value: function render() {
440
- var _this6 = this,
325
+ var _this2 = this,
441
326
  _classNames;
442
327
 
443
- var _this$props = this.props,
444
- classes = _this$props.classes,
445
- disabledDays = _this$props.disabledDays,
446
- disablePastDays = _this$props.disablePastDays,
447
- disableFutureDays = _this$props.disableFutureDays,
448
- enableTime = _this$props.enableTime,
449
- labelFrom = _this$props.labelFrom,
450
- labelTo = _this$props.labelTo,
451
- locale = _this$props.locale,
452
- format = _this$props.format,
453
- from = _this$props.from,
454
- minimumDate = _this$props.minimumDate,
455
- onReset = _this$props.onReset,
456
- to = _this$props.to,
457
- translations = _this$props.translations,
458
- id = _this$props.id,
459
- staticPosition = _this$props.staticPosition,
460
- props = (0, _objectWithoutProperties2.default)(_this$props, ["classes", "disabledDays", "disablePastDays", "disableFutureDays", "enableTime", "labelFrom", "labelTo", "locale", "format", "from", "minimumDate", "onReset", "to", "translations", "id", "staticPosition"]);
461
- var _this$state = this.state,
462
- fromCurrentMonth = _this$state.fromCurrentMonth,
463
- toCurrentMonth = _this$state.toCurrentMonth;
328
+ var _this$props2 = this.props,
329
+ classes = _this$props2.classes,
330
+ disabled = _this$props2.disabled,
331
+ disabledDays = _this$props2.disabledDays,
332
+ disableFutureDays = _this$props2.disableFutureDays,
333
+ enableTime = _this$props2.enableTime,
334
+ labelFrom = _this$props2.labelFrom,
335
+ labelTo = _this$props2.labelTo,
336
+ locale = _this$props2.locale,
337
+ format = _this$props2.format,
338
+ from = _this$props2.from,
339
+ fromError = _this$props2.fromError,
340
+ minimumDate = _this$props2.minimumDate,
341
+ onReset = _this$props2.onReset,
342
+ to = _this$props2.to,
343
+ toError = _this$props2.toError,
344
+ translations = _this$props2.translations,
345
+ id = _this$props2.id,
346
+ staticPosition = _this$props2.staticPosition,
347
+ errorText = _this$props2.errorText,
348
+ hasSelector = _this$props2.hasSelector,
349
+ helperIcon = _this$props2.helperIcon,
350
+ helperText = _this$props2.helperText,
351
+ props = (0, _objectWithoutProperties2.default)(_this$props2, ["classes", "disabled", "disabledDays", "disableFutureDays", "enableTime", "labelFrom", "labelTo", "locale", "format", "from", "fromError", "minimumDate", "onReset", "to", "toError", "translations", "id", "staticPosition", "errorText", "hasSelector", "helperIcon", "helperText"]);
464
352
  var now = new Date();
465
353
  var modifiers = {
466
354
  start: from,
@@ -505,92 +393,77 @@ function (_React$Component) {
505
393
  selectedDays: selectedDays,
506
394
  todayButton: translations.today,
507
395
  weekdayElement: _Weekday.default
508
- }, props); // Build Props for the From DatePicker
509
- // Disable days after 'to' date if define
510
-
511
- var after;
512
-
513
- if (to instanceof Date && disableFutureDays) {
514
- after = to < now ? now : to;
515
- } else if (to instanceof Date) {
516
- after = to;
517
- } else if (disableFutureDays) {
518
- after = now;
519
- }
520
-
521
- var disabledDaysFrom = (0, _extends2.default)({}, disablePastDays && {
522
- before: now
523
- }, (to || disableFutureDays) && {
524
- after: after
525
- }, disabledDays);
396
+ }, props);
526
397
  var fromDayPickerProps = (0, _extends2.default)({}, dayPickerProps, {
527
- onTodayButtonClick: this.handleCurrentMonthChangeFrom,
528
- NavBarElement: this.renderNavBarFrom,
529
- captionElement: this.renderCaptionFrom,
530
- disabledDays: disabledDaysFrom,
531
- month: fromCurrentMonth,
532
- modifiers: (0, _extends2.default)({}, modifiers, {
533
- disabled: disabledDaysFrom
534
- })
535
- }); // Build Props for the To DatePicker
536
- // Disable days before 'from' date if define
537
-
538
- var before;
539
-
540
- if (from instanceof Date && disablePastDays) {
541
- before = from < now ? now : from;
542
- } else if (from instanceof Date) {
543
- before = from;
544
- } else if (disablePastDays) {
545
- before = now;
546
- }
547
-
548
- var disabledDaysTo = (0, _extends2.default)({}, (from || disablePastDays) && {
549
- before: before
550
- }, disableFutureDays && {
551
- after: now
552
- }, disabledDays);
398
+ onTodayButtonClick: this.handleCurrentMonthChange,
399
+ navbarElement: this.renderNavBar,
400
+ captionElement: this.renderCaption,
401
+ disabledDays: (0, _extends2.default)({
402
+ before: minimumDate
403
+ }, disableFutureDays && {
404
+ after: now
405
+ }, to && {
406
+ after: to
407
+ }),
408
+ month: this.state.currentMonth,
409
+ modifiers: (0, _extends2.default)({}, modifiers)
410
+ });
553
411
  var toDayPickerProps = (0, _extends2.default)({}, dayPickerProps, {
554
- onTodayButtonClick: this.handleCurrentMonthChangeTo,
555
- NavBarElement: this.renderNavBarTo,
556
- captionElement: this.renderCaptionTo,
557
- disabledDays: disabledDaysTo,
558
- month: toCurrentMonth,
559
- modifiers: (0, _extends2.default)({}, modifiers, {
560
- disabled: disabledDaysTo
561
- })
412
+ onTodayButtonClick: this.handleCurrentMonthChange,
413
+ navbarElement: this.renderNavBar,
414
+ onDayClick: this.onDayToClick,
415
+ captionElement: this.renderCaption,
416
+ disabledDays: (0, _extends2.default)({
417
+ before: minimumDate
418
+ }, disableFutureDays && {
419
+ after: now
420
+ }, from && {
421
+ before: from
422
+ }),
423
+ month: this.state.currentMonth,
424
+ modifiers: (0, _extends2.default)({}, modifiers)
562
425
  }); // From & To InputProps
563
426
 
564
427
  var fromInputProps = (0, _extends2.default)({}, onReset && {
565
428
  onReset: function onReset() {
566
- return _this6.handleReset('from');
429
+ return _this2.handleReset('from');
567
430
  }
568
- }, props, labelFrom && {
431
+ }, props, fromError && {
432
+ error: true
433
+ }, labelFrom && {
569
434
  label: labelFrom
570
435
  }, {
571
436
  id: "".concat(id, "-from"),
572
- onChange: this.handleInputChange('from')
437
+ onChange: this.handleInputChange('from'),
438
+ disabled: disabled
573
439
  });
574
440
  var toInputProps = (0, _extends2.default)({}, onReset && {
575
441
  onReset: function onReset() {
576
- return _this6.handleReset('to');
442
+ return _this2.handleReset('to');
577
443
  }
578
- }, props, labelTo && {
444
+ }, props, toError && {
445
+ error: true
446
+ }, labelTo && {
579
447
  label: labelTo
580
448
  }, {
581
449
  id: "".concat(id, "-to"),
582
- onChange: this.handleInputChange('to')
450
+ onChange: this.handleInputChange('to'),
451
+ disabled: disabled
583
452
  });
584
453
  var toClass = (0, _classnames.default)(classes.toInput, (_classNames = {}, (0, _defineProperty2.default)(_classNames, classes.absolute, staticPosition === true && this.state.focusedInput === 'from'), (0, _defineProperty2.default)(_classNames, classes.right4, staticPosition === true && this.state.focusedInput === 'from'), _classNames));
585
- return _react.default.createElement("div", {
454
+
455
+ var content = _react.default.createElement("div", {
586
456
  className: (0, _classnames.default)(classes.root, classes.rangePickerContainer)
587
457
  }, _react.default.createElement("div", {
588
458
  className: classes.fromInput,
589
- onFocus: this.handleDayPickerFocus('from'),
590
- onBlur: this.handleDayPickerBlur('from')
459
+ onFocus: function onFocus() {
460
+ return _this2.handleDayPickerFocus('from');
461
+ } // onBlur={() => this.handleDayPickerBlur('from')}
462
+
591
463
  }, _react.default.createElement("div", null, _react.default.createElement(_DayPickerInput.default, {
464
+ key: this.state.keyFrom,
592
465
  ref: function ref(el) {
593
- _this6.fromInput = el;
466
+ _this2.fromInput = el;
594
467
  },
595
468
  value: from,
596
469
  hideOnDayClick: false,
@@ -601,15 +474,22 @@ function (_React$Component) {
601
474
  format: enableTime ? "".concat(format, " HH:mm") : format,
602
475
  formatDate: _moment.default.formatDate,
603
476
  parseDate: _moment.default.parseDate,
604
- onDayChange: this.handleDayChangeFrom,
477
+ onDayChange: function onDayChange(day) {
478
+ return _this2.handleDayChange('from', day);
479
+ },
605
480
  placeholder: ''
606
481
  }))), _react.default.createElement("div", {
607
482
  className: toClass,
608
- onFocus: this.handleDayPickerFocus('to'),
609
- onBlur: this.handleDayPickerBlur('to')
483
+ onFocus: function onFocus() {
484
+ return _this2.handleDayPickerFocus('to');
485
+ },
486
+ onBlur: function onBlur() {
487
+ return _this2.handleDayPickerBlur('to');
488
+ }
610
489
  }, _react.default.createElement(_DayPickerInput.default, {
490
+ key: this.state.keyTo,
611
491
  ref: function ref(el) {
612
- _this6.toInput = el;
492
+ _this2.toInput = el;
613
493
  },
614
494
  value: to,
615
495
  hideOnDayClick: false,
@@ -619,10 +499,23 @@ function (_React$Component) {
619
499
  inputProps: toInputProps,
620
500
  format: enableTime ? "".concat(format, " HH:mm") : format,
621
501
  formatDate: _moment.default.formatDate,
622
- parseDate: _moment.default.parseDate,
623
- onDayChange: this.handleDayChangeTo,
502
+ parseDate: _moment.default.parseDate //onDayChange={(day) => this.handleDayChange('to', day)}
503
+ ,
624
504
  placeholder: ''
625
505
  })));
506
+
507
+ if (!hasSelector) {
508
+ content = _react.default.createElement(_HiFormControl.default, {
509
+ disabled: disabled,
510
+ helperIcon: helperIcon,
511
+ helperText: helperText,
512
+ errorText: errorText,
513
+ error: fromError || toError,
514
+ label: ' '
515
+ }, content);
516
+ }
517
+
518
+ return content;
626
519
  }
627
520
  }]);
628
521
  return HiDateRangePicker;
@@ -630,22 +523,26 @@ function (_React$Component) {
630
523
 
631
524
  HiDateRangePicker.defaultProps = {
632
525
  disabledDays: [],
633
- disablePastDays: false,
634
- disableFutureDays: false,
526
+ disableFutureDays: true,
635
527
  staticPosition: false,
636
528
  enableTime: false,
637
- format: 'YYYY-DD-MM',
529
+ hasSelector: false,
530
+ format: 'YYYY-MM-DD',
638
531
  labelFrom: 'Start',
639
532
  labelTo: 'End',
640
533
  locale: 'fr-FR',
641
- minimumDate: new Date(2013, 4, 1),
642
- // by default 1 May 2013
643
534
  translations: {
644
535
  today: 'today',
645
536
  hour: 'Hour',
646
537
  minute: 'Minute',
647
538
  month: 'Month',
648
- year: 'Year'
539
+ year: 'Year',
540
+ invalid_format: 'The date format is not valid',
541
+ to_superior_from: 'Date from cannot be greater than date to',
542
+ missing_date_from: 'Missing date from',
543
+ missing_date_to: 'Missing date to',
544
+ date_superior_max_date: 'Date from cannot be greater than %s',
545
+ date_inferior_min_date: 'Date from cannot be before than %s'
649
546
  }
650
547
  };
651
548
  HiDateRangePicker.propTypes = process.env.NODE_ENV !== "production" ? {
@@ -659,25 +556,20 @@ HiDateRangePicker.propTypes = process.env.NODE_ENV !== "production" ? {
659
556
  */
660
557
  disabled: _propTypes.default.bool,
661
558
 
662
- /**
663
- * Définie les jours non sélectionnables
664
- */
665
- disabledDays: _propTypes.default.oneOfType([_propTypes.default.array, _propTypes.default.object, _propTypes.default.instanceOf(Date)]),
666
-
667
559
  /**
668
560
  * Uniquement la sélection de date antérieures à aujourd'hui (inclu)
669
561
  */
670
562
  disableFutureDays: _propTypes.default.bool,
671
563
 
672
564
  /**
673
- * Uniquement la sélection de date postérieures à aujourd'hui (inclu)
565
+ * Ajoute la gestion de l'heure
674
566
  */
675
- disablePastDays: _propTypes.default.bool,
567
+ enableTime: _propTypes.default.bool,
676
568
 
677
569
  /**
678
- * Ajoute la gestion de l'heure
570
+ * Texte de l'erreur
679
571
  */
680
- enableTime: _propTypes.default.bool,
572
+ errorText: _propTypes.default.string,
681
573
 
682
574
  /**
683
575
  * Format des dates affichées
@@ -687,7 +579,29 @@ HiDateRangePicker.propTypes = process.env.NODE_ENV !== "production" ? {
687
579
  /**
688
580
  * Date de début sélectionnée
689
581
  */
690
- from: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.string]),
582
+ from: _propTypes.default.instanceOf(Date),
583
+ //from: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.string]),
584
+
585
+ /**
586
+ * Erreur sur date from
587
+ */
588
+ fromError: _propTypes.default.bool,
589
+
590
+ /**
591
+ * @ignore
592
+ * Si true, on n'enveloppe pas le composant avec un HiFormControl
593
+ */
594
+ hasSelector: _propTypes.default.bool,
595
+
596
+ /**
597
+ * Si "true", le texte d'aide s'affichera seulement au clic sur l'icône "Information"
598
+ */
599
+ helperIcon: _propTypes.default.bool,
600
+
601
+ /**
602
+ * Texte de l'aide
603
+ */
604
+ helperText: _propTypes.default.string,
691
605
 
692
606
  /**
693
607
  * Utilisé pour construire les ids des champs from et to en les suffixant "-from" et "-to"
@@ -712,7 +626,7 @@ HiDateRangePicker.propTypes = process.env.NODE_ENV !== "production" ? {
712
626
  /**
713
627
  * Date minimale sélectionnable
714
628
  */
715
- minimumDate: _propTypes.default.instanceOf(Date),
629
+ minimumDate: _propTypes.default.instanceOf(Date).isRequired,
716
630
 
717
631
  /**
718
632
  * Callback à la sélection d'une date
@@ -725,7 +639,7 @@ HiDateRangePicker.propTypes = process.env.NODE_ENV !== "production" ? {
725
639
  * @param {string} nom du champs
726
640
  * @param {string} nouvelle valeur du champs
727
641
  */
728
- onChange: _propTypes.default.func,
642
+ onChange: _propTypes.default.func.isRequired,
729
643
 
730
644
  /**
731
645
  * Callback au reset de l'input
@@ -741,7 +655,12 @@ HiDateRangePicker.propTypes = process.env.NODE_ENV !== "production" ? {
741
655
  /**
742
656
  * Date de fin sélectionnée
743
657
  */
744
- to: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.string]),
658
+ to: _propTypes.default.instanceOf(Date),
659
+
660
+ /**
661
+ * Erreur sur date to
662
+ */
663
+ toError: _propTypes.default.bool,
745
664
 
746
665
  /**
747
666
  * Traductions