1
- import { useMemo } from "react"
2
- import { cva , type VariantProps } from "class-variance-authority"
1
+ import { useMemo } from "react" ;
2
+ import { cva , type VariantProps } from "class-variance-authority" ;
3
3
4
- import { cn } from "@/lib/utils"
5
- import { Label } from "@/components/ui/label"
6
- import { Separator } from "@/components/ui/separator"
4
+ import { cn } from "@/lib/utils" ;
5
+ import { Label } from "@/components/ui/label" ;
6
+ import { Separator } from "@/components/ui/separator" ;
7
7
8
8
function FieldSet ( { className, ...props } : React . ComponentProps < "fieldset" > ) {
9
9
return (
@@ -16,7 +16,7 @@ function FieldSet({ className, ...props }: React.ComponentProps<"fieldset">) {
16
16
) }
17
17
{ ...props }
18
18
/>
19
- )
19
+ ) ;
20
20
}
21
21
22
22
function FieldLegend ( {
@@ -28,15 +28,10 @@ function FieldLegend({
28
28
< legend
29
29
data-slot = "field-legend"
30
30
data-variant = { variant }
31
- className = { cn (
32
- "mb-3 font-medium" ,
33
- "data-[variant=legend]:text-base" ,
34
- "data-[variant=label]:text-sm" ,
35
- className
36
- ) }
31
+ className = { cn ( "mb-3 font-medium" , "data-[variant=legend]:text-base" , "data-[variant=label]:text-sm" , className ) }
37
32
{ ...props }
38
33
/>
39
- )
34
+ ) ;
40
35
}
41
36
42
37
function FieldGroup ( { className, ...props } : React . ComponentProps < "div" > ) {
@@ -49,32 +44,29 @@ function FieldGroup({ className, ...props }: React.ComponentProps<"div">) {
49
44
) }
50
45
{ ...props }
51
46
/>
52
- )
47
+ ) ;
53
48
}
54
49
55
- const fieldVariants = cva (
56
- "group/field flex w-full gap-3 data-[invalid=true]:text-destructive" ,
57
- {
58
- variants : {
59
- orientation : {
60
- vertical : [ "flex-col [&>*]:w-full [&>.sr-only]:w-auto" ] ,
61
- horizontal : [
62
- "flex-row items-center" ,
63
- "[&>[data-slot=field-label]]:flex-auto" ,
64
- "has-[>[data-slot=field-content]]:items-start has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px" ,
65
- ] ,
66
- responsive : [
67
- "flex-col [&>*]:w-full [&>.sr-only]:w-auto @md/field-group:flex-row @md/field-group:items-center @md/field-group:[&>*]:w-auto" ,
68
- "@md/field-group:[&>[data-slot=field-label]]:flex-auto" ,
69
- "@md/field-group:has-[>[data-slot=field-content]]:items-start @md/field-group:has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px" ,
70
- ] ,
71
- } ,
72
- } ,
73
- defaultVariants : {
74
- orientation : "vertical" ,
50
+ const fieldVariants = cva ( "group/field flex w-full gap-3 data-[invalid=true]:text-destructive" , {
51
+ variants : {
52
+ orientation : {
53
+ vertical : [ "flex-col [&>*]:w-full [&>.sr-only]:w-auto" ] ,
54
+ horizontal : [
55
+ "flex-row items-center" ,
56
+ "[&>[data-slot=field-label]]:flex-auto" ,
57
+ "has-[>[data-slot=field-content]]:items-start has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px" ,
58
+ ] ,
59
+ responsive : [
60
+ "flex-col [&>*]:w-full [&>.sr-only]:w-auto @md/field-group:flex-row @md/field-group:items-center @md/field-group:[&>*]:w-auto" ,
61
+ "@md/field-group:[&>[data-slot=field-label]]:flex-auto" ,
62
+ "@md/field-group:has-[>[data-slot=field-content]]:items-start @md/field-group:has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px" ,
63
+ ] ,
75
64
} ,
76
- }
77
- )
65
+ } ,
66
+ defaultVariants : {
67
+ orientation : "vertical" ,
68
+ } ,
69
+ } ) ;
78
70
79
71
function Field ( {
80
72
className,
@@ -89,26 +81,20 @@ function Field({
89
81
className = { cn ( fieldVariants ( { orientation } ) , className ) }
90
82
{ ...props }
91
83
/>
92
- )
84
+ ) ;
93
85
}
94
86
95
87
function FieldContent ( { className, ...props } : React . ComponentProps < "div" > ) {
96
88
return (
97
89
< div
98
90
data-slot = "field-content"
99
- className = { cn (
100
- "group/field-content flex flex-1 flex-col gap-1.5 leading-snug" ,
101
- className
102
- ) }
91
+ className = { cn ( "group/field-content flex flex-1 flex-col gap-1.5 leading-snug" , className ) }
103
92
{ ...props }
104
93
/>
105
- )
94
+ ) ;
106
95
}
107
96
108
- function FieldLabel ( {
109
- className,
110
- ...props
111
- } : React . ComponentProps < typeof Label > ) {
97
+ function FieldLabel ( { className, ...props } : React . ComponentProps < typeof Label > ) {
112
98
return (
113
99
< Label
114
100
data-slot = "field-label"
@@ -120,7 +106,7 @@ function FieldLabel({
120
106
) }
121
107
{ ...props }
122
108
/>
123
- )
109
+ ) ;
124
110
}
125
111
126
112
function FieldTitle ( { className, ...props } : React . ComponentProps < "div" > ) {
@@ -133,7 +119,7 @@ function FieldTitle({ className, ...props }: React.ComponentProps<"div">) {
133
119
) }
134
120
{ ...props }
135
121
/>
136
- )
122
+ ) ;
137
123
}
138
124
139
125
function FieldDescription ( { className, ...props } : React . ComponentProps < "p" > ) {
@@ -148,24 +134,21 @@ function FieldDescription({ className, ...props }: React.ComponentProps<"p">) {
148
134
) }
149
135
{ ...props }
150
136
/>
151
- )
137
+ ) ;
152
138
}
153
139
154
140
function FieldSeparator ( {
155
141
children,
156
142
className,
157
143
...props
158
144
} : React . ComponentProps < "div" > & {
159
- children ?: React . ReactNode
145
+ children ?: React . ReactNode ;
160
146
} ) {
161
147
return (
162
148
< div
163
149
data-slot = "field-separator"
164
150
data-content = { ! ! children }
165
- className = { cn (
166
- "relative -my-2 h-5 text-sm group-data-[variant=outline]/field-group:-mb-2" ,
167
- className
168
- ) }
151
+ className = { cn ( "relative -my-2 h-5 text-sm group-data-[variant=outline]/field-group:-mb-2" , className ) }
169
152
{ ...props }
170
153
>
171
154
< Separator className = "absolute inset-0 top-1/2" />
@@ -178,7 +161,7 @@ function FieldSeparator({
178
161
</ span >
179
162
) }
180
163
</ div >
181
- )
164
+ ) ;
182
165
}
183
166
184
167
function FieldError ( {
@@ -187,33 +170,30 @@ function FieldError({
187
170
errors,
188
171
...props
189
172
} : React . ComponentProps < "div" > & {
190
- errors ?: Array < { message ?: string } | undefined >
173
+ errors ?: Array < { message ?: string } | undefined > ;
191
174
} ) {
192
175
const content = useMemo ( ( ) => {
193
176
if ( children ) {
194
- return children
177
+ return children ;
195
178
}
196
179
197
180
if ( ! errors ) {
198
- return null
181
+ return null ;
199
182
}
200
183
201
184
if ( errors ?. length === 1 && errors [ 0 ] ?. message ) {
202
- return errors [ 0 ] . message
185
+ return errors [ 0 ] . message ;
203
186
}
204
187
205
188
return (
206
189
< ul className = "ml-4 flex list-disc flex-col gap-1" >
207
- { errors . map (
208
- ( error , index ) =>
209
- error ?. message && < li key = { index } > { error . message } </ li >
210
- ) }
190
+ { errors . map ( ( error , index ) => error ?. message && < li key = { index } > { error . message } </ li > ) }
211
191
</ ul >
212
- )
213
- } , [ children , errors ] )
192
+ ) ;
193
+ } , [ children , errors ] ) ;
214
194
215
195
if ( ! content ) {
216
- return null
196
+ return null ;
217
197
}
218
198
219
199
return (
@@ -225,7 +205,7 @@ function FieldError({
225
205
>
226
206
{ content }
227
207
</ div >
228
- )
208
+ ) ;
229
209
}
230
210
231
211
export {
@@ -239,4 +219,4 @@ export {
239
219
FieldSet ,
240
220
FieldContent ,
241
221
FieldTitle ,
242
- }
222
+ } ;
0 commit comments