Skip to content

Commit 68e51ef

Browse files
authored
Merge pull request #2260 from oasisprotocol/mz/uil-appbar
Replace MUI AppBar component with tailwind classes
2 parents b97555b + 93894a0 commit 68e51ef

File tree

3 files changed

+32
-30
lines changed

3 files changed

+32
-30
lines changed

.changelog/2260.internal.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Replace MUI AppBar component with tailwind classes
Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { FC } from 'react'
2-
import AppBar from '@mui/material/AppBar'
3-
import useScrollTrigger from '@mui/material/useScrollTrigger'
42
import { useTheme } from '@mui/material/styles'
3+
import { useScrolled } from '../../hooks/useScrolled'
54
import { HomePageLink } from './Logotype'
65
import { NetworkSelector } from './NetworkSelector'
7-
import Button from '@mui/material/Button'
6+
import { Button } from '@oasisprotocol/ui-library/src/components/ui/button'
87
import { useScopeParam } from '../../hooks/useScopeParam'
98
import { useScreenSize } from '../../hooks/useScreensize'
109
import { isScopeSelectorNeeded } from '../../utils/route-utils'
@@ -17,29 +16,19 @@ export const Header: FC = () => {
1716
const { isDesktop } = useScreenSize()
1817
const scope = useScopeParam()
1918
const withScopeSelector = !!scope && isScopeSelectorNeeded(scope)
20-
const scrollTrigger = useScrollTrigger({
21-
disableHysteresis: true,
22-
threshold: 0,
23-
})
19+
const scrolled = useScrolled()
2420

2521
return (
26-
<AppBar
27-
position="sticky"
28-
sx={{
29-
transitionProperty: 'background-color',
30-
transitionDuration: `${theme.transitions.duration.standard}ms`,
31-
transitionTimingFunction: theme.transitions.easing.easeInOut,
32-
backgroundColor: scrollTrigger
33-
? theme.palette.layout.contrastSecondary
34-
: theme.palette.layout.secondary,
35-
borderRadius: 0,
36-
boxShadow: '0px 4px 6px -1px rgba(0, 0, 0, 0.10), 0px 2px 4px -1px rgba(0, 0, 0, 0.06)',
22+
<header
23+
className="flex flex-col w-full box-border flex-shrink-0 sticky z-[1100] top-0 right-0 left-auto shadow-md"
24+
style={{
25+
backgroundColor: theme.palette.layout.contrastSecondary,
3726
}}
3827
>
3928
<div className="px-4">
4029
<div className="grid grid-cols-12 pt-3 pb-4 px-0 md:px-[4%]">
4130
<div className="col-span-6 xl:col-span-3 flex items-center">
42-
<HomePageLink showText={!scrollTrigger && !isMobile} />
31+
<HomePageLink showText={!scrolled && !isMobile} />
4332
</div>
4433

4534
{withScopeSelector && (
@@ -50,21 +39,15 @@ export const Header: FC = () => {
5039

5140
{isDesktop && (
5241
<div className="col-span-3 flex justify-end items-center">
53-
<Button
54-
component="a"
55-
href="https://rose.oasis.io/"
56-
target="_blank"
57-
rel="noopener noreferrer"
58-
color="secondary"
59-
variant="outlined"
60-
size="large"
61-
>
62-
{t('common.visitRoseApp')}
42+
<Button variant="outline" size="lg" asChild>
43+
<a href="https://rose.oasis.io/" target="_blank" rel="noopener noreferrer">
44+
{t('common.visitRoseApp')}
45+
</a>
6346
</Button>
6447
</div>
6548
)}
6649
</div>
6750
</div>
68-
</AppBar>
51+
</header>
6952
)
7053
}

src/app/hooks/useScrolled.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { useEffect, useState } from 'react'
2+
3+
export function useScrolled(): boolean {
4+
const [scrolled, setScrolled] = useState(false)
5+
6+
useEffect(() => {
7+
const handleScroll = () => {
8+
setScrolled(window.scrollY > 0)
9+
}
10+
11+
handleScroll()
12+
window.addEventListener('scroll', handleScroll, { passive: true })
13+
14+
return () => window.removeEventListener('scroll', handleScroll)
15+
}, [])
16+
17+
return scrolled
18+
}

0 commit comments

Comments
 (0)