Skip to content

Commit

Permalink
Pure <Tabs>
Browse files Browse the repository at this point in the history
  • Loading branch information
soyjavi committed Nov 11, 2015
1 parent bcec735 commit 42b9496
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 27 deletions.
2 changes: 1 addition & 1 deletion components/tabs/tab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Tab extends React.Component {
};

componentDidMount () {
this.active(this.props.active);
if (this.props.active) this.active(this.props.active);
}

componentWillReceiveProps (next_props) {
Expand Down
16 changes: 3 additions & 13 deletions components/tabs/tabs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,13 @@ class Tabs extends React.Component {

componentDidMount () {
setTimeout(() => {
this.setState({pointer: this._pointerPosition(this.state.index)});
this.setState({pointer: this._pointerPosition(this.props.index)});
}, 20);
}

componentWillReceiveProps (next_props) {
const index = next_props.index || this.state.index;
this.setState({
index,
pointer: this._pointerPosition(index)
});
this.setState({ index, pointer: this._pointerPosition(index) });
}

_pointerPosition (index = 0) {
Expand All @@ -48,7 +45,7 @@ class Tabs extends React.Component {
index,
pointer: this._pointerPosition(index)
});
if (this.props.onChange) this.props.onChange(this);
if (this.props.onChange) this.props.onChange(index);
};

renderLabels (labels) {
Expand Down Expand Up @@ -91,13 +88,6 @@ class Tabs extends React.Component {
</div>
);
}

active (value) {
this.setState({active: value});
if (this.props.onActive && value) {
this.props.onActive(this);
}
}
}

export default Tabs;
39 changes: 26 additions & 13 deletions spec/components/tabs.jsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
import React from 'react';
import { Tabs, Tab } from '../../components/tabs';

const TabsTest = () => (
<section>
<h5>Tabs</h5>
<p>This tabs can be disabled or hidden</p>
class TabsTest extends React.Component {

<Tabs>
<Tab label='Primary'><small>Primary content</small></Tab>
<Tab label='Secondary'><small>Secondary content</small></Tab>
<Tab label='Third' disabled><small>Disabled content</small></Tab>
<Tab label='Fourth' hidden><small>Fourth content hidden</small></Tab>
<Tab label='Fifth'><small>Fifth content</small></Tab>
</Tabs>
</section>
);
state = {
index: 1
};

handleTabsOnChange = (index) => {
console.log('handleTabsOnChange', index);
};

render () {
return (
<section>
<h5>Tabs</h5>
<p>This tabs can be disabled or hidden</p>

<Tabs index={this.state.index} onChange={this.handleTabsOnChange}>
<Tab label='Primary'><small>Primary content</small></Tab>
<Tab label='Secondary'><small>Secondary content</small></Tab>
<Tab label='Third' disabled><small>Disabled content</small></Tab>
<Tab label='Fourth' hidden><small>Fourth content hidden</small></Tab>
<Tab label='Fifth'><small>Fifth content</small></Tab>
</Tabs>
</section>
);
}
}

export default TabsTest;

0 comments on commit 42b9496

Please sign in to comment.