From 443d5c2007465631d733041e1f1082f38bddd5e0 Mon Sep 17 00:00:00 2001 From: Bill Date: Tue, 11 May 2021 18:11:22 -0400 Subject: [PATCH] Update draggable window --- src/hooks/draggable-window/DraggableWindow.tsx | 15 +++++++++------ .../draggable-window/DraggableWindow.types.tsx | 1 + 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/hooks/draggable-window/DraggableWindow.tsx b/src/hooks/draggable-window/DraggableWindow.tsx index 6f4878f0..b4ab9b8f 100644 --- a/src/hooks/draggable-window/DraggableWindow.tsx +++ b/src/hooks/draggable-window/DraggableWindow.tsx @@ -6,7 +6,7 @@ const currentWindows: HTMLDivElement[] = []; export const DraggableWindow: FC = props => { - const { disableDrag = false } = props; + const { disableDrag = false, noCenter = false } = props; const elementRef = useRef(); @@ -53,11 +53,14 @@ export const DraggableWindow: FC = props => bringToTop(); - const left = ((element.parentElement.clientWidth - element.clientWidth) / 2); - const top = ((element.parentElement.clientHeight - element.clientHeight) / 2); + if(!noCenter) + { + const left = ((document.body.clientWidth / 2) - (element.clientWidth / 2)); + const top = ((document.body.clientHeight / 2) - (element.clientHeight / 2)); - element.style.left = `${ left }px`; - element.style.top = `${ top }px`; + element.style.left = `${ left }px`; + element.style.top = `${ top }px`; + } return () => { @@ -65,7 +68,7 @@ export const DraggableWindow: FC = props => if(index >= 0) currentWindows.splice(index, 1); } - }, [ elementRef ]); + }, [ elementRef, noCenter ]); function getWindowContent(): JSX.Element { diff --git a/src/hooks/draggable-window/DraggableWindow.types.tsx b/src/hooks/draggable-window/DraggableWindow.types.tsx index 0bcccf9b..d74ff113 100644 --- a/src/hooks/draggable-window/DraggableWindow.types.tsx +++ b/src/hooks/draggable-window/DraggableWindow.types.tsx @@ -6,5 +6,6 @@ export interface DraggableWindowProps handle: string; draggableOptions?: Partial; disableDrag?: boolean; + noCenter?: boolean; children?: ReactNode; }