better-auth-ui 3.2.6 → 3.2.11

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.
@@ -1,5 +1,3 @@
1
- "use client"
2
-
3
1
  import * as React from "react"
4
2
  import * as LabelPrimitive from "@radix-ui/react-label"
5
3
  import { Slot } from "@radix-ui/react-slot"
@@ -7,7 +5,6 @@ import {
7
5
  Controller,
8
6
  FormProvider,
9
7
  useFormContext,
10
- useFormState,
11
8
  type ControllerProps,
12
9
  type FieldPath,
13
10
  type FieldValues,
@@ -20,18 +17,16 @@ const Form = FormProvider
20
17
 
21
18
  type FormFieldContextValue<
22
19
  TFieldValues extends FieldValues = FieldValues,
23
- TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
20
+ TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>
24
21
  > = {
25
22
  name: TName
26
23
  }
27
24
 
28
- const FormFieldContext = React.createContext<FormFieldContextValue>(
29
- {} as FormFieldContextValue
30
- )
25
+ const FormFieldContext = React.createContext<FormFieldContextValue | null>(null)
31
26
 
32
27
  const FormField = <
33
28
  TFieldValues extends FieldValues = FieldValues,
34
- TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
29
+ TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>
35
30
  >({
36
31
  ...props
37
32
  }: ControllerProps<TFieldValues, TName>) => {
@@ -45,14 +40,18 @@ const FormField = <
45
40
  const useFormField = () => {
46
41
  const fieldContext = React.useContext(FormFieldContext)
47
42
  const itemContext = React.useContext(FormItemContext)
48
- const { getFieldState } = useFormContext()
49
- const formState = useFormState({ name: fieldContext.name })
50
- const fieldState = getFieldState(fieldContext.name, formState)
43
+ const { getFieldState, formState } = useFormContext()
51
44
 
52
45
  if (!fieldContext) {
53
46
  throw new Error("useFormField should be used within <FormField>")
54
47
  }
55
48
 
49
+ if (!itemContext) {
50
+ throw new Error("useFormField should be used within <FormItem>")
51
+ }
52
+
53
+ const fieldState = getFieldState(fieldContext.name, formState)
54
+
56
55
  const { id } = itemContext
57
56
 
58
57
  return {
@@ -69,47 +68,48 @@ type FormItemContextValue = {
69
68
  id: string
70
69
  }
71
70
 
72
- const FormItemContext = React.createContext<FormItemContextValue>(
73
- {} as FormItemContextValue
74
- )
71
+ const FormItemContext = React.createContext<FormItemContextValue | null>(null)
75
72
 
76
- function FormItem({ className, ...props }: React.ComponentProps<"div">) {
73
+ const FormItem = React.forwardRef<
74
+ HTMLDivElement,
75
+ React.HTMLAttributes<HTMLDivElement>
76
+ >(({ className, ...props }, ref) => {
77
77
  const id = React.useId()
78
78
 
79
79
  return (
80
80
  <FormItemContext.Provider value={{ id }}>
81
- <div
82
- data-slot="form-item"
83
- className={cn("grid gap-2", className)}
84
- {...props}
85
- />
81
+ <div ref={ref} className={cn("space-y-2", className)} {...props} />
86
82
  </FormItemContext.Provider>
87
83
  )
88
- }
84
+ })
85
+ FormItem.displayName = "FormItem"
89
86
 
90
- function FormLabel({
91
- className,
92
- ...props
93
- }: React.ComponentProps<typeof LabelPrimitive.Root>) {
87
+ const FormLabel = React.forwardRef<
88
+ React.ElementRef<typeof LabelPrimitive.Root>,
89
+ React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root>
90
+ >(({ className, ...props }, ref) => {
94
91
  const { error, formItemId } = useFormField()
95
92
 
96
93
  return (
97
94
  <Label
98
- data-slot="form-label"
99
- data-error={!!error}
100
- className={cn("data-[error=true]:text-destructive", className)}
95
+ ref={ref}
96
+ className={cn(error && "text-destructive", className)}
101
97
  htmlFor={formItemId}
102
98
  {...props}
103
99
  />
104
100
  )
105
- }
101
+ })
102
+ FormLabel.displayName = "FormLabel"
106
103
 
107
- function FormControl({ ...props }: React.ComponentProps<typeof Slot>) {
104
+ const FormControl = React.forwardRef<
105
+ React.ElementRef<typeof Slot>,
106
+ React.ComponentPropsWithoutRef<typeof Slot>
107
+ >(({ ...props }, ref) => {
108
108
  const { error, formItemId, formDescriptionId, formMessageId } = useFormField()
109
109
 
110
110
  return (
111
111
  <Slot
112
- data-slot="form-control"
112
+ ref={ref}
113
113
  id={formItemId}
114
114
  aria-describedby={
115
115
  !error
@@ -120,24 +120,32 @@ function FormControl({ ...props }: React.ComponentProps<typeof Slot>) {
120
120
  {...props}
121
121
  />
122
122
  )
123
- }
123
+ })
124
+ FormControl.displayName = "FormControl"
124
125
 
125
- function FormDescription({ className, ...props }: React.ComponentProps<"p">) {
126
+ const FormDescription = React.forwardRef<
127
+ HTMLParagraphElement,
128
+ React.HTMLAttributes<HTMLParagraphElement>
129
+ >(({ className, ...props }, ref) => {
126
130
  const { formDescriptionId } = useFormField()
127
131
 
128
132
  return (
129
133
  <p
130
- data-slot="form-description"
134
+ ref={ref}
131
135
  id={formDescriptionId}
132
- className={cn("text-muted-foreground text-sm", className)}
136
+ className={cn("text-[0.8rem] text-muted-foreground", className)}
133
137
  {...props}
134
138
  />
135
139
  )
136
- }
140
+ })
141
+ FormDescription.displayName = "FormDescription"
137
142
 
138
- function FormMessage({ className, ...props }: React.ComponentProps<"p">) {
143
+ const FormMessage = React.forwardRef<
144
+ HTMLParagraphElement,
145
+ React.HTMLAttributes<HTMLParagraphElement>
146
+ >(({ className, children, ...props }, ref) => {
139
147
  const { error, formMessageId } = useFormField()
140
- const body = error ? String(error?.message ?? "") : props.children
148
+ const body = error ? String(error?.message ?? "") : children
141
149
 
142
150
  if (!body) {
143
151
  return null
@@ -145,15 +153,16 @@ function FormMessage({ className, ...props }: React.ComponentProps<"p">) {
145
153
 
146
154
  return (
147
155
  <p
148
- data-slot="form-message"
156
+ ref={ref}
149
157
  id={formMessageId}
150
- className={cn("text-destructive text-sm", className)}
158
+ className={cn("text-[0.8rem] font-medium text-destructive", className)}
151
159
  {...props}
152
160
  >
153
161
  {body}
154
162
  </p>
155
163
  )
156
- }
164
+ })
165
+ FormMessage.displayName = "FormMessage"
157
166
 
158
167
  export {
159
168
  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 }