2017-08-10 01:56:27 +00:00
|
|
|
import React, {PureComponent} from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2017-03-03 01:44:07 +00:00
|
|
|
import autobind from 'autobind-decorator';
|
2016-11-23 19:33:24 +00:00
|
|
|
import {trackEvent} from '../../../analytics/index';
|
2017-06-01 22:58:09 +00:00
|
|
|
import * as misc from '../../../common/misc';
|
2016-07-07 20:10:55 +00:00
|
|
|
|
2017-03-03 01:44:07 +00:00
|
|
|
@autobind
|
2017-02-28 21:32:23 +00:00
|
|
|
class Link extends PureComponent {
|
2017-03-03 01:44:07 +00:00
|
|
|
_handleClick (e) {
|
2016-11-23 19:33:24 +00:00
|
|
|
e && e.preventDefault();
|
2016-11-29 22:28:55 +00:00
|
|
|
const {href, onClick} = this.props;
|
|
|
|
|
|
|
|
// Also call onClick that was passed to us if there was one
|
|
|
|
onClick && onClick(e);
|
2017-06-01 22:58:09 +00:00
|
|
|
misc.clickLink(href);
|
2016-11-29 22:28:55 +00:00
|
|
|
trackEvent('Link', 'Click', href);
|
2017-03-03 20:09:08 +00:00
|
|
|
}
|
2016-11-23 22:55:09 +00:00
|
|
|
|
2016-07-07 20:10:55 +00:00
|
|
|
render () {
|
2017-03-03 20:09:08 +00:00
|
|
|
const {
|
|
|
|
onClick, // eslint-disable-line no-unused-vars
|
|
|
|
button,
|
|
|
|
href,
|
|
|
|
children,
|
|
|
|
...other
|
|
|
|
} = this.props;
|
|
|
|
return button
|
|
|
|
? <button onClick={this._handleClick} {...other}>{children}</button>
|
|
|
|
: <a href={href} onClick={this._handleClick} {...other}>{children}</a>;
|
2016-07-07 20:10:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Link.propTypes = {
|
2016-08-25 17:06:01 +00:00
|
|
|
href: PropTypes.string.isRequired,
|
|
|
|
|
|
|
|
// Optional
|
2017-03-08 05:52:17 +00:00
|
|
|
button: PropTypes.bool,
|
|
|
|
onClick: PropTypes.func,
|
|
|
|
children: PropTypes.node
|
2016-07-07 20:10:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Link;
|