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 ) ;
@@ -30,8 +34,6 @@ const Canvas = (props: {}): JSX.Element => {
30
34
//remote cursor data
31
35
const [ remoteCursors , setRemoteCursors ] = useState ( [ ] ) ;
32
36
33
-
34
-
35
37
// Toggle switch for live cursor tracking
36
38
const [ toggleSwitch , setToggleSwitch ] = useState ( true ) ;
37
39
@@ -289,7 +291,9 @@ const Canvas = (props: {}): JSX.Element => {
289
291
backgroundColor : isOver ? '#242323' : '#191919' ,
290
292
// borderStyle: isOver ? 'dotted' : 'solid',
291
293
aspectRatio : 'auto 774 / 1200' ,
292
- boxSizing : 'border-box'
294
+ boxSizing : 'border-box' ,
295
+ transform : `scale(${ zoom } )` ,
296
+ transformOrigin : 'top center'
293
297
} ;
294
298
295
299
// Combine the default styles of the canvas with the custom styles set by the user for that component
@@ -311,24 +315,14 @@ const Canvas = (props: {}): JSX.Element => {
311
315
'#9267FF'
312
316
] ;
313
317
314
- const [ zoom , setZoom ] = useState ( 1 ) ;
315
-
316
- // zoom in
317
- const zoomIn = ( ) => {
318
- setZoom ( zoom + 0.1 ) ;
319
- } ;
320
-
321
- // zoom out
322
- const zoomOut = ( ) => {
323
- setZoom ( Math . max ( zoom - 0.1 , 0.1 ) ) ;
324
- } ;
325
-
326
318
const zoomedChildren : React . CSSProperties = {
327
319
transform : `scale(${ zoom } )` ,
320
+ width : '100%' ,
328
321
transformOrigin : 'top center' ,
329
322
display : 'flex' ,
330
323
flexDirection : 'column' ,
331
- alignItems : 'center'
324
+ alignItems : 'center' ,
325
+ overflow : 'auto'
332
326
} ;
333
327
334
328
const buttonStyle : React . CSSProperties = {
@@ -341,84 +335,63 @@ const Canvas = (props: {}): JSX.Element => {
341
335
} ;
342
336
343
337
return (
344
- < div >
345
- < div
346
- style = { {
347
- position : 'relative' ,
348
- bottom : 0 ,
349
- left : 0 ,
350
- display : 'flex' ,
351
-
352
- marginRight : 'auto'
353
- } }
354
- >
355
- < Button style = { buttonStyle } onClick = { zoomIn } >
356
- < ZoomIn />
357
- </ Button >
358
- < Button style = { buttonStyle } onClick = { zoomOut } >
359
- < ZoomOut />
360
- </ Button >
361
- </ div >
362
- < div
363
- className = { 'componentContainer' }
364
- ref = { drop }
365
- data-testid = "drop"
366
- style = { canvasStyle }
367
- onClick = { onClickHandler }
368
- onMouseMove = { handleMouseMove }
369
- >
370
- < div className = "allElements" style = { zoomedChildren } >
371
- { renderChildren ( currentComponent . children ) }
372
- </ div >
373
- { remoteCursors . map (
374
- ( cursor , idx ) =>
375
- cursor . isVisible && (
376
- < div
377
- key = { idx }
378
- className = "remote-cursor"
379
- style = { {
380
- position : 'absolute' ,
381
- left : cursor . x + 'px' ,
382
- top : cursor . y - 68 + 'px' ,
383
- //cursor style
384
- fontSize : '1em' ,
385
- color : userColors [ userList . indexOf ( cursor . remoteUserName ) ]
386
- } }
387
- >
388
- { < FaMousePointer /> }
389
- { cursor . remoteUserName }
390
- </ div >
391
- )
392
- ) }
393
- < label className = "switch" >
394
- { userList . length > 1 && (
395
- < Button
396
- className = "btn-toggle"
397
- 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"
398
353
style = { {
399
- position : 'fixed' ,
400
- width : '100px' ,
401
- height : '35px' ,
402
- bottom : '200px' ,
403
- right : '45vw' ,
404
- padding : '5px' ,
405
- textAlign : 'center' ,
406
- color : '#ffffff' ,
407
- backgroundColor : '#151515' ,
408
- zIndex : 0 ,
409
- border : '2px solid #354e9c' ,
410
- whiteSpace : 'nowrap' ,
411
- cursor : 'pointer' ,
412
- 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 ) ]
413
360
} }
414
361
>
415
- { toggleText === 'on' ? 'View Cursors' : 'Hide Cursors' }
416
- </ Button >
417
- ) }
418
- </ label >
419
- </ 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 >
420
393
</ div >
421
394
) ;
422
- } ;
395
+ } ) ;
423
396
424
397
export default Canvas ;
0 commit comments