import { MAX_ANSWER_LENGTH } from 'common/answer' import { XIcon } from '@heroicons/react/solid' import { Col } from '../layout/col' import { Row } from '../layout/row' import { ExpandingInput } from '../expanding-input' export function MultipleChoiceAnswers(props: { answers: string[] setAnswers: (answers: string[]) => void }) { const { answers, setAnswers } = props const setAnswer = (i: number, answer: string) => { const newAnswers = setElement(answers, i, answer) setAnswers(newAnswers) } const removeAnswer = (i: number) => { const newAnswers = answers.slice(0, i).concat(answers.slice(i + 1)) setAnswers(newAnswers) } const addAnswer = () => setAnswer(answers.length, '') return ( {answers.map((answer, i) => ( {i + 1}.{' '} setAnswer(i, e.target.value)} className="ml-2 w-full" placeholder="Type your answer..." rows={1} maxLength={MAX_ANSWER_LENGTH} /> {answers.length > 2 && ( )} ))} ) } const setElement = (array: T[], i: number, elem: T) => { const newArray = array.concat() newArray[i] = elem return newArray }