Card Traffic
roi-ui/card-trafficFreeItem
A website traffic card component with line chart and statistics.
Install it
npx shadcn@latest add https://roiui.com/r/card-traffic.jsonSource
1"use client";23import { CartesianGrid, Line, LineChart, XAxis, YAxis } from "recharts";4import { Badge } from "@/registry/brook/ui/badge/badge";5import { Card, CardContent, CardHeader, CardTitle } from "@/registry/brook/ui/card/card";6import { type ChartConfig, ChartContainer, ChartTooltip, ChartTooltipContent } from "@/registry/brook/ui/chart/chart";7import styles from "./card-traffic.module.css";89type TrafficDataPoint = {10 date: number;11 desktop: number;12 mobile: number;13};1415type CardTrafficProps = {16 data: TrafficDataPoint[];17};1819const CHART_START_YEAR = 2025;20const CHART_START_MONTH = 6;21const CHART_START_DAY = 14;2223const formatDate = (value: unknown) => {24 const dayNumber = Math.round(Number(value));2526 const startDate = new Date(CHART_START_YEAR, CHART_START_MONTH, CHART_START_DAY);27 const currentDate = new Date(startDate);28 currentDate.setDate(startDate.getDate() + (dayNumber - 1));2930 return currentDate.toLocaleDateString("en-US", {31 month: "short",32 day: "numeric",33 });34};3536const chartConfig = {37 mobile: {38 label: "Mobile",39 color: "var(--chart-1)",40 },41 desktop: {42 label: "Desktop",43 color: "var(--chart-2)",44 },45} satisfies ChartConfig;4647export function CardTraffic({ data }: CardTrafficProps) {48 return (49 <Card50 className={styles.cardContainer}51 style={{52 maxWidth: "600px",53 width: "100%",54 }}55 >56 <CardHeader>57 <CardTitle>Website Traffic</CardTitle>58 </CardHeader>59 <CardContent className={styles.chartContainer}>60 <div style={{ width: "100%", height: "100%" }}>61 <ChartContainer config={chartConfig}>62 <LineChart data={data}>63 <CartesianGrid strokeDasharray="3 3" vertical={false} />64 <XAxis dataKey="date" hide={true} tickFormatter={formatDate} />65 <YAxis hide={true} />66 <ChartTooltip content={<ChartTooltipContent />} />67 <Line68 animationDuration={800}69 dataKey="mobile"70 dot={false}71 stroke="var(--color-mobile)"72 strokeWidth={2}73 type="monotone"74 />75 <Line76 animationBegin={200}77 animationDuration={800}78 dataKey="desktop"79 dot={false}80 stroke="var(--color-desktop)"81 strokeWidth={2}82 type="monotone"83 />84 </LineChart>85// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from Roi UI
All 123 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | Roi UI | Other | Free | no deps · 2 files | |
| Accordion (Tailwind)accordion-tailwind | Roi UI | Other | Free | no deps | |
| AI Chatai-chat | Roi UI | Other | Free | no deps · 2 files | |
| AI Chat (Tailwind)ai-chat-tailwind | Roi UI | Other | Free | no deps | |
| Alertalert | Roi UI | Other | Free | 1 dep · 2 files | |
| Alert Dialogalert-dialog | Roi UI | Other | Free | no deps · 2 files | |
| Alert Dialog (Tailwind)alert-dialog-tailwind | Roi UI | Other | Free | no deps | |
| Alert (Tailwind)alert-tailwind | Roi UI | Other | Free | 1 dep |
