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
Delta Badge
A colored arrow and percentage for a change, up or down.
import { DeltaBadge } from "@/registry/vcare/ui/delta-badge"
export default function DeltaBadgeDemo() {
return (
<div className="flex flex-wrap items-center gap-3">
<DeltaBadge delta={0.124} />
<DeltaBadge delta={-0.032} />
<DeltaBadge delta={0} />
<DeltaBadge delta={0.08} variant="soft" />
<DeltaBadge delta={-0.15} variant="text" />
<DeltaBadge delta={-0.1} invert variant="soft" />
</div>
)
}Installation
npx shadcn@latest add @vcare/delta-badgeOr install directly from the URL: https://ui.vcarehms.com/r/delta-badge.json
- Install the dependencies:
npm i lucide-react - Add the registry items it uses: format, utils.
- Copy this file into your project and change the
@/registry/vcare/…imports to your own paths.
components/ui/delta-badge.tsx
import * as React from 'react';
import { Minus, TrendingDown, TrendingUp } from 'lucide-react';
import { cn } from '@/registry/vcare/lib/utils';
import { formatDelta } from '@/registry/vcare/lib/format';
export type DeltaDirection = 'up' | 'down' | 'flat';
export function getDeltaDirection(delta: number | undefined): DeltaDirection {
if (delta === undefined || delta === 0 || !Number.isFinite(delta)) return 'flat';
return delta > 0 ? 'up' : 'down';
}
const directionIcon: Record<DeltaDirection, React.ElementType> = {
up: TrendingUp,
down: TrendingDown,
flat: Minus,
};
export interface DeltaBadgeProps extends React.ComponentProps<'span'> {
/** Fractional change, e.g. 0.124 for +12.4%. */
delta: number;
/** Treat a decrease as good and an increase as bad (churn, latency, errors). */
invert?: boolean;
variant?: 'outline' | 'soft' | 'text';
showIcon?: boolean;
}
function DeltaBadge({ delta, invert = false, variant = 'outline', showIcon = true, className, children, ...props }: DeltaBadgeProps) {
const direction = getDeltaDirection(delta);
const positive = direction === 'flat' ? null : (direction === 'up') !== invert;
const Icon = directionIcon[direction];
return (
<span
data-slot="delta-badge"
data-direction={direction}
data-positive={positive}
className={cn(
'inline-flex items-center gap-1 text-xs font-medium tabular-nums',
variant === 'outline' && 'rounded-md border px-1.5 py-0.5',
variant === 'soft' && 'rounded-md px-1.5 py-0.5',
variant === 'soft' && positive === true && 'bg-emerald-500/10',
variant === 'soft' && positive === false && 'bg-red-500/10',
variant === 'soft' && positive === null && 'bg-muted',
positive === true && 'text-emerald-600 dark:text-emerald-400',
positive === false && 'text-red-600 dark:text-red-400',
positive === null && 'text-muted-foreground',
className,
)}
{...props}
>
{showIcon ? <Icon className="size-3" aria-hidden="true" /> : null}
{children ?? formatDelta(delta)}
</span>
);
}
export { DeltaBadge };Usage
import { DeltaBadge } from "@/components/ui/delta-badge"Exports
DeltaBadge
Dependencies
lucide-react@^1.80.0(npm)@vcare/format(registry)@vcare/utils(registry)
Raw item: /r/delta-badge.json