@nolwenture/formik-jsonschema-form 0.4.2 → 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 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 var FormRegistry = React.createContext({
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
- var isSubmitting = useFormikContext().isSubmitting;
43
- var schema = props.schema, _a = props.uiSchema, uiSchema = _a === void 0 ? {} : _a, className = props.className, children = props.children, _b = props.fields, fields = _b === void 0 ? {} : _b, _c = props.templates, templates = _c === void 0 ? {} : _c, _d = props.components, components = _d === void 0 ? {} : _d, _e = props.formContext, formContext = _e === void 0 ? {} : _e, _f = props.useItemsAsAdditionalItems, useItemsAsAdditionalItems = _f === void 0 ? false : _f, _g = props.hideUnmarkedAdditionalProperties, hideUnmarkedAdditionalProperties = _g === void 0 ? false : _g;
44
- var registry = {
45
- fields: __assign(__assign({}, defaultFields), fields),
46
- templates: __assign(__assign({}, defaultTemplates), templates),
47
- components: __assign(__assign({}, defaultComponents), 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: formContext,
50
- useItemsAsAdditionalItems: useItemsAsAdditionalItems,
51
- hideUnmarkedAdditionalProperties: hideUnmarkedAdditionalProperties,
38
+ formContext,
39
+ useItemsAsAdditionalItems,
40
+ hideUnmarkedAdditionalProperties,
52
41
  };
53
- var _h = registry.components, FormEl = _h.Form, FormButton = _h.FormButton, FormButtonWrapper = _h.FormButtonWrapper;
54
- var _SchemaField = registry.fields.SchemaField;
55
- return (_jsx(FormRegistry.Provider, __assign({ value: registry }, { children: _jsxs(FormEl, __assign({ className: className }, { children: [_jsx(_SchemaField, { name: "", schema: schema, uiSchema: uiSchema }), children ? (children) : (_jsx(FormButtonWrapper, { children: _jsx(FormButton, __assign({ type: "submit", disabled: isSubmitting }, { children: "Send" })) }))] })) })));
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
  }
@@ -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,80 @@ export default {
65
23
  uiSchema: { control: { type: "object" } },
66
24
  },
67
25
  };
68
- var Template = function (args) { return (_jsx(Formik, __assign({ initialValues: {}, onSubmit: function (values, formikHelpers) { return __awaiter(void 0, void 0, void 0, function () {
69
- return __generator(this, function (_a) {
70
- action("onSubmit(_, formHelper)")(formikHelpers);
71
- action("onSubmit(values)")(values);
72
- formikHelpers.setSubmitting(false);
73
- return [2 /*return*/];
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
- var InfoFieldButtonNew = styled(InfoFieldButton)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n outline: 2px red solid;\n margin: 0.5em;\n ", " {\n min-width: 200px;\n background: orange;\n color: blue;\n }\n ", " {\n color: green;\n }\n"], ["\n outline: 2px red solid;\n margin: 0.5em;\n ", " {\n min-width: 200px;\n background: orange;\n color: blue;\n }\n ", " {\n color: green;\n }\n"])), InfoFieldButton.styles.InfoFieldBoxInnerElementStyle, InfoFieldButton.styles.InfoFieldLabelStyle);
81
- export var WithUiSchema = Template.bind({});
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
- export var CompleteSchema = Template.bind({});
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 var StrictlyTyped = function () {
93
- return (_jsx(Formik, __assign({ initialValues: { firstName: "", lastName: "" }, onSubmit: function (values, formikHelpers) { return __awaiter(void 0, void 0, void 0, function () {
94
- return __generator(this, function (_a) {
95
- action("onSubmit(_, formHelper)")(formikHelpers);
96
- action("onSubmit(values)")(values);
97
- formikHelpers.setSubmitting(false);
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
- var CustomizedForm = styled(Form)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n ", " {\n color: red;\n }\n"], ["\n ", " {\n color: red;\n }\n"])), styledComponents.FieldTitle);
104
- var CustomizedFieldWrapper = styled.div(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n outline: 2px solid\n ", ";\n"], ["\n outline: 2px solid\n ", ";\n"])), function (props) { return (props.title === "ABC" ? "blue" : "transparent"); });
105
- var CustomizedErrorMessage = function (props) {
106
- var name = props.name;
107
- var errors = useFormikContext().errors;
108
- var error = errors[name];
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
- var CustomizedRequiredIndicator = styled(styledComponents.RequiredIndicator)(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n color: aqua;\n"], ["\n color: aqua;\n"])));
112
- export var StylesCustomized = function () {
113
- return (_jsx(Formik, __assign({ initialValues: {}, onSubmit: function (values, formikHelpers) { return __awaiter(void 0, void 0, void 0, function () {
114
- return __generator(this, function (_a) {
115
- action("onSubmit(_, formHelper)")(formikHelpers);
116
- action("onSubmit(values)")(values);
117
- formikHelpers.setSubmitting(false);
118
- return [2 /*return*/];
119
- });
120
- }); } }, { children: _jsx(CustomizedForm, { schema: simpleSchema, uiSchema: {
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: {
121
100
  age: {
122
101
  props: {
123
102
  wrapper: {
@@ -138,15 +117,42 @@ export var StylesCustomized = function () {
138
117
  RequiredIndicator: CustomizedRequiredIndicator,
139
118
  } }) })));
140
119
  };
141
- export var WithGeneratedSchema = Template.bind({});
120
+ export const WithGeneratedSchema = Template.bind({});
142
121
  WithGeneratedSchema.args = {
143
122
  schema: generatedSchema,
144
123
  uiSchema: {},
145
124
  useItemsAsAdditionalItems: true,
146
125
  };
147
- export var WithRequiredInput = Template.bind({});
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({});
148
151
  WithRequiredInput.args = {
149
152
  schema: requiredInputSchema,
150
- uiSchema: {},
153
+ uiSchema: requiredInputUiSchema,
154
+ // components: {
155
+ // RadioButtonField: MyRadioButtonField,
156
+ // ToggleSwitchField: MyToggleSwitchField,
157
+ // },
151
158
  };
152
- 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", function () {
5
+ test("renders title", () => {
6
6
  render(_jsx(Form, { schema: simpleSchema }));
7
- var titleElement = screen.getByText(/TITLE/i);
7
+ const titleElement = screen.getByText(/TITLE/i);
8
8
  expect(titleElement).toBeInTheDocument();
9
9
  });
@@ -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
- var _this = this;
55
- var _a = useState({
16
+ const [editorGeneratedSchemas, setEditorGeneratedSchemas] = useState({
56
17
  schema: {},
57
18
  uiSchema: {},
58
- }), editorGeneratedSchemas = _a[0], setEditorGeneratedSchemas = _a[1];
59
- useEffect(function () { return console.log(editorGeneratedSchemas); }, [editorGeneratedSchemas]);
60
- return (_jsxs("div", __assign({ style: { display: "flex", justifyContent: "space-between" } }, { children: [_jsxs("div", { children: [_jsx("h1", { children: "Editor" }), _jsx(Formik, __assign({ initialValues: { schema: {}, uiSchema: {} }, onSubmit: function (values, formikHelpers) { return __awaiter(_this, void 0, void 0, function () {
61
- return __generator(this, function (_a) {
62
- setEditorGeneratedSchemas(values);
63
- formikHelpers.setSubmitting(false);
64
- return [2 /*return*/];
65
- });
66
- }); } }, { children: _jsx(Form, __assign({}, formEditorSchemas)) }))] }), _jsxs("div", { children: [_jsx("h1", { children: "Preview" }), _jsx(Formik, __assign({ initialValues: {}, onSubmit: function (values, formikHelpers) { return __awaiter(_this, void 0, void 0, function () {
67
- return __generator(this, function (_a) {
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
- var Template = function (args) { return (_jsx(FormEditor, __assign({}, args))); };
21
- export var Default = Template.bind({});
9
+ const Template = (args) => (_jsx(FormEditor, Object.assign({}, args)));
10
+ export const Default = Template.bind({});
22
11
  Default.args = {};
@@ -9,3 +9,4 @@ export declare const completeSchema: Schema;
9
9
  export declare const completeUiSchema: UiSchema;
10
10
  export declare const generatedSchema: Schema;
11
11
  export declare const requiredInputSchema: Schema;
12
+ export declare const requiredInputUiSchema: UiSchema;
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- export var simpleSchema = {
2
+ export const simpleSchema = {
3
3
  title: "TITLE",
4
4
  properties: {
5
5
  firstName: { type: "string", title: "First name" },
@@ -7,7 +7,7 @@ export var simpleSchema = {
7
7
  age: { type: "number", title: "Age" },
8
8
  },
9
9
  };
10
- export var simpleUiSchema = {
10
+ export const simpleUiSchema = {
11
11
  "ui:description": "Description text",
12
12
  firstName: {
13
13
  "ui:info": {
@@ -15,7 +15,7 @@ export var simpleUiSchema = {
15
15
  },
16
16
  },
17
17
  };
18
- export var completeSchema = {
18
+ export const completeSchema = {
19
19
  title: "Inventory",
20
20
  type: "object",
21
21
  required: ["string", "number", "boolean", "enum"],
@@ -46,6 +46,7 @@ export var completeSchema = {
46
46
  title: "Enum",
47
47
  description: "Enum description",
48
48
  enum: [1, 2, 3, 4],
49
+ default: 1,
49
50
  },
50
51
  enumOneOf: {
51
52
  type: "number",
@@ -69,6 +70,20 @@ export var completeSchema = {
69
70
  { const: 4, title: "four" },
70
71
  ],
71
72
  },
73
+ enumTagSelectAnyOf: {
74
+ type: "string",
75
+ title: "Enum searchable tag select anyOf",
76
+ description: "Enum searchable tag select anyOf description",
77
+ anyOf: [
78
+ { const: "cat", title: "cat" },
79
+ { const: "dog", title: "dog" },
80
+ { const: "bunny", title: "bunny" },
81
+ { const: "canary", title: "canary" },
82
+ { const: "hamster", title: "hamster" },
83
+ { const: "goldfish", title: "goldfish" },
84
+ { const: "dragon", title: "dragon" },
85
+ ],
86
+ },
72
87
  null: { type: "null", title: "Null", description: "Null description" },
73
88
  nested: {
74
89
  type: "object",
@@ -189,7 +204,7 @@ export var completeSchema = {
189
204
  },
190
205
  },
191
206
  };
192
- export var completeUiSchema = {
207
+ export const completeUiSchema = {
193
208
  string: {
194
209
  "ui:help": "String help",
195
210
  "ui:options": {
@@ -214,8 +229,13 @@ export var completeUiSchema = {
214
229
  },
215
230
  enum: {
216
231
  "ui:help": "Enum help",
232
+ "ui:placeholderOptionOptions": {
233
+ props: { disabled: false, hidden: false },
234
+ },
235
+ },
236
+ enumOneOf: {
237
+ placeholder: "Select one",
217
238
  },
218
- enumOneOf: { placeholder: "Select one" },
219
239
  null: {
220
240
  "ui:help": "Null help",
221
241
  },
@@ -277,8 +297,15 @@ export var completeUiSchema = {
277
297
  },
278
298
  },
279
299
  },
300
+ enumTagSelectAnyOf: {
301
+ "ui:field": "SearchMultiTagSelectField",
302
+ "ui:options": {
303
+ placeholder: "Search...",
304
+ emptySearchMessage: "...no matching results found",
305
+ },
306
+ },
280
307
  };
281
- export var generatedSchema = {
308
+ export const generatedSchema = {
282
309
  type: "object",
283
310
  properties: {
284
311
  object: {
@@ -297,12 +324,14 @@ export var generatedSchema = {
297
324
  required: ["object", "value", "property"],
298
325
  additionalProperties: false,
299
326
  };
300
- export var requiredInputSchema = {
327
+ export const requiredInputSchema = {
301
328
  title: "TITLE",
302
329
  required: ["lastName", "requiredNestedObject", "requiredArray"],
303
330
  properties: {
304
331
  firstName: { type: "string", title: "First name" },
305
332
  lastName: { type: "string", title: "Last name" },
333
+ feeling: { type: "boolean", title: "Feeling happy today?" },
334
+ vibes: { type: "boolean", title: "Turn on the good vibes" },
306
335
  arrayOfObject: {
307
336
  type: "array",
308
337
  title: "Array of objects",
@@ -358,3 +387,12 @@ export var requiredInputSchema = {
358
387
  },
359
388
  },
360
389
  };
390
+ export const requiredInputUiSchema = {
391
+ feeling: {
392
+ "ui:field": "RadioField",
393
+ "ui:label": { true: "yes", false: "no" },
394
+ },
395
+ vibes: {
396
+ "ui:field": "ToggleField",
397
+ },
398
+ };