All files / components/Icon/LoadingIcon LoadingIcon.jsx

100% Statements 8/8
50% Branches 1/2
100% Functions 0/0
100% Lines 8/8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83            120x 120x 120x                       120x                   120x                       16x   16x   16x                                                                        
import _ from 'lodash';
import React from 'react';
import Icon from '../Icon';
import { lucidClassNames } from '../../../util/style-helpers';
import { createClass, omitProps } from '../../../util/component-types';
 
const { oneOf } = React.PropTypes;
const cx = lucidClassNames.bind('&-LoadingIcon');
const durations = {
	fast: '0.75s',
	normal: '1.25s',
	slow: '4s',
};
 
/**
 *
 * {"categories": ["visual design", "icons"], "extend": "Icon", "madeFrom": ["Icon"]}
 *
 * A loading icon.
 */
const LoadingIcon = createClass({
	displayName: 'LoadingIcon',
	propTypes: {
		...Icon.propTypes,
		/**
		 * The speed of rotation of the spinner. Defaults to 'normal'
		 */
		speed: oneOf(['fast', 'normal', 'slow']),
	},
	getDefaultProps() {
		return {
			...Icon.getDefaultProps(),
			speed: 'normal',
		};
	},
	render() {
		const {
			className,
			speed,
			style,
			isDisabled,
			...passThroughs,
		} = this.props;
 
		const animationDuration = `${durations[speed] || durations.normal}`;
 
		return (
			<Icon
				{...omitProps(passThroughs, LoadingIcon)}
				{..._.pick(passThroughs, _.keys(Icon.propTypes))}
				viewBox='0 0 100 100'
				className={cx('&', className)}
				style={{ animationDuration, ...style }}
				isDisabled={isDisabled}
			>
				<rect
					x='0'
					y='0'
					width='100'
					height='100'
					fill='none'
				/>
				<circle
					className={cx('&-circle')}
					cx='50'
					cy='50'
					r='40'
				/>
				<circle
					style={{ animationDuration }}
					className={cx('&-spinner', { '&-spinner-is-disabled': isDisabled })}
					cx='50'
					cy='50'
					r='40'
				/>
 
			</Icon>
		);
	},
});
 
export default LoadingIcon;