aboutsummaryrefslogtreecommitdiff
path: root/extension/src/RadioButtonGroup.tsx
blob: 14f348d7aabc37edf51d9c0c59da23c54256e6bd (plain) (blame)
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
53
import React, {useId, useState} from "react";

interface radioEntry {
    label: string,
    data: any,
}

interface IProps {
    groupLabel: string,
    items: radioEntry[],
    defaultData: any
}

function RadioButtonGroup(props: IProps) {
    const [selected, setSelected] = useState(props.defaultData);

    return (
        <>
            <h3>{props.groupLabel}</h3>
            <div className="radio-group">
                { props.items.map((item) => (
                    <label>
                        <input
                            type="radio"
                            name={useId()}
                            value={item.data}
                            checked={item.data === selected}
                            onChange={e => setSelected(e.target.value)}
                        />
                        {item.label}
                    </label>
                )) }
            </div>
            <span>currently selected: {selected}</span>
        </>
    )
}

export default RadioButtonGroup

//     <h3>Sort</h3>
//     <label>
//         <input type="radio" name="sort"/>
//         From bookmarks
//     </label>
//     <label>
//         <input type="radio" name="sort"/>
//         Alphabetical
//     </label>
//     <label>
//         <input type="radio" name="sort"/>
//         Frequency
//     </label>