2022-05-18 21:54:29 +03:00

38 lines
822 B
TypeScript

import type { RadioChangeEvent, RadioProps } from 'antd';
import { Form, Radio as AntRadio } from 'antd';
import type { BaseElementProps, BaseOption } from './types';
const { Item: FormItem } = Form;
type ElementProps = BaseElementProps<string | null> & {
options: BaseOption[];
};
export default function Radio({
value = null,
setValue,
options,
status,
isValid,
help,
...props
}: ElementProps) {
function handleChange(e: RadioChangeEvent) {
setValue(e.target.value);
}
return (
<FormItem hasFeedback validateStatus={isValid === false ? 'error' : ''} help={help}>
<AntRadio.Group
value={value}
options={options}
onChange={handleChange}
disabled={status === 'Disabled'}
{...props}
/>
</FormItem>
);
}
export type { RadioProps };