@nolwenture/formik-jsonschema-form 0.4.1 → 0.5.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 +113 -0
- package/dist/Form.js +13 -24
- package/dist/Form.stories.js +98 -85
- package/dist/Form.test.js +2 -2
- package/dist/FormEditor.js +11 -56
- package/dist/FormEditor.stories.js +2 -13
- package/dist/_sampleData.d.ts +1 -0
- package/dist/_sampleData.js +67 -12
- package/dist/fields/AnyField.js +8 -19
- package/dist/fields/ArrayField.js +32 -54
- package/dist/fields/BooleanField.js +4 -15
- package/dist/fields/DateField.js +4 -15
- package/dist/fields/NullField.js +3 -14
- package/dist/fields/NumberField.js +1 -12
- package/dist/fields/ObjectField.js +18 -41
- package/dist/fields/RadioField.d.ts +3 -0
- package/dist/fields/RadioField.js +11 -0
- package/dist/fields/SchemaField.js +7 -18
- package/dist/fields/SearchMultiTagSelectField.d.ts +3 -0
- package/dist/fields/SearchMultiTagSelectField.js +13 -0
- package/dist/fields/StringField.js +9 -49
- package/dist/fields/ToggleField.d.ts +3 -0
- package/dist/fields/ToggleField.js +11 -0
- package/dist/fields/index.d.ts +3 -0
- package/dist/fields/index.js +3 -0
- package/dist/fields/types.js +1 -1
- package/dist/formEditorSchemas.js +3 -3
- package/dist/styledComponents.d.ts +50 -1
- package/dist/styledComponents.js +340 -135
- package/dist/templates/ArrayFieldTemplate.js +8 -20
- package/dist/templates/FieldTemplate.js +7 -20
- package/dist/templates/ObjectFieldTemplate.js +10 -20
- package/dist/types.d.ts +32 -1
- package/dist/utils.d.ts +7 -0
- package/dist/utils.js +50 -34
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -340,6 +340,119 @@ export function MyFormComponent() {
|
|
|
340
340
|
}
|
|
341
341
|
```
|
|
342
342
|
|
|
343
|
+
### Enum fields
|
|
344
|
+
|
|
345
|
+
Enum fields are fields with multiple options to either choose `oneOf` or `anyOf` from.
|
|
346
|
+
There is an alternative field implementation for "anyOf" that when given `"ui:field": "SearchMultiTagSelectField"` results in a searchable multi tag select field.
|
|
347
|
+
|
|
348
|
+
```tsx
|
|
349
|
+
const schema = {
|
|
350
|
+
properties: {
|
|
351
|
+
enum: {
|
|
352
|
+
type: "number",
|
|
353
|
+
title: "Enum",
|
|
354
|
+
enum: [1, 2, 3, 4],
|
|
355
|
+
},
|
|
356
|
+
enumOneOf: {
|
|
357
|
+
type: "number",
|
|
358
|
+
title: "Enum oneOf (non-standard)",
|
|
359
|
+
oneOf: [
|
|
360
|
+
{ const: 1, title: "one" },
|
|
361
|
+
{ const: 2, title: "two" },
|
|
362
|
+
{ const: 3, title: "three" },
|
|
363
|
+
{ const: 4, title: "four" },
|
|
364
|
+
],
|
|
365
|
+
},
|
|
366
|
+
enumAnyOf: {
|
|
367
|
+
type: "number",
|
|
368
|
+
title: "Enum anyOf (non-standard)",
|
|
369
|
+
anyOf: [
|
|
370
|
+
{ const: 1, title: "one" },
|
|
371
|
+
{ const: 2, title: "two" },
|
|
372
|
+
{ const: 3, title: "three" },
|
|
373
|
+
{ const: 4, title: "four" },
|
|
374
|
+
],
|
|
375
|
+
},
|
|
376
|
+
enumTagSelectAnyOf: {
|
|
377
|
+
type: "string",
|
|
378
|
+
title: "Enum searchable tag select anyOf",
|
|
379
|
+
anyOf: [
|
|
380
|
+
{ const: 1, title: "one" },
|
|
381
|
+
{ const: 2, title: "two" },
|
|
382
|
+
{ const: 3, title: "three" },
|
|
383
|
+
{ const: 4, title: "four" },
|
|
384
|
+
],
|
|
385
|
+
},
|
|
386
|
+
},
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
const uiSchema = {
|
|
390
|
+
enumTagSelectAnyOf: {
|
|
391
|
+
"ui:field": "SearchMultiTagSelectField",
|
|
392
|
+
"ui:options": {
|
|
393
|
+
placeholder: "Search...",
|
|
394
|
+
emptySearchMessage: "...no matching results found",
|
|
395
|
+
},
|
|
396
|
+
},
|
|
397
|
+
};
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
### Alternative fields
|
|
401
|
+
|
|
402
|
+
There are alternative fields available for certain types.
|
|
403
|
+
For `type: "string"` there is `DateField`, that has a "dd.mm.yyyy" date input field and a calendar date picker and will save the date input as "yyyy-mm-dd" string.
|
|
404
|
+
|
|
405
|
+
```tsx
|
|
406
|
+
const schema = {
|
|
407
|
+
properties: {
|
|
408
|
+
date: { type: "string", title: "Date" },
|
|
409
|
+
},
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
const uiSchema = {
|
|
413
|
+
date: { "ui:field": "DateField" },
|
|
414
|
+
};
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
For `type: "boolean"` there is `RadioField` and `ToggleField`.
|
|
418
|
+
`RadioField` can take labels for the "true" and "false" options. If left empty, the default labels will be "true" and "false".
|
|
419
|
+
|
|
420
|
+
```tsx
|
|
421
|
+
const schema = {
|
|
422
|
+
properties: {
|
|
423
|
+
question: { type: "boolean", title: "Are you ready?" },
|
|
424
|
+
mode: { type: "boolean", title: "Toggle mode" },
|
|
425
|
+
},
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
const uiSchema = {
|
|
429
|
+
question: {
|
|
430
|
+
"ui:field": "RadioField",
|
|
431
|
+
"ui:label": { true: "yes", false: "no" },
|
|
432
|
+
},
|
|
433
|
+
mode: { "ui:field": "ToggleField" },
|
|
434
|
+
};
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
The alternative fields are customisable. The customisable elements are:
|
|
438
|
+
|
|
439
|
+
```tsx
|
|
440
|
+
ToggleSwitchField.styles = {
|
|
441
|
+
ToggleLabelStyle: ToggleLabel,
|
|
442
|
+
ToggleFieldInputStyle: ToggleFieldInput,
|
|
443
|
+
ToggleStyle: Toggle,
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
RadioButtonField.styles = {
|
|
447
|
+
RadioButtonFieldContainerStyle: RadioButtonFieldContainer,
|
|
448
|
+
RadioButtonFieldElementStyle: RadioButtonFieldElement,
|
|
449
|
+
RadioButtonFieldInputStyle: RadioButtonFieldInput,
|
|
450
|
+
ButtonLabelStyle: ButtonLabel,
|
|
451
|
+
ButtonLabelTrueStyle: ButtonLabelTrue,
|
|
452
|
+
ButtonLabelFalseStyle: ButtonLabelFalse,
|
|
453
|
+
};
|
|
454
|
+
```
|
|
455
|
+
|
|
343
456
|
## Props
|
|
344
457
|
|
|
345
458
|
`Form` component props:
|
package/dist/Form.js
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
2
|
import React from "react";
|
|
14
3
|
import { useFormikContext } from "formik";
|
|
@@ -16,7 +5,7 @@ import * as defaultComponents from "./styledComponents";
|
|
|
16
5
|
import { warnFromUnsupportedKeys } from "./utils";
|
|
17
6
|
import * as defaultFields from "./fields";
|
|
18
7
|
import * as defaultTemplates from "./templates";
|
|
19
|
-
export
|
|
8
|
+
export const FormRegistry = React.createContext({
|
|
20
9
|
fields: defaultFields,
|
|
21
10
|
templates: defaultTemplates,
|
|
22
11
|
components: defaultComponents,
|
|
@@ -39,18 +28,18 @@ export function Form(props) {
|
|
|
39
28
|
"components",
|
|
40
29
|
"hideUnmarkedAdditionalProperties",
|
|
41
30
|
]);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
fields:
|
|
46
|
-
templates:
|
|
47
|
-
components:
|
|
31
|
+
const { isSubmitting } = useFormikContext();
|
|
32
|
+
const { schema, uiSchema = {}, className, children, fields = {}, templates = {}, components = {}, formContext = {}, useItemsAsAdditionalItems = false, hideUnmarkedAdditionalProperties = false, } = props;
|
|
33
|
+
const registry = {
|
|
34
|
+
fields: Object.assign(Object.assign({}, defaultFields), fields),
|
|
35
|
+
templates: Object.assign(Object.assign({}, defaultTemplates), templates),
|
|
36
|
+
components: Object.assign(Object.assign({}, defaultComponents), components),
|
|
48
37
|
definitions: {},
|
|
49
|
-
formContext
|
|
50
|
-
useItemsAsAdditionalItems
|
|
51
|
-
hideUnmarkedAdditionalProperties
|
|
38
|
+
formContext,
|
|
39
|
+
useItemsAsAdditionalItems,
|
|
40
|
+
hideUnmarkedAdditionalProperties,
|
|
52
41
|
};
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return (_jsx(FormRegistry.Provider,
|
|
42
|
+
const { Form: FormEl, FormButton, FormButtonWrapper } = registry.components;
|
|
43
|
+
const _SchemaField = registry.fields.SchemaField;
|
|
44
|
+
return (_jsx(FormRegistry.Provider, Object.assign({ value: registry }, { children: _jsxs(FormEl, Object.assign({ className: className }, { children: [_jsx(_SchemaField, { name: "", schema: schema, uiSchema: uiSchema }), children ? (children) : (_jsx(FormButtonWrapper, { children: _jsx(FormButton, Object.assign({ type: "submit", disabled: isSubmitting }, { children: "Send" })) }))] })) })));
|
|
56
45
|
}
|
package/dist/Form.stories.js
CHANGED
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
2
|
-
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
3
|
-
return cooked;
|
|
4
|
-
};
|
|
5
|
-
var __assign = (this && this.__assign) || function () {
|
|
6
|
-
__assign = Object.assign || function(t) {
|
|
7
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
8
|
-
s = arguments[i];
|
|
9
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
10
|
-
t[p] = s[p];
|
|
11
|
-
}
|
|
12
|
-
return t;
|
|
13
|
-
};
|
|
14
|
-
return __assign.apply(this, arguments);
|
|
15
|
-
};
|
|
16
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
17
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
18
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -22,39 +7,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
22
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
23
8
|
});
|
|
24
9
|
};
|
|
25
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
26
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
27
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
28
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
29
|
-
function step(op) {
|
|
30
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
31
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
32
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
33
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
34
|
-
switch (op[0]) {
|
|
35
|
-
case 0: case 1: t = op; break;
|
|
36
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
37
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
38
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
39
|
-
default:
|
|
40
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
41
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
42
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
43
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
44
|
-
if (t[2]) _.ops.pop();
|
|
45
|
-
_.trys.pop(); continue;
|
|
46
|
-
}
|
|
47
|
-
op = body.call(thisArg, _);
|
|
48
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
49
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
53
11
|
import { action } from "@storybook/addon-actions";
|
|
54
12
|
import styled from "styled-components";
|
|
55
13
|
import { Formik, useFormikContext } from "formik";
|
|
56
|
-
import { InfoFieldButton } from "./styledComponents";
|
|
57
|
-
import { completeSchema, completeUiSchema, simpleSchema, simpleUiSchema, generatedSchema, requiredInputSchema, } from "./_sampleData";
|
|
14
|
+
import { InfoFieldButton, SearchableMultiTagSelectField, } from "./styledComponents";
|
|
15
|
+
import { completeSchema, completeUiSchema, simpleSchema, simpleUiSchema, generatedSchema, requiredInputSchema, requiredInputUiSchema, } from "./_sampleData";
|
|
58
16
|
import { Form, styledComponents } from "./";
|
|
59
17
|
export default {
|
|
60
18
|
title: "Form",
|
|
@@ -65,59 +23,87 @@ export default {
|
|
|
65
23
|
uiSchema: { control: { type: "object" } },
|
|
66
24
|
},
|
|
67
25
|
};
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
});
|
|
75
|
-
}); } }, { children: _jsx(Form, __assign({}, args)) }))); };
|
|
76
|
-
export var Simple = Template.bind({});
|
|
26
|
+
const Template = (args) => (_jsx(Formik, Object.assign({ initialValues: {}, onSubmit: (values, formikHelpers) => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
+
action("onSubmit(_, formHelper)")(formikHelpers);
|
|
28
|
+
action("onSubmit(values)")(values);
|
|
29
|
+
formikHelpers.setSubmitting(false);
|
|
30
|
+
}) }, { children: _jsx(Form, Object.assign({}, args)) })));
|
|
31
|
+
export const Simple = Template.bind({});
|
|
77
32
|
Simple.args = {
|
|
78
33
|
schema: simpleSchema,
|
|
79
34
|
};
|
|
80
|
-
|
|
81
|
-
|
|
35
|
+
const InfoFieldButtonNew = styled(InfoFieldButton) `
|
|
36
|
+
outline: 2px red solid;
|
|
37
|
+
margin: 0.5em;
|
|
38
|
+
${InfoFieldButton.styles.InfoFieldBoxInnerElementStyle} {
|
|
39
|
+
min-width: 200px;
|
|
40
|
+
background: orange;
|
|
41
|
+
color: blue;
|
|
42
|
+
}
|
|
43
|
+
${InfoFieldButton.styles.InfoFieldLabelStyle} {
|
|
44
|
+
color: green;
|
|
45
|
+
}
|
|
46
|
+
`;
|
|
47
|
+
export const WithUiSchema = Template.bind({});
|
|
82
48
|
WithUiSchema.args = {
|
|
83
49
|
schema: simpleSchema,
|
|
84
50
|
uiSchema: simpleUiSchema,
|
|
85
51
|
components: { InfoFieldButton: InfoFieldButtonNew },
|
|
86
52
|
};
|
|
87
|
-
|
|
53
|
+
// TODO: get customisable styling to work
|
|
54
|
+
const MyStyledSearchField = styled(SearchableMultiTagSelectField) `
|
|
55
|
+
${SearchableMultiTagSelectField.styles.MultiSelectInputStyle} {
|
|
56
|
+
height: 2.5em;
|
|
57
|
+
}
|
|
58
|
+
${SearchableMultiTagSelectField.styles.MultiSelectBadgeStyle} {
|
|
59
|
+
background: blue;
|
|
60
|
+
}
|
|
61
|
+
`;
|
|
62
|
+
export const CompleteSchema = Template.bind({});
|
|
88
63
|
CompleteSchema.args = {
|
|
89
64
|
schema: completeSchema,
|
|
90
65
|
uiSchema: completeUiSchema,
|
|
66
|
+
components: { SearchableMultiTagSelectField: MyStyledSearchField },
|
|
91
67
|
};
|
|
92
|
-
export
|
|
93
|
-
return (_jsx(Formik,
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return [2 /*return*/];
|
|
99
|
-
});
|
|
100
|
-
}); } }, { children: _jsx(Form, { schema: simpleSchema }) })));
|
|
68
|
+
export const StrictlyTyped = () => {
|
|
69
|
+
return (_jsx(Formik, Object.assign({ initialValues: { firstName: "", lastName: "" }, onSubmit: (values, formikHelpers) => __awaiter(void 0, void 0, void 0, function* () {
|
|
70
|
+
action("onSubmit(_, formHelper)")(formikHelpers);
|
|
71
|
+
action("onSubmit(values)")(values);
|
|
72
|
+
formikHelpers.setSubmitting(false);
|
|
73
|
+
}) }, { children: _jsx(Form, { schema: simpleSchema }) })));
|
|
101
74
|
};
|
|
102
75
|
/*** CUSTOMIZATION ***/
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
76
|
+
const CustomizedForm = styled(Form) `
|
|
77
|
+
${styledComponents.FieldTitle} {
|
|
78
|
+
color: red;
|
|
79
|
+
}
|
|
80
|
+
`;
|
|
81
|
+
const CustomizedFieldWrapper = styled.div `
|
|
82
|
+
outline: 2px solid
|
|
83
|
+
${(props) => (props.title === "ABC" ? "blue" : "transparent")};
|
|
84
|
+
`;
|
|
85
|
+
const CustomizedErrorMessage = (props) => {
|
|
86
|
+
const { name } = props;
|
|
87
|
+
const { errors } = useFormikContext();
|
|
88
|
+
const error = errors[name];
|
|
109
89
|
return error ? _jsx("p", { children: error }) : _jsx("p", { children: "Hurray! No errors" });
|
|
110
90
|
};
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
91
|
+
const CustomizedRequiredIndicator = styled(styledComponents.RequiredIndicator) `
|
|
92
|
+
color: aqua;
|
|
93
|
+
`;
|
|
94
|
+
export const StylesCustomized = () => {
|
|
95
|
+
return (_jsx(Formik, Object.assign({ initialValues: {}, onSubmit: (values, formikHelpers) => __awaiter(void 0, void 0, void 0, function* () {
|
|
96
|
+
action("onSubmit(_, formHelper)")(formikHelpers);
|
|
97
|
+
action("onSubmit(values)")(values);
|
|
98
|
+
formikHelpers.setSubmitting(false);
|
|
99
|
+
}) }, { children: _jsx(CustomizedForm, { schema: simpleSchema, uiSchema: {
|
|
100
|
+
age: {
|
|
101
|
+
props: {
|
|
102
|
+
wrapper: {
|
|
103
|
+
title: "ABC",
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
},
|
|
121
107
|
firstName: {
|
|
122
108
|
props: {
|
|
123
109
|
wrapper: {
|
|
@@ -131,15 +117,42 @@ export var StylesCustomized = function () {
|
|
|
131
117
|
RequiredIndicator: CustomizedRequiredIndicator,
|
|
132
118
|
} }) })));
|
|
133
119
|
};
|
|
134
|
-
export
|
|
120
|
+
export const WithGeneratedSchema = Template.bind({});
|
|
135
121
|
WithGeneratedSchema.args = {
|
|
136
122
|
schema: generatedSchema,
|
|
137
123
|
uiSchema: {},
|
|
138
124
|
useItemsAsAdditionalItems: true,
|
|
139
125
|
};
|
|
140
|
-
|
|
126
|
+
// Test to add style to RadioButtonField and ToggleSwitchField
|
|
127
|
+
// const MyRadioButtonField = styled(RadioButtonField)`
|
|
128
|
+
// border: 1px solid purple;
|
|
129
|
+
// ${RadioButtonField.styles.RadioButtonFieldElementStyle} {
|
|
130
|
+
// font-family: sans-serif;
|
|
131
|
+
// font-weight: bold;
|
|
132
|
+
// }
|
|
133
|
+
// ${RadioButtonField.styles.ButtonLabelTrueStyle} {
|
|
134
|
+
// color: green;
|
|
135
|
+
// }
|
|
136
|
+
// ${RadioButtonField.styles.ButtonLabelFalseStyle} {
|
|
137
|
+
// color: red;
|
|
138
|
+
// }
|
|
139
|
+
// `;
|
|
140
|
+
// const MyToggleSwitchField = styled(ToggleSwitchField)`
|
|
141
|
+
// margin-left: 0.5em;
|
|
142
|
+
// ${ToggleSwitchField.styles.ToggleStyle}:before {
|
|
143
|
+
// background: green;
|
|
144
|
+
// }
|
|
145
|
+
// ${ToggleSwitchField.styles.ToggleFieldInputStyle}:checked +${ToggleSwitchField
|
|
146
|
+
// .styles.ToggleStyle} {
|
|
147
|
+
// background: pink;
|
|
148
|
+
// }
|
|
149
|
+
// `;
|
|
150
|
+
export const WithRequiredInput = Template.bind({});
|
|
141
151
|
WithRequiredInput.args = {
|
|
142
152
|
schema: requiredInputSchema,
|
|
143
|
-
uiSchema:
|
|
153
|
+
uiSchema: requiredInputUiSchema,
|
|
154
|
+
// components: {
|
|
155
|
+
// RadioButtonField: MyRadioButtonField,
|
|
156
|
+
// ToggleSwitchField: MyToggleSwitchField,
|
|
157
|
+
// },
|
|
144
158
|
};
|
|
145
|
-
var templateObject_1, templateObject_2, templateObject_3, templateObject_4;
|
package/dist/Form.test.js
CHANGED
|
@@ -2,8 +2,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { render, screen } from "@testing-library/react";
|
|
3
3
|
import { Form } from "./Form";
|
|
4
4
|
import { simpleSchema } from "./_sampleData";
|
|
5
|
-
test("renders title",
|
|
5
|
+
test("renders title", () => {
|
|
6
6
|
render(_jsx(Form, { schema: simpleSchema }));
|
|
7
|
-
|
|
7
|
+
const titleElement = screen.getByText(/TITLE/i);
|
|
8
8
|
expect(titleElement).toBeInTheDocument();
|
|
9
9
|
});
|
package/dist/FormEditor.js
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -18,57 +7,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
18
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
8
|
});
|
|
20
9
|
};
|
|
21
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
-
function step(op) {
|
|
26
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
-
switch (op[0]) {
|
|
31
|
-
case 0: case 1: t = op; break;
|
|
32
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
-
default:
|
|
36
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
-
if (t[2]) _.ops.pop();
|
|
41
|
-
_.trys.pop(); continue;
|
|
42
|
-
}
|
|
43
|
-
op = body.call(thisArg, _);
|
|
44
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
10
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
49
11
|
import { Formik } from "formik";
|
|
50
12
|
import { useEffect, useState } from "react";
|
|
51
13
|
import { Form } from "./Form";
|
|
52
14
|
import * as formEditorSchemas from "./formEditorSchemas";
|
|
53
15
|
export function FormEditor(props) {
|
|
54
|
-
|
|
55
|
-
var _a = useState({
|
|
16
|
+
const [editorGeneratedSchemas, setEditorGeneratedSchemas] = useState({
|
|
56
17
|
schema: {},
|
|
57
18
|
uiSchema: {},
|
|
58
|
-
})
|
|
59
|
-
useEffect(
|
|
60
|
-
return (_jsxs("div",
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
// action("onSubmit(_, formHelper)")(formikHelpers);
|
|
69
|
-
// action("onSubmit(values)")(values);
|
|
70
|
-
formikHelpers.setSubmitting(false);
|
|
71
|
-
return [2 /*return*/];
|
|
72
|
-
});
|
|
73
|
-
}); } }, { children: _jsx(Form, __assign({}, editorGeneratedSchemas)) }))] })] })));
|
|
19
|
+
});
|
|
20
|
+
useEffect(() => console.log(editorGeneratedSchemas), [editorGeneratedSchemas]);
|
|
21
|
+
return (_jsxs("div", Object.assign({ style: { display: "flex", justifyContent: "space-between" } }, { children: [_jsxs("div", { children: [_jsx("h1", { children: "Editor" }), _jsx(Formik, Object.assign({ initialValues: { schema: {}, uiSchema: {} }, onSubmit: (values, formikHelpers) => __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
setEditorGeneratedSchemas(values);
|
|
23
|
+
formikHelpers.setSubmitting(false);
|
|
24
|
+
}) }, { children: _jsx(Form, Object.assign({}, formEditorSchemas)) }))] }), _jsxs("div", { children: [_jsx("h1", { children: "Preview" }), _jsx(Formik, Object.assign({ initialValues: {}, onSubmit: (values, formikHelpers) => __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
// action("onSubmit(_, formHelper)")(formikHelpers);
|
|
26
|
+
// action("onSubmit(values)")(values);
|
|
27
|
+
formikHelpers.setSubmitting(false);
|
|
28
|
+
}) }, { children: _jsx(Form, Object.assign({}, editorGeneratedSchemas)) }))] })] })));
|
|
74
29
|
}
|
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
2
|
import { FormEditor } from "./FormEditor";
|
|
14
3
|
export default {
|
|
@@ -17,6 +6,6 @@ export default {
|
|
|
17
6
|
// More on argTypes: https://storybook.js.org/docs/react/api/argtypes
|
|
18
7
|
argTypes: {},
|
|
19
8
|
};
|
|
20
|
-
|
|
21
|
-
export
|
|
9
|
+
const Template = (args) => (_jsx(FormEditor, Object.assign({}, args)));
|
|
10
|
+
export const Default = Template.bind({});
|
|
22
11
|
Default.args = {};
|
package/dist/_sampleData.d.ts
CHANGED