Badge[bædʒ]
示例

源代码
import type { HTMLAttributes } from "react";
import { cn } from "@/lib/utils";
const variants: Record<string, string> = {
default: "bg-gray-100 text-gray-700",
red: "bg-red-50 text-red-700",
orange: "bg-orange-50 text-orange-700",
yellow: "bg-yellow-50 text-yellow-700",
green: "bg-green-50 text-green-700",
blue: "bg-blue-50 text-blue-700",
purple: "bg-purple-50 text-purple-700",
};
interface BadgeProps extends HTMLAttributes<HTMLSpanElement> {
variant?: keyof typeof variants;
}
export const Badge = function ({ className, variant = "default", ...props }: BadgeProps) {
return (
<span
className={cn(
"inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium",
variants[variant],
className,
)}
{...props}
/>
);
};
Badge.displayName = "Badge";