-
Notifications
You must be signed in to change notification settings - Fork 4
/
link.jsx
41 lines (34 loc) · 1.01 KB
/
link.jsx
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
var React = require('react');
module.exports = React.createClass({
propTypes: {
className: React.PropTypes.string,
href: React.PropTypes.string,
target: React.PropTypes.string,
onClick: React.PropTypes.func
},
handleClick: function(e) {
// if a handler was provided, run it
if (this.props.onClick) {
this.props.onClick(this.props.href);
}
// if target is set (e.g. to "_blank"), let the browser handle it
if (this.props.target || (this.props.href && this.props.href.indexOf('mailto:') === 0)) {
return;
}
// if keyboard click, or not a left click, let the browser handle it
if (!e.button === 0 || e.metaKey || e.altKey || e.ctrlKey || e.shiftKey) {
return;
}
// otherwise intercept the browser
if (this.props.onClick) {
e.preventDefault();
}
},
render: function() {
return React.createElement('a', Object.assign({}, this.props, {
href: this.props.href,
className: this.props.className ? 'link ' + this.props.className : 'link',
onClick: this.handleClick
}));
}
});