@instructure/quiz-interactions
Version:
A React UI component Library for quiz interaction types.
194 lines (192 loc) • 6.89 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, _OrderingResult;
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 { jsx } from '@instructure/emotion';
import { Text } from '@instructure/ui-text';
import t from '@instructure/quiz-i18n/es/format-message';
import { ItemBodyWrapper, RichContentRenderer } from '@instructure/quiz-rce';
import { FeedbackWrapper, NoResponse } from '@instructure/quiz-results-feedback';
import generateStyle from './styles';
import generateComponentTheme from './theme';
import { withStyleOverrides } from '@instructure/quiz-common';
/**
---
category: Ordering
---
Ordering Result component
```jsx_example
<SettingsSwitcher locales={LOCALES}>
<OrderingResult
itemBody="Order these characters from tallest to shortest:"
interactionData={{
choices: {
uuid4: { id: 'uuid4', itemBody: '<p>Aragorn</p>' },
uuid3: { id: 'uuid3', itemBody: '<p>Gimli</p>' },
uuid2: { id: 'uuid2', itemBody: '<p>Frodo</p>' },
uuid1: { id: 'uuid1', itemBody: '<p>Gollum</p>' }
}
}}
properties={{
displayAnswersParagraph: true,
includeLabels: true,
topLabel: 'Taller',
bottomLabel: 'Shorter'
}}
scoredData={{
value: [{
userResponded: 'uuid3',
resultScore: 0,
value: 'uuid4'
}, {
userResponded: 'uuid4',
resultScore: 0,
value: 'uuid3'
}, {
userResponded: 'uuid2',
resultScore: 1,
value: 'uuid2'
}, {
userResponded: 'uuid1',
resultScore: 1,
value: 'uuid1'
}]
}}
/>
</SettingsSwitcher>
```
**/
var OrderingResult = (_dec = withStyleOverrides(generateStyle, generateComponentTheme), _dec(_class = (_OrderingResult = /*#__PURE__*/function (_Component) {
function OrderingResult() {
_classCallCheck(this, OrderingResult);
return _callSuper(this, OrderingResult, arguments);
}
_inherits(OrderingResult, _Component);
return _createClass(OrderingResult, [{
key: "componentDidMount",
value: function componentDidMount() {
this.props.makeStyles();
}
}, {
key: "componentDidUpdate",
value: function componentDidUpdate() {
this.props.makeStyles();
}
}, {
key: "renderLabel",
value: function renderLabel(labelPosition) {
var properties = this.props.properties;
if (properties.includeLabels) {
return jsx("div", {
className: labelPosition,
css: this.props.styles[labelPosition]
}, jsx(Text, {
color: "primary"
}, properties[labelPosition]));
}
}
}, {
key: "renderChoices",
value: function renderChoices() {
var _this2 = this;
var choices = this.props.interactionData.choices;
var _this$props$scoredDat = this.props.scoredData,
correct = _this$props$scoredDat.correct,
value = _this$props$scoredDat.value;
if (!value || value.length === 0) {
return jsx(NoResponse, {
responseHidden: !value,
status: typeof correct === 'undefined' ? 'unknown' : 'incorrect',
richContent: true
});
}
return value.map(function (answer, idx) {
var status;
if (answer.resultScore >= 1) {
status = 'correct';
} else if (answer.resultScore <= 0) {
status = 'incorrect';
} else {
status = 'unknown';
}
var userChoice = choices[answer.userResponded];
var correctAnswer = choices[answer.value] ? choices[answer.value].itemBody : null;
var key = "choice_".concat(idx);
return jsx("div", {
css: _this2.props.styles.feedbackWrapper,
key: key
}, userChoice ? jsx(FeedbackWrapper, {
hiddenCorrectAnswerText: t('Correct Order Answer: '),
hiddenIncorrectAnswerText: t('Incorrect Order Answer: '),
correctAnswer: correctAnswer,
status: status,
richContent: true
}, jsx(RichContentRenderer, {
customStyles: _this2.props.styles.userResponse,
content: userChoice.itemBody
})) : jsx(NoResponse, {
correctAnswerLabel: correctAnswer,
responseHidden: answer.userResponded === void 0,
status: status,
richContent: true
}));
});
}
}, {
key: "render",
value: function render() {
return jsx("div", {
css: this.props.styles.holder
}, jsx(ItemBodyWrapper, {
itemBody: this.props.itemBody
}, this.renderLabel('topLabel'), jsx("div", {
css: this.props.styles.choicesWrapper
}, this.renderChoices()), this.renderLabel('bottomLabel')));
}
}]);
}(Component), _defineProperty(_OrderingResult, "displayName", 'OrderingResult'), _defineProperty(_OrderingResult, "componentId", "Quizzes".concat(_OrderingResult.displayName)), _defineProperty(_OrderingResult, "propTypes", {
interactionData: PropTypes.shape({
choices: PropTypes.objectOf(PropTypes.shape({
id: PropTypes.string.isRequired,
itemBody: PropTypes.string.isRequired
})).isRequired
}).isRequired,
itemBody: PropTypes.string.isRequired,
properties: PropTypes.shape({
displayAnswersParagraph: PropTypes.bool,
includeLabels: PropTypes.bool,
topLabel: PropTypes.string,
bottomLabel: PropTypes.string
}).isRequired,
scoredData: PropTypes.shape({
correct: PropTypes.bool,
value: PropTypes.arrayOf(PropTypes.shape({
resultScore: PropTypes.number,
userResponded: PropTypes.string,
value: PropTypes.string
}))
}).isRequired,
makeStyles: PropTypes.func,
styles: PropTypes.object
}), _OrderingResult)) || _class);
export { OrderingResult as default };