Add table and menu components

This commit is contained in:
2023-10-24 11:37:29 +07:00
parent 52c3e28fbc
commit 9918c7c3a4
10 changed files with 305 additions and 0 deletions
@@ -0,0 +1,23 @@
import { useEffect, useRef } from 'react';
export const useOutsideClick = (
handler: () => void,
listeningCapturing = true,
): React.MutableRefObject<HTMLUListElement | null> => {
const ref = useRef<HTMLUListElement>(null);
useEffect(() => {
const handleClick = (e: Event) => {
if (ref.current && !ref.current.contains(e.target as Node)) {
handler();
}
};
document.addEventListener('click', handleClick, listeningCapturing);
return () =>
document.removeEventListener('click', handleClick, listeningCapturing);
}, [handler, listeningCapturing]);
return ref;
};