@@ -67,7 +67,7 @@ const generateUnformattedCode = (
67
67
child . children = getEnrichedChildren ( child ) ;
68
68
}
69
69
// when we see a Switch, import React Router
70
- if ( referencedHTML . tag === 'Switch' ) importReactRouter = true ;
70
+ if ( referencedHTML . tag === 'Switch' || referencedHTML . tag === 'Link' ) importReactRouter = true ;
71
71
return child ;
72
72
} else if ( child . type === 'Route Link' ) {
73
73
links = true ;
@@ -82,26 +82,26 @@ const generateUnformattedCode = (
82
82
// Raised formatStyles so that it is declared before it is referenced. It was backwards.
83
83
// format styles stored in object to match React inline style format
84
84
const formatStyles = ( styleObj : any ) => {
85
- console . log ( styleObj ) ;
86
-
87
85
if ( Object . keys ( styleObj ) . length === 0 ) return `` ;
88
86
const formattedStyles = [ ] ;
89
- for ( let i in styleObj ) {
90
- let styleString = i + ': ' + "'" + styleObj [ i ] + "'" ;
91
- // if(i === 'style') {
92
- // styleString = i + ':' + JSON.stringify(styleObj[i]);
93
- // }
94
-
95
- formattedStyles . push ( styleString ) ;
87
+ let styleString ;
88
+ for ( let i in styleObj ) {
89
+ if ( i === 'style' ) {
90
+ styleString = i + ':' + JSON . stringify ( styleObj [ i ] ) ;
91
+ formattedStyles . push ( styleString ) ;
92
+ }
96
93
}
97
- return ' style={{' + formattedStyles . join ( ',' ) + '}}' ;
94
+ return formattedStyles ;
98
95
} ;
99
96
100
97
// function to dynamically add classes, ids, and styles to an element if it exists.
101
98
const elementTagDetails = ( childElement : object ) => {
102
99
let customizationDetails = "" ;
103
100
if ( childElement . childId && childElement . tag !== 'Route' ) customizationDetails += ( ' ' + `id="${ + childElement . childId } "` ) ;
104
- if ( childElement . attributes && childElement . attributes . cssClasses ) customizationDetails += ( ' ' + `className="${ childElement . attributes . cssClasses } "` ) ;
101
+ if ( childElement . attributes && childElement . attributes . cssClasses ) {
102
+ console . log ( childElement . attributes ) ;
103
+ customizationDetails += ( ' ' + `className="${ childElement . attributes . cssClasses } "` ) ;
104
+ }
105
105
if ( childElement . style && Object . keys ( childElement . style ) . length > 0 ) customizationDetails += ( ' ' + formatStyles ( childElement ) ) ;
106
106
return customizationDetails ;
107
107
} ;
@@ -214,8 +214,6 @@ const generateUnformattedCode = (
214
214
215
215
// create final component code. component code differs between classic react, next.js, gatsby.js
216
216
// classic react code
217
-
218
- //import { BrowserRouter as Router, Switch, Route, Link } from "react-router-dom";
219
217
if ( projectType === 'Classic React' ) {
220
218
return `
221
219
${ stateful && ! classBased ? `import React, {useState} from 'react';` : '' }
@@ -245,17 +243,17 @@ const generateUnformattedCode = (
245
243
${ classBased ? `render(): JSX.Element {` : `` }
246
244
${ ! importReactRouter ?
247
245
`return (
248
- <div className="${ currentComponent . name } " style={props.style }>
246
+ <div className="${ currentComponent . name } " ${ formatStyles ( currentComponent ) } >
249
247
${ writeNestedElements ( enrichedChildren ) }
250
248
</div>
251
249
);` : `return (
252
250
<Router>
253
- <div className="${ currentComponent . name } " style={props.style }>
251
+ <div className="${ currentComponent . name } " ${ formatStyles ( currentComponent ) } >
254
252
${ writeNestedElements ( enrichedChildren ) }
255
253
</div>
256
254
</Router>
257
255
);` }
258
- ${ classBased ? `}` : ` `}
256
+ ${ `} `}
259
257
export default ${ currentComponent . name } ;
260
258
` ;
261
259
}
@@ -300,7 +298,7 @@ const generateUnformattedCode = (
300
298
301
299
const ${ currentComponent . name } = (props: any): JSX.Element => {
302
300
303
- const [value, setValue] = useState<any | undefined>("INITIAL VALUE");
301
+ const[value, setValue] = useState<any | undefined>("INITIAL VALUE");
304
302
305
303
return (
306
304
<>
0 commit comments