joplin/ElectronClient/app/gui/Header.jsx

79 lines
2.1 KiB
React
Raw Normal View History

2017-11-06 20:54:58 +00: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-08 22:23:26 +00:00
makeButton(key, style, options) {
let icon = null;
if (options.iconName) {
const iconStyle = {
fontSize: Math.round(style.fontSize * 1.4),
color: style.color
};
if (options.title) iconStyle.marginRight = 5;
icon = <i style={iconStyle} className={"fa " + options.iconName}></i>
2017-11-08 22:23:26 +00:00
}
return <a className="button" style={style} key={key} href="#" onClick={() => {options.onClick()}}>{icon}{options.title ? options.title : ''}</a>
2017-11-06 20:54:58 +00: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-08 22:23:26 +00:00
style.display = 'flex';
style.flexDirection = 'row';
style.borderBottom = '1px solid ' + theme.dividerColor;
style.boxSizing = 'border-box';
2017-11-06 20:54:58 +00:00
const buttons = [];
2017-11-08 22:23:26 +00: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-09 19:21:10 +00:00
cursor: 'default',
2017-11-08 22:23:26 +00:00
};
2017-11-11 17:36:47 +00:00
if (showBackButton) {
buttons.push(this.makeButton('back', buttonStyle, { title: _('Back'), onClick: () => this.back_click(), iconName: 'fa-chevron-left ' }));
}
2017-11-06 20:54:58 +00:00
if (this.props.buttons) {
for (let i = 0; i < this.props.buttons.length; i++) {
2017-11-10 20:11:48 +00:00
const o = this.props.buttons[i];
buttons.push(this.makeButton('btn_' + i + '_' + o.title, buttonStyle, o));
2017-11-06 20:54:58 +00:00
}
}
return (
2017-11-08 22:23:26 +00:00
<div className="header" style={style}>
2017-11-06 20:54:58 +00:00
{ buttons }
</div>
);
}
}
const mapStateToProps = (state) => {
2017-11-08 17:51:55 +00:00
return { theme: state.settings.theme };
2017-11-06 20:54:58 +00:00
};
const Header = connect(mapStateToProps)(HeaderComponent);
module.exports = { Header };