2017-11-30 01:03:10 +02:00
|
|
|
const React = require('react');
|
|
|
|
const { themeStyle } = require('../theme.js');
|
|
|
|
|
|
|
|
class ToolbarButton extends React.Component {
|
|
|
|
render() {
|
|
|
|
const theme = themeStyle(this.props.theme);
|
|
|
|
|
2018-06-14 09:52:12 +02:00
|
|
|
const style = Object.assign({}, theme.toolbarStyle);
|
2017-11-30 01:03:10 +02:00
|
|
|
|
2018-06-12 00:47:44 +02:00
|
|
|
const title = this.props.title ? this.props.title : '';
|
|
|
|
const tooltip = this.props.tooltip ? this.props.tooltip : title;
|
|
|
|
|
2017-11-30 01:03:10 +02:00
|
|
|
let icon = null;
|
|
|
|
if (this.props.iconName) {
|
|
|
|
const iconStyle = {
|
2018-06-14 10:02:01 +02:00
|
|
|
fontSize: Math.round(theme.fontSize * 1.5),
|
2019-07-29 14:13:23 +02:00
|
|
|
color: theme.color,
|
2017-11-30 01:03:10 +02:00
|
|
|
};
|
2018-06-12 00:47:44 +02:00
|
|
|
if (title) iconStyle.marginRight = 5;
|
2019-09-19 23:51:18 +02:00
|
|
|
icon = <i style={iconStyle} className={`fa ${this.props.iconName}`}></i>;
|
2017-11-30 01:03:10 +02:00
|
|
|
}
|
|
|
|
|
2019-07-29 14:13:23 +02:00
|
|
|
const isEnabled = !('enabled' in this.props) || this.props.enabled === true;
|
2020-03-14 01:46:14 +02:00
|
|
|
const classes = ['button'];
|
2017-11-30 01:03:10 +02:00
|
|
|
if (!isEnabled) classes.push('disabled');
|
|
|
|
|
|
|
|
const finalStyle = Object.assign({}, style, {
|
|
|
|
opacity: isEnabled ? 1 : 0.4,
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<a
|
|
|
|
className={classes.join(' ')}
|
|
|
|
style={finalStyle}
|
2018-06-12 00:47:44 +02:00
|
|
|
title={tooltip}
|
2017-11-30 01:03:10 +02:00
|
|
|
href="#"
|
2019-07-29 14:13:23 +02:00
|
|
|
onClick={() => {
|
|
|
|
if (isEnabled && this.props.onClick) this.props.onClick();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{icon}
|
|
|
|
{title}
|
2017-11-30 01:03:10 +02:00
|
|
|
</a>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-29 14:13:23 +02:00
|
|
|
module.exports = ToolbarButton;
|