UNPKG

zent

Version:

一套前端设计语言和基于React的实现

136 lines (105 loc) 4.98 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports['default'] = undefined; var _createClass = 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _PanelHeader = require('../common/PanelHeader'); var _PanelHeader2 = _interopRequireDefault(_PanelHeader); var _DatePanelBody = require('./DatePanelBody'); var _DatePanelBody2 = _interopRequireDefault(_DatePanelBody); var _MonthPanel = require('../month/MonthPanel'); var _MonthPanel2 = _interopRequireDefault(_MonthPanel); var _TimePanel = require('../time/TimePanel'); var _TimePanel2 = _interopRequireDefault(_TimePanel); var _utils = require('../utils/'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var DatePanel = function (_Component) { _inherits(DatePanel, _Component); function DatePanel(props) { _classCallCheck(this, DatePanel); var _this = _possibleConstructorReturn(this, (DatePanel.__proto__ || Object.getPrototypeOf(DatePanel)).call(this, props)); _this.prevMonth = function () { var prev = (0, _utils.goMonths)(_this.props.actived, -1); _this.props.onChange(prev); }; _this.nextMonth = function () { var next = (0, _utils.goMonths)(_this.props.actived, 1); _this.props.onChange(next); }; _this.showMonth = function () { _this.setState({ showMonth: true, showTime: false }); }; _this.onSelectMonth = function (val, hide) { _this.props.onChange(val); _this.setState({ showMonth: hide || false, showTime: _this.props.showTime !== undefined && !hide }); }; _this.state = { showTime: props.showTime !== undefined, showMonth: false }; return _this; } /* * 在 monthPicker 的时候选择年不隐藏 monthPanel. */ _createClass(DatePanel, [{ key: 'render', value: function render() { var state = this.state; var props = this.props; var title = props.actived.getFullYear() + '\u5E74' + (props.actived.getMonth() + 1) + '\u6708'; var monthPanel = void 0; var timePanel = void 0; if (state.showMonth) { monthPanel = _react2['default'].createElement(_MonthPanel2['default'], { actived: props.actived, selected: props.selected, onSelect: this.onSelectMonth }); } if (props.showTime) { timePanel = _react2['default'].createElement(_TimePanel2['default'], { actived: props.showTime.actived, format: props.showTime.format, disabledTime: props.showTime.disabledTime, onChange: props.showTime.onChange }); } return _react2['default'].createElement( 'div', { className: 'date-panel' }, _react2['default'].createElement(_PanelHeader2['default'], { title: title, onClick: this.showMonth, prev: this.prevMonth, next: this.nextMonth }), _react2['default'].createElement(_DatePanelBody2['default'], { actived: props.actived, range: props.range, selected: props.selected, disabledDate: props.disabledDate, onSelect: props.onSelect, onHover: props.onHover }), state.showMonth ? monthPanel : '', state.showTime ? timePanel : '' ); } }]); return DatePanel; }(_react.Component); exports['default'] = DatePanel; module.exports = exports['default'];