client/entity-editor/common/numeric-field.js

"use strict";

require("core-js/modules/es.array.iterator.js");
require("core-js/modules/es.object.to-string.js");
require("core-js/modules/es.string.iterator.js");
require("core-js/modules/es.weak-map.js");
require("core-js/modules/web.dom-collections.iterator.js");
require("core-js/modules/es.object.get-own-property-descriptor.js");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var React = _interopRequireWildcard(require("react"));
var _reactBootstrap = require("react-bootstrap");
var _validationLabel = _interopRequireDefault(require("../common/validation-label"));
var _classnames = _interopRequireDefault(require("classnames"));
var _excluded = ["addonAfter", "show", "label", "empty", "error"];
/*
 * Copyright (C) 2017  Ben Ockmore
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
/**
 * Presentational component. This component renders a plain text input which
 * can be hidden, and an associated ValidationLabel.
 *
 * @param {Object} props - The properties passed to the component.
 * @param {boolean} props.error - Passed to the ValidationLabel within the
 *        component to indicate a validation error.
 * @param {boolean} props.empty - Passed to the ValidationLabel within the
 *        component to indicate that the field is empty.
 * @param {boolean} props.show - Determines the visibility of the field - if
 *        falsey, bootstrap's 'd-none' class is applied.
 * @param {string} props.label - The text to be used for the input label.
 * @returns {Object} A React component containing the rendered input.
 */
function NumericField(_ref) {
  var addonAfter = _ref.addonAfter,
    show = _ref.show,
    label = _ref.label,
    empty = _ref.empty,
    error = _ref.error,
    rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
  var labelElement = /*#__PURE__*/React.createElement(_validationLabel.default, {
    empty: empty,
    error: error
  }, label);
  var groupClassName = (0, _classnames.default)({
    'd-none': !show
  });
  return /*#__PURE__*/React.createElement(_reactBootstrap.Form.Group, {
    className: groupClassName
  }, /*#__PURE__*/React.createElement(_reactBootstrap.Form.Label, null, labelElement), /*#__PURE__*/React.createElement(_reactBootstrap.InputGroup, null, /*#__PURE__*/React.createElement(_reactBootstrap.Form.Control, (0, _extends2.default)({
    type: "number"
  }, rest)), /*#__PURE__*/React.createElement(_reactBootstrap.InputGroup.Append, null, /*#__PURE__*/React.createElement(_reactBootstrap.InputGroup.Text, null, addonAfter))));
}
NumericField.displayName = 'NumericField';
NumericField.defaultProps = {
  empty: false,
  error: false,
  show: true
};
var _default = NumericField;
exports.default = _default;
//# sourceMappingURL=numeric-field.js.map