UNPKG

@instructure/quiz-taking

Version:

118 lines 5.16 kB
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, _TakingSidebarItem; 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 ImmutablePropTypes from 'react-immutable-proptypes'; import { jsx } from '@instructure/emotion'; import t from '@instructure/quiz-i18n/es/format-message'; import { SidebarItem as CommonSidebarItem, Pin } from '@instructure/quiz-core'; import generateStyle from './styles'; import generateComponentTheme from './theme'; import { withStyleOverrides } from '@instructure/quiz-common'; export var TakingSidebarItem = (_dec = withStyleOverrides(generateStyle, generateComponentTheme), _dec(_class = (_TakingSidebarItem = /*#__PURE__*/function (_Component) { function TakingSidebarItem() { var _this2; _classCallCheck(this, TakingSidebarItem); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this2 = _callSuper(this, TakingSidebarItem, [].concat(args)); _defineProperty(_this2, "pinSessionItem", function (isPinned) { return function () { var _this2$props = _this2.props, pinSessionItem = _this2$props.pinSessionItem, quizSession = _this2$props.quizSession, position = _this2$props.position, screenreaderNotification = _this2$props.screenreaderNotification; var confirmationMessage = isPinned ? t('Question unpinned') : t('Question pinned'); pinSessionItem(quizSession.id, position).then(function () { screenreaderNotification(confirmationMessage); }); }; }); return _this2; } _inherits(TakingSidebarItem, _Component); return _createClass(TakingSidebarItem, [{ key: "renderPin", value: function renderPin() { var _this$props = this.props, isPinned = _this$props.isPinned, position = _this$props.position; return jsx(Pin, { isPinned: isPinned, pinSessionItem: this.pinSessionItem(isPinned), position: position }); } }, { key: "renderUnansweredMarkings", value: function renderUnansweredMarkings() { return jsx("div", { css: this.props.styles.unansweredDot, "data-automation": "sdk-take-sidebar-item-unanswered-dot" }); } }, { key: "render", value: function render() { return jsx("div", { css: this.props.styles.itemWrapper }, !this.props.isAnswered && this.renderUnansweredMarkings(), jsx(CommonSidebarItem, { itemBody: this.props.itemBody, itemId: this.props.quizEntryId, itemName: this.props.itemName, inStimulus: this.props.inStimulus, isAnswered: this.props.isAnswered, pointsPossible: this.props.pointsPossible, position: this.props.position, scrollToItem: this.props.scrollToItem, sidebarOpen: this.props.sidebarOpen }, this.renderPin())); } }]); }(Component), _defineProperty(_TakingSidebarItem, "displayName", 'TakingSidebarItem'), _defineProperty(_TakingSidebarItem, "componentId", "Quizzes".concat(_TakingSidebarItem.displayName)), _defineProperty(_TakingSidebarItem, "propTypes", { // Passed in by the Sidebar inStimulus: PropTypes.bool, itemBody: PropTypes.string, itemName: PropTypes.string.isRequired, pointsPossible: PropTypes.number.isRequired, position: PropTypes.number.isRequired, quizEntryId: PropTypes.string.isRequired, scrollToItem: PropTypes.func.isRequired, sidebarOpen: PropTypes.bool.isRequired, // Passes in by connect isAnswered: PropTypes.bool.isRequired, isPinned: PropTypes.bool.isRequired, pinSessionItem: PropTypes.func.isRequired, quizSession: ImmutablePropTypes.recordOf({ id: PropTypes.string.isRequired }).isRequired, screenreaderNotification: PropTypes.func.isRequired, /* eslint-disable-next-line react/forbid-prop-types, react/require-default-props */ styles: PropTypes.object }), _defineProperty(_TakingSidebarItem, "defaultProps", { inStimulus: false, itemBody: '' }), _TakingSidebarItem)) || _class); export default TakingSidebarItem;