Update draggable window

This commit is contained in:
Bill 2021-05-11 18:11:22 -04:00
parent 0e07a6d500
commit 443d5c2007
2 changed files with 10 additions and 6 deletions

View File

@ -6,7 +6,7 @@ const currentWindows: HTMLDivElement[] = [];
export const DraggableWindow: FC<DraggableWindowProps> = props => export const DraggableWindow: FC<DraggableWindowProps> = props =>
{ {
const { disableDrag = false } = props; const { disableDrag = false, noCenter = false } = props;
const elementRef = useRef<HTMLDivElement>(); const elementRef = useRef<HTMLDivElement>();
@ -53,11 +53,14 @@ export const DraggableWindow: FC<DraggableWindowProps> = props =>
bringToTop(); bringToTop();
const left = ((element.parentElement.clientWidth - element.clientWidth) / 2); if(!noCenter)
const top = ((element.parentElement.clientHeight - element.clientHeight) / 2); {
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.left = `${ left }px`;
element.style.top = `${ top }px`; element.style.top = `${ top }px`;
}
return () => return () =>
{ {
@ -65,7 +68,7 @@ export const DraggableWindow: FC<DraggableWindowProps> = props =>
if(index >= 0) currentWindows.splice(index, 1); if(index >= 0) currentWindows.splice(index, 1);
} }
}, [ elementRef ]); }, [ elementRef, noCenter ]);
function getWindowContent(): JSX.Element function getWindowContent(): JSX.Element
{ {

View File

@ -6,5 +6,6 @@ export interface DraggableWindowProps
handle: string; handle: string;
draggableOptions?: Partial<DraggableProps>; draggableOptions?: Partial<DraggableProps>;
disableDrag?: boolean; disableDrag?: boolean;
noCenter?: boolean;
children?: ReactNode; children?: ReactNode;
} }