UNPKG

@ebi-gene-expression-group/react-ebi-species

Version:
61 lines (59 loc) 4.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _react = _interopRequireDefault(require("react")); var _propTypes = _interopRequireDefault(require("prop-types")); var _styledComponents = _interopRequireDefault(require("styled-components")); var _mapping = require("./mapping"); var _templateObject, _templateObject2; function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; } function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } } function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } function _taggedTemplateLiteral(e, t) { return t || (t = e.slice(0)), Object.freeze(Object.defineProperties(e, { raw: { value: Object.freeze(t) } })); } var capitalizeFirstLetter = function capitalizeFirstLetter(string) { return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase(); }; var StyledEbiIcon = _styledComponents["default"].span(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n text-decoration: none;\n font-style: normal;\n text-rendering: optimizeLegibility !important;\n background-size: contain;\n font-weight: 400;\n"]))); // We don’t use props to set the colour here to avoid creating multiple classes var StyledEbiIconSpecies = (0, _styledComponents["default"])(StyledEbiIcon)(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n @font-face {\n font-family: 'EBI-Species';\n src:url('https://ebi.emblstatic.net/web_guidelines/EBI-Icon-fonts/v1.2/EBI-Species/fonts/EBI-Species.eot');\n src:url('https://ebi.emblstatic.net/web_guidelines/EBI-Icon-fonts/v1.2/EBI-Species/fonts/EBI-Species.eot?#iefix') format('embedded-opentype'),\n url('https://ebi.emblstatic.net/web_guidelines/EBI-Icon-fonts/v1.2/EBI-Species/fonts/EBI-Species.woff2') format('woff2'),\n url('https://ebi.emblstatic.net/web_guidelines/EBI-Icon-fonts/v1.2/EBI-Species/fonts/EBI-Species.woff') format('woff'),\n url('https://ebi.emblstatic.net/web_guidelines/EBI-Icon-fonts/v1.2/EBI-Species/fonts/EBI-Species.svg#EBI-Species') format('svg'),\n url('https://ebi.emblstatic.net/web_guidelines/EBI-Icon-fonts/v1.2/EBI-Species/fonts/EBI-Species.ttf') format('truetype');\n font-weight: normal;\n font-style: normal;\n }\n\n ::before {\n font-family: 'EBI-Species';\n content: attr(data-icon);\n text-transform: none;\n }\n"]))); var EbiSpeciesIconBare = function EbiSpeciesIconBare(_ref) { var species = _ref.species, groupColors = _ref.groupColors, color = _ref.color; var _lookUpIcon = (0, _mapping.lookUpIcon)(species), _lookUpIcon2 = _slicedToArray(_lookUpIcon, 2), group = _lookUpIcon2[0], icon = _lookUpIcon2[1]; return /*#__PURE__*/_react["default"].createElement(StyledEbiIconSpecies, { style: { color: color || groupColors[group] || "black" }, "data-icon": icon || "\u2754", title: capitalizeFirstLetter(species) }); }; EbiSpeciesIconBare.propTypes = { species: _propTypes["default"].string, groupColors: _propTypes["default"].shape({ warmBlooded: _propTypes["default"].string, plants: _propTypes["default"].string, other: _propTypes["default"].string }), color: _propTypes["default"].string }; EbiSpeciesIconBare.defaultProps = { species: "oryctolagus cuniculus", //rabbit is objectively the best species groupColors: { warmBlooded: "indianred", plants: "mediumseagreen", other: "deepskyblue" } }; var _default = exports["default"] = EbiSpeciesIconBare;