1
- import React , { Component , createRef } from 'react' ;
1
+ import React , { Component , createRef , Fragment } from 'react' ;
2
2
// import PropTypes from 'prop-types';
3
3
import {
4
- Stage , Layer , Image , Group ,
4
+ Stage , Layer , Image , Group , Label , Text , Tag ,
5
5
} from 'react-konva' ;
6
+ import Konva from 'konva' ;
6
7
import TransformerComponent from './TransformerComponent.jsx' ;
7
8
import Rectangle from './Rectangle.jsx' ;
8
9
9
-
10
10
class KonvaStage extends Component {
11
11
state = {
12
12
x : undefined ,
@@ -19,6 +19,10 @@ 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
22
26
handleStageMouseDown = ( e ) => {
23
27
// clicked on stage - cler selection
24
28
if ( e . target === e . target . getStage ( ) ) {
@@ -42,27 +46,11 @@ class KonvaStage extends Component {
42
46
}
43
47
} ;
44
48
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
-
61
49
render ( ) {
62
50
const {
63
- components, handleTransform, image , draggable, scaleX, scaleY, focusComponent,
51
+ components, handleTransform, draggable, scaleX, scaleY, focusComponent,
64
52
} = this . props ;
65
- const { selectedShapeName } = this . state ;
53
+ // const { selectedShapeName } = this.state;
66
54
67
55
return (
68
56
< Stage
@@ -80,45 +68,41 @@ class KonvaStage extends Component {
80
68
ref = { ( node ) => {
81
69
this . group = node ;
82
70
} }
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
- />
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 } />
102
101
</ Group >
103
102
</ Layer >
104
103
</ Stage >
105
104
) ;
106
105
}
107
106
}
108
107
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
-
124
108
export default KonvaStage ;
0 commit comments