UNPKG

mui-rhf-integration

Version:

React Hook Form integration for MUI with strict TypeScript handling based on form context.

22 lines (21 loc) 1.49 kB
import { FormControlProps, FormLabelProps, RadioGroupProps } from '@mui/material'; import { ReactNode } from 'react'; import { Control, FieldPathByValue, FieldValues, RegisterOptions } from 'react-hook-form'; export type RadioOption = { value: string; label: ReactNode; }; export type RhfRadioGroupProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPathByValue<TFieldValues, string | null | undefined> = FieldPathByValue<TFieldValues, string | null | undefined>, TContext = any, TTransformedValues = TFieldValues> = Omit<FormControlProps, "error" | "ref"> & { control: Control<TFieldValues, TContext, TTransformedValues>; name: TName; rules?: Omit<RegisterOptions<NoInfer<TFieldValues>, NoInfer<TName>>, "valueAsNumber" | "valueAsDate" | "setValueAs" | "disabled">; label: string; options: RadioOption[]; helperText?: string; slotProps?: { formLabel?: FormLabelProps; radioGroup?: Omit<RadioGroupProps, "name" | "onChange" | "onBlur" | "value">; }; }; declare const RhfRadioGroup: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPathByValue<TFieldValues, string | null | undefined> = FieldPathByValue<TFieldValues, string | null | undefined>, TContext = any, TTransformedValues = TFieldValues>({ control, name, rules, label, options, helperText, slotProps, ...formControlProps }: RhfRadioGroupProps<TFieldValues, TName, TContext, TTransformedValues>) => ReactNode; export default RhfRadioGroup;