Improve scroll anchor (#275)
This commit is contained in:
parent
b6cab643ef
commit
43c7cbb21e
12 changed files with 169 additions and 101 deletions
|
|
@ -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 />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue