All files / src/ExternalLink ExternalLink.js

88.88% Statements 8/9
87.5% Branches 7/8
100% Functions 2/2
88.88% Lines 8/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49                    1x 1x 1x           14x 14x   14x                                   5x   5x              
/**** Libraries ****/
import React from 'react';
import { defaultProps } from './props/defaultProps';
import { propTypes } from './props/propTypes';
 
/**** CSS ****/
import style from './ExternalLink.module.css';
 
export default class ExternalLink extends React.Component {
  addHttp(url) {
    const regEx = new RegExp(/(^(ftp|https|mailto|tel|http|simplehelp|dynamicsnav?):)/i);
    Eif (!regEx.test(url)) {
      return `http://${url}`;
    }
    return url;
  }
 
  render() {
    const { href, title, target, className, children, rel, dataId, onClick, customProps } = this.props;
    const urlOutput = href && typeof href !== 'boolean' ? this.addHttp(String(href)) : 'javascript:void(0);';
 
    return (
      <a
        href={urlOutput}
        target={target}
        className={`${style.link} ${className ? className : ''}`}
        data-title={title}
        rel={rel}
        data-id={dataId}
        data-test-id={dataId}
        onClick={onClick}
        {...customProps}
      >
        {children}
      </a>
    );
  }
}
 
ExternalLink.defaultProps = defaultProps;
 
ExternalLink.propTypes = propTypes;
 
// if (__DOCS__) {
//   ExternalLink.docs = {
//     componentGroup: 'Atom'
//   };
// }