Skip to content

Commit 6e8229e

Browse files
committed
add tabs
1 parent deff1e7 commit 6e8229e

File tree

1 file changed

+40
-40
lines changed

1 file changed

+40
-40
lines changed

src/components/Tabs.js

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { PropTypes, cloneElement } from 'react';
1+
import React, { PropTypes, cloneElement, Component } from 'react';
22
import { findDOMNode } from 'react-dom';
33
import cx from 'classnames';
44
import jss from 'js-stylesheet';
@@ -18,58 +18,56 @@ function isTabDisabled(node) {
1818

1919
let useDefaultStyles = true;
2020

21-
module.exports = React.createClass({
22-
displayName: 'Tabs',
21+
class Tabs extends Component {
2322

24-
propTypes: {
23+
static propTypes = {
2524
className: PropTypes.string,
2625
selectedIndex: PropTypes.number,
2726
onSelect: PropTypes.func,
2827
focus: PropTypes.bool,
2928
children: childrenPropType,
3029
forceRenderTabPanel: PropTypes.bool,
31-
},
30+
};
3231

33-
childContextTypes: {
32+
static childContextTypes = {
3433
forceRenderTabPanel: PropTypes.bool,
35-
},
34+
};
3635

37-
statics: {
38-
setUseDefaultStyles(use) {
39-
useDefaultStyles = use;
40-
},
41-
},
36+
static defaultProps = {
37+
selectedIndex: -1,
38+
focus: false,
39+
forceRenderTabPanel: false,
40+
};
4241

43-
getDefaultProps() {
44-
return {
45-
selectedIndex: -1,
46-
focus: false,
47-
forceRenderTabPanel: false,
48-
};
49-
},
42+
static setUseDefaultStyles = (use) => {
43+
useDefaultStyles = use;
44+
};
5045

51-
getInitialState() {
52-
return this.copyPropsToState(this.props, this.state);
53-
},
46+
constructor(props) {
47+
super(props);
48+
this.state = this.copyPropsToState(this.props, this.state);
49+
this.handleClick = this.handleClick.bind(this);
50+
this.handleKeyDown = this.handleKeyDown.bind(this);
51+
}
5452

5553
getChildContext() {
5654
return {
5755
forceRenderTabPanel: this.props.forceRenderTabPanel,
5856
};
59-
},
57+
}
6058

6159
componentDidMount() {
6260
if (useDefaultStyles) {
6361
jss(require('../helpers/styles.js')); // eslint-disable-line global-require
6462
}
65-
},
63+
}
6664

6765
componentWillReceiveProps(newProps) {
6866
// Use a transactional update to prevent race conditions
6967
// when reading the state in copyPropsToState
7068
// See https://github.com/reactjs/react-tabs/issues/51
7169
this.setState(state => this.copyPropsToState(newProps, state));
72-
},
70+
}
7371

7472
setSelected(index, focus) {
7573
// Don't do anything if nothing has changed
@@ -92,7 +90,7 @@ module.exports = React.createClass({
9290
// Update selected index
9391
this.setState({ selectedIndex: index, focus: focus === true });
9492
}
95-
},
93+
}
9694

9795
getNextTab(index) {
9896
const count = this.getTabsCount();
@@ -115,7 +113,7 @@ module.exports = React.createClass({
115113

116114
// No tabs are disabled, return index
117115
return index;
118-
},
116+
}
119117

120118
getPrevTab(index) {
121119
let i = index;
@@ -139,29 +137,29 @@ module.exports = React.createClass({
139137

140138
// No tabs are disabled, return index
141139
return index;
142-
},
140+
}
143141

144142
getTabsCount() {
145143
return this.props.children && this.props.children[0] ?
146144
React.Children.count(this.props.children[0].props.children) :
147145
0;
148-
},
146+
}
149147

150148
getPanelsCount() {
151149
return React.Children.count(this.props.children.slice(1));
152-
},
150+
}
153151

154152
getTabList() {
155153
return this.refs.tablist;
156-
},
154+
}
157155

158156
getTab(index) {
159157
return this.refs[`tabs-${index}`];
160-
},
158+
}
161159

162160
getPanel(index) {
163161
return this.refs[`panels-${index}`];
164-
},
162+
}
165163

166164
getChildren() {
167165
let index = 0;
@@ -246,7 +244,7 @@ module.exports = React.createClass({
246244

247245
return result;
248246
});
249-
},
247+
}
250248

251249
handleKeyDown(e) {
252250
if (this.isTabFromContainer(e.target)) {
@@ -272,7 +270,7 @@ module.exports = React.createClass({
272270

273271
this.setSelected(index, true);
274272
}
275-
},
273+
}
276274

277275
handleClick(e) {
278276
let node = e.target;
@@ -287,7 +285,7 @@ module.exports = React.createClass({
287285
return;
288286
}
289287
} while ((node = node.parentNode) !== null);
290-
},
288+
}
291289

292290
// This is an anti-pattern, so sue me
293291
copyPropsToState(props, state) {
@@ -313,7 +311,7 @@ module.exports = React.createClass({
313311
selectedIndex,
314312
focus: props.focus,
315313
};
316-
},
314+
}
317315

318316
/**
319317
* Determine if a node from event.target is a Tab element for the current Tabs container.
@@ -337,7 +335,7 @@ module.exports = React.createClass({
337335
} while (nodeAncestor);
338336

339337
return false;
340-
},
338+
}
341339

342340
render() {
343341
// This fixes an issue with focus management.
@@ -385,5 +383,7 @@ module.exports = React.createClass({
385383
{this.getChildren()}
386384
</div>
387385
);
388-
},
389-
});
386+
}
387+
}
388+
389+
export default Tabs;

0 commit comments

Comments
 (0)