index.tsx
50 lines
| 1 | import React from 'react'; |
| 2 | import classnames from 'classnames'; |
| 3 | import Spinner from '@givewp/src/Admin/components/Spinner'; |
| 4 | import styles from './styles.module.scss'; |
| 5 | |
| 6 | /** |
| 7 | * @since 4.8.0 abstracted from DonorSummary to be used with other components. Add ReactNode support. |
| 8 | * @since 4.5.0 |
| 9 | */ |
| 10 | export type SummaryItem = { |
| 11 | label: string; |
| 12 | value: string | React.ReactNode; |
| 13 | isPill?: boolean; |
| 14 | }; |
| 15 | |
| 16 | /** |
| 17 | * @since 4.8.0 |
| 18 | */ |
| 19 | interface SummaryTableProps { |
| 20 | title?: string; |
| 21 | subtitle?: string; |
| 22 | data: SummaryItem[]; |
| 23 | isLoading?: boolean; |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * @since 4.8.0 |
| 28 | */ |
| 29 | export default function SummaryTable({data, isLoading}: SummaryTableProps) { |
| 30 | return ( |
| 31 | <div className={styles.summaryTableContainer}> |
| 32 | {data.map((item, index) => ( |
| 33 | <div className={styles.summaryTable} key={index}> |
| 34 | <p className={styles.summaryTableLabel}>{item.label}</p> |
| 35 | {isLoading ? ( |
| 36 | <Spinner /> |
| 37 | ) : ( |
| 38 | <strong className={classnames(styles.summaryTableValue, { |
| 39 | [styles.pill]: item.isPill, |
| 40 | })}> |
| 41 | {item.value} |
| 42 | </strong> |
| 43 | )} |
| 44 | </div> |
| 45 | ))} |
| 46 | </div> |
| 47 | ); |
| 48 | } |
| 49 | |
| 50 |