Skip to content

Commit cbfa04c

Browse files
authored
Merge pull request #56 from ChristianEdwardPadilla/development
user props working
2 parents 749816c + 08b9c94 commit cbfa04c

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

src/components/Props.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,17 @@ const mapStateToProps = store => ({
8383

8484
const availablePropTypes = {
8585
string: 'STR',
86+
number: 'NUM',
8687
object: 'OBJ',
8788
array: 'ARR',
88-
number: 'NUM',
8989
boolean: 'BOOL',
9090
function: 'FUNC',
91-
symbol: 'SYM',
91+
// symbol: 'SYM',
9292
node: 'NODE',
9393
element: 'ELEM',
94+
any: 'ANY',
95+
tuple: 'TUP',
96+
enum: 'ENUM',
9497
};
9598

9699
const typeOptions = [

src/utils/componentRender.util.js

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,37 @@ const componentRender = (component, data) => {
33
stateful, id, position, childrenArray, title, props,
44
} = component;
55

6+
function typeSwitcher(type) {
7+
switch (type) {
8+
case 'string':
9+
return 'string';
10+
case 'number':
11+
return 'number';
12+
case 'object':
13+
return 'object';
14+
case 'array':
15+
return 'any[]';
16+
case 'bool':
17+
return 'boolean';
18+
case 'function':
19+
return '() => any';
20+
// case 'symbol':
21+
// return 'string';
22+
case 'node':
23+
return 'string';
24+
case 'element':
25+
return 'string';
26+
case 'tuple':
27+
return '[any]';
28+
case 'enum':
29+
return '{}';
30+
case 'any':
31+
return 'any';
32+
default:
33+
return 'any';
34+
}
35+
}
36+
// need to filter with reduce the import, copy from below
637
if (stateful) {
738
return `
839
import React, { Component } from 'react';
@@ -51,12 +82,19 @@ const componentRender = (component, data) => {
5182
.join('\n')}
5283
5384
type Props = {
54-
${props.map(prop => `${prop.key}: ${prop.type}`).join('\n')}
85+
${props.map(prop => `${prop.key}: ${typeSwitcher(prop.type)}`).join('\n')}
5586
}
5687
5788
const ${title} = (props: Props) => (
5889
<div>
59-
${childrenArray.map(child => `<${child.componentName}/>`).join('\n')}
90+
${childrenArray
91+
.map(
92+
child => `<${child.componentName} ${data
93+
.find(c => c.id === child.childComponentId)
94+
.props.map(prop => `${prop.key}={${prop.value}}`)
95+
.join(' ')}/>`,
96+
)
97+
.join('\n')}
6098
</div>
6199
);
62100

0 commit comments

Comments
 (0)