Credit Usage Card
A comprehensive card for displaying credit/usage metrics with progress visualization and history.
Preview
Full-featured credit usage card
Credits Used
56.4%
56.4M / 100M Credits
43.6M Credits Left
Usage History
Usage States
Various credit usage levels
Credits Used
25.0%
25M / 100M Credits
75.0M Credits Left
Usage History
Credits Used
85.0%
85M / 100M Credits
15.0M Credits Left
Usage History
Minimal
Without usage history
Credits Used
42.0%
42M / 100M Credits
58.0M Credits Left
Usage History
Custom Units
Different credit unit labels
Credits Used
72.0%
7.2GB / 10GB Credits
2.8GB Credits Left
Usage History
Graph Variant
Area chart visualization instead of table
Credits Used
56.4%
56.4M / 100M Credits
43.6M Credits Left
Usage History
Peak
4.1K
Avg / day
2.5K
Trend
+119.4%
Props
Component API reference
| Prop | Type | Default | Description |
|---|---|---|---|
variant | 'default' | 'graph' | 'default' | Display variant: 'default' shows table, 'graph' shows area chart |
creditsUsed | number | 56.4 | Current credits used |
totalCredits | number | 100 | Total credits available |
creditUnit | string | 'M' | Unit label (e.g., "M", "GB") |
autoSwitch | boolean | true | Auto-switch toggle state |
onAutoSwitchChange | (checked: boolean) => void | — | Toggle change callback |
autoSwitchLabel | string | 'Auto-switch...' | Toggle label text |
usageHistory | UsageHistoryItem[] | [] | History items for the default (table) variant |
usageChartData | UsageChartDataPoint[] | [] | Data points for the graph variant ({ date, credits }) |
periodOptions | { value: string; label: string }[] | — | Period dropdown options |
selectedPeriod | string | '30' | Selected period value |
onPeriodChange | (value: string) => void | — | Period change callback |
segments | number | 50 | Progress bar segments |
footerNote | string | 'Credit billing...' | Footer note text |
actionLabel | string | 'Manage plan' | Action button label |
onAction | () => void | — | Action button callback |
onViewAll | () => void | — | View all button callback |
className | string | — | Additional CSS classes |
Usage
Import and implementation examples
import { CreditUsageCard } from '@/blocks/data-display/credit-usage-card'
// Basic usage<CreditUsageCard creditsUsed={56.4} totalCredits={100} usageHistory={[ { date: 'Jan 5, 09:26 PM', model: 'Claude 4.5', credits: '641.5K', cost: '$0.54' }, { date: 'Jan 5, 09:21 PM', model: 'Claude 4.5', credits: '334.1K', cost: '$0.27' }, ]}/>
// With state managementconst [autoSwitch, setAutoSwitch] = useState(true)const [period, setPeriod] = useState('30')
<CreditUsageCard creditsUsed={56.4} totalCredits={100} autoSwitch={autoSwitch} onAutoSwitchChange={setAutoSwitch} selectedPeriod={period} onPeriodChange={setPeriod} usageHistory={usageData} onViewAll={() => router.push('/usage')} onAction={() => router.push('/billing')}/>
// Custom units<CreditUsageCard creditsUsed={7.2} totalCredits={10} creditUnit="GB" footerNote="Storage billing is monthly" actionLabel="Upgrade storage"/>
// Graph variant with area chart<CreditUsageCard variant="graph" creditsUsed={56.4} totalCredits={100} usageChartData={[ { date: 'Dec 26', credits: 1200 }, { date: 'Dec 27', credits: 1800 }, { date: 'Dec 28', credits: 950 }, // ... ]} selectedPeriod={period} onPeriodChange={setPeriod}/>Built With
4 componentsThis block uses the following UI components from the design system:
Features
Built-in functionality
- Segmented progress bar: Visual usage indicator with 50 segments
- Auto-switch toggle: Built-in switch for model fallback
- Usage history table: Default variant with date, model, credits, cost columns
- Graph variant: SVG area chart with hover tooltip, peak/avg/trend stats
- Period selector: Dropdown for time range filtering
- Customizable units: Support for any unit label (M, GB, etc.)
- Action buttons: View all and manage plan actions
- Footer with branding: Customizable footer note and icon
- Dark mode: Full dark mode support
Accessibility
Accessibility considerations
ARIA Attributes
Progress bar has role="progressbar"Switch is properly labeledTable uses semantic structureKeyboard Navigation
| Key | Action |
|---|---|
| Tab | Navigate through interactive elements |
| Space/Enter | Toggle switch, activate buttons |
| Arrow keys | Navigate select dropdown |
Notes
- History table is scrollable for many items
- Color is not the only indicator of usage level
- All interactive elements are keyboard accessible