-
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.
- Loading branch information
Showing
7 changed files
with
68 additions
and
5 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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,47 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
|
||
export default function ScrollButton({ type }) { | ||
const [isVisible, setIsVisible] = useState(true); | ||
|
||
const updateButtonVisibility = () => { | ||
const parentElement = document.getElementById('slider'); | ||
const { scrollLeft, scrollWidth, clientWidth } = parentElement; | ||
|
||
console.log(scrollLeft, scrollWidth, clientWidth, type) | ||
|
||
if (type === 'right') { | ||
setIsVisible(scrollLeft < scrollWidth - clientWidth); | ||
} | ||
|
||
else { | ||
setIsVisible(scrollLeft > 0) | ||
} | ||
}; | ||
|
||
|
||
useEffect(() => { | ||
const parentElement = document.getElementById('slider'); | ||
parentElement.addEventListener('scroll', updateButtonVisibility); | ||
updateButtonVisibility(); | ||
return () => { | ||
parentElement.removeEventListener('scroll', updateButtonVisibility); | ||
}; | ||
}, [type]); | ||
|
||
const handleClick = () => { | ||
const parentElement = document.getElementById('slider'); | ||
const scrollAmount = type === 'right' ? 200 : -200; | ||
parentElement.scrollBy({ left: scrollAmount, behavior: 'smooth' }); | ||
}; | ||
|
||
const style = type === 'right' ? 'right-0' : 'left-0'; | ||
|
||
return ( | ||
<button | ||
onClick={handleClick} | ||
className={`lg:hidden bg-[hsl(215,21%,11%)] z-[1] absolute top-[1.2rem] w-5 ${style} ${!isVisible && 'hidden'}`} | ||
> | ||
<img src={require(type === 'right' ? '../../../assets/right.png' : '../../../assets/left.png')} /> | ||
</button> | ||
); | ||
} |
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
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
a8f5abe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
argendata-front – ./
www.argendata.net
argendata-front-git-main-pmemoli.vercel.app
argendata-front.vercel.app
argendata-front-pmemoli.vercel.app
argendata.net