-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
breaking: moved to v1.0.0 + new features to ease setup
- Loading branch information
Showing
10 changed files
with
283 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import React from 'react'; | ||
|
||
const ButtonLink = () => { | ||
return <div>ButtonLink</div>; | ||
}; | ||
|
||
export default ButtonLink; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
'use client'; | ||
import React from 'react'; | ||
import { NProvider } from 'next13-progressbar'; | ||
|
||
import { Next13ProgressBar } from '../../../dist'; | ||
|
||
const Providers = ({ children }: { children: React.ReactNode }) => { | ||
return <NProvider color="#fff">{children}</NProvider>; | ||
return ( | ||
<> | ||
{children} | ||
<Next13ProgressBar height="4px" color="#0A2FFF" options={{ showSpinner: true }} showOnShallow /> | ||
</> | ||
); | ||
}; | ||
|
||
export default Providers; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
import React, { useEffect } from 'react'; | ||
import NProgress from 'nprogress'; | ||
import { usePathname, useSearchParams, useRouter as useNextRouter } from 'next/navigation'; | ||
import { NavigateOptions } from 'next/dist/shared/lib/app-router-context'; | ||
import { Next13ProgressProps } from '.'; | ||
|
||
type PushStateInput = [data: any, unused: string, url?: string | URL | null | undefined]; | ||
|
||
export const Next13ProgressBar = React.memo( | ||
({ color = '#0A2FFF', height = '2px', options, showOnShallow = false, delay = 0, style }: Next13ProgressProps) => { | ||
const styles = ( | ||
<style> | ||
{style || | ||
` | ||
#nprogress { | ||
pointer-events: none; | ||
} | ||
#nprogress .bar { | ||
background: ${color}; | ||
position: fixed; | ||
z-index: 1031; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: ${height}; | ||
} | ||
/* Fancy blur effect */ | ||
#nprogress .peg { | ||
display: block; | ||
position: absolute; | ||
right: 0px; | ||
width: 100px; | ||
height: 100%; | ||
box-shadow: 0 0 10px ${color}, 0 0 5px ${color}; | ||
opacity: 1.0; | ||
-webkit-transform: rotate(3deg) translate(0px, -4px); | ||
-ms-transform: rotate(3deg) translate(0px, -4px); | ||
transform: rotate(3deg) translate(0px, -4px); | ||
} | ||
/* Remove these to get rid of the spinner */ | ||
#nprogress .spinner { | ||
display: block; | ||
position: fixed; | ||
z-index: 1031; | ||
top: 15px; | ||
right: 15px; | ||
} | ||
#nprogress .spinner-icon { | ||
width: 18px; | ||
height: 18px; | ||
box-sizing: border-box; | ||
border: solid 2px transparent; | ||
border-top-color: ${color}; | ||
border-left-color: ${color}; | ||
border-radius: 50%; | ||
-webkit-animation: nprogress-spinner 400ms linear infinite; | ||
animation: nprogress-spinner 400ms linear infinite; | ||
} | ||
.nprogress-custom-parent { | ||
overflow: hidden; | ||
position: relative; | ||
} | ||
.nprogress-custom-parent #nprogress .spinner, | ||
.nprogress-custom-parent #nprogress .bar { | ||
position: absolute; | ||
} | ||
@-webkit-keyframes nprogress-spinner { | ||
0% { -webkit-transform: rotate(0deg); } | ||
100% { -webkit-transform: rotate(360deg); } | ||
} | ||
@keyframes nprogress-spinner { | ||
0% { transform: rotate(0deg); } | ||
100% { transform: rotate(360deg); } | ||
} | ||
`} | ||
</style> | ||
); | ||
|
||
NProgress.configure(options || {}); | ||
|
||
const pathname = usePathname(); | ||
const searchParams = useSearchParams(); | ||
|
||
useEffect(() => { | ||
NProgress.done(); | ||
}, [pathname, searchParams]); | ||
|
||
useEffect(() => { | ||
let timer: NodeJS.Timeout; | ||
|
||
const startProgress = () => { | ||
timer = setTimeout(NProgress.start, delay); | ||
}; | ||
|
||
const stopProgress = () => { | ||
clearTimeout(timer); | ||
NProgress.done(); | ||
}; | ||
|
||
const handleAnchorClick = (event: MouseEvent) => { | ||
const anchorElement = event.currentTarget as HTMLAnchorElement; | ||
|
||
// Skip anchors with target="_blank" | ||
if (anchorElement.target === '_blank') return; | ||
|
||
const targetUrl = new URL(anchorElement.href); | ||
const currentUrl = new URL(location.href); | ||
|
||
if (showOnShallow && targetUrl?.href === currentUrl?.href) return; | ||
if (targetUrl?.href === currentUrl?.href) return; | ||
|
||
startProgress(); | ||
}; | ||
|
||
const handleMutation: MutationCallback = () => { | ||
const anchorElements = document.querySelectorAll('a'); | ||
// Skip anchors with target="_blank" and anchors without href | ||
const validAnchorELes = Array.from(anchorElements).filter((anchor) => anchor.href); | ||
validAnchorELes.forEach((anchor) => anchor.addEventListener('click', handleAnchorClick)); | ||
}; | ||
|
||
const mutationObserver = new MutationObserver(handleMutation); | ||
mutationObserver.observe(document, { childList: true, subtree: true }); | ||
|
||
window.history.pushState = new Proxy(window.history.pushState, { | ||
apply: (target, thisArg, argArray: PushStateInput) => { | ||
stopProgress(); | ||
return target.apply(thisArg, argArray); | ||
}, | ||
}); | ||
}, []); | ||
|
||
return styles; | ||
}, | ||
() => true | ||
); | ||
|
||
export function useRouter() { | ||
const router = useNextRouter(); | ||
|
||
function push(href: string, options?: NavigateOptions) { | ||
NProgress.start(); | ||
return router.push(href, options); | ||
} | ||
|
||
return { ...router, push }; | ||
} |
Oops, something went wrong.