1
- import * as React from 'react' ;
2
- import { cva , type VariantProps } from 'class-variance-authority' ;
3
-
4
1
import { cn } from '@docs/lib/utils' ;
2
+ import { Slot } from '@radix-ui/react-slot' ;
3
+ import { cva , type VariantProps } from 'class-variance-authority' ;
4
+ import * as React from 'react' ;
5
5
6
6
const badgeVariants = cva (
7
- 'focus: ring- ring inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-offset-2 ' ,
7
+ 'focus-visible:border- ring focus-visible: ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive inline-flex w-fit shrink-0 items-center justify-center gap-1 overflow-hidden whitespace-nowrap rounded-md border px-2 py-0.5 text-xs font-medium transition-[color,box-shadow] focus-visible :ring-[3px] [&>svg]:pointer-events-none [&>svg]:size-3 ' ,
8
8
{
9
9
variants : {
10
10
variant : {
11
- default : 'bg-primary text-primary-foreground hover:bg-primary/80 border-transparent' ,
11
+ default : 'bg-primary text-primary-foreground [a&]: hover:bg-primary/90 border-transparent' ,
12
12
secondary :
13
- 'bg-secondary text-secondary-foreground hover:bg-secondary/80 border-transparent' ,
13
+ 'bg-secondary text-secondary-foreground [a&]: hover:bg-secondary/90 border-transparent' ,
14
14
destructive :
15
- 'bg-destructive text -destructive-foreground hover: bg-destructive/80 border-transparent' ,
16
- outline : 'text-foreground' ,
15
+ 'bg-destructive [a&]:hover:bg -destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark: bg-destructive/60 border-transparent text-white ' ,
16
+ outline : 'text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground ' ,
17
17
} ,
18
18
} ,
19
19
defaultVariants : {
@@ -26,8 +26,16 @@ export interface BadgeProps
26
26
extends React . HTMLAttributes < HTMLDivElement > ,
27
27
VariantProps < typeof badgeVariants > { }
28
28
29
- function Badge ( { className, variant, ...props } : BadgeProps ) {
30
- return < div className = { cn ( badgeVariants ( { variant } ) , className ) } { ...props } /> ;
29
+ function Badge ( {
30
+ className,
31
+ variant,
32
+ asChild = false ,
33
+ ...props
34
+ } : React . ComponentProps < 'span' > & VariantProps < typeof badgeVariants > & { asChild ?: boolean } ) {
35
+ const Comp = asChild ? Slot : 'span' ;
36
+ return (
37
+ < Comp data-slot = "badge" className = { cn ( badgeVariants ( { variant } ) , className ) } { ...props } />
38
+ ) ;
31
39
}
32
40
33
41
export { Badge , badgeVariants } ;
0 commit comments