mirror of
https://github.com/ershisan99/db-studio.git
synced 2025-12-17 05:09:25 +00:00
refactor login form
This commit is contained in:
34
frontend/src/components/ui/form/form-select.tsx
Normal file
34
frontend/src/components/ui/form/form-select.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import { Select } from "@/components/ui";
|
||||
import type { ComponentPropsWithoutRef } from "react";
|
||||
import {
|
||||
type Control,
|
||||
type FieldValues,
|
||||
type UseControllerProps,
|
||||
useController,
|
||||
} from "react-hook-form";
|
||||
|
||||
type Props<T extends FieldValues> = Omit<
|
||||
UseControllerProps<T>,
|
||||
"control" | "defaultValue" | "rules"
|
||||
> &
|
||||
Omit<ComponentPropsWithoutRef<typeof Select>, "value" | "onValueChange"> & {
|
||||
control: Control<T>;
|
||||
};
|
||||
|
||||
export const FormSelect = <T extends FieldValues>({
|
||||
control,
|
||||
name,
|
||||
disabled,
|
||||
shouldUnregister,
|
||||
...rest
|
||||
}: Props<T>) => {
|
||||
const {
|
||||
field: { onChange, ...field },
|
||||
} = useController({
|
||||
control,
|
||||
name,
|
||||
disabled,
|
||||
shouldUnregister,
|
||||
});
|
||||
return <Select {...field} {...rest} onValueChange={onChange} />;
|
||||
};
|
||||
Reference in New Issue
Block a user