index.tsx
65 lines
| 1 | import {Spinner} from '@givewp/components'; |
| 2 | import {HeaderText} from '../Header'; |
| 3 | import PercentChangePill |
| 4 | from '@givewp/campaigns/admin/components/CampaignDetailsPage/Components/CampaignStats/PercentChangePill'; |
| 5 | import classnames from 'classnames'; |
| 6 | import styles from './styles.module.scss'; |
| 7 | import { __ } from '@wordpress/i18n'; |
| 8 | |
| 9 | /** |
| 10 | * @since 4.10.0 replace inActive with upgrade object. |
| 11 | * @since 4.6.0 add href & inActive props to handle Fee Recovery widget. |
| 12 | * @since 4.4.0 |
| 13 | */ |
| 14 | export type StatWidgetProps = { |
| 15 | label: string; |
| 16 | value: string | React.ReactNode; |
| 17 | description?: string; |
| 18 | loading?: boolean; |
| 19 | className?: string; |
| 20 | upgrade?: { |
| 21 | href: string; |
| 22 | tooltip: string; |
| 23 | }; |
| 24 | }; |
| 25 | |
| 26 | /** |
| 27 | * @since 4.10.0 use upgrade object instead of inActive. |
| 28 | * @since 4.6.0 use new props to handle Fee Recovery widget. |
| 29 | * @since 4.4.0 |
| 30 | */ |
| 31 | export default function StatWidget({ |
| 32 | label, |
| 33 | value, |
| 34 | description, |
| 35 | upgrade = null, |
| 36 | loading = false, |
| 37 | className, |
| 38 | }: StatWidgetProps) { |
| 39 | return ( |
| 40 | <div className={classnames(styles.statWidget, className)}> |
| 41 | <header> |
| 42 | <HeaderText>{label}</HeaderText> |
| 43 | </header> |
| 44 | <div className={styles.statWidgetAmount}> |
| 45 | <div className={classnames(styles.statWidgetDisplay, {[styles.requiresUpgrade]: upgrade})}> |
| 46 | {!loading ? ( |
| 47 | value |
| 48 | ) : ( |
| 49 | <span> |
| 50 | <Spinner size="small" /> |
| 51 | </span> |
| 52 | )} |
| 53 | {upgrade && (<a className={styles.upgradeLink} href={upgrade?.href} data-addon-tooltip={upgrade?.tooltip}>{__('Upgrade', 'give')}</a>)} |
| 54 | </div> |
| 55 | </div> |
| 56 | {description && ( |
| 57 | <footer> |
| 58 | <div>{description}</div> |
| 59 | </footer> |
| 60 | )} |
| 61 | |
| 62 | </div> |
| 63 | ); |
| 64 | } |
| 65 |