better-auth-ui 3.2.6 → 3.2.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,7 +7,6 @@ import {
7
7
  Controller,
8
8
  FormProvider,
9
9
  useFormContext,
10
- useFormState,
11
10
  type ControllerProps,
12
11
  type FieldPath,
13
12
  type FieldValues,
@@ -20,18 +19,16 @@ const Form = FormProvider
20
19
 
21
20
  type FormFieldContextValue<
22
21
  TFieldValues extends FieldValues = FieldValues,
23
- TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
22
+ TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>
24
23
  > = {
25
24
  name: TName
26
25
  }
27
26
 
28
- const FormFieldContext = React.createContext<FormFieldContextValue>(
29
- {} as FormFieldContextValue
30
- )
27
+ const FormFieldContext = React.createContext<FormFieldContextValue | null>(null)
31
28
 
32
29
  const FormField = <
33
30
  TFieldValues extends FieldValues = FieldValues,
34
- TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
31
+ TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>
35
32
  >({
36
33
  ...props
37
34
  }: ControllerProps<TFieldValues, TName>) => {
@@ -45,14 +42,18 @@ const FormField = <
45
42
  const useFormField = () => {
46
43
  const fieldContext = React.useContext(FormFieldContext)
47
44
  const itemContext = React.useContext(FormItemContext)
48
- const { getFieldState } = useFormContext()
49
- const formState = useFormState({ name: fieldContext.name })
50
- const fieldState = getFieldState(fieldContext.name, formState)
45
+ const { getFieldState, formState } = useFormContext()
51
46
 
52
47
  if (!fieldContext) {
53
48
  throw new Error("useFormField should be used within <FormField>")
54
49
  }
55
50
 
51
+ if (!itemContext) {
52
+ throw new Error("useFormField should be used within <FormItem>")
53
+ }
54
+
55
+ const fieldState = getFieldState(fieldContext.name, formState)
56
+
56
57
  const { id } = itemContext
57
58
 
58
59
  return {
@@ -69,47 +70,48 @@ type FormItemContextValue = {
69
70
  id: string
70
71
  }
71
72
 
72
- const FormItemContext = React.createContext<FormItemContextValue>(
73
- {} as FormItemContextValue
74
- )
73
+ const FormItemContext = React.createContext<FormItemContextValue | null>(null)
75
74
 
76
- function FormItem({ className, ...props }: React.ComponentProps<"div">) {
75
+ const FormItem = React.forwardRef<
76
+ HTMLDivElement,
77
+ React.HTMLAttributes<HTMLDivElement>
78
+ >(({ className, ...props }, ref) => {
77
79
  const id = React.useId()
78
80
 
79
81
  return (
80
82
  <FormItemContext.Provider value={{ id }}>
81
- <div
82
- data-slot="form-item"
83
- className={cn("grid gap-2", className)}
84
- {...props}
85
- />
83
+ <div ref={ref} className={cn("space-y-2", className)} {...props} />
86
84
  </FormItemContext.Provider>
87
85
  )
88
- }
86
+ })
87
+ FormItem.displayName = "FormItem"
89
88
 
90
- function FormLabel({
91
- className,
92
- ...props
93
- }: React.ComponentProps<typeof LabelPrimitive.Root>) {
89
+ const FormLabel = React.forwardRef<
90
+ React.ElementRef<typeof LabelPrimitive.Root>,
91
+ React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root>
92
+ >(({ className, ...props }, ref) => {
94
93
  const { error, formItemId } = useFormField()
95
94
 
96
95
  return (
97
96
  <Label
98
- data-slot="form-label"
99
- data-error={!!error}
100
- className={cn("data-[error=true]:text-destructive", className)}
97
+ ref={ref}
98
+ className={cn(error && "text-destructive", className)}
101
99
  htmlFor={formItemId}
102
100
  {...props}
103
101
  />
104
102
  )
105
- }
103
+ })
104
+ FormLabel.displayName = "FormLabel"
106
105
 
107
- function FormControl({ ...props }: React.ComponentProps<typeof Slot>) {
106
+ const FormControl = React.forwardRef<
107
+ React.ElementRef<typeof Slot>,
108
+ React.ComponentPropsWithoutRef<typeof Slot>
109
+ >(({ ...props }, ref) => {
108
110
  const { error, formItemId, formDescriptionId, formMessageId } = useFormField()
109
111
 
110
112
  return (
111
113
  <Slot
112
- data-slot="form-control"
114
+ ref={ref}
113
115
  id={formItemId}
114
116
  aria-describedby={
115
117
  !error
@@ -120,24 +122,32 @@ function FormControl({ ...props }: React.ComponentProps<typeof Slot>) {
120
122
  {...props}
121
123
  />
122
124
  )
123
- }
125
+ })
126
+ FormControl.displayName = "FormControl"
124
127
 
125
- function FormDescription({ className, ...props }: React.ComponentProps<"p">) {
128
+ const FormDescription = React.forwardRef<
129
+ HTMLParagraphElement,
130
+ React.HTMLAttributes<HTMLParagraphElement>
131
+ >(({ className, ...props }, ref) => {
126
132
  const { formDescriptionId } = useFormField()
127
133
 
128
134
  return (
129
135
  <p
130
- data-slot="form-description"
136
+ ref={ref}
131
137
  id={formDescriptionId}
132
- className={cn("text-muted-foreground text-sm", className)}
138
+ className={cn("text-[0.8rem] text-muted-foreground", className)}
133
139
  {...props}
134
140
  />
135
141
  )
136
- }
142
+ })
143
+ FormDescription.displayName = "FormDescription"
137
144
 
138
- function FormMessage({ className, ...props }: React.ComponentProps<"p">) {
145
+ const FormMessage = React.forwardRef<
146
+ HTMLParagraphElement,
147
+ React.HTMLAttributes<HTMLParagraphElement>
148
+ >(({ className, children, ...props }, ref) => {
139
149
  const { error, formMessageId } = useFormField()
140
- const body = error ? String(error?.message ?? "") : props.children
150
+ const body = error ? String(error?.message ?? "") : children
141
151
 
142
152
  if (!body) {
143
153
  return null
@@ -145,15 +155,16 @@ function FormMessage({ className, ...props }: React.ComponentProps<"p">) {
145
155
 
146
156
  return (
147
157
  <p
148
- data-slot="form-message"
158
+ ref={ref}
149
159
  id={formMessageId}
150
- className={cn("text-destructive text-sm", className)}
160
+ className={cn("text-[0.8rem] font-medium text-destructive", className)}
151
161
  {...props}
152
162
  >
153
163
  {body}
154
164
  </p>
155
165
  )
156
- }
166
+ })
167
+ FormMessage.displayName = "FormMessage"
157
168
 
158
169
  export {
159
170
  useFormField,
@@ -1,57 +1,46 @@
1
- "use client"
2
-
3
1
  import * as React from "react"
4
2
  import { OTPInput, OTPInputContext } from "input-otp"
5
- import { MinusIcon } from "lucide-react"
3
+ import { Minus } from "lucide-react"
6
4
 
7
5
  import { cn } from "../../lib/utils"
8
6
 
9
- function InputOTP({
10
- className,
11
- containerClassName,
12
- ...props
13
- }: React.ComponentProps<typeof OTPInput> & {
14
- containerClassName?: string
15
- }) {
16
- return (
17
- <OTPInput
18
- data-slot="input-otp"
19
- containerClassName={cn(
20
- "flex items-center gap-2 has-disabled:opacity-50",
21
- containerClassName
22
- )}
23
- className={cn("disabled:cursor-not-allowed", className)}
24
- {...props}
25
- />
26
- )
27
- }
7
+ const InputOTP = React.forwardRef<
8
+ React.ElementRef<typeof OTPInput>,
9
+ React.ComponentPropsWithoutRef<typeof OTPInput>
10
+ >(({ className, containerClassName, ...props }, ref) => (
11
+ <OTPInput
12
+ ref={ref}
13
+ containerClassName={cn(
14
+ "flex items-center gap-2 has-[:disabled]:opacity-50",
15
+ containerClassName
16
+ )}
17
+ className={cn("disabled:cursor-not-allowed", className)}
18
+ {...props}
19
+ />
20
+ ))
21
+ InputOTP.displayName = "InputOTP"
28
22
 
29
- function InputOTPGroup({ className, ...props }: React.ComponentProps<"div">) {
30
- return (
31
- <div
32
- data-slot="input-otp-group"
33
- className={cn("flex items-center", className)}
34
- {...props}
35
- />
36
- )
37
- }
23
+ const InputOTPGroup = React.forwardRef<
24
+ React.ElementRef<"div">,
25
+ React.ComponentPropsWithoutRef<"div">
26
+ >(({ className, ...props }, ref) => (
27
+ <div ref={ref} className={cn("flex items-center", className)} {...props} />
28
+ ))
29
+ InputOTPGroup.displayName = "InputOTPGroup"
38
30
 
39
- function InputOTPSlot({
40
- index,
41
- className,
42
- ...props
43
- }: React.ComponentProps<"div"> & {
44
- index: number
45
- }) {
31
+ const InputOTPSlot = React.forwardRef<
32
+ React.ElementRef<"div">,
33
+ React.ComponentPropsWithoutRef<"div"> & { index: number }
34
+ >(({ index, className, ...props }, ref) => {
46
35
  const inputOTPContext = React.useContext(OTPInputContext)
47
- const { char, hasFakeCaret, isActive } = inputOTPContext?.slots[index] ?? {}
36
+ const { char, hasFakeCaret, isActive } = inputOTPContext.slots[index]
48
37
 
49
38
  return (
50
39
  <div
51
- data-slot="input-otp-slot"
52
- data-active={isActive}
40
+ ref={ref}
53
41
  className={cn(
54
- "data-[active=true]:border-ring data-[active=true]:ring-ring/50 data-[active=true]:aria-invalid:ring-destructive/20 dark:data-[active=true]:aria-invalid:ring-destructive/40 aria-invalid:border-destructive data-[active=true]:aria-invalid:border-destructive dark:bg-input/30 border-input relative flex h-9 w-9 items-center justify-center border-y border-r text-sm shadow-xs transition-all outline-none first:rounded-l-md first:border-l last:rounded-r-md data-[active=true]:z-10 data-[active=true]:ring-[3px]",
42
+ "relative flex h-9 w-9 items-center justify-center border-y border-r border-input text-sm shadow-sm transition-all first:rounded-l-md first:border-l last:rounded-r-md",
43
+ isActive && "z-10 ring-1 ring-ring",
55
44
  className
56
45
  )}
57
46
  {...props}
@@ -59,19 +48,22 @@ function InputOTPSlot({
59
48
  {char}
60
49
  {hasFakeCaret && (
61
50
  <div className="pointer-events-none absolute inset-0 flex items-center justify-center">
62
- <div className="animate-caret-blink bg-foreground h-4 w-px duration-1000" />
51
+ <div className="h-4 w-px animate-caret-blink bg-foreground duration-1000" />
63
52
  </div>
64
53
  )}
65
54
  </div>
66
55
  )
67
- }
56
+ })
57
+ InputOTPSlot.displayName = "InputOTPSlot"
68
58
 
69
- function InputOTPSeparator({ ...props }: React.ComponentProps<"div">) {
70
- return (
71
- <div data-slot="input-otp-separator" role="separator" {...props}>
72
- <MinusIcon />
73
- </div>
74
- )
75
- }
59
+ const InputOTPSeparator = React.forwardRef<
60
+ React.ElementRef<"div">,
61
+ React.ComponentPropsWithoutRef<"div">
62
+ >(({ ...props }, ref) => (
63
+ <div ref={ref} role="separator" {...props}>
64
+ <Minus />
65
+ </div>
66
+ ))
67
+ InputOTPSeparator.displayName = "InputOTPSeparator"
76
68
 
77
69
  export { InputOTP, InputOTPGroup, InputOTPSlot, InputOTPSeparator }
@@ -2,20 +2,21 @@ import * as React from "react"
2
2
 
3
3
  import { cn } from "../../lib/utils"
4
4
 
5
- function Input({ className, type, ...props }: React.ComponentProps<"input">) {
6
- return (
7
- <input
8
- type={type}
9
- data-slot="input"
10
- className={cn(
11
- "file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input flex h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
12
- "focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]",
13
- "aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
14
- className
15
- )}
16
- {...props}
17
- />
18
- )
19
- }
5
+ const Input = React.forwardRef<HTMLInputElement, React.ComponentProps<"input">>(
6
+ ({ className, type, ...props }, ref) => {
7
+ return (
8
+ <input
9
+ type={type}
10
+ className={cn(
11
+ "flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
12
+ className
13
+ )}
14
+ ref={ref}
15
+ {...props}
16
+ />
17
+ )
18
+ }
19
+ )
20
+ Input.displayName = "Input"
20
21
 
21
22
  export { Input }
@@ -1,24 +1,24 @@
1
- "use client"
2
-
3
1
  import * as React from "react"
4
2
  import * as LabelPrimitive from "@radix-ui/react-label"
3
+ import { cva, type VariantProps } from "class-variance-authority"
5
4
 
6
5
  import { cn } from "../../lib/utils"
7
6
 
8
- function Label({
9
- className,
10
- ...props
11
- }: React.ComponentProps<typeof LabelPrimitive.Root>) {
12
- return (
13
- <LabelPrimitive.Root
14
- data-slot="label"
15
- className={cn(
16
- "flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
17
- className
18
- )}
19
- {...props}
20
- />
21
- )
22
- }
7
+ const labelVariants = cva(
8
+ "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
9
+ )
10
+
11
+ const Label = React.forwardRef<
12
+ React.ElementRef<typeof LabelPrimitive.Root>,
13
+ React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> &
14
+ VariantProps<typeof labelVariants>
15
+ >(({ className, ...props }, ref) => (
16
+ <LabelPrimitive.Root
17
+ ref={ref}
18
+ className={cn(labelVariants(), className)}
19
+ {...props}
20
+ />
21
+ ))
22
+ Label.displayName = LabelPrimitive.Root.displayName
23
23
 
24
24
  export { Label }