UNPKG

@txdfe/at

Version:

一个设计体系组件库

218 lines (180 loc) 9.91 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); } 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 _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; } import React from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import Overlay from '../overlay'; import ConfigProvider from '../config-provider'; import { obj, func } from '../util'; /* eslint-disable react/prefer-stateless-function */ /** Loading */ var Loading = /*#__PURE__*/function (_React$Component) { _inherits(Loading, _React$Component); var _super = _createSuper(Loading); function Loading() { _classCallCheck(this, Loading); return _super.apply(this, arguments); } _createClass(Loading, [{ key: "render", value: function render() { var _classNames2, _classNames3, _classNames4; var _this$props = this.props, tip = _this$props.tip, visible = _this$props.visible, children = _this$props.children, className = _this$props.className, style = _this$props.style, indicator = _this$props.indicator, color = _this$props.color, prefix = _this$props.prefix, fullScreen = _this$props.fullScreen, onVisibleChange = _this$props.onVisibleChange, tipAlign = _this$props.tipAlign, size = _this$props.size, inline = _this$props.inline, rtl = _this$props.rtl; var indicatorDom = null; var dotCls = "".concat(prefix, "loading-dot"); if (indicator) { indicatorDom = indicator; } else { var _classNames; var backgroundColor = color; var fusionReactorCls = classNames((_classNames = {}, _defineProperty(_classNames, "".concat(prefix, "loading-dot-container"), true), _defineProperty(_classNames, "".concat(prefix, "loading-dot-container-").concat(size), true), _classNames)); indicatorDom = /*#__PURE__*/React.createElement("div", { className: fusionReactorCls, dir: rtl ? 'rtl' : undefined }, /*#__PURE__*/React.createElement("span", { className: dotCls, style: { backgroundColor: backgroundColor } }), /*#__PURE__*/React.createElement("span", { className: dotCls, style: { backgroundColor: backgroundColor } }), /*#__PURE__*/React.createElement("span", { className: dotCls, style: { backgroundColor: backgroundColor } })); } var loadingCls = classNames((_classNames2 = {}, _defineProperty(_classNames2, "".concat(prefix, "loading"), true), _defineProperty(_classNames2, "".concat(prefix, "open"), visible), _defineProperty(_classNames2, "".concat(prefix, "loading-inline"), inline), _defineProperty(_classNames2, className, className), _classNames2)); var tipCls = classNames((_classNames3 = {}, _defineProperty(_classNames3, "".concat(prefix, "loading-tip"), true), _defineProperty(_classNames3, "".concat(prefix, "loading-tip-fullscreen"), fullScreen), _defineProperty(_classNames3, "".concat(prefix, "loading-right-tip"), tipAlign === 'right'), _classNames3)); var others = obj.pickOthers(Loading.propTypes, this.props); var contentCls = classNames((_classNames4 = {}, _defineProperty(_classNames4, "".concat(prefix, "loading-component"), visible), _defineProperty(_classNames4, "".concat(prefix, "loading-wrap"), true), _classNames4)); return fullScreen ? [children, /*#__PURE__*/React.createElement(Overlay, _extends({ key: "overlay", hasMask: true, align: "cc cc" }, others, { className: className, style: style, visible: visible, onRequestClose: onVisibleChange }), /*#__PURE__*/React.createElement("div", { className: tipCls }, /*#__PURE__*/React.createElement("div", { className: "".concat(prefix, "loading-indicator") }, indicatorDom), /*#__PURE__*/React.createElement("div", { className: "".concat(prefix, "loading-tip-content") }, tip), /*#__PURE__*/React.createElement("div", { className: "".concat(prefix, "loading-tip-placeholder") }, tip)))] : /*#__PURE__*/React.createElement("div", _extends({ className: loadingCls, style: style }, obj.pickAttrs(others)), visible ? /*#__PURE__*/React.createElement("div", { className: tipCls }, /*#__PURE__*/React.createElement("div", { className: "".concat(prefix, "loading-indicator") }, indicatorDom), /*#__PURE__*/React.createElement("div", { className: "".concat(prefix, "loading-tip-content") }, tip), /*#__PURE__*/React.createElement("div", { className: "".concat(prefix, "loading-tip-placeholder") }, tip)) : null, /*#__PURE__*/React.createElement("div", { className: contentCls }, visible ? /*#__PURE__*/React.createElement("div", { className: "".concat(prefix, "loading-masker") }) : null, children)); } }]); return Loading; }(React.Component); _defineProperty(Loading, "propTypes", { /** * 样式前缀 */ prefix: PropTypes.string, /** * 自定义内容 */ tip: PropTypes.any, /** * 自定义内容位置 * @enumdesc 出现在动画右边, 出现在动画下面 */ tipAlign: PropTypes.oneOf(['right', 'bottom']), /** * loading 状态, 默认 true */ visible: PropTypes.bool, onVisibleChange: PropTypes.func, /** * 自定义class */ className: PropTypes.string, /** * 自定义内联样式 */ style: PropTypes.object, /** * 设置动画尺寸 * @description 仅仅对默认动画效果起作用 * @enumdesc 大号, 中号 */ size: PropTypes.oneOf(['large', 'medium']), /** * 自定义动画 */ indicator: PropTypes.any, /** * 动画颜色 */ color: PropTypes.string, /** * 全屏展示 */ fullScreen: PropTypes.bool, /** * 子元素 */ children: PropTypes.any, /** * should loader be displayed inline */ inline: PropTypes.bool, rtl: PropTypes.bool }); _defineProperty(Loading, "defaultProps", { prefix: 'next-', visible: true, onVisibleChange: func.noop, tipAlign: 'bottom', size: 'medium', inline: true }); export default ConfigProvider.config(Loading);