@wf-financing/ui 3.7.1 → 3.9.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": "@wf-financing/ui",
3
- "version": "3.7.1",
3
+ "version": "3.9.0",
4
4
  "exports": {
5
5
  ".": {
6
6
  "import": "./dist/index.es.js",
@@ -36,7 +36,7 @@
36
36
  "react-aria": "^3.41.1",
37
37
  "react-intl": "^6.2.5",
38
38
  "styled-components": "^6.1.19",
39
- "@wf-financing/embedded-types": "0.4.2"
39
+ "@wf-financing/embedded-types": "0.5.0"
40
40
  },
41
41
  "publishConfig": {
42
42
  "access": "public"
package/src/App.tsx CHANGED
@@ -1,7 +1,7 @@
1
- import { useState } from 'react';
2
1
  import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
3
2
  import { FlyUIProvider } from '@wayflyer/flyui';
4
3
  import { PartnerCallbackType, SdkOptionsType } from '@wf-financing/embedded-types';
4
+ import { useState } from 'react';
5
5
  import { createIntl, createIntlCache, IntlShape } from 'react-intl';
6
6
 
7
7
  import { PartnerTheme } from './config';
@@ -32,6 +32,7 @@ export const App = ({
32
32
  portalContainer,
33
33
  }: AppPropsType) => {
34
34
  const [isThemeLoaded, setIsThemeLoaded] = useState(false);
35
+ const [isWidgetDismissed, setIsWidgetDismissed] = useState(false);
35
36
 
36
37
  const locale = 'en';
37
38
 
@@ -43,9 +44,23 @@ export const App = ({
43
44
  createIntlCache(),
44
45
  );
45
46
 
47
+ const onWidgetDismiss = () => {
48
+ setIsWidgetDismissed(true);
49
+ };
50
+
46
51
  return (
47
52
  <QueryClientProvider client={queryClient}>
48
- <PartnerContext.Provider value={{ companyToken, options, partnerCallback, onWidgetClose, portalContainer }}>
53
+ <PartnerContext.Provider
54
+ value={{
55
+ companyToken,
56
+ options,
57
+ partnerCallback,
58
+ onWidgetClose,
59
+ portalContainer,
60
+ isWidgetDismissed,
61
+ onWidgetDismiss,
62
+ }}
63
+ >
49
64
  <FlyUIProvider
50
65
  theme={theme}
51
66
  intl={intl}
package/src/CtaWidget.tsx CHANGED
@@ -1,19 +1,30 @@
1
- import { useEffect } from 'react';
1
+ import { AnimatePresence } from 'framer-motion';
2
+ import { useState } from 'react';
2
3
 
4
+ import { AnimationWrapper } from './components/banner/AnimationWrapper';
3
5
  import { CtaBanner } from './components/banner/CtaBanner';
4
6
  import { useCtaBanner, usePartnerContext } from './hooks';
5
7
 
6
8
  export const CtaWidget = () => {
7
- const banner = useCtaBanner();
8
- const partnerContext = usePartnerContext();
9
+ const { isLoading, data } = useCtaBanner();
10
+ const { onWidgetClose, isWidgetDismissed, options } = usePartnerContext();
11
+ const [skipAnimation] = useState(() => !!options?.skipAnimations);
9
12
 
10
- useEffect(() => {
11
- if (!banner.isLoading && !banner.data) {
12
- requestAnimationFrame(() => {
13
- partnerContext.onWidgetClose();
14
- });
13
+ const showBanner = !isLoading && data && !isWidgetDismissed;
14
+
15
+ const handleExitComplete = () => {
16
+ if ((!isLoading && !data) || isWidgetDismissed) {
17
+ onWidgetClose();
15
18
  }
16
- }, [banner.data]);
19
+ };
17
20
 
18
- return <>{!banner.isLoading && banner.data && <CtaBanner />}</>;
21
+ return (
22
+ <AnimatePresence mode="wait" onExitComplete={handleExitComplete}>
23
+ {showBanner && (
24
+ <AnimationWrapper skipAnimation={skipAnimation}>
25
+ <CtaBanner skipAnimation={skipAnimation} />
26
+ </AnimationWrapper>
27
+ )}
28
+ </AnimatePresence>
29
+ );
19
30
  };
@@ -0,0 +1,37 @@
1
+ import { motion, MotionProps } from 'framer-motion';
2
+ import { PropsWithChildren } from 'react';
3
+
4
+ type Props = {
5
+ skipAnimation: boolean;
6
+ };
7
+
8
+ const animationProps: MotionProps = {
9
+ initial: { height: 0, overflow: 'hidden' },
10
+ animate: {
11
+ height: 'auto',
12
+ overflow: 'visible',
13
+ transition: {
14
+ duration: 0.4,
15
+ ease: [0.33, 1, 0.68, 1],
16
+ },
17
+ },
18
+ exit: {
19
+ height: 0,
20
+ overflow: 'hidden',
21
+ transition: {
22
+ duration: 0.4,
23
+ ease: [0.33, 1, 0.68, 1],
24
+ delay: 0.1,
25
+ },
26
+ },
27
+ };
28
+
29
+ export const AnimationWrapper = ({ children, skipAnimation }: PropsWithChildren<Props>) => {
30
+ const initial = skipAnimation ? animationProps.animate : animationProps.initial;
31
+
32
+ return (
33
+ <motion.div key="cta-banner-wrapper" {...animationProps} initial={initial}>
34
+ {children}
35
+ </motion.div>
36
+ );
37
+ };
@@ -1,14 +1,15 @@
1
1
  import { Button, Flex } from '@wayflyer/flyui';
2
2
  import { IconX16Line } from '@wayflyer/flyui-icons/16/line';
3
3
 
4
- import { usePartnerContext, useDismissCta } from '../../hooks';
4
+ import { useDismissCta, usePartnerContext } from '../../hooks';
5
5
 
6
6
  export const CloseButton = ({ isOnDarkTheme }: { isOnDarkTheme: boolean }) => {
7
- const { onWidgetClose: closeWidget } = usePartnerContext();
7
+ const { onWidgetDismiss } = usePartnerContext();
8
8
  const dismissCta = useDismissCta();
9
9
 
10
10
  const handleCloseWidget = () => {
11
- closeWidget();
11
+ onWidgetDismiss();
12
+
12
13
  dismissCta.mutate(undefined, {
13
14
  onError: (error) => {
14
15
  console.error('Failed to dismiss CTA', error);
@@ -9,6 +9,9 @@ const defaultArgs = {
9
9
  companyToken: 'demo-token',
10
10
  partnerCallback: () => {},
11
11
  onWidgetClose: () => {},
12
+ onWidgetDismiss: () => {},
13
+ isWidgetDismissed: false,
14
+ skipAnimation: false,
12
15
  portalContainer,
13
16
  };
14
17
 
@@ -16,7 +19,7 @@ type CtaBannerStoryArgs = typeof defaultArgs;
16
19
 
17
20
  const Template = (args: CtaBannerStoryArgs) => (
18
21
  <PartnerContext.Provider value={{ ...args }}>
19
- <CtaBanner />
22
+ <CtaBanner skipAnimation={false} />
20
23
  </PartnerContext.Provider>
21
24
  );
22
25
 
@@ -1,17 +1,18 @@
1
1
  import { Flex, useDetectDeviceSize, useTheme } from '@wayflyer/flyui';
2
- import { styled, css } from 'styled-components';
2
+ import { motion, MotionProps } from 'framer-motion';
3
+ import { css, styled } from 'styled-components';
3
4
 
5
+ import { MODAL_LOGO_IMAGE_URL, STATIC_BASE_URL } from '../../config';
6
+ import { usePreloadImage } from '../../hooks';
4
7
  import { CtaBannerContent } from './CtaBannerContent';
5
8
  import { FooterActions } from './FooterActions';
6
9
  import { HeaderActions } from './HeaderActions';
7
- import { usePreloadImage } from '../../hooks';
8
- import { MODAL_LOGO_IMAGE_URL, STATIC_BASE_URL } from '../../config';
9
10
 
10
11
  const ON_DARK_THEMES = ['athena'];
11
12
  const LIGHT_BG_THEMES = ['conjura', 'rocketFuel'];
12
13
  const TERTIARY_THEMES = ['reveni'];
13
14
 
14
- const BannerContainer = styled.aside<{ $isLightBgTheme: boolean; $isTertiaryTheme: boolean }>`
15
+ const BannerContainer = styled(motion.aside)<{ $isLightBgTheme: boolean; $isTertiaryTheme: boolean }>`
15
16
  padding: var(--sizes-spacing-4) var(--sizes-spacing-4) var(--sizes-spacing-4) var(--sizes-spacing-6);
16
17
  box-shadow: var(--effects-shadow);
17
18
  border-radius: var(--sizes-radius-md);
@@ -27,6 +28,8 @@ const BannerContainer = styled.aside<{ $isLightBgTheme: boolean; $isTertiaryThem
27
28
  return $isLightBgTheme ? css`var(--palette-layout-containerSurface)` : css`var(--palette-utility-primaryBrand)`;
28
29
  }};
29
30
 
31
+ transform-origin: top center;
32
+
30
33
  @media (max-width: 640px) {
31
34
  padding: var(--sizes-spacing-3) var(--sizes-spacing-3) var(--sizes-spacing-3) var(--sizes-spacing-4);
32
35
  flex-direction: column;
@@ -34,7 +37,32 @@ const BannerContainer = styled.aside<{ $isLightBgTheme: boolean; $isTertiaryThem
34
37
  }
35
38
  `;
36
39
 
37
- export const CtaBanner = () => {
40
+ const bannerAnimationProps: MotionProps = {
41
+ initial: { opacity: 0, scale: 0.8 },
42
+ animate: {
43
+ opacity: 1,
44
+ scale: 1,
45
+ transition: {
46
+ delay: 0.1,
47
+ duration: 0.4,
48
+ ease: [0.33, 1, 0.68, 1],
49
+ },
50
+ },
51
+ exit: {
52
+ opacity: 0,
53
+ scaleY: 0.8,
54
+ transition: {
55
+ duration: 0.2,
56
+ ease: [0.12, 0, 0.39, 0],
57
+ },
58
+ },
59
+ };
60
+
61
+ type Props = {
62
+ skipAnimation: boolean;
63
+ };
64
+
65
+ export const CtaBanner = ({ skipAnimation }: Props) => {
38
66
  const { isMobile, isTablet } = useDetectDeviceSize();
39
67
  const logoImageUrl = `${STATIC_BASE_URL}${MODAL_LOGO_IMAGE_URL}`;
40
68
  const { themeName } = useTheme();
@@ -44,8 +72,13 @@ export const CtaBanner = () => {
44
72
  usePreloadImage(logoImageUrl);
45
73
 
46
74
  return (
47
- <BannerContainer $isLightBgTheme={isLightBgTheme} $isTertiaryTheme={isTertiaryTheme}>
48
- <Flex gap="4" align="center" justify="space-between" width="100%">
75
+ <BannerContainer
76
+ $isLightBgTheme={isLightBgTheme}
77
+ $isTertiaryTheme={isTertiaryTheme}
78
+ {...bannerAnimationProps}
79
+ initial={skipAnimation ? bannerAnimationProps.animate : bannerAnimationProps.initial}
80
+ >
81
+ <Flex gap="4" align={isMobile ? 'flex-start' : 'center'} justify="space-between" width="100%">
49
82
  <CtaBannerContent isMobile={isMobile} isTablet={isTablet} isOnDarkTheme={isOnDarkTheme} />
50
83
  <HeaderActions isOnDarkTheme={isOnDarkTheme} />
51
84
  </Flex>
@@ -1,12 +1,20 @@
1
1
  import { useDetectDeviceSize } from '@wayflyer/flyui';
2
+ import styled from 'styled-components';
2
3
  import { BannerActionsDesktop } from './BannerActionsDesktop';
3
4
  import { CloseButton } from './CloseButton';
4
5
 
6
+ const MobileButtonContainer = styled.div`
7
+ margin-top: calc(0px - var(--sizes-spacing-3));
8
+ margin-right: calc(0px - var(--sizes-spacing-2));
9
+ `;
10
+
5
11
  export const HeaderActions = ({ isOnDarkTheme }: { isOnDarkTheme: boolean }) => {
6
12
  const { isMobile } = useDetectDeviceSize();
7
13
 
8
14
  return isMobile ? (
9
- <CloseButton isOnDarkTheme={isOnDarkTheme} />
15
+ <MobileButtonContainer>
16
+ <CloseButton isOnDarkTheme={isOnDarkTheme} />
17
+ </MobileButtonContainer>
10
18
  ) : (
11
19
  <BannerActionsDesktop isOnDarkTheme={isOnDarkTheme} />
12
20
  );
@@ -8,7 +8,7 @@ import {
8
8
  } from '@wf-financing/embedded-types';
9
9
  import { useState } from 'react';
10
10
 
11
- import { useCtaBanner, useContinueHostedApplication, useInvalidateCta } from '../../hooks';
11
+ import { useCtaBanner, useContinueHostedApplication } from '../../hooks';
12
12
  import { ConsentModal } from '../modal/ConsentModal';
13
13
 
14
14
  type CtaResponseType = CtaGenericOfferType | CtaIndicativeOfferType | CtaContinueFundingType;
@@ -18,7 +18,6 @@ export const ProceedFundingButton = ({ isOnDarkTheme }: { isOnDarkTheme: boolean
18
18
  const sdkResponse = useCtaBanner();
19
19
  const sdk = sdkResponse.data as CtaResponseType;
20
20
  const { mutate, isPending: isLoading } = useContinueHostedApplication();
21
- const invalidateCta = useInvalidateCta();
22
21
 
23
22
  if (!sdk) return null;
24
23
 
@@ -34,7 +33,6 @@ export const ProceedFundingButton = ({ isOnDarkTheme }: { isOnDarkTheme: boolean
34
33
  onSuccess: (nextUrl: ContinueHostedApplicationResponseType) => {
35
34
  const { next } = nextUrl;
36
35
  window.open(next);
37
- invalidateCta();
38
36
  },
39
37
  onError: (error) => {
40
38
  console.error('Failed to continue application', error);
@@ -10,6 +10,8 @@ const appArgs = {
10
10
  companyToken: 'demo-token',
11
11
  partnerCallback: () => {},
12
12
  onWidgetClose: () => {},
13
+ onWidgetDismiss: () => {},
14
+ isWidgetDismissed: false,
13
15
  portalContainer,
14
16
  };
15
17
 
@@ -3,7 +3,7 @@ import { IconArrowOnSquareUpRight16Line } from '@wayflyer/flyui-icons/16/line';
3
3
  import { StartHostedApplicationResponseType } from '@wf-financing/embedded-types';
4
4
  import { FormattedMessage } from 'react-intl';
5
5
 
6
- import { useDetectSmallScreen, useStartHostedApplication, useInvalidateCta } from '../../hooks';
6
+ import { useDetectSmallScreen, useStartHostedApplication } from '../../hooks';
7
7
 
8
8
  type ModalFooterType = {
9
9
  setOpen: (isOpen: boolean) => void;
@@ -13,7 +13,6 @@ export const ModalFooter = ({ setOpen }: ModalFooterType) => {
13
13
  const { isMobile } = useDetectDeviceSize();
14
14
  const { mutate, isPending: isLoading } = useStartHostedApplication();
15
15
  const isSmallScreen = useDetectSmallScreen();
16
- const invalidateCta = useInvalidateCta();
17
16
 
18
17
  const handleStartApplication = () => {
19
18
  mutate(undefined, {
@@ -21,7 +20,6 @@ export const ModalFooter = ({ setOpen }: ModalFooterType) => {
21
20
  const { next } = nextUrl;
22
21
  setOpen(false);
23
22
  window.open(next);
24
- invalidateCta();
25
23
  },
26
24
  onError: (error) => {
27
25
  console.error('Failed to start application', error);
@@ -6,4 +6,3 @@ export { useContinueHostedApplication } from './useContinueHostedApplication';
6
6
  export { useDismissCta } from './useDismissCta';
7
7
  export { useRemoveInerted } from './useRemoveInerted';
8
8
  export { usePreloadImage } from './usePreloadImage';
9
- export { useInvalidateCta } from './useInvalidateCta';
@@ -9,9 +9,9 @@ export const useCtaBanner = () => {
9
9
  return useQuery({
10
10
  queryKey: ['cta', companyToken],
11
11
  queryFn: () => fetchCtaBanner(companyToken, options),
12
- staleTime: Infinity,
13
- refetchOnWindowFocus: false,
14
- placeholderData: keepPreviousData,
15
12
  enabled: !!companyToken,
13
+ placeholderData: keepPreviousData,
14
+ refetchOnMount: false,
15
+ refetchOnWindowFocus: false,
16
16
  });
17
17
  };
@@ -2,16 +2,13 @@ import { useMutation } from '@tanstack/react-query';
2
2
 
3
3
  import { dismissCta } from '../api';
4
4
  import { usePartnerContext } from './usePartnerContext';
5
- import { useInvalidateCta } from './useInvalidateCta';
6
5
 
7
6
  export const useDismissCta = () => {
8
7
  const { companyToken, options } = usePartnerContext();
9
- const invalidateCta = useInvalidateCta();
10
8
 
11
9
  return useMutation({
12
10
  mutationFn: async () => {
13
11
  await dismissCta(companyToken, options);
14
- await invalidateCta();
15
12
  },
16
13
  });
17
14
  };
package/src/main.tsx CHANGED
@@ -2,10 +2,14 @@ import { PartnerCallbackType, SdkOptionsType } from '@wf-financing/embedded-type
2
2
  import ReactDOM from 'react-dom/client';
3
3
  import { StyleSheetManager } from 'styled-components';
4
4
 
5
+ import { MotionGlobalConfig } from 'framer-motion';
5
6
  import { App } from './App';
6
7
  import { PartnerTheme } from './config';
7
8
  import { applyFont, createRoots } from './utils';
8
9
 
10
+ let root: ReactDOM.Root | undefined;
11
+ let savedTargetId: string | undefined;
12
+
9
13
  export const mountToTarget = async (
10
14
  targetId: string,
11
15
  partnerTheme: PartnerTheme,
@@ -13,8 +17,14 @@ export const mountToTarget = async (
13
17
  companyToken: string,
14
18
  options?: SdkOptionsType,
15
19
  ): Promise<void> => {
16
- const hostEl = document.getElementById(targetId);
17
- if (!hostEl) throw new Error(`Target element with id "${targetId}" not found.`);
20
+ const isNewTargetId = targetId !== savedTargetId;
21
+
22
+ if (isNewTargetId) {
23
+ savedTargetId = targetId;
24
+ }
25
+
26
+ const hostEl = document.getElementById(savedTargetId as string);
27
+ if (!hostEl) throw new Error(`Target element with id "${savedTargetId}" not found.`);
18
28
 
19
29
  const shadow = hostEl.shadowRoot ?? hostEl.attachShadow({ mode: 'open' });
20
30
 
@@ -25,13 +35,19 @@ export const mountToTarget = async (
25
35
  }
26
36
 
27
37
  const { styledComponentsStyleRoot, portalRoot, bannerRoot } = createRoots(shadow);
28
- const root = ReactDOM.createRoot(bannerRoot);
38
+
39
+ if (isNewTargetId || !root) {
40
+ root = ReactDOM.createRoot(bannerRoot);
41
+ }
29
42
 
30
43
  const handleCloseWidget = () => {
31
44
  if (!root) throw new Error('Root is not found');
32
45
  root.unmount();
46
+ root = undefined;
33
47
  };
34
48
 
49
+ MotionGlobalConfig.skipAnimations = options?.skipAnimations;
50
+
35
51
  root.render(
36
52
  <StyleSheetManager target={styledComponentsStyleRoot}>
37
53
  <App
@@ -24,7 +24,7 @@ export const loadFont: LoadFontType = async (shadow, fontParams) => {
24
24
  fontStyles = document.createElement('style');
25
25
  fontStyles.id = fontStylesId;
26
26
  fontStyles.textContent = `
27
- :host { font-family: "${fontFamily}", sans-serif; }
27
+ :host { font-family: "${fontFamily}", sans-serif; background-color: transparent !important; overflow: visible !important; }
28
28
  ::slotted(*) { font-family: inherit; }
29
29
  `;
30
30
 
@@ -6,6 +6,8 @@ export type PartnerContextType = {
6
6
  partnerCallback: PartnerCallbackType;
7
7
  options?: SdkOptionsType;
8
8
  onWidgetClose: () => void;
9
+ onWidgetDismiss: () => void;
10
+ isWidgetDismissed: boolean;
9
11
  portalContainer: HTMLElement;
10
12
  };
11
13
 
@@ -1,13 +0,0 @@
1
- import { useQueryClient } from '@tanstack/react-query';
2
-
3
- import { usePartnerContext } from './usePartnerContext';
4
-
5
- export const useInvalidateCta = () => {
6
- const queryClient = useQueryClient();
7
- const { companyToken } = usePartnerContext();
8
-
9
- return () =>
10
- queryClient.invalidateQueries({
11
- queryKey: ['cta', companyToken],
12
- });
13
- };