@instructure/quiz-interactions
Version:
A React UI component Library for quiz interaction types.
123 lines • 4.77 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, _DraggableBlankChoice;
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 { DragSource } from 'react-dnd';
import { jsx } from '@instructure/emotion';
import { IconDragHandleLine } from '@instructure/ui-icons';
import { Text } from '@instructure/ui-text';
import { processNewMathInElem } from '@instructure/quiz-rce';
import generateStyle from './styles';
import generateComponentTheme from './theme';
import { withStyleOverrides } from '@instructure/quiz-common';
var DraggableBlankChoice = (_dec = withStyleOverrides(generateStyle, generateComponentTheme), _dec(_class = (_DraggableBlankChoice = /*#__PURE__*/function (_Component) {
function DraggableBlankChoice() {
var _this2;
_classCallCheck(this, DraggableBlankChoice);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this2 = _callSuper(this, DraggableBlankChoice, [].concat(args));
_defineProperty(_this2, "choiceRef", null);
_defineProperty(_this2, "handleChoiceRef", function (node) {
_this2.choiceRef = node;
});
return _this2;
}
_inherits(DraggableBlankChoice, _Component);
return _createClass(DraggableBlankChoice, [{
key: "componentDidMount",
value: function componentDidMount() {
this.props.makeStyles();
processNewMathInElem(this.choiceRef);
}
}, {
key: "componentDidUpdate",
value: function componentDidUpdate() {
this.props.makeStyles();
processNewMathInElem(this.choiceRef);
}
}, {
key: "render",
value: function render() {
var _this$props = this.props,
canDrag = _this$props.canDrag,
itemBody = _this$props.itemBody,
connectDragSource = _this$props.connectDragSource,
styles = _this$props.styles;
if (canDrag) {
return connectDragSource(jsx("div", null, jsx("div", {
css: styles.choice,
ref: this.handleChoiceRef
}, jsx(IconDragHandleLine, null), jsx(Text, {
color: "primary"
}, itemBody))));
} else {
return jsx("div", null, jsx("div", {
css: styles.choice,
ref: this.handleChoiceRef
}, jsx(Text, {
color: "primary"
}, itemBody)));
}
}
}]);
}(Component), _defineProperty(_DraggableBlankChoice, "displayName", 'DraggableBlankChoice'), _defineProperty(_DraggableBlankChoice, "componentId", "Quizzes".concat(_DraggableBlankChoice.displayName)), _defineProperty(_DraggableBlankChoice, "propTypes", {
id: PropTypes.string,
itemBody: PropTypes.string,
connectDragSource: PropTypes.func.isRequired,
// injected by React DnD
handleDrop: PropTypes.func,
returnChoiceToWordbank: PropTypes.func,
printOnly: PropTypes.bool,
canDrag: PropTypes.bool,
makeStyles: PropTypes.func,
styles: PropTypes.object
}), _defineProperty(_DraggableBlankChoice, "defaultProps", {
id: void 0,
itemBody: void 0,
handleDrop: void 0,
returnChoiceToWordbank: void 0,
printOnly: false,
canDrag: true
}), _DraggableBlankChoice)) || _class);
var dragSource = {
beginDrag: function beginDrag(props, monitor, component) {
return {
id: props.id,
itemBody: props.itemBody
};
},
endDrag: function endDrag(props, monitor) {
// if dropped outside of a BlankDropTarget, return to wordbank
if (!monitor.didDrop() && props.returnChoiceToWordbank) {
props.returnChoiceToWordbank(props.id);
}
}
};
function collectDrag(connect, monitor) {
return {
connectDragSource: connect.dragSource()
};
}
export default DragSource('fitb', dragSource, collectDrag)(DraggableBlankChoice);