Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/navigation component #100

Merged
merged 8 commits into from
Jul 13, 2017
80 changes: 80 additions & 0 deletions app/components/Navigation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import React from 'react'
import { connect as connectFela } from 'react-fela'
import { pipe } from 'ramda'
import AppBar from 'material-ui/AppBar'
import Drawer from 'material-ui/Drawer'
import MenuItem from 'material-ui/MenuItem'
import Divider from 'material-ui/Divider'

import styles from '../styles/Navigation'
import { FormattedMessage } from '../../lib/Intl'

class Navigation extends React.Component {
constructor (props) {
super(props)
this.state = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i know i mentioned this before, but what do you think about using recompose to handle stateful or lifecycle components? while i did say "functional purity" can be a trap, i am enjoying using recompose so far.

so this would be:

import { connect as connectFela } from 'react-fela'
import { withState, withHandlers } from 'recompose'
import { pipe, not } from 'ramda'

import styles from '../styles/Navigation'

const Navigation = (props) => {
  // render...
}

export default pipe(
  connectFela(styles),
  withState('isDrawerOpen', 'setDrawerOpen', false),
  withHandlers({
    toggleDrawer: ({ setDrawerOpen }) => () => setDrawerOpen(not)
  })
)(Navigation)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeaaaahhh nice ! i wanted to ask you how to do this actually - will give it a go!

drawerOpen: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm a fan of is* boolean props, so isDrawerOpen. helps disambiguate from thinking that this is a function which opens the drawer. what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A++ i agree

}
}

handleDrawerToggle = () => {
this.setState({ drawerOpen: !this.state.drawerOpen })
}

render () {
const { styles } = this.props
return (
<div>
<AppBar
title={
<FormattedMessage
id='app.name'
className={styles.labelText}
/>
}
onLeftIconButtonTouchTap={this.handleDrawerToggle}
/>
<Drawer open={this.state.drawerOpen}>
<MenuItem
leftIcon={
<i className="fa fa-bars" aria-hidden="true"/>
}
onTouchTap={this.handleDrawerToggle}
>
<FormattedMessage
id='app.closeMenu'
className={styles.labelText}
/>
</MenuItem>
<Divider />
<MenuItem
leftIcon={
<i className="fa fa-tachometer" aria-hidden="true" />
}
>
<FormattedMessage
id='app.dashboard'
className={styles.labelText}
/>
</MenuItem>
<Divider />
<MenuItem
leftIcon={
<i className="fa fa-sign-out" aria-hidden="true" />
}
>
<FormattedMessage
id='app.logOut'
className={styles.labelText}
/>
</MenuItem>
<Divider />
</Drawer>
</div>
)
}
}

export default pipe(
connectFela(styles)
)(Navigation)
3 changes: 3 additions & 0 deletions app/locales/en.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"app.name": "Cobuy",
"app.closeMenu": "close menu",
"app.dashboard": "dashboard",
"app.logOut": "log out",
"agents.nameLabel": "name",
"agents.descriptionLabel": "description",
"agents.logout": "log out",
Expand Down
9 changes: 9 additions & 0 deletions app/stories/Navigation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react'
import { storiesOf } from '@storybook/react'

import Navigation from '../components/Navigation'

storiesOf('app.Navigation', module)
.add('default', () => (
<Navigation />
))
1 change: 1 addition & 0 deletions app/stories/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require('./Button')
require('./TextField')
require('./AvatarField')
require('./Navigation')
6 changes: 6 additions & 0 deletions app/styles/Navigation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
container: (props) => ({}),
labelText: () => ({
textTransform: 'capitalize'
})
}