Data display

Counter

Navigation and tab counts. 20px pill, 12 Medium.

Preview

121212

Installation

Components are copied into your project — no runtime package.

  1. Create a counter.tsx file and paste the following code into it.

    src/components/ui/counter.tsx
    import { cx } from "@/utils/cx";
    
    export interface CounterProps {
      /** `muted` for counts, `accent` for selection, `alert` for unread. */
      tone?: "muted" | "accent" | "alert";
      className?: string;
      children: number | string;
    }
    
    /** Navigation and tab counts. 20px pill, 12 Medium. */
    export function Counter({ tone = "muted", className, children }: CounterProps) {
      return (
        <span
          className={cx(
            "inline-flex h-5 min-w-5 items-center justify-center rounded-full px-1.5 text-sm font-medium tabular",
            tone === "muted" && "bg-muted text-fg-secondary",
            tone === "accent" && "bg-accent text-fg-inverse",
            tone === "alert" && "bg-error text-fg-inverse",
            className,
          )}
        >
          {children}
        </span>
      );
    }
  2. Add the theme tokens and the cx helper from Installation if you haven’t yet, then update the import paths to match your project setup.