1
1
# FN-Scheme
2
2
#### Form schema component for Naive UI framework. Generate form from json like formkit schema component
3
- ## Documentation [ link] ( # )
4
3
5
- Package type: ` Module `
4
+ - Package type: ` Module `
5
+ - Original size: ` ??? `
6
+ - Bzip + minify: ` ??? `
6
7
7
8
8
9
#### TREE
9
10
- [ How to use] ( #how-to-use )
10
-
11
-
11
+ - [ Available components] ( #available-components )
12
12
13
13
14
14
### How to Use
@@ -28,7 +28,7 @@ import { FnSchema } from '@francyfox/fn-forms'
28
28
import { NaiveUISchema } from "@francyfox/fn-forms/module/schema";
29
29
30
30
const json = {
31
- $type: 'form',
31
+ $type: 'n- form',
32
32
children: []
33
33
} as NaiveUISchema
34
34
</script>
@@ -38,6 +38,192 @@ const json = {
38
38
</template>
39
39
```
40
40
41
+ 1 . Json start with form wrapper (` $type: 'form' ` )
42
+ 2 . In children create our form elements
43
+
44
+ ##### JSON API
45
+
46
+ - ` $type ` equal component name (like <n-form >)
47
+ - ` $prop ` equal component props
48
+ - ` $children ` equal component slot. U can use string for default slot, array for children (h - render functions)
49
+ json elements or object with slot functions ` { default: () => 'button text'} `
50
+
51
+ ##### Json test scheme
52
+ ``` json
53
+ [
54
+ {
55
+ $type: 'n-form',
56
+ $children: [
57
+ {
58
+ $type: 'n-space',
59
+ $children: [
60
+ {
61
+ $type: 'n-form-item',
62
+ $props: {
63
+ label: 'Name',
64
+ path: 'user.name',
65
+ },
66
+ $children: [
67
+ {
68
+ $type: 'n-input',
69
+ $props: {
70
+ placeholder: 'Input Name',
71
+ value: '$data.user.name',
72
+ },
73
+ },
74
+ ],
75
+ },
76
+ {
77
+ $type: 'n-form-item',
78
+ $props: {
79
+ label: 'Email',
80
+ path: 'user.email',
81
+ },
82
+ $children: [
83
+ {
84
+ $type: 'n-input',
85
+ $props: {
86
+ type: 'email',
87
+ placeholder: 'Input Email',
88
+ value: '$data.user.email',
89
+ },
90
+ },
91
+ ],
92
+ },
93
+ ],
94
+ },
95
+ {
96
+ $type: 'n-form-item',
97
+ $props: {
98
+ label: 'Age',
99
+ path: 'user.age',
100
+ },
101
+ $children: [
102
+ {
103
+ $type: 'n-input-number',
104
+ $props: {
105
+ placeholder: 'Input age',
106
+ clearable: true,
107
+ value: '$data.user.age',
108
+ },
109
+ },
110
+ ],
111
+ },
112
+ {
113
+ $type: 'n-form-item',
114
+ $props: {
115
+ label: 'Age',
116
+ path: 'user.agree',
117
+ },
118
+ $children: [
119
+ {
120
+ $type: 'n-checkbox',
121
+ $children: 'I agree',
122
+ $props: {
123
+ placeholder: 'Agree?',
124
+ value: '$data.user.agree',
125
+ },
126
+ },
127
+ ],
128
+ },
129
+ {
130
+ $type: 'n-form-item',
131
+ $props: {
132
+ label: 'Gender',
133
+ path: 'user.gender',
134
+ },
135
+ $children: [
136
+ {
137
+ $type: 'n-select',
138
+ $children: 'I agree',
139
+ $props: {
140
+ multiple: true,
141
+ value: '$data.user.gender',
142
+ options: [
143
+ {
144
+ label: 'Nowhere Man',
145
+ value: 'song4',
146
+ },
147
+ {
148
+ label: 'Think For Yourself',
149
+ value: 'song5',
150
+ },
151
+ ],
152
+ },
153
+ },
154
+ ],
155
+ },
156
+ {
157
+ $type: 'n-radio-group',
158
+ $props: {
159
+ value: '$data.user.live',
160
+ name: 'state'
161
+ },
162
+ $children: [
163
+ {
164
+ $type: 'n-radio',
165
+ $children: 'Live!',
166
+ $props: {
167
+ value: 'live',
168
+ },
169
+ },
170
+ {
171
+ $type: 'n-radio',
172
+ $children: 'Dead!',
173
+ $props: {
174
+ label: 'Dead!',
175
+ value: 'dead',
176
+ },
177
+ },
178
+ ],
179
+ },
180
+ {
181
+ $type: 'n-form-item',
182
+ $children: [
183
+ {
184
+ $type: 'n-switch',
185
+ $children: {
186
+ checked: () => 'TEst',
187
+ unchecked: () => 'NonTest'
188
+ },
189
+ $props: {
190
+ value: '$data.user.test',
191
+ railStyle: () => 'background: red'
192
+ }
193
+ }
194
+ ]
195
+ },
196
+ {
197
+ $type: 'n-form-item',
198
+ $children: [
199
+ {
200
+ $type: 'n-button',
201
+ $children: 'Send Form',
202
+ },
203
+ ],
204
+ },
205
+
206
+ ],
207
+ },
208
+ ]
209
+ ```
210
+
211
+ ``` ts
212
+ const formData = ref ({
213
+ user: {
214
+ name: ' francyfox' ,
215
+ email: ' test@mail.ru' ,
216
+ age: 16 ,
217
+ agree: true ,
218
+ gender: [' song4' ],
219
+ live: ' live' ,
220
+ test: false
221
+ },
222
+ });
223
+ ```
224
+ ![ image] ( 2023-05-23_13-51.png )
225
+
226
+
41
227
#### Available components:
42
228
- Form
43
229
- Input
0 commit comments