@zohodesk/dot
Version:
In this Library, we Provide Some Basic Components to Build Your Application
51 lines (46 loc) • 1.25 kB
JavaScript
/**** 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);
if (!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 /*#__PURE__*/React.createElement("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);
}
}
ExternalLink.defaultProps = defaultProps;
ExternalLink.propTypes = propTypes; // if (__DOCS__) {
// ExternalLink.docs = {
// componentGroup: 'Atom'
// };
// }