choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
162 lines (141 loc) • 5.41 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
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 { __decorate } from "tslib";
import React from 'react';
import moment from 'moment';
import noop from 'lodash/noop';
import classNames from 'classnames';
import DaysView from './DaysView';
import TimesView from './TimesView';
import autobind from '../_util/autobind';
import { ViewMode } from './enum';
import { FieldType } from '../data-set/enum';
import { $l } from '../locale-context';
import { getDateFormatByFieldType } from '../field/utils';
var DateTimesView =
/*#__PURE__*/
function (_DaysView) {
_inherits(DateTimesView, _DaysView);
var _super = _createSuper(DateTimesView);
function DateTimesView() {
var _this;
_classCallCheck(this, DateTimesView);
_this = _super.apply(this, arguments);
_this.getTimeProps = function () {
var _this$props$format = _this.props.format,
format = _this$props$format === void 0 ? getDateFormatByFieldType(TimesView.type) : _this$props$format;
var timeProps = _objectSpread({}, _this.props, {
mode: ViewMode.time,
datetimeSide: true,
format: format
});
return timeProps;
};
return _this;
}
_createClass(DateTimesView, [{
key: "getViewClassName",
value: function getViewClassName() {
var prefixCls = this.prefixCls;
return "".concat(prefixCls, "-datetime");
}
}, {
key: "handleTimeSelect",
value: function handleTimeSelect() {
this.changeViewMode(ViewMode.time);
}
}, {
key: "handleKeyDownRight",
value: function handleKeyDownRight(e) {
if (e.altKey) {
this.changeViewMode(ViewMode.time);
} else {
this.changeSelectedDate(this.getCloneDate().add(1, 'd'));
}
}
}, {
key: "getFirstDay",
value: function getFirstDay(date) {
var firstDay = date.clone().subtract(1, 'M');
var hour = firstDay.hour();
var minute = firstDay.minute();
var second = firstDay.second();
firstDay.date(firstDay.daysInMonth()).startOf('w');
firstDay.hour(hour);
firstDay.minute(minute);
firstDay.second(second);
return firstDay;
}
}, {
key: "choose",
value: function choose(date) {
var expand = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
var _this$props$onSelect = this.props.onSelect,
onSelect = _this$props$onSelect === void 0 ? noop : _this$props$onSelect;
onSelect(date, expand);
}
}, {
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(), false) : noop
};
return React.createElement("div", {
className: "".concat(prefixCls, "-footer")
}, React.createElement("a", _extends({}, footerProps), $l('DatePicker', 'now')));
}
}, {
key: "render",
value: function render() {
var prefixCls = this.prefixCls,
_this$props = this.props,
className = _this$props.className,
extraFooterPlacement = _this$props.extraFooterPlacement;
var classString = classNames("".concat(prefixCls, "-view"), className, this.getViewClassName());
return React.createElement("div", {
className: "".concat(this.getViewClassName(), "-wrapper")
}, React.createElement("div", {
className: classString
}, this.renderHeader(), this.renderBody(), extraFooterPlacement === 'top' && this.customFooter, this.renderFooter(), extraFooterPlacement === 'bottom' && this.customFooter), React.createElement(TimesView, _extends({}, this.getTimeProps())));
}
}]);
return DateTimesView;
}(DaysView);
export { DateTimesView as default };
DateTimesView.displayName = 'DateTimesView';
DateTimesView.type = FieldType.dateTime;
__decorate([autobind], DateTimesView.prototype, "handleTimeSelect", null);
//# sourceMappingURL=DateTimesView.js.map