Skip to content

Commit

Permalink
feat: header styles
Browse files Browse the repository at this point in the history
  • Loading branch information
NovaT82 committed Nov 1, 2024
1 parent 4e11445 commit 473fbda
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 164 deletions.
103 changes: 49 additions & 54 deletions src/routes/Blocks/Block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import Container from '@mui/material/Container';
import Grid from '@mui/material/Grid';
import { StyledPaper } from '../../components/StyledComponents';
import { useTheme } from '@mui/material/styles';
Expand All @@ -39,67 +38,63 @@ function Block() {
if (isLoading || isError) {
return (
<Grid item xs={12} md={12} lg={12}>
<Container maxWidth="xl">
<Grid container spacing={3}>
<Grid item xs={12} md={12} lg={12}>
<StyledPaper>
<FetchStatusCheck
isError={isError}
isLoading={isLoading}
errorMessage={error?.message || 'Error retrieving data'}
/>
</StyledPaper>
</Grid>
<Grid container spacing={3}>
<Grid item xs={12} md={12} lg={12}>
<StyledPaper>
<FetchStatusCheck
isError={isError}
isLoading={isLoading}
errorMessage={error?.message || 'Error retrieving data'}
/>
</StyledPaper>
</Grid>
</Container>
</Grid>
</Grid>
);
}

return (
<Grid item xs={12} md={12} lg={12}>
<Container maxWidth="xl">
<Grid container spacing={3}>
<Grid item xs={12} md={12} lg={6}>
<StyledPaper>
<BlockInfo blockHeight={blockHeight} />
</StyledPaper>
</Grid>
<Grid
item
xs={12}
md={12}
lg={6}
style={{
display: 'flex',
flexDirection: 'column',
gap: theme.spacing(3),
}}
>
<StyledPaper>
<BlockParts
blockHeight={blockHeight}
type="kernels"
itemsPerPage={5}
/>
</StyledPaper>
<StyledPaper>
<BlockParts
blockHeight={blockHeight}
type="outputs"
itemsPerPage={5}
/>
</StyledPaper>
<StyledPaper>
<BlockParts
blockHeight={blockHeight}
type="inputs"
itemsPerPage={5}
/>
</StyledPaper>
</Grid>
<Grid container spacing={3}>
<Grid item xs={12} md={12} lg={6}>
<StyledPaper>
<BlockInfo blockHeight={blockHeight} />
</StyledPaper>
</Grid>
</Container>
<Grid
item
xs={12}
md={12}
lg={6}
style={{
display: 'flex',
flexDirection: 'column',
gap: theme.spacing(3),
}}
>
<StyledPaper>
<BlockParts
blockHeight={blockHeight}
type="kernels"
itemsPerPage={5}
/>
</StyledPaper>
<StyledPaper>
<BlockParts
blockHeight={blockHeight}
type="outputs"
itemsPerPage={5}
/>
</StyledPaper>
<StyledPaper>
<BlockParts
blockHeight={blockHeight}
type="inputs"
itemsPerPage={5}
/>
</StyledPaper>
</Grid>
</Grid>
</Grid>
);
}
Expand Down
49 changes: 49 additions & 0 deletions src/routes/Header/AppHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import Header from './Header';
import TopBar from './TopBar';
import { useState, useEffect } from 'react';
import Box from '@mui/material/Box';

const darkBg = 'rgb(25, 14, 43, 0.95)';
const lightBg = 'rgba(0,0,0,0.1)';

function AppHeader() {
const [bgColor, setBgColor] = useState(lightBg);
const [isScrolled, setIsScrolled] = useState(false);

useEffect(() => {
const handleScroll = () => {
if (window.scrollY > 10) {
setBgColor(darkBg);
setIsScrolled(true);
} else {
setBgColor(lightBg);
setIsScrolled(false);
}
};

handleScroll();

window.addEventListener('scroll', handleScroll);
return () => {
window.removeEventListener('scroll', handleScroll);
};
}, []);

return (
<Box
style={{
position: 'sticky',
top: 0,
width: '100%',
backgroundColor: bgColor,
transition: 'background-color 0.3s ease',
zIndex: 1000,
}}
>
<TopBar />
<Header isScrolled={isScrolled} />
</Box>
);
}

export default AppHeader;
34 changes: 28 additions & 6 deletions src/routes/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ import SearchField from './SearchField';
import { useState } from 'react';
import { formatHash } from '../../utils/helpers';

function Header() {
interface HeaderProps {
isScrolled: boolean;
}

function Header({ isScrolled }: HeaderProps) {
const { data } = useAllBlocks();
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down('md'));
Expand Down Expand Up @@ -74,17 +78,24 @@ function Header() {
justifyContent: 'space-between',
alignItems: 'center',
width: '100%',
paddingTop: theme.spacing(3),
paddingBottom: theme.spacing(3),
minHeight: '100px',
paddingTop: isScrolled ? theme.spacing(1) : theme.spacing(3),
paddingBottom: isScrolled ? theme.spacing(0) : theme.spacing(3),
transition: 'padding 0.3s ease-in-out, height 0.3s ease-in-out',
}}
>
{isMobile ? (
<>
{!isExpanded && (
<Fade in={!isExpanded}>
<Link to="/">
<TariLogo fill={theme.palette.text.primary} />
<Box
style={{
marginTop: isScrolled ? '0' : '10px',
transition: 'margin 0.3s ease-in-out',
}}
>
<TariLogo fill={theme.palette.text.primary} />
</Box>
</Link>
</Fade>
)}
Expand Down Expand Up @@ -116,7 +127,14 @@ function Header() {
<Grid container spacing={3}>
<Grid item xs={10} md={3} lg={3}>
<Link to="/">
<TariLogo fill={theme.palette.text.primary} />
<Box
style={{
marginTop: isScrolled ? '0' : '10px',
transition: 'margin 0.3s ease-in-out',
}}
>
<TariLogo fill={theme.palette.text.primary} />
</Box>
</Link>
</Grid>
<Grid item xs={12} md={9} lg={9}>
Expand All @@ -131,6 +149,7 @@ function Header() {
<StatsItem
label="RandomX Hash Rate"
value={formattedMoneroHashRate}
isScrolled={isScrolled}
/>
<Divider
orientation="vertical"
Expand All @@ -140,6 +159,7 @@ function Header() {
<StatsItem
label="Sha3 Hash Rate"
value={formattedSha3HashRate}
isScrolled={isScrolled}
/>
<Divider
orientation="vertical"
Expand All @@ -149,6 +169,7 @@ function Header() {
<StatsItem
label="Avg Block Time"
value={formattedAverageBlockTime}
isScrolled={isScrolled}
lowerCase
/>
<Divider
Expand All @@ -159,6 +180,7 @@ function Header() {
<StatsItem
label="Block Height"
value={formattedBlockHeight}
isScrolled={isScrolled}
/>
</Box>
</Grid>
Expand Down
12 changes: 0 additions & 12 deletions src/routes/Header/StatsItem.css

This file was deleted.

26 changes: 22 additions & 4 deletions src/routes/Header/StatsItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,52 @@
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import { Box, Typography } from '@mui/material';
import './StatsItem.css';

interface Props {
label: string;
value: string;
lowerCase?: boolean;
isScrolled: boolean;
}

export default function StatsItem({ label, value, lowerCase }: Props) {
export default function StatsItem({
label,
value,
lowerCase,
isScrolled,
}: Props) {
return (
<Box
style={{
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
gap: 0,
minWidth: '108px',
}}
>
<Typography
variant="body1"
className="topbar-item-value"
style={{
textTransform: lowerCase ? 'lowercase' : 'uppercase',
fontFamily: 'AvenirHeavy',
fontSize: isScrolled ? '18px' : '24px',
color: '#fff',
textAlign: 'center',
transition: 'font-size 0.3s ease-in-out',
}}
>
{value}
</Typography>
<Typography className="topbar-item-label">{label}</Typography>
<Typography
style={{
fontSize: '12px',
color: '#fff',
textAlign: 'center',
}}
>
{label}
</Typography>
</Box>
);
}
Loading

0 comments on commit 473fbda

Please sign in to comment.