-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Commenting the behavior of Product Component.
- Loading branch information
1 parent
28f2ce4
commit 7958d9f
Showing
3 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import {AiOutlineArrowUp} from 'react-icons/ai'; | ||
export function GoToTopButton() { | ||
const [ isVisible, setIsVisible ] = useState(false); | ||
//create a go to top button | ||
|
||
const goToTop = () => { | ||
window.scrollTo({ | ||
top: 0, | ||
behavior: 'smooth' | ||
}); | ||
}; | ||
|
||
const toggleVisibility = () => { | ||
|
||
window.pageYOffset > 300? | ||
setIsVisible(true): | ||
setIsVisible(false) | ||
|
||
}; | ||
|
||
useEffect(() => { | ||
window.addEventListener('scroll', toggleVisibility); | ||
return () => { | ||
window.removeEventListener('scroll', toggleVisibility); | ||
}; | ||
}, []); | ||
|
||
//show the button only when the user scrolls down | ||
if (isVisible) { | ||
return ( | ||
<div className="fixed bottom-4 right-3"> | ||
<button className='rounded-full bg-gray-300 hover:scale-125 drop-shadow-sm transition-all p-2 text-gray-500' onClick={goToTop}> | ||
<AiOutlineArrowUp className='text-1xl'/> | ||
</button> | ||
</div> | ||
); | ||
} | ||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
import React ,{ReactNode}from 'react' | ||
import Navbar from '../Navbar' | ||
|
||
import {GoToTopButton} from '../GoToTopButton'; | ||
interface LayoutProps { | ||
children: ReactNode | ||
} | ||
|
||
export default function Layout({children}:LayoutProps) { | ||
|
||
|
||
|
||
return ( | ||
<> | ||
<Navbar/> | ||
<main className="flex w-full min-h-screen px-5 md:px-20 font-montserrat py-20 pb-24 bg-gray-200"> | ||
{children} | ||
</main> | ||
<GoToTopButton/> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters