UNPKG

@txdfe/at

Version:

一个设计体系组件库

149 lines (148 loc) 9.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _react = _interopRequireDefault(require("react")); var _propTypes = _interopRequireDefault(require("prop-types")); var _select = _interopRequireDefault(require("../../select")); var _radio = _interopRequireDefault(require("../../radio")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; } function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } } function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); } function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); } function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); } function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } var CardHeader = /*#__PURE__*/function (_React$PureComponent) { function CardHeader() { var _this; _classCallCheck(this, CardHeader); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _callSuper(this, CardHeader, [].concat(args)); _defineProperty(_this, "selectContainerHandler", function (target) { return target.parentNode; }); _defineProperty(_this, "onYearChange", function (year) { var _this$props = _this.props, visibleMonth = _this$props.visibleMonth, changeVisibleMonth = _this$props.changeVisibleMonth; changeVisibleMonth(visibleMonth.clone().year(year), 'yearSelect'); }); _defineProperty(_this, "changeVisibleMonth", function (month) { var _this$props2 = _this.props, visibleMonth = _this$props2.visibleMonth, changeVisibleMonth = _this$props2.changeVisibleMonth; changeVisibleMonth(visibleMonth.clone().month(month), 'monthSelect'); }); _defineProperty(_this, "onModePanelChange", function (mode) { _this.props.changeMode(mode); }); return _this; } _inherits(CardHeader, _React$PureComponent); return _createClass(CardHeader, [{ key: "getYearSelect", value: function getYearSelect(year) { var _this$props3 = this.props, prefix = _this$props3.prefix, yearRangeOffset = _this$props3.yearRangeOffset, _this$props3$yearRang = _this$props3.yearRange, yearRange = _this$props3$yearRang === void 0 ? [] : _this$props3$yearRang, locale = _this$props3.locale; var _yearRange = _slicedToArray(yearRange, 2), startYear = _yearRange[0], endYear = _yearRange[1]; if (!startYear || !endYear) { startYear = year - yearRangeOffset; endYear = year + yearRangeOffset; } var options = []; for (var i = startYear; i <= endYear; i++) { options.push(/*#__PURE__*/_react["default"].createElement(_select["default"].Option, { key: i, value: i }, i)); } return /*#__PURE__*/_react["default"].createElement(_select["default"], { prefix: prefix, value: year, "aria-label": locale.yearSelectAriaLabel, onChange: this.onYearChange, popupContainer: this.selectContainerHandler }, options); } }, { key: "getMonthSelect", value: function getMonthSelect(month) { var _this$props4 = this.props, prefix = _this$props4.prefix, momentLocale = _this$props4.momentLocale, locale = _this$props4.locale; var localeMonths = momentLocale.monthsShort(); var options = []; for (var i = 0; i < 12; i++) { options.push(/*#__PURE__*/_react["default"].createElement(_select["default"].Option, { key: i, value: i }, localeMonths[i])); } return /*#__PURE__*/_react["default"].createElement(_select["default"], { "aria-label": locale.monthSelectAriaLabel, prefix: prefix, value: month, onChange: this.changeVisibleMonth, popupContainer: this.selectContainerHandler }, options); } }, { key: "render", value: function render() { var _this$props5 = this.props, prefix = _this$props5.prefix, mode = _this$props5.mode, locale = _this$props5.locale, visibleMonth = _this$props5.visibleMonth; var yearSelect = this.getYearSelect(visibleMonth.year()); var monthSelect = mode === 'month' ? null : this.getMonthSelect(visibleMonth.month()); var panelSelect = /*#__PURE__*/_react["default"].createElement(_radio["default"].Group, { shape: "button", size: "medium", value: mode, onChange: this.onModePanelChange }, /*#__PURE__*/_react["default"].createElement(_radio["default"], { value: "date" }, locale.month), /*#__PURE__*/_react["default"].createElement(_radio["default"], { value: "month" }, locale.year)); return /*#__PURE__*/_react["default"].createElement("div", { className: "".concat(prefix, "calendar-header") }, yearSelect, monthSelect, panelSelect); } }]); }(_react["default"].PureComponent); _defineProperty(CardHeader, "propTypes", { yearRange: _propTypes["default"].arrayOf(_propTypes["default"].number), yearRangeOffset: _propTypes["default"].number, locale: _propTypes["default"].object }); _defineProperty(CardHeader, "defaultProps", { yearRangeOffset: 10 }); var _default = exports["default"] = CardHeader;