1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-27 21:00:13 +01:00
metamask-extension/ui/app/components/tab-bar.js

48 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-10-23 07:40:03 +02:00
const { Component } = require('react')
2016-11-04 20:00:56 +01:00
const h = require('react-hyperscript')
const PropTypes = require('prop-types')
2017-10-23 07:40:03 +02:00
const classnames = require('classnames')
2016-11-04 20:00:56 +01:00
2017-10-23 07:40:03 +02:00
class TabBar extends Component {
constructor (props) {
super(props)
const { defaultTab, tabs } = props
2016-11-04 20:00:56 +01:00
2017-10-23 07:40:03 +02:00
this.state = {
subview: defaultTab || tabs[0].key,
}
}
2016-11-04 20:00:56 +01:00
2017-10-23 07:40:03 +02:00
render () {
const { tabs = [], tabSelected } = this.props
const { subview } = this.state
2016-11-04 20:00:56 +01:00
2017-10-23 07:40:03 +02: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 20:00:56 +01:00
}
2017-11-02 03:30:33 +01:00
TabBar.propTypes = {
defaultTab: PropTypes.string,
tabs: PropTypes.array,
tabSelected: PropTypes.func,
}
2017-10-23 07:40:03 +02:00
module.exports = TabBar