Skip to content

Commit

Permalink
feat: responsive breadcrumb | metadata | header
Browse files Browse the repository at this point in the history
  • Loading branch information
0xtiti committed Aug 9, 2024
1 parent 7f9ebd4 commit 2053f29
Show file tree
Hide file tree
Showing 8 changed files with 259 additions and 48 deletions.
1 change: 1 addition & 0 deletions src/components/Breadcrumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const Breadcrumb = ({ isChain }: BreadcrumbProps) => {
const BreadcrumbNav = styled('nav')({
display: 'flex',
alignItems: 'center',
marginBottom: '1.5rem',
});

const BreadcrumbLink = styled(Link)(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/FeeParams.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const FeeParams = () => {
const { chainData } = useData();

return (
<>
<article>
<STitle>{t('CHAIN.FEEPARAMS.title')} </STitle>
<DataContainer>
<InfoBox
Expand Down Expand Up @@ -56,6 +56,6 @@ export const FeeParams = () => {
alt='max-icon'
/>
</DataContainer>
</>
</article>
);
};
25 changes: 17 additions & 8 deletions src/components/TitleBanner.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useTranslation } from 'next-i18next';
import { Box, Typography, styled } from '@mui/material';
import { Box, Typography, styled, useMediaQuery } from '@mui/material';
import Image from 'next/image';

import ZkLogoDark from '~/assets/icons/zkLogoDark.svg';
Expand All @@ -24,12 +24,16 @@ export const TitleBanner = () => {

const TitleBox = styled(Box)(() => {
const { currentTheme } = useCustomTheme();
const isMobile = useMediaQuery('(max-width:600px)');

return {
display: 'flex',
display: isMobile ? 'grid' : 'flex',
gridTemplateColumns: isMobile ? 'auto 1fr' : 'none',
alignItems: 'center',
alignSelf: 'flex-start',
gap: currentTheme.gap,
justifyContent: isMobile ? 'start' : 'center',
textAlign: isMobile ? 'left' : 'center',
};
});

Expand All @@ -44,9 +48,14 @@ const Bold = styled('span')({
fontWeight: 700,
});

const Subtitle = styled(Typography)(() => ({
fontSize: '3rem',
fontWeight: 700,
lineHeight: '4rem',
letterSpacing: '-0.03em',
}));
const Subtitle = styled(Typography)(() => {
const isMobile = useMediaQuery('(max-width:600px)');

return {
fontSize: '3rem',
fontWeight: 700,
lineHeight: '4rem',
letterSpacing: '-0.03em',
gridColumn: isMobile ? 'span 2' : 'auto',
};
});
31 changes: 26 additions & 5 deletions src/containers/ChainDetail/ChainMetadata.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Avatar, Box, Button, Typography, styled } from '@mui/material';
import { Avatar, Box, Button, Typography, styled, useMediaQuery } from '@mui/material';
import { useTranslation } from 'next-i18next';
import Image from 'next/image';

Expand Down Expand Up @@ -92,6 +92,7 @@ export const ChainMetadata = () => {

const MetadataContainer = styled(Box)(() => {
const { currentTheme, theme } = useCustomTheme();

return {
background: theme === 'dark' ? currentTheme.backgroundTertiary : currentTheme.backgroundSecondary,
borderRadius: currentTheme.borderRadius,
Expand All @@ -100,8 +101,10 @@ const MetadataContainer = styled(Box)(() => {
});

const FirstRow = styled(Box)(() => {
const isMobile = useMediaQuery('(max-width:600px)');

return {
display: 'flex',
display: isMobile ? 'grid' : 'flex',
alignItems: 'center',
justifyContent: 'space-between',
padding: '1.5rem 1rem',
Expand All @@ -110,8 +113,14 @@ const FirstRow = styled(Box)(() => {

const SecondRow = styled(Box)(() => {
const { currentTheme } = useCustomTheme();
const isMobile = useMediaQuery('(max-width:600px)');

return {
display: 'flex',
display: isMobile ? 'grid' : 'flex',
alignItems: 'center',
justifyContent: isMobile ? 'space-between' : 'flex-start',
gap: currentTheme.gap,
gridTemplateColumns: isMobile ? 'repeat(2, 1fr)' : 'none',
width: '100%',
borderTop: currentTheme.border,
};
Expand All @@ -127,6 +136,7 @@ const ChainIdentity = styled(Box)(() => {

const MetadataButton = styled(Button)(() => {
const { currentTheme, theme } = useCustomTheme();

return {
background: theme === 'dark' ? currentTheme.backgroundSecondary : currentTheme.backgroundTertiary,
borderRadius: currentTheme.borderRadius,
Expand All @@ -146,6 +156,7 @@ const MetadataButton = styled(Button)(() => {

const AddNetworkBtn = styled(Button)(() => {
const { currentTheme } = useCustomTheme();

return {
background: currentTheme.primary[500],
borderRadius: currentTheme.borderRadius,
Expand Down Expand Up @@ -175,16 +186,21 @@ const WebIcon = styled(Image)({

const ButtonsContainer = styled(Box)(() => {
const { currentTheme } = useCustomTheme();
const isMobile = useMediaQuery('(max-width:600px)');

return {
display: 'flex',
display: isMobile ? 'grid' : 'flex',
alignItems: 'center',
justifyContent: 'flex-end',
justifyContent: isMobile ? 'space-between' : 'flex-end',
gap: currentTheme.gap,
gridTemplateColumns: isMobile ? 'repeat(2, 1fr)' : 'none',
marginTop: isMobile ? '1rem' : 0,
};
});

export const ChainName = styled(Box)(() => {
const { currentTheme } = useCustomTheme();

return {
fontSize: '1.5rem',
fontWeight: 700,
Expand All @@ -195,6 +211,7 @@ export const ChainName = styled(Box)(() => {

export const ChainId = styled(Box)(() => {
const { currentTheme } = useCustomTheme();

return {
fontSize: '1rem',
fontWeight: 400,
Expand All @@ -205,13 +222,15 @@ export const ChainId = styled(Box)(() => {

export const ChainIdValue = styled('span')(() => {
const { currentTheme } = useCustomTheme();

return {
color: currentTheme.textPrimary,
};
});

const MetadataItem = styled(Box)(() => {
const { currentTheme } = useCustomTheme();

return {
display: 'flex',
alignItems: 'center',
Expand All @@ -227,6 +246,7 @@ const MetadataItem = styled(Box)(() => {

const Label = styled(Typography)(() => {
const { currentTheme } = useCustomTheme();

return {
fontSize: '0.875rem',
lineHeight: '1.25rem',
Expand All @@ -237,6 +257,7 @@ const Label = styled(Typography)(() => {

const Value = styled(Typography)(() => {
const { currentTheme } = useCustomTheme();

return {
fontSize: '1rem',
lineHeight: '1.5rem',
Expand Down
7 changes: 5 additions & 2 deletions src/containers/ChainDetail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import { Breadcrumb } from '~/components';
export const ChainDetail = () => {
return (
<ChainContainer>
<Breadcrumb isChain={true} />
<ChainMetadata />
<Box>
<Breadcrumb isChain={true} />
<ChainMetadata />
</Box>

<ChainDescription />
</ChainContainer>
);
Expand Down
46 changes: 46 additions & 0 deletions src/containers/Header/DesktopHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { useTranslation } from 'next-i18next';
import Image from 'next/image';

import { StyledHeader, LogoContainer, Logo, SIconButton } from '~/containers';
import { HeaderProps } from '.';

import { BasicSelect, SearchBar, Gas, SBox } from '~/components';
import LogoDark from '~/assets/icons/logoDark.svg';
import LogoLight from '~/assets/icons/logoLight.svg';
import LightMode from '~/assets/icons/lightMode.svg';
import DarkMode from '~/assets/icons/darkMode.svg';

interface DesktopHeaderProps extends HeaderProps {}

export const DesktopHeader = ({
theme,
goToHome,
handleChangeLanguage,
localesMap,
changeTheme,
}: DesktopHeaderProps) => {
const {
t,
i18n: { language },
} = useTranslation();

return (
<StyledHeader>
<LogoContainer onClick={goToHome} role='button' aria-label='Navigate to home'>
<Logo src={theme === 'dark' ? LogoDark : LogoLight} alt='ZK Chain Hub' />
</LogoContainer>
<SBox>
<Gas />
<SearchBar />
<BasicSelect
value={t(`LOCALES.${language}`)}
setValue={handleChangeLanguage}
list={Object.values(localesMap)}
/>
<SIconButton onClick={changeTheme}>
{theme === 'dark' ? <Image src={LightMode} alt='light mode' /> : <Image src={DarkMode} alt='dark mode' />}
</SIconButton>
</SBox>
</StyledHeader>
);
};
128 changes: 128 additions & 0 deletions src/containers/Header/MobileHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import React from 'react';
import { styled } from '@mui/material/styles';
import { Box, IconButton, Drawer, List, ListItem } from '@mui/material';
import MenuIcon from '@mui/icons-material/Menu';
import { useTranslation } from 'next-i18next';
import Image from 'next/image';

import LogoDark from '~/assets/icons/logoDark.svg';
import LogoLight from '~/assets/icons/logoLight.svg';
import LightMode from '~/assets/icons/lightMode.svg';
import DarkMode from '~/assets/icons/darkMode.svg';
import { BasicSelect, Gas, Icon } from '~/components';
import { useCustomTheme } from '~/hooks';
import SearchDark from '~/assets/icons/searchDark.svg';
import SearchLight from '~/assets/icons/searchLight.svg';

interface MobileHeaderProps {
theme: string;
goToHome: () => void;
handleChangeLanguage: (value: string) => void;
localesMap: Record<string, string>;
changeTheme: () => void;
}

export const MobileHeader = ({ theme, goToHome, handleChangeLanguage, localesMap, changeTheme }: MobileHeaderProps) => {
const {
t,
i18n: { language },
} = useTranslation();

const [drawerOpen, setDrawerOpen] = React.useState(false);

const toggleDrawer = (open: boolean) => () => {
setDrawerOpen(open);
};

return (
<StyledHeader>
<LogoContainer onClick={goToHome} role='button' aria-label='Navigate to home'>
<Logo src={theme === 'dark' ? LogoDark : LogoLight} alt='ZK Chain Hub' />
</LogoContainer>
<IconsContainer>
<SearchIconButton>
<Icon darkIcon={SearchDark} lightIcon={SearchLight} alt='Search' size={20} />
</SearchIconButton>
<IconButton onClick={toggleDrawer(true)} aria-label='open menu'>
<MenuIcon />
</IconButton>
</IconsContainer>
<Drawer anchor='right' open={drawerOpen} onClose={toggleDrawer(false)}>
<DrawerContent>
<List>
<ListItem>
<Gas />
</ListItem>
<ListItem>
<BasicSelect
value={t(`LOCALES.${language}`)}
setValue={handleChangeLanguage}
list={Object.values(localesMap)}
/>
</ListItem>
<ListItem>
<SIconButton onClick={changeTheme}>
{theme === 'dark' ? (
<Image src={LightMode} alt='light mode' />
) : (
<Image src={DarkMode} alt='dark mode' />
)}
</SIconButton>
</ListItem>
</List>
</DrawerContent>
</Drawer>
</StyledHeader>
);
};

export default MobileHeader;

// Styled components
const StyledHeader = styled('header')({
display: 'flex',
height: '5.5rem',
padding: '1rem',
alignItems: 'center',
justifyContent: 'space-between',
width: '100%',
});

const LogoContainer = styled(Box)({
display: 'flex',
alignItems: 'center',
height: '100%',
flexShrink: 0,
});

const Logo = styled(Image)({
width: '10rem',
height: 'auto',
});

const IconsContainer = styled(Box)({
display: 'flex',
alignItems: 'center',
gap: '1rem',
});

const SearchIconButton = styled(IconButton)({
padding: 0,
});

const SIconButton = styled(IconButton)(() => {
const { currentTheme } = useCustomTheme();
return {
color: `${currentTheme.textPrimary}`,
backgroundColor: `${currentTheme.backgroundSecondary}`,
borderRadius: `${currentTheme.borderRadius}`,
padding: '1rem',
width: '3.5rem',
height: '3.5rem',
};
});

const DrawerContent = styled(Box)({
width: '250px',
padding: '1rem',
});
Loading

0 comments on commit 2053f29

Please sign in to comment.