Skip to content

Commit

Permalink
fix: widget header with subvariant split (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
DNR500 authored Sep 11, 2024
1 parent 87e3ba4 commit c33d42a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
15 changes: 4 additions & 11 deletions packages/widget/src/components/AppContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { Box, Container, ScopedCssBaseline, styled } from '@mui/material';
import type { PropsWithChildren } from 'react';
import {
maxHeaderHeight,
minHeaderHeight,
} from '../components/Header/Header.js';
import { defaultMaxHeight } from '../config/constants.js';
import { useHeaderHeight } from '../hooks/useHeaderHeight.js';
import { useWidgetConfig } from '../providers/WidgetProvider/WidgetProvider.js';
import type { WidgetVariant } from '../types/widget.js';
import { ElementId, createElementId } from '../utils/elements.js';
Expand Down Expand Up @@ -103,14 +100,10 @@ export const FlexContainer = styled(Container)(({ theme }) => ({

export const AppContainer: React.FC<PropsWithChildren<{}>> = ({ children }) => {
// const ref = useRef<HTMLDivElement>(null);
const { variant, elementId, hiddenUI, theme } = useWidgetConfig();

const { variant, elementId, theme } = useWidgetConfig();
const { headerHeight } = useHeaderHeight();
const positionFixedAdjustment =
theme?.header?.position === 'fixed'
? hiddenUI?.includes('walletMenu')
? minHeaderHeight
: maxHeaderHeight
: 0;
theme?.header?.position === 'fixed' ? headerHeight : 0;

return (
<RelativeContainer
Expand Down
11 changes: 2 additions & 9 deletions packages/widget/src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
import type { FC, PropsWithChildren } from 'react';
import { useLocation } from 'react-router-dom';
import { useDefaultElementId } from '../../hooks/useDefaultElementId.js';
import { useWidgetConfig } from '../../providers/WidgetProvider/WidgetProvider.js';
import { useHeaderHeight } from '../../hooks/useHeaderHeight.js';
import { ElementId, createElementId } from '../../utils/elements.js';
import { stickyHeaderRoutes } from '../../utils/navigationRoutes.js';
import { Container } from './Header.style.js';
import { NavigationHeader } from './NavigationHeader.js';
import { WalletHeader } from './WalletHeader.js';

export const minHeaderHeight = 64;
export const maxHeaderHeight = 108;

export const HeaderContainer: FC<PropsWithChildren<{}>> = ({ children }) => {
const { pathname } = useLocation();
const elementId = useDefaultElementId();
const { hiddenUI } = useWidgetConfig();

const headerHeight = hiddenUI?.includes('walletMenu')
? minHeaderHeight
: maxHeaderHeight;
const { headerHeight } = useHeaderHeight();

return (
<Container
Expand Down
20 changes: 20 additions & 0 deletions packages/widget/src/hooks/useHeaderHeight.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useWidgetConfig } from '../providers/WidgetProvider/WidgetProvider.js';

export const minHeaderHeight = 64;
export const maxHeaderHeight = 108;
export const maxHeaderHeightSubvariantSplit = 136;

export const useHeaderHeight = () => {
const { hiddenUI, subvariant } = useWidgetConfig();

const headerHeight =
subvariant === 'split'
? maxHeaderHeightSubvariantSplit
: hiddenUI?.includes('walletMenu')
? minHeaderHeight
: maxHeaderHeight;

return {
headerHeight,
};
};

0 comments on commit c33d42a

Please sign in to comment.