From 7b983de3ed0fe30c77f8b00f9be36d9c9d87c307 Mon Sep 17 00:00:00 2001 From: Eugene Chybisov Date: Thu, 13 Apr 2023 11:57:53 +0800 Subject: [PATCH] fix: make config integrator optional --- packages/widget/src/App.tsx | 6 +++--- packages/widget/src/AppDrawer.tsx | 4 ++-- packages/widget/src/AppProvider.tsx | 4 ++-- packages/widget/src/types/widget.ts | 13 ++++++++++--- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/packages/widget/src/App.tsx b/packages/widget/src/App.tsx index 5fee9b0d8..7218a2dd1 100644 --- a/packages/widget/src/App.tsx +++ b/packages/widget/src/App.tsx @@ -13,16 +13,16 @@ import { Initializer } from './components/Initializer'; import { PoweredBy } from './components/PoweredBy'; import { SwapRoutesExpanded } from './components/SwapRoutes'; import { useExpandableVariant } from './hooks'; -import type { WidgetProps } from './types'; +import type { WidgetConfig, WidgetProps } from './types'; export const App: React.FC = forwardRef( ({ elementRef, open, integrator, ...other }, ref) => { - const config = useMemo( + const config: WidgetConfig = useMemo( () => ({ integrator, ...other, ...other.config }), [integrator, other], ); return config?.variant !== 'drawer' ? ( - + ) : ( diff --git a/packages/widget/src/AppDrawer.tsx b/packages/widget/src/AppDrawer.tsx index f3e202c37..bafbea49d 100644 --- a/packages/widget/src/AppDrawer.tsx +++ b/packages/widget/src/AppDrawer.tsx @@ -50,7 +50,7 @@ export const AppDrawer = forwardRef( [closeDrawer, openDrawer, toggleDrawer], ); - const drawerConfig: WidgetConfig = useMemo( + const widgetConfig: WidgetConfig = useMemo( () => ({ ...config, integrator, @@ -63,7 +63,7 @@ export const AppDrawer = forwardRef( ); return ( - + > = ({ +export const AppProvider: React.FC> = ({ children, config, }) => { diff --git a/packages/widget/src/types/widget.ts b/packages/widget/src/types/widget.ts index 22513975e..48189c9fa 100644 --- a/packages/widget/src/types/widget.ts +++ b/packages/widget/src/types/widget.ts @@ -166,7 +166,14 @@ export type WidgetDrawerProps = { open?: boolean; }; +export interface WidgetConfigProps { + config: WidgetConfig; +} + +export interface WidgetConfigPartialProps { + config?: Partial; +} + export type WidgetProps = WidgetDrawerProps & - WidgetConfig & { - config?: WidgetConfig; - }; + WidgetConfig & + WidgetConfigPartialProps;