import classnames from 'classnames' import { h } from 'preact' import './ButtonRadio.sass' export interface SelectionOption { value: string display: string } export interface ButtonRadioProps { name?: string onChange(redirect: string): void value: T extends SelectionOption ? T['value'] : T options: T[] } const getAttr = (x: string | SelectionOption, key: keyof SelectionOption): string => typeof x === 'string' ? x : x[key] export default function ButtonRadio({ name = 'buttonRadio', onChange, options, value }: ButtonRadioProps) { /** If it's a string, return the string, if it's a SelectionOption get the selection option property */ return
{options.map(o => ({ o: getAttr(o, 'value'), display: getAttr(o, 'display') })).map(({ o, display }) =>
o !== value && onChange(o)}>
)}
}