kontenhumas-fe/components/ui/badge.tsx

53 lines
1.5 KiB
TypeScript
Raw Normal View History

2025-09-23 13:07:34 +00:00
import * as React from "react";
import { cva, type VariantProps } from "class-variance-authority";
2025-09-16 08:29:07 +00:00
2025-09-23 13:07:34 +00:00
import { cn } from "@/lib/utils";
import { color, rounded } from "@/lib/type";
2025-09-16 08:29:07 +00:00
const badgeVariants = cva(
2025-09-23 13:07:34 +00:00
"inline-flex items-center rounded-md border py-1 px-2 text-xs capitalize font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
2025-09-16 08:29:07 +00:00
{
variants: {
2025-09-23 13:07:34 +00:00
color: {
default: "border-transparent bg-default text-default-foreground",
primary: "border-transparent bg-primary text-primary-foreground",
secondary: "bg-secondary border-transparent text-secondary-foreground ",
destructive: "bg-destructive border-transparent text-destructive-foreground",
success: "bg-success border-transparent text-success-foreground ",
info: "bg-info border-transparent text-info-foreground ",
warning: "bg-warning border-transparent text-warning-foreground",
2025-09-16 08:29:07 +00:00
},
2025-09-23 13:07:34 +00:00
rounded: {
sm: "rounded",
md: "rounded-md",
lg: "rounded-lg",
full: "rounded-full",
}
2025-09-16 08:29:07 +00:00
},
2025-09-23 13:07:34 +00:00
2025-09-16 08:29:07 +00:00
defaultVariants: {
2025-09-23 13:07:34 +00:00
color: "default",
rounded: "md",
2025-09-16 08:29:07 +00:00
},
}
2025-09-23 13:07:34 +00:00
);
export interface BadgeProps
extends React.HTMLAttributes<HTMLDivElement>,
VariantProps<typeof badgeVariants> {
color?: color;
rounded?: rounded;
}
2025-09-16 08:29:07 +00:00
2025-09-23 13:07:34 +00:00
function Badge({ className, color, rounded, ...props }: BadgeProps) {
2025-09-16 08:29:07 +00:00
return (
2025-09-23 13:07:34 +00:00
<div
className={cn(badgeVariants({ color, rounded }), className)}
2025-09-16 08:29:07 +00:00
{...props}
/>
2025-09-23 13:07:34 +00:00
);
2025-09-16 08:29:07 +00:00
}
2025-09-23 13:07:34 +00:00
export { Badge, badgeVariants };