"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 _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var React = _interopRequireWildcard(require("react"));
var _freeSolidSvgIcons = require("@fortawesome/free-solid-svg-icons");
var _reactFontawesome = require("@fortawesome/react-fontawesome");
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; }
/*
* 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.
*/
function icon(empty, error, warn) {
if (empty) {
return null;
}
if (error) {
return _freeSolidSvgIcons.faTimes;
}
if (warn) {
return _freeSolidSvgIcons.faExclamationTriangle;
}
return _freeSolidSvgIcons.faCheck;
}
function contextualColor(empty, error, warn) {
if (empty) {
return null;
}
if (error) {
return 'text-danger';
}
if (warn) {
return 'text-warning';
}
return 'text-success';
}
/**
* Presentational component. This component renders a textual label, intended
* to be used with an input. Some formatting is applied and an icon is chosen
* based on the validation state passed in via the component properties.
*
* @param {Object} props - The properties passed to the component.
* @param {node} props.children - The element or value to display within the
* label.
* @param {boolean} props.empty - A flag indicating whether the associated
* input is empty.
* @param {boolean} props.error - A flag indicating whether there has been an
* error validating the contents of the associated input field.
* @returns {Object} A React component containing the rendered input.
*/
function ValidationLabel(_ref) {
var children = _ref.children,
empty = _ref.empty,
error = _ref.error,
hideIcon = _ref.hideIcon,
errorMessage = _ref.errorMessage,
warn = _ref.warn,
warnMessage = _ref.warnMessage;
var warnElement = warn && !empty && !error && /*#__PURE__*/React.createElement("span", {
className: contextualColor(empty, error, warn)
}, " ", warnMessage, " ");
var errorElement = errorMessage && error && /*#__PURE__*/React.createElement("span", {
className: contextualColor(empty, error, warn)
}, " ", errorMessage, " ");
var iconElement = !hideIcon && icon(empty, error, warn) && /*#__PURE__*/React.createElement(_reactFontawesome.FontAwesomeIcon, {
className: "margin-left-0-5",
icon: icon(empty, error, warn)
});
return /*#__PURE__*/React.createElement("span", {
className: contextualColor(empty, error, warn)
}, children, iconElement, errorElement, warnElement);
}
ValidationLabel.displayName = 'ValidationLabel';
ValidationLabel.defaultProps = {
children: null,
empty: false,
error: false,
errorMessage: '',
hideIcon: false,
warn: false,
warnMessage: ''
};
var _default = ValidationLabel;
exports.default = _default;
//# sourceMappingURL=validation-label.js.map