Skip to content

Commit

Permalink
fix: make config integrator optional
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed Apr 13, 2023
1 parent 10b7e31 commit 7b983de
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
6 changes: 3 additions & 3 deletions packages/widget/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<WidgetProps> = forwardRef<WidgetDrawer, WidgetProps>(
({ elementRef, open, integrator, ...other }, ref) => {
const config = useMemo(
const config: WidgetConfig = useMemo(
() => ({ integrator, ...other, ...other.config }),
[integrator, other],
);
return config?.variant !== 'drawer' ? (
<AppProvider integrator={integrator} config={config}>
<AppProvider config={config}>
<AppDefault />
</AppProvider>
) : (
Expand Down
4 changes: 2 additions & 2 deletions packages/widget/src/AppDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const AppDrawer = forwardRef<WidgetDrawer, WidgetProps>(
[closeDrawer, openDrawer, toggleDrawer],
);

const drawerConfig: WidgetConfig = useMemo(
const widgetConfig: WidgetConfig = useMemo(
() => ({
...config,
integrator,
Expand All @@ -63,7 +63,7 @@ export const AppDrawer = forwardRef<WidgetDrawer, WidgetProps>(
);

return (
<AppProvider integrator={integrator} config={drawerConfig}>
<AppProvider config={widgetConfig}>
<DrawerButton
variant="contained"
onClick={toggleDrawer}
Expand Down
4 changes: 2 additions & 2 deletions packages/widget/src/AppProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import {
useWidgetConfig,
} from './providers';
import { StoreProvider } from './stores';
import type { WidgetProps } from './types';
import type { WidgetConfigProps } from './types';

export const AppProvider: React.FC<PropsWithChildren<WidgetProps>> = ({
export const AppProvider: React.FC<PropsWithChildren<WidgetConfigProps>> = ({
children,
config,
}) => {
Expand Down
13 changes: 10 additions & 3 deletions packages/widget/src/types/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,14 @@ export type WidgetDrawerProps = {
open?: boolean;
};

export interface WidgetConfigProps {
config: WidgetConfig;
}

export interface WidgetConfigPartialProps {
config?: Partial<WidgetConfig>;
}

export type WidgetProps = WidgetDrawerProps &
WidgetConfig & {
config?: WidgetConfig;
};
WidgetConfig &
WidgetConfigPartialProps;

0 comments on commit 7b983de

Please sign in to comment.