@instructure/quiz-interactions
Version:
A React UI component Library for quiz interaction types.
174 lines • 7.23 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, _OrderGroup;
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 { 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/es/format-message';
import { v4 as uuid } from 'uuid';
import { TextInput, withStyleOverrides } from '@instructure/quiz-common';
var OrderGroup = (_dec = withStyleOverrides(generateStyle, generateComponentTheme), _dec(_class = (_OrderGroup = /*#__PURE__*/function (_Component) {
function OrderGroup() {
var _this2;
_classCallCheck(this, OrderGroup);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this2 = _callSuper(this, OrderGroup, [].concat(args));
_defineProperty(_this2, "takeId", uuid());
// ===========
// RENDER
// ===========
_defineProperty(_this2, "renderActions", function (choiceId, isFinalChoice, isFirstChoice, choicePosition) {
if (_this2.props.actionsContent) {
return _this2.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
jsx("div", null, jsx(IconButton, {
size: "small",
withBackground: false,
withBorder: false,
readOnly: _this2.props.readOnly,
renderIcon: IconDragHandleLine,
screenReaderLabel: t('Reorder Choice')
}))
);
});
_defineProperty(_this2, "renderChoice", function (choiceId, index) {
var choicePosition = index + 1;
var isFirstChoice = index === 0;
var isFinalChoice = choicePosition === _this2.props.choiceOrder.length;
return jsx("div", {
key: choiceId,
css: _this2.props.styles.choiceContainer,
"data-testid": "choice-cointainer"
}, jsx("div", {
css: _this2.props.styles.choiceContainerContent
}, !_this2.props.displayAnswersParagraph && jsx("div", {
css: _this2.props.styles.choicePosition
}, jsx(ScreenReaderContent, null, t('position {position, number}', {
position: choicePosition
})), jsx(PresentationContent, null, jsx(Text, {
color: "primary"
}, t.number(choicePosition)))), jsx("div", {
css: _this2.props.styles.printedPositionInput
}, jsx(TextInput, {
width: "3rem",
defaultValue: _this2.props.readOnly ? t.number(choicePosition) : '',
renderLabel: "",
readOnly: true
})), jsx("div", {
css: _this2.props.styles.choice,
className: "fs-mask"
}, _this2.renderActions(choiceId, isFinalChoice, isFirstChoice, choicePosition), jsx(RichContentRenderer, {
customStyles: _this2.props.styles.choiceBody,
content: _this2.props.choices[choiceId.split('_')[0]].itemBody
}))));
});
return _this2;
}
_inherits(OrderGroup, _Component);
return _createClass(OrderGroup, [{
key: "componentDidMount",
value: function componentDidMount() {
this.props.makeStyles();
}
}, {
key: "componentDidUpdate",
value: function componentDidUpdate() {
this.props.makeStyles();
}
}, {
key: "renderChoicesContainer",
value: function renderChoicesContainer() {
var _this3 = this;
if (this.props.readOnly) {
return jsx("div", {
css: this.props.styles.container
}, this.props.choiceOrder.map(this.renderChoice));
}
return jsx("div", {
css: this.props.styles.container
}, this.props.choiceOrder.map(function (choiceId, i) {
var id = "".concat(choiceId, "_").concat(_this3.takeId);
return jsx(Card, {
key: choiceId,
index: i,
id: id,
choices: _this3.props.choices,
moveCard: _this3.props.onMoveChoice
}, _this3.renderChoice(id, i));
}));
}
}, {
key: "render",
value: function render() {
return jsx("div", null, this.props.includeLabels && jsx("div", {
css: this.props.styles.topLabel,
"data-automation": "sdk-ordering-toplabel"
}, jsx(ScreenReaderContent, null, t('Top label: {label}', {
label: this.props.topLabel
})), jsx(PresentationContent, null, jsx(Text, {
color: "primary"
}, this.props.topLabel))), this.renderChoicesContainer(), this.props.includeLabels && jsx("div", {
css: this.props.styles.bottomLabel,
"data-automation": "sdk-ordering-bottomlabel"
}, jsx(ScreenReaderContent, null, t('Bottom label: {label}', {
label: this.props.bottomLabel
})), jsx(PresentationContent, null, jsx(Text, {
color: "primary"
}, this.props.bottomLabel))));
}
}]);
}(Component), _defineProperty(_OrderGroup, "displayName", 'OrderGroup'), _defineProperty(_OrderGroup, "componentId", "Quizzes".concat(_OrderGroup.displayName)), _defineProperty(_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
}), _defineProperty(_OrderGroup, "defaultProps", {
bottomLabel: void 0,
topLabel: void 0,
actionsContent: void 0,
displayAnswersParagraph: void 0,
includeLabels: void 0,
onMoveChoice: void 0,
readOnly: false
}), _OrderGroup)) || _class);
export { OrderGroup as default };