UNPKG

react-loading-progress

Version:
108 lines (85 loc) 4.45 kB
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 display: flex;\n justify-content: ", ";\n align-items: center;\n overflow: hidden;\n position: absolute;\n"], ["\n display: flex;\n justify-content: ", ";\n align-items: center;\n overflow: hidden;\n position: absolute;\n"]), _templateObject2 = _taggedTemplateLiteral(["\n border-radius: 50%;\n transition: all 700ms 0s ease;\n"], ["\n border-radius: 50%;\n transition: all 700ms 0s ease;\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 } from "react"; import PropTypes from "prop-types"; import styled from "styled-components"; var Root = styled.div(_templateObject, function (props) { return props.placement; }); var Curled = styled.div(_templateObject2); var Ripple = function (_Component) { _inherits(Ripple, _Component); function Ripple() { var _ref; var _temp, _this, _ret; _classCallCheck(this, Ripple); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Ripple.__proto__ || Object.getPrototypeOf(Ripple)).call.apply(_ref, [this].concat(args))), _this), _this.state = { size: 0, opacity: 1, timeout: null }, _this.changeSize = function () { var size = _this.props.width > _this.props.height ? _this.props.width : _this.props.height; _this.setState({ size: size, opacity: 0 }); }, _temp), _possibleConstructorReturn(_this, _ret); } _createClass(Ripple, [{ key: "componentDidMount", value: function componentDidMount() { var timeout = setTimeout(this.changeSize, 10); this.setState({ timeout: timeout }); } }, { key: "componentWillUnmount", value: function componentWillUnmount() { if (this.state.timeout !== null) { clearTimeout(this.state.timeout); } } }, { key: "render", value: function render() { var rootStyle = { height: this.props.height + "px", width: this.props.width + "px" }; var style = { height: this.state.size + "px", width: this.state.size + "px", opacity: this.state.opacity, backgroundColor: this.props.error ? "rgba(255, 0, 0, 0.3)" : "rgba(0, 0, 0, 0.3)" }; return React.createElement( Root, { style: rootStyle, placement: this.props.placement }, React.createElement(Curled, { style: style }) ); } }]); return Ripple; }(Component); Ripple.defaultProps = { placement: "center", width: null, height: null, error: false }; Ripple.propTypes = { placement: PropTypes.string, width: PropTypes.number.isRequired, height: PropTypes.number.isRequired, error: PropTypes.bool }; export default Ripple;