@@ -4,46 +4,47 @@ import MenuItem from './MenuItem';
44
55import styles from './ConfigElement.module.css' ;
66
7- interface EitherProps extends ConfigElementProps {
7+ interface EitherProps < T extends string > extends ConfigElementProps {
88 id : string ;
99 a : string ;
1010 b : string ;
1111 aLabel ?: string ;
1212 bLabel ?: string ;
13- value : string ;
14- onChange : ( _ : string ) => any ;
13+ value : T ;
14+ onChange : ( _ : T ) => any ;
1515}
1616
17- export const Either : React . FC < EitherProps > =
18- ( { id, a, b, aLabel = a , bLabel = b , value, onChange, ...rest } ) => (
17+ export const Either =
18+ < T extends string , > ( { id, a, b, aLabel = a , bLabel = b , value, onChange, ...rest } : EitherProps < T > ) => (
1919 < ConfigElement { ...rest } >
2020 < div className = { styles . toggle } >
2121 < input id = { `${ id } -a` }
2222 name = { id }
2323 value = { a }
2424 type = "radio"
2525 checked = { value === a }
26- onChange = { ( ) => onChange ( a ) } />
26+ onChange = { ( ) => onChange ( a as T ) } />
2727 < label htmlFor = { `${ id } -a` } > { aLabel } </ label >
2828 < input id = { `${ id } -b` }
2929 name = { id }
3030 value = { b }
3131 type = "radio"
3232 checked = { value === b }
33- onChange = { ( ) => onChange ( b ) } />
33+ onChange = { ( ) => onChange ( b as T ) } />
3434 < label htmlFor = { `${ id } -b` } > { bLabel } </ label >
3535 </ div >
3636 </ ConfigElement >
3737 ) ;
3838
39- interface SelectProps extends ConfigElementProps {
40- value : string ;
41- onChange : ( _ : string ) => any ;
39+ interface SelectProps < T extends string > extends ConfigElementProps {
40+ children : React . ReactNode ;
41+ value : T ;
42+ onChange : ( _ : T ) => any ;
4243}
4344
44- export const Select : React . FC < SelectProps > = ( { value, onChange, children, ...rest } ) => (
45+ export const Select = < T extends string , > ( { value, onChange, children, ...rest } : SelectProps < T > ) => (
4546 < ConfigElement { ...rest } >
46- < select className = { styles . select } value = { value } onChange = { e => onChange ( e . target . value ) } >
47+ < select className = { styles . select } value = { value } onChange = { e => onChange ( e . target . value as T ) } >
4748 { children }
4849 </ select >
4950 </ ConfigElement >
0 commit comments