<Tabs> and <Tab> finished

old
Javi 2015-08-16 16:33:11 +07:00
parent 7241505a53
commit 6b5259d081
4 changed files with 65 additions and 11 deletions

View File

@ -19,19 +19,19 @@ module.exports = React.createClass
# -- Lifecycle # -- Lifecycle
componentDidMount: -> componentDidMount: ->
@setState pointer: @pointerPosition @state.index @setState pointer: _pointerPosition @state.index, @refs.navigation.getDOMNode()
componentWillReceiveProps: (next_props) -> componentWillReceiveProps: (next_props) ->
index = next_props.index or @state.index index = next_props.index or @state.index
@setState @setState
index : index index : index
pointer : @pointerPosition index pointer : _pointerPosition index, @refs.navigation.getDOMNode()
# -- Events # -- Events
onClick: (index, event, ref) -> onClick: (index, event, ref) ->
@setState @setState
index : index index : index
pointer : @pointerPosition index pointer : _pointerPosition index, @refs.navigation.getDOMNode()
@props.onChange? @ @props.onChange? @
# -- Render # -- Render
@ -65,9 +65,8 @@ module.exports = React.createClass
{ tabs } { tabs }
</div> </div>
# -- Private methods # -- Private methods
pointerPosition: (index = 0) -> _pointerPosition = (index = 0, navigation) ->
navigation = @refs.navigation.getDOMNode()
label = navigation.children[index].getBoundingClientRect() label = navigation.children[index].getBoundingClientRect()
style = style =
top : "#{navigation.getBoundingClientRect().height}px" top : "#{navigation.getBoundingClientRect().height}px"

50
components/tabs/tabs.md Normal file
View File

@ -0,0 +1,50 @@
# Tabs
```javascript
Tabs = require('../../components/tabs').Tabs
Tab = require('../../components/tabs').Tab
<Tabs>
<Tab label='Primary'>
<small>primary</small>
</Tab>
<Tab label='Secondary'>
<small>secondary</small>
</Tab>
<Tab label='Third' disabled>
<small>third</small>
</Tab>
<Tab label='Fourth' hidden>
<small>fourth</small>
</Tab>
</Tabs>
```
## Properties <Tabs>
| Name | Type | Default | Description|
|:- |:-: | :- |:-|
| **className** | String | `''` | Additional class name to provide custom styling.|
| **index** | Number | `0` | Current <Tab> |
| **onChange** | Function | | Callback function that is fired when the tab changes.
## Properties <Tab>
| Name | Type | Default | Description|
|:- |:-: | :- |:-|
| **active** | Boolean | `false` | If true, the current component is visible.|
| **className** | String | `''` | Additional class name to provide custom styling.|
| **disabled** | Boolean | `false` | If true, the current component is not clickable.|
| **hidden** | Boolean | `false` | If true, the current component is not visible.|
| **label** | String | | Label for navigation|
| **onActive** | Function | | Callback function that is fired when the tab is activated. |
| **tabIndex** | Number | | Sets the tabindex html attribute.|
## Methods <Tab>
#### active
Active/Deactive a determinate instance of the <Tab> component.
```
tab_instance.active(true);
```

View File

@ -19,5 +19,8 @@ module.exports = React.createClass
<Tab label='Fourth' hidden> <Tab label='Fourth' hidden>
<small>Fourth</small> <small>Fourth</small>
</Tab> </Tab>
<Tab label='Fifth'>
<small>Fifth</small>
</Tab>
</Tabs> </Tabs>
</section> </section>

View File

@ -12,6 +12,7 @@ Form = require './components/form'
Progress = require './components/progress' Progress = require './components/progress'
Slider = require './components/slider' Slider = require './components/slider'
Switch = require './components/switch' Switch = require './components/switch'
Tabs = require './components/tabs'
Test = React.createClass Test = React.createClass
@ -31,6 +32,7 @@ Test = React.createClass
<Progress /> <Progress />
<Slider /> <Slider />
<Switch /> <Switch />
<Tabs />
</app> </app>
React.render <Test/>, document.body React.render <Test/>, document.body