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'; import { combineContextAndProps } from '../../../utils'; const FormControlLabel = ( { children, ...props }: IFormControlLabelProps, ref: any ) => { const formControlContext = useFormControlContext(); const combinedProps = combineContextAndProps(formControlContext, props); const _ref = React.useRef(null); const { _astrick, ...resolvedProps } = usePropsResolution( 'FormControlLabel', combinedProps, { isDisabled: combinedProps.isDisabled, isReadOnly: combinedProps.isReadOnly, isInvalid: combinedProps.isInvalid, // isRequired: combinedProps.isRequired, } ); 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 (resolvedProps?.nativeID) { _ref.current.htmlFor = resolvedProps.nativeID; } } }, [resolvedProps?.nativeID, props.htmlFor]); return ( {children} {resolvedProps?.isRequired && requiredAsterisk()} ); }; export default memo(forwardRef(FormControlLabel));