diff --git a/HISTORY.md b/HISTORY.md index d5a74e8..d9a44db 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -10,6 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - `onSuccess` callback with the additional `preClearanceObtained` argument +- `flexible` option for `size` prop + +### Changed + +- Update `turnstile-types` to v1.2.3 ## [1.1.3] - 2024-02-19 diff --git a/package-lock.json b/package-lock.json index 8c2742e..a004299 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "devDependencies": { "@types/react": "^18.0.21", "prettier": "^2.7.1", - "turnstile-types": "^1.1.3", + "turnstile-types": "^1.2.3", "typescript": "^4.8.4" }, "peerDependencies": { @@ -116,10 +116,11 @@ } }, "node_modules/turnstile-types": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/turnstile-types/-/turnstile-types-1.1.3.tgz", - "integrity": "sha512-hurCjOLYMYU9OmUY2JX/ewHBcadUfOhHX1XgLx9A9Ig5TFl2NGqoyM4EyfaaClsROr95cT868rkgzxCvSCcY6A==", - "dev": true + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/turnstile-types/-/turnstile-types-1.2.3.tgz", + "integrity": "sha512-EDjhDB9TDwda2JRbhzO/kButPio3JgrC3gXMVAMotxldybTCJQVMvPNJ89rcAiN9vIrCb2i1E+VNBCqB8wue0A==", + "dev": true, + "license": "MIT" }, "node_modules/typescript": { "version": "4.8.4", @@ -215,9 +216,9 @@ } }, "turnstile-types": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/turnstile-types/-/turnstile-types-1.1.3.tgz", - "integrity": "sha512-hurCjOLYMYU9OmUY2JX/ewHBcadUfOhHX1XgLx9A9Ig5TFl2NGqoyM4EyfaaClsROr95cT868rkgzxCvSCcY6A==", + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/turnstile-types/-/turnstile-types-1.2.3.tgz", + "integrity": "sha512-EDjhDB9TDwda2JRbhzO/kButPio3JgrC3gXMVAMotxldybTCJQVMvPNJ89rcAiN9vIrCb2i1E+VNBCqB8wue0A==", "dev": true }, "typescript": { diff --git a/package.json b/package.json index 1cd5098..29206ad 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "devDependencies": { "@types/react": "^18.0.21", "prettier": "^2.7.1", - "turnstile-types": "^1.1.3", + "turnstile-types": "^1.2.3", "typescript": "^4.8.4" } } diff --git a/src/index.tsx b/src/index.tsx index 45e42fd..6537625 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,8 +1,8 @@ import React, { useEffect, useState, useRef } from "react"; import { TurnstileObject, - TurnstileOptions, SupportedLanguages, + RenderParameters, } from "turnstile-types"; const globalNamespace = ( @@ -52,7 +52,7 @@ const turnstileLoadPromise = new Promise((resolve, reject) => { export default function Turnstile({ id, className, - style, + style: customStyle, sitekey, action, cData, @@ -94,6 +94,15 @@ export default function Turnstile({ const ref = userRef ?? ownRef; + const style = fixedSize + ? { + width: + size === "compact" ? "130px" : size === "flexible" ? "100%" : "300px", + height: size === "compact" ? "120px" : "65px", + ...customStyle, + } + : customStyle; + useEffect(() => { if (!ref.current) return; let cancelled = false; @@ -110,7 +119,7 @@ export default function Turnstile({ } if (cancelled || !ref.current) return; let boundTurnstileObject: BoundTurnstileObject; - const turnstileOptions: TurnstileOptions = { + const turnstileOptions: RenderParameters = { sitekey, action, cData, @@ -130,7 +139,7 @@ export default function Turnstile({ inplaceState.onSuccess?.( token, preClearanceObtained, - boundTurnstileObject, + boundTurnstileObject ); }, "error-callback": (error?: any) => @@ -193,22 +202,7 @@ export default function Turnstile({ onUnsupported, ]); - return ( -
- ); + return
; } export interface TurnstileProps extends TurnstileCallbacks { @@ -220,7 +214,7 @@ export interface TurnstileProps extends TurnstileCallbacks { tabIndex?: number; responseField?: boolean; responseFieldName?: string; - size?: "normal" | "invisible" | "compact"; + size?: "normal" | "compact" | "flexible" | "invisible"; fixedSize?: boolean; retry?: "auto" | "never"; retryInterval?: number; @@ -238,12 +232,12 @@ export interface TurnstileCallbacks { onSuccess?: ( token: string, preClearanceObtained: boolean, - boundTurnstile: BoundTurnstileObject, + boundTurnstile: BoundTurnstileObject ) => void; onLoad?: (widgetId: string, boundTurnstile: BoundTurnstileObject) => void; onError?: ( error?: Error | any, - boundTurnstile?: BoundTurnstileObject, + boundTurnstile?: BoundTurnstileObject ) => void; onExpire?: (token: string, boundTurnstile: BoundTurnstileObject) => void; onTimeout?: (boundTurnstile: BoundTurnstileObject) => void; @@ -253,7 +247,7 @@ export interface TurnstileCallbacks { } export interface BoundTurnstileObject { - execute: (options?: TurnstileOptions) => void; + execute: (options?: RenderParameters) => void; reset: () => void; getResponse: () => void; isExpired: () => boolean;