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

feat: responsiveness #17

Merged
merged 5 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"gasPrice": "L1 Gas Price",
"transfer": "ERC-20 Transfer",
"home": "Home",
"menu": "Menu",
"LOCKEDASSETS": {
"lockedAssets": "Locked assets",
"lockedAssetsDescription": "Locked assets in Elastic Chain Ecosystem",
Expand Down
1 change: 1 addition & 0 deletions public/locales/es/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"gasPrice": "Precio del gas L1",
"transfer": "Transferencia ERC-20",
"home": "Inicio",
"menu": "Menú",
"LOCKEDASSETS": {
"lockedAssets": "Activos bloqueados",
"lockedAssetsDescription": "Activos bloqueados en el ecosistema de Elastic Chain",
Expand Down
1 change: 1 addition & 0 deletions src/assets/icons/closeDark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/assets/icons/closeLight.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/assets/icons/menuDark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/assets/icons/menuLight.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
7 changes: 6 additions & 1 deletion src/components/ChainInformation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,19 @@ export const ChainInformation = () => {
);
};

export const DataContainer = styled(Box)(() => {
export const DataContainer = styled(Box)(({ theme: muiTheme }) => {
const { currentTheme, theme } = useCustomTheme();

return {
background: theme === 'dark' ? currentTheme.backgroundTertiary : currentTheme.backgroundSecondary,
borderRadius: currentTheme.borderRadius,
border: currentTheme.border,
display: 'grid',
gridTemplateColumns: 'repeat(4, 1fr)',

[muiTheme.breakpoints.down('sm')]: {
gridTemplateColumns: 'repeat(1, 1fr)',
},
};
});

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>
);
};
2 changes: 1 addition & 1 deletion src/components/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const DataTable = ({ chains }: TableProps) => {
export const STableContainer = styled(TableContainer)(() => {
const { currentTheme } = useCustomTheme();
return {
width: '75rem',
width: '100%',
borderRadius: currentTheme.borderRadius,
border: currentTheme.border,
overflow: 'hidden',
Expand Down
28 changes: 21 additions & 7 deletions src/components/TitleBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,22 @@ export const TitleBanner = () => {
);
};

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

return {
display: 'flex',
alignItems: 'center',
alignSelf: 'flex-start',
gap: currentTheme.gap,
justifyContent: 'center',
textAlign: 'center',
[theme.breakpoints.down('sm')]: {
display: 'grid',
gridTemplateColumns: 'auto 1fr',
justifyContent: 'start',
textAlign: 'left',
},
};
});

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

const Subtitle = styled(Typography)(() => ({
fontSize: '3rem',
fontWeight: 700,
lineHeight: '4rem',
letterSpacing: '-0.03em',
}));
const Subtitle = styled(Typography)(({ theme }) => {
return {
fontSize: '3rem',
fontWeight: 700,
lineHeight: '4rem',
letterSpacing: '-0.03em',
gridColumn: 'auto',
[theme.breakpoints.down('sm')]: {
gridColumn: 'span 2',
},
};
});
88 changes: 77 additions & 11 deletions src/components/TotalValueLocked.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Box, Typography, Grid, styled } from '@mui/material';
import { Box, Typography, Grid, styled, useMediaQuery, useTheme } from '@mui/material';
import { useTranslation } from 'next-i18next';
import { TvlData } from '~/types';
import { TvlContentBox } from '~/components';
Expand All @@ -9,17 +9,78 @@ interface TotalValueLockedProps {
}

export const TotalValueLocked = ({ tvl }: TotalValueLockedProps) => {
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down('sm'));

return (
Comment on lines 11 to +14
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be nice if we can split these components into different files in another pr

<>
{isMobile && <MobileTvlContainer tvl={tvl} />}
{!isMobile && <DesktopTvlContainer tvl={tvl} />}
</>
);
};

const MobileTvlContainer = ({ tvl }: TotalValueLockedProps) => {
const { t } = useTranslation();

const renderTvlContent = (
data: TvlData,
index: number,
height: string,
xs: number,
smallCard?: boolean,
isLast?: boolean,
) => (
<Grid item xs={xs} key={index}>
<GridContainer imageUrl={data.imageUrl} height={height} smallCard={smallCard}>
<TvlContentBox
avatar={data.imageUrl}
token={data.token}
total={data.total}
tokenName={data.tokenName}
isLast={isLast}
/>
</GridContainer>
</Grid>
);

return (
<TvlContainer container spacing={0.5}>
{/* First item: full width */}
{renderTvlContent(tvl[0], 0, '12rem', 12)}

{/* Second item: full width, half height */}
{renderTvlContent(tvl[1], 1, '6rem', 12)}

{/* Third and Fourth items: half width each */}
<Grid item container xs={12} spacing={0.5}>
{renderTvlContent(tvl[2], 2, '6rem', 6)}
{renderTvlContent(tvl[3], 3, '6rem', 6)}
</Grid>

{/* Fifth item: half width */}
<Grid item container xs={12} spacing={0.5}>
{renderTvlContent(tvl[4], 4, '5rem', 6, true, true)}

{/* Sixth item: two-thirds width + others remaining */}
<Grid item container xs={6} spacing={0.5}>
{renderTvlContent(tvl[5], 5, '5rem', 9, true, true)}
<Grid item xs={3}>
<GridContainer height='5rem'>
<OthersBox>
<OthersText>{t('HOME.LOCKEDASSETS.others')}</OthersText>
</OthersBox>
</GridContainer>
</Grid>
</Grid>
</Grid>
</TvlContainer>
);
};

const DesktopTvlContainer = ({ tvl }: TotalValueLockedProps) => {
const { t } = useTranslation();

/**
* Renders the TVL content within a grid container.
* @param data - The TVL data.
* @param index - The index of the item in the array.
* @param height - The height of the container.
* @param xs - The grid size for the container.
* @param smallCard - Whether the card is small or not.
* @param isLast - Whether the card is the last one or not.
*/
const renderTvlContent = (
data: TvlData,
index: number,
Expand All @@ -43,18 +104,23 @@ export const TotalValueLocked = ({ tvl }: TotalValueLockedProps) => {

return (
<TvlContainer container spacing={0.5}>
{/* First item: full width */}
{renderTvlContent(tvl[0], 0, '12rem', 12)}

<Grid item container xs={12} spacing={0.5}>
{/* Second item: half width */}
{renderTvlContent(tvl[1], 1, '12rem', 6)}

<Grid item container xs={6} spacing={0.5}>
{/* Third and fourth items: one-third width each*/}
{tvl.slice(2, 4).map((data, index) => renderTvlContent(data, index + 2, '12rem', 4, true))}

<Grid item container xs={4} direction='column'>
{/* Fifth item: one-third width and half height */}
{renderTvlContent(tvl[4], 4, '5.85rem', 6, true)}

<Grid item container xs={6} spacing={0.5}>
{/* Sixth item: three-fourths width and halft height + others remaining width same height*/}
{renderTvlContent(tvl[5], 5, '5.85rem', 9, true, true)}
<Grid item xs={3}>
<GridContainer height='5.85rem'>
Expand All @@ -74,7 +140,7 @@ export const TotalValueLocked = ({ tvl }: TotalValueLockedProps) => {
const TvlContainer = styled(Grid)({
display: 'flex',
flexWrap: 'wrap',
width: '75rem',
alignItems: 'flex-start',
});

interface GridContainerProps {
Expand Down
23 changes: 12 additions & 11 deletions src/components/TvlContentBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ export const TvlContentBox = ({ avatar, token, total, tokenName, isLast }: TvlCo
<TopBox>
<TokenLogo src={avatar} alt={token} isLast={isLast || false} />
<TextBox>
<TokenName>{tokenName}</TokenName>
<TokenTicker>{token}</TokenTicker>
<TokenName isLast={isLast || false}>{tokenName}</TokenName>
<TokenTicker isLast={isLast || false}>{token}</TokenTicker>
</TextBox>
</TopBox>

<TvlAmount isLast={isLast || false}>{formatDataNumber(total, 0, true)}</TvlAmount>
<TvlAmount isLast={isLast ? isLast : false}>{formatDataNumber(total, 0, true)}</TvlAmount>
</ContentBox>
);
};
Expand All @@ -33,6 +33,7 @@ const ContentBox = styled(Box)({
alignItems: 'flex-start',
zIndex: 1,
width: '100%',
height: '100%',
});

const TopBox = styled(Box)(() => {
Expand All @@ -54,32 +55,32 @@ const TokenLogo = styled(Avatar)<TvlProps>(({ isLast }) => ({
}));

const TvlAmount = styled(Typography)<TvlProps>(({ isLast }) => ({
fontSize: `${isLast ? '0.85rem' : '1rem'}`,
fontSize: `${isLast ? '0.75rem' : '0.875rem'}`,
fontWeight: 400,
}));

const TextBox = styled(Box)(() => {
const { currentTheme } = useCustomTheme();
return {
display: 'flex',
alignItems: 'center',
flexWrap: 'wrap',
gap: currentTheme.gap,
};
});

const TokenName = styled(Typography)({
fontSize: '0.85rem',
const TokenName = styled(Typography)<TvlProps>(({ isLast }) => ({
fontSize: `${isLast ? '0.75rem' : '0.875rem'}`,
fontWeight: 400,
whiteSpace: 'nowrap',
});
margin: '0',
}));

const TokenTicker = styled(Typography)(() => {
const TokenTicker = styled(Typography)<TvlProps>(({ isLast }) => {
const { currentTheme } = useCustomTheme();
return {
fontSize: '0.85rem',
fontSize: `${isLast ? '0.75rem' : '0.875rem'}`,
fontWeight: 400,
color: currentTheme.textSecondary,
whiteSpace: 'nowrap',
margin: '0',
};
});
Loading
Loading