UNPKG

hy-checkbox

Version:

checkbox & radio ui components for react

167 lines (129 loc) 7.29 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); 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 _classnames = require('classnames'); var _classnames2 = _interopRequireDefault(_classnames); var _Input = require('../Input'); var _Input2 = _interopRequireDefault(_Input); require('rc-calendar/assets/index.css'); var _MonthCalendar = require('rc-calendar/lib/MonthCalendar'); var _MonthCalendar2 = _interopRequireDefault(_MonthCalendar); var _Picker = require('rc-calendar/lib/Picker'); var _Picker2 = _interopRequireDefault(_Picker); var _zh_CN = require('rc-calendar/lib/locale/zh_CN'); var _zh_CN2 = _interopRequireDefault(_zh_CN); var _moment = require('moment'); var _moment2 = _interopRequireDefault(_moment); require('moment/locale/zh-cn'); 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; } /* * @Author: SiMeiyu * @Date: 2017-07-04 09:59:49 */ var format = 'YYYY-MM'; var now = (0, _moment2.default)(); now.locale('zh-cn').utcOffset(8); var defaultCalendarValue = now.clone(); // defaultCalendarValue.add(-1, 'month'); function disabledDate(current) { if (!current) { // allow empty select return false; } var date = (0, _moment2.default)(); return current.year() < date.year() || current.year() === date.year() && current.month() < date.month(); // can not select days before today } var MonthPicker = function (_React$Component) { _inherits(MonthPicker, _React$Component); function MonthPicker(props) { _classCallCheck(this, MonthPicker); var _this = _possibleConstructorReturn(this, (MonthPicker.__proto__ || Object.getPrototypeOf(MonthPicker)).call(this, props)); _this.onChange = _this.onChange.bind(_this); _this.state = { value: _this.props.defaultValue }; return _this; } _createClass(MonthPicker, [{ key: 'onChange', value: function onChange(value) { console.log('DatePicker change: ' + (value && value.format(format))); this.setState({ value: value }); } }, { key: 'renderCalendar', value: function renderCalendar() { var _props = this.props, prefixCls = _props.prefixCls, isDisabledBefore = _props.isDisabledBefore; return _react2.default.createElement(_MonthCalendar2.default, { className: prefixCls + '-monthPicker-calendar', defaultValue: defaultCalendarValue, disabledDate: isDisabledBefore ? disabledDate : null, locale: _zh_CN2.default, style: { zIndex: 1000 } }); } }, { key: 'render', value: function render() { var _props2 = this.props, prefixCls = _props2.prefixCls, className = _props2.className, icon = _props2.icon, iconRight = _props2.iconRight, disabled = _props2.disabled, placeholder = _props2.placeholder; var value = this.state.value; var classes = (0, _classnames2.default)(prefixCls + '-monthPicker-input', className); return _react2.default.createElement( _Picker2.default, { animation: 'slide-up', disabled: disabled, calendar: this.renderCalendar(), value: value, onChange: this.onChange }, function (_ref) { var value = _ref.value; return _react2.default.createElement(_Input2.default, { className: classes, readOnly: true, disabled: disabled, value: value && value.format(format), placeholder: placeholder, icon: icon || null, iconRight: iconRight || null }); } ); } }]); return MonthPicker; }(_react2.default.Component); MonthPicker.propTypes = { prefixCls: _react2.default.PropTypes.string, className: _react2.default.PropTypes.string, defaultValue: _react2.default.PropTypes.object, disabled: _react2.default.PropTypes.bool, isDisabledBefore: _react2.default.PropTypes.bool, iconRight: _react2.default.PropTypes.bool, icon: _react2.default.PropTypes.string }; MonthPicker.defaultProps = { showTime: false, disabled: false, isDisabledBefore: true, prefixCls: 'ult', placeholder: '请选择月份' }; exports.default = MonthPicker;