@wf-financing/ui 3.7.1 → 3.8.1

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.8.1",
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
2
 
3
+ import { useState } from 'react';
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, isSuccess } = useCtaBanner();
10
+ const [skipAnimation] = useState(() => isSuccess);
11
+ const { onWidgetClose, isWidgetDismissed } = usePartnerContext();
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
  );
@@ -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
 
package/src/main.tsx CHANGED
@@ -2,6 +2,7 @@ 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';
@@ -32,6 +33,8 @@ export const mountToTarget = async (
32
33
  root.unmount();
33
34
  };
34
35
 
36
+ MotionGlobalConfig.skipAnimations = options?.skipAnimations;
37
+
35
38
  root.render(
36
39
  <StyleSheetManager target={styledComponentsStyleRoot}>
37
40
  <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