diff --git a/src/context/form-context.tsx b/src/context/form-context.tsx deleted file mode 100644 index 1c1d151..0000000 --- a/src/context/form-context.tsx +++ /dev/null @@ -1,25 +0,0 @@ -"use client" - -import { createContext } from "react" - -export interface FormContext { - classNames?: { - description?: string - label?: string - message?: string - input?: string - root?: string - } - - // forwardPropsFns?: { - // input?: (args: { - // component: string - // name: string - // value: string - // disabled?: boolean - // error?: FieldError - // }) => Record - // } -} - -export const Context = createContext({} as FormContext) diff --git a/src/form-provider.tsx b/src/form-provider.tsx deleted file mode 100644 index b8b7911..0000000 --- a/src/form-provider.tsx +++ /dev/null @@ -1,18 +0,0 @@ -"use client" - -import { ReactNode, useMemo } from "react" -import { Context, FormContext } from "./context/form-context" - -export interface FormProviderProps extends FormContext { - children: ReactNode -} - -export const FormProvider = ({ classNames, children }: FormProviderProps) => { - const values = useMemo( - () => ({ - classNames, - }), - [classNames] - ) - return {children} -} diff --git a/src/form.tsx b/src/form.tsx deleted file mode 100644 index d4dbfa5..0000000 --- a/src/form.tsx +++ /dev/null @@ -1,94 +0,0 @@ -"use client" - -import { - ComponentPropsWithoutRef, - ReactNode, - RefObject, - useImperativeHandle, - useRef, -} from "react" -import { - FieldValues, - FormProvider as FormPrimitiveProvider, - UseFormProps, - UseFormReturn, - useForm, -} from "react-hook-form" - -export interface FormProps< - TFieldValues extends FieldValues = FieldValues, - TContext = any, - TTransformedValues extends FieldValues | undefined = undefined, -> extends Omit, "onSubmit">, - UseFormProps { - ref?: RefObject - formRef?: RefObject> - children: ReactNode - onSubmit?: (data: TFieldValues) => void -} - -export const Form = < - TFieldValues extends FieldValues = FieldValues, - TContext = any, - TTransformedValues extends FieldValues | undefined = undefined, ->({ - children, - mode, - disabled, - reValidateMode, - defaultValues, - values, - errors, - resetOptions, - context, - shouldFocusError, - shouldUnregister, - shouldUseNativeValidation, - progressive, - criteriaMode, - delayError, - formRef, - ref, - resolver, - onSubmit, - ...props -}: FormProps) => { - const methods = useForm({ - resolver, - mode, - disabled, - reValidateMode, - defaultValues, - values, - errors, - resetOptions, - context, - shouldFocusError, - shouldUnregister, - shouldUseNativeValidation, - progressive, - criteriaMode, - delayError, - }) - - const innerFormElementRef = useRef(null) - - useImperativeHandle(formRef, () => methods as any, [methods]) - useImperativeHandle(ref, () => innerFormElementRef.current as any, [ - innerFormElementRef.current, - ]) - - return ( - -
- {children} -
-
- ) -} - -Form.displayName = "Form" diff --git a/src/hooks/use-context.ts b/src/hooks/use-context.ts deleted file mode 100644 index 028d213..0000000 --- a/src/hooks/use-context.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { useContext } from "react" -import { Context } from "../context/form-context" - -export const useCurrentFormContext = () => useContext(Context) diff --git a/src/hooks/use-form-ref.ts b/src/hooks/use-form-ref.ts deleted file mode 100644 index 158ff6d..0000000 --- a/src/hooks/use-form-ref.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { useEffect, useRef, useState } from "react" -import { FieldValues, UseFormReturn } from "react-hook-form" - -export const useFormRef = < - TFieldValues extends FieldValues = FieldValues, - TContext = any, - TTransformedValues extends FieldValues | undefined = undefined, ->() => { - const [form, setForm] = useState | null>(null) - - const ref = - useRef>(null) - - useEffect(() => { - if (ref.current) { - setForm(ref.current) - } - - return () => { - setForm(null) - } - }, [ref.current]) - - return [ref, form] as const -} diff --git a/src/hooks/use-rhf-hooks.ts b/src/hooks/use-rhf-hooks.ts deleted file mode 100644 index a24b9a7..0000000 --- a/src/hooks/use-rhf-hooks.ts +++ /dev/null @@ -1,19 +0,0 @@ -"use client" - -import { - useForm, - useController, - useFieldArray, - useFormContext, - useFormState, - useWatch, -} from "react-hook-form" - -export { - useForm, - useController, - useFieldArray, - useFormContext, - useFormState, - useWatch, -} diff --git a/src/index.ts b/src/index.ts index 4894193..cb1f4ed 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,10 +9,3 @@ export * from "./form-label" export * from "./form-message" export * from "./hooks/use-form-field" export * from "./utils" - -// export * from "./form" -// export * from "./form-provider" - -// export * from "./hooks/use-context" -// export * from "./hooks/use-rhf-hooks" -// export * from "./hooks/use-form-ref"