UNPKG

@txdfe/at

Version:

一个设计体系组件库

238 lines (195 loc) 12.4 kB
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } var _excluded = ["prefix", "className", "state", "icon", "dot", "time", "title", "timeLeft", "content", "index", "total", "folderIndex", "foldShow", "locale", "animation"]; function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } 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); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } 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 } }); Object.defineProperty(subClass, "prototype", { writable: false }); 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); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } 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 _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } 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; } /* eslint-disable react/no-did-mount-set-state */ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import Animate from '../../animate'; import Icon from '../../icon'; import Button from '../../button'; import { obj } from '../../util'; var Expand = Animate.Expand; /** Timeline.Item */ var TimelineItem = /*#__PURE__*/function (_Component) { _inherits(TimelineItem, _Component); var _super = _createSuper(TimelineItem); function TimelineItem(props) { var _this; _classCallCheck(this, TimelineItem); _this = _super.call(this, props); _defineProperty(_assertThisInitialized(_this), "toggleFold", function (folderIndex) { _this.props.toggleFold(folderIndex); }); _defineProperty(_assertThisInitialized(_this), "toggleSpread", function () { _this.setState({ isSpread: !_this.state.isSpread }); }); _defineProperty(_assertThisInitialized(_this), "beforeEnter", function () { _this['timeline-item'].style['min-height'] = 'auto'; }); _defineProperty(_assertThisInitialized(_this), "beforeLeave", function () { _this['timeline-item'].style['min-height'] = '48px'; // timeleft 节点最小高度 }); _this.state = { isSpread: false }; return _this; } _createClass(TimelineItem, [{ key: "render", value: function render() { var _classNames, _classNames2, _classNames3, _classNames4, _this2 = this; var _this$props = this.props, prefix = _this$props.prefix, className = _this$props.className, state = _this$props.state, icon = _this$props.icon, dot = _this$props.dot, time = _this$props.time, title = _this$props.title, timeLeft = _this$props.timeLeft, content = _this$props.content, index = _this$props.index, total = _this$props.total, folderIndex = _this$props.folderIndex, foldShow = _this$props.foldShow, locale = _this$props.locale, animation = _this$props.animation, others = _objectWithoutProperties(_this$props, _excluded); var finalItemNode = dot; if (!finalItemNode) { if (icon) { finalItemNode = /*#__PURE__*/React.createElement("span", { className: "".concat(prefix, "timeline-item-icon") }, /*#__PURE__*/React.createElement(Icon, { type: icon, size: "small" })); } else { finalItemNode = /*#__PURE__*/React.createElement("span", { className: "".concat(prefix, "timeline-item-dot") }); } } var itemCls = classNames((_classNames = {}, _defineProperty(_classNames, "".concat(prefix, "timeline-item"), true), _defineProperty(_classNames, "".concat(prefix, "timeline-item-first"), index === 0), _defineProperty(_classNames, "".concat(prefix, "timeline-item-last"), index === total - 1), _defineProperty(_classNames, "".concat(prefix, "timeline-item-").concat(state), state), _defineProperty(_classNames, "".concat(prefix, "timeline-item-folded"), folderIndex), _defineProperty(_classNames, "".concat(prefix, "timeline-item-unfolded"), foldShow), _defineProperty(_classNames, "".concat(prefix, "timeline-item-has-left-content"), timeLeft), _defineProperty(_classNames, className, className), _classNames)); var folderCls = classNames((_classNames2 = {}, _defineProperty(_classNames2, "".concat(prefix, "timeline-item-folder"), true), _defineProperty(_classNames2, "".concat(prefix, "timeline-item-has-left-content"), timeLeft), _classNames2)); var itemNodeCls = classNames((_classNames3 = {}, _defineProperty(_classNames3, "".concat(prefix, "timeline-item-node"), true), _defineProperty(_classNames3, "".concat(prefix, "timeline-item-node-custom"), dot), _classNames3)); var dotTailCls = classNames((_classNames4 = {}, _defineProperty(_classNames4, "".concat(prefix, "timeline-item-dot-tail"), true), _defineProperty(_classNames4, "".concat(prefix, "timeline-item-dot-tail-solid"), foldShow), _defineProperty(_classNames4, "".concat(prefix, "timeline-hide"), index === total - 1 && foldShow), _classNames4)); var buttonProps = { text: true, size: 'small', type: 'primary', onClick: this.toggleFold.bind(this, folderIndex, total) }; var timelineNode = folderIndex && foldShow || !folderIndex ? /*#__PURE__*/React.createElement("div", _extends({}, obj.pickOthers(TimelineItem.propTypes, others), { className: itemCls, ref: function ref(e) { _this2['timeline-item'] = e; } }), /*#__PURE__*/React.createElement("div", { className: "".concat(prefix, "timeline-item-left-content") }, /*#__PURE__*/React.createElement("p", { className: "".concat(prefix, "timeline-item-body") }, timeLeft)), /*#__PURE__*/React.createElement("div", { className: "".concat(prefix, "timeline-item-timeline") }, /*#__PURE__*/React.createElement("div", { className: "".concat(prefix, "timeline-item-tail") }, /*#__PURE__*/React.createElement("i", null)), /*#__PURE__*/React.createElement("div", { className: itemNodeCls }, finalItemNode)), /*#__PURE__*/React.createElement("div", { className: "".concat(prefix, "timeline-item-content") }, title ? /*#__PURE__*/React.createElement("div", { className: "".concat(prefix, "timeline-item-title") }, title) : null, time ? /*#__PURE__*/React.createElement("div", { className: "".concat(prefix, "timeline-item-time") }, time) : null, content ? /*#__PURE__*/React.createElement("div", { className: "".concat(prefix, "timeline-item-body") }, content) : null)) : null; return /*#__PURE__*/React.createElement("li", { tabIndex: "0" }, animation && folderIndex ? /*#__PURE__*/React.createElement(Expand, { animationAppear: false, beforeEnter: this.beforeEnter, beforeLeave: this.beforeEnter, afterEnter: this.beforeLeave }, timelineNode) : timelineNode, folderIndex === index ? /*#__PURE__*/React.createElement("div", { className: folderCls }, /*#__PURE__*/React.createElement("div", { className: dotTailCls }), foldShow ? /*#__PURE__*/React.createElement(Button, buttonProps, locale.fold, /*#__PURE__*/React.createElement(Icon, { type: "chevron-up" })) : /*#__PURE__*/React.createElement(Button, buttonProps, locale.expand, /*#__PURE__*/React.createElement(Icon, { type: "chevron-down" }))) : null); } }]); return TimelineItem; }(Component); _defineProperty(TimelineItem, "propTypes", { prefix: PropTypes.string, index: PropTypes.number, total: PropTypes.number, folderIndex: PropTypes.number, foldShow: PropTypes.bool, /** * 节点状态 */ state: PropTypes.oneOf(['done', 'process', 'error', 'success']), /** * 图标 */ icon: PropTypes.string, /** * 自定义时间轴节点 */ dot: PropTypes.node, /** * 格式化后的时间 */ time: PropTypes.node, /** * 标题 */ title: PropTypes.node, /** * 左侧时间 */ timeLeft: PropTypes.node, /** * 右侧内容 */ content: PropTypes.node, toggleFold: PropTypes.func, className: PropTypes.string, locale: PropTypes.object, /** * 动画 */ animation: PropTypes.bool }); _defineProperty(TimelineItem, "defaultProps", { prefix: 'next-', state: 'done', toggleFold: function toggleFold() {}, animation: true }); export default TimelineItem;