Skip to content

Commit 60cb036

Browse files
recursive rendering changes, and new children are offset
1 parent b00cb19 commit 60cb036

File tree

4 files changed

+149
-100
lines changed

4 files changed

+149
-100
lines changed

src/components/GrandchildRectangle.jsx

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,77 @@
1-
import React, { Component, Fragment } from 'react';
2-
import { Rect } from 'react-konva';
1+
import React, { Component } from 'react';
2+
import { Rect, Group } from 'react-konva';
33
// import PropTypes from 'prop-types';
44

55
class GrandchildRectangle extends Component {
66
render() {
7-
return <Rect />;
7+
const {
8+
color,
9+
x,
10+
y,
11+
scaleX,
12+
scaleY,
13+
childId,
14+
componentId,
15+
componentName,
16+
width,
17+
height,
18+
focusChild,
19+
components,
20+
draggable,
21+
} = this.props;
22+
23+
// the Group is responsible for dragging of all children
24+
// the Rect emits changes to child width and height with help from Transformer
25+
return (
26+
<Group
27+
draggable={false}
28+
x={x}
29+
y={y}
30+
scaleX={scaleX}
31+
scaleY={scaleY}
32+
width={width}
33+
height={height}
34+
>
35+
<Rect
36+
name={`${childId}`}
37+
x={0}
38+
y={0}
39+
// absolutePosition={{ x, y }}
40+
// childId={childId}
41+
componentId={componentId}
42+
scaleX={1}
43+
scaleY={1}
44+
width={width}
45+
height={height}
46+
stroke={color}
47+
color={color}
48+
// fill={color}
49+
// opacity={0.8}
50+
strokeWidth={4}
51+
strokeScaleEnabled={false}
52+
draggable={false}
53+
/>
54+
{components
55+
.find(comp => comp.title === componentName)
56+
.childrenArray.map((grandchild, i) => (
57+
<GrandchildRectangle
58+
key={i}
59+
components={components}
60+
componentId={componentId}
61+
componentName={grandchild.componentName}
62+
focusChild={focusChild}
63+
// childId={grandchild.childId}
64+
x={grandchild.position.x}
65+
y={grandchild.position.y}
66+
scaleX={0.8}
67+
scaleY={0.8}
68+
width={grandchild.position.width}
69+
height={grandchild.position.height}
70+
color={color}
71+
/>
72+
))}
73+
</Group>
74+
);
875
}
976
}
1077

src/components/KonvaStage.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class KonvaStage extends Component {
2222
// // clicked on stage - clear selection
2323
if (e.target === e.target.getStage()) {
2424
// add functionality for allowing no focusChild
25+
console.log(e.target.getStage(), this.main, this.group);
2526
return;
2627
}
2728
// // clicked on transformer - do nothing
@@ -56,9 +57,9 @@ class KonvaStage extends Component {
5657

5758
return (
5859
<Stage
59-
ref={(node) => {
60-
this.stage = node;
61-
}}
60+
// ref={(node) => {
61+
// this.stage = node;
62+
// }}
6263
onMouseDown={this.handleStageMouseDown}
6364
width={window.innerWidth}
6465
height={window.innerHeight}

src/components/Rectangle.jsx

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
Rect, Group, Label, Text,
44
} from 'react-konva';
55
import TransformerComponent from './TransformerComponent.jsx';
6+
import GrandchildRectangle from './GrandchildRectangle.jsx';
67
// import PropTypes from 'prop-types';
78

89
class Rectangle extends Component {
@@ -97,36 +98,24 @@ class Rectangle extends Component {
9798
{components
9899
.find(comp => comp.title === componentName)
99100
.childrenArray.map((grandchild, i) => (
100-
<Rectangle
101+
<GrandchildRectangle
101102
key={i}
102103
components={components}
103104
componentId={componentId}
104105
componentName={grandchild.componentName}
105106
focusChild={focusChild}
106-
childId={grandchild.childId}
107-
x={grandchild.position.x}
108-
y={grandchild.position.y}
107+
// childId={childId}
108+
x={grandchild.position.x * 0.8 + 10}
109+
y={grandchild.position.y * 0.8 + 10}
109110
scaleX={0.8}
110111
scaleY={0.8}
111112
width={grandchild.position.width}
112113
height={grandchild.position.height}
113114
// title={child.componentName + child.childId}
114115
color={color}
115-
handleTransform={() => {}}
116116
draggable={false}
117117
/>
118118
))}
119-
{/* <Rect
120-
// replace with grandchildren rectangles
121-
scaleX={0.2}
122-
scaleY={0.2}
123-
width={width}
124-
height={height}
125-
stroke={color}
126-
color={color}
127-
strokeWidth={4}
128-
draggable={false}
129-
/> */}
130119
{focusChild.childId === childId && draggable ? (
131120
<TransformerComponent focusChild={focusChild} />
132121
) : (

0 commit comments

Comments
 (0)