blob: 1b1f50e1dff2535aed850074a6b9d390dff39c94 (
plain)
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
|
import cx from 'clsx';
import React from 'react';
import s from './Selection.module.scss';
type SelectionProps = {
OptionComponent?: (...args: any[]) => any;
optionPropsList?: any[];
selectedIndex?: number;
onChange?: (...args: any[]) => any;
};
export function Selection2({
OptionComponent,
optionPropsList,
selectedIndex,
onChange,
}: SelectionProps) {
const inputCx = cx('visually-hidden', s.input);
const onInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
onChange(e.target.value);
};
return (
<fieldset className={s.fieldset}>
{optionPropsList.map((props, idx) => {
return (
<label key={idx}>
<input
type="radio"
checked={selectedIndex === idx}
name="selection"
value={idx}
aria-labelledby={'traffic chart type ' + idx}
onChange={onInputChange}
className={inputCx}
/>
<div className={s.cnt}>
<OptionComponent {...props} />
</div>
</label>
);
})}
</fieldset>
);
}
|