1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports["default"] = void 0;
|
7 |
|
8 | var _react = _interopRequireWildcard(require("react"));
|
9 |
|
10 | var _propTypes = _interopRequireDefault(require("prop-types"));
|
11 |
|
12 | var _moment = _interopRequireDefault(require("moment"));
|
13 |
|
14 | var _classnames = _interopRequireDefault(require("classnames"));
|
15 |
|
16 | var _Header = _interopRequireDefault(require("./Header"));
|
17 |
|
18 | var _Combobox = _interopRequireDefault(require("./Combobox"));
|
19 |
|
20 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
21 |
|
22 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
|
23 |
|
24 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
25 |
|
26 | 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); } }
|
27 |
|
28 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
29 |
|
30 | function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
31 |
|
32 | function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
33 |
|
34 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
35 |
|
36 | 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); }
|
37 |
|
38 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
39 |
|
40 | 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; }
|
41 |
|
42 | function noop() {}
|
43 |
|
44 | function generateOptions(length, disabledOptions, hideDisabledOptions) {
|
45 | var step = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
|
46 | var arr = [];
|
47 |
|
48 | for (var value = 0; value < length; value += step) {
|
49 | if (!disabledOptions || disabledOptions.indexOf(value) < 0 || !hideDisabledOptions) {
|
50 | arr.push(value);
|
51 | }
|
52 | }
|
53 |
|
54 | return arr;
|
55 | }
|
56 |
|
57 | function toNearestValidTime(time, hourOptions, minuteOptions, secondOptions) {
|
58 | var hour = hourOptions.slice().sort(function (a, b) {
|
59 | return Math.abs(time.hour() - a) - Math.abs(time.hour() - b);
|
60 | })[0];
|
61 | var minute = minuteOptions.slice().sort(function (a, b) {
|
62 | return Math.abs(time.minute() - a) - Math.abs(time.minute() - b);
|
63 | })[0];
|
64 | var second = secondOptions.slice().sort(function (a, b) {
|
65 | return Math.abs(time.second() - a) - Math.abs(time.second() - b);
|
66 | })[0];
|
67 | return (0, _moment["default"])("".concat(hour, ":").concat(minute, ":").concat(second), 'HH:mm:ss');
|
68 | }
|
69 |
|
70 | var Panel =
|
71 |
|
72 | function (_Component) {
|
73 | _inherits(Panel, _Component);
|
74 |
|
75 | function Panel(props) {
|
76 | var _this;
|
77 |
|
78 | _classCallCheck(this, Panel);
|
79 |
|
80 | _this = _possibleConstructorReturn(this, _getPrototypeOf(Panel).call(this, props));
|
81 |
|
82 | _defineProperty(_assertThisInitialized(_this), "onChange", function (newValue) {
|
83 | var onChange = _this.props.onChange;
|
84 |
|
85 | _this.setState({
|
86 | value: newValue
|
87 | });
|
88 |
|
89 | onChange(newValue);
|
90 | });
|
91 |
|
92 | _defineProperty(_assertThisInitialized(_this), "onAmPmChange", function (ampm) {
|
93 | var onAmPmChange = _this.props.onAmPmChange;
|
94 | onAmPmChange(ampm);
|
95 | });
|
96 |
|
97 | _defineProperty(_assertThisInitialized(_this), "onCurrentSelectPanelChange", function (currentSelectPanel) {
|
98 | _this.setState({
|
99 | currentSelectPanel: currentSelectPanel
|
100 | });
|
101 | });
|
102 |
|
103 | _defineProperty(_assertThisInitialized(_this), "disabledHours", function () {
|
104 | var _this$props = _this.props,
|
105 | use12Hours = _this$props.use12Hours,
|
106 | disabledHours = _this$props.disabledHours;
|
107 | var disabledOptions = disabledHours();
|
108 |
|
109 | if (use12Hours && Array.isArray(disabledOptions)) {
|
110 | if (_this.isAM()) {
|
111 | disabledOptions = disabledOptions.filter(function (h) {
|
112 | return h < 12;
|
113 | }).map(function (h) {
|
114 | return h === 0 ? 12 : h;
|
115 | });
|
116 | } else {
|
117 | disabledOptions = disabledOptions.map(function (h) {
|
118 | return h === 12 ? 12 : h - 12;
|
119 | });
|
120 | }
|
121 | }
|
122 |
|
123 | return disabledOptions;
|
124 | });
|
125 |
|
126 | _this.state = {
|
127 | value: props.value
|
128 | };
|
129 | return _this;
|
130 | }
|
131 |
|
132 | _createClass(Panel, [{
|
133 | key: "componentWillReceiveProps",
|
134 | value: function componentWillReceiveProps(nextProps) {
|
135 | var value = nextProps.value;
|
136 |
|
137 | if (value) {
|
138 | this.setState({
|
139 | value: value
|
140 | });
|
141 | }
|
142 | }
|
143 | }, {
|
144 | key: "close",
|
145 |
|
146 | value: function close() {
|
147 | var onEsc = this.props.onEsc;
|
148 | onEsc();
|
149 | }
|
150 | }, {
|
151 | key: "isAM",
|
152 | value: function isAM() {
|
153 | var defaultOpenValue = this.props.defaultOpenValue;
|
154 | var value = this.state.value;
|
155 | var realValue = value || defaultOpenValue;
|
156 | return realValue.hour() >= 0 && realValue.hour() < 12;
|
157 | }
|
158 | }, {
|
159 | key: "render",
|
160 | value: function render() {
|
161 | var _this$props2 = this.props,
|
162 | prefixCls = _this$props2.prefixCls,
|
163 | className = _this$props2.className,
|
164 | placeholder = _this$props2.placeholder,
|
165 | disabledMinutes = _this$props2.disabledMinutes,
|
166 | disabledSeconds = _this$props2.disabledSeconds,
|
167 | hideDisabledOptions = _this$props2.hideDisabledOptions,
|
168 | showHour = _this$props2.showHour,
|
169 | showMinute = _this$props2.showMinute,
|
170 | showSecond = _this$props2.showSecond,
|
171 | format = _this$props2.format,
|
172 | defaultOpenValue = _this$props2.defaultOpenValue,
|
173 | clearText = _this$props2.clearText,
|
174 | onEsc = _this$props2.onEsc,
|
175 | addon = _this$props2.addon,
|
176 | use12Hours = _this$props2.use12Hours,
|
177 | focusOnOpen = _this$props2.focusOnOpen,
|
178 | onKeyDown = _this$props2.onKeyDown,
|
179 | hourStep = _this$props2.hourStep,
|
180 | minuteStep = _this$props2.minuteStep,
|
181 | secondStep = _this$props2.secondStep,
|
182 | inputReadOnly = _this$props2.inputReadOnly,
|
183 | clearIcon = _this$props2.clearIcon;
|
184 | var _this$state = this.state,
|
185 | value = _this$state.value,
|
186 | currentSelectPanel = _this$state.currentSelectPanel;
|
187 | var disabledHourOptions = this.disabledHours();
|
188 | var disabledMinuteOptions = disabledMinutes(value ? value.hour() : null);
|
189 | var disabledSecondOptions = disabledSeconds(value ? value.hour() : null, value ? value.minute() : null);
|
190 | var hourOptions = generateOptions(24, disabledHourOptions, hideDisabledOptions, hourStep);
|
191 | var minuteOptions = generateOptions(60, disabledMinuteOptions, hideDisabledOptions, minuteStep);
|
192 | var secondOptions = generateOptions(60, disabledSecondOptions, hideDisabledOptions, secondStep);
|
193 | var validDefaultOpenValue = toNearestValidTime(defaultOpenValue, hourOptions, minuteOptions, secondOptions);
|
194 | return _react["default"].createElement("div", {
|
195 | className: (0, _classnames["default"])(className, "".concat(prefixCls, "-inner"))
|
196 | }, _react["default"].createElement(_Header["default"], {
|
197 | clearText: clearText,
|
198 | prefixCls: prefixCls,
|
199 | defaultOpenValue: validDefaultOpenValue,
|
200 | value: value,
|
201 | currentSelectPanel: currentSelectPanel,
|
202 | onEsc: onEsc,
|
203 | format: format,
|
204 | placeholder: placeholder,
|
205 | hourOptions: hourOptions,
|
206 | minuteOptions: minuteOptions,
|
207 | secondOptions: secondOptions,
|
208 | disabledHours: this.disabledHours,
|
209 | disabledMinutes: disabledMinutes,
|
210 | disabledSeconds: disabledSeconds,
|
211 | onChange: this.onChange,
|
212 | focusOnOpen: focusOnOpen,
|
213 | onKeyDown: onKeyDown,
|
214 | inputReadOnly: inputReadOnly,
|
215 | clearIcon: clearIcon
|
216 | }), _react["default"].createElement(_Combobox["default"], {
|
217 | prefixCls: prefixCls,
|
218 | value: value,
|
219 | defaultOpenValue: validDefaultOpenValue,
|
220 | format: format,
|
221 | onChange: this.onChange,
|
222 | onAmPmChange: this.onAmPmChange,
|
223 | showHour: showHour,
|
224 | showMinute: showMinute,
|
225 | showSecond: showSecond,
|
226 | hourOptions: hourOptions,
|
227 | minuteOptions: minuteOptions,
|
228 | secondOptions: secondOptions,
|
229 | disabledHours: this.disabledHours,
|
230 | disabledMinutes: disabledMinutes,
|
231 | disabledSeconds: disabledSeconds,
|
232 | onCurrentSelectPanelChange: this.onCurrentSelectPanelChange,
|
233 | use12Hours: use12Hours,
|
234 | isAM: this.isAM()
|
235 | }), addon(this));
|
236 | }
|
237 | }]);
|
238 |
|
239 | return Panel;
|
240 | }(_react.Component);
|
241 |
|
242 | _defineProperty(Panel, "propTypes", {
|
243 | clearText: _propTypes["default"].string,
|
244 | prefixCls: _propTypes["default"].string,
|
245 | className: _propTypes["default"].string,
|
246 | defaultOpenValue: _propTypes["default"].object,
|
247 | value: _propTypes["default"].object,
|
248 | placeholder: _propTypes["default"].string,
|
249 | format: _propTypes["default"].string,
|
250 | inputReadOnly: _propTypes["default"].bool,
|
251 | disabledHours: _propTypes["default"].func,
|
252 | disabledMinutes: _propTypes["default"].func,
|
253 | disabledSeconds: _propTypes["default"].func,
|
254 | hideDisabledOptions: _propTypes["default"].bool,
|
255 | onChange: _propTypes["default"].func,
|
256 | onAmPmChange: _propTypes["default"].func,
|
257 | onEsc: _propTypes["default"].func,
|
258 | showHour: _propTypes["default"].bool,
|
259 | showMinute: _propTypes["default"].bool,
|
260 | showSecond: _propTypes["default"].bool,
|
261 | use12Hours: _propTypes["default"].bool,
|
262 | hourStep: _propTypes["default"].number,
|
263 | minuteStep: _propTypes["default"].number,
|
264 | secondStep: _propTypes["default"].number,
|
265 | addon: _propTypes["default"].func,
|
266 | focusOnOpen: _propTypes["default"].bool,
|
267 | onKeyDown: _propTypes["default"].func,
|
268 | clearIcon: _propTypes["default"].node
|
269 | });
|
270 |
|
271 | _defineProperty(Panel, "defaultProps", {
|
272 | prefixCls: 'rc-time-picker-panel',
|
273 | onChange: noop,
|
274 | disabledHours: noop,
|
275 | disabledMinutes: noop,
|
276 | disabledSeconds: noop,
|
277 | defaultOpenValue: (0, _moment["default"])(),
|
278 | use12Hours: false,
|
279 | addon: noop,
|
280 | onKeyDown: noop,
|
281 | onAmPmChange: noop,
|
282 | inputReadOnly: false
|
283 | });
|
284 |
|
285 | var _default = Panel;
|
286 | exports["default"] = _default; |
\ | No newline at end of file |