@seafile/seafile-calendar 0.1.2-beta.0 → 1.0.0-alpha.0
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/assets/index.css +177 -144
- package/es/Calendar.js +124 -69
- package/es/calendar/CalendarRightPanel.js +193 -63
- package/es/date/DateInput.js +0 -1
- package/es/time/TimeInput.js +206 -0
- package/lib/Calendar.js +127 -69
- package/lib/calendar/CalendarRightPanel.js +193 -63
- package/lib/date/DateInput.js +0 -1
- package/lib/time/TimeInput.js +234 -0
- package/package.json +1 -1
package/es/Calendar.js
CHANGED
|
@@ -15,6 +15,7 @@ import CalendarRightPanel from './calendar/CalendarRightPanel';
|
|
|
15
15
|
import { calendarMixinWrapper, calendarMixinPropTypes, calendarMixinDefaultProps, getNowByCurrentStateValue } from './mixin/CalendarMixin';
|
|
16
16
|
import { commonMixinWrapper, propType, defaultProp } from './mixin/CommonMixin';
|
|
17
17
|
import DateInput from './date/DateInput';
|
|
18
|
+
import TimeInput from './time/TimeInput';
|
|
18
19
|
import { getTimeConfig, getTodayTime, syncTime, CALENDAR_STATUS } from './util';
|
|
19
20
|
import { goStartMonth, goEndMonth, goTime } from './util/toTime';
|
|
20
21
|
import localeData from 'dayjs/plugin/localeData';
|
|
@@ -47,7 +48,8 @@ var Calendar = function (_React$Component) {
|
|
|
47
48
|
mode: _this.props.mode || 'date',
|
|
48
49
|
value: getMomentObjectIfValid(props.value) || getMomentObjectIfValid(props.defaultValue) || dayjs(),
|
|
49
50
|
selectedValue: props.selectedValue || props.defaultSelectedValue,
|
|
50
|
-
currentStatus: CALENDAR_STATUS.SPECIFIC_TIME
|
|
51
|
+
currentStatus: CALENDAR_STATUS.SPECIFIC_TIME,
|
|
52
|
+
hasExplicitTime: false
|
|
51
53
|
};
|
|
52
54
|
return _this;
|
|
53
55
|
}
|
|
@@ -78,6 +80,8 @@ var Calendar = function (_React$Component) {
|
|
|
78
80
|
};
|
|
79
81
|
|
|
80
82
|
Calendar.prototype.render = function render() {
|
|
83
|
+
var _this2 = this;
|
|
84
|
+
|
|
81
85
|
var props = this.props,
|
|
82
86
|
state = this.state;
|
|
83
87
|
var locale = props.locale,
|
|
@@ -120,7 +124,9 @@ var Calendar = function (_React$Component) {
|
|
|
120
124
|
|
|
121
125
|
timePickerEle = React.cloneElement(timePicker, timePickerProps);
|
|
122
126
|
}
|
|
123
|
-
|
|
127
|
+
|
|
128
|
+
var baseFormat = Array.isArray(this.getFormat()) ? this.getFormat()[0] : this.getFormat();
|
|
129
|
+
var headerDatePlaceholder = baseFormat.replace(/\s*HH:mm(?::ss)?\s*/, '').trim() || 'YYYY-MM-DD';
|
|
124
130
|
var inputFormat = Array.isArray(this.getFormat()) ? this.getFormat() : [this.getFormat()];
|
|
125
131
|
|
|
126
132
|
var dateInputElement = props.showDateInput ? React.createElement(DateInput, {
|
|
@@ -128,8 +134,8 @@ var Calendar = function (_React$Component) {
|
|
|
128
134
|
key: 'date-input',
|
|
129
135
|
value: value,
|
|
130
136
|
locale: locale,
|
|
131
|
-
placeholder:
|
|
132
|
-
showClear:
|
|
137
|
+
placeholder: headerDatePlaceholder,
|
|
138
|
+
showClear: false,
|
|
133
139
|
disabledTime: disabledTime,
|
|
134
140
|
disabledDate: disabledDate,
|
|
135
141
|
onClear: this.onClear,
|
|
@@ -141,6 +147,17 @@ var Calendar = function (_React$Component) {
|
|
|
141
147
|
inputMode: inputMode
|
|
142
148
|
}) : null;
|
|
143
149
|
|
|
150
|
+
var timeInputTopElement = React.createElement(TimeInput, {
|
|
151
|
+
key: 'time-input-top',
|
|
152
|
+
prefixCls: prefixCls,
|
|
153
|
+
value: value,
|
|
154
|
+
selectedValue: selectedValue,
|
|
155
|
+
showFromSelected: this.state.hasExplicitTime,
|
|
156
|
+
onChange: this.onTimeInputChange,
|
|
157
|
+
onSelect: this.onTimeInputSelect,
|
|
158
|
+
inputMode: 'numeric'
|
|
159
|
+
});
|
|
160
|
+
|
|
144
161
|
var children = [];
|
|
145
162
|
if (props.renderSidebar) {
|
|
146
163
|
children.push(props.renderSidebar());
|
|
@@ -148,7 +165,24 @@ var Calendar = function (_React$Component) {
|
|
|
148
165
|
children.push(React.createElement(
|
|
149
166
|
'div',
|
|
150
167
|
{ className: prefixCls + '-panel', key: 'panel' },
|
|
151
|
-
|
|
168
|
+
React.createElement(
|
|
169
|
+
'div',
|
|
170
|
+
{ className: prefixCls + '-inputs' },
|
|
171
|
+
React.createElement(
|
|
172
|
+
'div',
|
|
173
|
+
{ className: prefixCls + '-date-input-col' },
|
|
174
|
+
React.createElement(
|
|
175
|
+
'div',
|
|
176
|
+
{ className: prefixCls + '-date-input' },
|
|
177
|
+
dateInputElement
|
|
178
|
+
)
|
|
179
|
+
),
|
|
180
|
+
React.createElement(
|
|
181
|
+
'div',
|
|
182
|
+
{ className: prefixCls + '-time-input-col' },
|
|
183
|
+
timeInputTopElement
|
|
184
|
+
)
|
|
185
|
+
),
|
|
152
186
|
React.createElement(
|
|
153
187
|
'div',
|
|
154
188
|
{ className: prefixCls + '-date-panel-container' },
|
|
@@ -192,39 +226,45 @@ var Calendar = function (_React$Component) {
|
|
|
192
226
|
firstDayOfWeek: firstDayOfWeek,
|
|
193
227
|
currentStatus: currentStatus
|
|
194
228
|
})
|
|
195
|
-
)
|
|
196
|
-
React.createElement(CalendarFooter, {
|
|
197
|
-
showOk: props.showOk,
|
|
198
|
-
mode: mode,
|
|
199
|
-
renderFooter: props.renderFooter,
|
|
200
|
-
locale: locale,
|
|
201
|
-
prefixCls: prefixCls,
|
|
202
|
-
showToday: props.showToday,
|
|
203
|
-
disabledTime: disabledTime,
|
|
204
|
-
showTimePicker: showTimePicker,
|
|
205
|
-
showDateInput: props.showDateInput,
|
|
206
|
-
timePicker: timePicker,
|
|
207
|
-
selectedValue: selectedValue,
|
|
208
|
-
value: value,
|
|
209
|
-
disabledDate: disabledDate,
|
|
210
|
-
okDisabled: props.showOk !== false && (!selectedValue || !this.isAllowedDate(selectedValue)),
|
|
211
|
-
onOk: this.onOk,
|
|
212
|
-
onSelect: this.onSelect,
|
|
213
|
-
onToday: this.onToday,
|
|
214
|
-
onOpenTimePicker: this.openTimePicker,
|
|
215
|
-
onCloseTimePicker: this.closeTimePicker
|
|
216
|
-
})
|
|
229
|
+
)
|
|
217
230
|
),
|
|
218
231
|
showHourAndMinute && React.createElement(CalendarRightPanel, {
|
|
219
232
|
prefixCls: prefixCls,
|
|
220
233
|
value: value,
|
|
234
|
+
selectedValue: selectedValue,
|
|
221
235
|
locale: locale,
|
|
222
|
-
onSelect:
|
|
236
|
+
onSelect: function onSelect(v) {
|
|
237
|
+
if (!_this2.state.hasExplicitTime) {
|
|
238
|
+
_this2.setState({ hasExplicitTime: true });
|
|
239
|
+
}
|
|
240
|
+
_this2.onDateTableSelect(v);
|
|
241
|
+
},
|
|
223
242
|
onClickRightPanelTime: onClickRightPanelTime,
|
|
224
243
|
defaultMinutesTime: this.props.defaultMinutesTime,
|
|
225
244
|
format: inputFormat
|
|
226
245
|
})
|
|
227
|
-
)
|
|
246
|
+
),
|
|
247
|
+
React.createElement(CalendarFooter, {
|
|
248
|
+
showOk: props.showOk,
|
|
249
|
+
mode: mode,
|
|
250
|
+
renderFooter: props.renderFooter,
|
|
251
|
+
locale: locale,
|
|
252
|
+
prefixCls: prefixCls,
|
|
253
|
+
showToday: props.showToday,
|
|
254
|
+
disabledTime: disabledTime,
|
|
255
|
+
showTimePicker: showTimePicker,
|
|
256
|
+
showDateInput: props.showDateInput,
|
|
257
|
+
timePicker: timePicker,
|
|
258
|
+
selectedValue: selectedValue,
|
|
259
|
+
value: value,
|
|
260
|
+
disabledDate: disabledDate,
|
|
261
|
+
okDisabled: props.showOk !== false && (!selectedValue || !this.isAllowedDate(selectedValue)),
|
|
262
|
+
onOk: this.onOk,
|
|
263
|
+
onSelect: this.onSelect,
|
|
264
|
+
onToday: this.onToday,
|
|
265
|
+
onOpenTimePicker: this.openTimePicker,
|
|
266
|
+
onCloseTimePicker: this.closeTimePicker
|
|
267
|
+
})
|
|
228
268
|
));
|
|
229
269
|
|
|
230
270
|
return this.renderRoot({
|
|
@@ -285,14 +325,14 @@ Calendar.defaultProps = _extends({}, calendarMixinDefaultProps, defaultProp, {
|
|
|
285
325
|
});
|
|
286
326
|
|
|
287
327
|
var _initialiseProps = function _initialiseProps() {
|
|
288
|
-
var
|
|
328
|
+
var _this3 = this;
|
|
289
329
|
|
|
290
330
|
this.onPanelChange = function (value, mode) {
|
|
291
|
-
var props =
|
|
292
|
-
state =
|
|
331
|
+
var props = _this3.props,
|
|
332
|
+
state = _this3.state;
|
|
293
333
|
|
|
294
334
|
if (!('mode' in props)) {
|
|
295
|
-
|
|
335
|
+
_this3.setState({ mode: mode });
|
|
296
336
|
}
|
|
297
337
|
props.onPanelChange(value || state.value, mode);
|
|
298
338
|
};
|
|
@@ -304,109 +344,109 @@ var _initialiseProps = function _initialiseProps() {
|
|
|
304
344
|
var keyCode = event.keyCode;
|
|
305
345
|
// mac
|
|
306
346
|
var ctrlKey = event.ctrlKey || event.metaKey;
|
|
307
|
-
var disabledDate =
|
|
308
|
-
var value =
|
|
347
|
+
var disabledDate = _this3.props.disabledDate;
|
|
348
|
+
var value = _this3.state.value;
|
|
309
349
|
|
|
310
350
|
switch (keyCode) {
|
|
311
351
|
case KeyCode.DOWN:
|
|
312
|
-
|
|
352
|
+
_this3.goTime(1, 'weeks');
|
|
313
353
|
event.preventDefault();
|
|
314
354
|
return 1;
|
|
315
355
|
case KeyCode.UP:
|
|
316
|
-
|
|
356
|
+
_this3.goTime(-1, 'weeks');
|
|
317
357
|
event.preventDefault();
|
|
318
358
|
return 1;
|
|
319
359
|
case KeyCode.LEFT:
|
|
320
360
|
if (ctrlKey) {
|
|
321
|
-
|
|
361
|
+
_this3.goTime(-1, 'years');
|
|
322
362
|
} else {
|
|
323
|
-
|
|
363
|
+
_this3.goTime(-1, 'days');
|
|
324
364
|
}
|
|
325
365
|
event.preventDefault();
|
|
326
366
|
return 1;
|
|
327
367
|
case KeyCode.RIGHT:
|
|
328
368
|
if (ctrlKey) {
|
|
329
|
-
|
|
369
|
+
_this3.goTime(1, 'years');
|
|
330
370
|
} else {
|
|
331
|
-
|
|
371
|
+
_this3.goTime(1, 'days');
|
|
332
372
|
}
|
|
333
373
|
event.preventDefault();
|
|
334
374
|
return 1;
|
|
335
375
|
case KeyCode.HOME:
|
|
336
|
-
|
|
376
|
+
_this3.setValue(goStartMonth(_this3.state.value));
|
|
337
377
|
event.preventDefault();
|
|
338
378
|
return 1;
|
|
339
379
|
case KeyCode.END:
|
|
340
|
-
|
|
380
|
+
_this3.setValue(goEndMonth(_this3.state.value));
|
|
341
381
|
event.preventDefault();
|
|
342
382
|
return 1;
|
|
343
383
|
case KeyCode.PAGE_DOWN:
|
|
344
|
-
|
|
384
|
+
_this3.goTime(1, 'month');
|
|
345
385
|
event.preventDefault();
|
|
346
386
|
return 1;
|
|
347
387
|
case KeyCode.PAGE_UP:
|
|
348
|
-
|
|
388
|
+
_this3.goTime(-1, 'month');
|
|
349
389
|
event.preventDefault();
|
|
350
390
|
return 1;
|
|
351
391
|
case KeyCode.ENTER:
|
|
352
392
|
if (!disabledDate || !disabledDate(value)) {
|
|
353
|
-
|
|
393
|
+
_this3.onSelect(value, {
|
|
354
394
|
source: 'keyboard'
|
|
355
395
|
});
|
|
356
396
|
}
|
|
357
397
|
event.preventDefault();
|
|
358
398
|
return 1;
|
|
359
399
|
default:
|
|
360
|
-
|
|
400
|
+
_this3.props.onKeyDown(event);
|
|
361
401
|
return 1;
|
|
362
402
|
}
|
|
363
403
|
};
|
|
364
404
|
|
|
365
405
|
this.onClear = function () {
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
406
|
+
_this3.onSelect(null);
|
|
407
|
+
_this3.props.onClear();
|
|
408
|
+
_this3.setState({ currentStatus: CALENDAR_STATUS.CURRENT_TIME, hasExplicitTime: false });
|
|
369
409
|
};
|
|
370
410
|
|
|
371
411
|
this.onOk = function () {
|
|
372
|
-
var selectedValue =
|
|
412
|
+
var selectedValue = _this3.state.selectedValue;
|
|
373
413
|
|
|
374
|
-
if (
|
|
375
|
-
|
|
414
|
+
if (_this3.isAllowedDate(selectedValue)) {
|
|
415
|
+
_this3.props.onOk(selectedValue);
|
|
376
416
|
}
|
|
377
417
|
};
|
|
378
418
|
|
|
379
419
|
this.onDateInputChange = function (value) {
|
|
380
|
-
|
|
420
|
+
_this3.onSelect(value, {
|
|
381
421
|
source: 'dateInput'
|
|
382
422
|
});
|
|
383
423
|
};
|
|
384
424
|
|
|
385
425
|
this.onDateInputSelect = function (value) {
|
|
386
|
-
|
|
426
|
+
_this3.onSelect(value, {
|
|
387
427
|
source: 'dateInputSelect'
|
|
388
428
|
});
|
|
389
429
|
};
|
|
390
430
|
|
|
391
431
|
this.onDateTableSelect = function (value) {
|
|
392
|
-
var timePicker =
|
|
393
|
-
var selectedValue =
|
|
432
|
+
var timePicker = _this3.props.timePicker;
|
|
433
|
+
var selectedValue = _this3.state.selectedValue;
|
|
394
434
|
|
|
395
|
-
|
|
435
|
+
_this3.setState({ currentStatus: CALENDAR_STATUS.SPECIFIC_TIME });
|
|
396
436
|
if (!selectedValue && timePicker) {
|
|
397
437
|
var timePickerDefaultValue = timePicker.props.defaultValue;
|
|
398
438
|
if (timePickerDefaultValue) {
|
|
399
439
|
syncTime(timePickerDefaultValue, value);
|
|
400
440
|
}
|
|
401
441
|
}
|
|
402
|
-
|
|
442
|
+
_this3.onSelect(value);
|
|
403
443
|
};
|
|
404
444
|
|
|
405
445
|
this.onToday = function () {
|
|
406
|
-
var value =
|
|
446
|
+
var value = _this3.state.value;
|
|
407
447
|
|
|
408
448
|
var now = getTodayTime(value);
|
|
409
|
-
|
|
449
|
+
_this3.onSelect(now, {
|
|
410
450
|
source: 'todayButton'
|
|
411
451
|
});
|
|
412
452
|
};
|
|
@@ -414,33 +454,48 @@ var _initialiseProps = function _initialiseProps() {
|
|
|
414
454
|
this.onBlur = function (event) {
|
|
415
455
|
setTimeout(function () {
|
|
416
456
|
var dateInput = DateInput.getInstance();
|
|
417
|
-
var
|
|
457
|
+
var timeInput = TimeInput.getInstance && TimeInput.getInstance();
|
|
458
|
+
var rootInstance = _this3.rootInstance;
|
|
418
459
|
|
|
419
|
-
if (!rootInstance || rootInstance.contains(document.activeElement) || dateInput && dateInput.contains(document.activeElement)) {
|
|
460
|
+
if (!rootInstance || rootInstance.contains(document.activeElement) || dateInput && dateInput.contains(document.activeElement) || timeInput && timeInput.contains && timeInput.contains(document.activeElement)) {
|
|
420
461
|
// focused element is still part of Calendar
|
|
421
462
|
return;
|
|
422
463
|
}
|
|
423
464
|
|
|
424
|
-
if (
|
|
425
|
-
|
|
465
|
+
if (_this3.props.onBlur) {
|
|
466
|
+
_this3.props.onBlur(event);
|
|
426
467
|
}
|
|
427
468
|
}, 0);
|
|
428
469
|
};
|
|
429
470
|
|
|
471
|
+
this.onTimeInputChange = function (value) {
|
|
472
|
+
if (!_this3.state.hasExplicitTime) {
|
|
473
|
+
_this3.setState({ hasExplicitTime: true });
|
|
474
|
+
}
|
|
475
|
+
_this3.onSelect(value, { source: 'timeInputChange' });
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
this.onTimeInputSelect = function (value) {
|
|
479
|
+
if (!_this3.state.hasExplicitTime) {
|
|
480
|
+
_this3.setState({ hasExplicitTime: true });
|
|
481
|
+
}
|
|
482
|
+
_this3.onSelect(value, { source: 'timeInputSelect' });
|
|
483
|
+
};
|
|
484
|
+
|
|
430
485
|
this.getRootDOMNode = function () {
|
|
431
|
-
return ReactDOM.findDOMNode(
|
|
486
|
+
return ReactDOM.findDOMNode(_this3);
|
|
432
487
|
};
|
|
433
488
|
|
|
434
489
|
this.openTimePicker = function () {
|
|
435
|
-
|
|
490
|
+
_this3.onPanelChange(null, 'time');
|
|
436
491
|
};
|
|
437
492
|
|
|
438
493
|
this.closeTimePicker = function () {
|
|
439
|
-
|
|
494
|
+
_this3.onPanelChange(null, 'date');
|
|
440
495
|
};
|
|
441
496
|
|
|
442
497
|
this.goTime = function (direction, unit) {
|
|
443
|
-
|
|
498
|
+
_this3.setValue(goTime(_this3.state.value, direction, unit));
|
|
444
499
|
};
|
|
445
500
|
};
|
|
446
501
|
|
|
@@ -13,103 +13,232 @@ var CalendarRightPanel = function (_React$Component) {
|
|
|
13
13
|
|
|
14
14
|
var _this = _possibleConstructorReturn(this, _React$Component.call(this, props));
|
|
15
15
|
|
|
16
|
-
_this.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
_this.centerScroll = function (container, index) {
|
|
17
|
+
if (!container || index < 0) return;
|
|
18
|
+
var firstItem = container.querySelector('li');
|
|
19
|
+
var itemHeight = firstItem && firstItem.offsetHeight || 32;
|
|
20
|
+
var containerHeight = container.clientHeight || 0;
|
|
21
|
+
var maxScroll = Math.max(0, container.scrollHeight - containerHeight);
|
|
22
|
+
var target = index * itemHeight - (containerHeight / 2 - itemHeight / 2);
|
|
23
|
+
if (target < 0) target = 0;
|
|
24
|
+
if (target > maxScroll) target = maxScroll;
|
|
25
|
+
container.scrollTop = target;
|
|
22
26
|
};
|
|
23
27
|
|
|
24
|
-
_this.
|
|
25
|
-
var
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
_this.onSelectMinute = function (minute) {
|
|
29
|
+
var base = _this.props.selectedValue || _this.props.value || _this.state.highlightTime || dayjs();
|
|
30
|
+
var h = parseInt(_this.getSelectedHour(), 10) || 0;
|
|
31
|
+
var m = parseInt(minute, 10) || 0;
|
|
32
|
+
var current = base.clone().hour(h).minute(m);
|
|
33
|
+
_this.skipScrollUpdates = 2;
|
|
34
|
+
_this.setState({ highlightTime: current });
|
|
35
|
+
_this.props.onSelect(current);
|
|
36
|
+
if (_this.props.onClickRightPanelTime) {
|
|
37
|
+
_this.props.onClickRightPanelTime();
|
|
31
38
|
}
|
|
32
|
-
return times;
|
|
33
39
|
};
|
|
34
40
|
|
|
35
|
-
_this.
|
|
36
|
-
_this.
|
|
41
|
+
_this.onSelectHour = function (hour) {
|
|
42
|
+
var base = _this.props.selectedValue || _this.props.value || _this.state.highlightTime || dayjs();
|
|
43
|
+
var h = parseInt(hour, 10) || 0;
|
|
44
|
+
var m = parseInt(_this.getSelectedMinute(), 10) || 0;
|
|
45
|
+
var current = base.clone().hour(h).minute(m);
|
|
46
|
+
_this.skipScrollUpdates = 2;
|
|
47
|
+
_this.setState({ highlightTime: current });
|
|
48
|
+
_this.props.onSelect(current);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
_this.getHours = function () {
|
|
52
|
+
return Array.from({ length: 24 }, function (_, i) {
|
|
53
|
+
return String(i).padStart(2, '0');
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
_this.getMinutes = function () {
|
|
58
|
+
return Array.from({ length: 60 }, function (_, i) {
|
|
59
|
+
return String(i).padStart(2, '0');
|
|
60
|
+
});
|
|
37
61
|
};
|
|
38
62
|
|
|
39
|
-
_this.
|
|
40
|
-
_this.
|
|
63
|
+
_this.getSelectedHour = function () {
|
|
64
|
+
var highlightTime = _this.state.highlightTime;
|
|
65
|
+
var _this$props = _this.props,
|
|
66
|
+
value = _this$props.value,
|
|
67
|
+
selectedValue = _this$props.selectedValue;
|
|
68
|
+
|
|
69
|
+
var v = highlightTime || selectedValue || value;
|
|
70
|
+
return v ? v.format('HH') : '00';
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
_this.getSelectedMinute = function () {
|
|
74
|
+
var highlightTime = _this.state.highlightTime;
|
|
75
|
+
var _this$props2 = _this.props,
|
|
76
|
+
value = _this$props2.value,
|
|
77
|
+
selectedValue = _this$props2.selectedValue;
|
|
78
|
+
|
|
79
|
+
var v = highlightTime || selectedValue || value;
|
|
80
|
+
return v ? v.format('mm') : '00';
|
|
41
81
|
};
|
|
42
82
|
|
|
43
83
|
var format = Array.isArray(_this.props.format) ? _this.props.format[0] : _this.props.format;
|
|
44
84
|
_this.state = {
|
|
45
|
-
highlightTime: _this.props.value || null,
|
|
85
|
+
highlightTime: _this.props.selectedValue || _this.props.value || null,
|
|
46
86
|
localeFormat: format
|
|
47
87
|
};
|
|
48
|
-
|
|
49
|
-
_this.
|
|
88
|
+
|
|
89
|
+
_this.hoursRef = React.createRef();
|
|
90
|
+
_this.minutesRef = React.createRef();
|
|
91
|
+
_this.hours = _this.getHours();
|
|
92
|
+
_this.minutes = _this.getMinutes();
|
|
93
|
+
|
|
94
|
+
_this.skipScrollUpdates = 0;
|
|
50
95
|
return _this;
|
|
51
96
|
}
|
|
52
97
|
|
|
98
|
+
CalendarRightPanel.getDerivedStateFromProps = function getDerivedStateFromProps(nextProps, prevState) {
|
|
99
|
+
if (nextProps.selectedValue) {
|
|
100
|
+
if (!prevState.highlightTime || !prevState.highlightTime.isSame(nextProps.selectedValue)) {
|
|
101
|
+
return { highlightTime: nextProps.selectedValue };
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return null;
|
|
105
|
+
};
|
|
106
|
+
|
|
53
107
|
CalendarRightPanel.prototype.componentDidMount = function componentDidMount() {
|
|
54
|
-
var
|
|
108
|
+
var _this2 = this;
|
|
55
109
|
|
|
56
|
-
var
|
|
57
|
-
|
|
110
|
+
var _props = this.props,
|
|
111
|
+
defaultMinutesTime = _props.defaultMinutesTime,
|
|
112
|
+
value = _props.value,
|
|
113
|
+
selectedValue = _props.selectedValue;
|
|
114
|
+
|
|
115
|
+
var baseTime = defaultMinutesTime || (selectedValue || value ? (selectedValue || value).format('HH:mm') : '00:00');
|
|
116
|
+
var base = baseTime.split(':');
|
|
117
|
+
var hIdx = this.hours.findIndex(function (h) {
|
|
118
|
+
return h === base[0];
|
|
119
|
+
});
|
|
120
|
+
var mIdx = this.minutes.findIndex(function (m) {
|
|
121
|
+
return m === base[1];
|
|
58
122
|
});
|
|
59
|
-
var
|
|
60
|
-
|
|
123
|
+
var hourIndex = hIdx > -1 ? hIdx : 0;
|
|
124
|
+
var minuteIndex = mIdx > -1 ? mIdx : 0;
|
|
125
|
+
|
|
126
|
+
if (typeof window !== 'undefined' && window.requestAnimationFrame) {
|
|
127
|
+
window.requestAnimationFrame(function () {
|
|
128
|
+
_this2.centerScroll(_this2.hoursRef.current, hourIndex);
|
|
129
|
+
_this2.centerScroll(_this2.minutesRef.current, minuteIndex);
|
|
130
|
+
});
|
|
131
|
+
} else {
|
|
132
|
+
this.centerScroll(this.hoursRef.current, hourIndex);
|
|
133
|
+
this.centerScroll(this.minutesRef.current, minuteIndex);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
CalendarRightPanel.prototype.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
|
|
138
|
+
var _this3 = this;
|
|
139
|
+
|
|
140
|
+
var prevV = prevState.highlightTime || prevProps.selectedValue || prevProps.value;
|
|
141
|
+
var currV = this.state.highlightTime || this.props.selectedValue || this.props.value;
|
|
142
|
+
|
|
143
|
+
var prevH = prevV ? prevV.format('HH') : '00';
|
|
144
|
+
var prevM = prevV ? prevV.format('mm') : '00';
|
|
145
|
+
var currH = currV ? currV.format('HH') : '00';
|
|
146
|
+
var currM = currV ? currV.format('mm') : '00';
|
|
147
|
+
|
|
148
|
+
if (this.skipScrollUpdates > 0) {
|
|
149
|
+
this.skipScrollUpdates -= 1;
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
var hChanged = prevH !== currH;
|
|
154
|
+
var mChanged = prevM !== currM;
|
|
155
|
+
if (hChanged || mChanged) {
|
|
156
|
+
var scrollHours = function scrollHours() {
|
|
157
|
+
if (hChanged) {
|
|
158
|
+
var hIdx = _this3.hours.findIndex(function (h) {
|
|
159
|
+
return h === currH;
|
|
160
|
+
});
|
|
161
|
+
var hourIndex = hIdx > -1 ? hIdx : 0;
|
|
162
|
+
_this3.centerScroll(_this3.hoursRef.current, hourIndex);
|
|
163
|
+
}
|
|
164
|
+
if (mChanged) {
|
|
165
|
+
var mIdx = _this3.minutes.findIndex(function (m) {
|
|
166
|
+
return m === currM;
|
|
167
|
+
});
|
|
168
|
+
var minuteIndex = mIdx > -1 ? mIdx : 0;
|
|
169
|
+
_this3.centerScroll(_this3.minutesRef.current, minuteIndex);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
if (typeof window !== 'undefined' && window.requestAnimationFrame) {
|
|
173
|
+
window.requestAnimationFrame(scrollHours);
|
|
174
|
+
} else {
|
|
175
|
+
scrollHours();
|
|
176
|
+
}
|
|
177
|
+
}
|
|
61
178
|
};
|
|
62
179
|
|
|
63
180
|
CalendarRightPanel.prototype.render = function render() {
|
|
64
|
-
var
|
|
181
|
+
var _this4 = this;
|
|
65
182
|
|
|
66
|
-
var
|
|
67
|
-
value = _props.value,
|
|
68
|
-
prefixCls = _props.prefixCls,
|
|
69
|
-
locale = _props.locale;
|
|
183
|
+
var prefixCls = this.props.prefixCls;
|
|
70
184
|
|
|
71
|
-
var
|
|
72
|
-
var
|
|
73
|
-
var isZhcn = locale && locale.today === '今天';
|
|
185
|
+
var selectedHour = this.getSelectedHour();
|
|
186
|
+
var selectedMinute = this.getSelectedMinute();
|
|
74
187
|
return React.createElement(
|
|
75
188
|
'div',
|
|
76
189
|
{ className: prefixCls + '-right-panel' },
|
|
77
190
|
React.createElement(
|
|
78
191
|
'div',
|
|
79
|
-
{ className: prefixCls + '-right-panel-header'
|
|
80
|
-
|
|
192
|
+
{ className: prefixCls + '-right-panel-time-header' },
|
|
193
|
+
selectedHour,
|
|
194
|
+
':',
|
|
195
|
+
selectedMinute
|
|
81
196
|
),
|
|
82
197
|
React.createElement(
|
|
83
198
|
'div',
|
|
84
|
-
{ className: prefixCls + '-right-panel-body'
|
|
199
|
+
{ className: prefixCls + '-right-panel-body' },
|
|
85
200
|
React.createElement(
|
|
86
|
-
'
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
201
|
+
'div',
|
|
202
|
+
{ className: prefixCls + '-right-panel-col', ref: this.hoursRef },
|
|
203
|
+
React.createElement(
|
|
204
|
+
'ul',
|
|
205
|
+
null,
|
|
206
|
+
this.hours.map(function (h) {
|
|
207
|
+
return React.createElement(
|
|
208
|
+
'li',
|
|
209
|
+
{
|
|
210
|
+
key: h,
|
|
211
|
+
onClick: function onClick() {
|
|
212
|
+
return _this4.onSelectHour(h);
|
|
213
|
+
},
|
|
214
|
+
className: prefixCls + '-right-panel-item ' + (h === selectedHour ? prefixCls + '-right-panel-item-selected' : '')
|
|
215
|
+
},
|
|
216
|
+
h
|
|
217
|
+
);
|
|
218
|
+
})
|
|
219
|
+
)
|
|
220
|
+
),
|
|
221
|
+
React.createElement(
|
|
222
|
+
'div',
|
|
223
|
+
{ className: prefixCls + '-right-panel-col', ref: this.minutesRef },
|
|
224
|
+
React.createElement(
|
|
225
|
+
'ul',
|
|
226
|
+
null,
|
|
227
|
+
this.minutes.map(function (m) {
|
|
228
|
+
return React.createElement(
|
|
229
|
+
'li',
|
|
230
|
+
{
|
|
231
|
+
key: m,
|
|
232
|
+
onClick: function onClick() {
|
|
233
|
+
return _this4.onSelectMinute(m);
|
|
234
|
+
},
|
|
235
|
+
className: prefixCls + '-right-panel-item ' + (m === selectedMinute ? prefixCls + '-right-panel-item-selected' : '')
|
|
236
|
+
},
|
|
237
|
+
m
|
|
238
|
+
);
|
|
239
|
+
})
|
|
240
|
+
)
|
|
107
241
|
)
|
|
108
|
-
),
|
|
109
|
-
React.createElement(
|
|
110
|
-
'div',
|
|
111
|
-
{ className: prefixCls + '-right-panel-footer', onClick: this.scrollDown },
|
|
112
|
-
React.createElement('span', null)
|
|
113
242
|
)
|
|
114
243
|
);
|
|
115
244
|
};
|
|
@@ -120,6 +249,7 @@ var CalendarRightPanel = function (_React$Component) {
|
|
|
120
249
|
CalendarRightPanel.propTypes = {
|
|
121
250
|
prefixCls: PropTypes.string,
|
|
122
251
|
value: PropTypes.object,
|
|
252
|
+
selectedValue: PropTypes.object,
|
|
123
253
|
onSelect: PropTypes.func,
|
|
124
254
|
onClickRightPanelTime: PropTypes.func,
|
|
125
255
|
locale: PropTypes.object,
|
package/es/date/DateInput.js
CHANGED