import React, { useCallback } from 'react'; import { Box, Flex, Grid, type GridProps, HStack } from '@chakra-ui/react'; import { useTranslation } from 'next-i18next'; import QuestionTip from '../MyTooltip/QuestionTip'; type Props = Omit & { list: { title: string | React.ReactNode; desc?: string; value: T; children?: React.ReactNode; tooltip?: string; }[]; align?: 'flex-top' | 'center'; value: T; defaultBg?: string; activeBg?: string; onChange: (e: T) => void; isDisabled?: boolean; }; const LeftRadio = ({ list, value, align = 'center', px = 3.5, py = 4, gridGap = [3, 5], defaultBg = 'myGray.50', activeBg = 'primary.50', onChange, isDisabled = false, ...props }: Props) => { const { t } = useTranslation(); const getBoxStyle = useCallback( (isActive: boolean) => { const baseStyle = { px, py, border: 'base', borderWidth: '1px', borderRadius: 'md' }; if (isActive) { return { ...baseStyle, borderColor: 'primary.400', bg: activeBg, boxShadow: 'focus', cursor: 'pointer', opacity: 1 }; } if (isDisabled) { return { ...baseStyle, bg: 'myWhite.300', borderColor: 'myGray.200', color: 'myGray.500', cursor: 'not-allowed', opacity: 0.6 }; } return { ...baseStyle, bg: defaultBg, _hover: { borderColor: 'primary.300' }, cursor: 'pointer', opacity: 1 }; }, [activeBg, defaultBg, isDisabled, px, py] ); return ( {list.map((item) => { const isActive = value === item.value; return ( !isDisabled && onChange(item.value)} {...getBoxStyle(isActive)} > {/* Circle */} {typeof item.title === 'string' ? ( {t(item.title as any)} {!!item.tooltip && } ) : ( item.title )} {!!item.desc && ( {t(item.desc as any)} )} {item?.children && ( {item?.children} )} ); })} ); }; export default LeftRadio;