@instructure/quiz-interactions
Version:
A React UI component Library for quiz interaction types.
119 lines • 4.72 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
var _dec, _class, _Match;
function _callSuper(_this, derived, args) {
function isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
return !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
} catch (e) {
return false;
}
}
derived = _getPrototypeOf(derived);
return _possibleConstructorReturn(_this, isNativeReflectConstruct() ? Reflect.construct(derived, args || [], _getPrototypeOf(_this).constructor) : derived.apply(_this, args));
}
/** @jsx jsx */
import { Component } from 'react';
import PropTypes from 'prop-types';
import find from 'lodash/fp/find';
import { jsx } from '@instructure/emotion';
import { ScreenReaderContent } from '@instructure/ui-a11y-content';
import { Text } from '@instructure/ui-text';
import MatchSelect from './MatchSelect';
import { ItemBodyWrapper } from '@instructure/quiz-rce';
import ChoicesList from '../../categorization/common/ChoicesList';
import generateStyle from './styles';
import generateComponentTheme from './theme';
import t from '@instructure/quiz-i18n/es/format-message';
import { withStyleOverrides } from '@instructure/quiz-common';
var Match = (_dec = withStyleOverrides(generateStyle, generateComponentTheme), _dec(_class = (_Match = /*#__PURE__*/function (_Component) {
function Match() {
_classCallCheck(this, Match);
return _callSuper(this, Match, arguments);
}
_inherits(Match, _Component);
return _createClass(Match, [{
key: "renderQuestion",
value: function renderQuestion(questionId, index) {
var _find = find({
id: questionId
}, this.props.interactionData.questions),
itemBody = _find.itemBody;
return jsx("div", {
css: this.props.styles.item,
key: questionId
}, jsx("div", {
css: this.props.styles.question,
"data-testid": "question"
}, jsx(ScreenReaderContent, null, t('Prompt {index, number}', {
index: index
})), jsx(Text, {
color: "primary"
}, itemBody)), jsx("div", {
css: this.props.styles.divider
}), jsx("div", {
css: this.props.styles.answer,
className: "fs-mask"
}, jsx(MatchSelect, {
handleResponseUpdate: this.props.handleResponseUpdate,
selectedAnswers: this.props.selectedAnswers,
interaction: this.props.readOnly ? 'readonly' : 'enabled',
options: this.props.interactionData.answers,
questionId: questionId,
renderLabel: jsx(ScreenReaderContent, null, t('Answer for prompt {index, number} {prompt}', {
index: index,
prompt: itemBody
}))
})));
}
}, {
key: "render",
value: function render() {
var _this2 = this;
var distractors = this.props.interactionData.answers.map(function (answer) {
return {
id: answer,
itemBody: answer
};
});
return jsx(ItemBodyWrapper, {
itemBody: this.props.itemBody
}, jsx("div", {
css: this.props.styles.itemsList
}, this.props.interactionData.questions.map(function (_ref, index) {
var id = _ref.id;
return _this2.renderQuestion(id, index + 1);
})), jsx("div", {
css: this.props.styles.choicesList
}, jsx(ChoicesList, {
distractors: distractors
})));
}
}]);
}(Component), _defineProperty(_Match, "displayName", 'Match'), _defineProperty(_Match, "componentId", "Quizzes".concat(_Match.displayName)), _defineProperty(_Match, "propTypes", {
handleResponseUpdate: PropTypes.func,
interactionData: PropTypes.shape({
questions: PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.string,
itemBody: PropTypes.string
})),
answers: PropTypes.arrayOf(PropTypes.string)
}).isRequired,
itemBody: PropTypes.string.isRequired,
selectedAnswers: PropTypes.shape({
value: PropTypes.objectOf(PropTypes.string)
}).isRequired,
readOnly: PropTypes.bool,
styles: PropTypes.object
}), _defineProperty(_Match, "defaultProps", {
handleResponseUpdate: void 0,
readOnly: false
}), _Match)) || _class);
export { Match as default };