import React from 'react'; import { Controller, useFormContext } from 'react-hook-form'; import Radio from '@mui/material/Radio'; import FormLabel from '@mui/material/FormLabel'; import RadioGroup from '@mui/material/RadioGroup'; import FormControl from '@mui/material/FormControl'; import FormHelperText from '@mui/material/FormHelperText'; import FormControlLabel from '@mui/material/FormControlLabel'; import { IRHFRadioGroupProps } from '../types'; /** * @description {RHFRadioGroup} - Renders a radio group component with form control and validation. * @param {IRHFRadioGroupProps} props - The props for the RHFRadioGroup component. * @return {JSX.Element} The radio group component. */ export const RHFRadioGroup = ({ row, name, label, options, spacing, helperText, ...other }: IRHFRadioGroupProps) => { const { control } = useFormContext(); const labelledby = label ? `${name}-${label}` : ''; return ( ( {label && ( {label} )} {options.map((option) => ( } label={option.label} sx={{ '&:not(:last-of-type)': { mb: spacing || 0, }, ...(row && { mr: 0, '&:not(:last-of-type)': { mr: spacing || 2, }, }), }} /> ))} {(!!error || helperText) && ( {error ? error?.message : helperText} )} )} /> ); };