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 _rcTrigger = _interopRequireDefault(require("rc-trigger"));
|
13 |
|
14 | var _moment = _interopRequireDefault(require("moment"));
|
15 |
|
16 | var _reactLifecyclesCompat = require("react-lifecycles-compat");
|
17 |
|
18 | var _classnames = _interopRequireDefault(require("classnames"));
|
19 |
|
20 | var _Panel = _interopRequireDefault(require("./Panel"));
|
21 |
|
22 | var _placements = _interopRequireDefault(require("./placements"));
|
23 |
|
24 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
25 |
|
26 | 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; } }
|
27 |
|
28 | function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
29 |
|
30 | function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
31 |
|
32 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
33 |
|
34 | 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); } }
|
35 |
|
36 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
37 |
|
38 | function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
39 |
|
40 | function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
41 |
|
42 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
43 |
|
44 | 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); }
|
45 |
|
46 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
47 |
|
48 | 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; }
|
49 |
|
50 | function noop() {}
|
51 |
|
52 | function refFn(field, component) {
|
53 | this[field] = component;
|
54 | }
|
55 |
|
56 | var Picker =
|
57 |
|
58 | function (_Component) {
|
59 | _inherits(Picker, _Component);
|
60 |
|
61 | function Picker(props) {
|
62 | var _this;
|
63 |
|
64 | _classCallCheck(this, Picker);
|
65 |
|
66 | _this = _possibleConstructorReturn(this, _getPrototypeOf(Picker).call(this, props));
|
67 |
|
68 | _defineProperty(_assertThisInitialized(_this), "onPanelChange", function (value) {
|
69 | _this.setValue(value);
|
70 | });
|
71 |
|
72 | _defineProperty(_assertThisInitialized(_this), "onAmPmChange", function (ampm) {
|
73 | var onAmPmChange = _this.props.onAmPmChange;
|
74 | onAmPmChange(ampm);
|
75 | });
|
76 |
|
77 | _defineProperty(_assertThisInitialized(_this), "onClear", function (event) {
|
78 | event.stopPropagation();
|
79 |
|
80 | _this.setValue(null);
|
81 |
|
82 | _this.setOpen(false);
|
83 | });
|
84 |
|
85 | _defineProperty(_assertThisInitialized(_this), "onVisibleChange", function (open) {
|
86 | _this.setOpen(open);
|
87 | });
|
88 |
|
89 | _defineProperty(_assertThisInitialized(_this), "onEsc", function () {
|
90 | _this.setOpen(false);
|
91 |
|
92 | _this.focus();
|
93 | });
|
94 |
|
95 | _defineProperty(_assertThisInitialized(_this), "onKeyDown", function (e) {
|
96 | if (e.keyCode === 40) {
|
97 | _this.setOpen(true);
|
98 | }
|
99 | });
|
100 |
|
101 | _this.saveInputRef = refFn.bind(_assertThisInitialized(_this), 'picker');
|
102 | _this.savePanelRef = refFn.bind(_assertThisInitialized(_this), 'panelInstance');
|
103 |
|
104 | var defaultOpen = props.defaultOpen,
|
105 | defaultValue = props.defaultValue,
|
106 | _props$open = props.open,
|
107 | _open = _props$open === void 0 ? defaultOpen : _props$open,
|
108 | _props$value = props.value,
|
109 | _value = _props$value === void 0 ? defaultValue : _props$value;
|
110 |
|
111 | _this.state = {
|
112 | open: _open,
|
113 | value: _value
|
114 | };
|
115 | return _this;
|
116 | }
|
117 |
|
118 | _createClass(Picker, [{
|
119 | key: "setValue",
|
120 | value: function setValue(value) {
|
121 | var onChange = this.props.onChange;
|
122 |
|
123 | if (!('value' in this.props)) {
|
124 | this.setState({
|
125 | value: value
|
126 | });
|
127 | }
|
128 |
|
129 | onChange(value);
|
130 | }
|
131 | }, {
|
132 | key: "getFormat",
|
133 | value: function getFormat() {
|
134 | var _this$props = this.props,
|
135 | format = _this$props.format,
|
136 | showHour = _this$props.showHour,
|
137 | showMinute = _this$props.showMinute,
|
138 | showSecond = _this$props.showSecond,
|
139 | use12Hours = _this$props.use12Hours;
|
140 |
|
141 | if (format) {
|
142 | return format;
|
143 | }
|
144 |
|
145 | if (use12Hours) {
|
146 | var fmtString = [showHour ? 'h' : '', showMinute ? 'mm' : '', showSecond ? 'ss' : ''].filter(function (item) {
|
147 | return !!item;
|
148 | }).join(':');
|
149 | return fmtString.concat(' a');
|
150 | }
|
151 |
|
152 | return [showHour ? 'HH' : '', showMinute ? 'mm' : '', showSecond ? 'ss' : ''].filter(function (item) {
|
153 | return !!item;
|
154 | }).join(':');
|
155 | }
|
156 | }, {
|
157 | key: "getPanelElement",
|
158 | value: function getPanelElement() {
|
159 | var _this$props2 = this.props,
|
160 | prefixCls = _this$props2.prefixCls,
|
161 | placeholder = _this$props2.placeholder,
|
162 | disabledHours = _this$props2.disabledHours,
|
163 | disabledMinutes = _this$props2.disabledMinutes,
|
164 | disabledSeconds = _this$props2.disabledSeconds,
|
165 | hideDisabledOptions = _this$props2.hideDisabledOptions,
|
166 | inputReadOnly = _this$props2.inputReadOnly,
|
167 | showHour = _this$props2.showHour,
|
168 | showMinute = _this$props2.showMinute,
|
169 | showSecond = _this$props2.showSecond,
|
170 | defaultOpenValue = _this$props2.defaultOpenValue,
|
171 | clearText = _this$props2.clearText,
|
172 | addon = _this$props2.addon,
|
173 | use12Hours = _this$props2.use12Hours,
|
174 | focusOnOpen = _this$props2.focusOnOpen,
|
175 | onKeyDown = _this$props2.onKeyDown,
|
176 | hourStep = _this$props2.hourStep,
|
177 | minuteStep = _this$props2.minuteStep,
|
178 | secondStep = _this$props2.secondStep,
|
179 | clearIcon = _this$props2.clearIcon;
|
180 | var value = this.state.value;
|
181 | return _react["default"].createElement(_Panel["default"], {
|
182 | clearText: clearText,
|
183 | prefixCls: "".concat(prefixCls, "-panel"),
|
184 | ref: this.savePanelRef,
|
185 | value: value,
|
186 | inputReadOnly: inputReadOnly,
|
187 | onChange: this.onPanelChange,
|
188 | onAmPmChange: this.onAmPmChange,
|
189 | defaultOpenValue: defaultOpenValue,
|
190 | showHour: showHour,
|
191 | showMinute: showMinute,
|
192 | showSecond: showSecond,
|
193 | onEsc: this.onEsc,
|
194 | format: this.getFormat(),
|
195 | placeholder: placeholder,
|
196 | disabledHours: disabledHours,
|
197 | disabledMinutes: disabledMinutes,
|
198 | disabledSeconds: disabledSeconds,
|
199 | hideDisabledOptions: hideDisabledOptions,
|
200 | use12Hours: use12Hours,
|
201 | hourStep: hourStep,
|
202 | minuteStep: minuteStep,
|
203 | secondStep: secondStep,
|
204 | addon: addon,
|
205 | focusOnOpen: focusOnOpen,
|
206 | onKeyDown: onKeyDown,
|
207 | clearIcon: clearIcon
|
208 | });
|
209 | }
|
210 | }, {
|
211 | key: "getPopupClassName",
|
212 | value: function getPopupClassName() {
|
213 | var _this$props3 = this.props,
|
214 | showHour = _this$props3.showHour,
|
215 | showMinute = _this$props3.showMinute,
|
216 | showSecond = _this$props3.showSecond,
|
217 | use12Hours = _this$props3.use12Hours,
|
218 | prefixCls = _this$props3.prefixCls,
|
219 | popupClassName = _this$props3.popupClassName;
|
220 | var selectColumnCount = 0;
|
221 |
|
222 | if (showHour) {
|
223 | selectColumnCount += 1;
|
224 | }
|
225 |
|
226 | if (showMinute) {
|
227 | selectColumnCount += 1;
|
228 | }
|
229 |
|
230 | if (showSecond) {
|
231 | selectColumnCount += 1;
|
232 | }
|
233 |
|
234 | if (use12Hours) {
|
235 | selectColumnCount += 1;
|
236 | }
|
237 |
|
238 |
|
239 | return (0, _classnames["default"])(popupClassName, _defineProperty({}, "".concat(prefixCls, "-panel-narrow"), (!showHour || !showMinute || !showSecond) && !use12Hours), "".concat(prefixCls, "-panel-column-").concat(selectColumnCount));
|
240 | }
|
241 | }, {
|
242 | key: "setOpen",
|
243 | value: function setOpen(open) {
|
244 | var _this$props4 = this.props,
|
245 | onOpen = _this$props4.onOpen,
|
246 | onClose = _this$props4.onClose;
|
247 | var currentOpen = this.state.open;
|
248 |
|
249 | if (currentOpen !== open) {
|
250 | if (!('open' in this.props)) {
|
251 | this.setState({
|
252 | open: open
|
253 | });
|
254 | }
|
255 |
|
256 | if (open) {
|
257 | onOpen({
|
258 | open: open
|
259 | });
|
260 | } else {
|
261 | onClose({
|
262 | open: open
|
263 | });
|
264 | }
|
265 | }
|
266 | }
|
267 | }, {
|
268 | key: "focus",
|
269 | value: function focus() {
|
270 | this.picker.focus();
|
271 | }
|
272 | }, {
|
273 | key: "blur",
|
274 | value: function blur() {
|
275 | this.picker.blur();
|
276 | }
|
277 | }, {
|
278 | key: "renderClearButton",
|
279 | value: function renderClearButton() {
|
280 | var _this2 = this;
|
281 |
|
282 | var value = this.state.value;
|
283 | var _this$props5 = this.props,
|
284 | prefixCls = _this$props5.prefixCls,
|
285 | allowEmpty = _this$props5.allowEmpty,
|
286 | clearIcon = _this$props5.clearIcon,
|
287 | clearText = _this$props5.clearText,
|
288 | disabled = _this$props5.disabled;
|
289 |
|
290 | if (!allowEmpty || !value || disabled) {
|
291 | return null;
|
292 | }
|
293 |
|
294 | if (_react["default"].isValidElement(clearIcon)) {
|
295 | var _ref = clearIcon.props || {},
|
296 | _onClick = _ref.onClick;
|
297 |
|
298 | return _react["default"].cloneElement(clearIcon, {
|
299 | onClick: function onClick() {
|
300 | if (_onClick) _onClick.apply(void 0, arguments);
|
301 |
|
302 | _this2.onClear.apply(_this2, arguments);
|
303 | }
|
304 | });
|
305 | }
|
306 |
|
307 | return _react["default"].createElement("a", {
|
308 | role: "button",
|
309 | className: "".concat(prefixCls, "-clear"),
|
310 | title: clearText,
|
311 | onClick: this.onClear,
|
312 | tabIndex: 0
|
313 | }, clearIcon || _react["default"].createElement("i", {
|
314 | className: "".concat(prefixCls, "-clear-icon")
|
315 | }));
|
316 | }
|
317 | }, {
|
318 | key: "render",
|
319 | value: function render() {
|
320 | var _this$props6 = this.props,
|
321 | prefixCls = _this$props6.prefixCls,
|
322 | placeholder = _this$props6.placeholder,
|
323 | placement = _this$props6.placement,
|
324 | align = _this$props6.align,
|
325 | id = _this$props6.id,
|
326 | disabled = _this$props6.disabled,
|
327 | transitionName = _this$props6.transitionName,
|
328 | style = _this$props6.style,
|
329 | className = _this$props6.className,
|
330 | getPopupContainer = _this$props6.getPopupContainer,
|
331 | name = _this$props6.name,
|
332 | autoComplete = _this$props6.autoComplete,
|
333 | onFocus = _this$props6.onFocus,
|
334 | onBlur = _this$props6.onBlur,
|
335 | autoFocus = _this$props6.autoFocus,
|
336 | inputReadOnly = _this$props6.inputReadOnly,
|
337 | inputIcon = _this$props6.inputIcon,
|
338 | popupStyle = _this$props6.popupStyle;
|
339 | var _this$state = this.state,
|
340 | open = _this$state.open,
|
341 | value = _this$state.value;
|
342 | var popupClassName = this.getPopupClassName();
|
343 | return _react["default"].createElement(_rcTrigger["default"], {
|
344 | prefixCls: "".concat(prefixCls, "-panel"),
|
345 | popupClassName: popupClassName,
|
346 | popupStyle: popupStyle,
|
347 | popup: this.getPanelElement(),
|
348 | popupAlign: align,
|
349 | builtinPlacements: _placements["default"],
|
350 | popupPlacement: placement,
|
351 | action: disabled ? [] : ['click'],
|
352 | destroyPopupOnHide: true,
|
353 | getPopupContainer: getPopupContainer,
|
354 | popupTransitionName: transitionName,
|
355 | popupVisible: open,
|
356 | onPopupVisibleChange: this.onVisibleChange
|
357 | }, _react["default"].createElement("span", {
|
358 | className: (0, _classnames["default"])(prefixCls, className),
|
359 | style: style
|
360 | }, _react["default"].createElement("input", {
|
361 | className: "".concat(prefixCls, "-input"),
|
362 | ref: this.saveInputRef,
|
363 | type: "text",
|
364 | placeholder: placeholder,
|
365 | name: name,
|
366 | onKeyDown: this.onKeyDown,
|
367 | disabled: disabled,
|
368 | value: value && value.format(this.getFormat()) || '',
|
369 | autoComplete: autoComplete,
|
370 | onFocus: onFocus,
|
371 | onBlur: onBlur,
|
372 | autoFocus: autoFocus,
|
373 | onChange: noop,
|
374 | readOnly: !!inputReadOnly,
|
375 | id: id
|
376 | }), inputIcon || _react["default"].createElement("span", {
|
377 | className: "".concat(prefixCls, "-icon")
|
378 | }), this.renderClearButton()));
|
379 | }
|
380 | }], [{
|
381 | key: "getDerivedStateFromProps",
|
382 | value: function getDerivedStateFromProps(props, state) {
|
383 | var newState = {};
|
384 |
|
385 | if ('value' in props) {
|
386 | newState.value = props.value;
|
387 | }
|
388 |
|
389 | if (props.open !== undefined) {
|
390 | newState.open = props.open;
|
391 | }
|
392 |
|
393 | return Object.keys(newState).length > 0 ? _objectSpread({}, state, {}, newState) : null;
|
394 | }
|
395 | }]);
|
396 |
|
397 | return Picker;
|
398 | }(_react.Component);
|
399 |
|
400 | _defineProperty(Picker, "propTypes", {
|
401 | prefixCls: _propTypes["default"].string,
|
402 | clearText: _propTypes["default"].string,
|
403 | value: _propTypes["default"].object,
|
404 | defaultOpenValue: _propTypes["default"].object,
|
405 | inputReadOnly: _propTypes["default"].bool,
|
406 | disabled: _propTypes["default"].bool,
|
407 | allowEmpty: _propTypes["default"].bool,
|
408 | defaultValue: _propTypes["default"].object,
|
409 | open: _propTypes["default"].bool,
|
410 | defaultOpen: _propTypes["default"].bool,
|
411 | align: _propTypes["default"].object,
|
412 | placement: _propTypes["default"].any,
|
413 | transitionName: _propTypes["default"].string,
|
414 | getPopupContainer: _propTypes["default"].func,
|
415 | placeholder: _propTypes["default"].string,
|
416 | format: _propTypes["default"].string,
|
417 | showHour: _propTypes["default"].bool,
|
418 | showMinute: _propTypes["default"].bool,
|
419 | showSecond: _propTypes["default"].bool,
|
420 | style: _propTypes["default"].object,
|
421 | className: _propTypes["default"].string,
|
422 | popupClassName: _propTypes["default"].string,
|
423 | popupStyle: _propTypes["default"].object,
|
424 | disabledHours: _propTypes["default"].func,
|
425 | disabledMinutes: _propTypes["default"].func,
|
426 | disabledSeconds: _propTypes["default"].func,
|
427 | hideDisabledOptions: _propTypes["default"].bool,
|
428 | onChange: _propTypes["default"].func,
|
429 | onAmPmChange: _propTypes["default"].func,
|
430 | onOpen: _propTypes["default"].func,
|
431 | onClose: _propTypes["default"].func,
|
432 | onFocus: _propTypes["default"].func,
|
433 | onBlur: _propTypes["default"].func,
|
434 | addon: _propTypes["default"].func,
|
435 | name: _propTypes["default"].string,
|
436 | autoComplete: _propTypes["default"].string,
|
437 | use12Hours: _propTypes["default"].bool,
|
438 | hourStep: _propTypes["default"].number,
|
439 | minuteStep: _propTypes["default"].number,
|
440 | secondStep: _propTypes["default"].number,
|
441 | focusOnOpen: _propTypes["default"].bool,
|
442 | onKeyDown: _propTypes["default"].func,
|
443 | autoFocus: _propTypes["default"].bool,
|
444 | id: _propTypes["default"].string,
|
445 | inputIcon: _propTypes["default"].node,
|
446 | clearIcon: _propTypes["default"].node
|
447 | });
|
448 |
|
449 | _defineProperty(Picker, "defaultProps", {
|
450 | clearText: 'clear',
|
451 | prefixCls: 'rc-time-picker',
|
452 | defaultOpen: false,
|
453 | inputReadOnly: false,
|
454 | style: {},
|
455 | className: '',
|
456 | popupClassName: '',
|
457 | popupStyle: {},
|
458 | id: '',
|
459 | align: {},
|
460 | defaultOpenValue: (0, _moment["default"])(),
|
461 | allowEmpty: true,
|
462 | showHour: true,
|
463 | showMinute: true,
|
464 | showSecond: true,
|
465 | disabledHours: noop,
|
466 | disabledMinutes: noop,
|
467 | disabledSeconds: noop,
|
468 | hideDisabledOptions: false,
|
469 | placement: 'bottomLeft',
|
470 | onChange: noop,
|
471 | onAmPmChange: noop,
|
472 | onOpen: noop,
|
473 | onClose: noop,
|
474 | onFocus: noop,
|
475 | onBlur: noop,
|
476 | addon: noop,
|
477 | use12Hours: false,
|
478 | focusOnOpen: false,
|
479 | onKeyDown: noop
|
480 | });
|
481 |
|
482 | (0, _reactLifecyclesCompat.polyfill)(Picker);
|
483 | var _default = Picker;
|
484 | exports["default"] = _default; |
\ | No newline at end of file |