import React, { memo, forwardRef } from 'react'; import { Pressable, IPressableProps } from '../Pressable'; import { Center } from '../../composites/Center'; import Box from '../Box'; import { usePropsResolution } from '../../../hooks/useThemeProps'; import type { IRadioProps } from './types'; import { useRadio } from '@react-native-aria/radio'; import { RadioContext } from './RadioGroup'; import { mergeRefs } from '../../../utils'; import { CircleIcon } from '../Icon/Icons'; const Radio = ( { icon, children, wrapperRef, ...props }: IRadioProps, ref: any ) => { const contextState = React.useContext(RadioContext); const { _interactionBox: { _pressed: _iterationBoxPressed, ..._interactionBox }, _radio: { _checked: _radioChecked, _disabled: _radioDisabled, _invalid: _radioInvalid, ..._radio }, _icon, isInvalid, ...themedProps } = usePropsResolution('Radio', { ...contextState, ...props, }); const inputRef = React.useRef(null); const { inputProps } = useRadio(props, contextState.state, inputRef); const { disabled, checked } = inputProps; // only calling below function when icon exist. const sizedIcon = () => //@ts-ignore React.cloneElement(icon, { ..._icon, }); return ( {({ isPressed }: any) => { return (
{/* Interaction Wrapper */} {/* radio */}
{icon && sizedIcon && checked ? ( sizedIcon() ) : ( )}
{/* Label */} {children}
); }}
); }; export default memo(forwardRef(Radio));