UNPKG

@instructure/quiz-interactions

Version:

A React UI component Library for quiz interaction types.

211 lines (209 loc) • 7.22 kB
function _assert_this_initialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _call_super(_this, derived, args) { derived = _get_prototype_of(derived); return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args)); } function _class_call_check(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for(var i = 0; i < props.length; i++){ var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _create_class(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } function _define_property(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _get_prototype_of(o) { _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _get_prototype_of(o); } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _set_prototype_of(subClass, superClass); } function _possible_constructor_return(self, call) { if (call && (_type_of(call) === "object" || typeof call === "function")) { return call; } return _assert_this_initialized(self); } function _set_prototype_of(o, p) { _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _set_prototype_of(o, p); } function _type_of(obj) { "@swc/helpers - typeof"; return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; } function _is_native_reflect_construct() { try { var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {})); } catch (_) {} return (_is_native_reflect_construct = function() { return !!result; })(); } import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { ItemBodyWrapper } from '@instructure/quiz-rce'; import { ScreenReaderContent } from '@instructure/ui-a11y-content'; import { Decimal } from '@instructure/quiz-i18n'; import { TextInput, parseSeparators } from '@instructure/quiz-common'; import { ApplyLocaleContext } from '@instructure/ui-i18n'; import t from '@instructure/quiz-i18n/format-message'; var NumericShow = /*#__PURE__*/ function(Component) { "use strict"; _inherits(NumericShow, Component); function NumericShow() { _class_call_check(this, NumericShow); return _call_super(this, NumericShow, arguments); } _create_class(NumericShow, [ { key: "componentDidMount", value: function componentDidMount() { Decimal.accountSettingDelimiters = this.props.separatorConfig ? parseSeparators(this.props.separatorConfig) : null; } }, { key: "locale", get: function get() { return this.props.locale || this.context.locale || 'en-US'; } }, { key: "firstCriteria", get: function get() { var scoringData = this.props.scoringData; return scoringData && scoringData.value && scoringData.value[0] || {}; } }, { key: "value", get: function get() { var _this_firstCriteria = this.firstCriteria, type = _this_firstCriteria.type, value = _this_firstCriteria.value, start = _this_firstCriteria.start, end = _this_firstCriteria.end; if (type === 'withinARange') { return t('{minimum} to {maximum} inclusive', { minimum: this.formatNumber(start), maximum: this.formatNumber(end) }); } return this.formatNumber(value); } }, { key: "formatNumber", value: function formatNumber(value) { return isNaN(value) ? value : Decimal.toLocaleString(value.toString(), this.locale); } }, { key: "render", value: function render() { return /*#__PURE__*/ React.createElement(ItemBodyWrapper, { itemBody: this.props.itemBody }, /*#__PURE__*/ React.createElement(TextInput, { renderLabel: /*#__PURE__*/ React.createElement(ScreenReaderContent, null, t('Answer value')), interaction: "readonly", tabIndex: -1, defaultValue: this.value })); } } ]); return NumericShow; }(Component); _define_property(NumericShow, "propTypes", { itemBody: PropTypes.string.isRequired, locale: PropTypes.string, scoringData: PropTypes.shape({ value: PropTypes.array }), separatorConfig: PropTypes.shape({ decimalSeparator: PropTypes.string, thousandSeparator: PropTypes.string }) }); _define_property(NumericShow, "contextType", ApplyLocaleContext); _define_property(NumericShow, "defaultProps", { locale: void 0, scoringData: void 0 }); /** --- category: Numeric --- Numeric Show component ```jsx_example <SettingsSwitcher locales={LOCALES}> <NumericShow itemBody="x is an integer and 9 < x^2 < 99. What's the max value of x, minus the minimum value of x" scoringData={{ value: [{ type: 'exactResponse', id: '1', value: '18' }, { type: 'withinARange', id: '2', start: '18', end: '18' }, { type: 'preciseResponse', id: '3', value: '18', precision: '1', precisionType: 'decimals' }, { type: 'marginOfError', id: '4', value: '18', margin: '0.4', marginType: 'absolute' }] }} /> </SettingsSwitcher> ``` **/ export { NumericShow as default };