UNPKG

@instructure/quiz-interactions

Version:

A React UI component Library for quiz interaction types.

137 lines 4.87 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"; 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 { Decimal } from '@instructure/quiz-i18n'; import { Flex } from '@instructure/quiz-common'; import { ScientificNumberInput } from '@instructure/quiz-number-input'; import t from '@instructure/quiz-i18n/es/format-message'; var WithinARange = /*#__PURE__*/function (_Component) { function WithinARange() { var _this2; _classCallCheck(this, WithinARange); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this2 = _callSuper(this, WithinARange, [].concat(args)); _defineProperty(_this2, "state", { start: '', end: '' }); _defineProperty(_this2, "handleStartChange", function (event, value, normalized) { _this2.setState({ start: value }); _this2.props.onChange(event, { id: _this2.props.id, start: normalized }); }); _defineProperty(_this2, "handleEndChange", function (event, value, normalized) { _this2.setState({ end: value }); _this2.props.onChange(event, { id: _this2.props.id, end: normalized }); }); return _this2; } _inherits(WithinARange, _Component); return _createClass(WithinARange, [{ key: "UNSAFE_componentWillMount", value: function UNSAFE_componentWillMount() { if (this.props.start) { var start; try { start = Decimal.toLocaleString(this.props.start, this.props.locale); } catch (_unused) { start = this.props.start; } this.setState({ start: start }); } if (this.props.end) { var end; try { end = Decimal.toLocaleString(this.props.end, this.props.locale); } catch (_unused2) { end = this.props.end; } this.setState({ end: end }); } } }, { key: "render", value: function render() { var currentStartValue = this.state.start; var currentEndValue = this.state.end; return /*#__PURE__*/React.createElement(Flex, { alignItems: "start" }, /*#__PURE__*/React.createElement(Flex.Item, { shouldGrow: true, shouldShrink: true, margin: "0 xx-small" }, this.props.numericTypeSelect), /*#__PURE__*/React.createElement(Flex.Item, { shouldGrow: true, shouldShrink: true, margin: "0 xx-small" }, /*#__PURE__*/React.createElement(ScientificNumberInput, { renderLabel: t('Range start'), messages: this.props.messages.start, onChange: this.handleStartChange, value: currentStartValue, "aria-valuetext": "".concat(currentStartValue, " ").concat(t('Range start')), isRequired: true })), /*#__PURE__*/React.createElement(Flex.Item, { shouldGrow: true, shouldShrink: true, margin: "0 xx-small" }, /*#__PURE__*/React.createElement(ScientificNumberInput, { renderLabel: t('Range end'), messages: this.props.messages.end, onChange: this.handleEndChange, value: currentEndValue, "aria-valuetext": "".concat(currentEndValue, " ").concat(t('Range end')), isRequired: true }))); } }]); }(Component); _defineProperty(WithinARange, "propTypes", { end: PropTypes.string, id: PropTypes.string.isRequired, locale: PropTypes.string.isRequired, messages: PropTypes.objectOf(PropTypes.array), numericTypeSelect: PropTypes.node.isRequired, onChange: PropTypes.func.isRequired, start: PropTypes.string }); _defineProperty(WithinARange, "defaultProps", { end: void 0, messages: void 0, start: void 0 }); export { WithinARange as default };