1
1
import React , { useEffect , useState , useRef } from "react" ;
2
2
import {
3
3
TurnstileObject ,
4
- TurnstileOptions ,
5
4
SupportedLanguages ,
5
+ RenderParameters ,
6
6
} from "turnstile-types" ;
7
7
8
8
const globalNamespace = (
@@ -52,7 +52,7 @@ const turnstileLoadPromise = new Promise((resolve, reject) => {
52
52
export default function Turnstile ( {
53
53
id,
54
54
className,
55
- style,
55
+ style : customStyle ,
56
56
sitekey,
57
57
action,
58
58
cData,
@@ -94,6 +94,15 @@ export default function Turnstile({
94
94
95
95
const ref = userRef ?? ownRef ;
96
96
97
+ const style = fixedSize
98
+ ? {
99
+ width :
100
+ size === "compact" ? "130px" : size === "flexible" ? "100%" : "300px" ,
101
+ height : size === "compact" ? "120px" : "65px" ,
102
+ ...customStyle ,
103
+ }
104
+ : customStyle ;
105
+
97
106
useEffect ( ( ) => {
98
107
if ( ! ref . current ) return ;
99
108
let cancelled = false ;
@@ -110,7 +119,7 @@ export default function Turnstile({
110
119
}
111
120
if ( cancelled || ! ref . current ) return ;
112
121
let boundTurnstileObject : BoundTurnstileObject ;
113
- const turnstileOptions : TurnstileOptions = {
122
+ const turnstileOptions : RenderParameters = {
114
123
sitekey,
115
124
action,
116
125
cData,
@@ -130,7 +139,7 @@ export default function Turnstile({
130
139
inplaceState . onSuccess ?.(
131
140
token ,
132
141
preClearanceObtained ,
133
- boundTurnstileObject ,
142
+ boundTurnstileObject
134
143
) ;
135
144
} ,
136
145
"error-callback" : ( error ?: any ) =>
@@ -193,22 +202,7 @@ export default function Turnstile({
193
202
onUnsupported ,
194
203
] ) ;
195
204
196
- return (
197
- < div
198
- ref = { ref }
199
- id = { id }
200
- className = { className }
201
- style = {
202
- fixedSize
203
- ? {
204
- ...( style ?? { } ) ,
205
- width : size === "compact" ? "130px" : "300px" ,
206
- height : size === "compact" ? "120px" : "65px" ,
207
- }
208
- : style
209
- }
210
- />
211
- ) ;
205
+ return < div ref = { ref } id = { id } className = { className } style = { style } /> ;
212
206
}
213
207
214
208
export interface TurnstileProps extends TurnstileCallbacks {
@@ -220,7 +214,7 @@ export interface TurnstileProps extends TurnstileCallbacks {
220
214
tabIndex ?: number ;
221
215
responseField ?: boolean ;
222
216
responseFieldName ?: string ;
223
- size ?: "normal" | "invisible " | "compact " ;
217
+ size ?: "normal" | "compact " | "flexible" | "invisible ";
224
218
fixedSize ?: boolean ;
225
219
retry ?: "auto" | "never" ;
226
220
retryInterval ?: number ;
@@ -238,12 +232,12 @@ export interface TurnstileCallbacks {
238
232
onSuccess ?: (
239
233
token : string ,
240
234
preClearanceObtained : boolean ,
241
- boundTurnstile : BoundTurnstileObject ,
235
+ boundTurnstile : BoundTurnstileObject
242
236
) => void ;
243
237
onLoad ?: ( widgetId : string , boundTurnstile : BoundTurnstileObject ) => void ;
244
238
onError ?: (
245
239
error ?: Error | any ,
246
- boundTurnstile ?: BoundTurnstileObject ,
240
+ boundTurnstile ?: BoundTurnstileObject
247
241
) => void ;
248
242
onExpire ?: ( token : string , boundTurnstile : BoundTurnstileObject ) => void ;
249
243
onTimeout ?: ( boundTurnstile : BoundTurnstileObject ) => void ;
@@ -253,7 +247,7 @@ export interface TurnstileCallbacks {
253
247
}
254
248
255
249
export interface BoundTurnstileObject {
256
- execute : ( options ?: TurnstileOptions ) => void ;
250
+ execute : ( options ?: RenderParameters ) => void ;
257
251
reset : ( ) => void ;
258
252
getResponse : ( ) => void ;
259
253
isExpired : ( ) => boolean ;
0 commit comments