Download apps/vscode/webview-ui/src/components/inputarea/hooks/useClickOutside.ts from SaylorTwift/kimi-code: direct link, hf CLI and curl.
- Browser
- Download file 647 Bytes
-
https://huggingface.co/SaylorTwift/kimi-code/resolve/main/apps/vscode/webview-ui/src/components/inputarea/hooks/useClickOutside.ts
- Command line
-
hf download hf://SaylorTwift/kimi-code/apps/vscode/webview-ui/src/components/inputarea/hooks/useClickOutside.ts
-
curl -L -o useClickOutside.ts https://huggingface.co/SaylorTwift/kimi-code/resolve/main/apps/vscode/webview-ui/src/components/inputarea/hooks/useClickOutside.ts
647 Bytes
| import { useEffect, RefObject } from "react"; | |
| export function useClickOutside(refs: RefObject<HTMLElement | null>[], isActive: boolean, onClickOutside: () => void): void { | |
| useEffect(() => { | |
| if (!isActive) { | |
| return; | |
| } | |
| const handleClick = (e: MouseEvent) => { | |
| const target = e.target as Node; | |
| const isOutside = refs.every((ref) => ref.current && !ref.current.contains(target)); | |
| if (isOutside) { | |
| onClickOutside(); | |
| } | |
| }; | |
| document.addEventListener("mousedown", handleClick); | |
| return () => document.removeEventListener("mousedown", handleClick); | |
| }, [refs, isActive, onClickOutside]); | |
| } | |