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
Sparkline
A tiny line or area chart without axes.
import { Sparkline } from "@/registry/vcare/ui/sparkline"
export default function SparklineDemo() {
return (
<div className="mx-auto grid max-w-md gap-4 sm:grid-cols-2">
<Sparkline className="h-16" data={[12, 18, 15, 22, 28, 24, 31, 35, 30, 38]} />
<Sparkline className="h-16" variant="line" color="var(--chart-3)" data={[40, 36, 38, 31, 29, 33, 27, 22, 25, 20]} />
</div>
)
}Installation
npx shadcn@latest add @vcare/sparklineOr install directly from the URL: https://ui.vcarehms.com/r/sparkline.json
- Install the dependencies:
npm i recharts - Add the registry items it uses: utils.
- Copy this file into your project and change the
@/registry/vcare/…imports to your own paths.
components/ui/sparkline.tsx
'use client';
import * as React from 'react';
import { Area, AreaChart, AreaRevealShape, Line, LineChart, ResponsiveContainer, type AreaRevealShapeProps } from 'recharts';
import { cn } from '@/registry/vcare/lib/utils';
export interface SparklineProps extends React.ComponentProps<'div'> {
/** Series to plot, oldest first. */
data: number[];
variant?: 'area' | 'line';
/** Area fill: a plain gradient, or a dot grid that fades out toward the line. */
fill?: 'gradient' | 'dots';
/** Any CSS color. Defaults to the theme primary. */
color?: string;
curve?: 'monotone' | 'linear' | 'step';
strokeWidth?: number;
/** Animate after hydration and when data changes. Respects reduced motion. */
animate?: boolean;
animationDuration?: number;
}
const reducedMotionQuery = '(prefers-reduced-motion: reduce)';
function subscribeToReducedMotion(onChange: () => void) {
const query = window.matchMedia(reducedMotionQuery);
query.addEventListener('change', onChange);
return () => query.removeEventListener('change', onChange);
}
function getReducedMotionSnapshot() {
return window.matchMedia(reducedMotionQuery).matches;
}
function getReducedMotionServerSnapshot() {
return true;
}
/** Area shape that masks the fill to a dot grid while keeping the stroke solid. */
function DotGridAreaShape({ maskId, ...props }: AreaRevealShapeProps & { maskId: string }) {
return (
<>
<g mask={`url(#${maskId})`}>
<AreaRevealShape {...props} stroke="none" />
</g>
<AreaRevealShape {...props} id={undefined} fill="none" />
</>
);
}
function Sparkline({
data,
variant = 'area',
fill = 'gradient',
color = 'var(--primary)',
curve = 'monotone',
strokeWidth = 1.5,
animate = true,
animationDuration = 500,
className,
...props
}: SparklineProps) {
const id = React.useId();
const reducedMotion = React.useSyncExternalStore(subscribeToReducedMotion, getReducedMotionSnapshot, getReducedMotionServerSnapshot);
const animationActive = animate && !reducedMotion;
const dots = variant === 'area' && fill === 'dots';
const points = React.useMemo(() => data.map((y, i) => ({ i, y })), [data]);
const margin = { top: 2, right: 0, bottom: 0, left: 0 };
return (
<div data-slot="sparkline" aria-hidden="true" className={cn('h-10 w-full', className)} {...props}>
<ResponsiveContainer width="100%" height="100%">
{variant === 'line' ? (
<LineChart data={points} margin={margin}>
<Line
type={curve}
dataKey="y"
stroke={color}
strokeWidth={strokeWidth}
dot={false}
isAnimationActive={animationActive}
animationDuration={animationDuration}
animationEasing="ease-out"
/>
</LineChart>
) : (
<AreaChart data={points} margin={margin}>
<defs>
<linearGradient id={id} x1="0" y1="0" x2="0" y2="1">
<stop offset="0%" stopColor={color} stopOpacity={dots ? 0.08 : 0.3} />
<stop offset="100%" stopColor={color} stopOpacity={dots ? 0.9 : 0} />
</linearGradient>
{dots ? (
<>
<pattern id={`${id}-dots`} patternUnits="userSpaceOnUse" width={4} height={4}>
<circle cx={2} cy={2} r={0.9} fill="#fff" />
</pattern>
<mask id={`${id}-mask`} maskUnits="userSpaceOnUse" x={0} y={0} width="100%" height="100%">
<rect width="100%" height="100%" fill={`url(#${id}-dots)`} />
</mask>
</>
) : null}
</defs>
<Area
type={curve}
dataKey="y"
stroke={color}
strokeWidth={strokeWidth}
fill={`url(#${id})`}
fillOpacity={dots ? 1 : undefined}
dot={false}
isAnimationActive={animationActive}
animationDuration={animationDuration}
animationEasing="ease-out"
shape={dots ? (shapeProps: AreaRevealShapeProps) => <DotGridAreaShape {...shapeProps} maskId={`${id}-mask`} /> : undefined}
/>
</AreaChart>
)}
</ResponsiveContainer>
</div>
);
}
export { Sparkline };Usage
import { Sparkline } from "@/components/ui/sparkline"Exports
Sparkline
Dependencies
recharts@^3.11.1(npm)@vcare/utils(registry)
Raw item: /r/sparkline.json