UNPKG

@massds/mayflower-react

Version:

React versions of Mayflower design system UI components

120 lines (101 loc) 4.69 kB
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } /** * DecorativeLink module. * @module @massds/mayflower-react/DecorativeLink * @requires module:@massds/mayflower-assets/scss/01-atoms/decorative-link * @requires module:@massds/mayflower-assets/scss/01-atoms/svg-icons * @requires module:@massds/mayflower-assets/scss/01-atoms/svg-loc-icons */ import React from "react"; import PropTypes from "prop-types"; import classNames from "classnames"; // eslint-disable-next-line import/no-unresolved import IconPdf from "../Icon/IconPdf.mjs"; // eslint-disable-next-line import/no-unresolved import IconDocx from "../Icon/IconDocx.mjs"; // eslint-disable-next-line import/no-unresolved import IconXlxs from "../Icon/IconXlxs.mjs"; // eslint-disable-next-line import/no-unresolved import IconGeneric from "../Icon/IconGeneric.mjs"; // eslint-disable-next-line import/no-unresolved import IconArrow from "../Icon/IconArrow.mjs"; const DecorativeLink = props => { var _classNames; const showFileIcon = props.showFileIcon, className = props.className, href = props.href, info = props.info, text = props.text, details = props.details, icon = props.icon, rest = _objectWithoutPropertiesLoose(props, ["showFileIcon", "className", "href", "info", "text", "details", "icon"]); const classes = classNames((_classNames = { 'ma__decorative-link': true, 'ma__download-link': showFileIcon }, _classNames[props.className] = className, _classNames)); let decIcon = null; let title; if (showFileIcon) { // eslint-disable-next-line no-bitwise const getFileExtension = filename => filename.slice((filename.lastIndexOf('.') - 1 >>> 0) + 2); let ext = getFileExtension(href); title = ext + " file"; const genericFile = ['csv', 'doc', 'docm', 'dot', 'dotx', 'dwg', 'geojson', 'gif', 'json', 'jpg', 'kml', 'kmz', 'mp3', 'mpp', 'msg', 'odf', 'ods', 'odt', 'png', 'pps', 'ppsx', 'potx', 'ppt', 'pptm', 'pptx', 'ppsm', 'prx', 'pub', 'rdf', 'rtf', 'tiff', 'tsv', 'txt', 'xls', 'xlsb', 'xlsm', 'xml', 'zip']; ext = genericFile.indexOf(ext) !== -1 ? 'generic' : ext; switch (ext) { case 'pdf': decIcon = /*#__PURE__*/React.createElement(IconPdf, { title: title, width: 35, height: 36 }); break; case 'docx': decIcon = /*#__PURE__*/React.createElement(IconDocx, { title: title, width: 35, height: 36 }); break; case 'xlxs': decIcon = /*#__PURE__*/React.createElement(IconXlxs, { title: title, width: 35, height: 36 }); break; case 'generic': decIcon = /*#__PURE__*/React.createElement(IconGeneric, { title: title, width: 35, height: 36 }); break; default: decIcon = null; } } return /*#__PURE__*/React.createElement("span", { className: classes }, /*#__PURE__*/React.createElement("a", _extends({}, rest, { href: href, title: info || null }), decIcon && /*#__PURE__*/React.createElement("span", { className: "ma__download-link--icon" }, decIcon, /*#__PURE__*/React.createElement("span", null, "\xA0")), /*#__PURE__*/React.createElement("span", null, text), details && /*#__PURE__*/React.createElement("span", { className: "ma__decorative-link__details" }, /*#__PURE__*/React.createElement("span", null, "\xA0"), /*#__PURE__*/React.createElement("span", null, details)), /*#__PURE__*/React.createElement("span", null, "\xA0"), icon || /*#__PURE__*/React.createElement(IconArrow, { "aria-hidden": "true" }))); }; DecorativeLink.propTypes = process.env.NODE_ENV !== "production" ? { href: PropTypes.string, info: PropTypes.string, text: PropTypes.string, showFileIcon: PropTypes.bool, className: PropTypes.string, details: PropTypes.string, icon: PropTypes.elementType } : {}; DecorativeLink.defaultProps = { href: '#', text: 'Lorem ipsum dolor sit amet', showFileIcon: false }; export default DecorativeLink;