Skip to content

Commit 0cec549

Browse files
authored
dev: Improve vue vanilla dev app layout and example selection (#2269)
- Add simple grid layout to the vue vanilla dev app - save example name at location hash - show schema and uischema
1 parent 07a96dc commit 0cec549

File tree

1 file changed

+126
-29
lines changed
  • packages/vue-vanilla/dev/components

1 file changed

+126
-29
lines changed

packages/vue-vanilla/dev/components/App.vue

Lines changed: 126 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,22 @@ export default defineComponent({
4545
return examples.find((ex) => ex.name === name)!;
4646
},
4747
},
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+
},
4856
methods: {
4957
onChange(event: JsonFormsChangeEvent) {
5058
console.log(event);
5159
this.data = event.data;
60+
61+
const searchURL = new URL(String(window.location));
62+
searchURL.hash = this.currentExampleName;
63+
window.history.pushState({}, '', searchURL);
5264
},
5365
onExampleChange(event: any) {
5466
this.currentExampleName = event.target.value;
@@ -73,7 +85,40 @@ export default defineComponent({
7385

7486
<template>
7587
<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">
77122
<h4>Select Example:</h4>
78123
<select v-model="currentExampleName" @change="onExampleChange($event)">
79124
<option
@@ -85,42 +130,94 @@ export default defineComponent({
85130
{{ option.label }}
86131
</option>
87132
</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>
96133
</div>
97134

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>
112151
</div>
113152
</template>
114153

115154
<style scoped>
116-
.form {
117-
max-width: 500px;
118-
flex: 1;
119-
}
120155
.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+
121182
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;
122191
}
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;
125222
}
126223
</style>

0 commit comments

Comments
 (0)