insomnia/app/ui/components/base/Link.js

27 lines
580 B
JavaScript
Raw Normal View History

2016-07-07 20:10:55 +00:00
import React, {Component, PropTypes} from 'react';
import {shell} from 'electron';
2016-07-07 20:10:55 +00:00
class Link extends Component {
render () {
2016-08-25 17:06:01 +00:00
const {button, href, children, ...other} = this.props;
return button ? (
<button onClick={() => shell.openExternal(href)} {...other}>
{children}
</button>
) :(
<a href={href} onClick={e => {e.preventDefault(); shell.openExternal(href)}} {...other}>
2016-07-07 20:10:55 +00:00
{children}
</a>
)
}
}
Link.propTypes = {
2016-08-25 17:06:01 +00:00
href: PropTypes.string.isRequired,
// Optional
button: PropTypes.bool
2016-07-07 20:10:55 +00:00
};
export default Link;