1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 8× 1× 9× 3× 3× 1× 1× 1× 1× 1× 1× 1× 1× 3× 3× 3× 3× 3× 3× 1× 1× 4× 4× 4× 4× 4× 1× 1× 3× 3× 3× 1× 1× 3× 3× 3× 3× 3× 3× 1× 1× 1× 2× 2× 3× 1× 1× 1× 2× 2× 3× 3× 3× 3× 3× 3× 3× 3× 3× 3× 2× 1× 3× 1× 1× 1× 1× 1× 1× | 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _propTypes = require('prop-types'); var _propTypes2 = _interopRequireDefault(_propTypes); var _moment = require('moment'); var _moment2 = _interopRequireDefault(_moment); var _uxcoreIcon = require('uxcore-icon'); var _uxcoreIcon2 = _interopRequireDefault(_uxcoreIcon); var _classnames4 = require('classnames'); var _classnames5 = _interopRequireDefault(_classnames4); var _Picker = require('rc-calendar/lib/Picker'); var _Picker2 = _interopRequireDefault(_Picker); var _RcYearCalendar = require('./RcYearCalendar'); var _RcYearCalendar2 = _interopRequireDefault(_RcYearCalendar); var _util = require('./util'); var _util2 = _interopRequireDefault(_util); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } function _defineProperty(obj, key, value) { Iif (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _classCallCheck(instance, Constructor) { Iif (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { Iif (!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) { Iif (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 } }); Eif (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); } var CalendarLocale = {}; CalendarLocale['zh-cn'] = require('rc-calendar/lib/locale/zh_CN'); CalendarLocale['en-us'] = require('rc-calendar/lib/locale/en_US'); var getCalendarContainer = _util2['default'].getCalendarContainer, generalizeFormat = _util2['default'].generalizeFormat; var YearCalendar = function (_React$Component) { _inherits(YearCalendar, _React$Component); function YearCalendar(props) { _classCallCheck(this, YearCalendar); var _this = _possibleConstructorReturn(this, _React$Component.call(this, props)); _this.state = {}; _this.clearValue = _this.clearValue.bind(_this); _this.handleChange = _this.handleChange.bind(_this); return _this; } YearCalendar.prototype.getTriggerNode = function getTriggerNode() { return this.trigger; }; YearCalendar.prototype.getDate = function getDate(date) { var me = this; var _me$props = me.props, timezone = _me$props.timezone, locale = _me$props.locale; var value = (0, _moment2['default'])(date).locale(locale); Iif (timezone) { return value.utcOffset(parseInt(timezone, 10) * 60); } return value; }; YearCalendar.prototype.clearValue = function clearValue(e) { e.stopPropagation(); this.props.onSelect(null, null); }; YearCalendar.prototype.saveRef = function saveRef(refName) { var me = this; return function (c) { me[refName] = c; }; }; YearCalendar.prototype.handleChange = function handleChange(v) { var p = this.props; if (v) { var date = v.valueOf(); this.props.onSelect(new Date(date), v.format(p.format)); } else { this.props.onSelect(v, v); } }; YearCalendar.prototype.render = function render() { var _this2 = this; var me = this; var p = me.props; var calendarOptions = { className: (0, _classnames5['default'])(p.className, _defineProperty({}, 'kuma-calendar-' + p.size, !!p.size)), style: p.style, locale: CalendarLocale[p.locale], showDateInput: p.showDateInput, orient: ['top', 'left'], prefixCls: 'kuma-calendar' }; var pickerOptions = { disabled: p.disabled, align: p.align, transitionName: p.transitionName, onOpenChange: p.onOpenChange, adjustOrientOnCalendarOverflow: false, prefixCls: 'kuma-calendar-picker', getCalendarContainer: p.getPopupContainer || getCalendarContainer }; if (p.value) { var value = this.getDate(p.value); pickerOptions.value = value; calendarOptions.defaultValue = value; } else { pickerOptions.value = null; // calendarOptions.defaultValue = null; calendarOptions.value = p.defaultOpenValue ? this.getDate(p.defaultOpenValue) : null; } if (p.defaultValue) { var _value = this.getDate(p.defaultValue); calendarOptions.defaultValue = _value; pickerOptions.defaultValue = _value; } else { var _value2 = this.getDate(new Date().getTime()); calendarOptions.defaultValue = _value2; } var calendar = _react2['default'].createElement(_RcYearCalendar2['default'], calendarOptions); var triggerStyle = {}; Iif (p.inputWidth) { triggerStyle.width = p.inputWidth; } var inputClassName = (0, _classnames5['default'])('kuma-input', _defineProperty({}, 'kuma-input-' + p.size + '-size', !!p.size)); var triggerClassName = (0, _classnames5['default'])('kuma-calendar-picker-input', _defineProperty({}, 'kuma-calendar-picker-input-' + p.size, !!p.size)); return _react2['default'].createElement( _Picker2['default'], _extends({ calendar: calendar, onChange: me.handleChange }, pickerOptions), function (_ref) { var value = _ref.value; var showClear = p.allowClear ? value && !p.disabled : false; var newValue = value; if (newValue) { newValue = newValue.format(generalizeFormat(p.format)); } else { newValue = ''; } return _react2['default'].createElement( 'span', { className: triggerClassName, style: triggerStyle, ref: me.saveRef('trigger') }, _react2['default'].createElement('input', { value: newValue, readOnly: true, disabled: me.props.disabled, placeholder: me.props.placeholder, className: inputClassName }), p.hasTrigger ? _react2['default'].createElement(_uxcoreIcon2['default'], { usei: true, name: 'riqi', className: 'kuma-calendar-trigger-icon ' + (showClear ? 'kuma-calendar-trigger-icon__has-clear' : '') }) : null, showClear ? _react2['default'].createElement('i', { className: 'uxcore-icon uxicon-biaodanlei-tongyongqingchu kuma-icon-close', onClick: _this2.clearValue }) : null ); } ); }; return YearCalendar; }(_react2['default'].Component); YearCalendar.displayName = 'YearCalendar'; YearCalendar.defaultProps = { format: 'YYYY', placeholder: '请选择年份', onSelect: function onSelect() {}, locale: 'zh-cn', transitionName: 'calendarSlideUp', align: { offset: [0, 0] }, allowClear: true, showDateInput: false, hasTrigger: true }; YearCalendar.propTypes = { allowClear: _propTypes2['default'].bool, format: _propTypes2['default'].string, inputWidth: _propTypes2['default'].number, placeholder: _propTypes2['default'].string, onSelect: _propTypes2['default'].func, locale: _propTypes2['default'].string, getPopupContainer: _propTypes2['default'].func }; exports['default'] = YearCalendar; module.exports = exports['default']; |