choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
184 lines (161 loc) • 5.83 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 _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
function _createSuper(Derived) {
function isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
return true;
} catch (e) {
return false;
}
}
return function () {
var Super = _getPrototypeOf(Derived),
result;
if (isNativeReflectConstruct()) {
var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possibleConstructorReturn(this, result);
};
}
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.changeSelectedDate(this.getCloneDate().subtract(1, 'M'));
}
}
}, {
key: "handleKeyDownRight",
value: function handleKeyDownRight(e) {
stopEvent(e);
if (!e.altKey) {
this.changeSelectedDate(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;
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(React.createElement("tr", {
onClick: this.handleCellClick.bind(this, currentDate),
key: firstDay.format('M_D')
}, 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 prefixCls = this.prefixCls,
disabledNow = this.props.disabledNow;
var footerProps = {
className: classNames("".concat(prefixCls, "-footer-now-btn"), _defineProperty({}, "".concat(prefixCls, "-now-disabled"), disabledNow)),
onClick: !disabledNow ? this.choose.bind(this, moment()) : noop
};
return React.createElement("div", {
className: "".concat(prefixCls, "-footer")
}, React.createElement("a", _extends({}, footerProps), $l('DatePicker', 'this_week')));
}
}, {
key: "getWeekCell",
value: function getWeekCell(props, text) {
var prefixCls = this.prefixCls;
return React.createElement("td", _extends({}, props), React.createElement("div", {
className: "".concat(prefixCls, "-cell-inner")
}, "W", text));
}
}, {
key: "getDaysOfWeek",
value: function getDaysOfWeek() {
return [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