|
| 1 | +import { MetricCardTemplate, MetricCardSkeletonTemplate } from '@/templates/MetricCardTemplate'; |
| 2 | + |
| 3 | +# Metric Card |
| 4 | + |
| 5 | +Displays a labeled metric with a value, optional trend direction, and percentage change badge. Includes a skeleton loading state for consistent UX during data fetches. |
| 6 | + |
| 7 | +<div className="not-prose my-8 rounded-lg border overflow-hidden bg-gradient-to-br from-muted/40 via-background to-muted/40 dark:from-muted/20 dark:via-background dark:to-muted/20"> |
| 8 | + <MetricCardTemplate /> |
| 9 | +</div> |
| 10 | + |
| 11 | +## Features |
| 12 | + |
| 13 | +- **Trend indicator**: Shows an up/down badge colored by positive (green) or negative (red) trend |
| 14 | +- **Context-aware direction**: `isLowerBetter` flips what counts as a positive trend (e.g., response time going down is good) |
| 15 | +- **Loading skeleton**: `MetricCardSkeleton` matches the card dimensions for seamless loading states |
| 16 | +- **Card variants**: Supports the same `variant` prop as the base Card (`default`, `solid`) |
| 17 | + |
| 18 | +## Installation |
| 19 | + |
| 20 | +```bash |
| 21 | +npx shadcn@latest add @uipath/metric-card |
| 22 | +``` |
| 23 | + |
| 24 | +### Dependencies |
| 25 | + |
| 26 | +This component depends on the following registry components: |
| 27 | + |
| 28 | +- [Card](/shadcn-components/card) |
| 29 | +- [Badge](/shadcn-components/badge) |
| 30 | +- [Skeleton](/shadcn-components/skeleton) |
| 31 | + |
| 32 | +## Usage |
| 33 | + |
| 34 | +```tsx |
| 35 | +import { MetricCard, MetricCardSkeleton } from '@/components/ui/metric-card'; |
| 36 | +``` |
| 37 | + |
| 38 | +### Basic |
| 39 | + |
| 40 | +```tsx |
| 41 | +<MetricCard label="Total Revenue" value="$12,450" /> |
| 42 | +``` |
| 43 | + |
| 44 | +### With Trend |
| 45 | + |
| 46 | +```tsx |
| 47 | +<MetricCard |
| 48 | + label="Total Revenue" |
| 49 | + value="$12,450" |
| 50 | + trend="up" |
| 51 | + percentage={8.2} |
| 52 | +/> |
| 53 | +``` |
| 54 | + |
| 55 | +### Lower is Better |
| 56 | + |
| 57 | +Use `isLowerBetter` for metrics where a downward trend is positive, such as response time or error rate. |
| 58 | + |
| 59 | +```tsx |
| 60 | +<MetricCard |
| 61 | + label="Avg. Response Time" |
| 62 | + value="1.2s" |
| 63 | + trend="down" |
| 64 | + percentage={15} |
| 65 | + isLowerBetter |
| 66 | +/> |
| 67 | +``` |
| 68 | + |
| 69 | +### Dashboard Grid |
| 70 | + |
| 71 | +```tsx |
| 72 | +<div className="grid grid-cols-2 lg:grid-cols-4 gap-4"> |
| 73 | + <MetricCard label="Summaries" value={142} trend="up" percentage={12} /> |
| 74 | + <MetricCard label="Review Time" value="4.2m" trend="down" percentage={8} isLowerBetter /> |
| 75 | + <MetricCard label="Approved" value={98} trend="up" percentage={5} /> |
| 76 | + <MetricCard label="Rejected" value={3} trend="down" percentage={20} isLowerBetter /> |
| 77 | +</div> |
| 78 | +``` |
| 79 | + |
| 80 | +### Loading State |
| 81 | + |
| 82 | +<div className="not-prose my-8 rounded-lg border overflow-hidden bg-gradient-to-br from-muted/40 via-background to-muted/40 dark:from-muted/20 dark:via-background dark:to-muted/20"> |
| 83 | + <MetricCardSkeletonTemplate /> |
| 84 | +</div> |
| 85 | + |
| 86 | +```tsx |
| 87 | +<div className="grid grid-cols-2 lg:grid-cols-4 gap-4"> |
| 88 | + <MetricCardSkeleton /> |
| 89 | + <MetricCardSkeleton /> |
| 90 | + <MetricCardSkeleton /> |
| 91 | + <MetricCardSkeleton /> |
| 92 | +</div> |
| 93 | +``` |
| 94 | + |
| 95 | +## API Reference |
| 96 | + |
| 97 | +### MetricCard |
| 98 | + |
| 99 | +| Prop | Type | Default | Description | |
| 100 | +|------|------|---------|-------------| |
| 101 | +| `label` | `string` | — | The metric label | |
| 102 | +| `value` | `string \| number` | — | The metric value to display | |
| 103 | +| `trend` | `'up' \| 'down' \| 'neutral'` | — | Direction of the trend | |
| 104 | +| `percentage` | `number` | — | Percentage change amount | |
| 105 | +| `isLowerBetter` | `boolean` | `false` | If true, a downward trend is positive (green) | |
| 106 | +| `variant` | `'default' \| 'solid'` | `'default'` | Card styling variant | |
| 107 | + |
| 108 | +### MetricCardSkeleton |
| 109 | + |
| 110 | +| Prop | Type | Default | Description | |
| 111 | +|------|------|---------|-------------| |
| 112 | +| `variant` | `'default' \| 'solid'` | `'default'` | Card styling variant | |
0 commit comments