@instructure/quiz-interactions
Version:
A React UI component Library for quiz interaction types.
251 lines (250 loc) • 10.8 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;
})();
}
function _ts_decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
import { Component } from 'react';
import PropTypes from 'prop-types';
import { IconButton } from '@instructure/ui-buttons';
import { IconDragHandleLine } from '@instructure/ui-icons';
import { ScreenReaderContent, PresentationContent } from '@instructure/ui-a11y-content';
import { Text } from '@instructure/ui-text';
import { jsx } from '@instructure/emotion';
import { RichContentRenderer } from '@instructure/quiz-rce';
import Card from '../../../common/components/Card';
import generateStyle from './styles';
import generateComponentTheme from './theme';
import t from '@instructure/quiz-i18n/format-message';
import { v4 as uuid } from 'uuid';
import { TextInput, withStyleOverrides } from '@instructure/quiz-common';
var OrderGroup = /*#__PURE__*/ function(Component) {
"use strict";
_inherits(OrderGroup, Component);
function OrderGroup() {
_class_call_check(this, OrderGroup);
var _this;
_this = _call_super(this, OrderGroup, arguments), _define_property(_this, "takeId", uuid()), // ===========
// RENDER
// ===========
_define_property(_this, "renderActions", function(choiceId, isFinalChoice, isFirstChoice, choicePosition) {
if (_this.props.actionsContent) {
return _this.props.actionsContent(choiceId, isFinalChoice, isFirstChoice, choicePosition);
}
return(// We need to wrap the button in a div for drag-and-drop to work in IE11 and Firefox
/*#__PURE__*/ jsx("div", null, /*#__PURE__*/ jsx(IconButton, {
size: "small",
withBackground: false,
withBorder: false,
readOnly: _this.props.readOnly,
renderIcon: IconDragHandleLine,
screenReaderLabel: t('Reorder Choice')
})));
}), _define_property(_this, "renderChoice", function(choiceId, index) {
var choicePosition = index + 1;
var isFirstChoice = index === 0;
var isFinalChoice = choicePosition === _this.props.choiceOrder.length;
return /*#__PURE__*/ jsx("div", {
key: choiceId,
css: _this.props.styles.choiceContainer,
"data-testid": "choice-cointainer"
}, /*#__PURE__*/ jsx("div", {
css: _this.props.styles.choiceContainerContent
}, !_this.props.displayAnswersParagraph && /*#__PURE__*/ jsx("div", {
css: _this.props.styles.choicePosition
}, /*#__PURE__*/ jsx(ScreenReaderContent, null, t('position {position, number}', {
position: choicePosition
})), /*#__PURE__*/ jsx(PresentationContent, null, /*#__PURE__*/ jsx(Text, {
color: "primary"
}, t.number(choicePosition)))), /*#__PURE__*/ jsx("div", {
css: _this.props.styles.printedPositionInput
}, /*#__PURE__*/ jsx(TextInput, {
width: "3rem",
defaultValue: _this.props.readOnly ? t.number(choicePosition) : '',
renderLabel: "",
readOnly: true
})), /*#__PURE__*/ jsx("div", {
css: _this.props.styles.choice,
className: "fs-mask"
}, _this.renderActions(choiceId, isFinalChoice, isFirstChoice, choicePosition), /*#__PURE__*/ jsx(RichContentRenderer, {
customStyles: _this.props.styles.choiceBody,
content: _this.props.choices[choiceId.split('_')[0]].itemBody
}))));
});
return _this;
}
_create_class(OrderGroup, [
{
key: "componentDidMount",
value: function componentDidMount() {
this.props.makeStyles();
}
},
{
key: "componentDidUpdate",
value: function componentDidUpdate() {
this.props.makeStyles();
}
},
{
key: "renderChoicesContainer",
value: function renderChoicesContainer() {
var _this = this;
if (this.props.readOnly) {
return /*#__PURE__*/ jsx("div", {
css: this.props.styles.container
}, this.props.choiceOrder.map(this.renderChoice));
}
return /*#__PURE__*/ jsx("div", {
css: this.props.styles.container
}, this.props.choiceOrder.map(function(choiceId, i) {
var id = "".concat(choiceId, "_").concat(_this.takeId);
return /*#__PURE__*/ jsx(Card, {
key: choiceId,
index: i,
id: id,
choices: _this.props.choices,
moveCard: _this.props.onMoveChoice
}, _this.renderChoice(id, i));
}));
}
},
{
key: "render",
value: function render() {
return /*#__PURE__*/ jsx("div", null, this.props.includeLabels && /*#__PURE__*/ jsx("div", {
css: this.props.styles.topLabel,
"data-automation": "sdk-ordering-toplabel"
}, /*#__PURE__*/ jsx(ScreenReaderContent, null, t('Top label: {label}', {
label: this.props.topLabel
})), /*#__PURE__*/ jsx(PresentationContent, null, /*#__PURE__*/ jsx(Text, {
color: "primary"
}, this.props.topLabel))), this.renderChoicesContainer(), this.props.includeLabels && /*#__PURE__*/ jsx("div", {
css: this.props.styles.bottomLabel,
"data-automation": "sdk-ordering-bottomlabel"
}, /*#__PURE__*/ jsx(ScreenReaderContent, null, t('Bottom label: {label}', {
label: this.props.bottomLabel
})), /*#__PURE__*/ jsx(PresentationContent, null, /*#__PURE__*/ jsx(Text, {
color: "primary"
}, this.props.bottomLabel))));
}
}
]);
return OrderGroup;
}(Component);
_define_property(OrderGroup, "displayName", 'OrderGroup');
_define_property(OrderGroup, "componentId", "Quizzes".concat(OrderGroup.displayName));
_define_property(OrderGroup, "propTypes", {
bottomLabel: PropTypes.string,
topLabel: PropTypes.string,
choiceOrder: PropTypes.arrayOf(PropTypes.string).isRequired,
choices: PropTypes.shape({
itemBody: RichContentRenderer.propTypes.content
}).isRequired,
actionsContent: PropTypes.func,
displayAnswersParagraph: PropTypes.bool,
includeLabels: PropTypes.bool,
onMoveChoice: PropTypes.func,
readOnly: PropTypes.bool,
styles: PropTypes.object,
makeStyles: PropTypes.func
});
_define_property(OrderGroup, "defaultProps", {
bottomLabel: void 0,
topLabel: void 0,
actionsContent: void 0,
displayAnswersParagraph: void 0,
includeLabels: void 0,
onMoveChoice: void 0,
readOnly: false
});
export { OrderGroup as default };
OrderGroup = _ts_decorate([
withStyleOverrides(generateStyle, generateComponentTheme)
], OrderGroup);