@instructure/quiz-interactions
Version:
A React UI component Library for quiz interaction types.
180 lines (179 loc) • 8.68 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _react = require("react");
var _propTypes = _interopRequireDefault(require("prop-types"));
var _uiButtons = require("@instructure/ui-buttons");
var _uiIcons = require("@instructure/ui-icons");
var _uiA11yContent = require("@instructure/ui-a11y-content");
var _uiText = require("@instructure/ui-text");
var _emotion = require("@instructure/emotion");
var _quizRce = require("@instructure/quiz-rce");
var _Card = _interopRequireDefault(require("../../../common/components/Card"));
var _styles = _interopRequireDefault(require("./styles"));
var _theme = _interopRequireDefault(require("./theme"));
var _formatMessage = _interopRequireDefault(require("@instructure/quiz-i18n/es/format-message"));
var _uuid = require("uuid");
var _quizCommon = require("@instructure/quiz-common");
var _dec, _class, _OrderGroup;
/** @jsx jsx */
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 = (0, _getPrototypeOf2["default"])(derived);
return (0, _possibleConstructorReturn2["default"])(_this, isNativeReflectConstruct() ? Reflect.construct(derived, args || [], (0, _getPrototypeOf2["default"])(_this).constructor) : derived.apply(_this, args));
}
var OrderGroup = exports["default"] = (_dec = (0, _quizCommon.withStyleOverrides)(_styles["default"], _theme["default"]), _dec(_class = (_OrderGroup = /*#__PURE__*/function (_Component) {
function OrderGroup() {
var _this2;
(0, _classCallCheck2["default"])(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));
(0, _defineProperty2["default"])(_this2, "takeId", (0, _uuid.v4)());
// ===========
// RENDER
// ===========
(0, _defineProperty2["default"])(_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
(0, _emotion.jsx)("div", null, (0, _emotion.jsx)(_uiButtons.IconButton, {
size: "small",
withBackground: false,
withBorder: false,
readOnly: _this2.props.readOnly,
renderIcon: _uiIcons.IconDragHandleLine,
screenReaderLabel: (0, _formatMessage["default"])('Reorder Choice')
}))
);
});
(0, _defineProperty2["default"])(_this2, "renderChoice", function (choiceId, index) {
var choicePosition = index + 1;
var isFirstChoice = index === 0;
var isFinalChoice = choicePosition === _this2.props.choiceOrder.length;
return (0, _emotion.jsx)("div", {
key: choiceId,
css: _this2.props.styles.choiceContainer,
"data-testid": "choice-cointainer"
}, (0, _emotion.jsx)("div", {
css: _this2.props.styles.choiceContainerContent
}, !_this2.props.displayAnswersParagraph && (0, _emotion.jsx)("div", {
css: _this2.props.styles.choicePosition
}, (0, _emotion.jsx)(_uiA11yContent.ScreenReaderContent, null, (0, _formatMessage["default"])('position {position, number}', {
position: choicePosition
})), (0, _emotion.jsx)(_uiA11yContent.PresentationContent, null, (0, _emotion.jsx)(_uiText.Text, {
color: "primary"
}, _formatMessage["default"].number(choicePosition)))), (0, _emotion.jsx)("div", {
css: _this2.props.styles.printedPositionInput
}, (0, _emotion.jsx)(_quizCommon.TextInput, {
width: "3rem",
defaultValue: _this2.props.readOnly ? _formatMessage["default"].number(choicePosition) : '',
renderLabel: "",
readOnly: true
})), (0, _emotion.jsx)("div", {
css: _this2.props.styles.choice,
className: "fs-mask"
}, _this2.renderActions(choiceId, isFinalChoice, isFirstChoice, choicePosition), (0, _emotion.jsx)(_quizRce.RichContentRenderer, {
customStyles: _this2.props.styles.choiceBody,
content: _this2.props.choices[choiceId.split('_')[0]].itemBody
}))));
});
return _this2;
}
(0, _inherits2["default"])(OrderGroup, _Component);
return (0, _createClass2["default"])(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 (0, _emotion.jsx)("div", {
css: this.props.styles.container
}, this.props.choiceOrder.map(this.renderChoice));
}
return (0, _emotion.jsx)("div", {
css: this.props.styles.container
}, this.props.choiceOrder.map(function (choiceId, i) {
var id = "".concat(choiceId, "_").concat(_this3.takeId);
return (0, _emotion.jsx)(_Card["default"], {
key: choiceId,
index: i,
id: id,
choices: _this3.props.choices,
moveCard: _this3.props.onMoveChoice
}, _this3.renderChoice(id, i));
}));
}
}, {
key: "render",
value: function render() {
return (0, _emotion.jsx)("div", null, this.props.includeLabels && (0, _emotion.jsx)("div", {
css: this.props.styles.topLabel,
"data-automation": "sdk-ordering-toplabel"
}, (0, _emotion.jsx)(_uiA11yContent.ScreenReaderContent, null, (0, _formatMessage["default"])('Top label: {label}', {
label: this.props.topLabel
})), (0, _emotion.jsx)(_uiA11yContent.PresentationContent, null, (0, _emotion.jsx)(_uiText.Text, {
color: "primary"
}, this.props.topLabel))), this.renderChoicesContainer(), this.props.includeLabels && (0, _emotion.jsx)("div", {
css: this.props.styles.bottomLabel,
"data-automation": "sdk-ordering-bottomlabel"
}, (0, _emotion.jsx)(_uiA11yContent.ScreenReaderContent, null, (0, _formatMessage["default"])('Bottom label: {label}', {
label: this.props.bottomLabel
})), (0, _emotion.jsx)(_uiA11yContent.PresentationContent, null, (0, _emotion.jsx)(_uiText.Text, {
color: "primary"
}, this.props.bottomLabel))));
}
}]);
}(_react.Component), (0, _defineProperty2["default"])(_OrderGroup, "displayName", 'OrderGroup'), (0, _defineProperty2["default"])(_OrderGroup, "componentId", "Quizzes".concat(_OrderGroup.displayName)), (0, _defineProperty2["default"])(_OrderGroup, "propTypes", {
bottomLabel: _propTypes["default"].string,
topLabel: _propTypes["default"].string,
choiceOrder: _propTypes["default"].arrayOf(_propTypes["default"].string).isRequired,
choices: _propTypes["default"].shape({
itemBody: _quizRce.RichContentRenderer.propTypes.content
}).isRequired,
actionsContent: _propTypes["default"].func,
displayAnswersParagraph: _propTypes["default"].bool,
includeLabels: _propTypes["default"].bool,
onMoveChoice: _propTypes["default"].func,
readOnly: _propTypes["default"].bool,
styles: _propTypes["default"].object,
makeStyles: _propTypes["default"].func
}), (0, _defineProperty2["default"])(_OrderGroup, "defaultProps", {
bottomLabel: void 0,
topLabel: void 0,
actionsContent: void 0,
displayAnswersParagraph: void 0,
includeLabels: void 0,
onMoveChoice: void 0,
readOnly: false
}), _OrderGroup)) || _class);