choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
203 lines (184 loc) • 6.51 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _get from "@babel/runtime/helpers/get";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/inherits";
import _createSuper from "@babel/runtime/helpers/createSuper";
import React from 'react';
import classNames from 'classnames';
import Icon from '../icon';
import DaysView, { alwaysValidDate } from './DaysView';
import { ViewMode } from './enum';
import { FieldType } from '../data-set/enum';
import { stopEvent } from '../_util/EventManager';
var MonthsView = /*#__PURE__*/function (_DaysView) {
_inherits(MonthsView, _DaysView);
var _super = _createSuper(MonthsView);
function MonthsView() {
_classCallCheck(this, MonthsView);
return _super.apply(this, arguments);
}
_createClass(MonthsView, [{
key: "getViewClassName",
value: function getViewClassName() {
var prefixCls = this.prefixCls;
return "".concat(prefixCls, "-month");
}
}, {
key: "handleKeyDownHome",
value: function handleKeyDownHome(e) {
stopEvent(e);
this.changeSelectedDate(this.getCloneDate().startOf('y'));
}
}, {
key: "handleKeyDownEnd",
value: function handleKeyDownEnd(e) {
stopEvent(e);
this.changeSelectedDate(this.getCloneDate().endOf('y'));
}
}, {
key: "handleKeyDownLeft",
value: function handleKeyDownLeft(e) {
stopEvent(e);
if (e.altKey) {
this.changeViewMode(ViewMode.year);
} else {
this.changeSelectedDate(this.getCloneDate().subtract(1, 'M'));
}
}
}, {
key: "handleKeyDownRight",
value: function handleKeyDownRight(e) {
stopEvent(e);
if (e.altKey) {
var mode = this.props.mode;
if (mode !== ViewMode.month) {
this.changeViewMode(mode);
}
} else {
this.changeSelectedDate(this.getCloneDate().add(1, 'M'));
}
}
}, {
key: "handleKeyDownUp",
value: function handleKeyDownUp(e) {
stopEvent(e);
this.changeSelectedDate(this.getCloneDate().subtract(3, 'M'));
}
}, {
key: "handleKeyDownDown",
value: function handleKeyDownDown(e) {
stopEvent(e);
this.changeSelectedDate(this.getCloneDate().add(3, 'M'));
}
}, {
key: "handleKeyDownPageUp",
value: function handleKeyDownPageUp(e) {
stopEvent(e);
this.changeSelectedDate(this.getCloneDate().subtract(e.altKey ? 10 : 1, 'y'));
}
}, {
key: "handleKeyDownPageDown",
value: function handleKeyDownPageDown(e) {
stopEvent(e);
this.changeSelectedDate(this.getCloneDate().add(e.altKey ? 10 : 1, 'y'));
}
}, {
key: "renderHeader",
value: function renderHeader() {
var prefixCls = this.prefixCls,
date = this.props.date;
return /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-header")
}, /*#__PURE__*/React.createElement("a", {
className: "".concat(prefixCls, "-prev-year"),
onClick: this.handlePrevYearClick
}, /*#__PURE__*/React.createElement(Icon, {
type: "first_page"
})), /*#__PURE__*/React.createElement("a", {
className: "".concat(prefixCls, "-view-select"),
onClick: this.handleYearSelect
}, date.year()), /*#__PURE__*/React.createElement("a", {
className: "".concat(prefixCls, "-next-year")
}, /*#__PURE__*/React.createElement(Icon, {
type: "last_page",
onClick: this.handleNextYearClick
})));
}
}, {
key: "renderPanelHead",
value: function renderPanelHead() {
return undefined;
}
}, {
key: "renderPanelBody",
value: function renderPanelBody() {
var prefixCls = this.prefixCls,
_this$props = this.props,
date = _this$props.date,
_this$props$renderer = _this$props.renderer,
renderer = _this$props$renderer === void 0 ? this.renderCell : _this$props$renderer,
_this$props$isValidDa = _this$props.isValidDate,
isValidDate = _this$props$isValidDa === void 0 ? alwaysValidDate : _this$props$isValidDa,
onDateMouseLeave = _this$props.onDateMouseLeave;
var selected = date.clone();
var prevMonth = date.clone().startOf('y');
var lastMonth = prevMonth.clone().add(12, 'M');
var rows = [];
var cells = [];
while (prevMonth.isBefore(lastMonth)) {
var _classNames;
var currentMonth = prevMonth.clone();
var isDisabled = !isValidDate(currentMonth, selected);
var className = classNames("".concat(prefixCls, "-cell"), (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-selected"), prevMonth.isSame(selected, 'M')), _defineProperty(_classNames, "".concat(prefixCls, "-disabled"), isDisabled), _classNames));
var text = prevMonth.localeData().monthsShort(prevMonth);
var monthProps = {
key: text,
className: className,
children: this.renderInner(text)
};
if (!isDisabled) {
monthProps.onClick = this.handleCellClick.bind(this, currentMonth);
monthProps.onMouseEnter = this.handleDateMouseEnter.bind(this, currentMonth);
monthProps.onMouseLeave = onDateMouseLeave;
}
cells.push(renderer(monthProps, text, currentMonth, selected));
if (cells.length === 3) {
rows.push( /*#__PURE__*/React.createElement("tr", {
key: text
}, cells));
cells = [];
}
prevMonth.add(1, 'M');
}
return rows;
}
}, {
key: "renderFooter",
value: function renderFooter() {
return undefined;
}
}, {
key: "getPanelClass",
value: function getPanelClass() {
return "".concat(this.prefixCls, "-month-panel");
}
}, {
key: "choose",
value: function choose(date) {
var mode = this.props.mode;
if (mode !== ViewMode.month) {
this.changeSelectedDate(date);
this.changeViewMode(mode);
} else {
_get(_getPrototypeOf(MonthsView.prototype), "choose", this).call(this, date);
}
}
}]);
return MonthsView;
}(DaysView);
export { MonthsView as default };
MonthsView.displayName = 'MonthsView';
MonthsView.type = FieldType.month;
//# sourceMappingURL=MonthsView.js.map