mirror of
https://github.com/billsonnn/nitro-react.git
synced 2024-11-26 23:50:52 +01:00
Update draggable window
This commit is contained in:
parent
0e07a6d500
commit
443d5c2007
@ -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
|
||||||
{
|
{
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user