From 68b61bceae49f4470cd1c1bbc5bbc519b54439bd Mon Sep 17 00:00:00 2001 From: Nazarii-4chain <150656925+Nazarii-4chain@users.noreply.github.com> Date: Thu, 29 Aug 2024 13:06:25 +0300 Subject: [PATCH] feat(SPV-955): Changed field type on login page (#999) --- src/components/ui/form/form.tsx | 108 +++++++++++++- src/components/ui/form/index.ts | 8 -- src/components/ui/index.ts | 1 + src/routes/login.tsx | 244 +++++++++++++++++++++----------- 4 files changed, 270 insertions(+), 91 deletions(-) diff --git a/src/components/ui/form/form.tsx b/src/components/ui/form/form.tsx index 287908ec..ee5a1152 100644 --- a/src/components/ui/form/form.tsx +++ b/src/components/ui/form/form.tsx @@ -1,3 +1,107 @@ -import { FormProvider } from 'react-hook-form'; +import { useFormField } from '@/components'; +import { Label } from '@/components/ui/label.tsx'; -export const Form = FormProvider; +import { cn } from '@/lib/utils.ts'; +import * as LabelPrimitive from '@radix-ui/react-label'; +import { Slot } from '@radix-ui/react-slot'; +import * as React from 'react'; +import { Controller, ControllerProps, FieldPath, FieldValues, FormProvider } from 'react-hook-form'; + +const Form = FormProvider; + +type FormFieldContextValue< + TFieldValues extends FieldValues = FieldValues, + TName extends FieldPath = FieldPath, +> = { + name: TName; +}; + +export const FormFieldContext = React.createContext({} as FormFieldContextValue); + +const FormField = < + TFieldValues extends FieldValues = FieldValues, + TName extends FieldPath = FieldPath, +>({ + ...props +}: ControllerProps) => { + return ( + + + + ); +}; + +type FormItemContextValue = { + id: string; +}; + +export const FormItemContext = React.createContext({} as FormItemContextValue); + +const FormItem = React.forwardRef>( + ({ className, ...props }, ref) => { + const id = React.useId(); + + return ( + +
+ + ); + }, +); +FormItem.displayName = 'FormItem'; + +const FormLabel = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => { + const { error, formItemId } = useFormField(); + + return