@instructure/quiz-interactions
Version:
A React UI component Library for quiz interaction types.
158 lines • 6.17 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 _MatchEdit;
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 RemoveChoiceButton from '../../../common/edit/components/RemoveChoiceButton';
import { toErrors } from '../../../../util/instUIMessages';
import t from '@instructure/quiz-i18n/es/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) {
function MatchEdit() {
var _this2;
_classCallCheck(this, MatchEdit);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this2 = _callSuper(this, MatchEdit, [].concat(args));
// =============
// HANDLERS
// =============
_defineProperty(_this2, "handleAnswerChange", function (event) {
_this2.props.editAnswer(_this2.props.questionId, event.target.value);
});
_defineProperty(_this2, "handleAnswerBlur", function (event) {
_this2.props.editAnswer(_this2.props.questionId, event.target.value.trim());
});
_defineProperty(_this2, "handleQuestionChange", function (event) {
_this2.props.editQuestion(_this2.props.questionId, event.target.value);
});
_defineProperty(_this2, "handleQuestionBlur", function (event) {
_this2.props.editQuestion(_this2.props.questionId, event.target.value.trim());
});
_defineProperty(_this2, "handleRemoveMatch", function () {
_this2.props.removeMatch(_this2.props.questionId);
});
// =============
// RENDERS
// =============
_defineProperty(_this2, "renderLabel", function (label, screenReaderContent) {
return jsx(View, null, jsx(ScreenReaderContent, null, screenReaderContent), jsx(Text, {
"aria-hidden": "true"
}, label));
});
return _this2;
}
_inherits(MatchEdit, _Component);
return _createClass(MatchEdit, [{
key: "render",
value: function render() {
var _this$props = this.props,
hasOnlyOneMatch = _this$props.hasOnlyOneMatch,
questionBody = _this$props.questionBody,
answerBody = _this$props.answerBody;
return jsx(Flex, {
direction: "row",
"data-role": "questionWrapper",
width: '100%',
justifyItems: "space-between",
alignItems: "start"
}, jsx(Flex.Item, {
shouldGrow: true
}, 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"
})), jsx(Flex.Item, {
as: "div",
shouldGrow: true
}, jsx("hr", {
css: {
marginTop: '48px'
}
})), jsx(Flex.Item, {
shouldGrow: true
}, jsx(Flex, {
direction: "row",
width: "100%",
alignItems: "start",
gap: "small"
}, jsx(Flex.Item, {
shouldGrow: true
}, 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 && jsx(Flex.Item, null, jsx(View, {
as: "div",
margin: "xx-large 0 0 0",
themeOverride: {
marginXxLarge: '30px'
}
}, 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"
}))))));
}
}]);
}(Component);
_MatchEdit = MatchEdit;
_defineProperty(MatchEdit, "displayName", 'MatchEdit');
_defineProperty(MatchEdit, "componentId", "Quizzes".concat(_MatchEdit.displayName));
_defineProperty(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
});
_defineProperty(MatchEdit, "defaultProps", {
disabled: false
});
export { MatchEdit as default };