-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: separating dependencies (#105)
Remove dependencies on useWindowSize, useScrollPosition, and useClipboard.
- Loading branch information
Showing
10 changed files
with
51 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@raddix/use-clipboard': minor | ||
--- | ||
|
||
Remove @raddix/use-timeout of peerDependecies |
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,6 @@ | ||
--- | ||
'@raddix/use-scroll-position': minor | ||
'@raddix/use-window-size': minor | ||
--- | ||
|
||
Remove @raddix/use-event-listener of peerDependencies |
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
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,39 +1,35 @@ | ||
import { type RefObject, useEffect, useState } from 'react'; | ||
import { useEventListener } from '@raddix/use-event-listener'; | ||
|
||
export interface ScrollPosition { | ||
x: number | null; | ||
y: number | null; | ||
} | ||
|
||
export interface Options<E extends HTMLElement> { | ||
target?: RefObject<E> | Document; | ||
interface Options { | ||
target?: RefObject<HTMLElement>; | ||
} | ||
|
||
export const useScrollPosition = <E extends HTMLElement = HTMLDivElement>({ | ||
target = globalThis.document | ||
}: Options<E> = {}): ScrollPosition => { | ||
export const useScrollPosition = ({ target }: Options = {}): ScrollPosition => { | ||
const [scrollPosition, setScrollPosition] = useState<ScrollPosition>({ | ||
x: 0, | ||
y: 0 | ||
}); | ||
|
||
const handle = () => { | ||
const targetElement = | ||
target instanceof Document ? document.documentElement : target.current; | ||
|
||
setScrollPosition({ | ||
x: targetElement?.scrollLeft ?? null, | ||
y: targetElement?.scrollTop ?? null | ||
}); | ||
}; | ||
|
||
useEffect(() => { | ||
const element = target ? target.current : window; | ||
|
||
const handle = () => { | ||
setScrollPosition({ | ||
x: (target ? target.current?.scrollLeft : window.scrollX) ?? null, | ||
y: (target ? target.current?.scrollTop : window.scrollY) ?? null | ||
}); | ||
}; | ||
handle(); | ||
|
||
element?.addEventListener('scroll', handle, { passive: true }); | ||
return () => element?.removeEventListener('scroll', handle); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
useEventListener('scroll', handle, { target, passive: true }); | ||
|
||
return scrollPosition; | ||
}; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.