Files
penx/components/ui/badge.tsx
2024-08-05 10:06:02 +08:00

46 lines
1.2 KiB
TypeScript

import * as React from 'react'
import { cn } from '@/lib/utils'
import { cva, type VariantProps } from 'class-variance-authority'
const badgeVariants = cva(
'inline-flex items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2',
{
variants: {
variant: {
default: 'border-transparent bg-primary text-primary-foreground',
secondary:
'border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80',
destructive:
'border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80',
outline: 'text-foreground border',
},
size: {
default: 'h-7 px-2 text-xs',
sm: 'h-7 px-2 text-xs',
md: 'h-8 px-2 text-xs',
lg: 'h-9 px-2 text-sm',
},
},
defaultVariants: {
variant: 'default',
size: 'default',
},
},
)
export interface BadgeProps
extends React.HTMLAttributes<HTMLDivElement>,
VariantProps<typeof badgeVariants> {}
function Badge({ className, variant, size, ...props }: BadgeProps) {
return (
<div
className={cn(badgeVariants({ variant, size }), className)}
{...props}
/>
)
}
export { Badge, badgeVariants }