All files / LoadingMessage LoadingMessage.tsx

92.1% Statements 35/38
100% Branches 8/8
25% Functions 1/4
100% Lines 35/35

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154                18x   18x           18x 18x 18x     18x 18x                 18x 18x 18x     18x 18x                 18x 18x 18x     18x 18x                                           18x     35x 35x   35x 35x 35x 35x 35x 35x 35x   35x                                                   18x 18x 18x   18x 18x 18x         18x                                                        
/* eslint-disable react/prop-types */
import _, { omit } from 'lodash';
import React from 'react';
import PropTypes from 'prop-types';
import { lucidClassNames } from '../../util/style-helpers';
import { getFirst, StandardProps } from '../../util/component-types';
import LoadingIcon from '../Icon/LoadingIcon/LoadingIcon';
 
const cx = lucidClassNames.bind('&-LoadingMessage');
 
const { any, node, string } = PropTypes;
 
/** Loading Message Icon */
export interface ILoadingMessageIconProps extends StandardProps {
	description?: string;
}
const LoadingMessageIcon = (_props: ILoadingMessageIconProps): null => null;
LoadingMessageIcon.displayName = 'LoadingMessage.Icon';
LoadingMessageIcon.peek = {
	description: `Renders the \`Icon\` element passed in.`,
};
LoadingMessageIcon.propName = 'Icon';
LoadingMessageIcon.propTypes = {
	description: string,
	children: any,
};
 
/** Loading Message Title */
export interface ILoadingMessageTitleProps extends StandardProps {
	description?: string;
}
const LoadingMessageTitle = (_props: ILoadingMessageTitleProps): null => null;
LoadingMessageTitle.displayName = 'LoadingMessage.Title';
LoadingMessageTitle.peek = {
	description: `Renders an \`<h3>\` that represents the title of the \`LoadingMessage\`.  Defaults to the string "Loading".`,
};
LoadingMessageTitle.propName = 'Title';
LoadingMessageTitle.propTypes = {
	description: string,
	children: any,
};
 
/** Loading Message Body */
export interface ILoadingMessageBodyProps extends StandardProps {
	description?: string;
}
const LoadingMessageBody = (_props: ILoadingMessageBodyProps): null => null;
LoadingMessageBody.displayName = 'LoadingMessage.Body';
LoadingMessageBody.peek = {
	description: `Renders a \`<span>\` that represents the body of the \`LoadingMessage\`.`,
};
LoadingMessageBody.propName = 'Body';
LoadingMessageBody.propTypes = {
	description: string,
	children: any,
};
 
/** Loading Message */
export interface ILoadingMessageProps
	extends StandardProps,
		React.DetailedHTMLProps<
			React.HTMLAttributes<HTMLDivElement>,
			HTMLDivElement
		> {
	/** Custom Icon element (alias for `LoadingMessage.Icon`) */
	Icon?: React.ReactNode;
 
	/** Custom Title element (alias for `LoadingMessage.Title`) */
	Title?: React.ReactNode;
 
	/** Custom Body element (alias for `LoadingMessage.Body`) */
	Body?: React.ReactNode;
}
 
export const LoadingMessage = (
	props: ILoadingMessageProps
): React.ReactElement => {
	const { className, ...passThroughs } = props;
	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
			{...omit(passThroughs, [
				'className',
				'children',
				'Icon',
				'Title',
				'Body',
				'initialState',
				'callbackId',
			])}
			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>
	);
};
 
LoadingMessage.Icon = LoadingMessageIcon;
LoadingMessage.Title = LoadingMessageTitle;
LoadingMessage.Body = LoadingMessageBody;
 
LoadingMessage._isPrivate = true;
LoadingMessage.displayName = 'LoadingMessage';
LoadingMessage.peek = {
	description: `A loading message.`,
	categories: ['communication'],
	madeFrom: ['LoadingIcon'],
};
LoadingMessage.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: node,
 
	/**
		Custom Title element (alias for \`LoadingMessage.Title\`)
	*/
	Title: node,
 
	/**
		Custom Body element (alias for \`LoadingMessage.Body\`)
	*/
	Body: node,
};
 
export default LoadingMessage;