Skip to content

Commit

Permalink
Merge pull request #4 from MrHertal/master
Browse files Browse the repository at this point in the history
Add TypeScript declaration files
  • Loading branch information
douglasjunior authored Dec 22, 2020
2 parents c299abd + f1c76f2 commit 37411cd
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<Handles>(null);

const send = () => {
console.log('send!');
recaptcha.current?.open();
};

const onVerify = (token: string) => {
console.log('success!', token);
};

return (
<View>
<Recaptcha
ref={recaptcha}
siteKey="<your-recaptcha-public-key>"
baseUrl="http://my.domain.com"
onVerify={onVerify}
size="invisible"
/>
<Button title="Send" onPress={send} />
</View>
);
};
```

## Contribute

New features, bug fixes and improvements are welcome! For questions and suggestions use the [issues](https://github.com/douglasjunior/react-native-recaptcha-that-works/issues).
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"url": "https://github.com/douglasjunior/react-native-recaptcha-that-works.git"
},
"main": "index.js",
"types": "types.d.ts",
"keywords": [
"react-native",
"ios",
Expand Down
47 changes: 47 additions & 0 deletions types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* 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<ViewStyle>;
};
export declare type Handles = {
open(): void;
close(): void;
};
declare const Recaptcha: React.ForwardRefExoticComponent<
Props & React.RefAttributes<Handles>
>;
export default Recaptcha;

0 comments on commit 37411cd

Please sign in to comment.