-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathButtonLink.tsx
35 lines (30 loc) · 1003 Bytes
/
ButtonLink.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { forwardRef } from 'react'
import { ButtonLink as StatelessButtonLink } from '@dao-dao/stateless'
import { StatefulButtonLinkProps } from '@dao-dao/types'
import { useUpdateNavigatingHref } from '../hooks/useUpdateNavigatingHref'
export const ButtonLink = forwardRef<HTMLDivElement, StatefulButtonLinkProps>(
function ButtonLink(
{ children, loading, onClick, href, forceNoNavigating = false, ...props },
ref
) {
const { navigatingToHref, updateNavigatingHref } = useUpdateNavigatingHref()
const navigating = !!href && navigatingToHref === href && !forceNoNavigating
return (
<StatelessButtonLink
{...props}
href={href}
loading={loading || navigating}
onClick={(event) => {
onClick?.(event)
// Update global loading state.
if (!props.openInNewTab) {
updateNavigatingHref(href)
}
}}
ref={ref}
>
{children}
</StatelessButtonLink>
)
}
)