@instructure/quiz-interactions
Version:
A React UI component Library for quiz interaction types.
130 lines (129 loc) • 5.66 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 _reactDnd = require("react-dnd");
var _emotion = require("@instructure/emotion");
var _uiIcons = require("@instructure/ui-icons");
var _uiText = require("@instructure/ui-text");
var _quizRce = require("@instructure/quiz-rce");
var _styles = _interopRequireDefault(require("./styles"));
var _theme = _interopRequireDefault(require("./theme"));
var _quizCommon = require("@instructure/quiz-common");
var _dec, _class, _DraggableBlankChoice;
/** @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 DraggableBlankChoice = (_dec = (0, _quizCommon.withStyleOverrides)(_styles["default"], _theme["default"]), _dec(_class = (_DraggableBlankChoice = /*#__PURE__*/function (_Component) {
function DraggableBlankChoice() {
var _this2;
(0, _classCallCheck2["default"])(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));
(0, _defineProperty2["default"])(_this2, "choiceRef", null);
(0, _defineProperty2["default"])(_this2, "handleChoiceRef", function (node) {
_this2.choiceRef = node;
});
return _this2;
}
(0, _inherits2["default"])(DraggableBlankChoice, _Component);
return (0, _createClass2["default"])(DraggableBlankChoice, [{
key: "componentDidMount",
value: function componentDidMount() {
this.props.makeStyles();
(0, _quizRce.processNewMathInElem)(this.choiceRef);
}
}, {
key: "componentDidUpdate",
value: function componentDidUpdate() {
this.props.makeStyles();
(0, _quizRce.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((0, _emotion.jsx)("div", null, (0, _emotion.jsx)("div", {
css: styles.choice,
ref: this.handleChoiceRef
}, (0, _emotion.jsx)(_uiIcons.IconDragHandleLine, null), (0, _emotion.jsx)(_uiText.Text, {
color: "primary"
}, itemBody))));
} else {
return (0, _emotion.jsx)("div", null, (0, _emotion.jsx)("div", {
css: styles.choice,
ref: this.handleChoiceRef
}, (0, _emotion.jsx)(_uiText.Text, {
color: "primary"
}, itemBody)));
}
}
}]);
}(_react.Component), (0, _defineProperty2["default"])(_DraggableBlankChoice, "displayName", 'DraggableBlankChoice'), (0, _defineProperty2["default"])(_DraggableBlankChoice, "componentId", "Quizzes".concat(_DraggableBlankChoice.displayName)), (0, _defineProperty2["default"])(_DraggableBlankChoice, "propTypes", {
id: _propTypes["default"].string,
itemBody: _propTypes["default"].string,
connectDragSource: _propTypes["default"].func.isRequired,
// injected by React DnD
handleDrop: _propTypes["default"].func,
returnChoiceToWordbank: _propTypes["default"].func,
printOnly: _propTypes["default"].bool,
canDrag: _propTypes["default"].bool,
makeStyles: _propTypes["default"].func,
styles: _propTypes["default"].object
}), (0, _defineProperty2["default"])(_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()
};
}
var _default = exports["default"] = (0, _reactDnd.DragSource)('fitb', dragSource, collectDrag)(DraggableBlankChoice);