UNPKG

halogen

Version:

A collection of loading spinners with React.js

119 lines (105 loc) 2.94 kB
'use strict'; var React = require('react'); var assign = require('domkit/appendVendorPrefix'); var insertKeyframesRule = require('domkit/insertKeyframesRule'); /** * @type {Object} */ var keyframes = { '0%': { transform: 'scaley(1.0)' }, '50%': { transform: 'scaley(0.4)' }, '100%': { transform: 'scaley(1.0)' } }; /** * @type {String} */ var animationName = insertKeyframesRule(keyframes); var Loader = React.createClass({ displayName: 'Loader', /** * @type {Object} */ propTypes: { loading: React.PropTypes.bool, color: React.PropTypes.string, height: React.PropTypes.string, width: React.PropTypes.string, margin: React.PropTypes.string, radius: React.PropTypes.string }, /** * @return {Object} */ getDefaultProps: function getDefaultProps() { return { loading: true, color: '#ffffff', height: '35px', width: '4px', margin: '2px', radius: '2px' }; }, /** * @return {Object} */ getLineStyle: function getLineStyle() { return { backgroundColor: this.props.color, height: this.props.height, width: this.props.width, margin: this.props.margin, borderRadius: this.props.radius, verticalAlign: this.props.verticalAlign }; }, /** * @param {Number} i * @return {Object} */ getAnimationStyle: function getAnimationStyle(i) { var animation = [animationName, '1s', i * 0.1 + 's', 'infinite', 'cubic-bezier(.2,.68,.18,1.08)'].join(' '); var animationFillMode = 'both'; return { animation: animation, animationFillMode: animationFillMode }; }, /** * @param {Number} i * @return {Object} */ getStyle: function getStyle(i) { return assign(this.getLineStyle(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(1) }), React.createElement('div', { style: this.getStyle(2) }), React.createElement('div', { style: this.getStyle(3) }), React.createElement('div', { style: this.getStyle(4) }), React.createElement('div', { style: this.getStyle(5) }) ); } return null; }, render: function render() { return this.renderLoader(this.props.loading); } }); module.exports = Loader;