Skip to content

Commit e5a858c

Browse files
Merge pull request #27 from ChristianEdwardPadilla/development
started recursive solution to descendant rendering
2 parents ba36089 + b978688 commit e5a858c

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

src/components/KonvaStage.jsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
import React, { Component, createRef, Fragment } from "react";
1+
import React, { Component, createRef, Fragment } from 'react';
22
// import PropTypes from 'prop-types';
3-
import { Stage, Layer, Group, Label, Text } from "react-konva";
4-
import TransformerComponent from "./TransformerComponent.jsx";
5-
import Rectangle from "./Rectangle.jsx";
3+
import {
4+
Stage, Layer, Group, Label, Text,
5+
} from 'react-konva';
6+
import TransformerComponent from './TransformerComponent.jsx';
7+
import Rectangle from './Rectangle.jsx';
68

79
class KonvaStage extends Component {
810
state = {
911
x: undefined,
10-
y: undefined
12+
y: undefined,
1113
};
1214

1315
constructor(props) {
@@ -16,22 +18,21 @@ class KonvaStage extends Component {
1618
this.group = createRef();
1719
}
1820

19-
handleStageMouseDown = e => {
21+
handleStageMouseDown = (e) => {
2022
// // clicked on stage - clear selection
2123
if (e.target === e.target.getStage()) {
2224
// add functionality for allowing no focusChild
2325
return;
2426
}
2527
// // clicked on transformer - do nothing
26-
const clickedOnTransformer =
27-
e.target.getParent().className === "Transformer";
28+
const clickedOnTransformer = e.target.getParent().className === 'Transformer';
2829
if (clickedOnTransformer) {
2930
return;
3031
}
3132

3233
// find clicked rect by its name
3334
const rectChildId = e.target.attrs.childId;
34-
console.log("e.target : ", rectChildId);
35+
console.log('e.target : ', rectChildId);
3536
this.props.changeFocusChild({ childId: rectChildId });
3637
};
3738

@@ -49,13 +50,13 @@ class KonvaStage extends Component {
4950
scaleY,
5051
focusComponent,
5152
focusChild,
52-
changeFocusChild
53+
changeFocusChild,
5354
} = this.props;
5455
const { selectedShapeName } = this.state;
5556

5657
return (
5758
<Stage
58-
ref={node => {
59+
ref={(node) => {
5960
this.stage = node;
6061
}}
6162
onMouseDown={this.handleStageMouseDown}

src/components/Rectangle.jsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,15 @@ class Rectangle extends Component {
3131
this.props.handleTransform(componentId, childId, transformation);
3232
}
3333

34-
findDescendants(component) {
35-
34+
findDescendants(component, components, descendants = []) {
35+
// fix this stuff Adam
36+
if (!component) return;
37+
component.childrenArray.forEach((child) => {
38+
descendants.push(child);
39+
const childComponent = components.find(comp => comp.title === child.componentName);
40+
this.findDescendants(childComponent, components, descendants);
41+
});
42+
return descendants;
3643
}
3744

3845
render() {
@@ -89,7 +96,7 @@ class Rectangle extends Component {
8996
<Label>
9097
<Text text={title} fill={'white'} />
9198
</Label>
92-
{}
99+
{this.findDescendants().map}
93100
<Rect
94101
// replace with grandchildren rectangles
95102
scaleX={0.2}

0 commit comments

Comments
 (0)