@arkyn/components 1.3.145 → 1.3.147

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. package/dist/bundle.js +84941 -18386
  2. package/dist/bundle.umd.cjs +1870 -210
  3. package/dist/components/ClientOnly.d.ts +7 -0
  4. package/dist/components/ClientOnly.d.ts.map +1 -0
  5. package/dist/components/ClientOnly.js +5 -0
  6. package/dist/components/GoogleTagManager/GoogleTagManager.client.d.ts +11 -0
  7. package/dist/components/GoogleTagManager/GoogleTagManager.client.d.ts.map +1 -0
  8. package/dist/components/GoogleTagManager/GoogleTagManager.client.js +8 -0
  9. package/dist/components/GoogleTagManager/googleTagManager.d.ts +20 -0
  10. package/dist/components/GoogleTagManager/googleTagManager.d.ts.map +1 -0
  11. package/dist/components/GoogleTagManager/googleTagManager.js +52 -0
  12. package/dist/components/GoogleTagManager/index.d.ts +11 -0
  13. package/dist/components/GoogleTagManager/index.d.ts.map +1 -0
  14. package/dist/components/GoogleTagManager/index.js +8 -0
  15. package/dist/components/GoogleTagManager/snippets/appendToDataLayer.d.ts +7 -0
  16. package/dist/components/GoogleTagManager/snippets/appendToDataLayer.d.ts.map +1 -0
  17. package/dist/components/GoogleTagManager/snippets/appendToDataLayer.js +7 -0
  18. package/dist/components/GoogleTagManager/snippets/generateGTMElements.d.ts +15 -0
  19. package/dist/components/GoogleTagManager/snippets/generateGTMElements.d.ts.map +1 -0
  20. package/dist/components/GoogleTagManager/snippets/generateGTMElements.js +25 -0
  21. package/dist/hooks/useHydrated.d.ts +3 -0
  22. package/dist/hooks/useHydrated.d.ts.map +1 -0
  23. package/dist/hooks/useHydrated.js +8 -0
  24. package/dist/index.d.ts +4 -1
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +5 -1
  27. package/dist/provider/ToastProvider.d.ts.map +1 -1
  28. package/dist/provider/ToastProvider.js +26 -2
  29. package/dist/style.css +1 -1
  30. package/package.json +1 -1
  31. package/src/components/ClientOnly.tsx +10 -0
  32. package/src/components/GoogleTagManager/GoogleTagManager.client.tsx +19 -0
  33. package/src/components/GoogleTagManager/googleTagManager.ts +100 -0
  34. package/src/components/GoogleTagManager/index.tsx +39 -0
  35. package/src/components/GoogleTagManager/snippets/appendToDataLayer.ts +14 -0
  36. package/src/components/GoogleTagManager/snippets/generateGTMElements.ts +43 -0
  37. package/src/hooks/useHydrated.ts +15 -0
  38. package/src/index.ts +6 -1
  39. package/src/provider/ToastProvider.tsx +26 -2
@@ -0,0 +1,100 @@
1
+ import { appendToDataLayer } from "./snippets/appendToDataLayer";
2
+ import { generateGTMElements } from "./snippets/generateGTMElements";
3
+
4
+ type InitializeDataLayerProps = {
5
+ dataLayerName: string;
6
+ dataLayer: Record<string, string>;
7
+ };
8
+
9
+ type InitializeGTMProps = {
10
+ id: string;
11
+ events: Record<string, string>;
12
+ dataLayer: Record<string, string>;
13
+ dataLayerName: string;
14
+ preview: string;
15
+ auth: string;
16
+ };
17
+
18
+ type InitializeProps = {
19
+ gtmId: string;
20
+ events: Record<string, string>;
21
+ dataLayer: Record<string, string>;
22
+ dataLayerName: string;
23
+ auth: string;
24
+ preview: string;
25
+ };
26
+
27
+ interface Window {
28
+ [key: string]: any;
29
+ }
30
+
31
+ declare var window: Window;
32
+
33
+ class GoogleTagManager {
34
+ private initializeDataScript(dataLayer: string) {
35
+ const script = document.createElement("script");
36
+ script.innerHTML = dataLayer;
37
+ return script;
38
+ }
39
+
40
+ private initializeGTMElements(props: InitializeGTMProps) {
41
+ const snippets = generateGTMElements(props);
42
+
43
+ const noScript = () => {
44
+ const noscript = document.createElement("noscript");
45
+ noscript.innerHTML = snippets.iframe;
46
+ return noscript;
47
+ };
48
+
49
+ const script = () => {
50
+ const script = document.createElement("script");
51
+ script.innerHTML = snippets.script;
52
+ return script;
53
+ };
54
+
55
+ const dataScript = this.initializeDataScript(snippets.dataLayerVar);
56
+
57
+ return {
58
+ noScript,
59
+ script,
60
+ dataScript,
61
+ };
62
+ }
63
+
64
+ initializeDataLayer(props: InitializeDataLayerProps) {
65
+ const { dataLayer, dataLayerName } = props;
66
+
67
+ if (window[dataLayerName]) return window[dataLayerName].push(dataLayer);
68
+
69
+ const snippets = appendToDataLayer({ dataLayer, dataLayerName });
70
+ const dataScript = this.initializeDataScript(snippets);
71
+
72
+ document.head.insertBefore(dataScript, document.head.childNodes[0]);
73
+ }
74
+
75
+ initialize(props: InitializeProps) {
76
+ const {
77
+ events,
78
+ gtmId,
79
+ dataLayer,
80
+ auth = "",
81
+ preview = "",
82
+ dataLayerName = "dataLayer",
83
+ } = props;
84
+
85
+ const gtm = this.initializeGTMElements({
86
+ id: gtmId,
87
+ events: events,
88
+ dataLayer: dataLayer || undefined,
89
+ dataLayerName: dataLayerName,
90
+ auth,
91
+ preview,
92
+ });
93
+
94
+ if (dataLayer) document.head.appendChild(gtm.dataScript);
95
+ document.head.insertBefore(gtm.script(), document.head.childNodes[0]);
96
+ document.body.insertBefore(gtm.noScript(), document.body.childNodes[0]);
97
+ }
98
+ }
99
+
100
+ export { GoogleTagManager };
@@ -0,0 +1,39 @@
1
+ import { ClientOnly } from "../../components/ClientOnly";
2
+ import { GoogleTagManagerClient } from "./GoogleTagManager.client";
3
+
4
+ type GoogleTagManagerProps = {
5
+ gtmId: string;
6
+ events?: Record<string, string>;
7
+ dataLayer?: Record<string, string>;
8
+ dataLayerName?: string;
9
+ auth?: string;
10
+ preview?: string;
11
+ };
12
+
13
+ function GoogleTagManager(props: GoogleTagManagerProps) {
14
+ const {
15
+ gtmId,
16
+ auth = "",
17
+ preview = "",
18
+ dataLayerName = "dataLayer",
19
+ events = {},
20
+ dataLayer = {},
21
+ } = props;
22
+
23
+ return (
24
+ <ClientOnly>
25
+ {() => (
26
+ <GoogleTagManagerClient
27
+ auth={auth}
28
+ dataLayer={dataLayer}
29
+ dataLayerName={dataLayerName}
30
+ events={events}
31
+ gtmId={gtmId}
32
+ preview={preview}
33
+ />
34
+ )}
35
+ </ClientOnly>
36
+ );
37
+ }
38
+
39
+ export { GoogleTagManager };
@@ -0,0 +1,14 @@
1
+ type AppendToDataLayer = {
2
+ dataLayer: Record<string, string>;
3
+ dataLayerName: string;
4
+ };
5
+
6
+ function appendToDataLayer(props: AppendToDataLayer) {
7
+ const { dataLayer, dataLayerName } = props;
8
+
9
+ return `
10
+ window.${dataLayerName} = window.${dataLayerName} || [];
11
+ window.${dataLayerName}.push(${JSON.stringify(dataLayer)})`;
12
+ }
13
+
14
+ export { appendToDataLayer };
@@ -0,0 +1,43 @@
1
+ import { appendToDataLayer } from "./appendToDataLayer";
2
+
3
+ type GenerateGTMElementsProps = {
4
+ id: string;
5
+ events: Record<string, string>;
6
+ dataLayer: Record<string, string>;
7
+ dataLayerName: string;
8
+ preview: string;
9
+ auth: string;
10
+ };
11
+
12
+ function generateGTMElements(props: GenerateGTMElementsProps) {
13
+ const { id, events, dataLayer, dataLayerName, preview, auth } = props;
14
+
15
+ const gtmAuth = `&gtm_auth=${auth}`;
16
+ const gtmPreview = `&gtm_preview=${preview}`;
17
+
18
+ if (!id) console.warn("GTM Id is required");
19
+
20
+ const iframe = `
21
+ <iframe src="https://www.googletagmanager.com/ns.html?id=${id}${gtmAuth}${gtmPreview}&gtm_cookies_win=x"
22
+ height="0" width="0" style="display:none;visibility:hidden" id="tag-manager"></iframe>`;
23
+
24
+ const script = `
25
+ (function(w,d,s,l,i){w[l]=w[l]||[];
26
+ w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js', ${JSON.stringify(
27
+ events
28
+ ).slice(1, -1)}});
29
+ var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';
30
+ j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl+'${gtmAuth}${gtmPreview}&gtm_cookies_win=x';
31
+ f.parentNode.insertBefore(j,f);
32
+ })(window,document,'script','${dataLayerName}','${id}');`;
33
+
34
+ const dataLayerVar = appendToDataLayer({ dataLayer, dataLayerName });
35
+
36
+ return {
37
+ iframe,
38
+ script,
39
+ dataLayerVar,
40
+ };
41
+ }
42
+
43
+ export { generateGTMElements };
@@ -0,0 +1,15 @@
1
+ import { useSyncExternalStore } from "react";
2
+
3
+ function subscribe() {
4
+ return () => {};
5
+ }
6
+
7
+ function useHydrated() {
8
+ return useSyncExternalStore(
9
+ subscribe,
10
+ () => true,
11
+ () => false
12
+ );
13
+ }
14
+
15
+ export { useHydrated };
package/src/index.ts CHANGED
@@ -9,7 +9,6 @@ export {
9
9
  export { Badge } from "./components/Badge";
10
10
  export { Card } from "./components/Card";
11
11
  export { Divider } from "./components/Divider";
12
- export { GoogleMap } from "./components/GoogleMap";
13
12
  export { Skeleton } from "./components/Skeleton";
14
13
  export {
15
14
  TableBody,
@@ -49,6 +48,7 @@ export { Tooltip } from "./components/Tooltip";
49
48
  export { useAutomation } from "./hooks/useAutomation";
50
49
  export { useDrawer } from "./hooks/useDrawer";
51
50
  export { useFieldErrors } from "./hooks/useFieldErrors";
51
+ export { useHydrated } from "./hooks/useHydrated";
52
52
  export { useModal } from "./hooks/useModal";
53
53
  export { useScopedParams } from "./hooks/useScopedParams";
54
54
  export { useToast } from "./hooks/useToast";
@@ -58,3 +58,8 @@ export { DrawerProvider } from "./provider/DrawerProvider";
58
58
  export { GoogleProvider } from "./provider/GoogleProvider";
59
59
  export { ModalProvider } from "./provider/ModalProvider";
60
60
  export { ToastProvider } from "./provider/ToastProvider";
61
+
62
+ // Others
63
+ export { ClientOnly } from "./components/ClientOnly";
64
+ export { GoogleMap } from "./components/GoogleMap";
65
+ export { GoogleTagManager } from "./components/GoogleTagManager";
@@ -7,9 +7,33 @@ function ToastProvider({ children }: ToastProviderProps) {
7
7
  function showToast(props: ToastProps) {
8
8
  switch (props.type) {
9
9
  case "success":
10
- return toast.success(props.message);
10
+ return toast.success(props.message, {
11
+ style: {
12
+ background: "#10B981",
13
+ color: "#ffffff",
14
+ padding: "12px 16px",
15
+ fontSize: "14px",
16
+ fontWeight: 600,
17
+ },
18
+ iconTheme: {
19
+ primary: "#059669",
20
+ secondary: "#ffffff",
21
+ },
22
+ });
11
23
  case "danger":
12
- return toast.error(props.message);
24
+ return toast.error(props.message, {
25
+ style: {
26
+ background: "#E11D48",
27
+ color: "#ffffff",
28
+ padding: "12px 16px",
29
+ fontSize: "14px",
30
+ fontWeight: 600,
31
+ },
32
+ iconTheme: {
33
+ primary: "#BE123C",
34
+ secondary: "#ffffff",
35
+ },
36
+ });
13
37
  }
14
38
  }
15
39