|
| 1 | +import { Card, Text, Spinner, mergeClasses } from '@fluentui/react-components'; |
| 2 | +import { mainLayoutStyles } from '../styles/Styles'; |
| 3 | +import { tokens } from '@fluentui/react-components'; |
| 4 | + |
| 5 | +interface StatCardProps { |
| 6 | + title: string; |
| 7 | + value: number | string; |
| 8 | + icon?: React.ReactNode; |
| 9 | + color?: 'brand' | 'success' | 'warning' | 'danger' | 'neutral'; |
| 10 | +} |
| 11 | + |
| 12 | +export default function StatCard({ title, value, icon, color = 'neutral' }: StatCardProps) { |
| 13 | + const styles = mainLayoutStyles(); |
| 14 | + |
| 15 | + const colorMap = { |
| 16 | + brand: tokens.colorBrandForeground1, |
| 17 | + success: tokens.colorPaletteGreenForeground1, |
| 18 | + warning: tokens.colorPaletteYellowForeground1, |
| 19 | + danger: tokens.colorPaletteRedForeground1, |
| 20 | + neutral: tokens.colorNeutralForeground1, |
| 21 | + }; |
| 22 | + |
| 23 | + const bgColorMap = { |
| 24 | + brand: tokens.colorBrandBackground2, |
| 25 | + success: tokens.colorPaletteGreenBackground2, |
| 26 | + warning: tokens.colorPaletteYellowBackground2, |
| 27 | + danger: tokens.colorPaletteRedBackground2, |
| 28 | + neutral: tokens.colorNeutralBackground2, |
| 29 | + }; |
| 30 | + |
| 31 | + return ( |
| 32 | + <Card |
| 33 | + className={mergeClasses(styles.artifCard)} |
| 34 | + style={{ |
| 35 | + padding: tokens.spacingVerticalL, |
| 36 | + display: 'flex', |
| 37 | + flexDirection: 'column', |
| 38 | + gap: tokens.spacingVerticalM, |
| 39 | + minWidth: '200px', |
| 40 | + }} |
| 41 | + > |
| 42 | + <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}> |
| 43 | + <Text style={{ fontSize: tokens.fontSizeBase300, color: tokens.colorNeutralForeground3 }}> |
| 44 | + {title} |
| 45 | + </Text> |
| 46 | + {icon && ( |
| 47 | + <div |
| 48 | + style={{ |
| 49 | + width: '32px', |
| 50 | + height: '32px', |
| 51 | + borderRadius: '50%', |
| 52 | + backgroundColor: bgColorMap[color], |
| 53 | + color: colorMap[color], |
| 54 | + display: 'flex', |
| 55 | + alignItems: 'center', |
| 56 | + justifyContent: 'center', |
| 57 | + }} |
| 58 | + > |
| 59 | + {icon} |
| 60 | + </div> |
| 61 | + )} |
| 62 | + </div> |
| 63 | + <Text |
| 64 | + style={{ |
| 65 | + fontSize: tokens.fontSizeBase600, |
| 66 | + fontWeight: tokens.fontWeightBold, |
| 67 | + color: colorMap[color], |
| 68 | + }} |
| 69 | + > |
| 70 | + {typeof value === 'number' ? value.toLocaleString() : value} |
| 71 | + </Text> |
| 72 | + </Card> |
| 73 | + ); |
| 74 | +} |
| 75 | + |
| 76 | +export function StatCardSkeleton() { |
| 77 | + const styles = mainLayoutStyles(); |
| 78 | + |
| 79 | + return ( |
| 80 | + <Card |
| 81 | + className={mergeClasses(styles.artifCard)} |
| 82 | + style={{ |
| 83 | + padding: tokens.spacingVerticalL, |
| 84 | + display: 'flex', |
| 85 | + alignItems: 'center', |
| 86 | + justifyContent: 'center', |
| 87 | + minWidth: '200px', |
| 88 | + minHeight: '120px', |
| 89 | + }} |
| 90 | + > |
| 91 | + <Spinner size="small" /> |
| 92 | + </Card> |
| 93 | + ); |
| 94 | +} |
0 commit comments