Skip to content

Commit 917ecc2

Browse files
Tolga MizrakciTolga Mizrakci
authored andcommitted
focus component changing on left panel cards
1 parent d4cbcc5 commit 917ecc2

File tree

1 file changed

+55
-39
lines changed

1 file changed

+55
-39
lines changed

src/components/KonvaStage.jsx

Lines changed: 55 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import React, { Component, createRef, Fragment } from 'react';
1+
import React, { Component, createRef } from 'react';
22
// import PropTypes from 'prop-types';
33
import {
4-
Stage, Layer, Image, Group, Label, Text, Tag,
4+
Stage, Layer, Image, Group,
55
} from 'react-konva';
6-
import Konva from 'konva';
76
import TransformerComponent from './TransformerComponent.jsx';
87
import Rectangle from './Rectangle.jsx';
98

9+
1010
class KonvaStage extends Component {
1111
state = {
1212
x: undefined,
@@ -19,10 +19,6 @@ class KonvaStage extends Component {
1919
this.group = createRef();
2020
}
2121

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
2622
handleStageMouseDown = (e) => {
2723
// clicked on stage - cler selection
2824
if (e.target === e.target.getStage()) {
@@ -46,11 +42,27 @@ class KonvaStage extends Component {
4642
}
4743
};
4844

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+
4961
render() {
5062
const {
51-
components, handleTransform, draggable, scaleX, scaleY, focusComponent,
63+
components, handleTransform, image, draggable, scaleX, scaleY, focusComponent,
5264
} = this.props;
53-
// const { selectedShapeName } = this.state;
65+
const { selectedShapeName } = this.state;
5466

5567
return (
5668
<Stage
@@ -68,41 +80,45 @@ class KonvaStage extends Component {
6880
ref={(node) => {
6981
this.group = node;
7082
}}
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+
/>
101102
</Group>
102103
</Layer>
103104
</Stage>
104105
);
105106
}
106107
}
107108

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+
108124
export default KonvaStage;

0 commit comments

Comments
 (0)