2022-05-23 12:35:50 +00:00
|
|
|
import { Row } from './layout/row'
|
|
|
|
import clsx from 'clsx'
|
|
|
|
|
|
|
|
export function ChoicesToggleGroup(props: {
|
2022-05-25 18:45:02 +00:00
|
|
|
currentChoice: number | string
|
|
|
|
setChoice: (p: any) => void //number | string does not work here because of SetStateAction in .tsx
|
|
|
|
choices: number[] | string[]
|
2022-05-23 12:35:50 +00:00
|
|
|
titles: string[]
|
|
|
|
isSubmitting?: boolean
|
|
|
|
}) {
|
|
|
|
const { currentChoice, setChoice, titles, choices, isSubmitting } = props
|
|
|
|
const baseButtonClassName = 'btn btn-outline btn-md sm:btn-md normal-case'
|
|
|
|
const activeClasss =
|
|
|
|
'bg-indigo-600 focus:bg-indigo-600 hover:bg-indigo-600 text-white'
|
|
|
|
return (
|
|
|
|
<Row className={'mt-2 items-center gap-2'}>
|
|
|
|
<div className={'btn-group justify-stretch'}>
|
|
|
|
{choices.map((choice, i) => {
|
|
|
|
return (
|
|
|
|
<button
|
2022-05-25 18:45:02 +00:00
|
|
|
key={choice.toString()}
|
2022-05-23 12:35:50 +00:00
|
|
|
disabled={isSubmitting}
|
|
|
|
className={clsx(
|
|
|
|
baseButtonClassName,
|
|
|
|
currentChoice === choice ? activeClasss : ''
|
|
|
|
)}
|
|
|
|
onClick={() => setChoice(choice)}
|
|
|
|
>
|
|
|
|
{titles[i]}
|
|
|
|
</button>
|
|
|
|
)
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
</Row>
|
|
|
|
)
|
|
|
|
}
|