import {RadioGroup} from '@headlessui/react' import clsx from 'clsx' import {orderBy} from 'lodash' import {Row} from '../layout/row' export function RadioToggleGroup(props: { currentChoice: number choicesMap: Record setChoice: (p: number) => void className?: string toggleClassName?: string indexColors?: Record }) { const {currentChoice, setChoice, choicesMap, className, toggleClassName, indexColors} = props const orderedChoicesMap = orderBy(Object.entries(choicesMap), ([_, choice]) => choice) const length = orderedChoicesMap.length return ( {orderedChoicesMap[0][0]} {orderedChoicesMap.map(([choiceKey, choice], index) => ( { if (currentChoice == choice) { setChoice(-1) } }} aria-label={choiceKey} key={choiceKey} value={choice} data-testid={`compatibility-question-importance-${choice}`} className={({disabled}) => clsx( disabled ? 'cursor-not-allowed' : 'cursor-pointer ', ' mx-auto h-5 w-5 rounded-full bg-opacity-20 ring-1 ring-opacity-70 transition-all dark:bg-opacity-20 dark:aria-checked:bg-opacity-100', ' aria-checked:bg-opacity-100 aria-checked:ring-8 aria-checked:ring-opacity-40 dark:aria-checked:ring-opacity-40', disabled ? 'bg-ink-400 ring-ink-400' : indexColors ? indexColors[index] : index == 0 ? `bg-rose-600 ring-rose-600 dark:bg-rose-500 dark:ring-rose-500` : index == 1 ? `bg-rose-400 ring-rose-400` : index == 2 ? `bg-stone-400 ring-stone-400 dark:bg-stone-500 dark:ring-stone-500` : index == 3 ? `bg-teal-300 ring-teal-300 dark:bg-teal-200 dark:ring-teal-200 ` : `bg-teal-400 ring-teal-400`, toggleClassName, ) } /> ))} {orderedChoicesMap[length - 1][0]} ) }