custom-app
Version:
ITIMS��Ʒ�鿪��ר��React���,�Dz��ý��ּ�dhcc-app���������
270 lines (237 loc) • 10.3 kB
JavaScript
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
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); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
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; }
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import moment from 'moment';
import classNames from 'classnames';
import Header from './Header';
import Combobox from './Combobox';
function noop() {}
function generateOptions(length, disabledOptions, hideDisabledOptions) {
var step = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
var arr = [];
for (var value = 0; value < length; value += step) {
if (!disabledOptions || disabledOptions.indexOf(value) < 0 || !hideDisabledOptions) {
arr.push(value);
}
}
return arr;
}
function toNearestValidTime(time, hourOptions, minuteOptions, secondOptions) {
var hour = hourOptions.slice().sort(function (a, b) {
return Math.abs(time.hour() - a) - Math.abs(time.hour() - b);
})[0];
var minute = minuteOptions.slice().sort(function (a, b) {
return Math.abs(time.minute() - a) - Math.abs(time.minute() - b);
})[0];
var second = secondOptions.slice().sort(function (a, b) {
return Math.abs(time.second() - a) - Math.abs(time.second() - b);
})[0];
return moment("".concat(hour, ":").concat(minute, ":").concat(second), 'HH:mm:ss');
}
var Panel =
/*#__PURE__*/
function (_Component) {
_inherits(Panel, _Component);
function Panel(props) {
var _this;
_classCallCheck(this, Panel);
_this = _possibleConstructorReturn(this, _getPrototypeOf(Panel).call(this, props));
_defineProperty(_assertThisInitialized(_this), "onChange", function (newValue) {
var onChange = _this.props.onChange;
_this.setState({
value: newValue
});
onChange(newValue);
});
_defineProperty(_assertThisInitialized(_this), "onAmPmChange", function (ampm) {
var onAmPmChange = _this.props.onAmPmChange;
onAmPmChange(ampm);
});
_defineProperty(_assertThisInitialized(_this), "onCurrentSelectPanelChange", function (currentSelectPanel) {
_this.setState({
currentSelectPanel: currentSelectPanel
});
});
_defineProperty(_assertThisInitialized(_this), "disabledHours", function () {
var _this$props = _this.props,
use12Hours = _this$props.use12Hours,
disabledHours = _this$props.disabledHours;
var disabledOptions = disabledHours();
if (use12Hours && Array.isArray(disabledOptions)) {
if (_this.isAM()) {
disabledOptions = disabledOptions.filter(function (h) {
return h < 12;
}).map(function (h) {
return h === 0 ? 12 : h;
});
} else {
disabledOptions = disabledOptions.map(function (h) {
return h === 12 ? 12 : h - 12;
});
}
}
return disabledOptions;
});
_this.state = {
value: props.value
};
return _this;
}
_createClass(Panel, [{
key: "componentWillReceiveProps",
value: function componentWillReceiveProps(nextProps) {
var value = nextProps.value;
if (value) {
this.setState({
value: value
});
}
}
}, {
key: "close",
// https://github.com/ant-design/ant-design/issues/5829
value: function close() {
var onEsc = this.props.onEsc;
onEsc();
}
}, {
key: "isAM",
value: function isAM() {
var defaultOpenValue = this.props.defaultOpenValue;
var value = this.state.value;
var realValue = value || defaultOpenValue;
return realValue.hour() >= 0 && realValue.hour() < 12;
}
}, {
key: "render",
value: function render() {
var _this$props2 = this.props,
prefixCls = _this$props2.prefixCls,
className = _this$props2.className,
placeholder = _this$props2.placeholder,
disabledMinutes = _this$props2.disabledMinutes,
disabledSeconds = _this$props2.disabledSeconds,
hideDisabledOptions = _this$props2.hideDisabledOptions,
showHour = _this$props2.showHour,
showMinute = _this$props2.showMinute,
showSecond = _this$props2.showSecond,
format = _this$props2.format,
defaultOpenValue = _this$props2.defaultOpenValue,
clearText = _this$props2.clearText,
onEsc = _this$props2.onEsc,
addon = _this$props2.addon,
use12Hours = _this$props2.use12Hours,
focusOnOpen = _this$props2.focusOnOpen,
onKeyDown = _this$props2.onKeyDown,
hourStep = _this$props2.hourStep,
minuteStep = _this$props2.minuteStep,
secondStep = _this$props2.secondStep,
inputReadOnly = _this$props2.inputReadOnly,
clearIcon = _this$props2.clearIcon;
var _this$state = this.state,
value = _this$state.value,
currentSelectPanel = _this$state.currentSelectPanel;
var disabledHourOptions = this.disabledHours();
var disabledMinuteOptions = disabledMinutes(value ? value.hour() : null);
var disabledSecondOptions = disabledSeconds(value ? value.hour() : null, value ? value.minute() : null);
var hourOptions = generateOptions(24, disabledHourOptions, hideDisabledOptions, hourStep);
var minuteOptions = generateOptions(60, disabledMinuteOptions, hideDisabledOptions, minuteStep);
var secondOptions = generateOptions(60, disabledSecondOptions, hideDisabledOptions, secondStep);
var validDefaultOpenValue = toNearestValidTime(defaultOpenValue, hourOptions, minuteOptions, secondOptions);
return React.createElement("div", {
className: classNames(className, "".concat(prefixCls, "-inner"))
}, React.createElement(Header, {
clearText: clearText,
prefixCls: prefixCls,
defaultOpenValue: validDefaultOpenValue,
value: value,
currentSelectPanel: currentSelectPanel,
onEsc: onEsc,
format: format,
placeholder: placeholder,
hourOptions: hourOptions,
minuteOptions: minuteOptions,
secondOptions: secondOptions,
disabledHours: this.disabledHours,
disabledMinutes: disabledMinutes,
disabledSeconds: disabledSeconds,
onChange: this.onChange,
focusOnOpen: focusOnOpen,
onKeyDown: onKeyDown,
inputReadOnly: inputReadOnly,
clearIcon: clearIcon
}), React.createElement(Combobox, {
prefixCls: prefixCls,
value: value,
defaultOpenValue: validDefaultOpenValue,
format: format,
onChange: this.onChange,
onAmPmChange: this.onAmPmChange,
showHour: showHour,
showMinute: showMinute,
showSecond: showSecond,
hourOptions: hourOptions,
minuteOptions: minuteOptions,
secondOptions: secondOptions,
disabledHours: this.disabledHours,
disabledMinutes: disabledMinutes,
disabledSeconds: disabledSeconds,
onCurrentSelectPanelChange: this.onCurrentSelectPanelChange,
use12Hours: use12Hours,
onEsc: onEsc,
isAM: this.isAM()
}), addon(this));
}
}]);
return Panel;
}(Component);
_defineProperty(Panel, "propTypes", {
clearText: PropTypes.string,
prefixCls: PropTypes.string,
className: PropTypes.string,
defaultOpenValue: PropTypes.object,
value: PropTypes.object,
placeholder: PropTypes.string,
format: PropTypes.string,
inputReadOnly: PropTypes.bool,
disabledHours: PropTypes.func,
disabledMinutes: PropTypes.func,
disabledSeconds: PropTypes.func,
hideDisabledOptions: PropTypes.bool,
onChange: PropTypes.func,
onAmPmChange: PropTypes.func,
onEsc: PropTypes.func,
showHour: PropTypes.bool,
showMinute: PropTypes.bool,
showSecond: PropTypes.bool,
use12Hours: PropTypes.bool,
hourStep: PropTypes.number,
minuteStep: PropTypes.number,
secondStep: PropTypes.number,
addon: PropTypes.func,
focusOnOpen: PropTypes.bool,
onKeyDown: PropTypes.func,
clearIcon: PropTypes.node
});
_defineProperty(Panel, "defaultProps", {
prefixCls: 'rc-time-picker-panel',
onChange: noop,
disabledHours: noop,
disabledMinutes: noop,
disabledSeconds: noop,
defaultOpenValue: moment(),
use12Hours: false,
addon: noop,
onKeyDown: noop,
onAmPmChange: noop,
inputReadOnly: false
});
export default Panel;