1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-15 09:04:04 +02:00
joplin/ElectronClient/app/gui/Header.jsx

69 lines
1.8 KiB
React
Raw Normal View History

2017-11-06 22:54:58 +02:00
const React = require('react');
const { connect } = require('react-redux');
const { reg } = require('lib/registry.js');
const { themeStyle } = require('../theme.js');
const { _ } = require('lib/locale.js');
class HeaderComponent extends React.Component {
back_click() {
this.props.dispatch({ type: 'NAV_BACK' });
}
2017-11-09 00:23:26 +02:00
makeButton(key, style, options) {
let icon = null;
if (options.iconName) {
icon = <i style={{fontSize: style.fontSize * 1.4, marginRight: 5}} className={"icon " + options.iconName}></i>
}
console.info(style);
return <a className="button" style={style} key={key} href="#" onClick={() => {options.onClick()}}>{icon}{options.title}</a>
2017-11-06 22:54:58 +02:00
}
render() {
const style = this.props.style;
const theme = themeStyle(this.props.theme);
const showBackButton = this.props.showBackButton === undefined || this.props.showBackButton === true;
style.height = theme.headerHeight;
2017-11-09 00:23:26 +02:00
style.display = 'flex';
style.flexDirection = 'row';
2017-11-06 22:54:58 +02:00
const buttons = [];
if (showBackButton) {
2017-11-09 00:23:26 +02:00
buttons.push(this.makeButton('back', {}, { title: _('Back'), onClick: () => this.back_click() }));
2017-11-06 22:54:58 +02:00
}
2017-11-09 00:23:26 +02:00
const buttonStyle = {
height: theme.headerHeight,
display: 'flex',
alignItems: 'center',
paddingLeft: theme.headerButtonHPadding,
paddingRight: theme.headerButtonHPadding,
color: theme.color,
textDecoration: 'none',
fontFamily: theme.fontFamily,
fontSize: theme.fontSize,
boxSizing: 'border-box',
};
2017-11-06 22:54:58 +02:00
if (this.props.buttons) {
for (let i = 0; i < this.props.buttons.length; i++) {
2017-11-09 00:23:26 +02:00
buttons.push(this.makeButton('btn_' + i, buttonStyle, this.props.buttons[i]));
2017-11-06 22:54:58 +02:00
}
}
return (
2017-11-09 00:23:26 +02:00
<div className="header" style={style}>
2017-11-06 22:54:58 +02:00
{ buttons }
</div>
);
}
}
const mapStateToProps = (state) => {
2017-11-08 19:51:55 +02:00
return { theme: state.settings.theme };
2017-11-06 22:54:58 +02:00
};
const Header = connect(mapStateToProps)(HeaderComponent);
module.exports = { Header };