Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,10 @@ export const locations = {

const INITIAL_Z_INDEX = 1000;

// Minimum window dimensions for resizing
const MIN_WINDOW_WIDTH = 300;
const MIN_WINDOW_HEIGHT = 200;

const WINDOW_CONFIG = {
finder: { isOpen: false, zIndex: INITIAL_Z_INDEX, data: null, isMinimized: false, width: null, height: null },
contact: { isOpen: false, zIndex: INITIAL_Z_INDEX, data: null, isMinimized: false, width: null, height: null },
Expand All @@ -503,4 +507,4 @@ const WINDOW_CONFIG = {
imgfile: { isOpen: false, zIndex: INITIAL_Z_INDEX, data: null, isMinimized: false, width: null, height: null },
};

export { INITIAL_Z_INDEX, WINDOW_CONFIG };
export { INITIAL_Z_INDEX, WINDOW_CONFIG, MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT };
25 changes: 18 additions & 7 deletions src/hoc/WindowWrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useGSAP } from "@gsap/react";
import { useLayoutEffect, useRef, useState } from "react"
import gsap from "gsap";
import { Draggable } from "gsap/Draggable";
import { MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT } from "#constants";

/**
* Higher-order component that wraps a window-like component with
Expand Down Expand Up @@ -79,20 +80,20 @@ const WindowWrapper = (Component, windowKey) => {
let newTop = startTop;

if (edge.includes('right')) {
newWidth = Math.max(300, startWidth + (e.clientX - startX));
newWidth = Math.max(MIN_WINDOW_WIDTH, startWidth + (e.clientX - startX));
}
if (edge.includes('left')) {
const delta = e.clientX - startX;
newWidth = Math.max(300, startWidth - delta);
if (newWidth > 300) newLeft = startLeft + delta;
newWidth = Math.max(MIN_WINDOW_WIDTH, startWidth - delta);
if (newWidth > MIN_WINDOW_WIDTH) newLeft = startLeft + delta;
}
if (edge.includes('bottom')) {
newHeight = Math.max(200, startHeight + (e.clientY - startY));
newHeight = Math.max(MIN_WINDOW_HEIGHT, startHeight + (e.clientY - startY));
}
if (edge.includes('top')) {
const delta = e.clientY - startY;
newHeight = Math.max(200, startHeight - delta);
if (newHeight > 200) newTop = startTop + delta;
newHeight = Math.max(MIN_WINDOW_HEIGHT, startHeight - delta);
if (newHeight > MIN_WINDOW_HEIGHT) newTop = startTop + delta;
}

el.style.width = `${newWidth}px`;
Expand Down Expand Up @@ -123,12 +124,22 @@ const WindowWrapper = (Component, windowKey) => {
{ selector: '.resize-corner-tl', edge: 'top-left' },
];

const listeners = [];

edges.forEach(({ selector, edge }) => {
const handle = el.querySelector(selector);
if (handle) {
handle.addEventListener('mousedown', (e) => handleMouseDown(e, edge));
const listener = (e) => handleMouseDown(e, edge);
handle.addEventListener('mousedown', listener);
listeners.push({ handle, listener });
}
});

return () => {
listeners.forEach(({ handle, listener }) => {
handle.removeEventListener('mousedown', listener);
});
};
}, [windowKey, focusWindow, resizeWindow]);


Expand Down