choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
207 lines (186 loc) • 6.44 kB
JavaScript
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";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
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, { Component } from 'react';
import PropTypes from 'prop-types';
import noop from 'lodash/noop';
import { getMonthName } from '../util';
var CalendarHeader =
/*#__PURE__*/
function (_Component) {
_inherits(CalendarHeader, _Component);
var _super = _createSuper(CalendarHeader);
function CalendarHeader() {
_classCallCheck(this, CalendarHeader);
return _super.apply(this, arguments);
}
_createClass(CalendarHeader, [{
key: "onYearChange",
value: function onYearChange(year) {
var newValue = this.props.value.clone();
newValue.year(parseInt(year, 10));
this.props.onValueChange(newValue);
}
}, {
key: "onMonthChange",
value: function onMonthChange(month) {
var newValue = this.props.value.clone();
newValue.month(parseInt(month, 10));
this.props.onValueChange(newValue);
}
}, {
key: "yearSelectElement",
value: function yearSelectElement(year) {
var _this$props = this.props,
yearSelectOffset = _this$props.yearSelectOffset,
yearSelectTotal = _this$props.yearSelectTotal,
prefixCls = _this$props.prefixCls,
Select = _this$props.Select;
var start = year - yearSelectOffset;
var end = start + yearSelectTotal;
var options = [];
for (var index = start; index < end; index++) {
options.push(React.createElement(Select.Option, {
key: "".concat(index)
}, index));
}
return React.createElement(Select, {
className: "".concat(prefixCls, "-header-year-select"),
onChange: this.onYearChange.bind(this),
dropdownStyle: {
zIndex: 2000
},
dropdownMenuStyle: {
maxHeight: 250,
overflow: 'auto',
fontSize: 12
},
optionLabelProp: "children",
value: String(year),
showSearch: false
}, options);
}
}, {
key: "monthSelectElement",
value: function monthSelectElement(month) {
var props = this.props;
var t = props.value.clone();
var prefixCls = props.prefixCls;
var options = [];
var Select = props.Select;
for (var index = 0; index < 12; index++) {
t.month(index);
options.push(React.createElement(Select.Option, {
key: "".concat(index)
}, getMonthName(t)));
}
return React.createElement(Select, {
className: "".concat(prefixCls, "-header-month-select"),
dropdownStyle: {
zIndex: 2000
},
dropdownMenuStyle: {
maxHeight: 250,
overflow: 'auto',
overflowX: 'hidden',
fontSize: 12
},
optionLabelProp: "children",
value: String(month),
showSearch: false,
onChange: this.onMonthChange.bind(this)
}, options);
}
}, {
key: "changeTypeToDate",
value: function changeTypeToDate() {
this.props.onTypeChange('date');
}
}, {
key: "changeTypeToMonth",
value: function changeTypeToMonth() {
this.props.onTypeChange('month');
}
}, {
key: "render",
value: function render() {
var _this$props2 = this.props,
value = _this$props2.value,
locale = _this$props2.locale,
prefixCls = _this$props2.prefixCls,
type = _this$props2.type,
showTypeSwitch = _this$props2.showTypeSwitch,
headerComponents = _this$props2.headerComponents;
var year = value.year();
var month = value.month();
var yearSelect = this.yearSelectElement(year);
var monthSelect = type === 'month' ? null : this.monthSelectElement(month);
var switchCls = "".concat(prefixCls, "-header-switcher");
var typeSwitcher = showTypeSwitch ? React.createElement("span", {
className: switchCls
}, type === 'date' ? React.createElement("span", {
className: "".concat(switchCls, "-focus")
}, locale.month) : React.createElement("span", {
onClick: this.changeTypeToDate.bind(this),
className: "".concat(switchCls, "-normal")
}, locale.month), type === 'month' ? React.createElement("span", {
className: "".concat(switchCls, "-focus")
}, locale.year) : React.createElement("span", {
onClick: this.changeTypeToMonth.bind(this),
className: "".concat(switchCls, "-normal")
}, locale.year)) : null;
return React.createElement("div", {
className: "".concat(prefixCls, "-header")
}, typeSwitcher, monthSelect, yearSelect, headerComponents);
}
}]);
return CalendarHeader;
}(Component);
_defineProperty(CalendarHeader, "propTypes", {
value: PropTypes.object,
locale: PropTypes.object,
yearSelectOffset: PropTypes.number,
yearSelectTotal: PropTypes.number,
onValueChange: PropTypes.func,
onTypeChange: PropTypes.func,
Select: PropTypes.func,
prefixCls: PropTypes.string,
type: PropTypes.string,
showTypeSwitch: PropTypes.bool,
headerComponents: PropTypes.array
});
_defineProperty(CalendarHeader, "defaultProps", {
yearSelectOffset: 10,
yearSelectTotal: 20,
onValueChange: noop,
onTypeChange: noop
});
export { CalendarHeader as default };
//# sourceMappingURL=CalendarHeader.js.map