2024-03-29 20:08:34 -04:00
|
|
|
import { TemplateOptions, ShortAnswer as ShortAnswerType, TextFormat } from './types';
|
|
|
|
|
import QuestionContainer from './QuestionContainer';
|
|
|
|
|
import Title from './Title';
|
2024-09-23 15:55:37 -04:00
|
|
|
import textType from './TextType';
|
2024-03-29 20:08:34 -04:00
|
|
|
import GlobalFeedback from './GlobalFeedback';
|
|
|
|
|
import { ParagraphStyle, InputStyle } from '../constants';
|
|
|
|
|
import { state } from './index';
|
|
|
|
|
|
|
|
|
|
type ShortAnswerOptions = TemplateOptions & ShortAnswerType;
|
|
|
|
|
type AnswerOptions = TemplateOptions & Pick<ShortAnswerType, 'choices'>;
|
|
|
|
|
|
|
|
|
|
export default function ShortAnswer({
|
|
|
|
|
title,
|
|
|
|
|
stem,
|
|
|
|
|
choices,
|
|
|
|
|
globalFeedback
|
|
|
|
|
}: ShortAnswerOptions): string {
|
|
|
|
|
return `${QuestionContainer({
|
|
|
|
|
children: [
|
|
|
|
|
Title({
|
|
|
|
|
type: 'Réponse courte',
|
|
|
|
|
title: title
|
|
|
|
|
}),
|
2024-09-23 15:55:37 -04:00
|
|
|
`<p style="${ParagraphStyle(state.theme)}">${textType({
|
2024-03-29 20:08:34 -04:00
|
|
|
text: stem
|
|
|
|
|
})}</p>`,
|
|
|
|
|
Answers({ choices: choices }),
|
|
|
|
|
GlobalFeedback({ feedback: globalFeedback })
|
|
|
|
|
]
|
|
|
|
|
})}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Answers({ choices }: AnswerOptions): string {
|
|
|
|
|
const placeholder = choices
|
2024-09-23 15:55:37 -04:00
|
|
|
.map(({ text }) => textType({ text: text as TextFormat }))
|
2024-03-29 20:08:34 -04:00
|
|
|
.join(', ');
|
|
|
|
|
return `
|
|
|
|
|
<div>
|
|
|
|
|
<span style="${ParagraphStyle(
|
|
|
|
|
state.theme
|
|
|
|
|
)}">Réponse: </span><input class="gift-input" type="text" style="${InputStyle(
|
|
|
|
|
state.theme
|
|
|
|
|
)}" placeholder="${placeholder}">
|
|
|
|
|
</div>
|
|
|
|
|
`;
|
|
|
|
|
}
|