All files / components/LoadingMessage LoadingMessage.jsx

100% Statements 13/13
100% Branches 8/8
100% Functions 0/0
100% Lines 13/13
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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110            120x           120x                 120x                                                                                                                   19x           19x   19x 19x 19x 19x 19x 19x 19x   19x                            
import _ from 'lodash';
import React from 'react';
import { lucidClassNames } from '../../util/style-helpers';
import { createClass, getFirst, omitProps } from '../../util/component-types';
import LoadingIcon from '../Icon/LoadingIcon/LoadingIcon';
 
const cx = lucidClassNames.bind('&-LoadingMessage');
 
const {
	any,
	node,
	string,
} = React.PropTypes;
 
/**
 *
 * {"categories": ["communication"], "madeFrom": ["LoadingIcon"]}
 *
 * A loading message.
 *
 */
const LoadingMessage = createClass({
	displayName: 'LoadingMessage',
	_isPrivate: true,
	propTypes: {
		/**
		 * Class names that are appended to the defaults.
		 */
		className: string,
		/**
		 * Any valid React children.
		 */
		children: node,
		/**
		 * Custom Icon element (alias for `LoadingMessage.Icon`)
		 */
		Icon: any,
		/**
		 * Custom Title element (alias for `LoadingMessage.Title`)
		 */
		Title: any,
		/**
		 * Custom Body element (alias for `LoadingMessage.Body`)
		 */
		Body: any,
	},
 
	components: {
		/**
		 * Renders the `Icon` element passed in
		 */
		Icon: createClass({
			displayName: 'LoadingMessage.Icon',
			propName: 'Icon',
		}),
		/**
		 * Renders an `<h3>` that represents the title of the `LoadingMessage`.
		 * Defaults to the string "Loading".
		 */
		Title: createClass({
			displayName: 'LoadingMessage.Title',
			propName: 'Title',
		}),
		/**
		 * Renders an `<span>` that represents the body of the `LoadingMessage`.
		 */
		Body: createClass({
			displayName: 'LoadingMessage.Body',
			propName: 'Body',
		}),
	},
 
	render() {
		const {
			props,
			props: {
				className,
				...passThroughs,
			},
		} = this;
 
		const {
			Icon,
			Title,
			Body,
		} = LoadingMessage;
 
		const defaultTitle = 'Loading';
		const iconElement = getFirst(props, Icon);
		const iconChildren = _.get(iconElement, 'props.children', <LoadingIcon />);
		const titleElement = getFirst(props, Title);
		const titleChildren = _.get(titleElement, 'props.children');
		const bodyElement = getFirst(props, Body);
		const bodyChildren = _.get(bodyElement, 'props.children', null);
 
		return (
			<div
				{...omitProps(passThroughs, LoadingMessage)}
				className={cx('&', { '&-no-content': _.isNull(titleChildren) && !bodyChildren }, className)}
			>
				{iconChildren}
				{!_.isNull(titleChildren) && <h3 className={cx('&-title')}>{titleChildren || defaultTitle}</h3>}
				{bodyChildren && <span className={cx('&-body')}>{bodyChildren}</span>}
			</div>
		);
	},
});
 
export default LoadingMessage;