91 lines
2.1 KiB
JavaScript
Raw Normal View History

2016-09-15 18:56:08 +02:00
import React from 'react';
import pluralize from 'pluralize';
import { IndexLink } from 'react-router';
import { Menu, MenuItem, Button, IconButton } from 'react-toolbox';
2016-09-15 18:56:08 +02:00
import AppBar from 'react-toolbox/lib/app_bar';
import FindBar from '../FindBar/FindBar';
2016-09-15 18:56:08 +02:00
import styles from './AppHeader.css';
export default class AppHeader extends React.Component {
state = {
createMenuActive: false
}
handleCreatePostClick = collectionName => {
const { onCreateEntryClick } = this.props;
if (onCreateEntryClick) {
onCreateEntryClick(collectionName);
}
}
handleCreateButtonClick = () => {
2016-09-15 18:56:08 +02:00
this.setState({
createMenuActive: true
});
}
handleCreateMenuHide = () => {
2016-09-15 18:56:08 +02:00
this.setState({
createMenuActive: false
});
}
render() {
const {
collections,
commands,
defaultCommands,
runCommand,
toggleNavDrawer
} = this.props;
2016-09-15 18:56:08 +02:00
const { createMenuActive } = this.state;
return (
<AppBar
fixed
theme={styles}
>
<IconButton
icon="menu"
inverse
onClick={toggleNavDrawer}
/>
2016-09-15 18:56:08 +02:00
<IndexLink to="/">
Dashboard
</IndexLink>
<FindBar
commands={commands}
defaultCommands={defaultCommands}
runCommand={runCommand}
2016-09-15 18:56:08 +02:00
/>
<Button
className={styles.createBtn}
icon='add'
floating
accent
onClick={this.handleCreateButtonClick}
2016-09-15 18:56:08 +02:00
>
<Menu
active={createMenuActive}
position="topRight"
onHide={this.handleCreateMenuHide}
2016-09-15 18:56:08 +02:00
>
{
collections.valueSeq().map(collection =>
2016-09-15 18:56:08 +02:00
<MenuItem
key={collection.get('name')}
value={collection.get('name')}
onClick={this.handleCreatePostClick.bind(this, collection.get('name'))}
caption={pluralize(collection.get('label'), 1)}
/>
)
}
</Menu>
</Button>
2016-09-15 18:56:08 +02:00
</AppBar>
);
}
}