forked from deriv-com/deriv-app
-
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.
Merge pull request #58 from likhith-deriv/likhith/76946/migrate-hooks…
…-folder-to-ts likhith/migrated hooks folder to ts
- Loading branch information
Showing
14 changed files
with
66 additions
and
54 deletions.
There are no files selected for viewing
File renamed without changes.
8 changes: 5 additions & 3 deletions
8
...s/components/src/hooks/use-blockscroll.js → ...s/components/src/hooks/use-blockscroll.ts
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
2 changes: 1 addition & 1 deletion
2
...s/components/src/hooks/use-constructor.js → ...s/components/src/hooks/use-constructor.ts
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
6 changes: 3 additions & 3 deletions
6
...ages/components/src/hooks/use-interval.js → ...ages/components/src/hooks/use-interval.ts
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 was deleted.
Oops, something went wrong.
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,29 @@ | ||
import React, { RefObject } from 'react'; | ||
|
||
export const useOnClickOutside = ( | ||
ref: RefObject<HTMLElement>, | ||
handler: (event: MouseEvent) => void, | ||
validationFn: (event: MouseEvent) => boolean | ||
) => { | ||
React.useEffect(() => { | ||
const listener = (event: MouseEvent) => { | ||
const path = event.composedPath?.()[0] ?? (event as MouseEvent & { path: HTMLElement }).path; //event.path is non-standard and will be deprecated | ||
// When component is isolated (e.g, iframe, shadow DOM) event.target refers to whole container not the component. path[0] is the node that the event originated from, it does not need to walk the array | ||
if ( | ||
ref && | ||
ref.current && | ||
!ref.current.contains(event.target as HTMLElement) && | ||
!ref.current.contains(path as HTMLElement) | ||
) { | ||
if (validationFn && !validationFn(event)) return; | ||
handler(event); | ||
} | ||
}; | ||
|
||
document.addEventListener('mousedown', listener); | ||
|
||
return () => { | ||
document.removeEventListener('mousedown', listener); | ||
}; | ||
}, [ref, handler, validationFn]); | ||
}; |
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
4 changes: 2 additions & 2 deletions
4
...ages/components/src/hooks/use-previous.js → ...ages/components/src/hooks/use-previous.ts
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
10 changes: 6 additions & 4 deletions
10
...es/components/src/hooks/use-safe-state.js → ...es/components/src/hooks/use-safe-state.ts
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
8 changes: 4 additions & 4 deletions
8
...omponents/src/hooks/use-state-callback.js → ...omponents/src/hooks/use-state-callback.ts
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