Badge
Badge with thoughtful defaults, semantic styling, and editable source.
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/badge.jsonUse it
Scroll horizontally for long lines
"use client";
import {Badge} from '@/components/jez-ui/ui/badge';
export default function Example(){
return <><div className="grid max-w-md gap-7"><h3 className="text-2xl">A status worth noticing.</h3><div className="flex flex-wrap gap-3"><Badge tone="positive">● Live</Badge><Badge tone="accent">In review</Badge><Badge tone="warning">Needs attention</Badge><Badge>Draft</Badge></div><p className="text-sm text-muted-foreground">Small signals. Clear next steps.</p></div></>;
}Props & types
Scroll horizontally for long lines
React.HTMLAttributes<HTMLSpanElement> & {
tone?: "neutral" | "accent" | "positive" | "warning";
}Source
View 2 source files
registry/ui/badge.tsx
Scroll horizontally for long lines
"use client";
import * as React from "react";
import { cn } from "./utils";
export function Badge({
className,
tone = "neutral",
...props
}: React.HTMLAttributes<HTMLSpanElement> & {
tone?: "neutral" | "accent" | "positive" | "warning";
}) {
return (
<span
className={cn(
"inline-flex items-center gap-1.5 rounded-full px-2.5 py-1 text-xs font-medium",
{
"bg-muted text-foreground": tone === "neutral",
"bg-primary/10 text-primary": tone === "accent",
"bg-accent text-[#293620]": tone === "positive",
"bg-[#f6e5c1] text-[#704517]": tone === "warning",
},
className,
)}
{...props}
/>
);
}
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 →