client/entity-editor/button-bar/alias-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 _excluded = ["aliasesInvalid", "numAliases"];
/*
 * 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 AliasButton component renders a button
 * component in the style of a link. The link text indicates the number of
 * aliases currently set in the AliasEditor, and invites the user to add new or
 * edit existing aliases.
 *
 * @param {Object} props - The properties passed to the component.
 * @param {number} props.numAliases - The number of aliases present in the
 *        AliasEditor - used to determine the correct button label.
 * @returns {ReactElement} React element containing the rendered AliasButton.
 */
function AliasButton(_ref) {
  var aliasesInvalid = _ref.aliasesInvalid,
    numAliases = _ref.numAliases,
    props = (0, _objectWithoutProperties2.default)(_ref, _excluded);
  var text = 'Add aliases…';
  if (numAliases === 1) {
    text = 'Edit 1 alias…';
  } else if (numAliases > 1) {
    text = "Edit ".concat(numAliases, " aliases\u2026");
  }
  var iconElement = aliasesInvalid && /*#__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: "link"
  }, props), iconElement, text);
}
AliasButton.displayName = 'AliasButton';
AliasButton.propTypes = {
  aliasesInvalid: _propTypes.default.bool.isRequired,
  numAliases: _propTypes.default.number.isRequired
};
var _default = AliasButton;
exports.default = _default;
//# sourceMappingURL=alias-button.js.map