Skip to content
← Blocks

Analytics Overview

A working analytics overview with illustrative data and frontend interactions.

Open ↗

Make it yours.

Install the editable source and its dependencies into your React + Tailwind project.

Scroll horizontally for long lines
pnpm dlx shadcn@4.0.8 add http://localhost:3000/r/analytics-overview.json

Use it

Scroll horizontally for long lines
"use client";
import { AnalyticsOverview } from "@/components/jez-ui/blocks/analytics-overview";

export default function Example() {
  return (
    <>
      <AnalyticsOverview />
    </>
  );
}

Compose your own

These styled parts are included in the same install. Use children to build your layout; add className only when you want an override.

Scroll horizontally for long lines
"use client";
import {
  AnalyticsOverview,
  AnalyticsOverviewMetrics,
  AnalyticsOverviewCharts,
} from "@/components/jez-ui/blocks/analytics-overview";

export default function Example() {
  return (
    <AnalyticsOverview>
      <AnalyticsOverviewMetrics />
      <AnalyticsOverviewCharts />
    </AnalyticsOverview>
  );
}
Scroll horizontally for long lines
import { AnalyticsOverview, AnalyticsOverviewContent, AnalyticsOverviewItemTitle, AnalyticsOverviewItem, AnalyticsOverviewMetrics, AnalyticsOverviewCharts } from "@/components/jez-ui/blocks/analytics-overview";
Read the composition guide →

Props & types

Scroll horizontally for long lines
export type AnalyticsOverviewOptions = {
  className?: string;
  metrics?: typeof AnalyticsOverviewDefaultMetrics;
};

export type AnalyticsOverviewProps = Omit<
  React.ComponentProps<"section">,
  keyof AnalyticsOverviewOptions
> &
  AnalyticsOverviewOptions;

AnalyticsOverviewProps

Source

View 5 source files

registry/blocks/analytics-overview.tsx

Scroll horizontally for long lines
"use client";
import * as React from "react";
import { ArrowUpRight } from "lucide-react";
import { cn } from "../ui/utils";
import { AreaChart } from "../ui/area-chart";
import { DonutChart } from "../ui/donut-chart";
export type AnalyticsOverviewOptions = {
  className?: string;
  metrics?: typeof AnalyticsOverviewDefaultMetrics;
};
export type AnalyticsOverviewProps = Omit<
  React.ComponentProps<"section">,
  keyof AnalyticsOverviewOptions
> &
  AnalyticsOverviewOptions;
const AnalyticsOverviewDefaultMetrics = [
  {
    label: "Revenue",
    value: "£24,860",
    change: "12.8%",
    note: "vs. previous month",
  },
  {
    label: "Sessions",
    value: "18,204",
    change: "8.2%",
    note: "vs. previous month",
  },
  {
    label: "Conversion",
    value: "3.8%",
    change: "0.6 pts",
    note: "vs. previous month",
  },
];
function useAnalyticsOverviewModel({
  metrics = AnalyticsOverviewDefaultMetrics,
  className,
  children,
  ...rootProps
}: AnalyticsOverviewProps) {
  return { metrics, className, children, rootProps };
}
const AnalyticsOverviewCompositionContext = React.createContext<ReturnType<
  typeof useAnalyticsOverviewModel
> | null>(null);
function useAnalyticsOverviewComposition() {
  const context = React.useContext(AnalyticsOverviewCompositionContext);
  if (!context)
    throw new Error(
      "AnalyticsOverview parts must be inside AnalyticsOverview.",
    );
  return context;
}
export function AnalyticsOverview(props: AnalyticsOverviewProps) {
  const model = useAnalyticsOverviewModel(props);
  const { className, rootProps, children } = model;
  return (
    <AnalyticsOverviewCompositionContext.Provider value={model}>
      <section {...rootProps} className={cn("grid gap-6", className)}>
        {children !== undefined ? (
          children
        ) : (
          <>
            <AnalyticsOverviewMetrics />
            <AnalyticsOverviewCharts />
          </>
        )}
      </section>
    </AnalyticsOverviewCompositionContext.Provider>
  );
}

export function AnalyticsOverviewContent({
  className,
  ...props
}: React.ComponentProps<"div">) {
  return (
    <div
      data-slot="analytics-overview-content"
      className={cn("grid gap-4 sm:grid-cols-3", className)}
      {...props}
    />
  );
}
export function AnalyticsOverviewItemTitle({
  className,
  ...props
}: React.ComponentProps<"h3">) {
  return (
    <h3
      data-slot="analytics-overview-itemtitle"
      className={cn("text-sm font-semibold", className)}
      {...props}
    />
  );
}

export function AnalyticsOverviewItem({
  className,
  ...props
}: React.ComponentProps<"div">) {
  return (
    <div
      data-slot="analytics-overview-item"
      className={cn("rounded-xl border border-border p-5", className)}
      {...props}
    />
  );
}

export function AnalyticsOverviewMetrics({
  children,
  ...props
}: Partial<React.ComponentProps<typeof AnalyticsOverviewContent>> & {
  children?: React.ReactNode;
}) {
  const { metrics } = useAnalyticsOverviewComposition();
  return (
    <AnalyticsOverviewContent {...props}>
      {children === undefined
        ? metrics.map((m) => (
            <AnalyticsOverviewItem key={m.label}>
              <p className="text-sm text-muted-foreground">{m.label}</p>
              <p className="mt-3 font-display text-3xl tracking-tight tabular-nums">
                {m.value}
              </p>
              <p className="mt-4 flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground">
                <span className="flex items-center gap-1 font-medium text-primary">
                  <ArrowUpRight size={13} />
                  {m.change}
                </span>
                {m.note}
              </p>
            </AnalyticsOverviewItem>
          ))
        : children}
    </AnalyticsOverviewContent>
  );
}
export function AnalyticsOverviewCharts({
  children,
  ...props
}: Partial<React.ComponentProps<"div">> & { children?: React.ReactNode }) {
  return (
    <div
      {...props}
      className={cn(
        "grid gap-5 lg:grid-cols-[minmax(0,2fr)_minmax(0,1fr)]",
        props.className,
      )}
    >
      {children === undefined ? (
        <>
          <div className="min-w-0 rounded-xl border border-border p-5">
            <AnalyticsOverviewItemTitle>
              Revenue over time
            </AnalyticsOverviewItemTitle>
            <p className="mb-5 mt-1 text-xs text-muted-foreground">
              Weekly breakdown · illustrative data
            </p>
            <AreaChart
              label="Weekly revenue (£) · illustrative"
              className="[&_figcaption]:sr-only"
              data={[
                { name: "Mon", value: 2840 },
                { name: "Tue", value: 3420 },
                { name: "Wed", value: 2960 },
                { name: "Thu", value: 4120 },
                { name: "Fri", value: 3650 },
                { name: "Sat", value: 4290 },
                { name: "Sun", value: 3580 },
              ]}
            />
          </div>
          <div className="min-w-0 rounded-xl border border-border p-5">
            <h3 className="text-sm font-semibold">Audience mix</h3>
            <p className="mb-5 mt-1 text-xs text-muted-foreground">
              Sessions by source
            </p>
            <DonutChart className="[&_figcaption]:sr-only" />
          </div>
        </>
      ) : (
        children
      )}
    </div>
  );
}

registry/ui/utils.ts

Scroll horizontally for long lines
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...values: ClassValue[]) {
  return twMerge(clsx(values));
}

registry/ui/area-chart.tsx

Scroll horizontally for long lines
"use client";
import * as React from "react";
import { cn } from "./utils";
import {
  ResponsiveContainer,
  AreaChart as Plot,
  Area,
  XAxis,
  YAxis,
  CartesianGrid,
  Tooltip,
} from "recharts";
import { ChartFrame, sampleChartData, type ChartProps } from "./chart-frame";
export function AreaChart({
  data = sampleChartData,
  label = "Area chart",
  className,
  color = "var(--primary)",
  children,
  ...rootProps
}: ChartProps) {
  return (
    <ChartFrame
      {...rootProps}
      data={data}
      label={label}
      className={cn("", className)}
    >
      {children !== undefined ? (
        children
      ) : (
        <>
          <ResponsiveContainer
            initialDimension={{ width: 600, height: 240 }}
            width="100%"
            height="100%"
          >
            <Plot
              data={data}
              margin={{ top: 8, right: 12, left: -24, bottom: 0 }}
              accessibilityLayer
            >
              <CartesianGrid vertical={false} stroke="var(--border)" />
              <XAxis
                dataKey="name"
                tickLine={false}
                axisLine={false}
                tick={{ fill: "var(--muted-foreground)", fontSize: 11 }}
              />
              <YAxis
                tickLine={false}
                axisLine={false}
                tick={{ fill: "var(--muted-foreground)", fontSize: 11 }}
              />
              <Tooltip
                contentStyle={{
                  background: "var(--background)",
                  border: "1px solid var(--border)",
                  borderRadius: 8,
                  color: "var(--foreground)",
                }}
              />
              <Area
                dataKey="value"
                fill={color}
                stroke={color}
                type="monotone"
                fillOpacity={0.14}
                strokeWidth={2}
                isAnimationActive={false}
              />
            </Plot>
          </ResponsiveContainer>
        </>
      )}
    </ChartFrame>
  );
}

registry/ui/chart-frame.tsx

Scroll horizontally for long lines
"use client";
import * as React from "react";
import { cn } from "./utils";
export type ChartDatum = { name: string; value: number; previous?: number };
export const sampleChartData: ChartDatum[] = [
  { name: "Mon", value: 32, previous: 24 },
  { name: "Tue", value: 48, previous: 31 },
  { name: "Wed", value: 39, previous: 36 },
  { name: "Thu", value: 65, previous: 42 },
  { name: "Fri", value: 57, previous: 38 },
  { name: "Sat", value: 82, previous: 49 },
  { name: "Sun", value: 73, previous: 51 },
];
export type ChartProps<E extends React.ElementType = "figure"> =
  React.ComponentProps<E> & {
    data?: ChartDatum[];
    label?: string;
    className?: string;
    color?: string;
  };
export function ChartFrame({
  children,
  data,
  label,
  className,
  contentProps,
  captionProps,
  ...rootProps
}: React.ComponentProps<"figure"> & {
  contentProps?: React.ComponentProps<"div">;
  captionProps?: React.ComponentProps<"figcaption">;
  children: React.ReactNode;
  data: ChartDatum[];
  label: string;
  className?: string;
}) {
  return (
    <figure {...rootProps} className={cn("m-0 w-full min-w-0", className)}>
      <ChartCaption {...captionProps}>{label}</ChartCaption>
      <ChartContent {...contentProps}>{children}</ChartContent>
      <details className="mt-3 text-xs text-muted-foreground">
        <summary>View data table</summary>
        <table className="mt-3 w-full text-left">
          <caption className="sr-only">{label}</caption>
          <thead>
            <tr>
              <th>Period</th>
              <th>Value</th>
              <th>Previous</th>
            </tr>
          </thead>
          <tbody>
            {data.map((d, i) => (
              <tr key={i}>
                <th className="py-1 font-normal">{d.name}</th>
                <td>{d.value}</td>
                <td>{d.previous ?? "—"}</td>
              </tr>
            ))}
          </tbody>
        </table>
      </details>
    </figure>
  );
}

export function ChartCaption({
  className,
  ...props
}: React.ComponentProps<"figcaption">) {
  return (
    <figcaption
      className={cn("mb-4 text-sm font-medium", className)}
      {...props}
    />
  );
}
export function ChartContent({
  className,
  ...props
}: React.ComponentProps<"div">) {
  return (
    <div
      className={cn("h-60 w-full min-w-0 overflow-hidden", className)}
      {...props}
    />
  );
}

registry/ui/donut-chart.tsx

Scroll horizontally for long lines
"use client";
import * as React from "react";
import { cn } from "./utils";
import { ResponsiveContainer, PieChart, Pie, Cell, Tooltip } from "recharts";
import { ChartFrame, type ChartProps } from "./chart-frame";
export function DonutChart({
  data = [
    { name: "Direct", value: 48 },
    { name: "Search", value: 32 },
    { name: "Referral", value: 20 },
  ],
  label = "Traffic sources",
  className,
  color,
  colors = ["var(--primary)", "#9eb95f", "#e29366", "#8498bb"],
  children,
  ...rootProps
}: ChartProps & { colors?: string[] }) {
  return (
    <ChartFrame
      {...rootProps}
      data={data}
      label={label}
      className={cn("", className)}
    >
      {children !== undefined ? (
        children
      ) : (
        <>
          <ResponsiveContainer initialDimension={{ width: 600, height: 240 }}>
            <PieChart>
              <Pie
                data={data}
                dataKey="value"
                nameKey="name"
                innerRadius="58%"
                outerRadius="88%"
                paddingAngle={3}
                isAnimationActive={false}
              >
                {data.map((_, i) => (
                  <Cell
                    key={i}
                    fill={
                      color ?? colors[i % colors.length] ?? "var(--primary)"
                    }
                  />
                ))}
              </Pie>
              <Tooltip />
            </PieChart>
          </ResponsiveContainer>
        </>
      )}
    </ChartFrame>
  );
}

Dependencies

lucide-react@0.577.0 · clsx@2.1.1 · tailwind-merge@3.5.0 · recharts@3.8.0

Accessibility & behaviour

Provide meaningful labels and preserve keyboard focus styles. Check contrast when customising theme colours.

Read the accessibility and performance guide →