Skip to content

Commit 8ae5112

Browse files
committed
Merge branch 'use-es6-class' of https://github.com/LeoAJ/react-tabs into dev-1.0
2 parents 3649d50 + 3bd9935 commit 8ae5112

File tree

5 files changed

+83
-84
lines changed

5 files changed

+83
-84
lines changed

src/components/Tab.js

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import React, { PropTypes } from 'react';
1+
import React, { PropTypes, Component } from 'react';
22
import cx from 'classnames';
33

4-
module.exports = React.createClass({
5-
displayName: 'Tab',
4+
class Tab extends Component {
65

7-
propTypes: {
6+
static propTypes = {
87
className: PropTypes.string,
98
id: PropTypes.string,
109
tabRef: PropTypes.func,
@@ -19,32 +18,30 @@ module.exports = React.createClass({
1918
PropTypes.object,
2019
PropTypes.string,
2120
]),
22-
},
21+
};
2322

24-
getDefaultProps() {
25-
return {
26-
focus: false,
27-
selected: false,
28-
id: null,
29-
panelId: null,
30-
activeTabClassName: 'ReactTabs__Tab--selected',
31-
disabledTabClassName: 'ReactTabs__Tab--disabled',
32-
};
33-
},
23+
static defaultProps = {
24+
focus: false,
25+
selected: false,
26+
id: null,
27+
panelId: null,
28+
activeTabClassName: 'ReactTabs__Tab--selected',
29+
disabledTabClassName: 'ReactTabs__Tab--disabled',
30+
};
3431

3532
componentDidMount() {
3633
this.checkFocus();
37-
},
34+
}
3835

3936
componentDidUpdate() {
4037
this.checkFocus();
41-
},
38+
}
4239

4340
checkFocus() {
4441
if (this.props.selected && this.props.focus) {
4542
this.node.focus();
4643
}
47-
},
44+
}
4845

4946
render() {
5047
const {
@@ -82,5 +79,7 @@ module.exports = React.createClass({
8279
{children}
8380
</li>
8481
);
85-
},
86-
});
82+
}
83+
}
84+
85+
export default Tab;

src/components/TabList.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { PropTypes } from 'react';
1+
import React, { PropTypes, Component } from 'react';
22
import cx from 'classnames';
33
import Tab from './Tab';
44

@@ -20,18 +20,17 @@ function renderChildren(props) {
2020
});
2121
}
2222

23-
module.exports = React.createClass({
24-
displayName: 'TabList',
23+
class TabList extends Component {
2524

26-
propTypes: {
25+
static propTypes = {
2726
className: PropTypes.string,
2827
activeTabClassName: PropTypes.string,
2928
disabledTabClassName: PropTypes.string,
3029
children: PropTypes.oneOfType([
3130
PropTypes.object,
3231
PropTypes.array,
3332
]),
34-
},
33+
};
3534

3635
render() {
3736
const {
@@ -53,5 +52,7 @@ module.exports = React.createClass({
5352
{renderChildren({ activeTabClassName, disabledTabClassName, children })}
5453
</ul>
5554
);
56-
},
57-
});
55+
}
56+
}
57+
58+
export default TabList;

src/components/TabPanel.js

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import React, { PropTypes } from 'react';
1+
import React, { PropTypes, Component } from 'react';
22
import cx from 'classnames';
33

4-
module.exports = React.createClass({
5-
displayName: 'TabPanel',
4+
class TabPanel extends Component {
65

7-
propTypes: {
6+
static propTypes = {
87
children: PropTypes.oneOfType([
98
PropTypes.array,
109
PropTypes.object,
@@ -15,23 +14,20 @@ module.exports = React.createClass({
1514
selected: PropTypes.bool,
1615
style: PropTypes.object,
1716
tabId: PropTypes.string,
18-
},
17+
};
1918

20-
contextTypes: {
19+
static contextTypes = {
2120
forceRenderTabPanel: PropTypes.bool,
22-
},
21+
};
2322

24-
getDefaultProps() {
25-
return {
26-
selected: false,
27-
id: null,
28-
tabId: null,
29-
};
30-
},
23+
static defaultProps = {
24+
selected: false,
25+
id: null,
26+
tabId: null,
27+
};
3128

3229
render() {
3330
const { className, children, selected, id, tabId, style, ...attributes } = this.props;
34-
3531
return (
3632
<div
3733
{...attributes}
@@ -50,5 +46,7 @@ module.exports = React.createClass({
5046
{(this.context.forceRenderTabPanel || selected) ? children : null}
5147
</div>
5248
);
53-
},
54-
});
49+
}
50+
}
51+
52+
export default TabPanel;

src/components/Tabs.js

Lines changed: 39 additions & 39 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 cx from 'classnames';
33
import jss from 'js-stylesheet';
44
import uuid from '../helpers/uuid';
@@ -17,58 +17,56 @@ function isTabDisabled(node) {
1717

1818
let useDefaultStyles = true;
1919

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

23-
propTypes: {
22+
static propTypes = {
2423
className: PropTypes.string,
2524
selectedIndex: PropTypes.number, // eslint-disable-line react/no-unused-prop-types
2625
onSelect: PropTypes.func,
2726
focus: PropTypes.bool, // eslint-disable-line react/no-unused-prop-types
2827
children: childrenPropType,
2928
forceRenderTabPanel: PropTypes.bool,
30-
},
29+
};
3130

32-
childContextTypes: {
31+
static childContextTypes = {
3332
forceRenderTabPanel: PropTypes.bool,
34-
},
33+
};
3534

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

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

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

5452
getChildContext() {
5553
return {
5654
forceRenderTabPanel: this.props.forceRenderTabPanel,
5755
};
58-
},
56+
}
5957

6058
componentDidMount() {
6159
if (useDefaultStyles) {
6260
jss(require('../helpers/styles')); // eslint-disable-line global-require
6361
}
64-
},
62+
}
6563

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

7371
setSelected(index, focus) {
7472
// Don't do anything if nothing has changed
@@ -91,7 +89,7 @@ module.exports = React.createClass({
9189
// Update selected index
9290
this.setState({ selectedIndex: index, focus: focus === true });
9391
}
94-
},
92+
}
9593

9694
getNextTab(index) {
9795
const count = this.getTabsCount();
@@ -112,7 +110,7 @@ module.exports = React.createClass({
112110

113111
// No tabs are disabled, return index
114112
return index;
115-
},
113+
}
116114

117115
getPrevTab(index) {
118116
let i = index;
@@ -134,21 +132,21 @@ module.exports = React.createClass({
134132

135133
// No tabs are disabled, return index
136134
return index;
137-
},
135+
}
138136

139137
getTabsCount() {
140138
return this.props.children && this.props.children[0] ?
141139
React.Children.count(this.props.children[0].props.children) :
142140
0;
143-
},
141+
}
144142

145143
getPanelsCount() {
146144
return React.Children.count(this.props.children.slice(1));
147-
},
145+
}
148146

149147
getTab(index) {
150148
return this.tabNodes[`tabs-${index}`];
151-
},
149+
}
152150

153151
getChildren() {
154152
let index = 0;
@@ -230,9 +228,9 @@ module.exports = React.createClass({
230228

231229
return result;
232230
});
233-
},
231+
}
234232

235-
tabNodes: [],
233+
tabNodes: [];
236234

237235
handleKeyDown(e) {
238236
if (this.isTabFromContainer(e.target)) {
@@ -258,7 +256,7 @@ module.exports = React.createClass({
258256

259257
this.setSelected(index, true);
260258
}
261-
},
259+
}
262260

263261
handleClick(e) {
264262
let node = e.target;
@@ -273,7 +271,7 @@ module.exports = React.createClass({
273271
return;
274272
}
275273
} while ((node = node.parentNode) !== null);
276-
},
274+
}
277275

278276
// This is an anti-pattern, so sue me
279277
copyPropsToState(props, state) {
@@ -299,7 +297,7 @@ module.exports = React.createClass({
299297
selectedIndex,
300298
focus: props.focus,
301299
};
302-
},
300+
}
303301

304302
/**
305303
* Determine if a node from event.target is a Tab element for the current Tabs container.
@@ -322,7 +320,7 @@ module.exports = React.createClass({
322320
} while (nodeAncestor);
323321

324322
return false;
325-
},
323+
}
326324

327325
render() {
328326
// This fixes an issue with focus management.
@@ -371,5 +369,7 @@ module.exports = React.createClass({
371369
{this.getChildren()}
372370
</div>
373371
);
374-
},
375-
});
372+
}
373+
}
374+
375+
export default Tabs;

src/helpers/childrenPropType.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import Tab from '../components/Tab';
33
import TabList from '../components/TabList';
4+
import TabPanel from '../components/TabPanel';
45

56
module.exports = function childrenPropTypes(props, propName) {
67
let error;
@@ -27,7 +28,7 @@ module.exports = function childrenPropTypes(props, propName) {
2728
tabsCount++;
2829
}
2930
});
30-
} else if (child.type.displayName === 'TabPanel') {
31+
} else if (child.type === TabPanel) {
3132
panelsCount++;
3233
} else {
3334
error = new Error(

0 commit comments

Comments
 (0)