1 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
2 |
|
3 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
4 |
|
5 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
6 |
|
7 | function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
8 |
|
9 | function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
10 |
|
11 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
12 |
|
13 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
14 |
|
15 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
16 |
|
17 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
18 |
|
19 | import React, { Component } from 'react';
|
20 | import PropTypes from 'prop-types';
|
21 | import Select from './Select';
|
22 |
|
23 | var formatOption = function formatOption(option, disabledOptions) {
|
24 | var value = "".concat(option);
|
25 |
|
26 | if (option < 10) {
|
27 | value = "0".concat(option);
|
28 | }
|
29 |
|
30 | var disabled = false;
|
31 |
|
32 | if (disabledOptions && disabledOptions.indexOf(option) >= 0) {
|
33 | disabled = true;
|
34 | }
|
35 |
|
36 | return {
|
37 | value: value,
|
38 | disabled: disabled
|
39 | };
|
40 | };
|
41 |
|
42 | var Combobox =
|
43 |
|
44 | function (_Component) {
|
45 | _inherits(Combobox, _Component);
|
46 |
|
47 | function Combobox() {
|
48 | var _getPrototypeOf2;
|
49 |
|
50 | var _this;
|
51 |
|
52 | _classCallCheck(this, Combobox);
|
53 |
|
54 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
55 | args[_key] = arguments[_key];
|
56 | }
|
57 |
|
58 | _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(Combobox)).call.apply(_getPrototypeOf2, [this].concat(args)));
|
59 |
|
60 | _defineProperty(_assertThisInitialized(_this), "onItemChange", function (type, itemValue) {
|
61 | var _this$props = _this.props,
|
62 | onChange = _this$props.onChange,
|
63 | defaultOpenValue = _this$props.defaultOpenValue,
|
64 | use12Hours = _this$props.use12Hours,
|
65 | propValue = _this$props.value,
|
66 | isAM = _this$props.isAM,
|
67 | onAmPmChange = _this$props.onAmPmChange;
|
68 | var value = (propValue || defaultOpenValue).clone();
|
69 |
|
70 | if (type === 'hour') {
|
71 | if (use12Hours) {
|
72 | if (isAM) {
|
73 | value.hour(+itemValue % 12);
|
74 | } else {
|
75 | value.hour(+itemValue % 12 + 12);
|
76 | }
|
77 | } else {
|
78 | value.hour(+itemValue);
|
79 | }
|
80 | } else if (type === 'minute') {
|
81 | value.minute(+itemValue);
|
82 | } else if (type === 'ampm') {
|
83 | var ampm = itemValue.toUpperCase();
|
84 |
|
85 | if (use12Hours) {
|
86 | if (ampm === 'PM' && value.hour() < 12) {
|
87 | value.hour(value.hour() % 12 + 12);
|
88 | }
|
89 |
|
90 | if (ampm === 'AM') {
|
91 | if (value.hour() >= 12) {
|
92 | value.hour(value.hour() - 12);
|
93 | }
|
94 | }
|
95 | }
|
96 |
|
97 | onAmPmChange(ampm);
|
98 | } else {
|
99 | value.second(+itemValue);
|
100 | }
|
101 |
|
102 | onChange(value);
|
103 | });
|
104 |
|
105 | _defineProperty(_assertThisInitialized(_this), "onEnterSelectPanel", function (range) {
|
106 | var onCurrentSelectPanelChange = _this.props.onCurrentSelectPanelChange;
|
107 | onCurrentSelectPanelChange(range);
|
108 | });
|
109 |
|
110 | return _this;
|
111 | }
|
112 |
|
113 | _createClass(Combobox, [{
|
114 | key: "getHourSelect",
|
115 | value: function getHourSelect(hour) {
|
116 | var _this2 = this;
|
117 |
|
118 | var _this$props2 = this.props,
|
119 | prefixCls = _this$props2.prefixCls,
|
120 | hourOptions = _this$props2.hourOptions,
|
121 | disabledHours = _this$props2.disabledHours,
|
122 | showHour = _this$props2.showHour,
|
123 | use12Hours = _this$props2.use12Hours;
|
124 |
|
125 | if (!showHour) {
|
126 | return null;
|
127 | }
|
128 |
|
129 | var disabledOptions = disabledHours();
|
130 | var hourOptionsAdj;
|
131 | var hourAdj;
|
132 |
|
133 | if (use12Hours) {
|
134 | hourOptionsAdj = [12].concat(hourOptions.filter(function (h) {
|
135 | return h < 12 && h > 0;
|
136 | }));
|
137 | hourAdj = hour % 12 || 12;
|
138 | } else {
|
139 | hourOptionsAdj = hourOptions;
|
140 | hourAdj = hour;
|
141 | }
|
142 |
|
143 | return React.createElement(Select, {
|
144 | prefixCls: prefixCls,
|
145 | options: hourOptionsAdj.map(function (option) {
|
146 | return formatOption(option, disabledOptions);
|
147 | }),
|
148 | selectedIndex: hourOptionsAdj.indexOf(hourAdj),
|
149 | type: "hour",
|
150 | onSelect: this.onItemChange,
|
151 | onMouseEnter: function onMouseEnter() {
|
152 | return _this2.onEnterSelectPanel('hour');
|
153 | }
|
154 | });
|
155 | }
|
156 | }, {
|
157 | key: "getMinuteSelect",
|
158 | value: function getMinuteSelect(minute) {
|
159 | var _this3 = this;
|
160 |
|
161 | var _this$props3 = this.props,
|
162 | prefixCls = _this$props3.prefixCls,
|
163 | minuteOptions = _this$props3.minuteOptions,
|
164 | disabledMinutes = _this$props3.disabledMinutes,
|
165 | defaultOpenValue = _this$props3.defaultOpenValue,
|
166 | showMinute = _this$props3.showMinute,
|
167 | propValue = _this$props3.value;
|
168 |
|
169 | if (!showMinute) {
|
170 | return null;
|
171 | }
|
172 |
|
173 | var value = propValue || defaultOpenValue;
|
174 | var disabledOptions = disabledMinutes(value.hour());
|
175 | return React.createElement(Select, {
|
176 | prefixCls: prefixCls,
|
177 | options: minuteOptions.map(function (option) {
|
178 | return formatOption(option, disabledOptions);
|
179 | }),
|
180 | selectedIndex: minuteOptions.indexOf(minute),
|
181 | type: "minute",
|
182 | onSelect: this.onItemChange,
|
183 | onMouseEnter: function onMouseEnter() {
|
184 | return _this3.onEnterSelectPanel('minute');
|
185 | }
|
186 | });
|
187 | }
|
188 | }, {
|
189 | key: "getSecondSelect",
|
190 | value: function getSecondSelect(second) {
|
191 | var _this4 = this;
|
192 |
|
193 | var _this$props4 = this.props,
|
194 | prefixCls = _this$props4.prefixCls,
|
195 | secondOptions = _this$props4.secondOptions,
|
196 | disabledSeconds = _this$props4.disabledSeconds,
|
197 | showSecond = _this$props4.showSecond,
|
198 | defaultOpenValue = _this$props4.defaultOpenValue,
|
199 | propValue = _this$props4.value;
|
200 |
|
201 | if (!showSecond) {
|
202 | return null;
|
203 | }
|
204 |
|
205 | var value = propValue || defaultOpenValue;
|
206 | var disabledOptions = disabledSeconds(value.hour(), value.minute());
|
207 | return React.createElement(Select, {
|
208 | prefixCls: prefixCls,
|
209 | options: secondOptions.map(function (option) {
|
210 | return formatOption(option, disabledOptions);
|
211 | }),
|
212 | selectedIndex: secondOptions.indexOf(second),
|
213 | type: "second",
|
214 | onSelect: this.onItemChange,
|
215 | onMouseEnter: function onMouseEnter() {
|
216 | return _this4.onEnterSelectPanel('second');
|
217 | }
|
218 | });
|
219 | }
|
220 | }, {
|
221 | key: "getAMPMSelect",
|
222 | value: function getAMPMSelect() {
|
223 | var _this5 = this;
|
224 |
|
225 | var _this$props5 = this.props,
|
226 | prefixCls = _this$props5.prefixCls,
|
227 | use12Hours = _this$props5.use12Hours,
|
228 | format = _this$props5.format,
|
229 | isAM = _this$props5.isAM;
|
230 |
|
231 | if (!use12Hours) {
|
232 | return null;
|
233 | }
|
234 |
|
235 | var AMPMOptions = ['am', 'pm']
|
236 | .map(function (c) {
|
237 | return format.match(/\sA/) ? c.toUpperCase() : c;
|
238 | }).map(function (c) {
|
239 | return {
|
240 | value: c
|
241 | };
|
242 | });
|
243 | var selected = isAM ? 0 : 1;
|
244 | return React.createElement(Select, {
|
245 | prefixCls: prefixCls,
|
246 | options: AMPMOptions,
|
247 | selectedIndex: selected,
|
248 | type: "ampm",
|
249 | onSelect: this.onItemChange,
|
250 | onMouseEnter: function onMouseEnter() {
|
251 | return _this5.onEnterSelectPanel('ampm');
|
252 | }
|
253 | });
|
254 | }
|
255 | }, {
|
256 | key: "render",
|
257 | value: function render() {
|
258 | var _this$props6 = this.props,
|
259 | prefixCls = _this$props6.prefixCls,
|
260 | defaultOpenValue = _this$props6.defaultOpenValue,
|
261 | propValue = _this$props6.value;
|
262 | var value = propValue || defaultOpenValue;
|
263 | return React.createElement("div", {
|
264 | className: "".concat(prefixCls, "-combobox")
|
265 | }, this.getHourSelect(value.hour()), this.getMinuteSelect(value.minute()), this.getSecondSelect(value.second()), this.getAMPMSelect(value.hour()));
|
266 | }
|
267 | }]);
|
268 |
|
269 | return Combobox;
|
270 | }(Component);
|
271 |
|
272 | _defineProperty(Combobox, "propTypes", {
|
273 | format: PropTypes.string,
|
274 | defaultOpenValue: PropTypes.object,
|
275 | prefixCls: PropTypes.string,
|
276 | value: PropTypes.object,
|
277 | onChange: PropTypes.func,
|
278 | onAmPmChange: PropTypes.func,
|
279 | showHour: PropTypes.bool,
|
280 | showMinute: PropTypes.bool,
|
281 | showSecond: PropTypes.bool,
|
282 | hourOptions: PropTypes.array,
|
283 | minuteOptions: PropTypes.array,
|
284 | secondOptions: PropTypes.array,
|
285 | disabledHours: PropTypes.func,
|
286 | disabledMinutes: PropTypes.func,
|
287 | disabledSeconds: PropTypes.func,
|
288 | onCurrentSelectPanelChange: PropTypes.func,
|
289 | use12Hours: PropTypes.bool,
|
290 | isAM: PropTypes.bool
|
291 | });
|
292 |
|
293 | export default Combobox; |
\ | No newline at end of file |