From 647c8c582ebaa942a99a083bdbde50230dbe4eb3 Mon Sep 17 00:00:00 2001 From: titix Date: Tue, 10 Sep 2024 17:43:44 -0300 Subject: [PATCH] fix: rpc dynamic grid --- src/components/RPC.tsx | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/components/RPC.tsx b/src/components/RPC.tsx index df90c57..3611cfb 100644 --- a/src/components/RPC.tsx +++ b/src/components/RPC.tsx @@ -3,9 +3,13 @@ import { useTranslation } from 'next-i18next'; import { Box, Typography, Tooltip, styled, Skeleton, Button } from '@mui/material'; import { useData, useCustomTheme, useCopyToClipboard } from '~/hooks'; -import { DataContainer, STitle, Icon, NotAvailable, STooltip } from '~/components'; +import { STitle, Icon, NotAvailable, STooltip } from '~/components'; import { checkRpcStatus } from '~/utils'; +interface RpcProps { + count: number; +} + export const RPC = () => { const { t } = useTranslation(); const { chainData } = useData(); @@ -41,6 +45,10 @@ export const RPC = () => { return rpcData.length > 4 && !rpcIsLoading; }, [rpcData, rpcIsLoading]); + const count = useMemo(() => { + return Math.min(rpcData.length, 4); + }, [rpcData.length]); + return (
@@ -48,7 +56,7 @@ export const RPC = () => { {t('CHAIN.RPC.subtitle')} - + {rpcIsLoading && Array.from({ length: 4 }).map((_, index) => ( @@ -89,7 +97,7 @@ export const RPC = () => { {t('CHAIN.CHAININFORMATION.notAvailable')} )} - + {showMoreButton && ( @@ -104,6 +112,22 @@ export const RPC = () => { ); }; +export const RPCContainer = styled(Box)(({ theme: muiTheme, count }) => { + const { currentTheme, theme } = useCustomTheme(); + + return { + background: theme === 'dark' ? currentTheme.backgroundTertiary : currentTheme.backgroundSecondary, + borderRadius: currentTheme.borderRadius, + border: currentTheme.border, + display: 'grid', + gridTemplateColumns: `repeat(${count}, 1fr)`, + + [muiTheme.breakpoints.down('md')]: { + gridTemplateColumns: 'repeat(1, 1fr)', + }, + }; +}); + const RPCTitle = styled(Box)(() => { return { display: 'flex', @@ -123,7 +147,7 @@ const RPCBox = styled(Box)(() => { const { currentTheme } = useCustomTheme(); return { display: 'flex', - height: '4.5rem', + minHeight: '4.5rem', alignItems: 'center', width: '100%', padding: currentTheme.padding,