Created
October 27, 2021 16:54
-
-
Save riceboyler/7cbf1e353e30dba21d180037a8a86378 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { HStack, useRadioGroup } from '@chakra-ui/react'; | |
import React from 'react'; | |
import { QuestionResponse } from '../types'; | |
import RadioButton from './RadioButton'; | |
interface Props { | |
question: QuestionResponse; | |
value: string; | |
onChange: (e: string) => void; | |
} | |
const RadioCard = ({ question, value, onChange }: Props) => { | |
const options = question.excludeNA ? ['Yes', 'No'] : ['Yes', 'No', 'N/A']; | |
const { getRootProps, getRadioProps } = useRadioGroup({ | |
name: `question-${question.question_id}`, | |
defaultValue: question.actual_response ?? question.suggested_response?.toString(), | |
value, | |
onChange: onChange | |
}); | |
const group = getRootProps(); | |
return ( | |
<HStack | |
{...group} | |
w="200px" | |
> | |
{options.map((value) => { | |
const radio = getRadioProps({ value }); | |
return ( | |
<RadioButton | |
key={value} | |
question={question} | |
{...radio} | |
> | |
{value} | |
</RadioButton> | |
); | |
})} | |
</HStack> | |
); | |
}; | |
export default RadioCard; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment