UNPKG

choerodon-ui

Version:

An enterprise-class UI design language and React-based implementation

133 lines (119 loc) 4.75 kB
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 _createSuper from "@babel/runtime/helpers/createSuper"; 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(_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: "handleCellClick", value: function handleCellClick(date) { this.changeSelectedDate(date); } }, { 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 /*#__PURE__*/React.createElement("div", { className: "".concat(prefixCls, "-footer") }, /*#__PURE__*/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 /*#__PURE__*/React.createElement("div", { className: "".concat(this.getViewClassName(), "-wrapper") }, /*#__PURE__*/React.createElement("div", { className: classString }, this.renderHeader(), this.renderBody(), extraFooterPlacement === 'top' && this.customFooter, this.renderFooter(), extraFooterPlacement === 'bottom' && this.customFooter), /*#__PURE__*/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