diff --git a/README.md b/README.md index 3539e76..c462163 100644 --- a/README.md +++ b/README.md @@ -70,15 +70,17 @@ function Widget() { ### Render options -| **Option** | **Type** | **Default** | **Description** | -| ----------------- | --------- | ------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| theme | `string` | `'auto'` | The widget theme. You can choose between `light`, `dark` or `auto`. | -| tabIndex | `number` | `0` | The `tabindex` of Turnstile’s iframe for accessibility purposes. | -| action | `string` | `undefined` | A customer value that can be used to differentiate widgets under the same `sitekey` in analytics and which is returned upon validation. This can only contain up to 32 alphanumeric characters including `_` and `-`. | -| cData | `string` | `undefined` | A customer payload that can be used to attach customer data to the challenge throughout its issuance and which is returned upon validation. This can only contain up to 255 alphanumeric characters including `_` and `-`. | -| responseField | `boolean` | `true` | A boolean that controls if an input element with the response token is created. | -| responseFieldName | `string` | `'cf-turnstile-response'` | Name of the input element. | -| size | `string` | `'normal'` | The widget size. Can take the following values: `'normal'`, `'compact'`. The normal size is 300x65px, the compact size is 130x120px. | +| **Option** | **Type** | **Default** | **Description** | +| ----------------- | --------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| theme | `string` | `'auto'` | The widget theme. You can choose between `light`, `dark` or `auto`. | +| tabIndex | `number` | `0` | The `tabindex` of Turnstile’s iframe for accessibility purposes. | +| action | `string` | `undefined` | A customer value that can be used to differentiate widgets under the same `sitekey` in analytics and which is returned upon validation. This can only contain up to 32 alphanumeric characters including `_` and `-`. | +| cData | `string` | `undefined` | A customer payload that can be used to attach customer data to the challenge throughout its issuance and which is returned upon validation. This can only contain up to 255 alphanumeric characters including `_` and `-`. | +| responseField | `boolean` | `true` | A boolean that controls if an input element with the response token is created. | +| responseFieldName | `string` | `'cf-turnstile-response'` | Name of the input element. | +| size | `string` | `'normal'` | The widget size. Can take the following values: `'normal'`, `'compact'`. The normal size is 300x65px, the compact size is 130x120px. | +| retry | `string` | `'auto'` | Controls whether the widget should automatically retry to obtain a token if it did not succeed. The default is `'auto'`, which will retry automatically. This can be set to `'never'` to disable retry upon failure. | +| retryInterval | `number` | `8000` | When `retry` is set to `'auto'`, `retryInterval` controls the time between retry attempts in milliseconds. The value must be a positive integer less than `900000`. When `retry` is set to `'never'`, this parameter has no effect. | > All this options are optional. diff --git a/src/lib.tsx b/src/lib.tsx index 3e94a4a..9e25942 100644 --- a/src/lib.tsx +++ b/src/lib.tsx @@ -94,7 +94,9 @@ export const Turnstile = forwardRef { @@ -132,10 +134,7 @@ export const Turnstile = forwardRef window.turnstile?.reset(), 290 * 1000) - - return () => { - clearInterval(timerId) - } + return () => clearInterval(timerId) } }, [configJson, scriptOptionsJson]) diff --git a/src/types.d.ts b/src/types.d.ts index 880681f..81e12e1 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -59,7 +59,7 @@ interface TurnstileInstance { } /** Common options for the `.render()` function and the `options` prop in the `` component */ -interface TurnstileBaseOptions { +interface CommonRenderOptions { /** * A customer value that can be used to differentiate widgets under the same sitekey in analytics and which is returned upon validation. This can only contain up to 32 alphanumeric characters including _ and -. * @default undefined @@ -81,10 +81,15 @@ interface TurnstileBaseOptions { * @default `normal` */ size?: 'normal' | 'compact' + /** + * Controls whether the widget should automatically retry to obtain a token if it did not succeed. The default is `'auto'`, which will retry automatically. This can be set to `'never'` to disable retry upon failure. + * @default `auto` + */ + retry?: 'auto' | 'never' } /** Props needed for the `options` prop in the `` component */ -interface ComponentRenderOptions extends TurnstileBaseOptions { +interface ComponentRenderOptions extends CommonRenderOptions { /** * The tabindex of Turnstile’s iframe for accessibility purposes. * @default 0 @@ -100,10 +105,15 @@ interface ComponentRenderOptions extends TurnstileBaseOptions { * @default `cf-turnstile-response` */ responseFieldName?: string + /** + * When `retry` is set to `'auto'`, `retryInterval` controls the time between retry attempts in milliseconds. The value must be a positive integer less than `900000`. When `retry` is set to `'never'`, this parameter has no effect. + * @default 8000 + */ + retryInterval?: number } /** Props needed for the `.render()` function */ -interface RenderParameters extends TurnstileBaseOptions { +interface RenderParameters extends CommonRenderOptions { /** * Every widget has a sitekey. This sitekey is associated with the corresponding widget configuration and is created upon the widget creation. */ @@ -136,6 +146,11 @@ interface RenderParameters extends TurnstileBaseOptions { * @default `cf-turnstile-response` */ 'response-field-name'?: string + /** + * When `retry` is set to `'auto'`, `retry-interval` controls the time between retry attempts in milliseconds. The value must be a positive integer less than `900000`. When `retry` is set to `'never'`, this parameter has no effect. + * @default 8000 + */ + 'retry-interval'?: number } interface ScriptOptions {