1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 04:46:40 +07:00

added flow display controls overlay

This commit is contained in:
Fedor Katurov 2021-10-13 16:14:37 +07:00
parent c8204a41a2
commit 5fef4bc804
14 changed files with 327 additions and 116 deletions

View file

@ -9,7 +9,7 @@ export const useFlowCellControls = (
) => {
const onChange = useCallback(
(value: Partial<FlowDisplay>) => onChangeCellView(id, { ...flow, ...value }),
[]
[flow, onChangeCellView]
);
const hasDescription = !!description && description.length > 32;
@ -17,23 +17,23 @@ export const useFlowCellControls = (
const toggleViewDescription = useCallback(() => {
const show_description = !(flow && flow.show_description);
onChange({ show_description });
}, [id, flow, onChange]);
}, [flow, onChange]);
const setViewSingle = useCallback(() => {
onChange({ display: 'single' });
}, [id, flow, onChange]);
}, [onChange]);
const setViewHorizontal = useCallback(() => {
onChange({ display: 'horizontal' });
}, [id, flow, onChange]);
}, [onChange]);
const setViewVertical = useCallback(() => {
onChange({ display: 'vertical' });
}, [id, flow]);
}, [onChange]);
const setViewQuadro = useCallback(() => {
onChange({ display: 'quadro' });
}, [id, flow, onChange]);
}, [onChange]);
return {
hasDescription,

View file

@ -0,0 +1,30 @@
/**
* Handles blur by detecting clicks outside refs.
*/
import { useCallback, useEffect, useRef, useState } from 'react';
export const useClickOutsideFocus = () => {
const ref = useRef<HTMLElement>();
const [isActive, setIsActive] = useState(false);
const activate = useCallback(() => setIsActive(true), [setIsActive]);
const deactivate = useCallback(() => setIsActive(false), [setIsActive]);
useEffect(() => {
if (!isActive || !ref.current) {
return;
}
const deactivator = (event: MouseEvent) => {
if (!ref.current?.contains(event.target as Node)) {
deactivate();
}
};
document.addEventListener('mouseup', deactivator);
return () => document.removeEventListener('mouseup', deactivator);
}, [isActive]);
return { ref, isActive, activate, deactivate };
};