Streamline <PathLoaderButton />
This commit is contained in:
parent
25b7629a60
commit
0cfb9442c4
@ -1,39 +1,24 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
import { ReactNode, useEffect, useState, useTransition } from 'react';
|
import { ComponentProps, useEffect, useState, useTransition } from 'react';
|
||||||
import { SpinnerColor } from '../Spinner';
|
|
||||||
import LoaderButton from '@/components/primitives/LoaderButton';
|
import LoaderButton from '@/components/primitives/LoaderButton';
|
||||||
|
|
||||||
export default function PathLoaderButton({
|
export default function PathLoaderButton({
|
||||||
path,
|
path,
|
||||||
icon,
|
|
||||||
title,
|
|
||||||
prefetch,
|
prefetch,
|
||||||
loaderDelay = 100,
|
loaderDelay = 100,
|
||||||
shouldScroll = true,
|
shouldScroll = true,
|
||||||
shouldReplace,
|
shouldReplace,
|
||||||
spinnerColor,
|
|
||||||
shouldPreventDefault,
|
|
||||||
styleAs,
|
|
||||||
hideTextOnMobile,
|
|
||||||
className,
|
|
||||||
children,
|
children,
|
||||||
|
...props
|
||||||
}: {
|
}: {
|
||||||
path: string
|
path: string
|
||||||
icon?: ReactNode
|
|
||||||
title?: string
|
|
||||||
prefetch?: boolean
|
prefetch?: boolean
|
||||||
loaderDelay?: number
|
loaderDelay?: number
|
||||||
shouldScroll?: boolean
|
shouldScroll?: boolean
|
||||||
shouldReplace?: boolean
|
shouldReplace?: boolean
|
||||||
spinnerColor?: SpinnerColor
|
} & ComponentProps<typeof LoaderButton>) {
|
||||||
shouldPreventDefault?: boolean
|
|
||||||
styleAs?: 'button' | 'link' | 'link-without-hover'
|
|
||||||
hideTextOnMobile?: boolean
|
|
||||||
className?: string
|
|
||||||
children?: ReactNode
|
|
||||||
}) {
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const [isPending, startTransition] = useTransition();
|
const [isPending, startTransition] = useTransition();
|
||||||
@ -59,9 +44,7 @@ export default function PathLoaderButton({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<LoaderButton
|
<LoaderButton
|
||||||
icon={icon}
|
{...props}
|
||||||
title={title}
|
|
||||||
className={className}
|
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
startTransition(() => {
|
startTransition(() => {
|
||||||
if (shouldReplace) {
|
if (shouldReplace) {
|
||||||
@ -71,11 +54,7 @@ export default function PathLoaderButton({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
shouldPreventDefault={shouldPreventDefault}
|
|
||||||
isLoading={shouldShowLoader}
|
isLoading={shouldShowLoader}
|
||||||
spinnerColor={spinnerColor}
|
|
||||||
styleAs={styleAs}
|
|
||||||
hideTextOnMobile={hideTextOnMobile}
|
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</LoaderButton>
|
</LoaderButton>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user