Weekly Installs Card
KPI stats card for weekly installs and growth: a large total, a hairline recharts sparkline over eight weeks with only the latest point highlighted, and a change caption. Recharts is pinned to 3.8.0.
"use client"
import { Line, LineChart } from "recharts"
import { Eyebrow } from "@/components/eyebrow/eyebrow"
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card"
import { ChartContainer, type ChartConfig } from "@/components/ui/chart"
import { Separator } from "@/components/ui/separator"
// The copy: change text here, not in the markup.
const COPY = {
title: "Installs",
body: "Components added to projects, week by week.",
unit: "this month",
window: "Last 8 weeks",
change: "+20.1% on last month",
} as const
const VALUE = 48120
const data = [
{ installs: 10400 },
{ installs: 14405 },
{ installs: 9400 },
{ installs: 8200 },
{ installs: 7000 },
{ installs: 9600 },
{ installs: 11244 },
{ installs: 26475 },
]
const chartConfig = {
installs: { label: "Installs" },
} satisfies ChartConfig
// The line is a hairline; only the latest week takes the accent.
function LatestDot(props: { cx?: number; cy?: number; index?: number }) {
if (props.index !== data.length - 1) return null
return <circle cx={props.cx} cy={props.cy} r={3} fill="var(--art-accent)" />
}
export default function InstallsSparklineCard() {
return (
<Card className="mx-auto w-full max-w-sm gap-8">
<CardHeader>
<CardTitle>{COPY.title}</CardTitle>
<CardDescription>{COPY.body}</CardDescription>
</CardHeader>
<CardContent className="flex flex-col gap-8">
<span className="flex items-baseline gap-2">
<span className="text-3xl font-medium tabular-nums">
{VALUE.toLocaleString("en-US")}
</span>
<Eyebrow variant="mono" render={<span />}>
{COPY.unit}
</Eyebrow>
</span>
<figure className="flex flex-col gap-3">
<ChartContainer config={chartConfig} className="h-28 w-full">
<LineChart
data={data}
margin={{ top: 6, right: 6, left: 6, bottom: 6 }}
>
<Line
type="monotone"
dataKey="installs"
stroke="var(--muted-foreground)"
strokeWidth={1.5}
dot={<LatestDot />}
activeDot={false}
isAnimationActive={false}
/>
</LineChart>
</ChartContainer>
<Separator />
<figcaption className="flex items-baseline justify-between">
<Eyebrow variant="mono" render={<span />}>
{COPY.window}
</Eyebrow>
<span className="text-sm/7 tabular-nums">{COPY.change}</span>
</figcaption>
</figure>
</CardContent>
</Card>
)
}
import { mergeProps } from "@base-ui/react/merge-props"
import { useRender } from "@base-ui/react/use-render"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "cn"
const eyebrowVariants = cva("text-eyebrow", {
variants: {
/**
* `default` is a 14px/20px label. `icon` adds a row with a 16px icon
* and a 12px gap; put the icon first and give it `aria-hidden`.
* `mono` is a 12px/20px label in the mono face, in sentence case like
* the others: the kit sets no label in capitals.
*/
variant: {
default: "text-sm/5 font-medium text-eyebrow",
icon: "flex items-center gap-3 text-sm/5 font-medium [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
mono: "font-mono text-xs/5 font-medium",
},
},
defaultVariants: { variant: "default" },
})
/**
* A short label above a heading, rendered as a `<p>` at weight 500.
* The default is 14px/20px in the kit's eyebrow color. The surrounding
* layout controls the space to the heading. Use `className` to customize
* the typography or color, and `render` to change the element: a `p` is
* right when the label stands alone as a line of text; pass
* `render={<span />}` or `render={<div />}` when it sits inside a heading,
* link, button or other inline text, where a `p` is not valid HTML.
*/
function Eyebrow({
className,
variant = "default",
render,
...props
}: useRender.ComponentProps<"p"> & VariantProps<typeof eyebrowVariants>) {
return useRender({
defaultTagName: "p",
render,
state: { slot: "eyebrow", variant },
props: mergeProps<"p">(
{ className: cn(eyebrowVariants({ variant }), className) },
props
),
})
}
export { Eyebrow, eyebrowVariants }
Installation
npx shadcn@latest add @01orbital/installs-sparkline-cardMake it yours
- Its words are in
COPYat the top ofcomponents/blocks/metrics/installs-sparkline-card/index.tsx: change them there, not in the markup. VALUE, also at the top of the file, holds its lists and settings.
Built from
npm: recharts@3.8.0. The CLI installs it for you.
Built from these parts. The CLI adds each one that is missing and won't replace a file you already have unless you choose to:
The shadcn parts here are their Base UI versions, and this piece uses Base UI's API. A Radix version you already have won't work with it.
Last updated on