- Accordion
- Agent Thinking
- Alert
- Alert Dialog
- Announcement
- Aspect Ratio
- Attachment
- Avatar
- Badge
- Breadcrumb
- Bubble
- Button
- Button Group
- Calendar
- Card
- Carousel
- Checkbox
- Checkbox Card
- Code Block
- Collapsible
- Color Picker
- Combobox
- Command
- Composer
- Composer Loader
- Context Menu
- Data Grid
- Data Table
- Date Picker
- Dialog
- Direction
- Drawer
- Dropdown Menu
- Empty
- Field
- File Upload
- Hover Card
- Input
- Input Group
- Input Otp
- Item
- Kbd
- Label
- Marker
- Menubar
- Message
- Message Scroller
- Meter
- Native Select
- Navigation Menu
- Number Field
- Pagination
- Period Switcher
- Popover
- Progress
- Questionnaire
- Radio Card
- Radio Group
- Resizable
- Reveal
- Scroll Area
- Search Field
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Social Button
- Sonner
- Spinner
- Status Dot
- Switch
- Switch Card
- Table
- Tabs
- Tag Group
- Textarea
- Theme Toggle
- Time Field
- Toggle
- Toggle Group
- Tooltip
- Trace
- Tree View
- Agent Creator 01
- Agent Limits Card 01
- Agent Progress 01
- AI Chat 01
- AI Image Generation 01
- AI Profile 01
- Alerts Card 01
- Auth Card 01
- Calendar 01
- Composer 01
- Composer Attachments 01
- Composer Panel 01
- Finance Dashboard 01
- Home Dashboard 01
- Marketing Dashboard 01
- Medical Profile 01
- Meeting Scheduler 01
- Multi Agent Chat 01
- Notification Center 01
- Patient Info Card 01
- Project Board 01
- Questionnaire 01
- Settings Modal 01
- Sidebar 01
- Stat Cards 01
- Task List 01
- Web Search 01
- Activity Rings Card 01
- Area Chart Card 01
- Bar List Card 01
- Combo Chart Card 01
- Contributions Card 01
- Earnings Chart Card 01
- Funnel Chart Card 01
- Heatmap Chart Card 01
- Line Chart Card 01
- Most Active Days Card 01
- Orders Chart Card 01
- Radar Chart Card 01
- Radial Chart Card 01
- Revenue Chart Card 01
- Sankey Chart Card 01
- Scatter Chart Card 01
- Sleep Score Card 01
- Stage Bars Card 01
- Steps Card 01
Activity
31,900steps recorded
22 - 28 Jun
Mon
Tue
Wed
Thu
Fri
Sat
Sun
Installation
Set up the @cobalt registry first, as described in Installation, then add the block:
$ pnpm dlx shadcn@latest add @cobalt/steps-card-01
Pass an array of weeks, each with a display label and up to seven daily values. The title and unit can be customized.
Source
"use client";
import { cn } from "cn";
import * as React from "react";
import { useCountUp } from "@/components/hooks/use-count-up";
import { Button } from "@/components/ui/button";
import {
Card,
CardAction,
CardContent,
CardHeader,
CardTitle,
} from "@/components/ui/card";
import {
PeriodSwitcher,
PeriodSwitcherLabel,
PeriodSwitcherNext,
PeriodSwitcherPrevious,
} from "@/components/ui/period-switcher";
import { Reveal } from "@/components/ui/reveal";
export interface StepsDay {
label: string;
value: number;
}
export interface StepsWeek {
label: string;
days: StepsDay[];
}
export function StepsCard({
weeks,
title = "Activity",
unit = "steps recorded",
className,
}: {
weeks: StepsWeek[];
title?: string;
unit?: string;
className?: string;
}) {
const [index, setIndex] = React.useState(0);
const [hoveredDay, setHoveredDay] = React.useState<number | null>(null);
const [focusedDay, setFocusedDay] = React.useState<number | null>(null);
const week = weeks[Math.min(index, Math.max(weeks.length - 1, 0))];
const total =
week?.days.reduce((sum, day) => sum + Math.max(0, day.value), 0) ?? 0;
const max = Math.max(1, ...(week?.days.map((day) => day.value) ?? [])) * 1.12;
const activeDay = week?.days[hoveredDay ?? focusedDay ?? -1];
const activeValue = activeDay ? Math.max(0, activeDay.value) : total;
const valueRef = useCountUp<HTMLSpanElement>(activeValue);
return (
<Reveal
variant="card"
render={
<Card
radius={20}
variant="muted"
className={cn("w-full max-w-[576px]", className)}
/>
}
>
<CardHeader className="gap-0">
<CardTitle variant="secondary">{title}</CardTitle>
<div className="flex items-baseline gap-1">
<span
ref={valueRef}
className="text-2xl leading-8.5 font-medium tabular-nums"
aria-label={`${activeDay ? `${activeDay.label}: ` : ""}${activeValue.toLocaleString()} ${unit}`}
>
{activeValue.toLocaleString("en-US")}
</span>
<span className="text-xs text-muted-foreground" aria-hidden="true">
{unit}
{activeDay ? ` · ${activeDay.label}` : ""}
</span>
</div>
<CardAction>
<PeriodSwitcher>
<PeriodSwitcherPrevious
tooltip="Previous week"
disabled={index <= 0}
onClick={() => setIndex((current) => Math.max(0, current - 1))}
/>
<PeriodSwitcherLabel className="min-w-[110px]">
{week?.label ?? "No weeks"}
</PeriodSwitcherLabel>
<PeriodSwitcherNext
tooltip="Next week"
disabled={index >= weeks.length - 1}
onClick={() =>
setIndex((current) => Math.min(weeks.length - 1, current + 1))
}
/>
</PeriodSwitcher>
</CardAction>
</CardHeader>
<CardContent>
<div
className="grid grid-cols-7 gap-2"
aria-label={`${week?.label ?? "Week"} activity`}
>
{week?.days.slice(0, 7).map((day, i) => (
<div
key={`${i}-${day.label}`}
className="flex min-w-0 flex-col items-center gap-2.5"
>
<div className="h-50.5 w-full max-w-12.5">
<Button
variant="unstyled"
radius={10}
aria-label={`${day.label}: ${Math.max(0, day.value).toLocaleString()} ${unit}`}
onMouseEnter={() => setHoveredDay(i)}
onMouseLeave={() => setHoveredDay(null)}
onFocus={() => setFocusedDay(i)}
onBlur={() => setFocusedDay(null)}
className="group relative h-full w-full"
>
<span
aria-hidden="true"
className="absolute inset-0 rounded-[10px] bg-(--border-subtle,var(--input))"
/>
<div
className="absolute inset-x-0 bottom-0 h-(--bar-height) rounded-[10px] bg-(--steps-card-fill,var(--chart-1)) transition-all duration-450 ease-out starting:h-0 group-hover:ring-2 group-hover:ring-(--steps-card-fill,var(--chart-1)) group-hover:ring-offset-2 group-hover:ring-offset-(--border-subtle,var(--input)) motion-reduce:transition-none"
style={
{
"--bar-height": `${(Math.max(0, day.value) / max) * 100}%`,
} as React.CSSProperties
}
/>
</Button>
</div>
<span className="text-xs leading-4 text-muted-foreground">
{day.label}
</span>
</div>
))}
</div>
</CardContent>
</Reveal>
);
} On this page