Jon/windowing updates (#2955)
This commit is contained in:
@@ -21,6 +21,11 @@ import { cn } from "@/util/utils";
|
|||||||
|
|
||||||
type OS = "Windows" | "macOS" | "Linux" | "Unknown";
|
type OS = "Windows" | "macOS" | "Linux" | "Unknown";
|
||||||
|
|
||||||
|
const Constants = {
|
||||||
|
MinHeight: 52,
|
||||||
|
MinWidth: 256,
|
||||||
|
} as const;
|
||||||
|
|
||||||
function MacOsButton(props: {
|
function MacOsButton(props: {
|
||||||
color: string;
|
color: string;
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
@@ -93,29 +98,40 @@ function getOs(): OS {
|
|||||||
|
|
||||||
function FloatingWindow({
|
function FloatingWindow({
|
||||||
children,
|
children,
|
||||||
|
initialWidth,
|
||||||
|
initialHeight,
|
||||||
title,
|
title,
|
||||||
|
zIndex,
|
||||||
|
// --
|
||||||
|
onInteract,
|
||||||
}: {
|
}: {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
|
initialHeight?: number;
|
||||||
|
initialWidth?: number;
|
||||||
title: string;
|
title: string;
|
||||||
|
zIndex?: string;
|
||||||
|
// --
|
||||||
|
onInteract?: () => void;
|
||||||
}) {
|
}) {
|
||||||
|
console.log(title, initialWidth, initialHeight);
|
||||||
const [position, setPosition] = useState({ x: 0, y: 0 });
|
const [position, setPosition] = useState({ x: 0, y: 0 });
|
||||||
const [size, setSize] = useState({
|
const [size, setSize] = useState({
|
||||||
left: 0,
|
left: 0,
|
||||||
top: 0,
|
top: 0,
|
||||||
width: 800,
|
height: initialHeight ?? Constants.MinHeight,
|
||||||
height: 680,
|
width: initialWidth ?? Constants.MinWidth,
|
||||||
});
|
});
|
||||||
const [lastSize, setLastSize] = useState({
|
const [lastSize, setLastSize] = useState({
|
||||||
left: 0,
|
left: 0,
|
||||||
top: 0,
|
top: 0,
|
||||||
width: 800,
|
height: initialHeight ?? Constants.MinHeight,
|
||||||
height: 680,
|
width: initialWidth ?? Constants.MinWidth,
|
||||||
});
|
});
|
||||||
const [sizeBeforeMaximize, setSizeBeforeMaximize] = useState({
|
const [sizeBeforeMaximize, setSizeBeforeMaximize] = useState({
|
||||||
left: 0,
|
left: 0,
|
||||||
top: 0,
|
top: 0,
|
||||||
width: 800,
|
height: initialHeight ?? Constants.MinHeight,
|
||||||
height: 680,
|
width: initialWidth ?? Constants.MinWidth,
|
||||||
});
|
});
|
||||||
const [isMaximized, setIsMaximized] = useState(false);
|
const [isMaximized, setIsMaximized] = useState(false);
|
||||||
const [isMinimized, setIsMinimized] = useState(false);
|
const [isMinimized, setIsMinimized] = useState(false);
|
||||||
@@ -198,6 +214,19 @@ function FloatingWindow({
|
|||||||
[dragStartSize],
|
[dragStartSize],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!initialWidth || !initialHeight) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setSize({
|
||||||
|
left: 0,
|
||||||
|
top: 0,
|
||||||
|
width: initialWidth,
|
||||||
|
height: initialHeight,
|
||||||
|
});
|
||||||
|
setPosition({ x: 0, y: 0 });
|
||||||
|
}, [initialWidth, initialHeight]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forces the sizing to take place after the resize is complete.
|
* Forces the sizing to take place after the resize is complete.
|
||||||
*
|
*
|
||||||
@@ -346,6 +375,7 @@ function FloatingWindow({
|
|||||||
height: "100%",
|
height: "100%",
|
||||||
pointerEvents: "none",
|
pointerEvents: "none",
|
||||||
padding: "0.5rem",
|
padding: "0.5rem",
|
||||||
|
zIndex,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Draggable
|
<Draggable
|
||||||
@@ -365,11 +395,15 @@ function FloatingWindow({
|
|||||||
background: "#020817",
|
background: "#020817",
|
||||||
boxSizing: "border-box",
|
boxSizing: "border-box",
|
||||||
pointerEvents: "auto",
|
pointerEvents: "auto",
|
||||||
|
overflow: "hidden",
|
||||||
}}
|
}}
|
||||||
className={cn("border-8 border-gray-900", {
|
className={cn("border-2 border-gray-700", {
|
||||||
"hover:border-slate-500": !isMaximized,
|
"hover:border-slate-500": !isMaximized,
|
||||||
})}
|
})}
|
||||||
bounds={parentRef.current ?? "parent"}
|
minHeight={Constants.MinHeight}
|
||||||
|
minWidth={Constants.MinWidth}
|
||||||
|
// TODO: turn back on; turning off clears a resize bug atm
|
||||||
|
// bounds={parentRef.current ?? "parent"}
|
||||||
enable={
|
enable={
|
||||||
isMaximized
|
isMaximized
|
||||||
? false
|
? false
|
||||||
@@ -421,11 +455,12 @@ function FloatingWindow({
|
|||||||
display: "flex",
|
display: "flex",
|
||||||
flexDirection: "column",
|
flexDirection: "column",
|
||||||
}}
|
}}
|
||||||
|
onMouseDownCapture={() => onInteract?.()}
|
||||||
onDoubleClick={() => {
|
onDoubleClick={() => {
|
||||||
toggleMaximized();
|
toggleMaximized();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div className="my-window-header flex w-full cursor-move items-center justify-start gap-2 bg-[#031827] p-3">
|
<div className="my-window-header flex h-[3rem] w-full cursor-move items-center justify-start gap-2 bg-[#031827] p-3">
|
||||||
{os === "macOS" ? (
|
{os === "macOS" ? (
|
||||||
<>
|
<>
|
||||||
<div className="buttons-container flex items-center gap-2">
|
<div className="buttons-container flex items-center gap-2">
|
||||||
|
|||||||
Reference in New Issue
Block a user