nifty-wallet/ui/app/components/tab-bar.js

48 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-10-22 22:40:03 -07:00
const { Component } = require('react')
2016-11-04 12:00:56 -07:00
const h = require('react-hyperscript')
2017-11-01 19:30:33 -07:00
const PropTypes = require('react').PropTypes
2017-10-22 22:40:03 -07:00
const classnames = require('classnames')
2016-11-04 12:00:56 -07:00
2017-10-22 22:40:03 -07:00
class TabBar extends Component {
constructor (props) {
super(props)
const { defaultTab, tabs } = props
2016-11-04 12:00:56 -07:00
2017-10-22 22:40:03 -07:00
this.state = {
subview: defaultTab || tabs[0].key,
}
}
2016-11-04 12:00:56 -07:00
2017-10-22 22:40:03 -07:00
render () {
const { tabs = [], tabSelected } = this.props
const { subview } = this.state
2016-11-04 12:00:56 -07:00
2017-10-22 22:40:03 -07:00
return (
h('.tab-bar', {}, [
tabs.map((tab) => {
const { key, content } = tab
return h('div', {
className: classnames('tab-bar__tab pointer', {
'tab-bar__tab--active': subview === key,
}),
onClick: () => {
this.setState({ subview: key })
tabSelected(key)
},
key,
}, content)
}),
h('div.tab-bar__tab.tab-bar__grow-tab'),
])
)
}
2016-11-04 12:00:56 -07:00
}
2017-11-01 19:30:33 -07:00
TabBar.propTypes = {
defaultTab: PropTypes.string,
tabs: PropTypes.array,
tabSelected: PropTypes.func,
}
2017-10-22 22:40:03 -07:00
module.exports = TabBar