UNPKG

halogen

Version:

A collection of loading spinners with React.js

113 lines (99 loc) 2.58 kB
'use strict'; var React = require('react'); var assign = require('domkit/appendVendorPrefix'); var insertKeyframesRule = require('domkit/insertKeyframesRule'); /** * @type {Object} */ var keyframes = { '25%': { transform: 'rotateX(180deg) rotateY(0)' }, '50%': { transform: 'rotateX(180deg) rotateY(180deg)' }, '75%': { transform: 'rotateX(0) rotateY(180deg)' }, '100%': { transform: 'rotateX(0) rotateY(0)' } }; /** * @type {String} */ var animationName = insertKeyframesRule(keyframes); var Loader = React.createClass({ displayName: 'Loader', /** * @type {Object} */ propTypes: { loading: React.PropTypes.bool, color: React.PropTypes.string, size: React.PropTypes.string, margin: React.PropTypes.string }, /** * @return {Object} */ getDefaultProps: function getDefaultProps() { return { loading: true, color: '#ffffff', size: '50px' }; }, /** * @return {Object} */ getSquareStyle: function getSquareStyle() { return { backgroundColor: this.props.color, width: this.props.size, height: this.props.size, verticalAlign: this.props.verticalAlign }; }, /** * @param {Number} i * @return {Object} */ getAnimationStyle: function getAnimationStyle(i) { var animation = [animationName, '3s', '0s', 'infinite', 'cubic-bezier(.09,.57,.49,.9)'].join(' '); var animationFillMode = 'both'; var perspective = '100px'; return { perspective: perspective, animation: animation, animationFillMode: animationFillMode }; }, /** * @param {Number} i * @return {Object} */ getStyle: function getStyle(i) { return assign(this.getSquareStyle(i), this.getAnimationStyle(i), { display: 'inline-block' }); }, /** * @param {Boolean} loading * @return {ReactComponent || null} */ renderLoader: function renderLoader(loading) { if (loading) { return React.createElement( 'div', { id: this.props.id, className: this.props.className }, React.createElement('div', { style: this.getStyle() }) ); } return null; }, render: function render() { return this.renderLoader(this.props.loading); } }); module.exports = Loader;