feat: implement auto scroll
This commit is contained in:
parent
a9993640ff
commit
b8d3ba85f5
6 changed files with 71 additions and 17 deletions
|
|
@ -3,26 +3,12 @@
|
|||
import * as React from 'react'
|
||||
|
||||
import { cn } from '@/lib/utils'
|
||||
import { useAtBottom } from '@/lib/hooks/use-at-bottom'
|
||||
import { Button, type ButtonProps } from '@/components/ui/button'
|
||||
import { IconArrowDown } from '@/components/ui/icons'
|
||||
|
||||
export function ButtonScrollToBottom({ className, ...props }: ButtonProps) {
|
||||
const [isAtBottom, setIsAtBottom] = React.useState(false)
|
||||
|
||||
React.useEffect(() => {
|
||||
const handleScroll = () => {
|
||||
setIsAtBottom(
|
||||
window.innerHeight + window.scrollY > document.body.offsetHeight - 100
|
||||
)
|
||||
}
|
||||
|
||||
window.addEventListener('scroll', handleScroll, { passive: true })
|
||||
handleScroll()
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('scroll', handleScroll)
|
||||
}
|
||||
}, [])
|
||||
const isAtBottom = useAtBottom()
|
||||
|
||||
return (
|
||||
<Button
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue