Improve scroll anchor (#275)

This commit is contained in:
Jeremy 2024-03-20 04:37:08 +03:00 committed by GitHub
parent b6cab643ef
commit 43c7cbb21e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 169 additions and 101 deletions

View file

@ -3,13 +3,20 @@
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 = useAtBottom()
interface ButtonScrollToBottomProps extends ButtonProps {
isAtBottom: boolean
scrollToBottom: () => void
}
export function ButtonScrollToBottom({
className,
isAtBottom,
scrollToBottom,
...props
}: ButtonScrollToBottomProps) {
return (
<Button
variant="outline"
@ -19,12 +26,7 @@ export function ButtonScrollToBottom({ className, ...props }: ButtonProps) {
isAtBottom ? 'opacity-0' : 'opacity-100',
className
)}
onClick={() =>
window.scrollTo({
top: document.body.offsetHeight,
behavior: 'smooth'
})
}
onClick={() => scrollToBottom()}
{...props}
>
<IconArrowDown />