EvalueTonSavoir/client/src/components/GiftTemplate/templates/ShortAnswerTemplate.ts

46 lines
1.5 KiB
TypeScript
Raw Normal View History

2025-01-25 02:02:18 -05:00
import { TemplateOptions } from './types';
import QuestionContainer from './QuestionContainerTemplate';
import Title from './TitleTemplate';
import {textType} from './TextTypeTemplate';
import GlobalFeedback from './GlobalFeedbackTemplate';
2024-03-29 20:08:34 -04:00
import { ParagraphStyle, InputStyle } from '../constants';
import { state } from './index';
2025-01-25 02:02:18 -05:00
import { ShortAnswerQuestion } from 'gift-pegjs';
2024-03-29 20:08:34 -04:00
2025-01-25 02:02:18 -05:00
type ShortAnswerOptions = TemplateOptions & ShortAnswerQuestion;
type AnswerOptions = TemplateOptions & Pick<ShortAnswerQuestion, 'choices'>;
2024-03-29 20:08:34 -04:00
2025-01-25 02:02:18 -05:00
export default function ShortAnswerTemplate({
2024-03-29 20:08:34 -04:00
title,
2025-01-25 02:02:18 -05:00
formattedStem,
2024-03-29 20:08:34 -04:00
choices,
2025-01-25 02:02:18 -05:00
formattedGlobalFeedback
2024-03-29 20:08:34 -04:00
}: ShortAnswerOptions): string {
return `${QuestionContainer({
children: [
Title({
type: 'Réponse courte',
title: title
}),
2025-01-25 02:02:18 -05:00
`<p style="${ParagraphStyle(state.theme)}">${textType(formattedStem)}</p>`,
2024-03-29 20:08:34 -04:00
Answers({ choices: choices }),
2025-01-25 02:02:18 -05:00
formattedGlobalFeedback ? GlobalFeedback(formattedGlobalFeedback) : ''
2024-03-29 20:08:34 -04:00
]
})}`;
}
function Answers({ choices }: AnswerOptions): string {
const placeholder = choices
2025-01-25 02:02:18 -05:00
.map(({ text }) => textType({ format: '', text: text }))
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>
`;
}