"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 _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,
isUnifiedForm = _ref.isUnifiedForm,
props = (0, _objectWithoutProperties2.default)(_ref, _excluded);
var textComponent = 'Add identifiers (eg. ISBN, Wikidata ID)…';
if (!isUnifiedForm) {
if (numIdentifiers === 1) {
textComponent = 'Edit 1 identifier (eg. ISBN, Wikidata ID)…';
} else if (numIdentifiers > 1) {
textComponent = "Edit ".concat(numIdentifiers, " identifiers (eg. ISBN, Wikidata ID)\u2026");
}
} else if (numIdentifiers > 0) {
textComponent = /*#__PURE__*/_react.default.createElement("span", null, "Edit identifiers ", /*#__PURE__*/_react.default.createElement(_reactBootstrap.Badge, {
className: "ml-1",
variant: "light"
}, numIdentifiers));
} else {
textComponent = 'Add Identifiers';
}
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
};
IdentifierButton.defaultProps = {
isUnifiedForm: false
};
var _default = IdentifierButton;
exports.default = _default;
//# sourceMappingURL=identifier-button.js.map