index.tsx
60 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.6.0 add href & inActive props to handle Fee Recovery widget. |
| 11 | * @since 4.4.0 |
| 12 | */ |
| 13 | export type StatWidgetProps = { |
| 14 | label: string; |
| 15 | value: string | React.ReactNode; |
| 16 | description?: string; |
| 17 | loading?: boolean; |
| 18 | inActive?: boolean; |
| 19 | href?: string; |
| 20 | }; |
| 21 | |
| 22 | /** |
| 23 | * @since 4.6.0 use new props to handle Fee Recovery widget. |
| 24 | * @since 4.4.0 |
| 25 | */ |
| 26 | export default function StatWidget({ |
| 27 | label, |
| 28 | value, |
| 29 | description, |
| 30 | href, |
| 31 | loading = false, |
| 32 | inActive = false, |
| 33 | }: StatWidgetProps) { |
| 34 | return ( |
| 35 | <div className={classnames(styles.statWidget)}> |
| 36 | <header> |
| 37 | <HeaderText>{label}</HeaderText> |
| 38 | </header> |
| 39 | <div className={styles.statWidgetAmount}> |
| 40 | <div className={classnames(styles.statWidgetDisplay, {[styles.inActive]: inActive})}> |
| 41 | {!loading ? ( |
| 42 | value |
| 43 | ) : ( |
| 44 | <span> |
| 45 | <Spinner size="small" /> |
| 46 | </span> |
| 47 | )} |
| 48 | {inActive && (<a className={styles.upgradeLink} href={href} data-feerecovery-tooltip={__('Keep 100% of your fundraising revenue by providing donors with the option to cover the credit card processing fees', 'give')}>{__('Upgrade', 'give')}</a>)} |
| 49 | </div> |
| 50 | </div> |
| 51 | {description && ( |
| 52 | <footer> |
| 53 | <div>{description}</div> |
| 54 | </footer> |
| 55 | )} |
| 56 | |
| 57 | </div> |
| 58 | ); |
| 59 | } |
| 60 |