UNPKG

choerodon-ui

Version:

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

135 lines (119 loc) 4.42 kB
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 _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() { _classCallCheck(this, DateTimesView); return _super.apply(this, arguments); } _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, _this$props = this.props, date = _this$props.date, 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')), React.createElement("a", { className: "".concat(prefixCls, "-footer-view-select"), onClick: this.handleTimeSelect }, date.format(getDateFormatByFieldType(TimesView.type)))); } }]); return DateTimesView; }(DaysView); export { DateTimesView as default }; DateTimesView.displayName = 'DateTimesView'; DateTimesView.type = FieldType.dateTime; __decorate([autobind], DateTimesView.prototype, "handleTimeSelect", null); //# sourceMappingURL=DateTimesView.js.map