@instructure/quiz-interactions
Version:
A React UI component Library for quiz interaction types.
114 lines (113 loc) • 4.24 kB
JavaScript
/** @jsx jsx */ function _array_like_to_array(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
return arr2;
}
function _array_with_holes(arr) {
if (Array.isArray(arr)) return arr;
}
function _iterable_to_array_limit(arr, i) {
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
if (_i == null) return;
var _arr = [];
var _n = true;
var _d = false;
var _s, _e;
try {
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally{
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally{
if (_d) throw _e;
}
}
return _arr;
}
function _non_iterable_rest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _sliced_to_array(arr, i) {
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
}
function _unsupported_iterable_to_array(o, minLen) {
if (!o) return;
if (typeof o === "string") return _array_like_to_array(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(n);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
}
import { useEffect, useRef } from 'react';
import PropTypes from 'prop-types';
import { useDrag } 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/components/RichContentRenderer/mathRenderer';
import generateStyle from './styles';
import generateComponentTheme from './theme';
import { withStyleOverrides } from '@instructure/quiz-common/util/withStyleOverrides';
function DraggableBlankChoice(props) {
var canDrag = props.canDrag, id = props.id, itemBody = props.itemBody, returnChoiceToWordbank = props.returnChoiceToWordbank, makeStyles = props.makeStyles, styles = props.styles;
var choiceRef = useRef(null);
var _useDrag = _sliced_to_array(useDrag(function() {
return {
type: 'fitb',
item: {
id: id,
itemBody: itemBody
},
canDrag: canDrag,
end: function(draggedItem, monitor) {
if (!monitor.didDrop() && returnChoiceToWordbank) {
returnChoiceToWordbank(draggedItem.id);
}
}
};
}, [
id,
itemBody,
canDrag,
returnChoiceToWordbank
]), 2), drag = _useDrag[1];
useEffect(function() {
makeStyles();
processNewMathInElem(choiceRef.current);
});
return /*#__PURE__*/ jsx("div", {
ref: drag
}, /*#__PURE__*/ jsx("div", {
css: styles.choice,
ref: choiceRef
}, canDrag && /*#__PURE__*/ jsx(IconDragHandleLine, null), /*#__PURE__*/ jsx(Text, {
color: "primary"
}, itemBody)));
}
DraggableBlankChoice.displayName = 'DraggableBlankChoice';
DraggableBlankChoice.componentId = "Quizzes".concat(DraggableBlankChoice.displayName);
DraggableBlankChoice.propTypes = {
id: PropTypes.string,
itemBody: PropTypes.string,
handleDrop: PropTypes.func,
returnChoiceToWordbank: PropTypes.func,
printOnly: PropTypes.bool,
canDrag: PropTypes.bool,
makeStyles: PropTypes.func,
styles: PropTypes.object
};
DraggableBlankChoice.defaultProps = {
id: undefined,
itemBody: undefined,
handleDrop: undefined,
returnChoiceToWordbank: undefined,
printOnly: false,
canDrag: true
};
export default withStyleOverrides(generateStyle, generateComponentTheme)(DraggableBlankChoice);