index.tsx 834 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import cn from 'classnames'
  5. import s from './style.module.css'
  6. type OPTION = {
  7. label: string
  8. value: any
  9. }
  10. type Props = {
  11. className?: string
  12. options: OPTION[]
  13. value: any
  14. onChange: (value: any) => void
  15. }
  16. const RadioGroup: FC<Props> = ({
  17. className = '',
  18. options,
  19. value,
  20. onChange,
  21. }) => {
  22. return (
  23. <div className={cn(className, 'flex')}>
  24. {options.map(item => (
  25. <div
  26. key={item.value}
  27. className={cn(s.item, item.value === value && s.checked)}
  28. onClick={() => onChange(item.value)}
  29. >
  30. <div className={s.radio}></div>
  31. <div className='text-[13px] font-medium text-gray-900'>{item.label}</div>
  32. </div>
  33. ))}
  34. </div>
  35. )
  36. }
  37. export default React.memo(RadioGroup)