← Componentes
Badge
Etiqueta pequeña de estado o categoría. Dos tamaños, no cuatro — a esta escala xs/lg no resuelven nada que sm/md no resuelvan ya. Fondo tintado en los semánticos (ver Colores), mismo radio de 6px que el resto — nada de pill/rounded-full aunque sea lo común en otros sistemas.
Playground
Variant
Size
Nuevo
<Badge>Nuevo</Badge>Todas las combinaciones
| sm | md | |
|---|---|---|
| default | Nuevo | Nuevo |
| primary | Nuevo | Nuevo |
| success | Nuevo | Nuevo |
| danger | Nuevo | Nuevo |
| warning | Nuevo | Nuevo |
| info | Nuevo | Nuevo |
import * as React from "react";
import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "./lib/cn";
const badgeVariants = cva(
// same 6px radius as the rest of the library — a pill/rounded-full
// shape is the common default elsewhere, but that breaks the "one
// radius everywhere" rule, so it's deliberately not used here
"inline-flex w-fit items-center gap-1 whitespace-nowrap rounded-md font-medium",
{
variants: {
variant: {
default: "bg-muted text-muted-foreground",
primary: "bg-primary/15 text-primary",
success: "bg-success/15 text-success",
danger: "bg-danger/15 text-danger",
warning: "bg-warning/15 text-warning",
info: "bg-info/15 text-info",
},
size: {
sm: "h-5 px-1.5 text-[0.6875rem]",
md: "h-6 px-2 text-xs",
},
},
defaultVariants: {
variant: "default",
size: "sm",
},
},
);
export interface BadgeProps
extends React.HTMLAttributes<HTMLSpanElement>,
VariantProps<typeof badgeVariants> {}
export const Badge = React.forwardRef<HTMLSpanElement, BadgeProps>(
({ className, variant, size, ...props }, ref) => {
return <span ref={ref} className={cn(badgeVariants({ variant, size }), className)} {...props} />;
},
);
Badge.displayName = "Badge";Código real de packages/ui/src/badge.tsx.
Uso
import { Badge } from "./components/ui/badge";
<Badge variant="success">Activo</Badge>API
| Prop | Tipo | Default |
|---|---|---|
| variant | default | primary | success | danger | warning | info | default |
| size | sm | md | sm |
El resto son los atributos nativos de <span> — se pasan directo.