1
- import React , { PropTypes , cloneElement } from 'react' ;
1
+ import React , { PropTypes , cloneElement , Component } from 'react' ;
2
2
import { findDOMNode } from 'react-dom' ;
3
3
import cx from 'classnames' ;
4
4
import jss from 'js-stylesheet' ;
@@ -18,58 +18,56 @@ function isTabDisabled(node) {
18
18
19
19
let useDefaultStyles = true ;
20
20
21
- module . exports = React . createClass ( {
22
- displayName : 'Tabs' ,
21
+ class Tabs extends Component {
23
22
24
- propTypes : {
23
+ static propTypes = {
25
24
className : PropTypes . string ,
26
25
selectedIndex : PropTypes . number ,
27
26
onSelect : PropTypes . func ,
28
27
focus : PropTypes . bool ,
29
28
children : childrenPropType ,
30
29
forceRenderTabPanel : PropTypes . bool ,
31
- } ,
30
+ } ;
32
31
33
- childContextTypes : {
32
+ static childContextTypes = {
34
33
forceRenderTabPanel : PropTypes . bool ,
35
- } ,
34
+ } ;
36
35
37
- statics : {
38
- setUseDefaultStyles ( use ) {
39
- useDefaultStyles = use ;
40
- } ,
41
- } ,
36
+ static defaultProps = {
37
+ selectedIndex : - 1 ,
38
+ focus : false ,
39
+ forceRenderTabPanel : false ,
40
+ } ;
42
41
43
- getDefaultProps ( ) {
44
- return {
45
- selectedIndex : - 1 ,
46
- focus : false ,
47
- forceRenderTabPanel : false ,
48
- } ;
49
- } ,
42
+ static setUseDefaultStyles = ( use ) => {
43
+ useDefaultStyles = use ;
44
+ } ;
50
45
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
+ }
54
52
55
53
getChildContext ( ) {
56
54
return {
57
55
forceRenderTabPanel : this . props . forceRenderTabPanel ,
58
56
} ;
59
- } ,
57
+ }
60
58
61
59
componentDidMount ( ) {
62
60
if ( useDefaultStyles ) {
63
61
jss ( require ( '../helpers/styles.js' ) ) ; // eslint-disable-line global-require
64
62
}
65
- } ,
63
+ }
66
64
67
65
componentWillReceiveProps ( newProps ) {
68
66
// Use a transactional update to prevent race conditions
69
67
// when reading the state in copyPropsToState
70
68
// See https://github.com/reactjs/react-tabs/issues/51
71
69
this . setState ( state => this . copyPropsToState ( newProps , state ) ) ;
72
- } ,
70
+ }
73
71
74
72
setSelected ( index , focus ) {
75
73
// Don't do anything if nothing has changed
@@ -92,7 +90,7 @@ module.exports = React.createClass({
92
90
// Update selected index
93
91
this . setState ( { selectedIndex : index , focus : focus === true } ) ;
94
92
}
95
- } ,
93
+ }
96
94
97
95
getNextTab ( index ) {
98
96
const count = this . getTabsCount ( ) ;
@@ -115,7 +113,7 @@ module.exports = React.createClass({
115
113
116
114
// No tabs are disabled, return index
117
115
return index ;
118
- } ,
116
+ }
119
117
120
118
getPrevTab ( index ) {
121
119
let i = index ;
@@ -139,29 +137,29 @@ module.exports = React.createClass({
139
137
140
138
// No tabs are disabled, return index
141
139
return index ;
142
- } ,
140
+ }
143
141
144
142
getTabsCount ( ) {
145
143
return this . props . children && this . props . children [ 0 ] ?
146
144
React . Children . count ( this . props . children [ 0 ] . props . children ) :
147
145
0 ;
148
- } ,
146
+ }
149
147
150
148
getPanelsCount ( ) {
151
149
return React . Children . count ( this . props . children . slice ( 1 ) ) ;
152
- } ,
150
+ }
153
151
154
152
getTabList ( ) {
155
153
return this . refs . tablist ;
156
- } ,
154
+ }
157
155
158
156
getTab ( index ) {
159
157
return this . refs [ `tabs-${ index } ` ] ;
160
- } ,
158
+ }
161
159
162
160
getPanel ( index ) {
163
161
return this . refs [ `panels-${ index } ` ] ;
164
- } ,
162
+ }
165
163
166
164
getChildren ( ) {
167
165
let index = 0 ;
@@ -246,7 +244,7 @@ module.exports = React.createClass({
246
244
247
245
return result ;
248
246
} ) ;
249
- } ,
247
+ }
250
248
251
249
handleKeyDown ( e ) {
252
250
if ( this . isTabFromContainer ( e . target ) ) {
@@ -272,7 +270,7 @@ module.exports = React.createClass({
272
270
273
271
this . setSelected ( index , true ) ;
274
272
}
275
- } ,
273
+ }
276
274
277
275
handleClick ( e ) {
278
276
let node = e . target ;
@@ -287,7 +285,7 @@ module.exports = React.createClass({
287
285
return ;
288
286
}
289
287
} while ( ( node = node . parentNode ) !== null ) ;
290
- } ,
288
+ }
291
289
292
290
// This is an anti-pattern, so sue me
293
291
copyPropsToState ( props , state ) {
@@ -313,7 +311,7 @@ module.exports = React.createClass({
313
311
selectedIndex,
314
312
focus : props . focus ,
315
313
} ;
316
- } ,
314
+ }
317
315
318
316
/**
319
317
* Determine if a node from event.target is a Tab element for the current Tabs container.
@@ -337,7 +335,7 @@ module.exports = React.createClass({
337
335
} while ( nodeAncestor ) ;
338
336
339
337
return false ;
340
- } ,
338
+ }
341
339
342
340
render ( ) {
343
341
// This fixes an issue with focus management.
@@ -385,5 +383,7 @@ module.exports = React.createClass({
385
383
{ this . getChildren ( ) }
386
384
</ div >
387
385
) ;
388
- } ,
389
- } ) ;
386
+ }
387
+ }
388
+
389
+ export default Tabs ;
0 commit comments