From ad78b1aaf22f523cb332a2a021aa3b6d47612d46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Hertault?= Date: Mon, 21 Dec 2020 17:01:36 +0100 Subject: [PATCH 1/2] Add TypeScript declaration files --- index.d.ts | 26 +++++++++++++++++++++++++ package.json | 1 + src/Recaptcha.d.ts | 45 +++++++++++++++++++++++++++++++++++++++++++ src/get-template.d.ts | 25 ++++++++++++++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 index.d.ts create mode 100644 src/Recaptcha.d.ts create mode 100644 src/get-template.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..a5d1e5f --- /dev/null +++ b/index.d.ts @@ -0,0 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2020 Douglas Nassif Roma Junior + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +import Recaptcha, { Handles, Props } from "./src/Recaptcha"; +export { Props, Handles }; +export default Recaptcha; diff --git a/package.json b/package.json index 4d4314b..2386f22 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "url": "https://github.com/douglasjunior/react-native-recaptcha-that-works.git" }, "main": "index.js", + "types": "index.d.ts", "keywords": [ "react-native", "ios", diff --git a/src/Recaptcha.d.ts b/src/Recaptcha.d.ts new file mode 100644 index 0000000..7f4ea38 --- /dev/null +++ b/src/Recaptcha.d.ts @@ -0,0 +1,45 @@ +/** + * MIT License + * + * Copyright (c) 2020 Douglas Nassif Roma Junior + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +import React, { ReactNode } from "react"; +import { StyleProp, ViewStyle } from "react-native"; +export declare type Props = { + headerComponent?: ReactNode; + onVerify?: (token: string) => void; + onExpire?: () => void; + onError?: (error: string) => void; + onClose?: () => void; + onLoad?: () => void; + theme?: "dark" | "light"; + size?: "invisible" | "normal" | "compact"; + siteKey: string; + baseUrl: string; + lang?: string; + style?: StyleProp; +}; +export declare type Handles = { + open(): void; + close(): void; +}; +declare const Recaptcha: React.ForwardRefExoticComponent>; +export default Recaptcha; diff --git a/src/get-template.d.ts b/src/get-template.d.ts new file mode 100644 index 0000000..cb87aa5 --- /dev/null +++ b/src/get-template.d.ts @@ -0,0 +1,25 @@ +/** + * MIT License + * + * Copyright (c) 2020 Douglas Nassif Roma Junior + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +declare const getTemplate: (params: Record) => string; +export default getTemplate; From f1c76f2802a3863303816248251a9a666feab3e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Hertault?= Date: Mon, 21 Dec 2020 21:14:09 +0100 Subject: [PATCH 2/2] Put all types in one file and add an example --- README.md | 36 ++++++++++++++++++++++++++++++++ index.d.ts | 26 ----------------------- package.json | 2 +- src/get-template.d.ts | 25 ---------------------- src/Recaptcha.d.ts => types.d.ts | 32 +++++++++++++++------------- 5 files changed, 54 insertions(+), 67 deletions(-) delete mode 100644 index.d.ts delete mode 100644 src/get-template.d.ts rename src/Recaptcha.d.ts => types.d.ts (73%) diff --git a/README.md b/README.md index b02930b..c69588f 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,42 @@ Note: If using `size="invisible"`, then challange run automatically when `open` - [I'm not a robot](https://developers.google.com/recaptcha/docs/display) - [Invisible](https://developers.google.com/recaptcha/docs/invisible) +## TypeScript + +Example usage in TypeScript project: + +```tsx +import Recaptcha, { Handles } from "react-native-recaptcha-that-works"; + +// ... + +export const Component: React.FC = () => { + const recaptcha = React.useRef(null); + + const send = () => { + console.log('send!'); + recaptcha.current?.open(); + }; + + const onVerify = (token: string) => { + console.log('success!', token); + }; + + return ( + + +