Skip to content

Commit 2b87b85

Browse files
committed
designed the string outpu for code preview
1 parent df540db commit 2b87b85

File tree

4 files changed

+34
-16
lines changed

4 files changed

+34
-16
lines changed

src/components/CodePreview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class CodePreview extends Component<Props> {
2626
}}
2727
>
2828
<SyntaxHighlighter style={hybrid}>
29-
{format(componentRender(focusComponent, components))}
29+
{componentRender(focusComponent, components)}
3030
</SyntaxHighlighter>
3131
</div>
3232
);

src/components/Rectangle.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ class Rectangle extends Component<PropsInt, StateInt> {
149149
fillPatternImage={this.state.image ? this.state.image : this.setImage(imageSource)}
150150
fillPatternScaleX={this.state.image ? width / this.state.image.width : 1}
151151
fillPatternScaleY={this.state.image ? height / this.state.image.height : 1}
152+
_useStrictMode
152153
/>
153154
<Label>
154155
<Text
@@ -194,16 +195,14 @@ class Rectangle extends Component<PropsInt, StateInt> {
194195
}
195196
/>
196197
))}
197-
{focusChild &&
198-
focusChild.childId === childId &&
199-
draggable && (
200-
<TransformerComponent
201-
focusChild={focusChild}
202-
rectClass={'childRect'}
203-
anchorSize={8}
204-
color={'grey'}
205-
/>
206-
)}
198+
{focusChild && focusChild.childId === childId && draggable && (
199+
<TransformerComponent
200+
focusChild={focusChild}
201+
rectClass={'childRect'}
202+
anchorSize={8}
203+
color={'grey'}
204+
/>
205+
)}
207206
</Group>
208207
);
209208
}

src/utils/Interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export interface ChildrenInt extends Array<ChildInt> {}
3030
export interface ComponentInt {
3131
id: number;
3232
stateful: boolean;
33+
classBased: boolean;
3334
title: string;
3435
color: string;
3536
props: PropInt[];

src/utils/componentRender.util.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ const componentRender = (component: ComponentInt, components: ComponentsInt) =>
55
const {
66
childrenArray,
77
title,
8-
props
8+
props,
9+
stateful,
10+
classBased
911
}: {
1012
childrenArray: ChildrenInt;
1113
title: string;
1214
props: PropInt[];
15+
stateful: boolean;
16+
classBased: boolean;
1317
} = component;
14-
18+
let stateful1 = true;
1519
function typeSwitcher(type: string) {
1620
switch (type) {
1721
case 'string':
@@ -112,7 +116,10 @@ const componentRender = (component: ComponentInt, components: ComponentsInt) =>
112116
}
113117

114118
return `
115-
import React from 'react';
119+
${classBased ? `import React, {Component, useState} from 'react';` : ``}
120+
${stateful && !classBased ? `import React, {useState} from 'react';` : ``}
121+
${!stateful && !classBased ? `import React from 'react';` : ``}
122+
116123
${childrenArray
117124
.filter(child => child.childType !== 'HTML')
118125
.map(child => `import ${child.componentName} from './${child.componentName}.tsx'`)
@@ -129,9 +136,19 @@ const componentRender = (component: ComponentInt, components: ComponentsInt) =>
129136
${props.map(prop => `${prop.key}: ${typeSwitcher(prop.type)}\n`)}
130137
};
131138
132-
const ${title} = (props: Props) => {
139+
${classBased ? `class ${title} extends Component {` : `const ${title} = (props: Props) => {`}
140+
${stateful ? `const ['PROP', 'setPROP'] = useState("INITIAL VALUE FOR PROP");` : ``}
141+
${
142+
true
143+
? `constructor(props) {
144+
super(props);
145+
this.state = {}
146+
}`
147+
: ``
148+
}
149+
133150
const {${props.map(el => el.key).join(', ')}} = props;
134-
151+
${true ? `render() {` : ``}
135152
return (
136153
<div>
137154
${cloneDeep(childrenArray)
@@ -144,6 +161,7 @@ const componentRender = (component: ComponentInt, components: ComponentsInt) =>
144161
</div>
145162
);
146163
}
164+
${true ? `}` : ``}
147165
export default ${title};
148166
`;
149167
};

0 commit comments

Comments
 (0)