|
| 1 | +import React from 'react'; |
| 2 | +import { Card, CardContent, CardHeader, CardTitle } from '@object-ui/components'; |
| 3 | +import { cn } from '@object-ui/components'; |
| 4 | +import { ArrowDownIcon, ArrowUpIcon, MinusIcon } from 'lucide-react'; |
| 5 | + |
| 6 | +export interface MetricWidgetProps { |
| 7 | + label: string; |
| 8 | + value: string | number; |
| 9 | + trend?: { |
| 10 | + value: number; |
| 11 | + label?: string; |
| 12 | + direction?: 'up' | 'down' | 'neutral'; |
| 13 | + }; |
| 14 | + icon?: React.ReactNode; |
| 15 | + className?: string; |
| 16 | + description?: string; |
| 17 | +} |
| 18 | + |
| 19 | +export const MetricWidget = ({ |
| 20 | + label, |
| 21 | + value, |
| 22 | + trend, |
| 23 | + icon, |
| 24 | + className, |
| 25 | + description, |
| 26 | + ...props |
| 27 | +}: MetricWidgetProps) => { |
| 28 | + return ( |
| 29 | + <Card className={cn("h-full", className)} {...props}> |
| 30 | + <CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2"> |
| 31 | + <CardTitle className="text-sm font-medium"> |
| 32 | + {label} |
| 33 | + </CardTitle> |
| 34 | + {icon && <div className="h-4 w-4 text-muted-foreground">{icon}</div>} |
| 35 | + </CardHeader> |
| 36 | + <CardContent> |
| 37 | + <div className="text-2xl font-bold">{value}</div> |
| 38 | + {(trend || description) && ( |
| 39 | + <p className="text-xs text-muted-foreground flex items-center mt-1"> |
| 40 | + {trend && ( |
| 41 | + <span className={cn( |
| 42 | + "flex items-center mr-2", |
| 43 | + trend.direction === 'up' && "text-green-500", |
| 44 | + trend.direction === 'down' && "text-red-500", |
| 45 | + trend.direction === 'neutral' && "text-yellow-500" |
| 46 | + )}> |
| 47 | + {trend.direction === 'up' && <ArrowUpIcon className="h-3 w-3 mr-1" />} |
| 48 | + {trend.direction === 'down' && <ArrowDownIcon className="h-3 w-3 mr-1" />} |
| 49 | + {trend.direction === 'neutral' && <MinusIcon className="h-3 w-3 mr-1" />} |
| 50 | + {trend.value}% |
| 51 | + </span> |
| 52 | + )} |
| 53 | + {description || trend?.label} |
| 54 | + </p> |
| 55 | + )} |
| 56 | + </CardContent> |
| 57 | + </Card> |
| 58 | + ); |
| 59 | +}; |
0 commit comments