-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathApp.vue
More file actions
156 lines (142 loc) · 3.07 KB
/
App.vue
File metadata and controls
156 lines (142 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<script setup lang="ts">
import { ref, provide } from "vue";
import { JsonForms, JsonFormsChangeEvent } from "@jsonforms/vue";
import { defaultStyles, mergeStyles, vanillaRenderers } from "@jsonforms/vue-vanilla";
const renderers = Object.freeze([
...vanillaRenderers,
// here you can add custom renderers
]);
const schema = {
properties: {
name: {
type: "string",
minLength: 1,
description: "The task's name"
},
description: {
title: "Long Description",
type: "string",
},
done: {
type: "boolean",
},
dueDate: {
type: "string",
format: "date",
description: "The task's due date"
},
rating: {
type: "integer",
maximum: 5,
},
recurrence: {
type: "string",
enum: ["Never", "Daily", "Weekly", "Monthly"]
},
recurrenceInterval: {
type: "integer",
description: "Days until recurrence"
},
},
};
const uischema = {
type: "HorizontalLayout",
elements: [
{
type: "VerticalLayout",
elements: [
{
type: "Control",
scope: "#/properties/name",
},
{
type: "Control",
scope: "#/properties/description",
options: {
multi: true,
}
},
{
type: "Control",
scope: "#/properties/done",
},
],
},
{
type: "VerticalLayout",
elements: [
{
type: "Control",
scope: "#/properties/dueDate",
},
{
type: "Control",
scope: "#/properties/rating",
},
{
type: "Control",
scope: "#/properties/recurrence",
},
{
type: "Control",
scope: "#/properties/recurrenceInterval",
},
],
},
],
};
const data = ref({
name: "Send email to Adrian",
description: "Confirm if you have passed the subject\nHereby ...",
done: true,
recurrence: "Daily",
rating: 3,
});
const onChange = (event: JsonFormsChangeEvent) => {
data.value = event.data;
};
// mergeStyles combines all classes from both styles definitions into one
const myStyles = mergeStyles(defaultStyles, { control: { label: "mylabel" } });
// Provide styles to child components
provide('styles', myStyles);
</script>
<template>
<img alt="Vue logo" src="./assets/logo.png" />
<h1>JSON Forms Vue 3</h1>
<div class="myform">
<json-forms :data="data" :renderers="renderers" :schema="schema" :uischema="uischema" @change="onChange" />
</div>
<pre>{{ data }}</pre>
</template>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
margin-left: 120px;
margin-right: 120px;
}
.mylabel {
color: darkslategrey;
}
.vertical-layout {
margin-left: 10px;
margin-right: 10px;
}
.myform {
width: 640px;
margin: 0 auto;
}
.text-area {
min-height: 80px;
}
pre {
background: lightcyan;
padding: 10px;
text-align: left;
width: 100%;
}
</style>