import * as React from "react"; import { Controller, type FieldPath, type FieldValues, get, useFormContext, } from "react-hook-form"; import { FormMessage } from "~/components/FormMessage"; import { Label } from "~/components/Label"; import { SendouSwitch } from "../elements/Switch"; export function ToggleFormField({ label, name, bottomText, }: { label: string; name: FieldPath; bottomText?: string; }) { const methods = useFormContext(); const id = React.useId(); const error = get(methods.formState.errors, name); return (
( )} /> {error && ( {error.message as string} )} {bottomText && !error ? ( {bottomText} ) : null}
); }