1+ /*global grecaptcha*/
12"use strict" ;
2- var React = require ( "react" ) ;
3- var PropTypes = React . PropTypes ;
3+ import React from "react" ;
4+ const PropTypes = React . PropTypes ;
45
5- var ReCAPTCHA = React . createClass ( {
6+ const ReCAPTCHA = React . createClass ( {
67 displayName : "react-reCAPTCHA" ,
78 propTypes : {
89 sitekey : PropTypes . string . isRequired ,
910 onChange : PropTypes . func . isRequired ,
1011 onloadCallbackName : PropTypes . string . isRequired , // Name on the script tag onload query parameter
1112 theme : PropTypes . oneOf ( [ "dark" , "light" ] ) ,
1213 type : PropTypes . oneOf ( [ "image" , "audio" ] ) ,
14+ elementId : PropTypes . string ,
1315 tabindex : PropTypes . number ,
1416 onLoad : PropTypes . func ,
1517 onExpired : PropTypes . func ,
1618 } ,
1719
18- getDefaultState : function ( ) {
20+ getDefaultState ( ) {
1921 return { } ;
2022 } ,
2123
22- getDefaultProps : function ( ) {
24+ getDefaultProps ( ) {
2325 return {
2426 theme : "light" ,
2527 type : "image" ,
@@ -28,50 +30,51 @@ var ReCAPTCHA = React.createClass({
2830 } ;
2931 } ,
3032
31- getValue : function ( ) {
33+ getValue ( ) {
3234 if ( typeof grecaptcha !== "undefined" && this . state . widgetId ) {
3335 return grecaptcha . getResponse ( this . state . widgetId ) ;
3436 }
3537 return null ;
3638 } ,
3739
38- reset : function ( ) {
40+ reset ( ) {
3941 if ( typeof grecaptcha !== "undefined" && this . state . widgetId ) {
40- grecaptcha . reset ( this . props . widgetId ) ;
42+ grecaptcha . reset ( this . state . widgetId ) ;
4143 }
4244 } ,
4345
44- handleExpired : function ( ) {
46+ handleExpired ( ) {
4547 if ( this . props . onExpired ) {
4648 this . props . onExpired ( ) ;
4749 } else if ( this . props . onChange ) {
4850 this . props . onChange ( null ) ;
4951 }
5052 } ,
5153
52- explicitRender : function ( ) {
53- var id = grecaptcha . render ( this . refs . captcha . getDOMNode ( ) , {
54- sitekey : this . props . sitekey ,
55- callback : this . props . onChange ,
56- theme : this . props . theme ,
57- type : this . props . type ,
58- tabindex : this . props . tabindex ,
59- "expired-callback" : this . handleExpired ,
60- } ) ;
61- this . setState ( {
62- widgetId : id ,
63- } ) ;
54+ explicitRender ( ) {
55+ if ( typeof grecaptcha !== "undefined" ) {
56+ let id = grecaptcha . render ( this . refs . captcha . getDOMNode ( ) , {
57+ sitekey : this . props . sitekey ,
58+ callback : this . props . onChange ,
59+ theme : this . props . theme ,
60+ type : this . props . type ,
61+ tabindex : this . props . tabindex ,
62+ "expired-callback" : this . handleExpired ,
63+ } ) ;
64+ this . setState ( {
65+ widgetId : id ,
66+ } ) ;
67+ }
6468 } ,
6569
66-
67- handleLoad : function ( ) {
70+ handleLoad ( ) {
6871 this . explicitRender ( ) ;
6972 if ( this . props . onLoad ) {
7073 this . props . onLoad ( ) ;
7174 }
7275 } ,
7376
74- componentDidMount : function ( ) {
77+ componentDidMount ( ) {
7578 // If script is not loaded, set the callback on window.
7679 if ( typeof grecaptcha === "undefined" ) {
7780 window [ this . props . onloadCallbackName ] = this . handleLoad ;
@@ -80,11 +83,11 @@ var ReCAPTCHA = React.createClass({
8083 }
8184 } ,
8285
83- render : function ( ) {
86+ render ( ) {
8487 return (
8588 < div ref = "captcha" id = { this . props . elementId } />
8689 ) ;
8790 }
8891} ) ;
8992
90- module . exports = ReCAPTCHA ;
93+ export default ReCAPTCHA ;
0 commit comments