choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
158 lines (141 loc) • 5.53 kB
JavaScript
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
import _extends from "@babel/runtime/helpers/extends";
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 moment from 'moment';
import classNames from 'classnames';
import noop from 'lodash/noop';
import DaysView from './DaysView';
import { ViewMode } from './enum';
import { FieldType } from '../data-set/enum';
import { $l } from '../locale-context';
import { stopEvent } from '../_util/EventManager';
var WeeksView = /*#__PURE__*/function (_DaysView) {
_inherits(WeeksView, _DaysView);
var _super = _createSuper(WeeksView);
function WeeksView() {
_classCallCheck(this, WeeksView);
return _super.apply(this, arguments);
}
_createClass(WeeksView, [{
key: "getViewClassName",
value: function getViewClassName() {
var prefixCls = this.prefixCls;
return "".concat(prefixCls, "-week");
}
}, {
key: "handleKeyDownLeft",
value: function handleKeyDownLeft(e) {
stopEvent(e);
if (e.altKey) {
this.changeViewMode(ViewMode.month);
} else {
this.changeCursorDate(this.getCloneDate().subtract(1, 'M'));
}
}
}, {
key: "handleKeyDownRight",
value: function handleKeyDownRight(e) {
stopEvent(e);
if (!e.altKey) {
this.changeCursorDate(this.getCloneDate().add(1, 'M'));
}
}
}, {
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,
onDateMouseLeave = _this$props.onDateMouseLeave;
var selected = date.clone();
var firstDay = this.getFirstDay(date);
var lastDay = firstDay.clone().add(42, 'd');
var rows = [];
var cells = [];
while (firstDay.isBefore(lastDay)) {
var currentDate = firstDay.clone();
var className = classNames("".concat(prefixCls, "-cell"), _defineProperty({}, "".concat(prefixCls, "-selected"), firstDay.isSame(selected, 'w')));
var text = String(currentDate.date());
var dayProps = {
key: firstDay.format('M_D'),
className: className,
children: this.renderInner(text)
};
if (cells.length === 0) {
var weekProps = {
key: firstDay.format('Wo'),
className: "".concat(className, " ").concat(prefixCls, "-week-cell")
};
cells.push(this.getWeekCell(weekProps, firstDay.week()));
}
cells.push(renderer(dayProps, text, currentDate, selected));
if (cells.length === 8) {
rows.push( /*#__PURE__*/React.createElement("tr", {
onClick: this.handleCellClick.bind(this, currentDate),
key: firstDay.format('M_D'),
onMouseEnter: this.handleDateMouseEnter.bind(this, currentDate),
onMouseLeave: onDateMouseLeave
}, cells));
cells = [];
}
firstDay.add(1, 'd');
}
return rows;
}
}, {
key: "choose",
value: function choose(date) {
_get(_getPrototypeOf(WeeksView.prototype), "choose", this).call(this, date.startOf('W'));
}
}, {
key: "getPanelClass",
value: function getPanelClass() {
return "".concat(this.prefixCls, "-week-panel");
}
}, {
key: "renderFooter",
value: function renderFooter() {
var _classNames2;
var prefixCls = this.prefixCls,
_this$props2 = this.props,
disabledNow = _this$props2.disabledNow,
isExistValue = _this$props2.isExistValue;
var footerProps = {
className: classNames("".concat(prefixCls, "-footer-now-btn"), (_classNames2 = {}, _defineProperty(_classNames2, "".concat(prefixCls, "-now-disabled"), disabledNow), _defineProperty(_classNames2, "".concat(prefixCls, "-now-selected"), isExistValue), _classNames2)),
onClick: !disabledNow ? this.choose.bind(this, moment()) : noop
};
return /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-footer")
}, /*#__PURE__*/React.createElement("a", _extends({}, footerProps), $l('DatePicker', 'this_week')));
}
}, {
key: "getWeekCell",
value: function getWeekCell(props, text) {
var prefixCls = this.prefixCls;
return /*#__PURE__*/React.createElement("td", _extends({}, props), /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-cell-inner")
}, "W", text));
}
}, {
key: "getDaysOfWeek",
value: function getDaysOfWeek() {
return [/*#__PURE__*/React.createElement("th", {
key: "null"
}, "\xA0")].concat(_toConsumableArray(_get(_getPrototypeOf(WeeksView.prototype), "getDaysOfWeek", this).call(this)));
}
}]);
return WeeksView;
}(DaysView);
export { WeeksView as default };
WeeksView.displayName = 'WeeksView';
WeeksView.type = FieldType.week;
//# sourceMappingURL=WeeksView.js.map