@thecb/components 11.2.17 → 11.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -24397,6 +24397,39 @@ function useConditionallyAddValidator(condition, validatorFn, addValidator, remo
24397
24397
  }, [condition, addValidator, removeValidator]);
24398
24398
  }
24399
24399
 
24400
+ /**
24401
+ * A custom hook to dynamically load the Cloudflare Turnstile script.
24402
+ *
24403
+ * @param {string} verifyURL - The URL of the Turnstile verification script.
24404
+ */
24405
+ var useTurnstileScript = function useTurnstileScript(verifyURL) {
24406
+ var _useState = React.useState(false),
24407
+ _useState2 = _slicedToArray(_useState, 2),
24408
+ isLoaded = _useState2[0],
24409
+ setIsLoaded = _useState2[1];
24410
+ React.useEffect(function () {
24411
+ if (typeof window === "undefined") {
24412
+ setIsLoaded(false);
24413
+ return;
24414
+ }
24415
+ if (window.turnstile && window.turnstile.render) {
24416
+ setIsLoaded(true);
24417
+ return;
24418
+ }
24419
+ var script = document.createElement("script");
24420
+ script.src = "".concat(verifyURL, "?render=explicit");
24421
+ script.onload = function () {
24422
+ setIsLoaded(true);
24423
+ };
24424
+ script.defer = true;
24425
+ document.getElementsByTagName("head")[0].appendChild(script);
24426
+ return function () {
24427
+ setIsLoaded(false);
24428
+ };
24429
+ }, [verifyURL]);
24430
+ return isLoaded;
24431
+ };
24432
+
24400
24433
 
24401
24434
 
24402
24435
  var index$1 = /*#__PURE__*/Object.freeze({
@@ -24404,7 +24437,8 @@ var index$1 = /*#__PURE__*/Object.freeze({
24404
24437
  useOutsideClick: useOutsideClickHook,
24405
24438
  useScrollTo: useScrollTo,
24406
24439
  useToastNotification: useToastNotification,
24407
- useConditionallyAddValidator: useConditionallyAddValidator
24440
+ useConditionallyAddValidator: useConditionallyAddValidator,
24441
+ useTurnstileScript: useTurnstileScript
24408
24442
  });
24409
24443
 
24410
24444
  var hoverColor$4 = "#116285";
@@ -49944,6 +49978,94 @@ var HeroImage = function HeroImage(_ref) {
49944
49978
  };
49945
49979
  var HeroImage$1 = withWindowSize(themeComponent(HeroImage, "HeroImage", fallbackValues$11, "v1"));
49946
49980
 
49981
+ var TurnstileWidgetContainer = styled__default(Box).withConfig({
49982
+ displayName: "TurnstileWidget__TurnstileWidgetContainer",
49983
+ componentId: "sc-btaugr-0"
49984
+ })(["display:flex;padding:", ";justify-content:", ";width:100%;"], function (_ref) {
49985
+ var padding = _ref.padding;
49986
+ return padding;
49987
+ }, function (_ref2) {
49988
+ var justify = _ref2.justify;
49989
+ return justify;
49990
+ });
49991
+ var TurnstileWidget = /*#__PURE__*/React.forwardRef(function (_ref3, ref) {
49992
+ var verifyURL = _ref3.verifyURL,
49993
+ siteKey = _ref3.siteKey,
49994
+ _ref3$onSuccess = _ref3.onSuccess,
49995
+ onSuccess = _ref3$onSuccess === void 0 ? noop$1 : _ref3$onSuccess,
49996
+ _ref3$onError = _ref3.onError,
49997
+ onError = _ref3$onError === void 0 ? noop$1 : _ref3$onError,
49998
+ _ref3$onExpired = _ref3.onExpired,
49999
+ onExpired = _ref3$onExpired === void 0 ? noop$1 : _ref3$onExpired,
50000
+ _ref3$padding = _ref3.padding,
50001
+ padding = _ref3$padding === void 0 ? "1rem" : _ref3$padding,
50002
+ _ref3$justify = _ref3.justify,
50003
+ justify = _ref3$justify === void 0 ? "flex-end" : _ref3$justify,
50004
+ _ref3$size = _ref3.size,
50005
+ size = _ref3$size === void 0 ? "normal" : _ref3$size,
50006
+ _ref3$tabindex = _ref3.tabindex,
50007
+ tabindex = _ref3$tabindex === void 0 ? 0 : _ref3$tabindex,
50008
+ _ref3$retry = _ref3.retry,
50009
+ retry = _ref3$retry === void 0 ? "auto" : _ref3$retry,
50010
+ _ref3$theme = _ref3.theme,
50011
+ theme = _ref3$theme === void 0 ? "auto" : _ref3$theme,
50012
+ _ref3$extraStyles = _ref3.extraStyles,
50013
+ extraStyles = _ref3$extraStyles === void 0 ? "" : _ref3$extraStyles;
50014
+ if (!verifyURL || !siteKey) return null;
50015
+ var widgetRef = React.useRef(null);
50016
+ var _useState = React.useState(null),
50017
+ _useState2 = _slicedToArray(_useState, 2),
50018
+ widgetId = _useState2[0],
50019
+ setWidgetId = _useState2[1];
50020
+ var isTurnstileLoaded = useTurnstileScript(verifyURL);
50021
+
50022
+ // Allow the parent component to reset the Turnstile widget
50023
+ React.useImperativeHandle(ref, function () {
50024
+ return {
50025
+ reset: function reset() {
50026
+ if (widgetId && window.turnstile) {
50027
+ window.turnstile.reset(widgetId);
50028
+ }
50029
+ }
50030
+ };
50031
+ }, [widgetId]);
50032
+ React.useEffect(function () {
50033
+ if (!widgetRef.current || !window.turnstile) return;
50034
+ if (!widgetId) {
50035
+ var newWidgetId = window.turnstile.render(widgetRef.current, {
50036
+ sitekey: siteKey,
50037
+ size: size,
50038
+ retry: retry,
50039
+ tabindex: tabindex,
50040
+ theme: theme,
50041
+ callback: function callback(token) {
50042
+ return onSuccess(token);
50043
+ },
50044
+ "error-callback": function errorCallback() {
50045
+ return onError();
50046
+ },
50047
+ "expired-callback": function expiredCallback() {
50048
+ return onExpired();
50049
+ }
50050
+ });
50051
+ setWidgetId(newWidgetId);
50052
+ }
50053
+ return function () {
50054
+ if (widgetId && window.turnstile) {
50055
+ window.turnstile.remove(widgetId);
50056
+ setWidgetId(null);
50057
+ }
50058
+ };
50059
+ }, [isTurnstileLoaded, siteKey, widgetId]);
50060
+ return /*#__PURE__*/React__default.createElement(TurnstileWidgetContainer, {
50061
+ padding: padding,
50062
+ justify: justify,
50063
+ extraStyles: extraStyles
50064
+ }, /*#__PURE__*/React__default.createElement("div", {
50065
+ ref: widgetRef
50066
+ }));
50067
+ });
50068
+
49947
50069
  var pageBackground = "#FBFCFD";
49948
50070
  var fallbackValues$12 = {
49949
50071
  pageBackground: pageBackground
@@ -50496,6 +50618,7 @@ exports.ToastNotification = ToastNotification;
50496
50618
  exports.ToggleSwitch = ToggleSwitch$1;
50497
50619
  exports.TrashIcon = TrashIcon$1;
50498
50620
  exports.TrashIconV2 = TrashIconV2$1;
50621
+ exports.TurnstileWidget = TurnstileWidget;
50499
50622
  exports.TypeaheadInput = TypeaheadInput;
50500
50623
  exports.VerifiedEmailIcon = VerifiedEmailIcon$1;
50501
50624
  exports.VoidedIcon = VoidedIcon;