Skip to content

Commit 39f7705

Browse files
added placeholder componentRect, changed styling of transformer
1 parent 8ad8eed commit 39f7705

File tree

5 files changed

+64
-38
lines changed

5 files changed

+64
-38
lines changed

src/components/GrandchildRectangle.jsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,12 @@ import { Rect, Group } from 'react-konva';
44

55
class GrandchildRectangle extends Component {
66
getComponentColor(componentId) {
7-
console.log('siodfbsldfk', componentId);
87
const color = this.props.components.find(comp => comp.id == componentId).color;
9-
console.log(color);
10-
118
return color;
129
}
1310

1411
render() {
1512
const {
16-
color,
1713
x,
1814
y,
1915
scaleX,
@@ -51,8 +47,7 @@ class GrandchildRectangle extends Component {
5147
scaleY={1}
5248
width={width}
5349
height={height}
54-
stroke={color}
55-
color={this.getComponentColor(childComponentId)}
50+
stroke={this.getComponentColor(childComponentId)}
5651
// fill={color}
5752
// opacity={0.8}
5853
strokeWidth={4}
@@ -76,7 +71,6 @@ class GrandchildRectangle extends Component {
7671
scaleY={1}
7772
width={grandchild.position.width * (width / (window.innerWidth / 2))}
7873
height={grandchild.position.height * (height / window.innerHeight)}
79-
color={color}
8074
/>
8175
))}
8276
</Group>

src/components/KonvaStage.jsx

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

98
class KonvaStage extends Component {
@@ -34,8 +33,6 @@ class KonvaStage extends Component {
3433
checkSize = () => {
3534
const width = this.container.offsetWidth;
3635
const height = this.container.offsetHeight;
37-
console.log('setting width: ', this.state.stageWidth, width);
38-
console.log('setting height: ', this.state.heightWidth, height);
3936
this.setState({
4037
stageWidth: width,
4138
stageHeight: height,
@@ -46,24 +43,28 @@ class KonvaStage extends Component {
4643
// // clicked on stage - clear selection
4744
if (e.target === e.target.getStage()) {
4845
// add functionality for allowing no focusChild
49-
console.log(e.target.getStage());
46+
console.log('user clicked on canvas:');
5047
return;
5148
}
5249
// // clicked on transformer - do nothing
5350
const clickedOnTransformer = e.target.getParent().className === 'Transformer';
5451
if (clickedOnTransformer) {
52+
console.log('user clicked on transformer');
5553
return;
5654
}
5755

56+
if (e.target.attrs.className === 'componentRect') {
57+
console.log('user clicked on componentRect');
58+
}
59+
5860
// find clicked rect by its name
5961
const rectChildId = e.target.attrs.childId;
60-
console.log('e.target : ', rectChildId);
62+
console.log('user clicked on child rectangle with Id: ', rectChildId);
6163
this.props.changeFocusChild({ childId: rectChildId });
6264
this.props.changeComponentFocusChild({
6365
componentId: this.props.focusComponent.id,
6466
childId: rectChildId,
6567
});
66-
// put individual component's focus child logic here
6768
};
6869

6970
render() {
@@ -101,6 +102,36 @@ class KonvaStage extends Component {
101102
height={this.state.stageHeight - 10}
102103
>
103104
<Layer>
105+
{focusComponent.title !== 'App' && (
106+
<Group
107+
draggable={true}
108+
x={focusComponent.position.x}
109+
y={focusComponent.position.y}
110+
width={focusComponent.position.width}
111+
height={focusComponent.position.height}
112+
>
113+
<Rect
114+
className={'componentRect'}
115+
stroke={focusComponent.color}
116+
x={0}
117+
y={0}
118+
width={focusComponent.position.width}
119+
height={focusComponent.position.height}
120+
strokeWidth={2}
121+
strokeScaleEnabled={false}
122+
/>
123+
<Label>
124+
<Text
125+
text={focusComponent.title}
126+
fill={focusComponent.color}
127+
fontStyle={'bold'}
128+
fontVariant={'small-caps'}
129+
fontSize={14}
130+
y={-15}
131+
/>
132+
</Label>
133+
</Group>
134+
)}
104135
{components
105136
.find(comp => comp.id === focusComponent.id)
106137
.childrenArray.map((child, i) => (
@@ -119,7 +150,6 @@ class KonvaStage extends Component {
119150
width={child.position.width}
120151
height={child.position.height}
121152
title={child.componentName + child.childId}
122-
color={child.color}
123153
handleTransform={handleTransform}
124154
draggable={true}
125155
/>

src/components/Rectangle.jsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ import GrandchildRectangle from './GrandchildRectangle.jsx';
88

99
class Rectangle extends Component {
1010
getComponentColor(componentId) {
11-
console.log('siodfbsldfk', componentId);
1211
const color = this.props.components.find(comp => comp.id == componentId).color;
13-
console.log(color);
14-
1512
return color;
1613
}
1714

@@ -42,7 +39,6 @@ class Rectangle extends Component {
4239

4340
render() {
4441
const {
45-
color,
4642
x,
4743
y,
4844
scaleX,
@@ -84,8 +80,7 @@ class Rectangle extends Component {
8480
scaleY={1}
8581
width={width}
8682
height={height}
87-
stroke={color}
88-
color={this.getComponentColor(childComponentId)}
83+
stroke={this.getComponentColor(childComponentId)}
8984
// fill={color}
9085
// opacity={0.8}
9186
onTransformEnd={event => this.handleResize(componentId, childId, event.target)}
@@ -94,7 +89,15 @@ class Rectangle extends Component {
9489
draggable={false}
9590
/>
9691
<Label>
97-
<Text text={title} fill={'white'} />
92+
<Text
93+
text={title}
94+
fill={'white'}
95+
fontStyle={'bold'}
96+
fontVariant={'small-caps'}
97+
fontSize={10}
98+
x={4}
99+
y={4}
100+
/>
98101
</Label>
99102
{components
100103
.find(comp => comp.title === childComponentName)
@@ -114,14 +117,11 @@ class Rectangle extends Component {
114117
width={grandchild.position.width * (width / (window.innerWidth / 2))}
115118
height={grandchild.position.height * (height / window.innerHeight)}
116119
// title={child.componentName + child.childId}
117-
color={grandchild.color}
118120
/>
119121
))}
120-
{focusChild && focusChild.childId === childId && draggable ? (
121-
<TransformerComponent focusChild={focusChild} />
122-
) : (
123-
<Label />
124-
)}
122+
{focusChild
123+
&& focusChild.childId === childId
124+
&& draggable && <TransformerComponent focusChild={focusChild} />}
125125
</Group>
126126
);
127127
}

src/components/TransformerComponent.jsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ export default class TransformerComponent extends Component {
3636
ref={(node) => {
3737
this.transformer = node;
3838
}}
39+
borderEnabled={false}
40+
anchorFill={'grey'}
41+
anchorStroke={'grey'}
42+
anchorSize={8}
43+
keepRatio={false}
3944
/>
4045
);
4146
}

src/utils/componentReducer.util.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ const initialComponentState = {
1515
props: [],
1616
nextPropId: 0,
1717
position: {
18-
x: 110,
19-
y: 120,
20-
width: 50,
21-
height: 50,
18+
x: 50,
19+
y: 50,
20+
width: 600,
21+
height: 600,
2222
},
2323
childrenArray: [],
2424
nextChildId: 1,
@@ -170,9 +170,6 @@ export const deleteChild = (
170170
export const handleTransform = (state, {
171171
componentId, childId, x, y, width, height,
172172
}) => {
173-
// console.log('componentId and childId: ', componentId, childId);
174-
// console.log('state.focuscomponent: ', state.focusComponent);
175-
console.log('incoming x and y: ', x, y);
176173
const child = state.components
177174
.find(comp => comp.id === componentId)
178175
.childrenArray.find(child => child.childId === childId);
@@ -285,10 +282,10 @@ export const deleteComponent = (state, { componentId }) => {
285282

286283
export const changeFocusComponent = (state, { title }) => {
287284
const newFocusComp = state.components.find(comp => comp.title === title);
288-
// set the "focus child" to the focus child of this particular component .
289-
const newFocusChildId = newFocusComp.focusChildId ;
285+
// set the "focus child" to the focus child of this particular component .
286+
const newFocusChildId = newFocusComp.focusChildId;
290287

291-
const newFocusChild = newFocusComp.childrenArray.find( child => child.childId == newFocusChildId) ;
288+
const newFocusChild = newFocusComp.childrenArray.find(child => child.childId == newFocusChildId);
292289

293290
const result = getSelectable(newFocusComp, state.components);
294291

0 commit comments

Comments
 (0)