UNPKG

@bigfishtv/cockpit

Version:

70 lines (55 loc) 2.38 kB
var _class, _temp; 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; } import React, { Component } from 'react'; import Icon from './Icon'; /** * Amazing spinner component :O */ var Spinner = (_temp = _class = function (_Component) { _inherits(Spinner, _Component); function Spinner(props) { _classCallCheck(this, Spinner); var _this = _possibleConstructorReturn(this, _Component.call(this, props)); _this.incrementSpinner = function () { var angle = (_this.state.angle + 30) % 360; _this.setState({ angle: angle }); }; _this.state = { angle: 0 }; return _this; } Spinner.prototype.componentDidMount = function componentDidMount() { this.spinnerInterval = setInterval(this.incrementSpinner, this.props.speed); }; Spinner.prototype.componentWillUnmount = function componentWillUnmount() { clearInterval(this.spinnerInterval); }; Spinner.prototype.render = function render() { var _props = this.props, name = _props.name, size = _props.size; var angle = this.state.angle; var rotate = 'rotate(' + angle + 'deg)'; var styles = { display: 'inline-block', transform: rotate, WebkitTransform: rotate, width: size, height: size, marginLeft: -size / 2, marginTop: -size / 2 }; return React.createElement( 'div', { style: styles, className: 'spinner' }, React.createElement(Icon, { name: name, size: size }) ); }; return Spinner; }(Component), _class.defaultProps = { name: 'spinner', speed: 60, size: 24 }, _temp); export { Spinner as default };