1
- import React , { PropTypes } from "react" ;
1
+ import React from "react" ;
2
+ import PropTypes from "prop-types" ;
2
3
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
+ }
17
9
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 ( ) {
33
11
if ( this . props . grecaptcha && this . state . widgetId !== undefined ) {
34
12
return this . props . grecaptcha . getResponse ( this . state . widgetId ) ;
35
13
}
36
14
return null ;
37
- } ,
15
+ }
38
16
39
- execute ( ) {
17
+ execute ( ) {
40
18
const { grecaptcha } = this . props ;
41
19
const { widgetId } = this . state ;
42
20
43
21
if ( grecaptcha && widgetId !== undefined ) {
44
22
return grecaptcha . execute ( widgetId ) ;
45
23
}
46
- } ,
24
+ }
47
25
48
- reset ( ) {
26
+ reset ( ) {
49
27
if ( this . props . grecaptcha && this . state . widgetId !== undefined ) {
50
28
this . props . grecaptcha . reset ( this . state . widgetId ) ;
51
29
}
52
- } ,
30
+ }
53
31
54
- handleExpired ( ) {
32
+ handleExpired ( ) {
55
33
if ( this . props . onExpired ) {
56
34
this . props . onExpired ( ) ;
57
35
} else if ( this . props . onChange ) {
58
36
this . props . onChange ( null ) ;
59
37
}
60
- } ,
38
+ }
61
39
62
- explicitRender ( cb ) {
40
+ explicitRender ( cb ) {
63
41
if ( this . props . grecaptcha && this . state . widgetId === undefined ) {
64
42
const id = this . props . grecaptcha . render ( this . refs . captcha , {
65
43
sitekey : this . props . sitekey ,
@@ -76,25 +54,44 @@ const ReCAPTCHA = React.createClass({
76
54
widgetId : id ,
77
55
} , cb ) ;
78
56
}
79
- } ,
57
+ }
80
58
81
- componentDidMount ( ) {
59
+ componentDidMount ( ) {
82
60
this . explicitRender ( ) ;
83
- } ,
61
+ }
84
62
85
- componentDidUpdate ( ) {
63
+ componentDidUpdate ( ) {
86
64
this . explicitRender ( ) ;
87
- } ,
65
+ }
88
66
89
- render ( ) {
67
+ render ( ) {
90
68
// consume properties owned by the reCATPCHA, pass the rest to the div so the user can style it.
91
69
/* eslint-disable no-unused-vars */
92
70
const { sitekey, onChange, theme, type, tabindex, onExpired, size, stoken, grecaptcha, badge, ...childProps } = this . props ;
93
71
/* eslint-enable no-unused-vars */
94
72
return (
95
73
< div { ...childProps } ref = "captcha" />
96
74
) ;
97
- } ,
98
- } ) ;
75
+ }
76
+ }
99
77
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
+ } ;
0 commit comments