import { connect, mapProps, mapReadPretty, useField } from '@formily/react'; import { isValid } from '@formily/shared'; import { Radio as AntdRadio, Tag } from 'antd'; import type { RadioGroupProps, RadioProps } from 'antd/lib/radio'; import React from 'react'; type ComposedRadio = React.FC & { Group?: React.FC; __ANT_RADIO?: boolean; }; export const Radio: ComposedRadio = connect( AntdRadio, mapProps({ value: 'checked', onInput: 'onChange', }), ); Radio.__ANT_RADIO = true; Radio.Group = connect( AntdRadio.Group, mapProps({ dataSource: 'options', }), mapReadPretty((props) => { if (!isValid(props.value)) { return
; } const { options = [], value } = props; const field = useField(); const dataSource = field.dataSource || []; console.log({ dataSource }); return (
{dataSource .filter((option) => option.value === value) .map((option, key) => ( {option.label} ))}
); }), ); export default Radio;