@txdfe/at
Version:
一个设计体系组件库
180 lines (178 loc) • 9.09 kB
JavaScript
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 _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
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); }
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) {
function Loading() {
_classCallCheck(this, Loading);
return _callSuper(this, Loading, arguments);
}
_inherits(Loading, _React$Component);
return _createClass(Loading, [{
key: "render",
value: function render() {
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 backgroundColor = color;
var fusionReactorCls = classNames(_defineProperty(_defineProperty({}, "".concat(prefix, "loading-dot-container"), true), "".concat(prefix, "loading-dot-container-").concat(size), true));
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(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "".concat(prefix, "loading"), true), "".concat(prefix, "open"), visible), "".concat(prefix, "loading-inline"), inline), className, className));
var tipCls = classNames(_defineProperty(_defineProperty(_defineProperty({}, "".concat(prefix, "loading-tip"), true), "".concat(prefix, "loading-tip-fullscreen"), fullScreen), "".concat(prefix, "loading-right-tip"), tipAlign === 'right'));
var others = obj.pickOthers(Loading.propTypes, this.props);
var contentCls = classNames(_defineProperty(_defineProperty({}, "".concat(prefix, "loading-component"), visible), "".concat(prefix, "loading-wrap"), true));
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));
}
}]);
}(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);