@instructure/quiz-interactions
Version:
A React UI component Library for quiz interaction types.
214 lines (213 loc) • 9.06 kB
JavaScript
/** @jsx jsx */ function _assert_this_initialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
function _call_super(_this, derived, args) {
derived = _get_prototype_of(derived);
return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
}
function _class_call_check(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _defineProperties(target, props) {
for(var i = 0; i < props.length; i++){
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _create_class(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
function _define_property(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _get_prototype_of(o) {
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _get_prototype_of(o);
}
function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function");
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
writable: true,
configurable: true
}
});
if (superClass) _set_prototype_of(subClass, superClass);
}
function _possible_constructor_return(self, call) {
if (call && (_type_of(call) === "object" || typeof call === "function")) {
return call;
}
return _assert_this_initialized(self);
}
function _set_prototype_of(o, p) {
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _set_prototype_of(o, p);
}
function _type_of(obj) {
"@swc/helpers - typeof";
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
}
function _is_native_reflect_construct() {
try {
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
} catch (_) {}
return (_is_native_reflect_construct = function() {
return !!result;
})();
}
import { Component } from 'react';
import PropTypes from 'prop-types';
import { jsx } from '@instructure/emotion';
import RemoveChoiceButton from '../../../common/edit/components/RemoveChoiceButton';
import { toErrors } from '../../../../util/instUIMessages';
import t from '@instructure/quiz-i18n/format-message';
import { View } from '@instructure/ui-view';
import { Text } from '@instructure/ui-text';
import { ScreenReaderContent } from '@instructure/ui-a11y-content';
import { TextInput, Flex } from '@instructure/quiz-common';
var MatchEdit = /*#__PURE__*/ function(Component) {
"use strict";
_inherits(MatchEdit, Component);
function MatchEdit() {
_class_call_check(this, MatchEdit);
var _this;
_this = _call_super(this, MatchEdit, arguments), // =============
// HANDLERS
// =============
_define_property(_this, "handleAnswerChange", function(event) {
_this.props.editAnswer(_this.props.questionId, event.target.value);
}), _define_property(_this, "handleAnswerBlur", function(event) {
_this.props.editAnswer(_this.props.questionId, event.target.value.trim());
}), _define_property(_this, "handleQuestionChange", function(event) {
_this.props.editQuestion(_this.props.questionId, event.target.value);
}), _define_property(_this, "handleQuestionBlur", function(event) {
_this.props.editQuestion(_this.props.questionId, event.target.value.trim());
}), _define_property(_this, "handleRemoveMatch", function() {
_this.props.removeMatch(_this.props.questionId);
}), // =============
// RENDERS
// =============
_define_property(_this, "renderLabel", function(label, screenReaderContent) {
return /*#__PURE__*/ jsx(View, null, /*#__PURE__*/ jsx(ScreenReaderContent, null, screenReaderContent), /*#__PURE__*/ jsx(Text, {
"aria-hidden": "true"
}, label));
});
return _this;
}
_create_class(MatchEdit, [
{
key: "render",
value: function render() {
var _this_props = this.props, hasOnlyOneMatch = _this_props.hasOnlyOneMatch, questionBody = _this_props.questionBody, answerBody = _this_props.answerBody;
return /*#__PURE__*/ jsx(Flex, {
direction: "row",
"data-role": "questionWrapper",
width: '100%',
justifyItems: "space-between",
alignItems: "start"
}, /*#__PURE__*/ jsx(Flex.Item, {
shouldGrow: true
}, /*#__PURE__*/ jsx(TextInput, {
renderLabel: this.renderLabel(t('Question'), t('Prompt {n, number} question', {
n: this.props.index + 1
})),
isRequired: true,
defaultValue: questionBody,
messages: toErrors(this.props.questionErrors),
onChange: this.handleQuestionChange,
onBlur: this.handleQuestionBlur,
"data-automation": "sdk-matching-question"
})), /*#__PURE__*/ jsx(Flex.Item, {
as: "div",
shouldGrow: true
}, /*#__PURE__*/ jsx("hr", {
css: {
marginTop: '48px'
}
})), /*#__PURE__*/ jsx(Flex.Item, {
shouldGrow: true
}, /*#__PURE__*/ jsx(Flex, {
direction: "row",
width: "100%",
alignItems: "start",
gap: "small"
}, /*#__PURE__*/ jsx(Flex.Item, {
shouldGrow: true
}, /*#__PURE__*/ jsx(TextInput, {
renderLabel: this.renderLabel(t('Answer'), t('Prompt {n, number} answer', {
n: this.props.index + 1
})),
isRequired: true,
defaultValue: answerBody,
messages: toErrors(this.props.answerErrors),
onChange: this.handleAnswerChange,
onBlur: this.handleAnswerBlur,
"data-automation": "sdk-matching-answer"
})), !hasOnlyOneMatch && !this.props.disabled && /*#__PURE__*/ jsx(Flex.Item, null, /*#__PURE__*/ jsx(View, {
as: "div",
margin: "xx-large 0 0 0",
themeOverride: {
marginXxLarge: '30px'
}
}, /*#__PURE__*/ jsx(RemoveChoiceButton, {
screenReaderText: t('Remove Question/Answer pair: {question} - {answer}', {
question: questionBody,
answer: answerBody
}),
onRemoveChoice: this.handleRemoveMatch,
choiceId: this.props.questionId,
"data-automation": "sdk-matching-delete"
}))))));
}
}
]);
return MatchEdit;
}(Component);
_define_property(MatchEdit, "displayName", 'MatchEdit');
_define_property(MatchEdit, "componentId", "Quizzes".concat(MatchEdit.displayName));
_define_property(MatchEdit, "propTypes", {
answerBody: PropTypes.string.isRequired,
answerErrors: PropTypes.array.isRequired,
disabled: PropTypes.bool,
editAnswer: PropTypes.func.isRequired,
editQuestion: PropTypes.func.isRequired,
hasOnlyOneMatch: PropTypes.bool.isRequired,
index: PropTypes.number.isRequired,
questionBody: PropTypes.string.isRequired,
questionErrors: PropTypes.array.isRequired,
questionId: PropTypes.string.isRequired,
removeMatch: PropTypes.func.isRequired
});
_define_property(MatchEdit, "defaultProps", {
disabled: false
});
export { MatchEdit as default };