import { useContext } from 'react'; import cx from 'classnames'; import getWidth from '../utils/getWidth'; import { getRadioState, useRadioHandler, IRadioProps } from './AbstractRadio'; import { DisabledContext } from '../disabled'; import GroupContext from './GroupContext'; export function RadioButton(props: IRadioProps) { const { className, style, children, // value 不要放到 input 上去 value, width, onMouseEnter, onMouseLeave, ...others } = props; const disabledCtx = useContext(DisabledContext); const groupCtx = useContext(GroupContext); if (!groupCtx) { throw new Error('Radio.Button must be nested within Radio.Group'); } const { checked, disabled, readOnly } = getRadioState( disabledCtx, groupCtx, props ); const onChange = useRadioHandler(groupCtx, props); const classString = cx(className, 'zent-radio-button', { 'zent-radio-button--checked': !!checked, 'zent-radio-button--disabled': disabled || readOnly, }); const widthStyle = getWidth(width); const wrapStyle = { ...style, ...widthStyle, }; return ( ); } export default RadioButton;