92 lines
2.3 KiB
JavaScript
Raw Normal View History

import React, { PropTypes } from 'react';
import ImmutablePropTypes from 'react-immutable-proptypes';
2016-09-15 18:56:08 +02:00
import pluralize from 'pluralize';
import { IndexLink } from 'react-router';
import { Menu, MenuItem } 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 {
static propTypes = {
2016-10-11 11:34:28 +02:00
collections: ImmutablePropTypes.orderedMap.isRequired,
commands: PropTypes.array.isRequired, // eslint-disable-line
defaultCommands: PropTypes.array.isRequired, // eslint-disable-line
runCommand: PropTypes.func.isRequired,
toggleNavDrawer: PropTypes.func.isRequired,
onCreateEntryClick: PropTypes.func.isRequired,
};
2016-09-15 18:56:08 +02:00
state = {
createMenuActive: false,
};
2016-09-15 18:56:08 +02:00
handleCreatePostClick = (collectionName) => {
2016-09-15 18:56:08 +02:00
const { onCreateEntryClick } = this.props;
if (onCreateEntryClick) {
onCreateEntryClick(collectionName);
}
};
2016-09-15 18:56:08 +02:00
handleCreateButtonClick = () => {
2016-09-15 18:56:08 +02:00
this.setState({
createMenuActive: true,
2016-09-15 18:56:08 +02:00
});
};
2016-09-15 18:56:08 +02:00
handleCreateMenuHide = () => {
2016-09-15 18:56:08 +02:00
this.setState({
createMenuActive: false,
2016-09-15 18:56:08 +02:00
});
};
2016-09-15 18:56:08 +02:00
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}
leftIcon="menu"
rightIcon="create"
onLeftIconClick={toggleNavDrawer}
onRightIconClick={this.handleCreateButtonClick}
2016-09-15 18:56:08 +02:00
>
<IndexLink to="/">
Dashboard
</IndexLink>
2016-10-06 15:13:31 +02:00
2016-09-15 18:56:08 +02:00
<FindBar
commands={commands}
defaultCommands={defaultCommands}
runCommand={runCommand}
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 =>
<MenuItem
key={collection.get('name')}
value={collection.get('name')}
onClick={this.handleCreatePostClick.bind(this, collection.get('name'))} // eslint-disable-line
caption={pluralize(collection.get('label'), 1)}
/>
)
}
</Menu>
2016-09-15 18:56:08 +02:00
</AppBar>
);
}
}