@@ -45,10 +45,22 @@ export default defineComponent({
45
45
return examples .find ((ex ) => ex .name === name )! ;
46
46
},
47
47
},
48
+ beforeMount() {
49
+ const searchURL = new URL (String (window .location ));
50
+ const name = searchURL .hash ?.substring (1 );
51
+ const exists = name && examples .find ((ex ) => ex .name === name );
52
+ if (name && exists ) {
53
+ this .currentExampleName = name ;
54
+ }
55
+ },
48
56
methods: {
49
57
onChange(event : JsonFormsChangeEvent ) {
50
58
console .log (event );
51
59
this .data = event .data ;
60
+
61
+ const searchURL = new URL (String (window .location ));
62
+ searchURL .hash = this .currentExampleName ;
63
+ window .history .pushState ({}, ' ' , searchURL );
52
64
},
53
65
onExampleChange(event : any ) {
54
66
this .currentExampleName = event .target .value ;
@@ -73,7 +85,40 @@ export default defineComponent({
73
85
74
86
<template >
75
87
<div class =" container" >
76
- <div className =" example-selector" >
88
+ <header >
89
+ <h1 >Welcome to JSON Forms with Vue Vanilla</h1 >
90
+ <p >More Forms. Less Code.</p >
91
+ </header >
92
+
93
+ <aside class =" example-selector" >
94
+ <div class =" data" >
95
+ <details >
96
+ <summary >data</summary >
97
+ <pre
98
+ >{{ JSON.stringify(data, null, 2) }}
99
+ </pre >
100
+ </details >
101
+
102
+ <details >
103
+ <summary >schema</summary >
104
+ <pre
105
+ >{{ JSON.stringify(example.schema, null, 2) }}
106
+ </pre >
107
+ </details >
108
+
109
+ <details >
110
+ <summary >uischema</summary >
111
+ <pre
112
+ >{{ JSON.stringify(example.uischema, null, 2) }}
113
+ </pre >
114
+ </details >
115
+
116
+ <h5 >i18n translator</h5 >
117
+ <textarea @change =" translationChange" ></textarea >
118
+ </div >
119
+ </aside >
120
+
121
+ <div class =" tools" >
77
122
<h4 >Select Example:</h4 >
78
123
<select v-model =" currentExampleName" @change =" onExampleChange($event)" >
79
124
<option
@@ -85,42 +130,94 @@ export default defineComponent({
85
130
{{ option.label }}
86
131
</option >
87
132
</select >
88
- <div class =" data" >
89
- <h5 >data</h5 >
90
- <pre
91
- >{{ JSON.stringify(data, null, 2) }}
92
- </pre >
93
- <h5 >i18n translator</h5 >
94
- <textarea @change =" translationChange" ></textarea >
95
- </div >
96
133
</div >
97
134
98
- <div class =" form" >
99
- <json-forms
100
- :key =" example.name"
101
- :data =" example.data"
102
- :schema =" example.schema"
103
- :uischema =" example.uischema"
104
- :renderers =" renderers"
105
- :config =" config"
106
- :i18n =" i18n"
107
- :additional-errors =" additionalErrors"
108
- @change =" onChange"
109
- >
110
- </json-forms >
111
- </div >
135
+ <main class =" form" >
136
+ <article >
137
+ <json-forms
138
+ :key =" example.name"
139
+ :data =" example.data"
140
+ :schema =" example.schema"
141
+ :uischema =" example.uischema"
142
+ :renderers =" renderers"
143
+ :config =" config"
144
+ :i18n =" i18n"
145
+ :additional-errors =" additionalErrors"
146
+ @change =" onChange"
147
+ >
148
+ </json-forms >
149
+ </article >
150
+ </main >
112
151
</div >
113
152
</template >
114
153
115
154
<style scoped>
116
- .form {
117
- max-width : 500px ;
118
- flex : 1 ;
119
- }
120
155
.container {
156
+ display : grid ;
157
+ grid-template-columns : 0 30% auto 0 ;
158
+ grid-column-gap : 2rem ;
159
+ grid-row-gap : 1rem ;
160
+ grid-template-areas :
161
+ ' header header header header'
162
+ ' . tools tools .'
163
+ ' . aside main .' ;
164
+ }
165
+ .container > header {
166
+ grid-area : header;
167
+
168
+ background-color : #00021e ;
169
+ padding : 2rem ;
170
+ color : white ;
171
+ text-align : center ;
172
+ }
173
+ .container > aside {
174
+ grid-area : aside;
175
+ }
176
+ .container > main {
177
+ grid-area : main;
178
+ }
179
+ .container > .tools {
180
+ grid-area : tools;
181
+
121
182
display : flex ;
183
+ align-items : center ;
184
+ justify-content : center ;
185
+ gap : 1rem ;
186
+ }
187
+
188
+ aside .data {
189
+ background-color : white ;
190
+ padding : 2rem ;
122
191
}
123
- .data {
124
- flex : 1 ;
192
+ aside summary ,
193
+ aside h5 {
194
+ font-size : 0.83em ;
195
+ font-weight : bold ;
196
+ margin : 0 0 1em ;
197
+ }
198
+ aside summary {
199
+ cursor : default ;
200
+ }
201
+ aside details pre {
202
+ background : #eee ;
203
+ border : 0 ;
204
+ min-height : 300px ;
205
+ max-height : 500px ;
206
+ overflow : scroll ;
207
+ }
208
+
209
+ main article {
210
+ background-color : white ;
211
+ padding : 1rem ;
212
+ }
213
+ </style >
214
+
215
+
216
+ <style >
217
+ body {
218
+ margin : 0 ;
219
+ padding : 0 ;
220
+ font-family : sans-serif ;
221
+ background : #f3f4fa ;
125
222
}
126
223
</style >
0 commit comments