@nolwenture/formik-jsonschema-form 0.8.0 → 0.9.0
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 +124 -0
- package/dist/Form.js +2 -1
- package/dist/Form.stories.d.ts +1 -0
- package/dist/Form.stories.js +7 -0
- package/dist/fields/ArrayField.js +2 -1
- package/dist/fields/MultipleChoiceField.js +0 -2
- package/dist/fields/SchemaField.js +7 -5
- package/dist/fields/stories/AnyField.stories.js +1 -1
- package/dist/fields/stories/ArrayField.stories.js +1 -1
- package/dist/fields/stories/BooleanField.stories.js +1 -1
- package/dist/fields/stories/DateField.stories.js +1 -1
- package/dist/fields/stories/NullField.stories.js +1 -1
- package/dist/fields/stories/NumberField.stories.js +1 -1
- package/dist/fields/stories/ObjectField.stories.js +1 -1
- package/dist/fields/stories/RadioField.stories.js +1 -1
- package/dist/fields/stories/SchemaField.stories.d.ts +43 -0
- package/dist/fields/stories/SchemaField.stories.js +47 -1
- package/dist/fields/stories/SearchMultiTagSelectField.stories.js +1 -1
- package/dist/fields/stories/StringField.stories.js +1 -1
- package/dist/fields/stories/ToggleField.stories.js +1 -1
- package/dist/formEditorSchemas.js +177 -21
- package/dist/sampleData/ageFieldDefinition.d.ts +2 -0
- package/dist/sampleData/ageFieldDefinition.js +5 -0
- package/dist/sampleData/refDefSchema.d.ts +3 -0
- package/dist/sampleData/refDefSchema.js +219 -0
- package/dist/styledComponents.js +0 -2
- package/dist/types.d.ts +4 -2
- package/dist/utils/__tests/resolveSchema.test.js +40 -30
- package/dist/utils/__tests/solveReferences.test.d.ts +1 -0
- package/dist/utils/__tests/solveReferences.test.js +12 -0
- package/dist/utils/__tests/testSchemas.d.ts +4 -0
- package/dist/utils/__tests/testSchemas.js +67 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/resolveSchema.d.ts +1 -1
- package/dist/utils/resolveSchema.js +88 -39
- package/dist/utils/solveReferences.d.ts +2 -0
- package/dist/utils/solveReferences.js +8 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -578,6 +578,130 @@ export const conditionsSchema = {
|
|
|
578
578
|
};
|
|
579
579
|
```
|
|
580
580
|
|
|
581
|
+
Another option to give conditional fields is using `dependencies`-object inside the main schema.
|
|
582
|
+
Dependencies can either be triggered by the conditional-giving property being present in the form values, or by the conditional-giving property having a certain value.
|
|
583
|
+
|
|
584
|
+
To have value-dependent conditionals, the `dependencies`-object needs to have an `oneOf`-array listing the possible conditional-giving values matching the enum-values of the conditional-giving field. Each case in in the `oneOf` array can either have no conditional fields, then the only key-value pair given inside `properties` is the matching conditional (see "no type"), or an unlimited amount of conditional fields listed after the matching conditional.
|
|
585
|
+
|
|
586
|
+
```tsx
|
|
587
|
+
export const refDefSchema: Schema = {
|
|
588
|
+
type: "object",
|
|
589
|
+
properties: {
|
|
590
|
+
creditCard: {
|
|
591
|
+
type: "number",
|
|
592
|
+
title: "Credit card number",
|
|
593
|
+
description:
|
|
594
|
+
"Giving any input to this field will trigger its dependent field 'billing_address'",
|
|
595
|
+
},
|
|
596
|
+
fieldType: {
|
|
597
|
+
type: "string",
|
|
598
|
+
description:
|
|
599
|
+
"Selecting an option in this field will render the correct dependent field from the provided oneOf-array",
|
|
600
|
+
enum: ["string", "object", "array"],
|
|
601
|
+
},
|
|
602
|
+
},
|
|
603
|
+
dependencies: {
|
|
604
|
+
creditCard: {
|
|
605
|
+
properties: {
|
|
606
|
+
billing_address: {
|
|
607
|
+
type: "object",
|
|
608
|
+
description: "This object depends on creditCard field input",
|
|
609
|
+
properties: {
|
|
610
|
+
street: { type: "string", title: "Street" },
|
|
611
|
+
city: { type: "string", title: "City" },
|
|
612
|
+
postalCode: { type: "number", title: "Postal code" },
|
|
613
|
+
},
|
|
614
|
+
},
|
|
615
|
+
},
|
|
616
|
+
required: ["billing_address"],
|
|
617
|
+
},
|
|
618
|
+
fieldType: {
|
|
619
|
+
oneOf: [
|
|
620
|
+
{
|
|
621
|
+
properties: {
|
|
622
|
+
fieldType: {
|
|
623
|
+
enum: ["no type"],
|
|
624
|
+
},
|
|
625
|
+
},
|
|
626
|
+
},
|
|
627
|
+
{
|
|
628
|
+
properties: {
|
|
629
|
+
fieldType: {
|
|
630
|
+
enum: ["string"],
|
|
631
|
+
},
|
|
632
|
+
stringField: {
|
|
633
|
+
type: "string",
|
|
634
|
+
title: "StringField",
|
|
635
|
+
},
|
|
636
|
+
},
|
|
637
|
+
},
|
|
638
|
+
{
|
|
639
|
+
properties: {
|
|
640
|
+
fieldType: {
|
|
641
|
+
enum: ["object"],
|
|
642
|
+
},
|
|
643
|
+
objectField: {
|
|
644
|
+
type: "object",
|
|
645
|
+
properties: {
|
|
646
|
+
objectString: {
|
|
647
|
+
type: "string",
|
|
648
|
+
title: "StringField in Object",
|
|
649
|
+
},
|
|
650
|
+
},
|
|
651
|
+
},
|
|
652
|
+
},
|
|
653
|
+
},
|
|
654
|
+
{
|
|
655
|
+
properties: {
|
|
656
|
+
fieldType: {
|
|
657
|
+
enum: ["array"],
|
|
658
|
+
},
|
|
659
|
+
arrayField: {
|
|
660
|
+
type: "array",
|
|
661
|
+
items: [{ type: "string", title: "StringField in fixed array" }],
|
|
662
|
+
},
|
|
663
|
+
},
|
|
664
|
+
},
|
|
665
|
+
],
|
|
666
|
+
},
|
|
667
|
+
},
|
|
668
|
+
};
|
|
669
|
+
```
|
|
670
|
+
|
|
671
|
+
Using `if-else-then` or `dependencies` depends mostly on the use case. For recursion, a combination of `$ref` and `dependencies`is recommended.
|
|
672
|
+
|
|
673
|
+
### Schema reference $ref
|
|
674
|
+
|
|
675
|
+
Schemas can be referenced. A referenced schema can be given to a property using `$ref` keyword. The definition for the referenced schema needs to be inside `definitions` object inside the main schema. The value-string given to $ref-key must always look like this:
|
|
676
|
+
`'#/definitions/{addMatchingKeyHere}'`
|
|
677
|
+
|
|
678
|
+
```tsx
|
|
679
|
+
const ageFieldDefinition: Schema = {
|
|
680
|
+
type: "number",
|
|
681
|
+
title: "Age",
|
|
682
|
+
};
|
|
683
|
+
|
|
684
|
+
export const refDefSchema: Schema = {
|
|
685
|
+
title: "References and Definitions",
|
|
686
|
+
type: "object",
|
|
687
|
+
properties: {
|
|
688
|
+
name: {
|
|
689
|
+
$ref: "#/definitions/name",
|
|
690
|
+
},
|
|
691
|
+
age: {
|
|
692
|
+
$ref: "#/definitions/age",
|
|
693
|
+
},
|
|
694
|
+
},
|
|
695
|
+
definitions: {
|
|
696
|
+
name: {
|
|
697
|
+
type: "string",
|
|
698
|
+
title: "Name",
|
|
699
|
+
},
|
|
700
|
+
age: ageFieldDefinition,
|
|
701
|
+
},
|
|
702
|
+
};
|
|
703
|
+
```
|
|
704
|
+
|
|
581
705
|
### Ordering fields
|
|
582
706
|
|
|
583
707
|
The order of fields can be set using `"ui:order": ["fieldName"]` inside the uiSchema.
|
package/dist/Form.js
CHANGED
|
@@ -30,11 +30,12 @@ export const Form = (props) => {
|
|
|
30
30
|
]);
|
|
31
31
|
const { isSubmitting } = useFormikContext();
|
|
32
32
|
const { schema, uiSchema = {}, className, children, fields = {}, templates = {}, components = {}, formContext = {}, useItemsAsAdditionalItems = false, hideUnmarkedAdditionalProperties = false, } = props;
|
|
33
|
+
const schemaDefinitions = schema.definitions;
|
|
33
34
|
const registry = {
|
|
34
35
|
fields: Object.assign(Object.assign({}, defaultFields), fields),
|
|
35
36
|
templates: Object.assign(Object.assign({}, defaultTemplates), templates),
|
|
36
37
|
components: Object.assign(Object.assign({}, defaultComponents), components),
|
|
37
|
-
definitions:
|
|
38
|
+
definitions: schemaDefinitions,
|
|
38
39
|
formContext,
|
|
39
40
|
useItemsAsAdditionalItems,
|
|
40
41
|
hideUnmarkedAdditionalProperties,
|
package/dist/Form.stories.d.ts
CHANGED
|
@@ -11,4 +11,5 @@ export declare const StylesCustomized: () => import("react/jsx-runtime").JSX.Ele
|
|
|
11
11
|
export declare const WithGeneratedSchema: Story;
|
|
12
12
|
export declare const WithRequiredInput: Story;
|
|
13
13
|
export declare const WithConditions: Story;
|
|
14
|
+
export declare const WithRefAndDefinitions: Story;
|
|
14
15
|
export declare const MultipleChoice: Story;
|
package/dist/Form.stories.js
CHANGED
|
@@ -25,6 +25,7 @@ import { Formik, useFormikContext } from "formik";
|
|
|
25
25
|
import { InfoFieldButton, SearchableMultiTagSelectField, } from "./styledComponents";
|
|
26
26
|
import { completeSchema, completeUiSchema, simpleSchema, simpleUiSchema, generatedSchema, requiredInputSchema, requiredInputUiSchema, conditionsSchema, conditionsUiSchema, } from "./sampleData";
|
|
27
27
|
import { Form, styledComponents } from "./";
|
|
28
|
+
import { refDefSchema, refDefUiSchema } from "./sampleData/refDefSchema";
|
|
28
29
|
import { multipleChoiceSchema, multipleChoiceUiSchema, } from "./sampleData/multipleChoiceSchema";
|
|
29
30
|
const meta = {
|
|
30
31
|
title: "Form",
|
|
@@ -185,6 +186,12 @@ export const WithConditions = {
|
|
|
185
186
|
hideUnmarkedAdditionalProperties: true,
|
|
186
187
|
},
|
|
187
188
|
};
|
|
189
|
+
export const WithRefAndDefinitions = {
|
|
190
|
+
args: {
|
|
191
|
+
schema: refDefSchema,
|
|
192
|
+
uiSchema: refDefUiSchema,
|
|
193
|
+
},
|
|
194
|
+
};
|
|
188
195
|
export const MultipleChoice = {
|
|
189
196
|
args: {
|
|
190
197
|
schema: multipleChoiceSchema,
|
|
@@ -93,7 +93,8 @@ export const ArrayField = (props) => {
|
|
|
93
93
|
// );
|
|
94
94
|
// Bacwards compatibility ends
|
|
95
95
|
const { disabled } = useExtractUiSchema(uiSchema);
|
|
96
|
-
|
|
96
|
+
const valueArray = Array.isArray(value) ? value : undefined;
|
|
97
|
+
return (_jsxs(ArrayFieldTemplate, Object.assign({}, props, { children: [_jsxs(ArrayFieldList, { children: [(items || []).map((itemSchema, index) => (_jsx(ArrayFieldItem, { children: _jsx(SchemaField, { name: `${name}[${index}]`, schema: typeof itemSchema !== "boolean" ? itemSchema : {}, uiSchema: (uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema[index]) || (uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema.items), forceDefaultValue: true }) }, index))), ((valueArray === null || valueArray === void 0 ? void 0 : valueArray.slice(items.length)) || []).map((_, index) => (_jsxs(ArrayFieldItem, { children: [_jsx(SchemaField, { name: `${name}[${index + items.length}]`, schema: additionalItems && typeof additionalItems !== "boolean"
|
|
97
98
|
? additionalItems
|
|
98
99
|
: {}, uiSchema: Object.assign({ disabled }, ((uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema[index + items.length]) || (uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema.items))) }), _jsxs(ArrayFieldItemButtons, { children: [GetArrayFieldButton({
|
|
99
100
|
purpose: ArrayFieldButtonPurpose.REMOVE,
|
|
@@ -9,7 +9,5 @@ export const MultipleChoiceField = (props) => {
|
|
|
9
9
|
const { name, uiSchema } = props;
|
|
10
10
|
const { props: inputProps, option } = useExtractUiSchema(uiSchema);
|
|
11
11
|
const enums = useMemo(() => getEnums(props), [props]);
|
|
12
|
-
console.log("option", option);
|
|
13
|
-
console.log("uiSchema", uiSchema);
|
|
14
12
|
return (_jsx(FieldTemplate, Object.assign({}, props, { children: _jsx(MultipleChoiceField, { inputProps: inputProps, name: name, enums: enums, style: option === null || option === void 0 ? void 0 : option.style }) })));
|
|
15
13
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useContext } from "react";
|
|
3
|
-
import { getSchemaType } from "../utils";
|
|
2
|
+
import { useContext, useMemo } from "react";
|
|
3
|
+
import { getSchemaType, solveReferences } from "../utils";
|
|
4
4
|
import { useExtractUiSchema } from "../hooks";
|
|
5
5
|
import { FormRegistry } from "../Form";
|
|
6
6
|
import { COMPONENT_TYPES } from "./types";
|
|
@@ -23,7 +23,9 @@ const useFieldComponent = (schema, uiSchema, fields) => {
|
|
|
23
23
|
};
|
|
24
24
|
export const SchemaField = (props) => {
|
|
25
25
|
const { schema, uiSchema } = props;
|
|
26
|
-
const { fields } = useContext(FormRegistry);
|
|
27
|
-
const
|
|
28
|
-
|
|
26
|
+
const { fields, definitions } = useContext(FormRegistry);
|
|
27
|
+
const schemaSolvedForReferences = useMemo(() => solveReferences(schema, definitions), [schema, definitions]);
|
|
28
|
+
const FieldComponent = useFieldComponent(schemaSolvedForReferences, uiSchema, fields);
|
|
29
|
+
const newProps = Object.assign(Object.assign({}, props), { schema: schemaSolvedForReferences });
|
|
30
|
+
return _jsx(FieldComponent, Object.assign({}, newProps));
|
|
29
31
|
};
|
|
@@ -12,7 +12,7 @@ import { within, userEvent, expect } from "@storybook/test";
|
|
|
12
12
|
import { Formik, Form } from "formik";
|
|
13
13
|
import { AnyField } from "./../AnyField";
|
|
14
14
|
export default {
|
|
15
|
-
title: "
|
|
15
|
+
title: "Fields/AnyField",
|
|
16
16
|
component: AnyField,
|
|
17
17
|
decorators: [
|
|
18
18
|
(Story) => (_jsx(Formik, { initialValues: { dynamicField: "" }, onSubmit: (values) => console.log(values), children: _jsx(Form, { children: Story() }) })),
|
|
@@ -12,7 +12,7 @@ import { within, userEvent, expect } from "@storybook/test";
|
|
|
12
12
|
import { Formik, Form } from "formik";
|
|
13
13
|
import { ArrayField } from "./../ArrayField";
|
|
14
14
|
export default {
|
|
15
|
-
title: "
|
|
15
|
+
title: "Fields/ArrayField",
|
|
16
16
|
component: ArrayField,
|
|
17
17
|
decorators: [
|
|
18
18
|
(Story) => (_jsx(Formik, { initialValues: { itemsList: [] }, onSubmit: (values) => console.log(values), children: _jsx(Form, { children: Story() }) })),
|
|
@@ -12,7 +12,7 @@ import { userEvent, expect } from "@storybook/test";
|
|
|
12
12
|
import { Formik, Form } from "formik";
|
|
13
13
|
import { BooleanField } from "./../BooleanField";
|
|
14
14
|
export default {
|
|
15
|
-
title: "
|
|
15
|
+
title: "Fields/BooleanField",
|
|
16
16
|
component: BooleanField,
|
|
17
17
|
decorators: [
|
|
18
18
|
(Story) => (_jsx(Formik, { initialValues: { acceptTerms: false }, onSubmit: (values) => console.log(values), children: _jsx(Form, { children: Story() }) })),
|
|
@@ -12,7 +12,7 @@ import { userEvent, expect } from "@storybook/test";
|
|
|
12
12
|
import { Formik, Form } from "formik";
|
|
13
13
|
import { DateField } from "./../DateField";
|
|
14
14
|
export default {
|
|
15
|
-
title: "
|
|
15
|
+
title: "Fields/DateField",
|
|
16
16
|
component: DateField,
|
|
17
17
|
decorators: [
|
|
18
18
|
(Story) => (_jsx(Formik, { initialValues: { birthDate: "" }, onSubmit: (values) => console.log(values), children: _jsx(Form, { children: Story() }) })),
|
|
@@ -12,7 +12,7 @@ import { within, expect } from "@storybook/test";
|
|
|
12
12
|
import { Formik, Form } from "formik";
|
|
13
13
|
import { NullField } from "./../NullField";
|
|
14
14
|
export default {
|
|
15
|
-
title: "
|
|
15
|
+
title: "Fields/NullField",
|
|
16
16
|
component: NullField,
|
|
17
17
|
decorators: [
|
|
18
18
|
(Story) => (_jsx(Formik, { initialValues: { someField: null }, onSubmit: (values) => console.log(values), children: _jsxs(Form, { children: [Story(), _jsx("button", { type: "submit", children: "Submit" })] }) })),
|
|
@@ -12,7 +12,7 @@ import { userEvent, expect } from "@storybook/test";
|
|
|
12
12
|
import { Formik, Form } from "formik";
|
|
13
13
|
import { NumberField } from "./../NumberField";
|
|
14
14
|
export default {
|
|
15
|
-
title: "
|
|
15
|
+
title: "Fields/NumberField",
|
|
16
16
|
component: NumberField,
|
|
17
17
|
decorators: [
|
|
18
18
|
(Story) => (_jsx(Formik, { initialValues: { numberInput: "" }, onSubmit: () => { }, children: _jsx(Form, { children: Story() }) })),
|
|
@@ -12,7 +12,7 @@ import { userEvent, expect } from "@storybook/test";
|
|
|
12
12
|
import { Formik, Form } from "formik";
|
|
13
13
|
import { ObjectField } from "./../ObjectField";
|
|
14
14
|
export default {
|
|
15
|
-
title: "
|
|
15
|
+
title: "Fields/ObjectField",
|
|
16
16
|
component: ObjectField,
|
|
17
17
|
decorators: [
|
|
18
18
|
(Story) => (_jsx(Formik, { initialValues: {}, onSubmit: () => { }, children: _jsx(Form, { children: Story() }) })),
|
|
@@ -12,7 +12,7 @@ import { userEvent, expect } from "@storybook/test";
|
|
|
12
12
|
import { RadioField } from "./../RadioField";
|
|
13
13
|
import { Formik, Form } from "formik";
|
|
14
14
|
export default {
|
|
15
|
-
title: "
|
|
15
|
+
title: "Fields/RadioField",
|
|
16
16
|
component: RadioField,
|
|
17
17
|
decorators: [
|
|
18
18
|
(Story) => (_jsx(Formik, { initialValues: {}, onSubmit: () => { }, children: _jsx(Form, { children: Story() }) })),
|
|
@@ -1671,3 +1671,46 @@ export declare const NumberField: {
|
|
|
1671
1671
|
tags?: string[] | undefined;
|
|
1672
1672
|
story?: Omit<import("@storybook/types").StoryAnnotations<import("@storybook/react").ReactRenderer, import("../../types").FieldProps, Partial<import("../../types").FieldProps>>, "story"> | undefined;
|
|
1673
1673
|
};
|
|
1674
|
+
export declare const ReferenceAndInitialValues: {
|
|
1675
|
+
args: {
|
|
1676
|
+
schema: {
|
|
1677
|
+
title: string;
|
|
1678
|
+
type: string;
|
|
1679
|
+
required: string[];
|
|
1680
|
+
properties: {
|
|
1681
|
+
name: {
|
|
1682
|
+
$ref: string;
|
|
1683
|
+
};
|
|
1684
|
+
age: {
|
|
1685
|
+
type: string;
|
|
1686
|
+
title: string;
|
|
1687
|
+
};
|
|
1688
|
+
creditCard: {
|
|
1689
|
+
type: string;
|
|
1690
|
+
};
|
|
1691
|
+
};
|
|
1692
|
+
dependencies: {
|
|
1693
|
+
creditCard: {
|
|
1694
|
+
properties: {
|
|
1695
|
+
billing_address: {
|
|
1696
|
+
$ref: string;
|
|
1697
|
+
};
|
|
1698
|
+
};
|
|
1699
|
+
required: string[];
|
|
1700
|
+
};
|
|
1701
|
+
};
|
|
1702
|
+
definitions: {
|
|
1703
|
+
name: {
|
|
1704
|
+
type: string;
|
|
1705
|
+
title: string;
|
|
1706
|
+
};
|
|
1707
|
+
address: {
|
|
1708
|
+
type: string;
|
|
1709
|
+
};
|
|
1710
|
+
};
|
|
1711
|
+
};
|
|
1712
|
+
};
|
|
1713
|
+
play: ({ canvasElement }: {
|
|
1714
|
+
canvasElement: HTMLElement;
|
|
1715
|
+
}) => Promise<void>;
|
|
1716
|
+
};
|
|
@@ -11,11 +11,17 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
11
11
|
import { userEvent, expect } from "@storybook/test";
|
|
12
12
|
import { Formik, Form } from "formik";
|
|
13
13
|
import { SchemaField } from "./../SchemaField";
|
|
14
|
+
const initialValues = {
|
|
15
|
+
name: "Test name",
|
|
16
|
+
age: "50",
|
|
17
|
+
creditCard: "test card",
|
|
18
|
+
billing_address: "Street 1",
|
|
19
|
+
};
|
|
14
20
|
export default {
|
|
15
21
|
title: "Fields/SchemaField",
|
|
16
22
|
component: SchemaField,
|
|
17
23
|
decorators: [
|
|
18
|
-
(Story) => (_jsx(Formik, { initialValues:
|
|
24
|
+
(Story) => (_jsx(Formik, { initialValues: initialValues, onSubmit: () => { }, children: _jsx(Form, { children: Story() }) })),
|
|
19
25
|
],
|
|
20
26
|
};
|
|
21
27
|
const Template = {
|
|
@@ -37,3 +43,43 @@ export const NumberField = Object.assign(Object.assign({}, Template), { args: Ob
|
|
|
37
43
|
yield userEvent.type(input, "123");
|
|
38
44
|
expect(input).toHaveValue(123);
|
|
39
45
|
}) });
|
|
46
|
+
export const ReferenceAndInitialValues = {
|
|
47
|
+
args: {
|
|
48
|
+
schema: {
|
|
49
|
+
title: "References and Definitions",
|
|
50
|
+
type: "object",
|
|
51
|
+
required: ["string", "number", "boolean", "enum"],
|
|
52
|
+
properties: {
|
|
53
|
+
name: { $ref: "#/definitions/name" },
|
|
54
|
+
age: { type: "number", title: "Age" },
|
|
55
|
+
creditCard: {
|
|
56
|
+
type: "string",
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
dependencies: {
|
|
60
|
+
creditCard: {
|
|
61
|
+
properties: {
|
|
62
|
+
billing_address: {
|
|
63
|
+
$ref: "#/definitions/address",
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
required: ["billing_address"],
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
definitions: {
|
|
70
|
+
name: { type: "string", title: "Name" },
|
|
71
|
+
address: { type: "string" },
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
play: (_c) => __awaiter(void 0, [_c], void 0, function* ({ canvasElement }) {
|
|
76
|
+
const nameField = canvasElement.querySelector('input[name="name"]');
|
|
77
|
+
const ageField = canvasElement.querySelector('input[name="age"]');
|
|
78
|
+
const creditCardField = canvasElement.querySelector('input[name="creditCard"]');
|
|
79
|
+
const addressField = canvasElement.querySelector('input[name="billing_address"]');
|
|
80
|
+
expect(nameField).toHaveValue(initialValues.name);
|
|
81
|
+
expect(ageField).toHaveValue(parseInt(initialValues.age));
|
|
82
|
+
expect(creditCardField).toHaveValue(initialValues.creditCard);
|
|
83
|
+
expect(addressField).toHaveValue(initialValues.billing_address);
|
|
84
|
+
}),
|
|
85
|
+
};
|
|
@@ -12,7 +12,7 @@ import { within, userEvent, expect } from "@storybook/test";
|
|
|
12
12
|
import { SearchMultiTagSelectField } from "./../SearchMultiTagSelectField";
|
|
13
13
|
import { Formik, Form } from "formik";
|
|
14
14
|
export default {
|
|
15
|
-
title: "
|
|
15
|
+
title: "Fields/SearchMultiTagSelectField",
|
|
16
16
|
component: SearchMultiTagSelectField,
|
|
17
17
|
decorators: [
|
|
18
18
|
(Story) => (_jsx(Formik, { initialValues: { tags: [] }, onSubmit: () => { }, children: _jsx(Form, { children: Story() }) })),
|
|
@@ -12,7 +12,7 @@ import { userEvent, expect } from "@storybook/test";
|
|
|
12
12
|
import { StringField } from "./../StringField";
|
|
13
13
|
import { Formik, Form } from "formik";
|
|
14
14
|
export default {
|
|
15
|
-
title: "
|
|
15
|
+
title: "Fields/StringField",
|
|
16
16
|
component: StringField,
|
|
17
17
|
decorators: [
|
|
18
18
|
(Story) => (_jsx(Formik, { initialValues: { name: "" }, onSubmit: () => { }, children: _jsx(Form, { children: Story() }) })),
|
|
@@ -12,7 +12,7 @@ import { userEvent, expect } from "@storybook/test";
|
|
|
12
12
|
import { ToggleField } from "../ToggleField";
|
|
13
13
|
import { Formik, Form } from "formik";
|
|
14
14
|
export default {
|
|
15
|
-
title: "
|
|
15
|
+
title: "Fields/ToggleField",
|
|
16
16
|
component: ToggleField,
|
|
17
17
|
decorators: [
|
|
18
18
|
(Story) => (_jsx(Formik, { initialValues: { toggle: false }, onSubmit: () => { }, children: _jsx(Form, { children: Story() }) })),
|
|
@@ -1,35 +1,191 @@
|
|
|
1
|
+
const fieldObject = {
|
|
2
|
+
type: {
|
|
3
|
+
type: "string",
|
|
4
|
+
title: "Field type",
|
|
5
|
+
oneOf: [
|
|
6
|
+
{ const: "string", title: "String" },
|
|
7
|
+
{ const: "number", title: "Number" },
|
|
8
|
+
{ const: "array", title: "Array" },
|
|
9
|
+
{ const: "object", title: "Object" },
|
|
10
|
+
{ const: "boolean", title: "Boolean" },
|
|
11
|
+
{ const: "null", title: "Null" },
|
|
12
|
+
{ const: "any", title: "Any" },
|
|
13
|
+
],
|
|
14
|
+
},
|
|
15
|
+
title: {
|
|
16
|
+
type: "string",
|
|
17
|
+
title: "Field title",
|
|
18
|
+
},
|
|
19
|
+
key: { type: "string", title: "Object Key" },
|
|
20
|
+
};
|
|
1
21
|
const field = {
|
|
2
22
|
type: "object",
|
|
3
|
-
properties:
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
23
|
+
properties: fieldObject,
|
|
24
|
+
allOf: [
|
|
25
|
+
{
|
|
26
|
+
if: {
|
|
27
|
+
properties: {
|
|
28
|
+
type: {
|
|
29
|
+
const: "array",
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
then: {
|
|
34
|
+
properties: {
|
|
35
|
+
hasFixedFields: {
|
|
36
|
+
type: "string",
|
|
37
|
+
title: "Fixed fields?",
|
|
38
|
+
oneOf: [
|
|
39
|
+
{ const: "true", title: "Yes" },
|
|
40
|
+
{ const: "false", title: "No" },
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
additionalItemsSchema: {
|
|
44
|
+
type: "array",
|
|
45
|
+
items: { type: "object", properties: fieldObject },
|
|
46
|
+
additionalItems: { type: "object", properties: fieldObject },
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
13
50
|
},
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
51
|
+
{
|
|
52
|
+
if: {
|
|
53
|
+
properties: {
|
|
54
|
+
type: {
|
|
55
|
+
const: "object",
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
then: {
|
|
60
|
+
properties: {
|
|
61
|
+
hasAdditionalProperties: {
|
|
62
|
+
type: "string",
|
|
63
|
+
title: "Additional fields?",
|
|
64
|
+
oneOf: [
|
|
65
|
+
{ const: "true", title: "Yes" },
|
|
66
|
+
{ const: "false", title: "No" },
|
|
67
|
+
],
|
|
68
|
+
},
|
|
69
|
+
objectField: {
|
|
70
|
+
type: "array",
|
|
71
|
+
items: { type: "object", properties: fieldObject },
|
|
72
|
+
additionalItems: { type: "object", properties: fieldObject },
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
},
|
|
17
76
|
},
|
|
18
|
-
|
|
77
|
+
{
|
|
78
|
+
if: {
|
|
79
|
+
properties: {
|
|
80
|
+
hasAdditionalProperties: {
|
|
81
|
+
const: "true",
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
then: {
|
|
86
|
+
properties: {
|
|
87
|
+
additionalItemsSchema: {
|
|
88
|
+
type: "array",
|
|
89
|
+
items: { type: "object", properties: fieldObject },
|
|
90
|
+
additionalItems: { type: "object", properties: fieldObject },
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
if: {
|
|
97
|
+
properties: {
|
|
98
|
+
hasFixedFields: {
|
|
99
|
+
const: "true",
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
then: {
|
|
104
|
+
properties: {
|
|
105
|
+
fixedArrayField: {
|
|
106
|
+
type: "array",
|
|
107
|
+
items: { type: "object", properties: fieldObject },
|
|
108
|
+
additionalItems: { type: "object", properties: fieldObject },
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
],
|
|
19
114
|
};
|
|
20
115
|
export const schema = {
|
|
116
|
+
// type: "object",
|
|
117
|
+
// properties: {
|
|
118
|
+
// "schema.type": {
|
|
119
|
+
// type: "string",
|
|
120
|
+
// default: "object",
|
|
121
|
+
// },
|
|
122
|
+
// "schema.title": {
|
|
123
|
+
// type: "string",
|
|
124
|
+
// title: "Form title",
|
|
125
|
+
// },
|
|
126
|
+
// "schema.properties": { type: "array", additionalItems: field },
|
|
127
|
+
// },
|
|
128
|
+
//$ref needs to get implemented correctly, so that this would work. Works in the playground, though
|
|
21
129
|
type: "object",
|
|
22
130
|
properties: {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
default: "object",
|
|
131
|
+
tree: {
|
|
132
|
+
$ref: "#/definitions/tree",
|
|
26
133
|
},
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
134
|
+
},
|
|
135
|
+
definitions: {
|
|
136
|
+
tree: {
|
|
137
|
+
type: "object",
|
|
138
|
+
properties: {
|
|
139
|
+
fieldType: {
|
|
140
|
+
type: "string",
|
|
141
|
+
enum: ["string", "object", "array"],
|
|
142
|
+
default: "string",
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
dependencies: {
|
|
146
|
+
fieldType: {
|
|
147
|
+
oneOf: [
|
|
148
|
+
{
|
|
149
|
+
properties: {
|
|
150
|
+
fieldType: {
|
|
151
|
+
enum: ["string"],
|
|
152
|
+
},
|
|
153
|
+
field: {
|
|
154
|
+
type: "string",
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
properties: {
|
|
160
|
+
fieldType: {
|
|
161
|
+
enum: ["object"],
|
|
162
|
+
},
|
|
163
|
+
field: {
|
|
164
|
+
$ref: "#/definitions/tree",
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
properties: {
|
|
170
|
+
fieldType: {
|
|
171
|
+
enum: ["array"],
|
|
172
|
+
},
|
|
173
|
+
field: {
|
|
174
|
+
type: "array",
|
|
175
|
+
items: {
|
|
176
|
+
$ref: "#/definitions/tree",
|
|
177
|
+
},
|
|
178
|
+
additionalItems: {
|
|
179
|
+
$ref: "#/definitions/tree",
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
],
|
|
185
|
+
},
|
|
186
|
+
},
|
|
30
187
|
},
|
|
31
188
|
},
|
|
32
|
-
additionalProperties: field,
|
|
33
189
|
};
|
|
34
190
|
export const uiSchema = {
|
|
35
191
|
"schema.type": { props: { type: "hidden" } },
|