Skip to content
← Components

Radial Gauge

Radial Gauge with readable values and an accessible data representation.

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/radial-gauge.json

Use it

Scroll horizontally for long lines
"use client";
import { RadialGauge } from "@/components/jez-ui/ui/radial-gauge";

export default function Example() {
  return (
    <>
      <div className="w-full max-w-2xl">
        <div className="mb-8 flex flex-wrap items-end justify-between gap-4">
          <div>
            <h3 className="text-3xl tracking-tight">Almost there.</h3>
            <p className="mt-2 text-sm text-muted-foreground">
              Progress toward the weekly target
            </p>
          </div>
          <span className="rounded-full border border-border px-3 py-1 text-xs text-muted-foreground">
            Demo data
          </span>
        </div>
        <RadialGauge />
      </div>
    </>
  );
}

Props & types

Scroll horizontally for long lines
Omit<
  React.ComponentProps<"figure">,
  keyof {
    value?: number;
    label?: string;
    className?: string;
  }
> & {
  value?: number;
  label?: string;
  className?: string;
}

Source

View 2 source files

registry/ui/radial-gauge.tsx

Scroll horizontally for long lines
"use client";
import * as React from "react";
import { cn } from "./utils";
export function RadialGauge({
  children,
  value = 72,
  label = "Capacity",
  className,
  ...rootProps
}: Omit<
  React.ComponentProps<"figure">,
  keyof {
    value?: number;
    label?: string;
    className?: string;
  }
> & {
  value?: number;
  label?: string;
  className?: string;
}) {
  const v = Math.min(100, Math.max(0, value));
  return (
    <figure
      {...rootProps}
      className={cn("m-0 grid justify-items-center gap-3", className)}
    >
      {children !== undefined ? (
        children
      ) : (
        <>
          <svg
            viewBox="0 0 180 180"
            className="size-52"
            role="img"
            aria-label={`${label}: ${v}%`}
          >
            <circle
              cx="90"
              cy="90"
              r="70"
              stroke="var(--muted)"
              strokeWidth="12"
              fill="none"
            />
            <circle
              cx="90"
              cy="90"
              r="70"
              stroke="var(--primary)"
              strokeWidth="12"
              fill="none"
              pathLength="100"
              strokeDasharray={`${v} 100`}
              strokeLinecap="round"
              transform="rotate(-90 90 90)"
            />
            <text
              x="90"
              y="100"
              textAnchor="middle"
              fill="var(--foreground)"
              fontSize="32"
            >
              {v}%
            </text>
          </svg>
          <figcaption className="text-sm">{label}</figcaption>
        </>
      )}
    </figure>
  );
}

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));
}

Dependencies

clsx@2.1.1 · tailwind-merge@3.5.0

Accessibility & behaviour

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

Read the accessibility and performance guide →