primereact
Version:
PrimeReact is an open source UI library for React featuring a rich set of 80+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with Prime
2 lines (1 loc) • 1.86 kB
JavaScript
import*as e from"react";import{useMountEffect as n,useUnmountEffect as r}from"primereact/hooks";import{ObjectUtils as t}from"primereact/utils";function a(){return a=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e},a.apply(this,arguments)}var c=e.memo(e.forwardRef((function(o,i){var u=e.useRef(null),p=e.useRef(null),l=e.useRef(null),s=e.useRef(!1),d=function(){p.current=window.grecaptcha.render(u.current,{sitekey:o.siteKey,theme:o.theme,type:o.type,size:o.size,tabindex:o.tabIndex,hl:o.language,callback:h,"expired-callback":g})},f=function(){p.current&&window.grecaptcha.reset(p.current)},m=function(){return p.current?window.grecaptcha.getResponse(p.current):null},h=function(e){o.onResponse&&o.onResponse({response:e})},g=function(){o.onExpire&&o.onExpire()},w=function(){if(l.current=null,!window.grecaptcha){var e=document.head||document.getElementsByTagName("head")[0],n=document.createElement("script");n.src="https://www.google.com/recaptcha/api.js?render=explicit",n.async=!0,n.defer=!0,n.onload=function(){window.grecaptcha?window.grecaptcha.ready((function(){d()})):console.warn("Recaptcha is not loaded")},l.current=n,e.appendChild(l.current)}};n((function(){s.current||(w(),window.grecaptcha&&d(),s.current=!0)})),r((function(){l.current&&l.current.parentNode&&l.current.parentNode.removeChild(l.current)})),e.useImperativeHandle(i,(function(){return{props:o,reset:f,getResponse:m,getElement:function(){return u.current}}}));var y=t.findDiffKeys(o,c.defaultProps);return e.createElement("div",a({ref:u,id:o.id},y))})));c.displayName="Captcha",c.defaultProps={__TYPE:"Captcha",id:null,siteKey:null,theme:"light",type:"image",size:"normal",tabIndex:0,language:"en",onResponse:null,onExpire:null};export{c as Captcha};