34 lines
862 B
TypeScript
34 lines
862 B
TypeScript
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
import { FieldValues, Path, RegisterOptions, UseFormReturn } from "react-hook-form";
|
|
import { cn } from "@repo/shared-components";
|
|
|
|
interface InputProps<T extends FieldValues>
|
|
extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "form"> {
|
|
name: Path<T>;
|
|
form: UseFormReturn<any>;
|
|
formOptions?: RegisterOptions<T>;
|
|
label?: string;
|
|
}
|
|
|
|
export const Switch = <T extends FieldValues>({
|
|
name,
|
|
label = name,
|
|
form,
|
|
className,
|
|
...inputProps
|
|
}: InputProps<T>) => {
|
|
return (
|
|
<div className="form-control ">
|
|
<label className="label cursor-pointer w-full">
|
|
<span className={cn("label-text text-left w-full", className)}>{label}</span>
|
|
<input
|
|
type="checkbox"
|
|
className={cn("toggle", className)}
|
|
{...form.register(name)}
|
|
{...inputProps}
|
|
/>
|
|
</label>
|
|
</div>
|
|
);
|
|
};
|