mirror of
https://github.com/plankanban/planka.git
synced 2025-07-22 22:59:44 +02:00
30 lines
656 B
JavaScript
30 lines
656 B
JavaScript
|
import { useCallback, useEffect, useRef } from 'react';
|
||
|
|
||
|
export default (isOpened, close) => {
|
||
|
const isClosable = useRef(null);
|
||
|
|
||
|
const handleFieldBlur = useCallback(() => {
|
||
|
if (isClosable.current) {
|
||
|
close();
|
||
|
}
|
||
|
}, [close]);
|
||
|
|
||
|
const handleControlMouseOver = useCallback(() => {
|
||
|
isClosable.current = false;
|
||
|
}, []);
|
||
|
|
||
|
const handleControlMouseOut = useCallback(() => {
|
||
|
isClosable.current = true;
|
||
|
}, []);
|
||
|
|
||
|
useEffect(() => {
|
||
|
if (isOpened) {
|
||
|
isClosable.current = true;
|
||
|
} else {
|
||
|
isClosable.current = null;
|
||
|
}
|
||
|
}, [isOpened]);
|
||
|
|
||
|
return [handleFieldBlur, handleControlMouseOver, handleControlMouseOut];
|
||
|
};
|