Skip to content

Commit 34cd9b1

Browse files
authored
Merge pull request #41 from dozoisch/react_15_5
Changed updated for react 15.5
2 parents 8afd4c0 + 72233da commit 34cd9b1

File tree

4 files changed

+57
-55
lines changed

4 files changed

+57
-55
lines changed

package.json

+8-6
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
},
3535
"homepage": "https://github.com/dozoisch/react-google-recaptcha",
3636
"peerDependencies": {
37-
"react": ">=0.14",
38-
"react-async-script": ">= 0.6.0"
37+
"react": ">=0.15.5",
38+
"react-async-script": ">= 0.9.0"
3939
},
4040
"devDependencies": {
4141
"babel-cli": "^6.0.0",
@@ -65,11 +65,13 @@
6565
"mocha": "~2.3.3",
6666
"mt-changelog": "^0.6.2",
6767
"phantomjs": "^1.9.18",
68-
"react": "^15.4.2",
69-
"react-addons-test-utils": "^15.4.2",
70-
"react-async-script": "^0.6.0",
71-
"react-dom": "^15.4.2",
68+
"react": "^15.5.0",
69+
"react-async-script": "^0.9.0",
70+
"react-dom": "^15.5.0",
7271
"release-script": "^0.5.3",
7372
"webpack": "~1.14.0"
73+
},
74+
"dependencies": {
75+
"prop-types": ">=15.5.0"
7476
}
7577
}

src/recaptcha.js

+44-47
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,43 @@
1-
import React, { PropTypes } from "react";
1+
import React from "react";
2+
import PropTypes from "prop-types";
23

3-
const ReCAPTCHA = React.createClass({
4-
displayName: "reCAPTCHA",
5-
propTypes: {
6-
sitekey: PropTypes.string.isRequired,
7-
onChange: PropTypes.func.isRequired,
8-
grecaptcha: PropTypes.object,
9-
theme: PropTypes.oneOf(["dark", "light"]),
10-
type: PropTypes.oneOf(["image", "audio"]),
11-
tabindex: PropTypes.number,
12-
onExpired: PropTypes.func,
13-
size: PropTypes.oneOf(["compact", "normal", "invisible"]),
14-
stoken: PropTypes.string,
15-
badge: PropTypes.oneOf(["bottomright", "bottomleft ", "inline"]),
16-
},
4+
export default class ReCAPTCHA extends React.Component {
5+
constructor() {
6+
super();
7+
this.state = {};
8+
}
179

18-
getInitialState () {
19-
return {};
20-
},
21-
22-
getDefaultProps () {
23-
return {
24-
theme: "light",
25-
type: "image",
26-
tabindex: 0,
27-
size: "normal",
28-
badge: "bottomright",
29-
};
30-
},
31-
32-
getValue () {
10+
getValue() {
3311
if (this.props.grecaptcha && this.state.widgetId !== undefined) {
3412
return this.props.grecaptcha.getResponse(this.state.widgetId);
3513
}
3614
return null;
37-
},
15+
}
3816

39-
execute () {
17+
execute() {
4018
const { grecaptcha } = this.props;
4119
const { widgetId } = this.state;
4220

4321
if (grecaptcha && widgetId !== undefined) {
4422
return grecaptcha.execute(widgetId);
4523
}
46-
},
24+
}
4725

48-
reset () {
26+
reset() {
4927
if (this.props.grecaptcha && this.state.widgetId !== undefined) {
5028
this.props.grecaptcha.reset(this.state.widgetId);
5129
}
52-
},
30+
}
5331

54-
handleExpired () {
32+
handleExpired() {
5533
if (this.props.onExpired) {
5634
this.props.onExpired();
5735
} else if (this.props.onChange) {
5836
this.props.onChange(null);
5937
}
60-
},
38+
}
6139

62-
explicitRender (cb) {
40+
explicitRender(cb) {
6341
if (this.props.grecaptcha && this.state.widgetId === undefined) {
6442
const id = this.props.grecaptcha.render(this.refs.captcha, {
6543
sitekey: this.props.sitekey,
@@ -76,25 +54,44 @@ const ReCAPTCHA = React.createClass({
7654
widgetId: id,
7755
}, cb);
7856
}
79-
},
57+
}
8058

81-
componentDidMount () {
59+
componentDidMount() {
8260
this.explicitRender();
83-
},
61+
}
8462

85-
componentDidUpdate () {
63+
componentDidUpdate() {
8664
this.explicitRender();
87-
},
65+
}
8866

89-
render () {
67+
render() {
9068
// consume properties owned by the reCATPCHA, pass the rest to the div so the user can style it.
9169
/* eslint-disable no-unused-vars */
9270
const { sitekey, onChange, theme, type, tabindex, onExpired, size, stoken, grecaptcha, badge, ...childProps } = this.props;
9371
/* eslint-enable no-unused-vars */
9472
return (
9573
<div {...childProps} ref="captcha" />
9674
);
97-
},
98-
});
75+
}
76+
}
9977

100-
export default ReCAPTCHA;
78+
ReCAPTCHA.displayName = "ReCAPTCHA";
79+
ReCAPTCHA.propTypes = {
80+
sitekey: PropTypes.string.isRequired,
81+
onChange: PropTypes.func.isRequired,
82+
grecaptcha: PropTypes.object,
83+
theme: PropTypes.oneOf(["dark", "light"]),
84+
type: PropTypes.oneOf(["image", "audio"]),
85+
tabindex: PropTypes.number,
86+
onExpired: PropTypes.func,
87+
size: PropTypes.oneOf(["compact", "normal", "invisible"]),
88+
stoken: PropTypes.string,
89+
badge: PropTypes.oneOf(["bottomright", "bottomleft ", "inline"]),
90+
};
91+
ReCAPTCHA.defaultProps = {
92+
theme: "light",
93+
type: "image",
94+
tabindex: 0,
95+
size: "normal",
96+
badge: "bottomright",
97+
};

test/recaptcha-spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from "react";
22
import ReactDOM from "react-dom";
3-
import ReactTestUtils from "react-addons-test-utils";
3+
import ReactTestUtils from "react-dom/test-utils";
44
import ReCAPTCHA from "../src/recaptcha"; // eslint-disable-line no-unused-vars
55

66
describe("ReCAPTCHA", () => {

test/recaptcha-wrapper-spec.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react";
2-
import ReactTestUtils from "react-addons-test-utils";
2+
import ReactTestUtils from "react-dom/test-utils";
33
import ReCAPTCHA from "../src/recaptcha-wrapper"; // eslint-disable-line no-unused-vars
44

55
const VALUE = "some value";
@@ -21,6 +21,9 @@ describe("ReCAPTCHAWrapper", () => {
2121
beforeEach(() => {
2222
window.grecaptcha = grecaptchaMock;
2323
});
24+
it("should be wrapped properly", () => {
25+
assert.equal(ReCAPTCHA.displayName, "AsyncScriptLoader(ReCAPTCHA)");
26+
});
2427
it("should proxy functions", () => {
2528
const instance = ReactTestUtils.renderIntoDocument(
2629
<ReCAPTCHA sitekey="xxx" />,

0 commit comments

Comments
 (0)