import { useMemo } from 'react'; import { Flex, FormControl, FormLabel, FormErrorMessage } from '@chakra-ui/react'; import { If } from '~/components'; import { useColorValue } from '~/context'; import { useBooleanValue } from '~/hooks'; import { TField } from './types'; export const FormField = (props: TField) => { const { name, label, errors, children, labelAddOn, fieldAddOn, hiddenLabels = false, ...rest } = props; const labelColor = useColorValue('blackAlpha.700', 'whiteAlpha.700'); const opacity = useBooleanValue(hiddenLabels, 0, undefined); const error = useMemo(() => { let result; if (Array.isArray(errors)) { result = errors.join(', '); } else if (typeof errors === 'string') { result = errors; } return result; }, [errors]); return ( {label} {labelAddOn} {children} {fieldAddOn} {error} ); };