@instructure/quiz-interactions
Version:
A React UI component Library for quiz interaction types.
114 lines (113 loc) • 5.32 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 _emotion = require("@instructure/emotion");
var _uiText = require("@instructure/ui-text");
var _DropTargetContainer = _interopRequireDefault(require("../DropTargetContainer"));
var _Pill = _interopRequireDefault(require("../Pill"));
var _styles = _interopRequireDefault(require("./styles"));
var _theme = _interopRequireDefault(require("./theme"));
var _formatMessage = _interopRequireDefault(require("@instructure/quiz-i18n/es/format-message"));
var _quizCommon = require("@instructure/quiz-common");
var _dec, _class, _ChoicesList;
/** @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 ChoicesList = exports["default"] = (_dec = (0, _quizCommon.withStyleOverrides)(_styles["default"], _theme["default"]), _dec(_class = (_ChoicesList = /*#__PURE__*/function (_Component) {
function ChoicesList() {
var _this2;
(0, _classCallCheck2["default"])(this, ChoicesList);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this2 = _callSuper(this, ChoicesList, [].concat(args));
(0, _defineProperty2["default"])(_this2, "renderChoices", function () {
return (0, _emotion.jsx)("div", {
className: "choicesBackground",
css: _this2.props.styles.choicesBackground
}, _this2.props.distractors.map(function (item) {
var id = "".concat(item.id, "_").concat(_this2.props.takeId);
return (0, _emotion.jsx)(_Pill["default"], {
key: item.id,
id: id,
itemBody: item.itemBody,
isDraggable: _this2.props.isDraggable,
actionsContent: _this2.props.actionsContent
});
}));
});
return _this2;
}
(0, _inherits2["default"])(ChoicesList, _Component);
return (0, _createClass2["default"])(ChoicesList, [{
key: "renderChoicesContainer",
value: function renderChoicesContainer() {
if (!this.props.distractors.length) {
return (0, _emotion.jsx)("div", {
className: "fs-mask",
css: this.props.styles.emptyContainer
}, (0, _emotion.jsx)(_uiText.Text, {
color: "secondary"
}, (0, _formatMessage["default"])('Drag Uncategorized Answers Here')));
}
if (this.props.isDraggable) {
return (0, _emotion.jsx)(_DropTargetContainer["default"], {
onDrop: this.props.onDrop,
className: "fs-mask",
css: this.props.styles.choicesContainer
}, this.renderChoices());
}
return (0, _emotion.jsx)("div", {
className: "fs-mask",
css: this.props.styles.choicesContainer
}, this.renderChoices());
}
}, {
key: "render",
value: function render() {
return (0, _emotion.jsx)("div", {
css: this.props.styles.mainContainer
}, (0, _emotion.jsx)(_uiText.Text, {
color: "primary"
}, (0, _formatMessage["default"])('Possible answers')), this.renderChoicesContainer());
}
}]);
}(_react.Component), (0, _defineProperty2["default"])(_ChoicesList, "displayName", 'ChoicesList'), (0, _defineProperty2["default"])(_ChoicesList, "componentId", "Quizzes".concat(_ChoicesList.displayName)), (0, _defineProperty2["default"])(_ChoicesList, "propTypes", {
actionsContent: _propTypes["default"].func,
distractors: _propTypes["default"].arrayOf(_propTypes["default"].shape({
id: _propTypes["default"].string.isRequired,
itemBody: _propTypes["default"].string.isRequired
})).isRequired,
isDraggable: _propTypes["default"].bool,
onDrop: _propTypes["default"].func,
takeId: _propTypes["default"].string,
styles: _propTypes["default"].object
}), (0, _defineProperty2["default"])(_ChoicesList, "defaultProps", {
actionsContent: void 0,
isDraggable: void 0,
onDrop: void 0,
takeId: ''
}), _ChoicesList)) || _class);