@axdspub/axiom-ui-forms 0.2.10 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +440 -272
- package/library/axiom-ui-forms.d.ts +107 -33
- package/library/esm/_virtual/index10.js +2 -2
- package/library/esm/_virtual/index12.js +2 -6
- package/library/esm/_virtual/index12.js.map +1 -1
- package/library/esm/_virtual/index13.js +2 -6
- package/library/esm/_virtual/index13.js.map +1 -1
- package/library/esm/_virtual/index3.js +2 -2
- package/library/esm/_virtual/index3.js.map +1 -1
- package/library/esm/_virtual/index6.js +2 -2
- package/library/esm/_virtual/index7.js +6 -2
- package/library/esm/_virtual/index7.js.map +1 -1
- package/library/esm/_virtual/index8.js +6 -2
- package/library/esm/_virtual/index8.js.map +1 -1
- package/library/esm/_virtual/index9.js +2 -2
- package/library/esm/node_modules/@axdspub/axiom-ui-utilities/library/index.js +1 -1
- package/library/esm/node_modules/@axdspub/axiom-ui-utilities/library/index.js.map +1 -1
- package/library/esm/node_modules/@radix-ui/react-icons/dist/react-icons.esm.js +23 -1
- package/library/esm/node_modules/@radix-ui/react-icons/dist/react-icons.esm.js.map +1 -1
- package/library/esm/node_modules/ajv/dist/compile/index.js +1 -1
- package/library/esm/node_modules/ajv/dist/vocabularies/applicator/index.js +1 -1
- package/library/esm/node_modules/ajv/dist/vocabularies/core/index.js +1 -1
- package/library/esm/node_modules/ajv/dist/vocabularies/discriminator/index.js +1 -1
- package/library/esm/node_modules/ajv/dist/vocabularies/format/index.js +1 -1
- package/library/esm/node_modules/hast-util-to-jsx-runtime/lib/index.js +1 -1
- package/library/esm/node_modules/jotai/esm/react.js +135 -0
- package/library/esm/node_modules/jotai/esm/react.js.map +1 -0
- package/library/esm/node_modules/jotai/esm/vanilla/internals.js +551 -0
- package/library/esm/node_modules/jotai/esm/vanilla/internals.js.map +1 -0
- package/library/esm/node_modules/jotai/esm/vanilla.js +111 -0
- package/library/esm/node_modules/jotai/esm/vanilla.js.map +1 -0
- package/library/esm/node_modules/react-router/dist/development/chunk-HA7DTUK3.js +1 -1
- package/library/esm/node_modules/unified/lib/index.js +1 -1
- package/library/esm/src/Form/Components/FieldCreator.js +20 -5
- package/library/esm/src/Form/Components/FieldCreator.js.map +1 -1
- package/library/esm/src/Form/Components/FieldLabel.js +1 -1
- package/library/esm/src/Form/Components/FieldLabel.js.map +1 -1
- package/library/esm/src/Form/Components/InlineMarkdown.js.map +1 -1
- package/library/esm/src/Form/Components/Inputs/Boolean.js.map +1 -1
- package/library/esm/src/Form/Components/Inputs/Constant.js.map +1 -1
- package/library/esm/src/Form/Components/Inputs/Date.js.map +1 -1
- package/library/esm/src/Form/Components/Inputs/DateTime.js.map +1 -1
- package/library/esm/src/Form/Components/Inputs/GeoJSON.js.map +1 -1
- package/library/esm/src/Form/Components/Inputs/GeoJSONInputLoader.js.map +1 -1
- package/library/esm/src/Form/Components/Inputs/Geometry.js +1 -1
- package/library/esm/src/Form/Components/Inputs/Geometry.js.map +1 -1
- package/library/esm/src/Form/Components/Inputs/GeometryInputLoader.js.map +1 -1
- package/library/esm/src/Form/Components/Inputs/JSON.js +64 -33
- package/library/esm/src/Form/Components/Inputs/JSON.js.map +1 -1
- package/library/esm/src/Form/Components/Inputs/JSONInputLoader.js.map +1 -1
- package/library/esm/src/Form/Components/Inputs/LongString.js.map +1 -1
- package/library/esm/src/Form/Components/Inputs/Number.js +34 -9
- package/library/esm/src/Form/Components/Inputs/Number.js.map +1 -1
- package/library/esm/src/Form/Components/Inputs/Object.js.map +1 -1
- package/library/esm/src/Form/Components/Inputs/OneOfInput.js.map +1 -1
- package/library/esm/src/Form/Components/Inputs/RadioGroup.js.map +1 -1
- package/library/esm/src/Form/Components/Inputs/SingleSelect.js +2 -1
- package/library/esm/src/Form/Components/Inputs/SingleSelect.js.map +1 -1
- package/library/esm/src/Form/Components/Inputs/String.js.map +1 -1
- package/library/esm/src/Form/Components/Inputs/Time.js.map +1 -1
- package/library/esm/src/Form/Components/Inputs/index.js +11 -0
- package/library/esm/src/Form/Components/Inputs/index.js.map +1 -0
- package/library/esm/src/Form/Components/Inputs/inputMap.js.map +1 -1
- package/library/esm/src/Form/Creator/FormContextProvider.js.map +1 -1
- package/library/esm/src/Form/Creator/FormCreator.js +17 -8
- package/library/esm/src/Form/Creator/FormCreator.js.map +1 -1
- package/library/esm/src/Form/Creator/FormFields.js +1 -1
- package/library/esm/src/Form/Creator/FormFields.js.map +1 -1
- package/library/esm/src/Form/Creator/FormHeader.js.map +1 -1
- package/library/esm/src/Form/Creator/FormSection.js.map +1 -1
- package/library/esm/src/Form/Creator/FormSectionContextProvider.js.map +1 -1
- package/library/esm/src/Form/Creator/NavElement.js.map +1 -1
- package/library/esm/src/Form/Creator/Page.js +44 -8
- package/library/esm/src/Form/Creator/Page.js.map +1 -1
- package/library/esm/src/Form/Creator/Wizard.js +78 -21
- package/library/esm/src/Form/Creator/Wizard.js.map +1 -1
- package/library/esm/src/Form/Manage/CopyableJSONOutput.js +3 -3
- package/library/esm/src/Form/Manage/CopyableJSONOutput.js.map +1 -1
- package/library/esm/src/library.js +9 -14
- package/library/esm/src/library.js.map +1 -1
- package/library/esm/src/utils/getters.js +33 -3
- package/library/esm/src/utils/getters.js.map +1 -1
- package/library/esm/src/utils/manipulators.js +80 -3
- package/library/esm/src/utils/manipulators.js.map +1 -1
- package/library/esm/src/utils/resolveRefs.js +44 -0
- package/library/esm/src/utils/resolveRefs.js.map +1 -0
- package/library/esm/src/utils/responsive/layoutState.js +18 -0
- package/library/esm/src/utils/responsive/layoutState.js.map +1 -0
- package/library/esm/src/utils/schemaToFormHelpers.js +157 -39
- package/library/esm/src/utils/schemaToFormHelpers.js.map +1 -1
- package/library/esm/src/utils/validators.js +4 -2
- package/library/esm/src/utils/validators.js.map +1 -1
- package/package.json +131 -129
- package/library/esm/src/Form/resolveRefs.js +0 -26
- package/library/esm/src/Form/resolveRefs.js.map +0 -1
package/README.md
CHANGED
@@ -1,272 +1,440 @@
|
|
1
|
-
React library that allows:
|
2
|
-
- Creation of forms using a json config file
|
3
|
-
- Creation of forms using a [json schema draft 7](https://json-schema.org/draft-07/json-schema-release-notes), with selective overrides using json config
|
4
|
-
- To do:
|
5
|
-
- allow addition of new form types and UI components by consuming library
|
6
|
-
- allow schema version 4 and draft 6
|
7
|
-
- support schema `required`
|
8
|
-
- support version 7 `if`/`then`/`else`
|
9
|
-
- support version 7 `readOnly`
|
10
|
-
- support version 7 `writeOnly`
|
11
|
-
|
12
|
-
|
13
|
-
.
|
14
|
-
|
15
|
-
# [Examples](https://axiom-ui-forms.srv.axds.co/)
|
16
|
-
|
17
|
-
## Create a form using a config
|
18
|
-
|
19
|
-
Test form config [here](https://axiom-ui-forms.srv.axds.co/). Note: currently, forms with wizards or pages require that the parent route includes `*` (only tested with `react-router-dom@7`). Todo: make url navigation on form optional.
|
20
|
-
|
21
|
-
```json
|
22
|
-
{
|
23
|
-
"id": "example",
|
24
|
-
"label": "Example form",
|
25
|
-
"description": "This is just an example",
|
26
|
-
"fields": [
|
27
|
-
{
|
28
|
-
"id": "title",
|
29
|
-
"type": "text",
|
30
|
-
"label": "Title"
|
31
|
-
},
|
32
|
-
{
|
33
|
-
"id": "description",
|
34
|
-
"type": "long_text",
|
35
|
-
"label": "Description"
|
36
|
-
},
|
37
|
-
{
|
38
|
-
"id": "favorites",
|
39
|
-
"type": "text",
|
40
|
-
"label": "List your favorite things",
|
41
|
-
"multiple": true
|
42
|
-
},
|
43
|
-
{
|
44
|
-
"id": "agree",
|
45
|
-
"type": "boolean",
|
46
|
-
"label": "Do you agree?"
|
47
|
-
},
|
48
|
-
{
|
49
|
-
"id": "signature",
|
50
|
-
"type": "text",
|
51
|
-
"label": "Sign your name then",
|
52
|
-
"conditions": { "dependsOn": "agree" }
|
53
|
-
}
|
54
|
-
]
|
55
|
-
}
|
56
|
-
```
|
57
|
-
|
58
|
-
```ts
|
59
|
-
import React, {type ReactElement} from 'react'
|
60
|
-
import { FormCreator, type IForm, type IFormValues } from '@axdspub/axiom-ui-forms'
|
61
|
-
|
62
|
-
export default ExampleForm = ({formConfig}: {formConfig: IForm}): ReactElement => {
|
63
|
-
const formValueState = React.useState<IFormValues>({})
|
64
|
-
const [formValues] = formValueState
|
65
|
-
useEffect(()=>{
|
66
|
-
// respond to change in formValues
|
67
|
-
},[formValues])
|
68
|
-
|
69
|
-
return (
|
70
|
-
<FormCreator form={formConfig} formValueState={formValueState} />
|
71
|
-
)
|
72
|
-
}
|
73
|
-
|
74
|
-
```
|
75
|
-
|
76
|
-
## Config to create a form with wizard steps using config.
|
77
|
-
Example [here](https://axiom-ui-forms.srv.axds.co/?tab=config&form=uQAEYmlkZ2V4YW1wbGVlbGFiZWxsRXhhbXBsZSBmb3Jta2Rlc2NyaXB0aW9ud1RoaXMgaXMganVzdCBhbiBleGFtcGxlbHdpemFyZF9zdGVwc4O5AARiaWRlaW50cm9lbGFiZWxsSW50cm9kdWN0aW9uZW9yZGVyAGZmaWVsZHOCuQADYmlkZXRpdGxlZHR5cGVkdGV4dGVsYWJlbGVUaXRsZbkAA2JpZGtkZXNjcmlwdGlvbmR0eXBlaWxvbmdfdGV4dGVsYWJlbGtEZXNjcmlwdGlvbrkABGJpZGNtYXBlbGFiZWxmU3RlcCAyZW9yZGVyAWZmaWVsZHOBuQADYmlkY21hcGR0eXBlZ2dlb2pzb25lbGFiZWxoTG9jYXRpb265AARiaWRlYWJvdXRlbGFiZWxuQWJvdXQgeW91cnNlbGZlb3JkZXICZXBhZ2VzgrkAA2JpZGlmYXZvcml0ZXNlbGFiZWxpRmF2b3JpdGVzZmZpZWxkc4G5AARiaWRuZmF2b3JpdGVzX2xpc3RkdHlwZWR0ZXh0ZWxhYmVseBlMaXN0IHlvdXIgZmF2b3JpdGUgdGhpbmdzaG11bHRpcGxl9bkAA2JpZGRzaWduZWxhYmVsaVNpZ25hdHVyZWZmaWVsZHOCuQADYmlkZWFncmVlZHR5cGVnYm9vbGVhbmVsYWJlbG1EbyB5b3UgYWdyZWU%2FuQADYmlkaXNpZ25hdHVyZWR0eXBlZHRleHRlbGFiZWxzU2lnbiB5b3VyIG5hbWUgdGhlbg%3D%3D).
|
78
|
-
|
79
|
-
```json
|
80
|
-
{
|
81
|
-
"id": "example",
|
82
|
-
"label": "Example form",
|
83
|
-
"description": "This is just an example",
|
84
|
-
"wizard_steps":[
|
85
|
-
{
|
86
|
-
"id":"intro",
|
87
|
-
"label":"Introduction",
|
88
|
-
"order": 0,
|
89
|
-
"fields":[
|
90
|
-
{
|
91
|
-
"id": "title",
|
92
|
-
"type": "text",
|
93
|
-
"label": "Title"
|
94
|
-
},
|
95
|
-
{
|
96
|
-
"id": "description",
|
97
|
-
"type": "long_text",
|
98
|
-
"label": "Description"
|
99
|
-
}
|
100
|
-
]
|
101
|
-
|
102
|
-
},
|
103
|
-
{
|
104
|
-
"id": "map",
|
105
|
-
"label": "Step 2",
|
106
|
-
"order": 1,
|
107
|
-
"fields": [
|
108
|
-
{
|
109
|
-
"id": "map",
|
110
|
-
"type": "geojson",
|
111
|
-
"label": "Location"
|
112
|
-
}
|
113
|
-
]
|
114
|
-
},
|
115
|
-
{
|
116
|
-
"id": "about",
|
117
|
-
"label": "About yourself",
|
118
|
-
"order": 2,
|
119
|
-
"pages":[
|
120
|
-
{
|
121
|
-
"id": "favorites",
|
122
|
-
"label": "Favorites",
|
123
|
-
"fields": [
|
124
|
-
{
|
125
|
-
"id": "favorites_list",
|
126
|
-
"type": "text",
|
127
|
-
"label": "List your favorite things",
|
128
|
-
"multiple": true
|
129
|
-
}
|
130
|
-
]
|
131
|
-
},
|
132
|
-
{
|
133
|
-
"id":"sign",
|
134
|
-
"label": "Signature",
|
135
|
-
"fields": [
|
136
|
-
{
|
137
|
-
"id": "agree",
|
138
|
-
"type": "boolean",
|
139
|
-
"label": "Do you agree?"
|
140
|
-
},
|
141
|
-
{
|
142
|
-
"id": "signature",
|
143
|
-
"type": "text",
|
144
|
-
"label": "Sign your name then"
|
145
|
-
}
|
146
|
-
]
|
147
|
-
}
|
148
|
-
]
|
149
|
-
|
150
|
-
}
|
151
|
-
|
152
|
-
]
|
153
|
-
}
|
154
|
-
|
155
|
-
```
|
156
|
-
|
157
|
-
|
158
|
-
# Create a form using a schema
|
159
|
-
|
160
|
-
Test schema to form [here](https://axiom-ui-forms.srv.axds.co/schema-to-form)
|
161
|
-
|
162
|
-
```json
|
163
|
-
{
|
164
|
-
"$id": "/test/schema",
|
165
|
-
"type": "object",
|
166
|
-
"properties": {
|
167
|
-
"label": {
|
168
|
-
"type": "string",
|
169
|
-
"maxLength": 100
|
170
|
-
},
|
171
|
-
"description": {
|
172
|
-
"type": "string"
|
173
|
-
},
|
174
|
-
"agree": {
|
175
|
-
"type": "boolean",
|
176
|
-
},
|
177
|
-
"signature": {
|
178
|
-
"type": "string"
|
179
|
-
}
|
180
|
-
}
|
181
|
-
}
|
182
|
-
|
183
|
-
```
|
184
|
-
|
185
|
-
|
186
|
-
```json
|
187
|
-
{
|
188
|
-
"$id": "/test/schema",
|
189
|
-
"type": "object",
|
190
|
-
"required": [
|
191
|
-
"label",
|
192
|
-
"description",
|
193
|
-
"agree"
|
194
|
-
],
|
195
|
-
"properties": {
|
196
|
-
"label": {
|
197
|
-
"type": "string",
|
198
|
-
"maxLength": 100
|
199
|
-
},
|
200
|
-
"description": {
|
201
|
-
"type": "string"
|
202
|
-
},
|
203
|
-
"agree": {
|
204
|
-
"type": "boolean"
|
205
|
-
}
|
206
|
-
}
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
}
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
1
|
+
React library that allows:
|
2
|
+
- Creation of forms using a json config file
|
3
|
+
- Creation of forms using a [json schema draft 7](https://json-schema.org/draft-07/json-schema-release-notes), with selective overrides using json config
|
4
|
+
- To do:
|
5
|
+
- allow addition of new form types and UI components by consuming library
|
6
|
+
- allow schema version 4 and draft 6
|
7
|
+
- support schema `required`
|
8
|
+
- support version 7 `if`/`then`/`else`
|
9
|
+
- support version 7 `readOnly`
|
10
|
+
- support version 7 `writeOnly`
|
11
|
+
|
12
|
+
|
13
|
+
.
|
14
|
+
|
15
|
+
# [Examples](https://axiom-ui-forms.srv.axds.co/)
|
16
|
+
|
17
|
+
## Create a form using a config
|
18
|
+
|
19
|
+
Test form config [here](https://axiom-ui-forms.srv.axds.co/). Note: currently, forms with wizards or pages require that the parent route includes `*` (only tested with `react-router-dom@7`). Todo: make url navigation on form optional.
|
20
|
+
|
21
|
+
```json
|
22
|
+
{
|
23
|
+
"id": "example",
|
24
|
+
"label": "Example form",
|
25
|
+
"description": "This is just an example",
|
26
|
+
"fields": [
|
27
|
+
{
|
28
|
+
"id": "title",
|
29
|
+
"type": "text",
|
30
|
+
"label": "Title"
|
31
|
+
},
|
32
|
+
{
|
33
|
+
"id": "description",
|
34
|
+
"type": "long_text",
|
35
|
+
"label": "Description"
|
36
|
+
},
|
37
|
+
{
|
38
|
+
"id": "favorites",
|
39
|
+
"type": "text",
|
40
|
+
"label": "List your favorite things",
|
41
|
+
"multiple": true
|
42
|
+
},
|
43
|
+
{
|
44
|
+
"id": "agree",
|
45
|
+
"type": "boolean",
|
46
|
+
"label": "Do you agree?"
|
47
|
+
},
|
48
|
+
{
|
49
|
+
"id": "signature",
|
50
|
+
"type": "text",
|
51
|
+
"label": "Sign your name then",
|
52
|
+
"conditions": { "dependsOn": "agree" }
|
53
|
+
}
|
54
|
+
]
|
55
|
+
}
|
56
|
+
```
|
57
|
+
|
58
|
+
```ts
|
59
|
+
import React, {type ReactElement} from 'react'
|
60
|
+
import { FormCreator, type IForm, type IFormValues } from '@axdspub/axiom-ui-forms'
|
61
|
+
|
62
|
+
export default ExampleForm = ({formConfig}: {formConfig: IForm}): ReactElement => {
|
63
|
+
const formValueState = React.useState<IFormValues>({})
|
64
|
+
const [formValues] = formValueState
|
65
|
+
useEffect(()=>{
|
66
|
+
// respond to change in formValues
|
67
|
+
},[formValues])
|
68
|
+
|
69
|
+
return (
|
70
|
+
<FormCreator form={formConfig} formValueState={formValueState} />
|
71
|
+
)
|
72
|
+
}
|
73
|
+
|
74
|
+
```
|
75
|
+
|
76
|
+
## Config to create a form with wizard steps using config.
|
77
|
+
Example [here](https://axiom-ui-forms.srv.axds.co/?tab=config&form=uQAEYmlkZ2V4YW1wbGVlbGFiZWxsRXhhbXBsZSBmb3Jta2Rlc2NyaXB0aW9ud1RoaXMgaXMganVzdCBhbiBleGFtcGxlbHdpemFyZF9zdGVwc4O5AARiaWRlaW50cm9lbGFiZWxsSW50cm9kdWN0aW9uZW9yZGVyAGZmaWVsZHOCuQADYmlkZXRpdGxlZHR5cGVkdGV4dGVsYWJlbGVUaXRsZbkAA2JpZGtkZXNjcmlwdGlvbmR0eXBlaWxvbmdfdGV4dGVsYWJlbGtEZXNjcmlwdGlvbrkABGJpZGNtYXBlbGFiZWxmU3RlcCAyZW9yZGVyAWZmaWVsZHOBuQADYmlkY21hcGR0eXBlZ2dlb2pzb25lbGFiZWxoTG9jYXRpb265AARiaWRlYWJvdXRlbGFiZWxuQWJvdXQgeW91cnNlbGZlb3JkZXICZXBhZ2VzgrkAA2JpZGlmYXZvcml0ZXNlbGFiZWxpRmF2b3JpdGVzZmZpZWxkc4G5AARiaWRuZmF2b3JpdGVzX2xpc3RkdHlwZWR0ZXh0ZWxhYmVseBlMaXN0IHlvdXIgZmF2b3JpdGUgdGhpbmdzaG11bHRpcGxl9bkAA2JpZGRzaWduZWxhYmVsaVNpZ25hdHVyZWZmaWVsZHOCuQADYmlkZWFncmVlZHR5cGVnYm9vbGVhbmVsYWJlbG1EbyB5b3UgYWdyZWU%2FuQADYmlkaXNpZ25hdHVyZWR0eXBlZHRleHRlbGFiZWxzU2lnbiB5b3VyIG5hbWUgdGhlbg%3D%3D).
|
78
|
+
|
79
|
+
```json
|
80
|
+
{
|
81
|
+
"id": "example",
|
82
|
+
"label": "Example form",
|
83
|
+
"description": "This is just an example",
|
84
|
+
"wizard_steps":[
|
85
|
+
{
|
86
|
+
"id":"intro",
|
87
|
+
"label":"Introduction",
|
88
|
+
"order": 0,
|
89
|
+
"fields":[
|
90
|
+
{
|
91
|
+
"id": "title",
|
92
|
+
"type": "text",
|
93
|
+
"label": "Title"
|
94
|
+
},
|
95
|
+
{
|
96
|
+
"id": "description",
|
97
|
+
"type": "long_text",
|
98
|
+
"label": "Description"
|
99
|
+
}
|
100
|
+
]
|
101
|
+
|
102
|
+
},
|
103
|
+
{
|
104
|
+
"id": "map",
|
105
|
+
"label": "Step 2",
|
106
|
+
"order": 1,
|
107
|
+
"fields": [
|
108
|
+
{
|
109
|
+
"id": "map",
|
110
|
+
"type": "geojson",
|
111
|
+
"label": "Location"
|
112
|
+
}
|
113
|
+
]
|
114
|
+
},
|
115
|
+
{
|
116
|
+
"id": "about",
|
117
|
+
"label": "About yourself",
|
118
|
+
"order": 2,
|
119
|
+
"pages":[
|
120
|
+
{
|
121
|
+
"id": "favorites",
|
122
|
+
"label": "Favorites",
|
123
|
+
"fields": [
|
124
|
+
{
|
125
|
+
"id": "favorites_list",
|
126
|
+
"type": "text",
|
127
|
+
"label": "List your favorite things",
|
128
|
+
"multiple": true
|
129
|
+
}
|
130
|
+
]
|
131
|
+
},
|
132
|
+
{
|
133
|
+
"id":"sign",
|
134
|
+
"label": "Signature",
|
135
|
+
"fields": [
|
136
|
+
{
|
137
|
+
"id": "agree",
|
138
|
+
"type": "boolean",
|
139
|
+
"label": "Do you agree?"
|
140
|
+
},
|
141
|
+
{
|
142
|
+
"id": "signature",
|
143
|
+
"type": "text",
|
144
|
+
"label": "Sign your name then"
|
145
|
+
}
|
146
|
+
]
|
147
|
+
}
|
148
|
+
]
|
149
|
+
|
150
|
+
}
|
151
|
+
|
152
|
+
]
|
153
|
+
}
|
154
|
+
|
155
|
+
```
|
156
|
+
|
157
|
+
|
158
|
+
# Create a form using a schema
|
159
|
+
|
160
|
+
Test schema to form [here](https://axiom-ui-forms.srv.axds.co/schema-to-form)
|
161
|
+
|
162
|
+
```json
|
163
|
+
{
|
164
|
+
"$id": "/test/schema",
|
165
|
+
"type": "object",
|
166
|
+
"properties": {
|
167
|
+
"label": {
|
168
|
+
"type": "string",
|
169
|
+
"maxLength": 100
|
170
|
+
},
|
171
|
+
"description": {
|
172
|
+
"type": "string"
|
173
|
+
},
|
174
|
+
"agree": {
|
175
|
+
"type": "boolean",
|
176
|
+
},
|
177
|
+
"signature": {
|
178
|
+
"type": "string"
|
179
|
+
}
|
180
|
+
}
|
181
|
+
}
|
182
|
+
|
183
|
+
```
|
184
|
+
|
185
|
+
|
186
|
+
```json
|
187
|
+
{
|
188
|
+
"$id": "/test/schema",
|
189
|
+
"type": "object",
|
190
|
+
"required": [
|
191
|
+
"label",
|
192
|
+
"description",
|
193
|
+
"agree"
|
194
|
+
],
|
195
|
+
"properties": {
|
196
|
+
"label": {
|
197
|
+
"type": "string",
|
198
|
+
"maxLength": 100
|
199
|
+
},
|
200
|
+
"description": {
|
201
|
+
"type": "string"
|
202
|
+
},
|
203
|
+
"agree": {
|
204
|
+
"type": "boolean"
|
205
|
+
}
|
206
|
+
}
|
207
|
+
}
|
208
|
+
```
|
209
|
+
|
210
|
+
|
211
|
+
|
212
|
+
```ts
|
213
|
+
import React, {type ReactElement} from 'react'
|
214
|
+
import { FormCreator, type IForm, type IFormValues } from '@axdspub/axiom-ui-forms'
|
215
|
+
import { type JSONSchema6 } from 'json-schema'
|
216
|
+
|
217
|
+
export default ExampleForm = ({schema}:{schema: JSONSchema7 }): ReactElement => {
|
218
|
+
const formValueState = React.useState<IFormValues>({})
|
219
|
+
const [formValues] = formValueState
|
220
|
+
useEffect(()=>{
|
221
|
+
// respond to change in formValues
|
222
|
+
},[formValues])
|
223
|
+
const errors = validateSchema(schema)
|
224
|
+
const formConfig = errors === null
|
225
|
+
? schemaToFormObject(schema)
|
226
|
+
: null
|
227
|
+
|
228
|
+
return (
|
229
|
+
<>{
|
230
|
+
errors !== null
|
231
|
+
? <p>Schema errors: {{errors}}</p>
|
232
|
+
: <SchemaFormCreator form={formConfig} formValueState={formValueState} >
|
233
|
+
}</>
|
234
|
+
|
235
|
+
)
|
236
|
+
|
237
|
+
}
|
238
|
+
|
239
|
+
```
|
240
|
+
|
241
|
+
|
242
|
+
# Create a form using a schema, and modify it with a form config
|
243
|
+
|
244
|
+
```ts
|
245
|
+
import { SchemaFormCreator } from '@axdspub/axiom-ui-forms'
|
246
|
+
import { type JSONSchema6 } from 'json-schema'
|
247
|
+
|
248
|
+
|
249
|
+
const schema: JSONSchema6 = {
|
250
|
+
properties: {
|
251
|
+
text_field: {
|
252
|
+
|
253
|
+
},
|
254
|
+
numeric_field: {
|
255
|
+
|
256
|
+
}
|
257
|
+
|
258
|
+
}
|
259
|
+
}
|
260
|
+
|
261
|
+
const fieldOverrides: IFieldOverride[] = [
|
262
|
+
{
|
263
|
+
prop: 'text_field',
|
264
|
+
label: 'This is my text field'
|
265
|
+
}
|
266
|
+
]
|
267
|
+
|
268
|
+
```
|
269
|
+
|
270
|
+
|
271
|
+
# Field definitions
|
272
|
+
## These can be used to create a form config, or as partials to override a schema
|
273
|
+
|
274
|
+
### root (all fields share these properties)
|
275
|
+
|
276
|
+
```json
|
277
|
+
{
|
278
|
+
"id": "fieldId",
|
279
|
+
"label": "Field label",
|
280
|
+
"description": "Field description",
|
281
|
+
"multiple": false,
|
282
|
+
"required": true,
|
283
|
+
"conditions": {
|
284
|
+
"dependsOn": "other_field_id",
|
285
|
+
"value": "val"
|
286
|
+
},
|
287
|
+
"defaultValue": "initial value",
|
288
|
+
"settings": {}
|
289
|
+
|
290
|
+
}
|
291
|
+
```
|
292
|
+
|
293
|
+
## string fields
|
294
|
+
|
295
|
+
### `type:text`
|
296
|
+
single line text field
|
297
|
+
|
298
|
+
```json
|
299
|
+
{
|
300
|
+
"placeHolder": "Example of field response"
|
301
|
+
}
|
302
|
+
```
|
303
|
+
|
304
|
+
## Enum select fields
|
305
|
+
|
306
|
+
### `type:select` and `type:radio`
|
307
|
+
|
308
|
+
```json
|
309
|
+
{
|
310
|
+
"options": [
|
311
|
+
{
|
312
|
+
"label": "Option 1",
|
313
|
+
"value": "option_1"
|
314
|
+
},
|
315
|
+
{
|
316
|
+
"label": "Option 2",
|
317
|
+
"value": "option_2"
|
318
|
+
}
|
319
|
+
]
|
320
|
+
}
|
321
|
+
```
|
322
|
+
|
323
|
+
|
324
|
+
## boolean
|
325
|
+
|
326
|
+
### `type:checkbox` and `type:boolean`
|
327
|
+
checkbox field
|
328
|
+
|
329
|
+
|
330
|
+
## number fields
|
331
|
+
|
332
|
+
### `type:number`
|
333
|
+
|
334
|
+
## date and time
|
335
|
+
|
336
|
+
### `type:date`
|
337
|
+
```json
|
338
|
+
{
|
339
|
+
"constraints": {
|
340
|
+
"minDate": "2023-02-01",
|
341
|
+
"maxDate": "2024-06-01"
|
342
|
+
}
|
343
|
+
}
|
344
|
+
```
|
345
|
+
|
346
|
+
### `type:time`
|
347
|
+
```json
|
348
|
+
{
|
349
|
+
"constraints": {
|
350
|
+
"minTime": "02:00:00",
|
351
|
+
"maxTime": "18:30:00"
|
352
|
+
}
|
353
|
+
}
|
354
|
+
```
|
355
|
+
|
356
|
+
### `type:datetime`
|
357
|
+
```json
|
358
|
+
{
|
359
|
+
"constraints": {
|
360
|
+
"minDateTime": "2023-02-01T00:00:00Z",
|
361
|
+
"maxDateTime": "2024-06-01T00:00:00Z"
|
362
|
+
}
|
363
|
+
}
|
364
|
+
```
|
365
|
+
|
366
|
+
|
367
|
+
### `type:object`
|
368
|
+
- `skip_path`: if `true`, `id` is not used to create path to child fields in output. Can not be `true` if `multiple` is `true`
|
369
|
+
- `fields`: array of child fields
|
370
|
+
- `layout`: type of layout for child form elements. Not fully supported yet.
|
371
|
+
```json
|
372
|
+
{
|
373
|
+
"skip_path": true,
|
374
|
+
"layout": "horizontal",
|
375
|
+
"fields": [
|
376
|
+
|
377
|
+
]
|
378
|
+
}
|
379
|
+
```
|
380
|
+
|
381
|
+
# Field overrides
|
382
|
+
Field overrides must contain a `prop` property. This can reference an existing property from a schema. If it doesn't reference an existing property, a new property will be added to the form and the form output
|
383
|
+
|
384
|
+
# Form overrides
|
385
|
+
Form overrides can have the following elements:
|
386
|
+
|
387
|
+
## wizard_steps
|
388
|
+
These create a wizard interface
|
389
|
+
```json
|
390
|
+
"wizard_steps": [
|
391
|
+
{
|
392
|
+
"id":"first_step",
|
393
|
+
"order": 1,
|
394
|
+
"label": "First step",
|
395
|
+
"fields": [],
|
396
|
+
"pages": []
|
397
|
+
},
|
398
|
+
{
|
399
|
+
"id":"second_step",
|
400
|
+
"order": 2,
|
401
|
+
"label": "Second step",
|
402
|
+
"fields": [],
|
403
|
+
"pages": []
|
404
|
+
}
|
405
|
+
]
|
406
|
+
```
|
407
|
+
|
408
|
+
## pages
|
409
|
+
```json
|
410
|
+
"pages":
|
411
|
+
|
412
|
+
```
|
413
|
+
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
# Tests
|
418
|
+
Uses vitest. Install vitest vscode plugin for extras
|
419
|
+
|
420
|
+
```node
|
421
|
+
npm run test
|
422
|
+
```
|
423
|
+
|
424
|
+
|
425
|
+
|
426
|
+
# Testing build locally
|
427
|
+
|
428
|
+
```bash
|
429
|
+
npm i spa-http-server -g
|
430
|
+
npm run build
|
431
|
+
cd build
|
432
|
+
http-server --push-state -p 8091 -o
|
433
|
+
```
|
434
|
+
|
435
|
+
# Publish version to NPM
|
436
|
+
|
437
|
+
```bash
|
438
|
+
npm login --scope=@axdspub
|
439
|
+
npm publish --access public
|
440
|
+
```
|