lbry-desktop/js/component/link.js

104 lines
2.9 KiB
JavaScript
Raw Normal View History

2016-11-22 21:19:08 +01:00
import React from 'react';
import {Icon, ToolTip} from './common.js';
export let Link = React.createClass({
2017-01-09 05:56:21 +01:00
propTypes: {
label: React.PropTypes.string,
icon: React.PropTypes.string,
button: React.PropTypes.string,
badge: React.PropTypes.string,
hidden: React.PropTypes.bool,
},
getDefaultProps: function() {
return {
hidden: false,
disabled: false,
};
},
handleClick: function(e) {
if (this.props.onClick) {
this.props.onClick(e);
}
},
render: function() {
2017-01-09 05:56:21 +01:00
if (this.props.hidden) {
return null;
}
const className = (this.props.className || '') +
(this.props.button ? ' button-block button-' + this.props.button : '') +
(!this.props.className && !this.props.button ? 'button-text' : '') +
(this.props.disabled ? ' disabled' : '');
let content;
if (this.props.children) { // Custom content
content = this.props.children;
} else {
content = [
'icon' in this.props ? <Icon icon={this.props.icon} fixed={true} /> : null,
<span className="link-label">{this.props.label}</span>,
'badge' in this.props ? <span className="badge">{this.props.badge}</span> : null,
];
}
return (
2017-01-09 05:56:21 +01:00
<a className={className} href={this.props.href || 'javascript:;'} title={this.props.title}
onClick={this.handleClick} {... 'style' in this.props ? {style: this.props.style} : {}}>
{this.props.button
? <span className="button__content">{content}</span>
: content}
</a>
);
}
});
var linkContainerStyle = {
position: 'relative',
};
2016-11-22 21:19:08 +01:00
export let ToolTipLink = React.createClass({
getInitialState: function() {
return {
showTooltip: false,
};
},
handleClick: function() {
if (this.props.tooltip) {
this.setState({
showTooltip: !this.state.showTooltip,
});
}
if (this.props.onClick) {
this.props.onClick();
}
},
handleTooltipMouseOut: function() {
this.setState({
showTooltip: false,
});
},
render: function() {
var href = this.props.href ? this.props.href : 'javascript:;',
icon = this.props.icon ? <Icon icon={this.props.icon} /> : '',
2016-08-07 23:05:04 +02:00
className = this.props.className +
(this.props.button ? ' button-block button-' + this.props.button : '') +
(this.props.hidden ? ' hidden' : '') +
(this.props.disabled ? ' disabled' : '');
return (
<span style={linkContainerStyle}>
2016-08-07 23:05:04 +02:00
<a className={className ? className : 'button-text'} href={href} style={this.props.style ? this.props.style : {}}
title={this.props.title} onClick={this.handleClick}>
{this.props.icon ? icon : '' }
{this.props.label}
</a>
{(!this.props.tooltip ? null :
<ToolTip open={this.state.showTooltip} onMouseOut={this.handleTooltipMouseOut}>
{this.props.tooltip}
</ToolTip>
)}
</span>
);
}
});