react-loading-progress
Version:
Loading display components
129 lines (105 loc) • 4.68 kB
JavaScript
var _createClass = 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _templateObject = _taggedTemplateLiteral(["\n background-color: rgba(0, 0, 0, 0.1);\n transition: opacity 800ms 0s ease;\n position: absolute;\n z-index: 3;\n"], ["\n background-color: rgba(0, 0, 0, 0.1);\n transition: opacity 800ms 0s ease;\n position: absolute;\n z-index: 3;\n"]);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
function _taggedTemplateLiteral(strings, raw) { return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
import React, { Component, Fragment } from "react";
import PropTypes from "prop-types";
import styled from "styled-components";
var Plain = styled.div(_templateObject);
var Fade = function (_Component) {
_inherits(Fade, _Component);
function Fade() {
var _ref;
var _temp, _this, _ret;
_classCallCheck(this, Fade);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Fade.__proto__ || Object.getPrototypeOf(Fade)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
opacity: 0,
block: false
}, _this.fadeIn = function () {
_this.setState({
opacity: 1
});
}, _this.fadeOut = function () {
_this.setState({
opacity: 0
});
}, _temp), _possibleConstructorReturn(_this, _ret);
}
_createClass(Fade, [{
key: "componentDidMount",
value: function componentDidMount() {
var _this2 = this;
if (this.props.fadeOut) {
setTimeout(function () {
return _this2.setState({ block: false });
}, 800);
this.fadeOut();
} else {
this.setState({ block: true });
this.fadeOut();
setTimeout(function () {
return _this2.fadeIn();
}, 10);
}
}
}, {
key: "componentWillReceiveProps",
value: function componentWillReceiveProps(nextProps) {
var _this3 = this;
if (nextProps.fadeOut) {
setTimeout(function () {
return _this3.setState({ block: false });
}, 800);
this.fadeOut();
} else {
this.setState({ block: true });
this.fadeOut();
setTimeout(function () {
return _this3.fadeIn();
}, 10);
}
}
}, {
key: "render",
value: function render() {
if (!this.props.mask) {
return this.props.children;
}
if (this.state.height === 0 && this.state.width === 0) {
return this.props.children;
}
var style = {
height: this.props.height + "px",
width: this.props.width + "px",
opacity: this.state.opacity,
visibility: "hidden"
};
if (!this.state.block) {
return this.props.children;
}
return React.createElement(
Fragment,
null,
React.createElement(Plain, { style: style }),
this.props.children
);
}
}]);
return Fade;
}(Component);
Fade.defaultProps = {
width: null,
height: null,
fadeOut: false
};
Fade.propTypes = {
width: PropTypes.number.isRequired,
height: PropTypes.number.isRequired,
fadeOut: PropTypes.bool.isRequired
};
export default Fade;