@thecb/components 11.3.2 → 11.3.3-beta.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thecb/components",
3
- "version": "11.3.2",
3
+ "version": "11.3.3-beta.0",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "typings": "dist/index.d.ts",
package/src/.DS_Store ADDED
Binary file
Binary file
Binary file
@@ -1,6 +1,9 @@
1
1
  import React from "react";
2
+ import { MATISSE_BLUE } from "../../../constants/colors";
2
3
 
3
- const CustomerSearchIcon = () => {
4
+ const CustomerSearchIcon = ({
5
+ fillPrimary = MATISSE_BLUE
6
+ }) => {
4
7
  return (
5
8
  <svg
6
9
  xmlns="http://www.w3.org/2000/svg"
@@ -75,7 +78,7 @@ const CustomerSearchIcon = () => {
75
78
  d="M185 185c28.719 0 52 5.373 52 12s-23.281 12-52 12c-28.718 0-52-5.373-52-12s23.282-12 52-12zM97 44a2 2 0 012 2v52a2 2 0 01-2 2H45a2 2 0 01-2-2V46a2 2 0 012-2h52zM80 70c-3.535 0-6.145 1.941-7.827 5.824C70.192 73.274 67.633 72 64.5 72c-5.912 0-9.773 4.536-11.585 13.608a2 2 0 001.83 2.388l.13.004h19.25l.148-.005a2 2 0 001.812-2.387 37.807 37.807 0 00-.733-3.045L75.184 82h11.893l.15-.005a2 2 0 001.797-2.451C87.534 73.18 84.526 70 80 70zm136-26c10.493 0 19 8.507 19 19s-8.507 19-19 19-19-8.507-19-19 8.507-19 19-19zM64.5 56a7 7 0 100 14 7 7 0 000-14zM216 58c-4.206 0-7.903 2.689-9.348 6.641a2.5 2.5 0 004.635 1.87l.061-.152.083-.214c.786-1.896 2.575-3.145 4.57-3.145 1.994 0 3.782 1.249 4.568 3.145l.083.214.061.152a2.5 2.5 0 004.635-1.87C223.903 60.69 220.207 58 216.001 58zM80 57a5.5 5.5 0 100 11 5.5 5.5 0 000-11z"
76
79
  ></path>
77
80
  <path
78
- fill="#15749D"
81
+ fill={fillPrimary}
79
82
  fillRule="nonzero"
80
83
  d="M182 176v20a4 4 0 01-3.8 3.995l-.2.005h-14a4 4 0 01-.2-7.995l.2-.005h10v-16h8zm14 0v16h10a4 4 0 013.995 3.8l.005.2a4 4 0 01-3.8 3.995l-.2.005h-14a4 4 0 01-3.995-3.8L188 196v-20h8zM69 128.5v9l-7.875 4.429 32.876 6.953c1.81-4.055 5.877-6.882 10.604-6.882a4 4 0 01.2 7.995l-.2.005a3.605 3.605 0 00-3.605 3.593v.035-.023a3.606 3.606 0 003.414 3.601l.191.005h6.644a4 4 0 01.2 7.995l-.2.005h-6.644c-5.246 0-9.679-3.48-11.115-8.259l-44.708-9.457c-3.58-.757-4.322-5.493-1.242-7.336l.175-.1L69 128.5zM263.644 96c6.184 0 11.24 4.838 11.586 10.936l38.713 7.13c3.304.609 4.407 4.749 1.927 6.93l-.15.125L301 133v-10.5l2.891-2.151-31.014-5.712a11.586 11.586 0 01-8.881 4.569l-.352.005H257l-.2-.005a4 4 0 010-7.99l.2-.005h6.644l.191-.005a3.606 3.606 0 003.414-3.601c0-1.99-.358-3.259-2.403-5.238a361.04 361.04 0 00-4.65-4.395A3.998 3.998 0 01263.644 96zM97 40a6 6 0 016 6v52a6 6 0 01-6 6H45a6 6 0 01-6-6V46a6 6 0 016-6h52zm0 4H45a2 2 0 00-1.995 1.85L43 46v52a2 2 0 001.85 1.995L45 100h52a2 2 0 001.995-1.85L99 98V46a2 2 0 00-1.85-1.995L97 44zM80 70c4.526 0 7.534 3.181 9.024 9.544a2 2 0 01-1.798 2.45l-.149.006H75.184c.342 1.11.643 2.313.901 3.608a2 2 0 01-1.812 2.387l-.149.005H54.876a2 2 0 01-1.961-2.392C54.727 76.536 58.588 72 64.5 72c3.134 0 5.692 1.275 7.673 3.824C73.855 71.941 76.465 70 80 70zM64.5 56a7 7 0 110 14 7 7 0 010-14zM80 57a5.5 5.5 0 110 11 5.5 5.5 0 010-11z"
81
84
  ></path>
@@ -1,6 +1,10 @@
1
1
  import React from "react";
2
+ import { SEA_GREEN, HINT_GREEN } from "../../../constants/colors";
2
3
 
3
- const PaymentSearchIcon = () => {
4
+ const PaymentSearchIcon = ({
5
+ fillPrimary = SEA_GREEN,
6
+ fillSecondary = HINT_GREEN
7
+ }) => {
4
8
  return (
5
9
  <svg
6
10
  xmlns="http://www.w3.org/2000/svg"
@@ -75,11 +79,11 @@ const PaymentSearchIcon = () => {
75
79
  xlinkHref="#payment-search-path-1"
76
80
  ></use>
77
81
  <path
78
- fill="#E8FFEF"
82
+ fill={fillSecondary}
79
83
  d="M185 185c28.719 0 52 5.373 52 12s-23.281 12-52 12c-28.718 0-52-5.373-52-12s23.282-12 52-12zM97 44a2 2 0 012 2v52a2 2 0 01-2 2H45a2 2 0 01-2-2V46a2 2 0 012-2h52zM74.134 56h-5.268c-.441 0-.806.304-.86.696l-.006.1v2.456c-4.391.845-7.029 3.74-7.144 7.532l-.004.26v.072c0 5.135 4.208 6.644 9.66 7.865 3.408.801 4.302 1.333 4.351 2.348l.002.093v.073c0 1.077-1.025 1.723-2.963 1.723-2.717 0-5.28-.875-7.66-2.542a.896.896 0 00-1.112.082l-.078.081-2.845 3.336a.84.84 0 00.11 1.21c2.061 1.596 4.522 2.668 7.182 3.207l.5.095.001 2.581c0 .37.3.677.688.725l.108.007h5.407c.403 0 .737-.275.79-.632l.007-.1v-2.602c4.212-.902 6.88-3.587 6.996-7.58l.004-.273v-.072c0-4.705-3.659-6.572-9.513-7.83-3.483-.767-4.411-1.263-4.462-2.344l-.002-.097v-.072c0-.934.842-1.616 2.562-1.616 2.041 0 4.32.669 6.462 2.007a.9.9 0 001.13-.126l.073-.089 2.566-3.556a.841.841 0 00-.185-1.18 14.999 14.999 0 00-5.178-2.318l-.451-.103-.002-2.62c0-.44-.388-.797-.866-.797z"
80
84
  ></path>
81
85
  <path
82
- fill="#317D4F"
86
+ fill={fillPrimary}
83
87
  fillRule="nonzero"
84
88
  d="M182 176v20a4 4 0 01-3.8 3.995l-.2.005h-14a4 4 0 01-.2-7.995l.2-.005h10v-16h8zm14 0v16h10a4 4 0 013.995 3.8l.005.2a4 4 0 01-3.8 3.995l-.2.005h-14a4 4 0 01-3.995-3.8L188 196v-20h8zM69 128.5v9l-7.875 4.429 32.876 6.953c1.81-4.055 5.877-6.882 10.604-6.882a4 4 0 01.2 7.995l-.2.005a3.605 3.605 0 00-3.605 3.593v.035-.023a3.606 3.606 0 003.414 3.601l.191.005h6.644a4 4 0 01.2 7.995l-.2.005h-6.644c-5.246 0-9.679-3.48-11.115-8.259l-44.708-9.457c-3.58-.757-4.322-5.493-1.242-7.336l.175-.1L69 128.5zM263.644 96c6.184 0 11.24 4.838 11.586 10.936l38.713 7.13c3.304.609 4.407 4.749 1.927 6.93l-.15.125L301 133v-10.5l2.891-2.151-31.014-5.712a11.586 11.586 0 01-8.881 4.569l-.352.005H257l-.2-.005a4 4 0 010-7.99l.2-.005h6.644l.191-.005a3.606 3.606 0 003.414-3.601c0-1.99-.358-3.259-2.403-5.238a361.04 361.04 0 00-4.65-4.395A3.998 3.998 0 01263.644 96zM97 40a6 6 0 016 6v52a6 6 0 01-6 6H45a6 6 0 01-6-6V46a6 6 0 016-6h52zm0 4H45a2 2 0 00-1.995 1.85L43 46v52a2 2 0 001.85 1.995L45 100h52a2 2 0 001.995-1.85L99 98V46a2 2 0 00-1.85-1.995L97 44zM74.134 56c.478 0 .866.356.866.796l.002 2.621c2.128.452 3.983 1.265 5.629 2.42.383.27.457.804.185 1.181l-2.566 3.556c-.275.382-.801.466-1.203.215-2.142-1.338-4.42-2.007-6.462-2.007-1.72 0-2.562.682-2.562 1.616v.072c0 1.15.879 1.652 4.464 2.442C78.341 70.169 82 72.036 82 76.742v.07c0 4.144-2.692 6.932-7 7.854v2.602c0 .404-.357.732-.797.732h-5.407c-.44 0-.796-.328-.796-.732v-2.581c-2.852-.502-5.493-1.606-7.684-3.302a.84.84 0 01-.11-1.21l2.846-3.336a.898.898 0 011.19-.163c2.38 1.667 4.943 2.542 7.66 2.542 1.938 0 2.963-.646 2.963-1.723v-.073c0-1.076-.841-1.615-4.353-2.44-5.452-1.222-9.66-2.73-9.66-7.866v-.072c0-3.92 2.657-6.928 7.148-7.792v-2.456c0-.44.388-.796.866-.796h5.268z"
85
89
  ></path>
@@ -6,42 +6,17 @@ import React, {
6
6
  useImperativeHandle
7
7
  } from "react";
8
8
  import { Box } from "../../atoms/layouts";
9
- import Text from "../../atoms/text";
10
9
  import styled from "styled-components";
11
10
  import { useTurnstileScript } from "../../../hooks";
12
11
  import { noop } from "../../../util/general";
13
- import { ERROR_COLOR } from "../../../constants/colors";
14
12
 
15
13
  const TurnstileWidgetContainer = styled(Box)`
16
14
  display: flex;
17
- flex-direction: column;
18
15
  padding: ${({ padding }) => padding};
19
16
  justify-content: ${({ justify }) => justify};
20
- align-items: ${({ align }) => align};
21
17
  width: 100%;
22
18
  `;
23
19
 
24
- const FATAL_ERROR_CODES = [
25
- // Configuration errors
26
- /^100/,
27
- /^105/,
28
- /^110100$/,
29
- /^110110$/,
30
- /^110200$/,
31
- /^110420$/,
32
- /^110430$/,
33
- /^400020$/,
34
- /^400030$/,
35
- /^400040$/,
36
- // Browser/environment errors
37
- /^110500$/,
38
- /^110510$/,
39
- /^200010$/,
40
- /^200100$/,
41
- // Internal errors
42
- /^120/
43
- ];
44
-
45
20
  const TurnstileWidget = forwardRef(
46
21
  (
47
22
  {
@@ -52,11 +27,10 @@ const TurnstileWidget = forwardRef(
52
27
  onExpired = noop,
53
28
  padding = "1rem",
54
29
  justify = "flex-end",
55
- align = "flex-end",
56
30
  size = "normal",
57
31
  tabindex = 0,
58
- retry = "never",
59
- theme = "light",
32
+ retry = "auto",
33
+ theme = "auto",
60
34
  extraStyles = ""
61
35
  },
62
36
  ref
@@ -64,118 +38,53 @@ const TurnstileWidget = forwardRef(
64
38
  if (!verifyURL || !siteKey) return null;
65
39
 
66
40
  const widgetRef = useRef(null);
67
- const widgetIdRef = useRef(null);
68
- const [error, setError] = useState(null);
69
-
70
- const { scriptLoaded, scriptError } = useTurnstileScript(verifyURL);
71
-
72
- // Clear the error state
73
- const clearError = () => {
74
- setError(null);
75
- };
76
-
77
- // Handle errors based on the retry strategy
78
- const handleError = errorCode => {
79
- if (!errorCode) return;
80
- const isFatalError = FATAL_ERROR_CODES.some(pattern =>
81
- pattern.test(errorCode)
82
- );
83
- const errorMessage = getErrorMessage(isFatalError);
84
- setError(errorMessage);
85
- };
86
-
87
- const getErrorMessage = isFatalError => {
88
- if (isFatalError) {
89
- return "Browser or system error. Please refresh the page or try a different browser.";
90
- }
91
- return "Something went wrong. Please refresh and try again.";
92
- };
41
+ const [widgetId, setWidgetId] = useState(null);
42
+ const isTurnstileLoaded = useTurnstileScript(verifyURL);
93
43
 
94
44
  // Allow the parent component to reset the Turnstile widget
95
45
  useImperativeHandle(
96
46
  ref,
97
47
  () => ({
98
48
  reset: () => {
99
- if (widgetIdRef.current && window.turnstile) {
100
- window.turnstile.reset(widgetIdRef.current);
101
- clearError();
49
+ if (widgetId && window.turnstile) {
50
+ window.turnstile.reset(widgetId);
102
51
  }
103
52
  }
104
53
  }),
105
- []
54
+ [widgetId]
106
55
  );
107
56
 
108
57
  useEffect(() => {
109
- if (scriptError) {
110
- setError(
111
- "Unable to load security verification. Please refresh the page."
112
- );
113
- onError?.("script_load_failed");
114
- return;
115
- }
116
-
117
- if (widgetIdRef.current || !window.turnstile || !scriptLoaded) return;
118
-
119
- try {
120
- widgetIdRef.current = window.turnstile.render(widgetRef.current, {
58
+ if (!widgetRef.current || !window.turnstile) return;
59
+ if (!widgetId) {
60
+ const newWidgetId = window.turnstile.render(widgetRef.current, {
121
61
  sitekey: siteKey,
122
62
  size: size,
123
63
  retry: retry,
124
64
  tabindex: tabindex,
125
65
  theme: theme,
126
- callback: token => {
127
- clearError();
128
- onSuccess?.(token);
129
- },
130
- "error-callback": errorCode => {
131
- handleError(errorCode);
132
- onError?.(errorCode);
133
- },
134
- "expired-callback": () => {
135
- clearError();
136
- onExpired?.();
137
- }
66
+ callback: token => onSuccess(token),
67
+ "error-callback": () => onError(),
68
+ "expired-callback": () => onExpired()
138
69
  });
139
- } catch (error) {
140
- setError(
141
- "Unable to load security verification. Please refresh the page."
142
- );
143
- onError?.("render_failed");
70
+ setWidgetId(newWidgetId);
144
71
  }
145
-
146
72
  return () => {
147
- if (widgetIdRef.current && window.turnstile) {
148
- window.turnstile.remove(widgetIdRef.current);
149
- widgetIdRef.current = null;
150
- clearError();
73
+ if (widgetId && window.turnstile) {
74
+ window.turnstile.remove(widgetId);
75
+ setWidgetId(null);
151
76
  }
152
77
  };
153
- }, [scriptLoaded, scriptError, siteKey]);
78
+ }, [isTurnstileLoaded, siteKey, widgetId]);
154
79
 
155
80
  return (
156
- <>
157
- <TurnstileWidgetContainer
158
- padding={padding}
159
- justify={justify}
160
- align={align}
161
- extraStyles={extraStyles}
162
- >
163
- <div ref={widgetRef} />
164
- {error && (
165
- <Text
166
- color={ERROR_COLOR}
167
- variant="pXS"
168
- extraStyles={`
169
- word-break: break-word;
170
- text-align: end;
171
- padding-top: 0.5rem;
172
- `}
173
- >
174
- {error}
175
- </Text>
176
- )}
177
- </TurnstileWidgetContainer>
178
- </>
81
+ <TurnstileWidgetContainer
82
+ padding={padding}
83
+ justify={justify}
84
+ extraStyles={extraStyles}
85
+ >
86
+ <div ref={widgetRef} />
87
+ </TurnstileWidgetContainer>
179
88
  );
180
89
  }
181
90
  );
@@ -6,44 +6,31 @@ import { useEffect, useState } from "react";
6
6
  * @param {string} verifyURL - The URL of the Turnstile verification script.
7
7
  */
8
8
  const useTurnstileScript = verifyURL => {
9
- const [scriptLoaded, setScriptLoaded] = useState(false);
10
- const [scriptError, setScriptError] = useState(false);
11
-
12
- const handleScriptError = () => {
13
- setScriptError(true);
14
- setScriptLoaded(false);
15
- };
9
+ const [isLoaded, setIsLoaded] = useState(false);
16
10
 
17
11
  useEffect(() => {
18
12
  if (typeof window === "undefined") {
19
- setScriptLoaded(false);
13
+ setIsLoaded(false);
20
14
  return;
21
15
  }
22
16
  if (window.turnstile && window.turnstile.render) {
23
- setScriptLoaded(true);
17
+ setIsLoaded(true);
24
18
  return;
25
19
  }
26
20
 
27
21
  const script = document.createElement("script");
28
22
  script.src = `${verifyURL}?render=explicit`;
29
23
  script.onload = () => {
30
- setScriptLoaded(true);
31
- };
32
- script.onerror = () => {
33
- handleScriptError();
34
- };
35
- script.onabort = () => {
36
- handleScriptError();
24
+ setIsLoaded(true);
37
25
  };
38
26
  script.defer = true;
39
27
  document.getElementsByTagName("head")[0].appendChild(script);
40
28
 
41
29
  return () => {
42
- setScriptLoaded(false);
43
- setScriptError(false);
30
+ setIsLoaded(false);
44
31
  };
45
32
  }, [verifyURL]);
46
33
 
47
- return { scriptLoaded, scriptError };
34
+ return isLoaded;
48
35
  };
49
36
  export default useTurnstileScript;