init create-fias

This commit is contained in:
Samandar Turgunboyev
2025-12-20 09:26:40 +05:00
commit fd397b670b
60 changed files with 6817 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
import React, { useEffect } from 'react';
/**
* Hook for closing some items when they are unnecessary to the user
* @param ref For an item that needs to be closed when the outer part is pressed
* @param closeFunction Closing function
* @param scrollClose If it shouldn't close when scrolling, false will be sent. Default true
*/
const useCloser = (
ref: React.RefObject<HTMLElement>,
closeFunction: () => void,
scrollClose: boolean = true,
) => {
useEffect(() => {
// call function when click outside is ref element
function handleClickOutside(event: MouseEvent) {
if (ref.current && !ref.current.contains(event.target as Node)) {
closeFunction();
}
}
// call function when page is scrolling
function handleScroll() {
if (scrollClose) {
closeFunction();
}
}
document.addEventListener('mousedown', handleClickOutside);
document.addEventListener('scroll', handleScroll);
return () => {
document.removeEventListener('mousedown', handleClickOutside);
document.removeEventListener('scroll', handleScroll);
};
}, [ref, closeFunction]);
};
export default useCloser;