@@ -27,7 +27,7 @@ export interface NextTopLoaderProps {
2727 */
2828 crawlSpeed ?: number ;
2929 /**
30- * The height for the TopLoader.
30+ * The height for the TopLoader in pixels (px) .
3131 * @default 3
3232 */
3333 height ?: number ;
@@ -53,74 +53,75 @@ export interface NextTopLoaderProps {
5353 speed ?: number ;
5454}
5555
56- const NextTopLoader = ( props : NextTopLoaderProps ) => {
57- const color = '#29d' ;
58- const height = 3 ;
56+ const NextTopLoader = ( {
57+ color,
58+ height,
59+ showSpinner,
60+ crawl,
61+ crawlSpeed,
62+ initialPosition,
63+ easing,
64+ speed,
65+ } : NextTopLoaderProps ) => {
66+ const defaultColor = '#29d' ;
67+ const defaultHeight = 3 ;
5968
6069 const styles = (
6170 < style >
6271 { `#nprogress{pointer-events:none}#nprogress .bar{background:${
63- props . color ? props . color : color
72+ color ?? defaultColor
6473 } ;position:fixed;z-index:1031;top:0;left:0;width:100%;height:${
65- props . height ? props . height : height
74+ height ?? defaultHeight
6675 } px}#nprogress .peg{display:block;position:absolute;right:0;width:100px;height:100%;box-shadow:0 0 10px ${
67- props . color ? props . color : color
76+ color ?? defaultColor
6877 } ,0 0 5px ${
69- props . color ? props . color : color
78+ color ?? defaultColor
7079 } ;opacity:1;-webkit-transform:rotate(3deg) translate(0px,-4px);-ms-transform:rotate(3deg) translate(0px,-4px);transform:rotate(3deg) translate(0px,-4px)}#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:2px solid transparent;border-top-color:${
71- props . color ? props . color : color
80+ color ?? defaultColor
7281 } ;border-left-color:${
73- props . color ? props . color : color
82+ color ?? defaultColor
7483 } ;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 .bar,.nprogress-custom-parent #nprogress .spinner{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)}}`}
7584 </ style >
7685 ) ;
7786
7887 React . useEffect ( ( ) => {
79- if ( props . showSpinner !== undefined ) {
80- NProgress . configure ( { showSpinner : props . showSpinner } ) ;
81- }
82- if ( props . crawl !== undefined ) {
83- NProgress . configure ( { trickle : props . crawl } ) ;
84- }
85- if ( props . crawlSpeed !== undefined ) {
86- NProgress . configure ( { trickleSpeed : props . crawlSpeed } ) ;
87- }
88- if ( props . initialPosition !== undefined ) {
89- NProgress . configure ( { minimum : props . initialPosition } ) ;
90- }
91- if ( props . easing !== undefined ) {
92- NProgress . configure ( { easing : props . easing } ) ;
93- }
94- if ( props . speed !== undefined ) {
95- NProgress . configure ( { speed : props . speed } ) ;
88+ NProgress . configure ( {
89+ showSpinner : showSpinner ?? true ,
90+ trickle : crawl ?? true ,
91+ trickleSpeed : crawlSpeed ?? 200 ,
92+ minimum : initialPosition ?? 0.08 ,
93+ easing : easing ?? 'ease' ,
94+ speed : speed ?? 200 ,
95+ } ) ;
96+
97+ function isAnchorOfCurrentUrl ( currentUrl : string , newUrl : string ) {
98+ const currentUrlObj = new URL ( currentUrl ) ;
99+ const newUrlObj = new URL ( newUrl ) ;
100+ // Compare hostname, pathname, and search parameters
101+ if (
102+ currentUrlObj . hostname === newUrlObj . hostname &&
103+ currentUrlObj . pathname === newUrlObj . pathname &&
104+ currentUrlObj . search === newUrlObj . search
105+ ) {
106+ // Check if the new URL is just an anchor of the current URL page
107+ const currentHash = currentUrlObj . hash ;
108+ const newHash = newUrlObj . hash ;
109+ return (
110+ currentHash !== newHash && currentUrlObj . href . replace ( currentHash , '' ) === newUrlObj . href . replace ( newHash , '' )
111+ ) ;
112+ }
113+ return false ;
96114 }
115+
97116 // eslint-disable-next-line no-var
98117 var npgclass = document . querySelectorAll ( 'html' ) ;
99118 let navLinks = document . querySelectorAll ( 'a' ) ;
100119 navLinks . forEach ( ( navLink ) => {
101120 navLink . addEventListener ( 'click' , ( event : MouseEvent ) => {
102121 let currentUrl = window . location . href ;
103122 let newUrl = ( event . currentTarget as HTMLAnchorElement ) . href ;
104- let isExternalLink = ( event . currentTarget as HTMLAnchorElement ) . target === "_blank" ;
105- function isAnchorOfCurrentUrl ( currentUrl : string , newUrl : string ) {
106- const currentUrlObj = new URL ( currentUrl ) ;
107- const newUrlObj = new URL ( newUrl ) ;
108- // Compare hostname, pathname, and search parameters
109- if (
110- currentUrlObj . hostname === newUrlObj . hostname &&
111- currentUrlObj . pathname === newUrlObj . pathname &&
112- currentUrlObj . search === newUrlObj . search
113- ) {
114- // Check if the new URL is just an anchor of the current URL page
115- const currentHash = currentUrlObj . hash ;
116- const newHash = newUrlObj . hash ;
117- return (
118- currentHash !== newHash &&
119- currentUrlObj . href . replace ( currentHash , '' ) === newUrlObj . href . replace ( newHash , '' )
120- ) ;
121- }
122- return false ;
123- }
123+ const isExternalLink = ( event . currentTarget as HTMLAnchorElement ) . target === '_blank' ;
124+
124125 const isAnchor = isAnchorOfCurrentUrl ( currentUrl , newUrl ) ;
125126 if ( newUrl === currentUrl || isAnchor || isExternalLink ) {
126127 NProgress . start ( ) ;
0 commit comments