2015-06-03 10:04:21 +08:00
|
|
|
React = require 'react'
|
|
|
|
_ = require "underscore"
|
|
|
|
{Flexbox} = require 'nylas-component-kit'
|
|
|
|
classNames = require 'classnames'
|
|
|
|
|
|
|
|
Tabs = require './tabs'
|
2015-10-04 09:11:29 +08:00
|
|
|
TabsStore = require './tabs-store'
|
|
|
|
PluginsActions = require './plugins-actions'
|
2015-06-03 10:04:21 +08:00
|
|
|
|
2015-10-04 09:11:29 +08:00
|
|
|
class PluginsTabs extends React.Component
|
|
|
|
@displayName: 'PluginsTabs'
|
2015-06-03 10:04:21 +08:00
|
|
|
|
|
|
|
@propTypes:
|
|
|
|
'onChange': React.PropTypes.Func
|
|
|
|
|
|
|
|
@containerRequired: false
|
|
|
|
@containerStyles:
|
|
|
|
minWidth: 200
|
|
|
|
maxWidth: 290
|
|
|
|
|
|
|
|
constructor: (@props) ->
|
|
|
|
@state = @_getStateFromStores()
|
|
|
|
|
|
|
|
render: ->
|
2015-10-04 09:11:29 +08:00
|
|
|
<ul className="plugins-view-tabs">
|
2015-06-03 10:04:21 +08:00
|
|
|
{@_renderItems()}
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
_renderItems: ->
|
|
|
|
Tabs.map ({name, key, icon}, idx) =>
|
|
|
|
classes = classNames
|
|
|
|
'tab': true
|
|
|
|
'active': idx is @state.tabIndex
|
2015-10-04 09:11:29 +08:00
|
|
|
<li key={key} className={classes} onClick={ => PluginsActions.selectTabIndex(idx)}>{name}</li>
|
2015-06-03 10:04:21 +08:00
|
|
|
|
|
|
|
componentDidMount: =>
|
|
|
|
@_unsubscribers = []
|
2015-10-04 09:11:29 +08:00
|
|
|
@_unsubscribers.push TabsStore.listen(@_onChange)
|
2015-06-03 10:04:21 +08:00
|
|
|
|
|
|
|
componentWillUnmount: =>
|
|
|
|
unsubscribe() for unsubscribe in @_unsubscribers
|
|
|
|
|
|
|
|
_getStateFromStores: =>
|
2015-10-04 09:11:29 +08:00
|
|
|
tabIndex: TabsStore.tabIndex()
|
2015-06-03 10:04:21 +08:00
|
|
|
|
|
|
|
_onChange: =>
|
|
|
|
@setState(@_getStateFromStores())
|
|
|
|
|
|
|
|
|
2015-10-04 09:11:29 +08:00
|
|
|
module.exports = PluginsTabs
|