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
Dashboard cards
Sleep Score Card
A score with its parts as bars.
import { SleepScoreCard } from "@/registry/vcare/ui/sleep-score-card"
export default function SleepScoreCardDemo() {
return (
<SleepScoreCard
className="mx-auto max-w-md"
label="Recovery score"
score={78}
rating="Good"
parts={[
{ label: "Sleep", detail: "7h 10m", value: 32, max: 40, color: "var(--chart-1)" },
{ label: "Activity", value: 24, max: 30, color: "var(--chart-2)" },
{ label: "Pain", detail: "Low", value: 22, max: 30, color: "var(--chart-3)" },
]}
/>
)
}Installation
npx shadcn@latest add @vcare/sleep-score-cardOr install directly from the URL: https://ui.vcarehms.com/r/sleep-score-card.json
- Add the registry items it uses: insight-card, utils.
- Copy this file into your project and change the
@/registry/vcare/…imports to your own paths.
components/ui/sleep-score-card.tsx
import { useState } from 'react';
import { InsightCard, InsightRow } from '@/registry/vcare/ui/insight-card';
import { cn } from '@/registry/vcare/lib/utils';
export interface SleepPart {
label: string;
/** Muted detail after the label, e.g. "7h 50m". */
detail?: string;
value: number;
max: number;
color: string;
}
interface Props {
score: number;
/** Word under the card label, e.g. "Excellent". */
rating: string;
parts: SleepPart[];
label?: string;
action?: React.ReactNode;
className?: string;
}
const R = 60;
const GAP = 6; // percent of the circle left empty between arcs
/** A ring split into one arc per factor. Each arc fills to value/max; hovering a row brings its arc forward. */
export function SleepScoreCard({ score, rating, parts, label, action, className }: Props) {
const [active, setActive] = useState<number | null>(null);
const total = parts.reduce((s, p) => s + p.max, 0) || 1;
let cursor = 0;
const arcs = parts.map((p, i) => {
const span = (p.max / total) * 100;
const start = cursor;
cursor += span;
const len = Math.max(0, span - GAP);
return { p, i, start: start + GAP / 2, len, fill: len * Math.min(1, p.value / (p.max || 1)) };
});
return (
<InsightCard className={className} label={label} value={rating} action={action}>
<div className="relative mx-auto size-44">
<svg viewBox="0 0 160 160" className="size-full -rotate-90" role="img" aria-label={`${rating}, ${score}`}>
{arcs.map(({ p, i, start, len, fill }) => {
const dim = active !== null && active !== i;
const arc = (length: number, opacity: number) => (
<circle
cx="80"
cy="80"
r={R}
fill="none"
stroke={p.color}
strokeWidth="16"
strokeLinecap="round"
pathLength="100"
strokeDasharray={`${Math.max(length, 0.01)} ${100 - Math.max(length, 0.01)}`}
strokeDashoffset={-start}
opacity={opacity}
/>
);
return (
<g key={p.label} className="transition-opacity duration-200" style={{ opacity: dim ? 0.35 : 1 }}>
{arc(len, 0.22)}
{arc(fill, 1)}
</g>
);
})}
</svg>
<span className="absolute inset-0 grid place-items-center text-4xl font-medium tabular-nums">{score}</span>
</div>
<div className="flex flex-col gap-1.5">
{parts.map((p, i) => (
<InsightRow
key={p.label}
onMouseEnter={() => setActive(i)}
onMouseLeave={() => setActive(null)}
className={cn('transition-opacity', active !== null && active !== i && 'opacity-60')}
>
<span className="flex min-w-0 items-center gap-2">
<span aria-hidden className="size-3 shrink-0 rounded-[4px]" style={{ backgroundColor: p.color }} />
<span className="truncate text-muted-foreground">
{p.label}
{p.detail ? `: ${p.detail}` : ''}
</span>
</span>
<span className="font-medium tabular-nums">
{p.value}/{p.max}
</span>
</InsightRow>
))}
</div>
</InsightCard>
);
}Usage
import { SleepScoreCard } from "@/components/ui/sleep-score-card"Exports
SleepScoreCard
Dependencies
@vcare/insight-card(registry)@vcare/utils(registry)
Raw item: /r/sleep-score-card.json