index.tsx 744 B

123456789101112131415161718192021222324
  1. import type { ReactElement } from 'react'
  2. import RadioGroupContext from '../../context'
  3. import s from '../../style.module.css'
  4. import cn from '@/utils/classnames'
  5. export type TRadioGroupProps = {
  6. children?: ReactElement | ReactElement[]
  7. value?: string | number
  8. className?: string
  9. onChange?: (value: any) => void
  10. }
  11. export default function Group({ children, value, onChange, className = '' }: TRadioGroupProps): JSX.Element {
  12. const onRadioChange = (value: any) => {
  13. onChange?.(value)
  14. }
  15. return (
  16. <div className={cn('flex items-center bg-gray-50', s.container, className)}>
  17. <RadioGroupContext.Provider value={{ value, onChange: onRadioChange }}>
  18. {children}
  19. </RadioGroupContext.Provider>
  20. </div>
  21. )
  22. }