UNPKG

3.18 kBJavaScriptView Raw
1import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
2import _createClass from 'babel-runtime/helpers/createClass';
3import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
4import _inherits from 'babel-runtime/helpers/inherits';
5import React from 'react';
6import DateTimePicker from 'rmc-date-picker';
7
8var TimePicker = function (_React$PureComponent) {
9 _inherits(TimePicker, _React$PureComponent);
10
11 function TimePicker() {
12 _classCallCheck(this, TimePicker);
13
14 var _this = _possibleConstructorReturn(this, (TimePicker.__proto__ || Object.getPrototypeOf(TimePicker)).apply(this, arguments));
15
16 _this.onDateChange = function (date) {
17 var onValueChange = _this.props.onValueChange;
18
19 onValueChange && onValueChange(date);
20 };
21 return _this;
22 }
23
24 _createClass(TimePicker, [{
25 key: 'getMinTime',
26 value: function getMinTime(date) {
27 var minDate = this.props.minDate;
28 if (!date || date.getFullYear() > minDate.getFullYear() || date.getMonth() > minDate.getMonth() || date.getDate() > minDate.getDate()) {
29 return TimePicker.defaultProps.minDate;
30 }
31 return minDate;
32 }
33 }, {
34 key: 'getMaxTime',
35 value: function getMaxTime(date) {
36 var maxDate = this.props.maxDate;
37 if (!date || date.getFullYear() < maxDate.getFullYear() || date.getMonth() < maxDate.getMonth() || date.getDate() < maxDate.getDate()) {
38 return TimePicker.defaultProps.maxDate;
39 }
40 return maxDate;
41 }
42 }, {
43 key: 'render',
44 value: function render() {
45 var _props = this.props,
46 locale = _props.locale,
47 title = _props.title,
48 value = _props.value,
49 defaultValue = _props.defaultValue,
50 prefixCls = _props.prefixCls,
51 pickerPrefixCls = _props.pickerPrefixCls,
52 clientHeight = _props.clientHeight;
53
54 var date = value || defaultValue || undefined;
55 var height = clientHeight && clientHeight * 3 / 8 - 52 || Number.POSITIVE_INFINITY;
56 return React.createElement(
57 'div',
58 { className: 'time-picker' },
59 React.createElement(
60 'div',
61 { className: 'title' },
62 title
63 ),
64 React.createElement(DateTimePicker, { prefixCls: prefixCls, pickerPrefixCls: pickerPrefixCls, style: {
65 height: height > 164 || height < 0 ? 164 : height,
66 overflow: 'hidden'
67 }, mode: 'time', date: date, locale: locale, minDate: this.getMinTime(date), maxDate: this.getMaxTime(date), onDateChange: this.onDateChange, use12Hours: true })
68 );
69 }
70 }]);
71
72 return TimePicker;
73}(React.PureComponent);
74
75export default TimePicker;
76
77TimePicker.defaultProps = {
78 minDate: new Date(0, 0, 0, 0, 0),
79 maxDate: new Date(9999, 11, 31, 23, 59, 59),
80 defaultValue: new Date(2000, 1, 1, 8)
81};
\No newline at end of file