File size: 1,276 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 |
import { __experimentalHStack as HStack, ProgressBar } from '@wordpress/components';
import './style.scss';
interface StatProps {
density?: 'low' | 'high';
description?: string;
descriptionAlignment?: 'start' | 'end';
metric: string;
progressColor?: 'alert-yellow' | 'alert-red' | 'alert-green';
progressLabel?: string;
progressValue?: number;
strapline?: string;
}
export function Stat( {
density = 'low',
description,
descriptionAlignment = 'start',
metric,
progressColor,
progressLabel,
progressValue,
strapline,
}: StatProps ) {
return (
<div className={ `dashboard-stat--density-${ density }` }>
{ strapline && <div className="dashboard-stat__strapline">{ strapline }</div> }
<HStack
alignment="baseline"
spacing={ 2 }
justify={ descriptionAlignment === 'start' ? 'start' : 'space-between' }
>
<div className="dashboard-stat__metric">{ metric }</div>
{ description && <div className="dashboard-stat__description">{ description }</div> }
</HStack>
{ progressValue !== undefined && (
<ProgressBar
className={ `dashboard-stat__progress-bar dashboard-stat__progress-bar--${ progressColor }` }
value={ progressValue }
aria-label={ progressLabel ?? `${ progressValue }%` }
/>
) }
</div>
);
}
|