UNPKG

@instructure/quiz-interactions

Version:

A React UI component Library for quiz interaction types.

101 lines (97 loc) 3.39 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 NumericTake from '../../numeric/Take'; import { substituteVars } from '../common/util'; /** --- category: Formula --- Formula Take 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 }] } } return ( <FormulaTake {...exampleProps} {...props} /> ) } <SettingsSwitcher locales={LOCALES}> <TakeStateProvider> <Example /> </TakeStateProvider> </SettingsSwitcher> ``` **/ var FormulaTake = /*#__PURE__*/function (_withI18nSupport) { function FormulaTake() { _classCallCheck(this, FormulaTake); return _callSuper(this, FormulaTake, arguments); } _inherits(FormulaTake, _withI18nSupport); return _createClass(FormulaTake, [{ key: "render", value: function render() { var _this$props = this.props, itemBody = _this$props.itemBody, interactionData = _this$props.interactionData, props = _objectWithoutProperties(_this$props, _excluded); var transformedBody = substituteVars(itemBody, interactionData.variables, this.locale); return /*#__PURE__*/React.createElement(NumericTake, Object.assign({}, props, { itemBody: transformedBody })); } }]); }(withI18nSupport(Component)); _defineProperty(FormulaTake, "propTypes", { itemBody: PropTypes.string.isRequired, interactionData: PropTypes.object.isRequired, handleResponseUpdate: PropTypes.func.isRequired, locale: PropTypes.string, separatorConfig: PropTypes.shape({ decimalSeparator: PropTypes.string, thousandSeparator: PropTypes.string }) }); _defineProperty(FormulaTake, "defaultProps", { locale: null }); _defineProperty(FormulaTake, "contextTypes", { locale: PropTypes.string }); export { FormulaTake as default };