File size: 1,111 Bytes
a417977
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import style from "./style.module.scss";
import {ChangeEvent} from "rollup";
import {JSX} from "preact";

export function Radio<Choices extends Record<string, string>>(props: {
    name: string,
    choices: Choices,
    value: keyof Choices,
    onChoose: (choice: keyof Choices) => void,
}) {
    let buttons = [];

    for (const [key, value] of Object.entries(props.choices)) {
        console.log(props.value)
        buttons.push(
            <div className={style.group}>
                <input
                    type="radio"
                    name={props.name}
                    id={key}
                    autoComplete="off"
                    value={key}
                    checked={props.value === key}
                    onClick={e => {
                        props.onChoose(key);
                    }}
                />
                <label
                    htmlFor={key}
                >
                    {value}
                </label>
            </div>
        )
    }


    return (
        <div className={style.container}>
            {buttons}
        </div>
    );
}