client/entity-editor/button-bar/identifier-button.js

"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
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 _reactBootstrap = require("react-bootstrap");
var _reactFontawesome = require("@fortawesome/react-fontawesome");
var _propTypes = _interopRequireDefault(require("prop-types"));
var _react = _interopRequireDefault(require("react"));
var _freeSolidSvgIcons = require("@fortawesome/free-solid-svg-icons");
var _reactI18next = require("react-i18next");
var _excluded = ["identifiersInvalid", "numIdentifiers", "isUnifiedForm"];
/*
 * Copyright (C) 2016  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.
 */
/**
 * Presentational component. The IdentifierButton component renders a button
 * component in the style of a link. The link text indicates the number of
 * identifiers currently set in the IdentifierEditor, and invites the user to
 * add new or edit existing identifiers.
 *
 * @param {Object} props - The properties passed to the component.
 * @param {boolean} props.identifiersInvalid - Whether the inputs are valid
 *        identifiers.
 * @param {number} props.numIdentifiers - The number of identifiers present in
 *        the IdentifierEditor - used to determine the correct button label.
 * @returns {ReactElement} React element containing the rendered
 *          IdentifierButton.
 */
function IdentifierButton(_ref) {
  var identifiersInvalid = _ref.identifiersInvalid,
    numIdentifiers = _ref.numIdentifiers,
    _ref$isUnifiedForm = _ref.isUnifiedForm,
    isUnifiedForm = _ref$isUnifiedForm === void 0 ? false : _ref$isUnifiedForm,
    props = (0, _objectWithoutProperties2.default)(_ref, _excluded);
  var _useTranslation = (0, _reactI18next.useTranslation)(),
    translate = _useTranslation.t;
  var textComponent = function () {
    if (!isUnifiedForm) {
      if (numIdentifiers === 0) {
        return translate('entityEditor.shared.addIdentifiers');
      }
      return translate('entityEditor.identifierButton.editIdentifiers', {
        count: numIdentifiers
      });
    }
    if (numIdentifiers > 0) {
      return /*#__PURE__*/_react.default.createElement("span", null, translate('entityEditor.identifierButton.editIdentifiersUnified'), ' ', /*#__PURE__*/_react.default.createElement(_reactBootstrap.Badge, {
        className: "ml-1",
        variant: "light"
      }, numIdentifiers));
    }
    return translate('entityEditor.identifierButton.addIdentifiersUnified');
  }();
  var iconElement = identifiersInvalid && /*#__PURE__*/_react.default.createElement(_reactFontawesome.FontAwesomeIcon, {
    className: "margin-right-0-5 text-danger",
    icon: _freeSolidSvgIcons.faTimes
  });
  return /*#__PURE__*/_react.default.createElement(_reactBootstrap.Button, (0, _extends2.default)({
    variant: !isUnifiedForm && 'link'
  }, props), iconElement, textComponent);
}
IdentifierButton.displayName = 'IdentifierButton';
IdentifierButton.propTypes = {
  identifiersInvalid: _propTypes.default.bool.isRequired,
  isUnifiedForm: _propTypes.default.bool,
  numIdentifiers: _propTypes.default.number.isRequired
};
var _default = exports.default = IdentifierButton;
//# sourceMappingURL=identifier-button.js.map