Documentation menu
Getting Started
Components
Primitives
- Agent Thinking
- Alert
- Alert Dialog
- Avatar
- Badge
- Breadcrumb
- Button
- Button Group
- Calendar
- Card
- Checkbox
- Command
- Command Palette
- Context Menu
- Data Table
- Dialog
- Dropdown Menu
- Empty
- Field
- Glow Cloud
- Input
- Label
- Medication Schedule
- Period Tabs
- Popover
- Rainbow Button
- Scroll Area
- Select
- Selectable Card
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner
- Spinner
- Switch
- Table
- Tabs
- Tag
- Textarea
- Timeline
- Tooltip
- Use Count Up
Charts and metrics
Patterns
- Confirm Button
- Date Picker
- Embedded
- Empty State
- Entity Drawer
- Error Boundary
- Field Row
- File Dropzone
- Form Dialog
- Kv
- List Editor
- List Page
- Live Time
- Mini Table
- Money
- Note Field
- Note Text
- Page Card
- Page Header
- Page Tabs
- Page Toolbar
- Person Cell
- Picture Field
- Print Card
- Range Switcher
- Row Actions
- Search Input
- Search Select
- Selected Box
- Signature Pad
- Status Badge
- Sub Nav Layout
- Suggest Input
- Tab Icons
- Table Footer
- Theme Accent Picker
- Time Picker
- View All Link
Dashboard cards
Advanced
Device frames
Website widgets
Website screens
Website panels
Charts and metrics
Metric Value
A number that abbreviates large values and animates when it changes.
import { MetricValue } from "@/registry/vcare/ui/metric-value"
export default function MetricValueDemo() {
return (
<div className="flex flex-wrap items-baseline justify-center gap-8 text-3xl font-semibold">
<MetricValue value={1284} />
<MetricValue value={2450000} format="currency" currency="INR" />
<MetricValue value={0.873} format="percent" />
<MetricValue value={18} suffix={<span className="text-base text-muted-foreground"> min</span>} />
</div>
)
}Installation
npx shadcn@latest add @vcare/metric-valueOr install directly from the URL: https://ui.vcarehms.com/r/metric-value.json
- Add the registry items it uses: format, tooltip, utils.
- Copy this file into your project and change the
@/registry/vcare/…imports to your own paths.
components/ui/metric-value.tsx
import * as React from 'react';
import { cn } from '@/registry/vcare/lib/utils';
import { formatNumber, type NumberFormat } from '@/registry/vcare/lib/format';
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/registry/vcare/ui/tooltip';
/** Values at or above this are abbreviated by default. */
export const DEFAULT_COMPACT_FROM = 100_000;
export interface MetricValueProps extends Omit<React.ComponentProps<'span'>, 'children'> {
/** Strings render as-is. */
value: number | string;
format?: NumberFormat;
currency?: string;
maximumFractionDigits?: number;
/** Values at or above this are abbreviated (e.g. $158K) with the full value in a tooltip. Set to Infinity to always show the full value. */
compactFrom?: number;
/** Text after the number, e.g. a unit. */
suffix?: React.ReactNode;
}
/** A formatted number. Large values are abbreviated and reveal the full value on hover. */
function MetricValue({
value,
format,
currency,
maximumFractionDigits,
compactFrom = DEFAULT_COMPACT_FROM,
suffix,
className,
...props
}: MetricValueProps) {
const classes = cn('tabular-nums', className);
if (typeof value !== 'number') {
return (
<span data-slot="metric-value" className={classes} {...props}>
{value}
{suffix}
</span>
);
}
const full = formatNumber(value, { format, currency, maximumFractionDigits });
const abbreviate = format !== 'percent' && Math.abs(value) >= compactFrom;
if (!abbreviate) {
return (
<span data-slot="metric-value" className={classes} {...props}>
{full}
{suffix}
</span>
);
}
return (
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<span data-slot="metric-value" data-compact="" className={cn(classes, 'cursor-default')} {...props}>
{formatNumber(value, { format, currency, compact: true })}
{suffix}
</span>
</TooltipTrigger>
<TooltipContent className="tabular-nums">
{full}
{suffix}
</TooltipContent>
</Tooltip>
</TooltipProvider>
);
}
export { MetricValue };Usage
import { DEFAULT_COMPACT_FROM, MetricValue } from "@/components/ui/metric-value"Exports
DEFAULT_COMPACT_FROM, MetricValue
Dependencies
@vcare/format(registry)@vcare/tooltip(registry)@vcare/utils(registry)
Raw item: /r/metric-value.json