Skip to content

Commit bf61955

Browse files
committed
Typescript and deps update.
1 parent 52ae505 commit bf61955

16 files changed

+10487
-45023
lines changed

.babelrc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
{
2-
"presets" : ["es2015", "react"],
3-
"plugins" : ["transform-object-rest-spread"]
2+
"presets" : [
3+
"@babel/preset-env",
4+
"@babel/preset-react",
5+
"@babel/preset-typescript",
6+
],
7+
"plugins": [
8+
"@babel/plugin-transform-typescript"
9+
]
410
}

.eslintrc

Lines changed: 12 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,17 @@
11
{
2-
"parser": "babel-eslint",
3-
"parserOptions": {
4-
"ecmaFeatures": {
5-
"jsx": true,
6-
"experimentalObjectRestSpread": true,
7-
"modules": true
8-
}
2+
parser: "@typescript-eslint/parser",
3+
plugins: ["@typescript-eslint"],
4+
env: {
5+
"browser": true
96
},
10-
"env": {
11-
"es6": true,
12-
"browser": true,
13-
"node": true,
14-
"amd": true,
15-
"jquery": true
16-
},
17-
"extends": [ "eslint:recommended" ],
18-
"plugins": [
19-
"react"
7+
extends: [
8+
"eslint:recommended",
9+
"plugin:react/recommended",
10+
"plugin:@typescript-eslint/recommended"
2011
],
21-
"rules": {
22-
"block-spacing": [1, "always"],
23-
"comma-spacing": [1, {"before": false, "after": true}],
24-
"computed-property-spacing": [1, "always"],
25-
"curly": [1, "all"],
26-
"indent": [1, 2],
27-
"key-spacing": [1, {"beforeColon": false, "afterColon": true}],
28-
"keyword-spacing": [2, {"before": true, "after": true}],
29-
"linebreak-style": [1, "unix"],
30-
"no-const-assign": 2,
31-
"no-extra-semi": 1,
32-
"no-console": 1,
33-
"no-extra-boolean-cast": 1,
34-
"no-mixed-spaces-and-tabs": 1,
35-
"no-unused-vars": 1,
36-
"no-unreachable": 1,
37-
"no-multiple-empty-lines": [1, {max: 1, maxEOF: 0, maxBOF: 0}],
38-
"object-curly-spacing": [1, "always"],
39-
"prefer-const": 1,
40-
"react/jsx-no-undef": 1,
41-
"react/jsx-uses-react": 1,
42-
"react/jsx-uses-vars": 1,
43-
"strict": 0,
44-
"semi": [1, "always"]
12+
settings: {
13+
react: {
14+
version: 'detect',
15+
},
4516
}
4617
}

README.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@ A React component which is interested in only Google invisible reCAPTCHA.
44

55
* Support multiple reCAPTCHA widgets on one page.
66
* Support React hooks.
7+
* Support Typescript.
8+
9+
## Migration from 0.x to 1.0.0
10+
11+
```js
12+
// Version 0.x
13+
<Recaptcha ref={ref => this.recaptcha = ref} ... />
14+
// this.recaptcha.execute invokes the reCAPTCHA check.
15+
16+
// Version 1.0.0
17+
const refCaptcha = React.useRef(null) // or React.createRef().
18+
<Recaptcha ref={refRecaptcha} ... />
19+
// refRecaptcha.current.callbacks.execute invokes the reCAPTCHA check.
20+
// ^^^^^^^^^^^^^^^^^^
21+
```
722

823
## [Demo][demo] ##
924

@@ -27,9 +42,9 @@ npm install react-google-invisible-recaptcha --save
2742
import Recaptcha from 'react-google-invisible-recaptcha';
2843

2944
<Recaptcha
45+
onResolved={() => console.log('Human detected.')} />
3046
ref={refRecaptcha}
3147
sitekey={<sitekey>}
32-
onResolved={() => console.log('Human detected.')} />
3348
```
3449

3550
## Configuration ##
@@ -66,18 +81,6 @@ this.refRecaptcha = React.createRef();
6681
// refRecaptcha.current.callbacks.getResponse function which returns the response token.
6782
```
6883

69-
## Migration from 0.x to 1.0.0
70-
71-
```js
72-
// version 0.x
73-
<Recaptcha ref={ref => this.recaptcha = ref} ... />
74-
// this.recaptcha.execute invokes the reCAPTCHA check.
75-
76-
// version 1.0.0
77-
<Recaptcha ref={refRecaptcha} ... />
78-
// refRecaptcha.current.callbacks.execute invokes the reCAPTCHA check.
79-
```
80-
8184
## License ##
8285

8386
MIT. See [LICENSE.md](http://github.com/szchenghuang/react-google-invisible-recaptcha/blob/master/LICENSE.md) for details.

dist/index.d.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import * as React from 'react';
2+
declare global {
3+
interface Window {
4+
grecaptcha: {
5+
render?: (wrapper: HTMLElement, options: {
6+
badge: Props['badge'];
7+
callback: string;
8+
'error-callback': () => void;
9+
'expired-callback': () => void;
10+
sitekey: string;
11+
size: 'invisible';
12+
tabindex: number;
13+
}) => string;
14+
execute?: (recaptchaId: string) => void;
15+
reset?: (recaptchaId: string) => void;
16+
getResponse?: (recaptchaId: string) => string;
17+
};
18+
GoogleRecaptchaLoaded: () => void;
19+
}
20+
}
21+
export declare type Callbacks = {
22+
execute: () => void;
23+
getResponse: () => string | undefined;
24+
reset: () => void;
25+
};
26+
declare type Props = {
27+
badge?: 'bottomright' | 'bottomleft' | 'inline';
28+
locale?: string;
29+
nonce?: string;
30+
onExpired?: () => void;
31+
onError?: () => void;
32+
onLoaded?: () => void;
33+
onResolved?: () => void;
34+
sitekey: string;
35+
style?: React.CSSProperties;
36+
tabindex?: number;
37+
};
38+
declare const GoogleRecaptcha: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLDivElement & {
39+
callbacks?: Callbacks | undefined;
40+
}>>;
41+
export default GoogleRecaptcha;

0 commit comments

Comments
 (0)