UNPKG

@instructure/quiz-interactions

Version:

A React UI component Library for quiz interaction types.

57 lines (49 loc) 1.62 kB
import React from 'react' import {rule, onSelf} from 'instructure-validations' import {Text} from '@instructure/ui-text' import {RichContentRenderer} from '@instructure/quiz-rce/components/RichContentRenderer/index' import InteractionType from '../InteractionType' import {ESSAY_SLUG} from '../../interaction_slugs' import t from '@instructure/quiz-i18n/format-message' export default class EssayInteractionType extends InteractionType { constructor(obj) { super() super.initializeProps(obj) } slug = ESSAY_SLUG translatedName = t('Essay') isSubjective = true getDefaultScoringData = intData => ({value: ''}) getDefaultInteractionData = () => ({ essay: null, rce: true, spellCheck: false, wordCount: false, wordLimitEnabled: false, wordLimitMax: null, wordLimitMin: null, fileUpload: false, }) getRenderedResponse = (responseValue, interactionData) => { if (interactionData.rce) { return <RichContentRenderer content={responseValue} /> } return <Text color="primary">{responseValue}</Text> } static validations() { return { interactionData: [ onSelf( rule('boundaries', { enableKey: 'wordLimitEnabled', minKey: 'wordLimitMin', maxKey: 'wordLimitMax', presenceMessage: t('Both minimum and maximum word limits cannot be blank'), numberMessage: t('Both minimum and maximum word limit values must be integers'), rangeMessage: t('Minimum word limit must be less than maximum word limit'), }), ), ], } } }