File size: 994 Bytes
56b6519
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import React from 'react';

import Radio from './Radio';

export type RadioOption = {
  id: string;
  label: string;
  value: string;
  disabled?: boolean;
};

type RadioGroupProps = {
  name: string;
  options: RadioOption[];
  value: string;
  onChange: (value: string) => void;
};

const DefaultRadioGroup = ({
  name,
  options,
  value,
  onChange,
}: RadioGroupProps) => {
  const handleRadioGroupChange = (
    event: React.ChangeEvent<HTMLInputElement>,
  ) => {
    onChange(event.target.value);
  };

  return (
    <div>
      {options.map(option => (
        <div className="mb-3" key={option.id}>
          <Radio
            checked={value === option.value}
            disabled={option.disabled}
            id={option.id}
            key={option.id}
            label={option.label}
            name={name}
            onChange={handleRadioGroupChange}
            value={option.value}
          />
        </div>
      ))}
    </div>
  );
};

export default DefaultRadioGroup;