UNPKG

choerodon-ui

Version:

An enterprise-class UI design language and React-based implementation

224 lines (192 loc) 7.19 kB
import _extends from "@babel/runtime/helpers/extends"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _inherits from "@babel/runtime/helpers/inherits"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; function _createSuper(Derived) { function isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } return function () { var Super = _getPrototypeOf(Derived), result; if (isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } import React, { cloneElement, Component, isValidElement } from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import omit from 'lodash/omit'; import isCssAnimationSupported from '../_util/isCssAnimationSupported'; import Animate from '../animate'; import Progress from '../progress/progress'; import { Size } from '../_util/enum'; import { ProgressType } from '../progress/enum'; import { getPrefixCls } from '../configure'; var Spin = /*#__PURE__*/ function (_Component) { _inherits(Spin, _Component); var _super = _createSuper(Spin); function Spin(props) { var _this; _classCallCheck(this, Spin); _this = _super.call(this, props); var spinning = props.spinning; _this.state = { spinning: spinning }; return _this; } _createClass(Spin, [{ key: "componentDidMount", value: function componentDidMount() { if (!isCssAnimationSupported()) { // Show text in IE9 this.setState({ notCssAnimationSupported: true }); } } }, { key: "componentWillUnmount", value: function componentWillUnmount() { if (this.debounceTimeout) { clearTimeout(this.debounceTimeout); } if (this.delayTimeout) { clearTimeout(this.delayTimeout); } } }, { key: "componentWillReceiveProps", value: function componentWillReceiveProps(nextProps) { var _this2 = this; var currentSpinning = this.props.spinning; var spinning = nextProps.spinning; var delay = this.props.delay; if (this.debounceTimeout) { clearTimeout(this.debounceTimeout); } if (currentSpinning && !spinning) { this.debounceTimeout = window.setTimeout(function () { return _this2.setState({ spinning: spinning }); }, 200); if (this.delayTimeout) { clearTimeout(this.delayTimeout); } } else if (spinning && delay && !isNaN(Number(delay))) { if (this.delayTimeout) { clearTimeout(this.delayTimeout); } this.delayTimeout = window.setTimeout(function () { return _this2.setState({ spinning: spinning }); }, delay); } else { this.setState({ spinning: spinning }); } } }, { key: "renderIndicator", value: function renderIndicator(prefixCls) { var _this$props = this.props, indicator = _this$props.indicator, size = _this$props.size; var dotClassName = "".concat(prefixCls, "-dot"); if (isValidElement(indicator)) { return cloneElement(indicator, { className: classNames(indicator.props.className, dotClassName) }); } return React.createElement(Progress, { size: size, className: dotClassName, type: ProgressType.loading }); } }, { key: "render", value: function render() { var _classNames; var _this$props2 = this.props, className = _this$props2.className, size = _this$props2.size, customizePrefixCls = _this$props2.prefixCls, tip = _this$props2.tip, wrapperClassName = _this$props2.wrapperClassName, children = _this$props2.children, style = _this$props2.style, restProps = _objectWithoutProperties(_this$props2, ["className", "size", "prefixCls", "tip", "wrapperClassName", "children", "style"]); var _this$state = this.state, spinning = _this$state.spinning, notCssAnimationSupported = _this$state.notCssAnimationSupported; var prefixCls = getPrefixCls('spin', customizePrefixCls); var spinClassName = classNames(prefixCls, (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-sm"), size === Size.small), _defineProperty(_classNames, "".concat(prefixCls, "-lg"), size === Size.large), _defineProperty(_classNames, "".concat(prefixCls, "-spinning"), spinning), _defineProperty(_classNames, "".concat(prefixCls, "-show-text"), !!tip || notCssAnimationSupported), _classNames), className); // fix https://fb.me/react-unknown-prop var divProps = omit(restProps, ['spinning', 'delay', 'indicator']); var spinElement = React.createElement("div", _extends({}, divProps, { className: spinClassName, style: style, key: "loading" }), this.renderIndicator(prefixCls), tip ? React.createElement("div", { className: "".concat(prefixCls, "-text") }, tip) : null); if (children) { var _classNames2; var animateClassName = "".concat(prefixCls, "-nested-loading"); if (wrapperClassName) { animateClassName += " ".concat(wrapperClassName); } var containerClassName = classNames((_classNames2 = {}, _defineProperty(_classNames2, "".concat(prefixCls, "-container"), true), _defineProperty(_classNames2, "".concat(prefixCls, "-blur"), spinning), _classNames2)); return React.createElement(Animate, _extends({}, divProps, { component: "div", className: animateClassName, transitionName: "fade" }), spinning && spinElement, React.createElement("div", { className: containerClassName, key: "container" }, children)); } return spinElement; } }]); return Spin; }(Component); export { Spin as default }; Spin.displayName = 'Spin'; Spin.defaultProps = { spinning: true, size: Size["default"], wrapperClassName: '' }; Spin.propTypes = { prefixCls: PropTypes.string, className: PropTypes.string, spinning: PropTypes.bool, size: PropTypes.oneOf([Size.small, Size["default"], Size.large]), wrapperClassName: PropTypes.string, indicator: PropTypes.node }; //# sourceMappingURL=index.js.map