2022-05-25 17:54:28 +00:00
|
|
|
import { RadioGroup } from '@headlessui/react'
|
2022-05-23 12:35:50 +00:00
|
|
|
import clsx from 'clsx'
|
2022-05-25 17:54:28 +00:00
|
|
|
import React from 'react'
|
2022-05-23 12:35:50 +00:00
|
|
|
|
|
|
|
export function ChoicesToggleGroup(props: {
|
2022-05-25 17:54:28 +00:00
|
|
|
currentChoice: number | string
|
|
|
|
choicesMap: { [key: string]: string | number }
|
2022-05-23 12:35:50 +00:00
|
|
|
isSubmitting?: boolean
|
2022-05-25 17:54:28 +00:00
|
|
|
setChoice: (p: number | string) => void
|
|
|
|
className?: string
|
2022-06-06 17:36:59 +00:00
|
|
|
toggleClassName?: string
|
2022-05-25 17:54:28 +00:00
|
|
|
children?: React.ReactNode
|
2022-05-23 12:35:50 +00:00
|
|
|
}) {
|
2022-05-25 17:54:28 +00:00
|
|
|
const {
|
|
|
|
currentChoice,
|
|
|
|
setChoice,
|
|
|
|
isSubmitting,
|
|
|
|
choicesMap,
|
|
|
|
className,
|
|
|
|
children,
|
2022-06-06 17:36:59 +00:00
|
|
|
toggleClassName,
|
2022-05-25 17:54:28 +00:00
|
|
|
} = props
|
2022-05-23 12:35:50 +00:00
|
|
|
return (
|
2022-06-05 02:53:55 +00:00
|
|
|
<RadioGroup
|
|
|
|
className={clsx(className, 'flex flex-row flex-wrap items-center gap-3')}
|
|
|
|
value={currentChoice.toString()}
|
|
|
|
onChange={(str) => null}
|
|
|
|
>
|
|
|
|
{Object.keys(choicesMap).map((choiceKey) => (
|
|
|
|
<RadioGroup.Option
|
|
|
|
key={choiceKey}
|
|
|
|
value={choicesMap[choiceKey]}
|
|
|
|
onClick={() => setChoice(choicesMap[choiceKey])}
|
|
|
|
className={({ active }) =>
|
|
|
|
clsx(
|
|
|
|
active ? 'ring-2 ring-indigo-500 ring-offset-2' : '',
|
|
|
|
currentChoice === choicesMap[choiceKey]
|
|
|
|
? 'border-transparent bg-indigo-500 text-white hover:bg-indigo-600'
|
|
|
|
: 'border-gray-200 bg-white text-gray-900 hover:bg-gray-50',
|
|
|
|
'flex cursor-pointer items-center justify-center rounded-md border py-3 px-3 text-sm font-medium normal-case',
|
|
|
|
"hover:ring-offset-2' hover:ring-2 hover:ring-indigo-500",
|
2022-06-06 17:36:59 +00:00
|
|
|
toggleClassName
|
2022-06-05 02:53:55 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
disabled={isSubmitting}
|
|
|
|
>
|
|
|
|
<RadioGroup.Label as="span">{choiceKey}</RadioGroup.Label>
|
|
|
|
</RadioGroup.Option>
|
|
|
|
))}
|
|
|
|
{children}
|
2022-06-05 02:28:27 +00:00
|
|
|
</RadioGroup>
|
2022-05-23 12:35:50 +00:00
|
|
|
)
|
|
|
|
}
|