UNPKG

@instructure/quiz-interactions

Version:

A React UI component Library for quiz interaction types.

207 lines (202 loc) • 6.8 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, _EssayExample; 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 */ /* eslint-disable react/jsx-no-literals */ import { Component } from 'react'; import PropTypes from 'prop-types'; import { cloneDeep } from 'lodash'; import { Heading } from '@instructure/ui-heading'; import { jsx } from '@instructure/emotion'; import EssayEdit from '../Edit'; import EssayShow from '../Show'; import EssayTake from '../Take'; import EssayResult from '../Result'; import generateStyle from '../../common/example/default'; import generateComponentTheme from '../../common/example/defaultTheme'; import { withStyleOverrides } from '@instructure/quiz-common'; /** --- category: Essay --- Essay Example. ```jsx_example <SettingsSwitcher locales={LOCALES}> <EssayExample /> </SettingsSwitcher> ``` **/ var EssayExample = (_dec = withStyleOverrides(generateStyle, generateComponentTheme), _dec(_class = (_EssayExample = /*#__PURE__*/function (_Component) { function EssayExample(props) { var _this2; _classCallCheck(this, EssayExample); _this2 = _callSuper(this, EssayExample); _defineProperty(_this2, "handleChangeItemState", function (itemState) { var newState = Object.assign({}, itemState, itemState.scoringData ? { scoredData: { value: _this2.transformScoredData(itemState.scoringData), gradeStatus: 'waiting' } } : null, itemState.interactionData ? { takeInteractionData: _this2.transformTakeInteractionData(itemState.interactionData) } : null); _this2.setState(newState); }); _defineProperty(_this2, "handleResponseUpdate", function (userResponse) { _this2.setState({ userResponse: { value: userResponse }, scoredData: { value: userResponse, gradeStatus: 'waiting' } }); }); _this2.state = {}; if (props.useDefaultData) { Object.assign(_this2.state, { interactionData: { rce: false, spellCheck: false, wordCount: false, wordLimitEnabled: false, wordLimitMax: null, wordLimitMin: null, notes: '' }, itemBody: 'Why did the Roman Empire fall?', properties: {}, scoringData: { value: 'goths and food shortage' }, scoredData: { gradeStatus: 'waiting', value: '' }, userResponse: { value: '' } }); _this2.state.takeInteractionData = _this2.transformTakeInteractionData(_this2.state.interactionData); } return _this2; } /** * Normally, this should be calling a service */ _inherits(EssayExample, _Component); return _createClass(EssayExample, [{ key: "transformScoredData", value: function transformScoredData(scoringData) { return cloneDeep(scoringData); } /** * Normally, this should be calling a service */ }, { key: "transformTakeInteractionData", value: function transformTakeInteractionData(interactionData) { return cloneDeep(interactionData); } }, { key: "renderEdit", value: function renderEdit() { return jsx("div", { title: "edit" }, jsx(Heading, { level: "h2" }, "Edit"), jsx(EssayEdit, { changeItemState: this.handleChangeItemState, interactionData: this.state.interactionData, itemBody: this.state.itemBody, itemId: this.state.itemId, properties: this.state.properties, scoringData: this.state.scoringData })); } }, { key: "renderShow", value: function renderShow() { return jsx("div", { title: "show" }, jsx(Heading, { level: "h2" }, "Show"), jsx(EssayShow, { interactionData: this.state.interactionData, itemBody: this.state.itemBody, properties: this.state.properties, scoringData: this.state.scoringData })); } }, { key: "renderTake", value: function renderTake() { return jsx("div", { title: "take" }, jsx(Heading, { level: "h2" }, "Take"), jsx(EssayTake, { interactionData: this.state.takeInteractionData, itemBody: this.state.itemBody, userResponse: this.state.userResponse, handleResponseUpdate: this.handleResponseUpdate })); } }, { key: "renderResult", value: function renderResult() { return jsx("div", { title: "result" }, jsx(Heading, { level: "h2" }, "Result"), jsx(EssayResult, { interactionData: this.state.takeInteractionData, itemBody: this.state.itemBody, scoredData: this.state.scoredData, scoringData: this.state.scoringData })); } }, { key: "render", value: function render() { return jsx("div", null, jsx("div", { css: this.props.styles.row }, jsx("div", { css: this.props.styles.panel }, this.renderEdit()), jsx("div", { css: this.props.styles.panel }, this.renderShow())), jsx("div", { css: this.props.styles.row }, jsx("div", { css: this.props.styles.panel }, this.renderTake()), jsx("div", { css: this.props.styles.panel }, this.renderResult()))); } }]); }(Component), _defineProperty(_EssayExample, "displayName", 'EssayExample'), _defineProperty(_EssayExample, "componentId", "Quizzes".concat(_EssayExample.displayName)), _defineProperty(_EssayExample, "propTypes", { useDefaultData: PropTypes.bool, styles: PropTypes.object }), _defineProperty(_EssayExample, "defaultProps", { useDefaultData: true }), _EssayExample)) || _class); export { EssayExample as default };