import { type FC, type Key, type ReactNode, useEffect } from 'react'; import { type RadioGroupProps } from 'antd'; import clsx from 'clsx' interface RadioCardOption { value: string | number | boolean | null | undefined | Key; label: string; labelDesc?: string; icon?: string; [key: string]: string | number | boolean | undefined | null | Key; } interface RadioCardProps extends Omit { options: RadioCardOption[]; onValueChange?: (value: string | null | undefined, option?: RadioCardOption) => void; onChange?: (value: string | null | undefined, option?: RadioCardOption) => void; itemRender?: (option: RadioCardOption) => ReactNode; } const RadioGroupCard: FC = ({ options, value, onValueChange, onChange, itemRender }) => { // 监听value变化 useEffect(() => { if (onValueChange) { onValueChange(value); } }, [value, onValueChange]); const handleChange = (option: RadioCardOption) => { if (option.disabled) return if (onChange) { onChange(value === option.value ? null : String(option.value), value === option.value ? undefined : option); } } return (
{options.map(option => (
handleChange(option)}> {itemRender ? itemRender(option) : ( <> {option.icon && }
{option.label}
{option.labelDesc}
)}
) )}
); }; export default RadioGroupCard;