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+ } ;
0 commit comments