@wf-financing/ui 3.13.5 → 4.0.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.
Files changed (41) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/index.es.js +5234 -5298
  3. package/package.json +4 -4
  4. package/sdk/index.ts +2 -2
  5. package/src/App.tsx +2 -2
  6. package/src/CtaWidget.tsx +2 -1
  7. package/src/api/continueHostedApplication.ts +2 -2
  8. package/src/api/ctaBanner.ts +2 -2
  9. package/src/api/dismissCta.ts +2 -2
  10. package/src/api/fetchCtaBanner.test.ts +1 -2
  11. package/src/api/getHeadlessSdkInstance.test.ts +1 -2
  12. package/src/api/getHeadlessSdkInstance.ts +2 -2
  13. package/src/api/startHostedApplication.test.ts +1 -2
  14. package/src/api/startHostedApplication.ts +2 -2
  15. package/src/components/banner/CtaBanner.tsx +1 -4
  16. package/src/components/modal/BulletList.tsx +24 -0
  17. package/src/components/modal/ConsentModal.snapshot.stories.tsx +6 -18
  18. package/src/components/modal/ConsentModal.tsx +7 -4
  19. package/src/components/modal/ConsentModalContent.tsx +13 -40
  20. package/src/components/modal/Modal.tsx +14 -6
  21. package/src/components/modal/ModalFooter.tsx +6 -11
  22. package/src/components/modal/ModalHeader.tsx +21 -0
  23. package/src/components/modal/TemplateWithUrl.tsx +1 -1
  24. package/src/components/modal/modalEnhancements.ts +20 -5
  25. package/src/config/index.ts +0 -3
  26. package/src/hooks/useContinueHostedApplication.ts +2 -1
  27. package/src/hooks/useCopy.ts +3 -10
  28. package/src/hooks/useCtaBanner.ts +2 -1
  29. package/src/hooks/useDismissCta.ts +2 -1
  30. package/src/hooks/usePreloadImage.ts +30 -10
  31. package/src/hooks/useStartHostedApplication.ts +2 -1
  32. package/src/main.tsx +2 -2
  33. package/src/utils/index.ts +0 -1
  34. package/src/utils/initializeHeadlessSdk.ts +2 -2
  35. package/src/utils/loadScriptAndInitializeSdk.ts +2 -2
  36. package/src/utils/partnerContext.ts +2 -2
  37. package/src/components/modal/FundingSteps.tsx +0 -34
  38. package/src/config/fontParameters.ts +0 -31
  39. package/src/config/staticUrls.ts +0 -5
  40. package/src/utils/applyFont.ts +0 -22
  41. package/src/utils/loadFont.ts +0 -33
@@ -1,20 +1,40 @@
1
1
  import { useEffect } from 'react';
2
+ import type { Copy } from '@wf-financing/ui-assets';
2
3
 
3
- export function usePreloadImage(src: string) {
4
+ export const usePreloadImage = (copy?: Copy) => {
4
5
  useEffect(() => {
5
6
  const head = document.head;
6
7
 
7
- if (!src) return;
8
+ if (!copy) return;
8
9
 
9
- const imageLink = document.createElement('link');
10
- imageLink.rel = 'preload';
11
- imageLink.as = 'image';
12
- imageLink.href = src;
10
+ const consentModal = copy.consentModal;
11
+ const logoUrl = consentModal.logoUrl;
12
+ const partnerTemplate = copy?.partnerTemplate;
13
+ const partnerLogoUrl = partnerTemplate?.partnerLogoUrl;
13
14
 
14
- head.appendChild(imageLink);
15
+ const imageUrls = [logoUrl, partnerLogoUrl];
16
+
17
+ const imageNodes = imageUrls.map((imageUrl) => {
18
+ if (imageUrl) {
19
+ const imageLink = document.createElement('link');
20
+ imageLink.rel = 'preload';
21
+ imageLink.as = 'image';
22
+ imageLink.href = imageUrl;
23
+
24
+ head.appendChild(imageLink);
25
+
26
+ return imageLink;
27
+ }
28
+
29
+ return null;
30
+ });
15
31
 
16
32
  return () => {
17
- head.removeChild(imageLink);
33
+ imageNodes.forEach((imageUrl) => {
34
+ if (imageUrl) {
35
+ head.removeChild(imageUrl);
36
+ }
37
+ });
18
38
  };
19
- }, [src]);
20
- }
39
+ }, [copy]);
40
+ };
@@ -5,8 +5,9 @@ import { usePartnerContext } from './usePartnerContext';
5
5
 
6
6
  export const useStartHostedApplication = () => {
7
7
  const { companyToken, options, partnerCallback } = usePartnerContext();
8
+ const headlessOptions = { isSandbox: options?.isSandbox };
8
9
 
9
10
  return useMutation({
10
- mutationFn: () => startHostedApplication(companyToken, partnerCallback, options),
11
+ mutationFn: () => startHostedApplication(companyToken, partnerCallback, headlessOptions),
11
12
  });
12
13
  };
package/src/main.tsx CHANGED
@@ -1,4 +1,4 @@
1
- import { PartnerCallbackType, SdkOptionsType } from '@wf-financing/embedded-types';
1
+ import { PartnerCallbackType, UiSdkOptions } from '@wf-financing/embedded-types';
2
2
  import { Logger } from '@wf-financing/logger';
3
3
  import ReactDOM from 'react-dom/client';
4
4
  import { StyleSheetManager } from 'styled-components';
@@ -16,7 +16,7 @@ export const mountToTarget = async (
16
16
  partnerTheme: PartnerTheme,
17
17
  partnerCallback: PartnerCallbackType,
18
18
  companyToken: string,
19
- options?: SdkOptionsType,
19
+ options?: UiSdkOptions,
20
20
  ): Promise<void> => {
21
21
  const isNewTargetId = targetId !== savedTargetId;
22
22
 
@@ -1,4 +1,3 @@
1
- export { applyFont } from './applyFont';
2
1
  export { applyStyles } from './applyStyles';
3
2
  export { createRoots } from './createRoots';
4
3
  export { getPartnerIdFromToken } from './getPartnerIdFromToken';
@@ -1,6 +1,6 @@
1
- import { IWayflyerHeadlessSdk, SdkOptionsType } from '@wf-financing/embedded-types';
1
+ import { IWayflyerHeadlessSdk, HeadlessSdkOptions } from '@wf-financing/embedded-types';
2
2
 
3
- export const initializeHeadlessSdk = (companyToken: string, options?: SdkOptionsType): IWayflyerHeadlessSdk => {
3
+ export const initializeHeadlessSdk = (companyToken: string, options?: HeadlessSdkOptions): IWayflyerHeadlessSdk => {
4
4
  if (!window.WayflyerHeadlessSdk) {
5
5
  throw new Error('Failed to load WayflyerHeadlessSdk from the script.');
6
6
  }
@@ -1,11 +1,11 @@
1
- import { IWayflyerHeadlessSdk, SdkOptionsType } from '@wf-financing/embedded-types';
1
+ import { IWayflyerHeadlessSdk, HeadlessSdkOptions } from '@wf-financing/embedded-types';
2
2
 
3
3
  import { initializeHeadlessSdk } from './initializeHeadlessSdk';
4
4
 
5
5
  export const loadScriptAndInitializeSdk = (
6
6
  script: HTMLScriptElement,
7
7
  companyToken: string,
8
- options?: SdkOptionsType,
8
+ options?: HeadlessSdkOptions,
9
9
  ): Promise<IWayflyerHeadlessSdk> => {
10
10
  return new Promise<IWayflyerHeadlessSdk>((resolve, reject) => {
11
11
  script.onload = () => {
@@ -1,10 +1,10 @@
1
- import { PartnerCallbackType, SdkOptionsType } from '@wf-financing/embedded-types';
1
+ import { PartnerCallbackType, UiSdkOptions } from '@wf-financing/embedded-types';
2
2
  import { createContext } from 'react';
3
3
 
4
4
  export type PartnerContextType = {
5
5
  companyToken: string;
6
6
  partnerCallback: PartnerCallbackType;
7
- options?: SdkOptionsType;
7
+ options?: UiSdkOptions;
8
8
  onWidgetClose: () => void;
9
9
  onWidgetDismiss: () => void;
10
10
  isWidgetDismissed: boolean;
@@ -1,34 +0,0 @@
1
- import { Flex, Text } from '@wayflyer/flyui';
2
-
3
- import { useDetectSmallScreen } from '../../hooks';
4
- import { getModalItems } from '../../utils';
5
-
6
- type ModalDescriptions = {
7
- title: string;
8
- description: string;
9
- };
10
-
11
- type FundingStepsProps = {
12
- descriptions: ModalDescriptions[];
13
- };
14
-
15
- export const FundingSteps = ({ descriptions }: FundingStepsProps) => {
16
- const isSmallScreen = useDetectSmallScreen();
17
- const modalDescriptions = getModalItems(descriptions);
18
-
19
- return (
20
- <Flex direction="column" gap="2">
21
- {modalDescriptions.map(({ title, description, Icon }) => (
22
- <Flex key={title} direction="row" align="center" gap="2">
23
- {!isSmallScreen && <Icon />}
24
- <Flex direction="column">
25
- <Text color="default" fontWeight="medium">
26
- {title}
27
- </Text>
28
- <Text color="placeholder">{description}</Text>
29
- </Flex>
30
- </Flex>
31
- ))}
32
- </Flex>
33
- );
34
- };
@@ -1,31 +0,0 @@
1
- import { STATIC_BASE_URL, DM_SANS_URL, MERRION_SANS_URL, MONTSERRAT_URL } from './staticUrls';
2
-
3
- export type FontParamsType = {
4
- fontFamily: string;
5
- fontUrl: string;
6
- fallbackFontUrl: string;
7
- };
8
-
9
- const dmSansParams = {
10
- fontFamily: 'DM Sans',
11
- fontUrl: `${STATIC_BASE_URL}${DM_SANS_URL}`,
12
- fallbackFontUrl: 'https://app.wayflyer.com/flyui-assets/fonts/dm-sans/DMSans-VariableFont_opsz,wght.ttf',
13
- };
14
-
15
- const merrionSansParams = {
16
- fontFamily: 'Merrion Sans',
17
- fontUrl: `${STATIC_BASE_URL}${MERRION_SANS_URL}`,
18
- fallbackFontUrl: 'https://app.wayflyer.com/flyui-assets/fonts/merrion-sans/Merrion_Sans-Medium.woff2',
19
- };
20
-
21
- const montserratParams = {
22
- fontFamily: 'Montserrat',
23
- fontUrl: `${STATIC_BASE_URL}${MONTSERRAT_URL}`,
24
- fallbackFontUrl: 'https://app.wayflyer.com/flyui-assets/fonts/montserrat/Montserrat-VariableFont_wght.ttf',
25
- };
26
-
27
- export const FONT_PARAMS: Record<string, FontParamsType> = {
28
- dmSansParams,
29
- merrionSansParams,
30
- montserratParams,
31
- };
@@ -1,5 +0,0 @@
1
- export const STATIC_BASE_URL = 'https://static.wayflyer.com/flyui-assets';
2
- export const DM_SANS_URL = '/fonts/dm-sans/DMSans-VariableFont_opsz,wght.ttf';
3
- export const MERRION_SANS_URL = '/fonts/merrion-sans/Merrion_Sans-Regular.woff2';
4
- export const MONTSERRAT_URL = '/fonts/montserrat/Montserrat-VariableFont_wght.ttf';
5
- export const MODAL_LOGO_IMAGE_URL = '/logos/wayflyer-ef.png';
@@ -1,22 +0,0 @@
1
- import { FONT_PARAMS, PartnerTheme } from '../config';
2
- import { loadFont } from './loadFont';
3
-
4
- type ApplyFontsType = (shadow: ShadowRoot, partnerTheme: PartnerTheme) => Promise<void>;
5
-
6
- export const applyFont: ApplyFontsType = async (shadow, partnerTheme) => {
7
- const { dmSansParams, merrionSansParams, montserratParams } = FONT_PARAMS;
8
-
9
- switch (partnerTheme) {
10
- case 'whiteLabel':
11
- await loadFont(shadow, dmSansParams);
12
- break;
13
- case 'athena':
14
- await loadFont(shadow, montserratParams);
15
- break;
16
- case 'wayflyer':
17
- await loadFont(shadow, merrionSansParams);
18
- break;
19
- default:
20
- await loadFont(shadow, merrionSansParams);
21
- }
22
- };
@@ -1,33 +0,0 @@
1
- import { FontParamsType } from 'src/config';
2
-
3
- type LoadFontType = (shadow: ShadowRoot, fontParams: FontParamsType) => Promise<void>;
4
-
5
- export const loadFont: LoadFontType = async (shadow, fontParams) => {
6
- const { fontFamily, fontUrl, fallbackFontUrl } = fontParams;
7
- const fontStylesId = 'font-styles';
8
-
9
- let font: FontFace;
10
-
11
- try {
12
- font = new FontFace(fontFamily, `url(${fontUrl})`);
13
- await font.load();
14
- } catch {
15
- font = new FontFace(fontFamily, `url(${fallbackFontUrl})`);
16
- await font.load();
17
- } finally {
18
- document.fonts.add(font!);
19
- }
20
-
21
- let fontStyles = shadow.getElementById(fontStylesId);
22
-
23
- if (!fontStyles) {
24
- fontStyles = document.createElement('style');
25
- fontStyles.id = fontStylesId;
26
- fontStyles.textContent = `
27
- :host { font-family: "${fontFamily}", sans-serif; background-color: transparent !important; overflow: visible !important; }
28
- ::slotted(*) { font-family: inherit; }
29
- `;
30
-
31
- shadow.appendChild(fontStyles);
32
- }
33
- };