From f203d6458c239f3f61e4a04f1c72a8fec94ca2ca Mon Sep 17 00:00:00 2001 From: KoalaHuman Date: Mon, 18 Dec 2017 10:59:27 +0300 Subject: [PATCH] Added React Google ReCAPTCHA --- types/react-google-recaptcha/index.d.ts | 86 +++++++++++++++++++ .../react-google-recaptcha-tests.tsx | 8 ++ types/react-google-recaptcha/tsconfig.json | 25 ++++++ types/react-google-recaptcha/tslint.json | 1 + 4 files changed, 120 insertions(+) create mode 100644 types/react-google-recaptcha/index.d.ts create mode 100644 types/react-google-recaptcha/react-google-recaptcha-tests.tsx create mode 100644 types/react-google-recaptcha/tsconfig.json create mode 100644 types/react-google-recaptcha/tslint.json diff --git a/types/react-google-recaptcha/index.d.ts b/types/react-google-recaptcha/index.d.ts new file mode 100644 index 0000000000..ade88fbda4 --- /dev/null +++ b/types/react-google-recaptcha/index.d.ts @@ -0,0 +1,86 @@ +// Type definitions for React Google Recaptcha 0.9 +// Project: https://github.com/dozoisch/react-google-recaptcha +// Definitions by: Koala Human +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +import * as React from 'react'; + +export as namespace RGR; + +export default ReCAPTCHA; + +declare class ReCAPTCHA extends React.Component { + /** + * Resets the reCAPTCHA widget + */ + reset(): void; + /** + * Programatically invoke the reCAPTCHA check. Used if the invisible reCAPTCHA is on a div instead of a button + */ + execute(): void; + + /** + * Gets the response for the reCAPTCHA widget. + * @return the response of the reCAPTCHA widget. + */ + getValue(): string | null; + + /** + * Gets the widgetId of reCAPTCHA widget + * @return widgetId | null + */ + getWidgetId(): number | null; +} + +type Theme = "light" | "dark"; +type Type = "image" | "audio"; +type Size = "compact" | "normal" | "invisible"; +type Badge = "bottomright" | "bottomleft" | "inline"; + +export interface ReCAPTCHAProps { + /** + * The API client key + */ + sitekey: string; + /** + * The function to be called when the user successfully completes the captcha. It will also be called + * with null, when captcha expires + * @param token string or null + */ + onChange: (token: string|null) => void; + /** + * Optional light or dark theme of the widget + * @default "light" + */ + theme?: Theme; + /** + * Optional image or audio The type of initial captcha + * @default "image" + */ + type?: Type; + /** + * Optional the tabindex of the element + * @default 0 + */ + tabindex?: number; + /** + * Optional callback, called when a challenge expires and has to be redone by the user. + */ + onExpired?: () => void; + /** + * Optional set the stoken parameter, which allows the captcha to be used from different domains, + * @see reCAPTCHA secure-token + */ + stoken?: string; + /** + * Optional compact, normal or invisible. This allows you to change the size or do an invisible captcha + */ + size?: Size; + /** + * Optional. The badge location for g-recaptcha with size of "invisible". + * + * @default "bottomright" + */ + badge?: Badge; +} diff --git a/types/react-google-recaptcha/react-google-recaptcha-tests.tsx b/types/react-google-recaptcha/react-google-recaptcha-tests.tsx new file mode 100644 index 0000000000..b3e60d538b --- /dev/null +++ b/types/react-google-recaptcha/react-google-recaptcha-tests.tsx @@ -0,0 +1,8 @@ +import ReCAPTCHA from 'react-google-recaptcha'; +import * as ReactDOM from 'react-dom'; +import * as React from 'react'; + +ReactDOM.render( + a}/>, + document.getElementById('example') +); diff --git a/types/react-google-recaptcha/tsconfig.json b/types/react-google-recaptcha/tsconfig.json new file mode 100644 index 0000000000..bbd1cfd004 --- /dev/null +++ b/types/react-google-recaptcha/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "jsx": "react", + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "react-google-recaptcha-tests.tsx" + ] +} diff --git a/types/react-google-recaptcha/tslint.json b/types/react-google-recaptcha/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/react-google-recaptcha/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }