import React, { memo, forwardRef } from 'react'; import Box from '../../primitives/Box'; import Text from '../../primitives/Text'; import { useFormControlContext } from './useFormControl'; import { usePropsResolution } from '../../../hooks/useThemeProps'; import type { IFormControlLabelProps } from './types'; import { mergeRefs } from '../../../utils'; const FormControlLabel = ( { children, _disabled, _invalid, ...props }: IFormControlLabelProps, ref: any ) => { const formControlContext = useFormControlContext(); const _ref = React.useRef(null); const { astrickColor, ...themedProps } = usePropsResolution( 'FormControlLabel', props ); const requiredAsterisk = () => ( * ); const mergedRef = mergeRefs([_ref, ref]); React.useEffect(() => { if (_ref.current) { // RN web doesn't support htmlFor for Label element yet if (props.htmlFor) { _ref.current.htmlFor = props.htmlFor; } else if (formControlContext?.nativeID) { _ref.current.htmlFor = formControlContext.nativeID; } } }, [formControlContext?.nativeID, props.htmlFor]); return ( {children} {formControlContext?.isRequired && requiredAsterisk()} ); }; export default memo(forwardRef(FormControlLabel));