import * as React from "react"; import { Col, Input, Row } from "reactstrap"; import { IChoiceProps } from "./Choice"; import { IInternalPromptProps, IPromptProps } from "./Prompt"; import { MultipleChoicePromptData } from "./QuizData"; export interface IMultipleChoicePromptProps extends IPromptProps { onlyOne?: boolean; randomOrder?: boolean; choices: Array>; } export class MultipleChoicePrompt extends React.PureComponent< IMultipleChoicePromptProps > { static is(value: any): value is MultipleChoicePrompt { return React.isValidElement(value) && value.type === MultipleChoicePrompt; } render() { return null; } } export interface IInternalMultipleChoicePromptProps extends IInternalPromptProps { prompt: MultipleChoicePromptData; input: boolean[]; update(fn: (input: boolean[]) => boolean[]): boolean[]; } export class InternalMultipleChoicePrompt extends React.PureComponent< IInternalMultipleChoicePromptProps > { createOnChange = (index: number) => () => { this.props.update(input => { const nextInput = this.props.prompt.onlyOne ? [] : input.slice(); nextInput[index] = !nextInput[index]; return nextInput; }); }; render() { return (
{this.props.prompt.prompt}
{this.props.prompt.choices.map((child, index) => (
{child.children} {index < this.props.prompt.choices.length - 1 &&
}
))}
); } }