1
+ import { forwardRef } from "react"
1
2
import { cva , VariantProps } from "class-variance-authority"
2
3
import { Slot } from "@radix-ui/react-slot"
3
4
4
5
import { cn } from "@/lib/utils/cn"
5
6
6
7
const tagVariants = cva (
7
- "inline-flex items-center rounded-full border px-2 py-0.5 min-h-8 text-xs uppercase transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 " ,
8
+ "inline-flex items-center rounded-full border px-2 py-0.5 min-h-8 text-xs uppercase transition-colors" ,
8
9
{
9
10
variants : {
10
11
status : {
11
- normal : "bg-background-highlight text-body-medium border-body-medium" ,
12
- tag : "bg-primary-low-contrast text-primary-high-contrast border-primary" ,
13
- success : "bg-success-light text-success border-success-border" ,
14
- error : "bg-error-light text-error border-error-border" ,
15
- warning : "bg-warning-light text-warning-dark border-warning-border" ,
12
+ normal :
13
+ "bg-background-highlight text-body-medium border-body-medium hover:shadow-body-medium" ,
14
+ tag : "bg-primary-low-contrast text-primary-high-contrast border-primary hover:shadow-primary-high-contrast" ,
15
+ success :
16
+ "bg-success-light text-success border-success-border hover:shadow-success" ,
17
+ error :
18
+ "bg-error-light text-error border-error-border hover:shadow-error" ,
19
+ warning :
20
+ "bg-warning-light text-warning-dark border-warning-border hover:shadow-warning-dark dark:hover:shadow-warning" ,
16
21
} ,
17
22
variant : {
18
23
subtle : "border-transparent" ,
19
- highContrast : "border-transparent" ,
24
+ "high-contrast" : "border-transparent" ,
20
25
solid : "border-transparent text-body-inverse" ,
21
26
outline : "bg-transparent" ,
22
27
} ,
@@ -25,45 +30,50 @@ const tagVariants = cva(
25
30
{
26
31
variant : "solid" ,
27
32
status : "normal" ,
28
- className : "bg-body-medium" ,
33
+ className :
34
+ "bg-body-medium focus-visible:outline-body hover:shadow-body" ,
29
35
} ,
30
36
{
31
37
variant : "solid" ,
32
38
status : "tag" ,
33
- className : "bg-primary" ,
39
+ className :
40
+ "bg-primary focus-visible:outline-primary-high-contrast hover:shadow-primary-high-contrast" ,
34
41
} ,
35
42
{
36
43
variant : "solid" ,
37
44
status : "success" ,
38
- className : "bg-success text-success-light" ,
45
+ className :
46
+ "bg-success text-success-light focus-visible:outline-success-dark hover:shadow-success-dark dark:hover:shadow-success-light" ,
39
47
} ,
40
48
{
41
49
variant : "solid" ,
42
50
status : "error" ,
43
- className : "bg-error text-error-light" ,
51
+ className :
52
+ "bg-error text-error-light focus-visible:outline-error-dark hover:shadow-error-dark dark:hover:shadow-error-light" ,
44
53
} ,
45
54
{
46
55
variant : "solid" ,
47
56
status : "warning" ,
48
- className : "bg-warning text-warning-dark" ,
57
+ className :
58
+ "bg-warning text-warning-dark focus-visible:outline-warning-border hover:shadow-warning-dark dark:hover:shadow-warning-light" ,
49
59
} ,
50
60
{
51
- variant : "highContrast " ,
61
+ variant : "high-contrast " ,
52
62
status : "normal" ,
53
63
className : "bg-body-light text-body" ,
54
64
} ,
55
65
{
56
- variant : "highContrast " ,
66
+ variant : "high-contrast " ,
57
67
status : "tag" ,
58
68
className : "bg-background-highlight" ,
59
69
} ,
60
70
{
61
- variant : "highContrast " ,
71
+ variant : "high-contrast " ,
62
72
status : "success" ,
63
73
className : "text-success-dark" ,
64
74
} ,
65
75
{
66
- variant : "highContrast " ,
76
+ variant : "high-contrast " ,
67
77
status : "error" ,
68
78
className : "text-error-dark" ,
69
79
} ,
@@ -96,14 +106,44 @@ export interface TagProps
96
106
asChild ?: boolean
97
107
}
98
108
99
- function Tag ( { className, asChild, variant, status, ...props } : TagProps ) {
100
- const Comp = asChild ? Slot : "div"
101
- return (
102
- < Comp
103
- className = { cn ( tagVariants ( { variant, status } ) , className ) }
104
- { ...props }
105
- />
106
- )
109
+ const Tag = forwardRef < HTMLDivElement , TagProps > (
110
+ ( { className, asChild, variant, status, ...props } , ref ) => {
111
+ const Comp = asChild ? Slot : "div"
112
+ return (
113
+ < Comp
114
+ ref = { ref }
115
+ className = { cn ( tagVariants ( { variant, status } ) , className ) }
116
+ { ...props }
117
+ />
118
+ )
119
+ }
120
+ )
121
+
122
+ Tag . displayName = "Tag"
123
+
124
+ export interface TagButtonProps
125
+ extends React . ButtonHTMLAttributes < HTMLButtonElement > ,
126
+ VariantProps < typeof tagVariants > {
127
+ asChild ?: boolean
107
128
}
108
129
109
- export { Tag }
130
+ const TagButton = forwardRef < HTMLButtonElement , TagButtonProps > (
131
+ ( { className, asChild, variant, status, ...props } , ref ) => {
132
+ const Comp = asChild ? Slot : "button"
133
+ return (
134
+ < Comp
135
+ ref = { ref }
136
+ className = { cn (
137
+ "hover:shadow-[2px_2px] focus-visible:outline focus-visible:outline-4 focus-visible:-outline-offset-1 focus-visible:outline-inherit" ,
138
+ tagVariants ( { variant, status } ) ,
139
+ className
140
+ ) }
141
+ { ...props }
142
+ />
143
+ )
144
+ }
145
+ )
146
+
147
+ TagButton . displayName = "TagButton"
148
+
149
+ export { Tag , TagButton }
0 commit comments