@@ -54,43 +54,86 @@ const useStyles = makeStyles((theme) => ({
54
54
}
55
55
} ) ) ;
56
56
57
- const payload = getParameters ( {
58
- files : {
59
- 'public/index.html' : {
60
- content :
61
- '<!DOCTYPE html>\n<html lang="en">\n <head>\n <meta charset="utf-8" />\n <meta\n name="viewport"\n content="width=device-width, initial-scale=1, shrink-to-fit=no"\n />\n <meta name="theme-color" content="#000000" />\n <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />\n <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />\n <title>Data driven forms example</title>\n\n <!--<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500">-->\n\n <!--<link rel="stylesheet" type="text/css" href="https://unpkg.com/@patternfly/[email protected] /patternfly-base.css"/>-->\n <!--<link rel="stylesheet" type="text/css" href="https://unpkg.com/@patternfly/[email protected] /patternfly-addons.css"/>-->\n </head>\n\n <body>\n <noscript>\n You need to enable JavaScript to run this app.\n </noscript>\n <div id="root"></div>\n </body>\n</html>\n'
62
- } ,
63
- 'package.json' : {
64
- content : {
65
- name : 'data-driven-forms-example' ,
66
- version : '1.0.0' ,
67
- description : '' ,
68
- keywords : [ ] ,
69
- main : 'src/index.js' ,
70
- dependencies : {
71
- '@data-driven-forms/mui-component-mapper' : '2.1.2' ,
72
- '@data-driven-forms/pf4-component-mapper' : '2.1.2' ,
73
- '@data-driven-forms/react-form-renderer' : '2.1.2' ,
74
- react : '16.12.0' ,
75
- 'react-dom' : '16.12.0' ,
76
- 'react-scripts' : '3.0.1'
77
- } ,
78
- devDependencies : { typescript : '3.8.3' } ,
79
- scripts : { start : 'react-scripts start' , build : 'react-scripts build' , test : 'react-scripts test --env=jsdom' , eject : 'react-scripts eject' } ,
80
- browserslist : [ '>0.2%' , 'not dead' , 'not ie <= 11' , 'not op_mini all' ]
57
+ /**
58
+ * Generates html markup for the sandbox
59
+ * @param {String } type either MUI or PF4
60
+ */
61
+ const generateIndex = ( type ) => `<!DOCTYPE html>
62
+ <html lang="en">
63
+ <head>
64
+ <meta charset="utf-8" />
65
+ <meta
66
+ name="viewport"
67
+ content="width=device-width, initial-scale=1, shrink-to-fit=no"
68
+ />
69
+ <meta name="theme-color" content="#000000" />
70
+ <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
71
+ <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
72
+ <title>Data driven forms example</title>
73
+ ${ type === 'mui' ? '<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500">' : '' }
74
+ ${
75
+ type === 'pf4'
76
+ ? `
77
+ <link rel="stylesheet" type="text/css" href="https://unpkg.com/@patternfly/[email protected] /patternfly-base.css"/>
78
+ <link rel="stylesheet" type="text/css" href="https://unpkg.com/@patternfly/[email protected] /patternfly-addons.css"/>
79
+ `
80
+ : ''
81
+ }
82
+ </head>
83
+
84
+ <body>
85
+ <noscript>
86
+ You need to enable JavaScript to run this app.
87
+ </noscript>
88
+ <div id="root" style="padding: 16px;"></div>
89
+ </body>
90
+ </html>
91
+ ` ;
92
+
93
+ const getPayload = ( type , code ) =>
94
+ getParameters ( {
95
+ files : {
96
+ 'public/index.html' : {
97
+ content : generateIndex ( type )
98
+ } ,
99
+ 'package.json' : {
100
+ content : {
101
+ name : 'data-driven-forms-example' ,
102
+ version : '1.0.0' ,
103
+ description : '' ,
104
+ keywords : [ ] ,
105
+ main : 'src/index.js' ,
106
+ dependencies : {
107
+ '@data-driven-forms/mui-component-mapper' : '2.1.2' ,
108
+ '@data-driven-forms/pf4-component-mapper' : '2.1.2' ,
109
+ '@data-driven-forms/react-form-renderer' : '2.1.2' ,
110
+ '@patternfly/react-core' : 'latest' ,
111
+ '@patternfly/react-icons' : 'latest' ,
112
+ '@material-ui/core' : 'latest' ,
113
+ '@material-ui/icons' : 'latest' ,
114
+ react : '16.12.0' ,
115
+ 'react-dom' : '16.12.0' ,
116
+ 'react-scripts' : '3.0.1'
117
+ } ,
118
+ devDependencies : { typescript : '3.8.3' } ,
119
+ scripts : {
120
+ start : 'react-scripts start' ,
121
+ build : 'react-scripts build' ,
122
+ test : 'react-scripts test --env=jsdom' ,
123
+ eject : 'react-scripts eject'
124
+ } ,
125
+ browserslist : [ '>0.2%' , 'not dead' , 'not ie <= 11' , 'not op_mini all' ]
126
+ }
127
+ } ,
128
+ 'src/index.js' : {
129
+ content :
130
+ 'import React from "react";\nimport ReactDOM from "react-dom";\n\nimport App from "./App";\n\nconst rootElement = document.getElementById("root");\nReactDOM.render(\n <React.StrictMode>\n <App />\n </React.StrictMode>,\n rootElement\n);\n'
131
+ } ,
132
+ 'src/App.js' : {
133
+ content : code
81
134
}
82
- } ,
83
- 'src/index.js' : {
84
- content :
85
- 'import React from "react";\nimport ReactDOM from "react-dom";\n\nimport App from "./App";\n\nconst rootElement = document.getElementById("root");\nReactDOM.render(\n <React.StrictMode>\n <App />\n </React.StrictMode>,\n rootElement\n);\n'
86
- } ,
87
- 'src/App.js' : {
88
- content : 'import React from "react";\n\nexport default function App() {\n return <div>there will be dragons</div>;\n}\n'
89
135
}
90
- }
91
- } ) ;
92
-
93
- console . log ( payload ) ;
136
+ } ) ;
94
137
95
138
const CodeExample = ( { source, mode } ) => {
96
139
const classes = useStyles ( ) ;
@@ -107,7 +150,7 @@ const CodeExample = ({ source, mode }) => {
107
150
{ Component && < Typography className = { classes . heading } > { Component . name } </ Typography > }
108
151
< Box display = "flex" >
109
152
< form action = "https://codesandbox.io/api/v1/sandboxes/define" method = "POST" target = "_blank" >
110
- < input type = "hidden" name = "parameters" value = { payload } />
153
+ < input type = "hidden" name = "parameters" value = { getPayload ( 'pf4' , codeSource ) } />
111
154
< input type = "submit" value = "Open in sandbox" />
112
155
</ form >
113
156
< Link
0 commit comments