oihana-next-ui 0.1.41 → 0.1.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/hooks/useResetScroll.js +18 -23
- package/src/version.js +1 -1
package/package.json
CHANGED
|
@@ -1,28 +1,21 @@
|
|
|
1
|
-
import { useEffect }
|
|
2
|
-
|
|
1
|
+
import { useEffect } from 'react' ;
|
|
3
2
|
import { usePathname } from 'next/navigation' ;
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* @param {React.RefObject<HTMLElement>} [ref] - Optional element reference. Defaults to window.
|
|
9
|
-
* @param {boolean} [disabled=false] - Whether to disable the scroll reset.
|
|
10
|
-
* @param {ScrollBehavior} [behavior='instant'] - Scroll behavior: 'instant' or 'smooth'.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```js
|
|
14
|
-
* // Reset window scroll on route change
|
|
15
|
-
* useResetScroll() ;
|
|
16
|
-
*
|
|
17
|
-
* // Reset a specific container
|
|
18
|
-
* const containerRef = useRef( null ) ;
|
|
19
|
-
* useResetScroll( containerRef ) ;
|
|
5
|
+
* Resets scroll position when the route (pathname) changes.
|
|
20
6
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
7
|
+
* @param {React.RefObject} [ref] - Optional scroll container ref.
|
|
8
|
+
* @param {boolean} [disabled=false]
|
|
9
|
+
* @param {string} [scrollClassName='drawer-content'] - CSS class of the fallback scroll container.
|
|
10
|
+
* @param {ScrollBehavior} [behavior='smooth'] - Scroll behavior.
|
|
24
11
|
*/
|
|
25
|
-
const useResetScroll =
|
|
12
|
+
const useResetScroll =
|
|
13
|
+
(
|
|
14
|
+
ref ,
|
|
15
|
+
disabled = false ,
|
|
16
|
+
scrollClassName = 'drawer-content' ,
|
|
17
|
+
behavior = 'smooth'
|
|
18
|
+
) =>
|
|
26
19
|
{
|
|
27
20
|
const pathname = usePathname() ;
|
|
28
21
|
|
|
@@ -33,11 +26,13 @@ const useResetScroll = ( ref , disabled = false , behavior = 'instant' ) =>
|
|
|
33
26
|
return ;
|
|
34
27
|
}
|
|
35
28
|
|
|
36
|
-
const element = ref?.current
|
|
29
|
+
const element = ref?.current
|
|
30
|
+
?? document.querySelector( `.${ scrollClassName }` )
|
|
31
|
+
?? window ;
|
|
37
32
|
|
|
38
|
-
element.scrollTo( { top
|
|
33
|
+
element.scrollTo( { top : 0 , behavior } ) ;
|
|
39
34
|
}
|
|
40
|
-
, [
|
|
35
|
+
, [ behavior , disabled , pathname , ref , scrollClassName ] ) ;
|
|
41
36
|
} ;
|
|
42
37
|
|
|
43
38
|
export default useResetScroll ;
|
package/src/version.js
CHANGED