Skip to content

Commit a4aed0d

Browse files
committed
moved allElements into parent container, canvas container
1 parent 522bb12 commit a4aed0d

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

app/src/components/main/Canvas.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,9 @@ const Canvas = forwardRef<HTMLDivElement, CanvasProps>(({ zoom }, ref) => {
291291
backgroundColor: isOver ? '#242323' : '#191919',
292292
// borderStyle: isOver ? 'dotted' : 'solid',
293293
aspectRatio: 'auto 774 / 1200',
294-
boxSizing: 'border-box'
294+
boxSizing: 'border-box',
295+
transform: `scale(${zoom})`,
296+
transformOrigin: 'top center'
295297
};
296298

297299
// Combine the default styles of the canvas with the custom styles set by the user for that component
@@ -342,9 +344,7 @@ const Canvas = forwardRef<HTMLDivElement, CanvasProps>(({ zoom }, ref) => {
342344
onClick={onClickHandler}
343345
onMouseMove={handleMouseMove}
344346
>
345-
<div className="allElements" style={zoomedChildren} ref={ref}>
346-
{renderChildren(currentComponent.children)}
347-
</div>
347+
{renderChildren(currentComponent.children)}
348348
{remoteCursors.map(
349349
(cursor, idx) =>
350350
cursor.isVisible && (

app/src/components/main/CanvasContainer.tsx

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,12 @@ function CanvasContainer(props: CanvasContainerProps): JSX.Element {
6767
//containerRef references the container that will ultimately have the scroll functionality
6868
const containerRef = useRef<HTMLDivElement>(null);
6969

70+
const container = document.getElementById('canvasContainer');
71+
7072
//useEffect dependency is the length of the parent components. No changes in children will scroll to the bottom. Once elements surpass the view of the canvas, scroll to bottom, else, keep scroll bar to the top.
7173
useEffect(() => {
72-
const allElements = document.querySelector('.allElements');
73-
const container = containerRef.current;
74-
if (
75-
container &&
76-
allElements &&
77-
state.components[0].children.length > 0
78-
) {
79-
container.scrollTop = container.scrollHeight;
80-
} else if (container) {
81-
container.scrollTop = 0;
74+
if (container && state.components[0].children.length > 0) {
75+
container.scrollTop = container.clientHeight;
8276
}
8377
}, [state.components[0].children.length]);
8478

@@ -101,7 +95,7 @@ function CanvasContainer(props: CanvasContainerProps): JSX.Element {
10195
};
10296

10397
return (
104-
<div style={canvasContainerStyle}>
98+
<div id="canvasContainer" style={canvasContainerStyle}>
10599
<div
106100
style={{
107101
position: 'sticky',
@@ -120,16 +114,15 @@ function CanvasContainer(props: CanvasContainerProps): JSX.Element {
120114
<Button
121115
style={backToTop}
122116
onClick={() => {
123-
containerRef.current.scrollTop = 0;
117+
container.scrollTop = 0;
124118
}}
125119
>
126120
Scroll Top
127121
</Button>
128122
<Button
129123
style={backToTop}
130124
onClick={() => {
131-
containerRef.current.scrollTop =
132-
containerRef.current.clientHeight;
125+
container.scrollTop = container.clientHeight;
133126
}}
134127
>
135128
Scroll Bottom

0 commit comments

Comments
 (0)