Skip to content

Commit a4fec23

Browse files
authored
Merge pull request #51 from react-component/fix-react-15.5-warning
fix react createClass and PropTypes warning
2 parents b9bb160 + 1e486ce commit a4fec23

File tree

8 files changed

+142
-134
lines changed

8 files changed

+142
-134
lines changed

examples/nested.js

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ const popupBorderStyle = {
3737
padding: 10,
3838
};
3939

40-
const Test = React.createClass({
41-
render() {
42-
const innerTrigger = (<div style={popupBorderStyle}>
43-
<div ref="container"/>
40+
const Test = () => {
41+
const innerTrigger = (
42+
<div style={popupBorderStyle}>
43+
<div ref="container" />
4444
<Trigger
4545
popupPlacement="bottom"
4646
action={['click']}
@@ -50,43 +50,45 @@ const Test = React.createClass({
5050
>
5151
<span href="#" style={{ margin: 20 }}>clickToShowInnerTrigger</span>
5252
</Trigger>
53-
</div>);
54-
return (
53+
</div>
54+
);
55+
return (
56+
<div>
5557
<div>
56-
<div>
58+
<Trigger
59+
popupPlacement="left"
60+
action={['click']}
61+
builtinPlacements={builtinPlacements}
62+
popup={<div style={popupBorderStyle}>i am a click popup</div>}
63+
>
64+
<span>
5765
<Trigger
58-
popupPlacement="left"
59-
action={['click']}
60-
builtinPlacements={builtinPlacements}
61-
popup={<div style={popupBorderStyle}>i am a click popup</div>}
62-
>
63-
<span>
64-
<Trigger
65-
popupPlacement="bottom"
66-
action={['hover']}
67-
builtinPlacements={builtinPlacements}
68-
popup={<div style={popupBorderStyle}>i am a hover popup</div>}
69-
>
70-
<span href="#" style={{ margin: 20 }}>trigger</span>
71-
</Trigger>
72-
</span>
73-
</Trigger>
74-
</div>
75-
<div style={{ margin: 50 }}>
76-
<Trigger
77-
popupPlacement="right"
66+
popupPlacement="bottom"
7867
action={['hover']}
7968
builtinPlacements={builtinPlacements}
80-
popup={innerTrigger}
69+
popup={<div style={popupBorderStyle}>i am a hover popup</div>}
8170
>
8271
<span href="#" style={{ margin: 20 }}>trigger</span>
8372
</Trigger>
84-
</div>
73+
</span>
74+
</Trigger>
8575
</div>
86-
);
87-
},
88-
});
76+
<div style={{ margin: 50 }}>
77+
<Trigger
78+
popupPlacement="right"
79+
action={['hover']}
80+
builtinPlacements={builtinPlacements}
81+
popup={innerTrigger}
82+
>
83+
<span href="#" style={{ margin: 20 }}>trigger</span>
84+
</Trigger>
85+
</div>
86+
</div>
87+
);
88+
};
8989

90-
ReactDOM.render(<div style={{ margin: 200 }}>
91-
<Test />
92-
</div>, document.getElementById('__react-content'));
90+
ReactDOM.render(
91+
<div style={{ margin: 200 }}>
92+
<Test />
93+
</div>
94+
, document.getElementById('__react-content'));

examples/simple.js

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -51,33 +51,31 @@ function getPopupContainer(trigger) {
5151
return trigger.parentNode;
5252
}
5353

54-
const Test = React.createClass({
55-
getInitialState() {
56-
return {
57-
mask: false,
58-
maskClosable: false,
59-
placement: 'right',
60-
trigger: {
61-
hover: 1,
62-
},
63-
offsetX: undefined,
64-
offsetY: undefined,
65-
};
66-
},
54+
class Test extends React.Component {
55+
state = {
56+
mask: false,
57+
maskClosable: false,
58+
placement: 'right',
59+
trigger: {
60+
hover: 1,
61+
},
62+
offsetX: undefined,
63+
offsetY: undefined,
64+
};
6765

68-
onPlacementChange(e) {
66+
onPlacementChange = (e) => {
6967
this.setState({
7068
placement: e.target.value,
7169
});
72-
},
70+
}
7371

74-
onTransitionChange(e) {
72+
onTransitionChange = (e) => {
7573
this.setState({
7674
transitionName: e.target.checked ? e.target.value : '',
7775
});
78-
},
76+
}
7977

80-
onTriggerChange(e) {
78+
onTriggerChange = (e) => {
8179
const trigger = assign({}, this.state.trigger);
8280
if (e.target.checked) {
8381
trigger[e.target.value] = 1;
@@ -87,49 +85,49 @@ const Test = React.createClass({
8785
this.setState({
8886
trigger,
8987
});
90-
},
88+
}
9189

92-
onOffsetXChange(e) {
90+
onOffsetXChange = (e) => {
9391
const targetValue = e.target.value;
9492
this.setState({
9593
offsetX: targetValue || undefined,
9694
});
97-
},
95+
}
9896

99-
onOffsetYChange(e) {
97+
onOffsetYChange = (e) => {
10098
const targetValue = e.target.value;
10199
this.setState({
102100
offsetY: targetValue || undefined,
103101
});
104-
},
102+
}
105103

106-
onVisibleChange(visible) {
104+
onVisibleChange = (visible) => {
107105
console.log('tooltip', visible);
108-
},
106+
}
109107

110-
onMask(e) {
108+
onMask = (e) => {
111109
this.setState({
112110
mask: e.target.checked,
113111
});
114-
},
112+
}
115113

116-
onMaskClosable(e) {
114+
onMaskClosable = (e) => {
117115
this.setState({
118116
maskClosable: e.target.checked,
119117
});
120-
},
118+
}
121119

122-
destroy() {
120+
destroy = () => {
123121
this.setState({
124122
destroyed: true,
125123
});
126-
},
124+
}
127125

128-
destroyPopupOnHide(e) {
126+
destroyPopupOnHide = (e) => {
129127
this.setState({
130128
destroyPopupOnHide: e.target.checked,
131129
});
132-
},
130+
}
133131

134132
render() {
135133
const state = this.state;
@@ -270,10 +268,7 @@ const Test = React.createClass({
270268
</Trigger>
271269
</div>
272270
</div>);
273-
},
274-
});
271+
}
272+
}
275273

276-
ReactDOM.render(
277-
<div>
278-
<Test />
279-
</div>, document.getElementById('__react-content'));
274+
ReactDOM.render(<Test />, document.getElementById('__react-content'));

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,17 @@
4646
"pre-commit": "1.x",
4747
"rc-tools": "5.x",
4848
"react": "15.x",
49-
"react-addons-test-utils": "15.x",
5049
"react-dom": "15.x"
5150
},
5251
"pre-commit": [
5352
"lint"
5453
],
5554
"dependencies": {
5655
"babel-runtime": "6.x",
56+
"create-react-class": "^15.5.2",
57+
"prop-types": "^15.5.8",
5758
"rc-align": "2.x",
58-
"rc-util": "4.x",
59-
"rc-animate": "2.x"
59+
"rc-animate": "2.x",
60+
"rc-util": "4.x"
6061
}
6162
}

src/LazyRenderBox.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
import React, { PropTypes } from 'react';
1+
import React, { Component } from 'react';
2+
import PropTypes from 'prop-types';
23

3-
const LazyRenderBox = React.createClass({
4-
propTypes: {
4+
class LazyRenderBox extends Component {
5+
static propTypes = {
56
children: PropTypes.any,
67
className: PropTypes.string,
78
visible: PropTypes.bool,
89
hiddenClassName: PropTypes.string,
9-
},
10+
};
1011
shouldComponentUpdate(nextProps) {
1112
return nextProps.hiddenClassName || nextProps.visible;
12-
},
13+
}
1314
render() {
1415
const { hiddenClassName, visible, ...props } = this.props;
1516

@@ -21,7 +22,7 @@ const LazyRenderBox = React.createClass({
2122
}
2223

2324
return React.Children.only(props.children);
24-
},
25-
});
25+
}
26+
}
2627

2728
export default LazyRenderBox;

src/Popup.jsx

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import React, { PropTypes } from 'react';
1+
import React, { Component } from 'react';
2+
import PropTypes from 'prop-types';
23
import ReactDOM from 'react-dom';
34
import Align from 'rc-align';
45
import Animate from 'rc-animate';
56
import PopupInner from './PopupInner';
67
import LazyRenderBox from './LazyRenderBox';
78

8-
const Popup = React.createClass({
9-
propTypes: {
9+
class Popup extends Component {
10+
static propTypes = {
1011
visible: PropTypes.bool,
1112
style: PropTypes.object,
1213
getClassNameFromAlign: PropTypes.func,
@@ -18,13 +19,13 @@ const Popup = React.createClass({
1819
className: PropTypes.string,
1920
prefixCls: PropTypes.string,
2021
onMouseLeave: PropTypes.func,
21-
},
22+
};
2223

2324
componentDidMount() {
2425
this.rootNode = this.getPopupDomNode();
25-
},
26+
}
2627

27-
onAlign(popupDomNode, align) {
28+
onAlign = (popupDomNode, align) => {
2829
const props = this.props;
2930
const alignClassName = props.getClassNameFromAlign(props.align);
3031
const currentAlignClassName = props.getClassNameFromAlign(align);
@@ -33,15 +34,15 @@ const Popup = React.createClass({
3334
popupDomNode.className = this.getClassName(currentAlignClassName);
3435
}
3536
props.onAlign(popupDomNode, align);
36-
},
37+
}
3738

3839
getPopupDomNode() {
3940
return ReactDOM.findDOMNode(this.refs.popup);
40-
},
41+
}
4142

42-
getTarget() {
43+
getTarget = () => {
4344
return this.props.getRootDomNode();
44-
},
45+
}
4546

4647
getMaskTransitionName() {
4748
const props = this.props;
@@ -51,7 +52,7 @@ const Popup = React.createClass({
5152
transitionName = `${props.prefixCls}-${animation}`;
5253
}
5354
return transitionName;
54-
},
55+
}
5556

5657
getTransitionName() {
5758
const props = this.props;
@@ -60,11 +61,11 @@ const Popup = React.createClass({
6061
transitionName = `${props.prefixCls}-${props.animation}`;
6162
}
6263
return transitionName;
63-
},
64+
}
6465

6566
getClassName(currentAlignClassName) {
6667
return `${this.props.prefixCls} ${this.props.className} ${currentAlignClassName}`;
67-
},
68+
}
6869

6970
getPopupElement() {
7071
const props = this.props;
@@ -137,7 +138,7 @@ const Popup = React.createClass({
137138
</PopupInner>
138139
</Align>
139140
</Animate>);
140-
},
141+
}
141142

142143
getZIndexStyle() {
143144
const style = {};
@@ -146,7 +147,7 @@ const Popup = React.createClass({
146147
style.zIndex = props.zIndex;
147148
}
148149
return style;
149-
},
150+
}
150151

151152
getMaskElement() {
152153
const props = this.props;
@@ -177,17 +178,20 @@ const Popup = React.createClass({
177178
}
178179
}
179180
return maskElement;
180-
},
181-
saveAlign(align) {
181+
}
182+
183+
saveAlign = (align) => {
182184
this.alignInstance = align;
183-
},
185+
}
184186

185187
render() {
186-
return (<div>
187-
{this.getMaskElement()}
188-
{this.getPopupElement()}
189-
</div>);
190-
},
191-
});
188+
return (
189+
<div>
190+
{this.getMaskElement()}
191+
{this.getPopupElement()}
192+
</div>
193+
);
194+
}
195+
}
192196

193197
export default Popup;

0 commit comments

Comments
 (0)