Skip to content

Commit

Permalink
Added resize observer
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszmigas committed Mar 5, 2024
1 parent aa146ad commit 1e4f9f9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 43 deletions.
4 changes: 4 additions & 0 deletions apps/web/src/components/appStatusBar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export const AppStatusBar = () => {
//image size
//selection size
//zoom level
//cursor position
return <div className="px-2 border-t bg-secondary">Status bar</div>;
};

42 changes: 0 additions & 42 deletions apps/web/src/components/canvasHost.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion apps/web/src/components/canvasViewport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const CanvasViewport = () => {
<div
style={{ opacity: 0 }}
ref={hostElementRef}
className="absolute size-full overflow-hidden transition-opacity duration-1000"
className="absolute size-full overflow-hidden transition-opacity duration-1000 cursor-crosshair"
></div>
<div className="absolute p-small">Middle mouse to move/zoom</div>
</div>
Expand Down
27 changes: 27 additions & 0 deletions apps/web/src/hooks/useResizeObserver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Size } from "@/utils/common";
import { RefObject, useEffect } from "react";

export const useResizeObserver = (
ref: RefObject<HTMLElement>,
onResize: (size: Size) => void
) => {
useEffect(() => {
if (!ref.current) return;

const element = ref.current;
const observer = new ResizeObserver((entries) => {
for (let entry of entries) {
const { width, height } = entry.contentRect;
onResize({ width, height });
}
});

observer.observe(element);

return () => {
observer.unobserve(element);
observer.disconnect();
};
}, [ref, onResize]);
};

0 comments on commit 1e4f9f9

Please sign in to comment.