import {RadioGroup} from '@headlessui/react' import clsx from 'clsx' import {toKey} from 'common/parsing' import {useT} from 'web/lib/locale' const colorClasses = { 'indigo-dark': 'text-ink-500 hover:bg-primary-100 hover:text-ink-700 aria-checked:bg-primary-500 aria-checked:text-white', indigo: 'text-ink-500 hover:bg-ink-50 aria-checked:bg-primary-100 aria-checked:text-primary-900', green: 'text-ink-500 hover:bg-ink-50 aria-checked:bg-teal-500 aria-checked:text-ink-0', red: 'text-ink-500 hover:bg-ink-50 aria-checked:bg-scarlet-500 aria-checked:text-ink-0', } export type ColorType = keyof typeof colorClasses export function ChoicesToggleGroup>(props: { currentChoice: T[keyof T] | undefined | null choicesMap: T disabled?: boolean disabledOptions?: Array setChoice: (val: T[keyof T]) => void color?: ColorType className?: string toggleClassName?: string children?: React.ReactNode translationPrefix?: string }) { const { currentChoice, setChoice, disabled, disabledOptions, choicesMap, color = 'indigo-dark', className, children, toggleClassName, translationPrefix, } = props const t = useT() // Object.entries(choicesMap).map(([choiceKey, choice]) => ( // console.log(`${translationPrefix}.${toKey(String(choice))}`) // )) return ( {Object.entries(choicesMap).map(([choiceKey, choice]) => ( clsx( disabled ? 'text-ink-300 aria-checked:bg-ink-300 aria-checked:text-ink-0 cursor-not-allowed' : 'cursor-pointer ' + colorClasses[color], 'ring-primary-500 flex items-center rounded-md p-2 outline-none transition-all focus-visible:ring-2 sm:px-3', toggleClassName, ) } > {translationPrefix ? t(`${translationPrefix}.${toKey(String(choice))}`, choiceKey) : choiceKey} ))} {children} ) }