Skip to content

dev: add simple grid layout to the dev app. save example name at location hash. show schema and uischema #2269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 126 additions & 29 deletions packages/vue-vanilla/dev/components/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,22 @@ export default defineComponent({
return examples.find((ex) => ex.name === name)!;
},
},
beforeMount() {
const searchURL = new URL(String(window.location));
const name = searchURL.hash?.substring(1);
const exists = name && examples.find((ex) => ex.name === name);
if (name && exists) {
this.currentExampleName = name;
}
},
methods: {
onChange(event: JsonFormsChangeEvent) {
console.log(event);
this.data = event.data;

const searchURL = new URL(String(window.location));
searchURL.hash = this.currentExampleName;
window.history.pushState({}, '', searchURL);
},
onExampleChange(event: any) {
this.currentExampleName = event.target.value;
Expand All @@ -76,7 +88,40 @@ export default defineComponent({

<template>
<div class="container">
<div className="example-selector">
<header>
<h1>Welcome to JSON Forms with Vue Vanilla</h1>
<p>More Forms. Less Code.</p>
</header>

<aside class="example-selector">
<div class="data">
<details>
<summary>data</summary>
<pre
>{{ JSON.stringify(data, null, 2) }}
</pre>
</details>

<details>
<summary>schema</summary>
<pre
>{{ JSON.stringify(example.schema, null, 2) }}
</pre>
</details>

<details>
<summary>uischema</summary>
<pre
>{{ JSON.stringify(example.uischema, null, 2) }}
</pre>
</details>

<h5>i18n translator</h5>
<textarea @change="translationChange"></textarea>
</div>
</aside>

<div class="tools">
<h4>Select Example:</h4>
<select v-model="currentExampleName" @change="onExampleChange($event)">
<option
Expand All @@ -88,42 +133,94 @@ export default defineComponent({
{{ option.label }}
</option>
</select>
<div class="data">
<h5>data</h5>
<pre
>{{ JSON.stringify(data, null, 2) }}
</pre>
<h5>i18n translator</h5>
<textarea @change="translationChange"></textarea>
</div>
</div>

<div class="form">
<json-forms
:key="example.name"
:data="example.data"
:schema="example.schema"
:uischema="example.uischema"
:renderers="renderers"
:config="config"
:i18n="i18n"
:additional-errors="additionalErrors"
@change="onChange"
>
</json-forms>
</div>
<main class="form">
<article>
<json-forms
:key="example.name"
:data="example.data"
:schema="example.schema"
:uischema="example.uischema"
:renderers="renderers"
:config="config"
:i18n="i18n"
:additional-errors="additionalErrors"
@change="onChange"
>
</json-forms>
</article>
</main>
</div>
</template>

<style scoped>
.form {
max-width: 500px;
flex: 1;
}
.container {
display: grid;
grid-template-columns: 0 30% auto 0;
grid-column-gap: 2rem;
grid-row-gap: 1rem;
grid-template-areas:
'header header header header'
'. tools tools .'
'. aside main .';
}
.container > header {
grid-area: header;

background-color: #00021e;
padding: 2rem;
color: white;
text-align: center;
}
.container > aside {
grid-area: aside;
}
.container > main {
grid-area: main;
}
.container > .tools {
grid-area: tools;

display: flex;
align-items: center;
justify-content: center;
gap: 1rem;
}

aside .data {
background-color: white;
padding: 2rem;
}
.data {
flex: 1;
aside summary,
aside h5 {
font-size: 0.83em;
font-weight: bold;
margin: 0 0 1em;
}
aside summary {
cursor: default;
}
aside details pre {
background: #eee;
border: 0;
min-height: 300px;
max-height: 500px;
overflow: scroll;
}

main article {
background-color: white;
padding: 1rem;
}
</style>


<style>
body {
margin: 0;
padding: 0;
font-family: sans-serif;
background: #f3f4fa;
}
</style>