1
- import React , { Component , createRef , Fragment } from 'react' ;
1
+ import React , { Component , createRef } from 'react' ;
2
2
// import PropTypes from 'prop-types';
3
3
import {
4
- Stage , Layer , Image , Group , Label , Text , Tag ,
4
+ Stage , Layer , Image , Group ,
5
5
} from 'react-konva' ;
6
- import Konva from 'konva' ;
7
6
import TransformerComponent from './TransformerComponent.jsx' ;
8
7
import Rectangle from './Rectangle.jsx' ;
9
8
9
+
10
10
class KonvaStage extends Component {
11
11
state = {
12
12
x : undefined ,
@@ -19,10 +19,6 @@ class KonvaStage extends Component {
19
19
this . group = createRef ( ) ;
20
20
}
21
21
22
- // Christian - this function causes the expansionPanel of the clicked rect to open
23
- // (and focusedComponent to change, which we don't want)
24
- // could reuse this logic for affecting state of children array
25
- // ADD FOCUS CHILD FUNCTIONALITY HERE
26
22
handleStageMouseDown = ( e ) => {
27
23
// clicked on stage - cler selection
28
24
if ( e . target === e . target . getStage ( ) ) {
@@ -46,11 +42,27 @@ class KonvaStage extends Component {
46
42
}
47
43
} ;
48
44
45
+ // WAS ALREADY COMMENTED OUT
46
+ // handleStageDrag = () => {
47
+ // // const mainWindowHeight = this.main.current.clientHeight;
48
+ // // const mainWindowWidth = this.main.current.clientWidth;
49
+ // // const groupX = this.refs.group.attrs.x;
50
+ // // const groupY = this.refs.group.attrs.y;
51
+
52
+ // // const componentX = (mainWindowWidth / 2) - groupX;
53
+ // // const componentY = (mainWindowHeight / 2) - groupY;
54
+ // // console.log(componentX, componentY);
55
+ // }
56
+
57
+ componentDidMount ( ) {
58
+ // this.props.setImage();
59
+ }
60
+
49
61
render ( ) {
50
62
const {
51
- components, handleTransform, draggable, scaleX, scaleY, focusComponent,
63
+ components, handleTransform, image , draggable, scaleX, scaleY, focusComponent,
52
64
} = this . props ;
53
- // const { selectedShapeName } = this.state;
65
+ const { selectedShapeName } = this . state ;
54
66
55
67
return (
56
68
< Stage
@@ -68,41 +80,45 @@ class KonvaStage extends Component {
68
80
ref = { ( node ) => {
69
81
this . group = node ;
70
82
} }
71
- draggable = { draggable }
72
- >
73
- { components . map ( ( comp , i ) => (
74
- < Fragment key = { i } >
75
- < Rectangle
76
- draggable = { comp . draggable }
77
- key = { i }
78
- componentId = { comp . id }
79
- x = { comp . position . x }
80
- y = { comp . position . y }
81
- width = { comp . position . width }
82
- height = { comp . position . height }
83
- title = { comp . title }
84
- color = { comp . color }
85
- handleTransform = { handleTransform }
86
- />
87
- < Label x = { comp . position . x } y = { comp . position . y } >
88
- < Text
89
- text = { `${ comp . title } ,${ comp . position . x . toPrecision (
90
- 3 ,
91
- ) } ,${ comp . position . y . toPrecision ( 3 ) } `}
92
- fontFamily = "Calibri"
93
- fontSize = { 12 }
94
- padding = { 5 }
95
- fill = "green"
96
- />
97
- </ Label >
98
- </ Fragment >
99
- ) ) }
100
- < TransformerComponent focusComponent = { focusComponent } />
83
+ draggable = { draggable } >
84
+ < Image image = { image } />
85
+ { components . map ( ( comp , i ) => < Rectangle
86
+ draggable = { comp . draggable }
87
+ selectedShapeName = { selectedShapeName }
88
+ key = { i }
89
+ componentId = { comp . id }
90
+ x = { comp . position . x }
91
+ y = { comp . position . y }
92
+ width = { comp . position . width }
93
+ height = { comp . position . height }
94
+ title = { comp . title }
95
+ color = { comp . color }
96
+ handleTransform = { handleTransform }
97
+ /> ) }
98
+ < TransformerComponent
99
+ focusComponent = { focusComponent }
100
+ selectedShapeName = { selectedShapeName }
101
+ />
101
102
</ Group >
102
103
</ Layer >
103
104
</ Stage >
104
105
) ;
105
106
}
106
107
}
107
108
109
+ // KonvaStage.propTypes = {
110
+ // draggable: PropTypes.bool.isRequired,
111
+ // components: PropTypes.array.isRequired,
112
+ // handleTransform: PropTypes.func.isRequired,
113
+ // image: PropTypes.oneOfType([
114
+ // PropTypes.string,
115
+ // PropTypes.object,
116
+ // ]),
117
+ // scaleX: PropTypes.number.isRequired,
118
+ // scaleY: PropTypes.number.isRequired,
119
+ // openExpansionPanel: PropTypes.func.isRequired,
120
+ // setImage: PropTypes.func.isRequired,
121
+ // focusComponent: PropTypes.object.isRequired,
122
+ // };
123
+
108
124
export default KonvaStage ;
0 commit comments