|
1
|
import { cva, type VariantProps } from "cva" |
|
2
|
import { Slot } from "radix-ui" |
|
3
|
import * as React from "react" |
|
4
|
|
|
5
|
import { badgeColorVariants } from "@/components/badge" |
|
6
|
import { clx } from "@/utils/clx" |
|
7
|
|
|
8
|
const iconBadgeVariants = cva({ |
|
9
|
base: "flex items-center justify-center overflow-hidden rounded-md border", |
|
10
|
variants: { |
|
11
|
size: { |
|
12
|
base: "h-6 w-6", |
|
13
|
large: "h-7 w-7", |
|
14
|
}, |
|
15
|
}, |
|
16
|
}) |
|
17
|
|
|
18
|
interface IconBadgeProps |
|
19
|
extends Omit<React.ComponentPropsWithoutRef<"span">, "color">, |
|
20
|
VariantProps<typeof badgeColorVariants>, |
|
21
|
VariantProps<typeof iconBadgeVariants> { |
|
22
|
asChild?: boolean |
|
23
|
} |
|
24
|
|
|
25
|
/** |
|
26
|
* This component is based on the `span` element and supports all of its props |
|
27
|
*/ |
|
28
|
const IconBadge = React.forwardRef<HTMLSpanElement, IconBadgeProps>( |
|
29
|
( |
|
30
|
{ |
|
31
|
children, |
|
32
|
className, |
|
33
|
/** |
|
34
|
* The badge's color. |
|
35
|
*/ |
|
36
|
color = "grey", |
|
37
|
/** |
|
38
|
* The badge's size. |
|
39
|
*/ |
|
40
|
size = "base", |
|
41
|
/** |
|
42
|
* Whether to remove the wrapper `span` element and use the |
|
43
|
* passed child element instead. |
|
44
|
*/ |
|
45
|
asChild = false, |
|
46
|
...props |
|
47
|
}: IconBadgeProps, |
|
48
|
ref |
|
49
|
) => { |
|
50
|
const Component = asChild ? Slot.Root : "span" |
|
51
|
|
|
52
|
return ( |
|
53
|
<Component |
|
54
|
ref={ref} |
|
55
|
className={clx( |
|
56
|
badgeColorVariants({ color }), |
|
57
|
iconBadgeVariants({ size }), |
|
58
|
className |
|
59
|
)} |
|
60
|
{...props} |
|
61
|
> |
|
62
|
{children} |
|
63
|
</Component> |
|
64
|
) |
|
65
|
} |
|
66
|
) |
|
67
|
IconBadge.displayName = "IconBadge" |
|
68
|
|
|
69
|
export { IconBadge } |