Skip to content

Commit a303ba1

Browse files
authored
Added handling for string prop in component content. (#3433)
* added " for string props * added switch case for type of the prop * captialize button
1 parent a47fe22 commit a303ba1

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

docuilib/src/components/pageComponents/ContentItem.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,20 @@ import ReactLiveScope from '../../theme/ReactLiveScope';
66
type ComponentItemProps = {
77
componentName: string;
88
props: Record<string, unknown>;
9-
}
9+
};
1010
const ComponentItem = (props: ComponentItemProps) => {
1111
const {componentName, props: componentProps} = props;
1212
const isComponentExists = !!ReactLiveScope[componentName];
1313
const propString = Object.keys(componentProps).reduce((acc, key) => {
1414
const propValue = componentProps[key];
15-
if (typeof propValue === 'object') {
16-
return `${acc}${key}={${JSON.stringify(propValue)}} `;
15+
switch (typeof propValue) {
16+
case 'object':
17+
return `${acc}${key}={${JSON.stringify(propValue)}} `;
18+
case 'string':
19+
return `${acc}${key}="${propValue}" `;
20+
default:
21+
return `${acc}${key}={${propValue}} `;
1722
}
18-
return `${acc}${key}={${propValue}} `;
1923
}, '');
2024

2125
const code = isComponentExists ? `<${componentName} ${propString} />` : '<Text>Component Not Found</Text>';
@@ -31,13 +35,12 @@ type Item = {
3135
component?: string;
3236
props?: any;
3337
value?: any;
34-
}
38+
};
3539
type ContentItemProps = {
3640
item: Item;
3741
componentName: string;
38-
}
42+
};
3943
export const ContentItem = ({item, componentName}: ContentItemProps) => {
40-
4144
const getFigmaEmbed = item => {
4245
const value = item.value;
4346
const height = item.height || 450;

src/components/test.api.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,20 @@
9595
{
9696
"component": "Text",
9797
"props": {
98-
"children": "\"This is a Text\""
98+
"children": "This is a Text"
9999
},
100100
"background": "yellow"
101101
},
102102
{
103103
"component": "Button",
104104
"props": {
105-
"label": "\"This is a button\""
105+
"label": "This is a Button"
106106
}
107107
},
108108
{
109109
"component": "Chip",
110110
"props": {
111-
"label": "\"This is a Chip\""
111+
"label": "This is a Chip"
112112
}
113113
}
114114
]

0 commit comments

Comments
 (0)