import { Flex, FormControl, FormLabel, FormErrorMessage } from '@chakra-ui/react'; import { useFormContext } from 'react-hook-form'; import { If } from '~/components'; import { useColorValue } from '~/context'; import { useBooleanValue } from '~/hooks'; import { TField, TFormError } from './types'; export const FormField: React.FC = (props: TField) => { const { name, label, children, labelAddOn, fieldAddOn, hiddenLabels = false, ...rest } = props; const labelColor = useColorValue('blackAlpha.700', 'whiteAlpha.700'); const errorColor = useColorValue('red.500', 'red.300'); const opacity = useBooleanValue(hiddenLabels, 0, undefined); const { errors } = useFormContext(); const error = name in errors && (errors[name] as TFormError); if (error !== false) { console.warn(`${label} Error: ${error.message}`); } return ( {label} {labelAddOn} {children} {fieldAddOn} {error && error.message} ); };