1 | import _extends from 'babel-runtime/helpers/extends';
|
2 | import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
|
3 | import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
4 | import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
5 | import _inherits from 'babel-runtime/helpers/inherits';
|
6 |
|
7 | var _class, _temp2;
|
8 |
|
9 | import React, { Component } from 'react';
|
10 | import PropTypes from 'prop-types';
|
11 | import classnames from 'classnames';
|
12 | import moment from 'moment';
|
13 | import nextLocale from '../locale/zh-cn';
|
14 | import { func } from '../util';
|
15 | import TimeMenu from './module/time-menu';
|
16 | import { checkMomentObj } from './utils';
|
17 |
|
18 | var noop = func.noop;
|
19 | var TimePickerPanel = (_temp2 = _class = function (_Component) {
|
20 | _inherits(TimePickerPanel, _Component);
|
21 |
|
22 | function TimePickerPanel() {
|
23 | var _temp, _this, _ret;
|
24 |
|
25 | _classCallCheck(this, TimePickerPanel);
|
26 |
|
27 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
28 | args[_key] = arguments[_key];
|
29 | }
|
30 |
|
31 | return _ret = (_temp = (_this = _possibleConstructorReturn(this, _Component.call.apply(_Component, [this].concat(args))), _this), _this.onSelectMenuItem = function (index, type) {
|
32 | var value = _this.props.value;
|
33 |
|
34 | var clonedValue = value ? value.clone() : moment('00:00:00', 'HH:mm:ss', true);
|
35 | switch (type) {
|
36 | case 'hour':
|
37 | clonedValue.hour(index);
|
38 | break;
|
39 | case 'minute':
|
40 | clonedValue.minute(index);
|
41 | break;
|
42 | case 'second':
|
43 | clonedValue.second(index);
|
44 | break;
|
45 | }
|
46 | _this.props.onSelect(clonedValue);
|
47 | }, _temp), _possibleConstructorReturn(_this, _ret);
|
48 | }
|
49 |
|
50 | TimePickerPanel.prototype.render = function render() {
|
51 | var _props = this.props,
|
52 | prefix = _props.prefix,
|
53 | value = _props.value,
|
54 | locale = _props.locale,
|
55 | className = _props.className,
|
56 | disabled = _props.disabled,
|
57 | showHour = _props.showHour,
|
58 | showMinute = _props.showMinute,
|
59 | showSecond = _props.showSecond,
|
60 | hourStep = _props.hourStep,
|
61 | minuteStep = _props.minuteStep,
|
62 | secondStep = _props.secondStep,
|
63 | disabledHours = _props.disabledHours,
|
64 | disabledMinutes = _props.disabledMinutes,
|
65 | disabledSeconds = _props.disabledSeconds,
|
66 | renderTimeMenuItems = _props.renderTimeMenuItems,
|
67 | others = _objectWithoutProperties(_props, ['prefix', 'value', 'locale', 'className', 'disabled', 'showHour', 'showMinute', 'showSecond', 'hourStep', 'minuteStep', 'secondStep', 'disabledHours', 'disabledMinutes', 'disabledSeconds', 'renderTimeMenuItems']);
|
68 |
|
69 | var colLen = [showHour, showMinute, showSecond].filter(function (v) {
|
70 | return v;
|
71 | }).length;
|
72 | var classNames = classnames(prefix + 'time-picker-panel', prefix + 'time-picker-panel-col-' + colLen, className);
|
73 |
|
74 | var commonProps = {
|
75 | prefix: prefix,
|
76 | disabled: disabled,
|
77 | onSelect: this.onSelectMenuItem,
|
78 | renderTimeMenuItems: renderTimeMenuItems,
|
79 | value: value
|
80 | };
|
81 |
|
82 | var activeHour = void 0;
|
83 | var activeMinute = void 0;
|
84 | var activeSecond = void 0;
|
85 |
|
86 | if (value && moment.isMoment(value)) {
|
87 | activeHour = value.hour();
|
88 | activeMinute = value.minute();
|
89 | activeSecond = value.second();
|
90 | }
|
91 |
|
92 | return React.createElement(
|
93 | 'div',
|
94 | _extends({}, others, { className: classNames }),
|
95 | showHour ? React.createElement(TimeMenu, _extends({}, commonProps, {
|
96 | activeIndex: activeHour,
|
97 | title: locale.hour,
|
98 | mode: 'hour',
|
99 | step: hourStep,
|
100 | disabledItems: disabledHours
|
101 | })) : null,
|
102 | showMinute ? React.createElement(TimeMenu, _extends({}, commonProps, {
|
103 | activeIndex: activeMinute,
|
104 | title: locale.minute,
|
105 | mode: 'minute',
|
106 | step: minuteStep,
|
107 | disabledItems: disabledMinutes
|
108 | })) : null,
|
109 | showSecond ? React.createElement(TimeMenu, _extends({}, commonProps, {
|
110 | activeIndex: activeSecond,
|
111 | title: locale.second,
|
112 | step: secondStep,
|
113 | mode: 'second',
|
114 | disabledItems: disabledSeconds
|
115 | })) : null
|
116 | );
|
117 | };
|
118 |
|
119 | return TimePickerPanel;
|
120 | }(Component), _class.propTypes = {
|
121 | prefix: PropTypes.string,
|
122 | |
123 |
|
124 |
|
125 | value: checkMomentObj,
|
126 | |
127 |
|
128 |
|
129 | showHour: PropTypes.bool,
|
130 | |
131 |
|
132 |
|
133 | showMinute: PropTypes.bool,
|
134 | |
135 |
|
136 |
|
137 | showSecond: PropTypes.bool,
|
138 | |
139 |
|
140 |
|
141 | hourStep: PropTypes.number,
|
142 | |
143 |
|
144 |
|
145 | minuteStep: PropTypes.number,
|
146 | |
147 |
|
148 |
|
149 | secondStep: PropTypes.number,
|
150 | |
151 |
|
152 |
|
153 |
|
154 |
|
155 | disabledHours: PropTypes.func,
|
156 | |
157 |
|
158 |
|
159 |
|
160 |
|
161 | disabledMinutes: PropTypes.func,
|
162 | |
163 |
|
164 |
|
165 |
|
166 |
|
167 | disabledSeconds: PropTypes.func,
|
168 | |
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 | renderTimeMenuItems: PropTypes.func,
|
180 | |
181 |
|
182 |
|
183 |
|
184 | onSelect: PropTypes.func,
|
185 | locale: PropTypes.object,
|
186 | disabled: PropTypes.bool,
|
187 | className: PropTypes.string
|
188 | }, _class.defaultProps = {
|
189 | prefix: 'next-',
|
190 | showHour: true,
|
191 | showSecond: true,
|
192 | showMinute: true,
|
193 | disabledHours: noop,
|
194 | disabledMinutes: noop,
|
195 | disabledSeconds: noop,
|
196 | onSelect: noop,
|
197 | disabled: false,
|
198 | locale: nextLocale.TimePicker
|
199 | }, _temp2);
|
200 | TimePickerPanel.displayName = 'TimePickerPanel';
|
201 |
|
202 |
|
203 | export default TimePickerPanel; |
\ | No newline at end of file |