UNPKG

zarm-web

Version:
171 lines (131 loc) 7.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireWildcard(require("react")); var _classnames2 = _interopRequireDefault(require("classnames")); var _LocaleReceiver = _interopRequireDefault(require("../locale-provider/LocaleReceiver")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; } function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } var CALENDAR_ROW_COUNT = 4; var CALENDAR_COL_COUNT = 3; var fn = function fn() {}; var CalendarMonthTable = /*#__PURE__*/ function (_Component) { _inherits(CalendarMonthTable, _Component); function CalendarMonthTable(props) { var _this; _classCallCheck(this, CalendarMonthTable); _this = _possibleConstructorReturn(this, _getPrototypeOf(CalendarMonthTable).call(this, props)); _this.state = { current: props.current || new Date() }; return _this; } _createClass(CalendarMonthTable, [{ key: "componentWillReceiveProps", value: function componentWillReceiveProps(nextProps) { if ('current' in nextProps) { this.setState({ current: nextProps.current }); } } // 渲染月份单元 }, { key: "renderMonthCell", value: function renderMonthCell(day) { var _classnames; var _this$props = this.props, onMonthClick = _this$props.onMonthClick, prefixCls = _this$props.prefixCls, disabledMonth = _this$props.disabledMonth, locale = _this$props.locale; var current = this.state.current; var fullDay = "".concat(day.year, "/").concat(day.month, "/").concat(day.date); // @ts-ignore var isDisabled = disabledMonth ? !disabledMonth(fullDay) : false; var cls = (0, _classnames2.default)((_classnames = {}, _defineProperty(_classnames, "".concat(prefixCls, "-text"), true), _defineProperty(_classnames, "".concat(prefixCls, "-text-disabled"), isDisabled), _defineProperty(_classnames, "".concat(prefixCls, "-text-selected"), current === fullDay), _classnames)); var onClick = function onClick() { return onMonthClick(fullDay); }; return _react.default.createElement("span", { className: cls, title: locale["month".concat(day.month)], onClick: isDisabled && fn || onClick }, locale["month".concat(day.month)]); } // 渲染月份 }, { key: "renderMonth", value: function renderMonth() { var stateCurrent = this.state.current; var dd = new Date(stateCurrent); var current = { year: dd.getFullYear(), month: dd.getMonth() + 1, date: dd.getDate() }; var months = []; for (var i = 1; i <= 12; i++) { months.push(this.renderMonthCell({ year: current.year, month: i, date: current.date })); } var tabelCell = []; var prefixCls = this.props.prefixCls; for (var m = 0; m < CALENDAR_ROW_COUNT; m++) { var tabelRow = []; for (var n = 0; n < CALENDAR_COL_COUNT; n++) { var index = m * CALENDAR_COL_COUNT + n; tabelRow.push(_react.default.createElement("td", { key: "column-".concat(n), className: "".concat(prefixCls, "-cell"), role: "gridcell" }, months[index])); } tabelCell.push(_react.default.createElement("tr", { key: "row-".concat(m), role: "row" }, tabelRow)); } return _react.default.createElement("tbody", null, tabelCell); } }, { key: "render", value: function render() { var _this$props2 = this.props, visible = _this$props2.visible, prefixCls = _this$props2.prefixCls; var style = { display: visible ? 'none' : 'block' }; return _react.default.createElement("div", { style: style }, _react.default.createElement("table", { className: "".concat(prefixCls, "-table ").concat(prefixCls, "-month") }, this.renderMonth())); } }]); return CalendarMonthTable; }(_react.Component); CalendarMonthTable.defaultProps = { prefixCls: 'ui-calendar', defaultValue: '', current: '', onMonthClick: fn }; var _default = (0, _LocaleReceiver.default)('Calendar')(CalendarMonthTable); exports.default = _default;