UNPKG

@instructure/quiz-interactions

Version:

A React UI component Library for quiz interaction types.

104 lines (100 loc) 3.54 kB
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties"; 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 _excluded = ["itemBody", "interactionData"]; 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)); } import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { withI18nSupport } from '@instructure/quiz-common'; import NumericResult from '../../numeric/Result'; import { substituteVars } from '../common/util'; /** --- category: Formula --- Formula Result component ```jsx_example function Example (props) { const exampleProps = { itemBody: 'Solve the equation \\(y = `m` \\cdot x + `b`\\) where x = `x`', interactionData: { variables: [ { name: 'm', value: 2 }, { name: 'b', value: 17.23456 }, { name: 'x', value: 1000 } ] }, scoredData: { value: { userResponse: '2017.23456', correctAnswer: '2017.23456', resultScore: 1 } } } return ( <FormulaResult {...exampleProps} {...props} /> ) } <SettingsSwitcher locales={LOCALES}> <Example /> </SettingsSwitcher> ``` **/ var FormulaResult = /*#__PURE__*/function (_withI18nSupport) { function FormulaResult() { _classCallCheck(this, FormulaResult); return _callSuper(this, FormulaResult, arguments); } _inherits(FormulaResult, _withI18nSupport); return _createClass(FormulaResult, [{ key: "render", value: function render() { var _this$props = this.props, itemBody = _this$props.itemBody, interactionData = _this$props.interactionData, other = _objectWithoutProperties(_this$props, _excluded); var transformedBody = substituteVars(itemBody, interactionData.variables, this.locale); return /*#__PURE__*/React.createElement(NumericResult, Object.assign({}, other, { itemBody: transformedBody })); } }]); }(withI18nSupport(Component)); _defineProperty(FormulaResult, "propTypes", { itemBody: PropTypes.string.isRequired, disabled: PropTypes.bool, interactionData: PropTypes.object.isRequired, scoredData: PropTypes.shape({ value: PropTypes.shape({ userResponse: PropTypes.string, correctAnswer: PropTypes.string, resultScore: PropTypes.number }) }).isRequired, locale: PropTypes.string }); _defineProperty(FormulaResult, "defaultProps", { locale: null }); _defineProperty(FormulaResult, "contextTypes", { locale: PropTypes.string }); export { FormulaResult as default };