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 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 8× 18× 1× 1× 1× 1× 1× 8× 8× 8× 8× 8× 9× 9× 9× 9× 9× 9× 9× 9× 9× 9× 9× 9× 9× 9× 9× 900× 9× 9× 108× 108× 108× 108× 9× 9× 9× 2× 7× 9× 36× 9× 9× 9× 9× 9× 9× 9× 9× 9× 9× 11× 1× 1× | 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _propTypes = require('prop-types'); var _propTypes2 = _interopRequireDefault(_propTypes); var _createReactClass = require('create-react-class'); var _createReactClass2 = _interopRequireDefault(_createReactClass); var _MonthPanel = require('rc-calendar/lib/month/MonthPanel'); var _MonthPanel2 = _interopRequireDefault(_MonthPanel); var _YearPanel = require('rc-calendar/lib/year/YearPanel'); var _YearPanel2 = _interopRequireDefault(_YearPanel); var _mapSelf = require('rc-util/lib/Children/mapSelf'); var _mapSelf2 = _interopRequireDefault(_mapSelf); var _uxcoreSelect = require('uxcore-select2'); var _uxcoreSelect2 = _interopRequireDefault(_uxcoreSelect); var _classnames3 = require('classnames'); var _classnames4 = _interopRequireDefault(_classnames3); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': 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; } var Option = _uxcoreSelect2['default'].Option; function goMonth(direction) { var next = this.props.value.clone(); next.add(direction, 'months'); this.props.onValueChange(next); } function goYear(direction) { var next = this.props.value.clone(); next.add(direction, 'years'); this.props.onValueChange(next); } var CalendarHeader = (0, _createReactClass2['default'])({ propTypes: { enablePrev: _propTypes2['default'].any, enableNext: _propTypes2['default'].any, prefixCls: _propTypes2['default'].string, showTimePicker: _propTypes2['default'].bool, locale: _propTypes2['default'].object, value: _propTypes2['default'].object, onValueChange: _propTypes2['default'].func, yearSelectOffset: _propTypes2['default'].number, yearSelectTotal: _propTypes2['default'].number }, getDefaultProps: function getDefaultProps() { return { enableNext: 1, enablePrev: 1, yearSelectOffset: 50, yearSelectTotal: 100 }; }, getInitialState: function getInitialState() { this.nextMonth = goMonth.bind(this, 1); this.previousMonth = goMonth.bind(this, -1); this.nextYear = goYear.bind(this, 1); this.previousYear = goYear.bind(this, -1); return {}; }, onSelect: function onSelect(value) { this.setState({ showMonthPanel: 0, showYearPanel: 0 }); this.props.onValueChange(value); }, onYearChange: function onYearChange(year) { var newValue = this.props.value.clone(); newValue.year(parseInt(year, 10)); var onValueChange = this.props.onValueChange; if (onValueChange) { onValueChange(newValue); } }, onMonthChange: function onMonthChange(month) { var newValue = this.props.value.clone(); newValue.month(parseInt(month, 10)); var onValueChange = this.props.onValueChange; if (onValueChange) { onValueChange(newValue); } }, getSelectContainer: function getSelectContainer() { return this.root; }, monthYearElement: function monthYearElement() { var _this = this; var props = this.props; var prefixCls = props.prefixCls; var locale = props.locale; var value = props.value; var monthBeforeYear = locale.monthBeforeYear; var selectClassName = prefixCls + '-' + (monthBeforeYear ? 'my-select' : 'ym-select'); var yearValue = value.year(); var startYear = yearValue - props.yearSelectOffset; var endYear = startYear + props.yearSelectTotal; var yearOptions = []; var monthOptions = []; var isLocaleCn = locale.year === '年'; var suffix = isLocaleCn ? '年' : ''; for (var i = startYear; i < endYear; i++) { yearOptions.push(_react2['default'].createElement( Option, { key: '' + i, label: '' + (i + suffix) }, i )); } var year = _react2['default'].createElement( _uxcoreSelect2['default'], { value: '' + yearValue, className: (0, _classnames4['default'])(prefixCls + '-year-select', _defineProperty({}, prefixCls + '-cn-select', isLocaleCn)), showSearch: false, dropdownMatchSelectWidth: false, dropdownClassName: prefixCls + '-year-select-dropdown', optionLabelProp: 'label', getPopupContainer: function getPopupContainer() { return _this.getSelectContainer(); }, dropdownAlign: { offset: [0, -2] }, onChange: this.onYearChange }, yearOptions ); for (var _i = 0; _i < 12; _i++) { var current = value.clone(); var localeData = value.localeData(); current.month(_i); monthOptions.push(_react2['default'].createElement( Option, { key: '' + _i, label: localeData.monthsShort(current) }, localeData.monthsShort(current) )); } var month = _react2['default'].createElement( _uxcoreSelect2['default'], { value: '' + value.month(), dropdownMatchSelectWidth: false, dropdownClassName: prefixCls + '-month-select-dropdown', className: (0, _classnames4['default'])(prefixCls + '-month-select', _defineProperty({}, prefixCls + '-cn-select', isLocaleCn)), showSearch: false, optionLabelProp: 'label', getPopupContainer: function getPopupContainer() { return _this.getSelectContainer(); }, dropdownAlign: { offset: [0, -2] }, onChange: this.onMonthChange }, monthOptions ); var my = []; if (monthBeforeYear) { my = [month, year]; } else { my = [year, month]; } return _react2['default'].createElement( 'span', { className: selectClassName }, (0, _mapSelf2['default'])(my) ); }, showIf: function showIf(condition, el) { return condition ? el : null; }, showMonthPanel: function showMonthPanel() { this.setState({ showMonthPanel: 1, showYearPanel: 0 }); }, showYearPanel: function showYearPanel() { this.setState({ showMonthPanel: 0, showYearPanel: 1 }); }, render: function render() { var _this2 = this; var props = this.props; var enableNext = props.enableNext, enablePrev = props.enablePrev, prefixCls = props.prefixCls, locale = props.locale, value = props.value, showTimePicker = props.showTimePicker; var state = this.state; var PanelClass = null; Iif (state.showMonthPanel) { PanelClass = _MonthPanel2['default']; } else Iif (state.showYearPanel) { PanelClass = _YearPanel2['default']; } var panel = void 0; Iif (PanelClass) { panel = _react2['default'].createElement(PanelClass, { locale: locale, defaultValue: value, rootPrefixCls: prefixCls, onSelect: this.onSelect }); } return _react2['default'].createElement( 'div', { className: prefixCls + '-header', ref: function ref(c) { _this2.root = c; } }, _react2['default'].createElement( 'div', { style: { position: 'relative' } }, this.showIf(enablePrev, _react2['default'].createElement('a', { className: prefixCls + '-prev-year-btn', role: 'button', onClick: this.previousYear, title: locale.previousYear })), this.showIf(enablePrev, _react2['default'].createElement('a', { className: prefixCls + '-prev-month-btn', role: 'button', onClick: this.previousMonth, title: locale.previousMonth })), this.monthYearElement(showTimePicker), this.showIf(enableNext, _react2['default'].createElement('a', { className: prefixCls + '-next-month-btn', onClick: this.nextMonth, title: locale.nextMonth })), this.showIf(enableNext, _react2['default'].createElement('a', { className: prefixCls + '-next-year-btn', onClick: this.nextYear, title: locale.nextYear })) ), panel ); } }); exports['default'] = CalendarHeader; module.exports = exports['default']; |