File size: 1,985 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { LoadingPlaceholder, StatsCard } from '@automattic/components';
import clsx from 'clsx';
import React from 'react';

import './stats-card-skeleton.scss';

type StatsCardSkeletonProps = {
	isLoading: boolean;
	className?: string;
	title?: string;
	/**
	 * @property {number} type - Type of card to display. One of three sets with different bar lengths to avoid a monotonous interface.
	 */
	type?: 1 | 2 | 3;
	withHero?: boolean;
	withSplitHeader?: boolean;
	toggleControl?: React.ReactNode;
	metricLabel?: string;
	mainItemLabel?: string;
	titleNodes?: React.ReactNode;
};

const StatsCardSkeleton: React.FC< StatsCardSkeletonProps > = ( {
	isLoading,
	className,
	title,
	type = 1,
	withHero,
	withSplitHeader,
	toggleControl,
	metricLabel,
	mainItemLabel,
	titleNodes,
} ) => {
	// Horizontal Bar placeholders
	const dataTypes = [
		[ 100, 80, 60, 40, 20 ],
		[ 100, 50, 30, 20, 10 ],
		[ 100, 70, 45, 20, 5 ],
	];

	const data = dataTypes[ type ] ?? dataTypes[ 1 ]; // Allow for different types

	return isLoading ? (
		<div
			className={ clsx(
				'stats-card-skeleton',
				{ [ 'stats-card-skeleton--with-hero' ]: withHero },
				className
			) }
		>
			{ /* TODO: Empty title - use another LoadingPlaceholder */ }
			<StatsCard
				title={ title || '' }
				metricLabel={ metricLabel }
				mainItemLabel={ mainItemLabel }
				heroElement={
					withHero ? (
						<LoadingPlaceholder
							className="stats-card-skeleton__placeholder"
							width="100%"
							height="400px"
						/>
					) : null
				}
				splitHeader={ withSplitHeader }
				toggleControl={ toggleControl }
				titleNodes={ titleNodes }
			>
				<ul>
					{ data?.map( ( value, index ) => {
						return (
							<li key={ index }>
								<LoadingPlaceholder
									className="stats-card-skeleton__placeholder"
									width={ `${ value }%` }
									height="36px"
								/>
							</li>
						);
					} ) }
				</ul>
			</StatsCard>
		</div>
	) : null;
};

export default StatsCardSkeleton;