Skip to content

Commit

Permalink
feat: add sticky header
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed Apr 19, 2022
1 parent 304eca1 commit ffade59
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 44 deletions.
23 changes: 23 additions & 0 deletions packages/widget/src/components/Header/Header.style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { AppBar, Box } from '@mui/material';
import { styled } from '@mui/material/styles';

export const HeaderAppBar = styled(AppBar, {
shouldForwardProp: (prop) => prop !== 'pt',
})<{ pt?: number }>(({ theme, pt }) => ({
backgroundColor: 'transparent',
color: theme.palette.common.black,
flexDirection: 'row',
alignItems: 'center',
position: 'relative',
minHeight: 48,
padding: theme.spacing(pt ?? 0, 3, 0, 3),
}));

export const Container = styled(Box, {
shouldForwardProp: (prop) => prop !== 'sticky',
})<{ sticky?: boolean }>(({ theme, sticky }) => ({
backgroundColor: sticky ? theme.palette.common.white : 'transparent',
position: sticky ? 'sticky' : 'relative',
top: 0,
zIndex: 1200,
}));
28 changes: 24 additions & 4 deletions packages/widget/src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
import { Box } from '@mui/material';
import { FC } from 'react';
import { FC, PropsWithChildren } from 'react';
import { useLocation } from 'react-router-dom';
import { ElementId } from '../../utils/elements';
import { routes } from '../../utils/routes';
import { Container } from './Header.style';
import { NavigationHeader } from './NavigationHeader';
import { WalletHeader } from './WalletHeader';

const stickyHeaderRoutes = [
routes.selectWallet,
routes.settings,
routes.swapRoutes,
];

const HeaderContainer: FC<PropsWithChildren<{}>> = ({ children }) => {
const { pathname } = useLocation();
return (
<Container
id={ElementId.Header}
sticky={stickyHeaderRoutes.includes(pathname)}
>
{children}
</Container>
);
};

export const Header: FC = () => (
<Box id={ElementId.Header}>
<HeaderContainer>
<WalletHeader />
<NavigationHeader />
</Box>
</HeaderContainer>
);
17 changes: 0 additions & 17 deletions packages/widget/src/components/Header/HeaderContainer.style.ts

This file was deleted.

11 changes: 0 additions & 11 deletions packages/widget/src/components/Header/HeaderContainer.tsx

This file was deleted.

19 changes: 11 additions & 8 deletions packages/widget/src/components/Header/NavigationHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import { Box, IconButton, Typography } from '@mui/material';
import { useTranslation } from 'react-i18next';
import { useLocation, useNavigate } from 'react-router-dom';
import { routes } from '../../utils/routes';
import { HeaderContainer } from './HeaderContainer';
import { HeaderAppBar } from './Header.style';

const routesWithBack = [
const backButtonRoutes = [
routes.selectWallet,
routes.settings,
routes.fromToken,
routes.toToken,
routes.selectWallet,
routes.swapRoutes,
routes.transaction,
];

Expand All @@ -31,14 +32,16 @@ export const NavigationHeader: React.FC = () => {

const handleHeaderTitle = () => {
switch (pathname) {
case routes.selectWallet:
return t(`header.selectWallet`);
case routes.settings:
return t(`header.settings`);
case routes.fromToken:
return t(`header.from`);
case routes.toToken:
return t(`header.to`);
case routes.selectWallet:
return t(`header.selectWallet`);
case routes.swapRoutes:
return t(`swap.routes`);
case routes.transaction:
return t(`header.processIsOn`);
default:
Expand All @@ -47,13 +50,13 @@ export const NavigationHeader: React.FC = () => {
};

return (
<HeaderContainer>
<HeaderAppBar elevation={0}>
{/* <Collapse
collapsedSize={0}
orientation="horizontal"
in={routesWithBack.includes(pathname)}
> */}
{routesWithBack.includes(pathname) ? (
{backButtonRoutes.includes(pathname) ? (
<IconButton
size="large"
aria-label="settings"
Expand Down Expand Up @@ -88,6 +91,6 @@ export const NavigationHeader: React.FC = () => {
) : (
<Box width={36} height={48} />
)}
</HeaderContainer>
</HeaderAppBar>
);
};
6 changes: 3 additions & 3 deletions packages/widget/src/components/Header/WalletHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useTranslation } from 'react-i18next';
import { useLocation, useNavigate } from 'react-router-dom';
import { useWallet } from '../../providers/WalletProvider';
import { routes } from '../../utils/routes';
import { HeaderContainer } from './HeaderContainer';
import { HeaderAppBar } from './Header.style';

export const WalletHeader: React.FC = () => {
const { t } = useTranslation();
Expand All @@ -19,7 +19,7 @@ export const WalletHeader: React.FC = () => {
: null;

return (
<HeaderContainer pt={1.5}>
<HeaderAppBar elevation={0} pt={1.5}>
{walletAddress ? (
<>
<Box
Expand Down Expand Up @@ -67,7 +67,7 @@ export const WalletHeader: React.FC = () => {
<ConnectButton />
</>
)}
</HeaderContainer>
</HeaderAppBar>
);
};

Expand Down
2 changes: 1 addition & 1 deletion packages/widget/src/components/MainContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useLocation } from 'react-router-dom';
import { ElementId } from '../utils/elements';

const Container = styled(MuiContainer)(({ theme }) => ({
height: '100%',
// height: '100%',
display: 'flex',
flexDirection: 'column',
overflowX: 'clip',
Expand Down

0 comments on commit ffade59

Please sign in to comment.