Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add close button on mobile #119

Merged
merged 9 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/widget/src/AppDrawer.style.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button, Typography } from '@mui/material';
import { Button, IconButton, Typography } from '@mui/material';
import { styled } from '@mui/material/styles';

const getButtonTransformWidth = (
Expand Down Expand Up @@ -96,3 +96,14 @@ export const DrawerButtonTypography = styled(Typography)(({ theme }) => ({
transform: 'rotateZ(180deg)',
writingMode: 'vertical-rl',
}));

export const CloseButtonLayout = styled(IconButton)(() => ({
position: 'absolute',
top: '12px',
right: '16px',
zIndex: 1,
height: '40px',
width: '40px',
alignItems: 'center',
justifyContent: 'center',
}));
10 changes: 9 additions & 1 deletion packages/widget/src/AppDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ import {
} from 'react';
import { useTranslation } from 'react-i18next';
import { AppDefault } from './App';
import { DrawerButton, DrawerButtonTypography } from './AppDrawer.style';
import {
CloseButtonLayout,
DrawerButton,
DrawerButtonTypography,
} from './AppDrawer.style';
import { AppProvider } from './AppProvider';
import type { WidgetConfig, WidgetProps, WidgetSubvariant } from './types';
import { HiddenUI } from './types';
import CloseIcon from '@mui/icons-material/CloseRounded';

export interface WidgetDrawer {
isOpen(): void;
Expand Down Expand Up @@ -103,6 +108,9 @@ export const AppDrawer = forwardRef<WidgetDrawer, WidgetProps>(
}}
keepMounted
>
<CloseButtonLayout onClick={closeDrawer} size="medium" edge="start">
<CloseIcon />
</CloseButtonLayout>
<AppDefault />
</Drawer>
</AppProvider>
Expand Down
10 changes: 10 additions & 0 deletions packages/widget/src/components/Header/Header.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,13 @@ export const WalletButton = styled(Button)(({ theme }) => ({
fontSize: '24px',
},
}));

export const DrawerWalletContainer = styled(Box)(() => ({
width: '100%',
display: 'flex',
justifyItems: 'start',

'& > button': {
marginLeft: '-0.75rem',
},
}));
10 changes: 7 additions & 3 deletions packages/widget/src/components/Header/NavigationHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { WalletMenuButton } from './WalletHeader';

export const NavigationHeader: React.FC = () => {
const { t } = useTranslation();
const { subvariant, hiddenUI } = useWidgetConfig();
const { subvariant, hiddenUI, variant } = useWidgetConfig();
const { navigate, navigateBack } = useNavigateBack();
const { account } = useWallet();
const { element, title } = useHeaderStore((state) => state);
Expand Down Expand Up @@ -115,7 +115,11 @@ export const NavigationHeader: React.FC = () => {
<Route
path={navigationRoutes.home}
element={
<>
<Box
paddingRight={
variant === 'drawer' && subvariant === 'split' ? 6 : 0
}
>
{account.isActive && !hiddenUI?.includes(HiddenUI.History) ? (
<Tooltip
title={t(`header.transactionHistory`)}
Expand Down Expand Up @@ -144,7 +148,7 @@ export const NavigationHeader: React.FC = () => {
<SettingsIcon />
</IconButton>
</Tooltip>
</>
</Box>
}
/>
<Route path="*" element={element || <Box width={28} height={40} />} />
Expand Down
15 changes: 14 additions & 1 deletion packages/widget/src/components/Header/WalletHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import { useLocation, useNavigate } from 'react-router-dom';
import { useChain } from '../../hooks';
import { useWallet, useWidgetConfig } from '../../providers';
import { navigationRoutes, shortenAddress } from '../../utils';
import { HeaderAppBar, WalletButton } from './Header.style';
import {
DrawerWalletContainer,
HeaderAppBar,
WalletButton,
} from './Header.style';
import { WalletMenu } from './WalletMenu';

export const WalletHeader: React.FC = () => {
Expand All @@ -23,6 +27,15 @@ export const WalletHeader: React.FC = () => {

export const WalletMenuButton: React.FC = () => {
const { account } = useWallet();
const { variant } = useWidgetConfig();

if (variant === 'drawer') {
return (
<DrawerWalletContainer>
{account.isActive ? <ConnectedButton /> : <ConnectButton />}
</DrawerWalletContainer>
);
}
return account.isActive ? <ConnectedButton /> : <ConnectButton />;
};

Expand Down