1
1
import { Component , DragItem } from '../../interfaces/Interfaces' ;
2
2
import { DropTargetMonitor , useDrop } from 'react-dnd' ;
3
- import React , { useEffect , useState } from 'react' ;
3
+ import React , { useEffect , useState , forwardRef } from 'react' ;
4
4
import {
5
5
addChild ,
6
6
changeFocus ,
@@ -20,7 +20,11 @@ import { display } from 'html2canvas/dist/types/css/property-descriptors/display
20
20
import { ZoomIn , ZoomOut } from '@mui/icons-material' ;
21
21
import { Button } from '@mui/material' ;
22
22
23
- const Canvas = ( props : { } ) : JSX . Element => {
23
+ interface CanvasProps {
24
+ zoom : number ;
25
+ }
26
+
27
+ const Canvas = forwardRef < HTMLDivElement , CanvasProps > ( ( { zoom } , ref ) => {
24
28
const state = useSelector ( ( store : RootState ) => store . appState ) ;
25
29
const contextParam = useSelector ( ( store : RootState ) => store . contextSlice ) ;
26
30
const roomCode = useSelector ( ( store : RootState ) => store . roomSlice . roomCode ) ;
@@ -287,7 +291,9 @@ const Canvas = (props: {}): JSX.Element => {
287
291
backgroundColor : isOver ? '#242323' : '#191919' ,
288
292
// borderStyle: isOver ? 'dotted' : 'solid',
289
293
aspectRatio : 'auto 774 / 1200' ,
290
- boxSizing : 'border-box'
294
+ boxSizing : 'border-box' ,
295
+ transform : `scale(${ zoom } )` ,
296
+ transformOrigin : 'top center'
291
297
} ;
292
298
293
299
// Combine the default styles of the canvas with the custom styles set by the user for that component
@@ -309,24 +315,14 @@ const Canvas = (props: {}): JSX.Element => {
309
315
'#9267FF'
310
316
] ;
311
317
312
- const [ zoom , setZoom ] = useState ( 1 ) ;
313
-
314
- // zoom in
315
- const zoomIn = ( ) => {
316
- setZoom ( zoom + 0.1 ) ;
317
- } ;
318
-
319
- // zoom out
320
- const zoomOut = ( ) => {
321
- setZoom ( Math . max ( zoom - 0.1 , 0.1 ) ) ;
322
- } ;
323
-
324
318
const zoomedChildren : React . CSSProperties = {
325
319
transform : `scale(${ zoom } )` ,
320
+ width : '100%' ,
326
321
transformOrigin : 'top center' ,
327
322
display : 'flex' ,
328
323
flexDirection : 'column' ,
329
- alignItems : 'center'
324
+ alignItems : 'center' ,
325
+ overflow : 'auto'
330
326
} ;
331
327
332
328
const buttonStyle : React . CSSProperties = {
@@ -339,84 +335,63 @@ const Canvas = (props: {}): JSX.Element => {
339
335
} ;
340
336
341
337
return (
342
- < div >
343
- < div
344
- style = { {
345
- position : 'relative' ,
346
- bottom : 0 ,
347
- left : 0 ,
348
- display : 'flex' ,
349
-
350
- marginRight : 'auto'
351
- } }
352
- >
353
- < Button style = { buttonStyle } onClick = { zoomIn } >
354
- < ZoomIn />
355
- </ Button >
356
- < Button style = { buttonStyle } onClick = { zoomOut } >
357
- < ZoomOut />
358
- </ Button >
359
- </ div >
360
- < div
361
- className = { 'componentContainer' }
362
- ref = { drop }
363
- data-testid = "drop"
364
- style = { canvasStyle }
365
- onClick = { onClickHandler }
366
- onMouseMove = { handleMouseMove }
367
- >
368
- < div className = "allElements" style = { zoomedChildren } >
369
- { renderChildren ( currentComponent . children ) }
370
- </ div >
371
- { remoteCursors . map (
372
- ( cursor , idx ) =>
373
- cursor . isVisible && (
374
- < div
375
- key = { idx }
376
- className = "remote-cursor"
377
- style = { {
378
- position : 'absolute' ,
379
- left : cursor . x + 'px' ,
380
- top : cursor . y - 68 + 'px' ,
381
- //cursor style
382
- fontSize : '1em' ,
383
- color : userColors [ userList . indexOf ( cursor . remoteUserName ) ]
384
- } }
385
- >
386
- { < FaMousePointer /> }
387
- { cursor . remoteUserName }
388
- </ div >
389
- )
390
- ) }
391
- < label className = "switch" >
392
- { userList . length > 1 && (
393
- < Button
394
- className = "btn-toggle"
395
- onClick = { multipleClicks }
338
+ < div
339
+ className = { 'componentContainer' }
340
+ ref = { drop }
341
+ data-testid = "drop"
342
+ style = { canvasStyle }
343
+ onClick = { onClickHandler }
344
+ onMouseMove = { handleMouseMove }
345
+ >
346
+ { renderChildren ( currentComponent . children ) }
347
+ { remoteCursors . map (
348
+ ( cursor , idx ) =>
349
+ cursor . isVisible && (
350
+ < div
351
+ key = { idx }
352
+ className = "remote-cursor"
396
353
style = { {
397
- position : 'fixed' ,
398
- width : '100px' ,
399
- height : '35px' ,
400
- bottom : '200px' ,
401
- right : '45vw' ,
402
- padding : '5px' ,
403
- textAlign : 'center' ,
404
- color : '#ffffff' ,
405
- backgroundColor : '#151515' ,
406
- zIndex : 0 ,
407
- border : '2px solid #0671e3' ,
408
- whiteSpace : 'nowrap' ,
409
- cursor : 'pointer' ,
410
- textTransform : 'none'
354
+ position : 'absolute' ,
355
+ left : cursor . x + 'px' ,
356
+ top : cursor . y - 68 + 'px' ,
357
+ //cursor style
358
+ fontSize : '1em' ,
359
+ color : userColors [ userList . indexOf ( cursor . remoteUserName ) ]
411
360
} }
412
361
>
413
- { toggleText === 'on' ? 'View Cursors' : 'Hide Cursors' }
414
- </ Button >
415
- ) }
416
- </ label >
417
- </ div >
362
+ { < FaMousePointer /> }
363
+ { cursor . remoteUserName }
364
+ </ div >
365
+ )
366
+ ) }
367
+ < label className = "switch" >
368
+ { userList . length > 1 && (
369
+ < Button
370
+ className = "btn-toggle"
371
+ onClick = { multipleClicks }
372
+ style = { {
373
+ position : 'fixed' ,
374
+ width : '100px' ,
375
+ height : '35px' ,
376
+ bottom : '200px' ,
377
+ right : '45vw' ,
378
+ padding : '5px' ,
379
+ textAlign : 'center' ,
380
+ color : '#ffffff' ,
381
+ backgroundColor : '#151515' ,
382
+ zIndex : 0 ,
383
+ border : '2px solid #354e9c' ,
384
+ whiteSpace : 'nowrap' ,
385
+ cursor : 'pointer' ,
386
+ textTransform : 'none'
387
+ } }
388
+ >
389
+ { toggleText === 'on' ? 'View Cursors' : 'Hide Cursors' }
390
+ </ Button >
391
+ ) }
392
+ </ label >
418
393
</ div >
419
394
) ;
420
- } ;
395
+ } ) ;
421
396
422
397
export default Canvas ;
0 commit comments