5bfe2a0331
* feat: add file manager module - Complete file manager implementation with UI/UX - Add drive management functionality - Add file upload/download with progress tracking - Add stamp integration and handling - Add bulk operations and context menus Co-authored-by: Roland Seres <roland.seres90@gmail.com> Co-authored-by: nidishk <nidishkrishnan45@gmail.com>
17 lines
541 B
TypeScript
17 lines
541 B
TypeScript
import { useEffect } from 'react'
|
|
|
|
export function useClickOutside<T extends Element>(ref: React.RefObject<T>, onClickOutside: () => void, active = true) {
|
|
useEffect(() => {
|
|
if (!active) return
|
|
|
|
function handleDocumentClick(e: MouseEvent) {
|
|
if (ref.current && !ref.current.contains(e.target as Node)) {
|
|
onClickOutside()
|
|
}
|
|
}
|
|
document.addEventListener('mousedown', handleDocumentClick)
|
|
|
|
return () => document.removeEventListener('mousedown', handleDocumentClick)
|
|
}, [ref, onClickOutside, active])
|
|
}
|