@nolwenture/formik-jsonschema-form 0.4.2 → 0.6.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 +187 -0
- package/dist/Form.d.ts +2 -2
- package/dist/Form.js +15 -26
- package/dist/Form.stories.d.ts +12 -11
- package/dist/Form.stories.js +134 -101
- package/dist/Form.test.js +3 -3
- package/dist/FormEditor.d.ts +3 -3
- package/dist/FormEditor.js +14 -59
- package/dist/FormEditor.stories.d.ts +5 -4
- package/dist/FormEditor.stories.js +3 -16
- package/dist/fields/AnyField.d.ts +3 -3
- package/dist/fields/AnyField.js +12 -24
- package/dist/fields/ArrayField.d.ts +3 -3
- package/dist/fields/ArrayField.js +42 -64
- package/dist/fields/BooleanField.d.ts +3 -3
- package/dist/fields/BooleanField.js +7 -18
- package/dist/fields/DateField.d.ts +3 -3
- package/dist/fields/DateField.js +7 -18
- package/dist/fields/NullField.d.ts +3 -3
- package/dist/fields/NullField.js +5 -16
- package/dist/fields/NumberField.d.ts +3 -3
- package/dist/fields/NumberField.js +3 -14
- package/dist/fields/ObjectField.d.ts +3 -3
- package/dist/fields/ObjectField.js +43 -46
- package/dist/fields/RadioField.d.ts +3 -0
- package/dist/fields/RadioField.js +11 -0
- package/dist/fields/SchemaField.d.ts +3 -3
- package/dist/fields/SchemaField.js +13 -23
- package/dist/fields/SearchMultiTagSelectField.d.ts +3 -0
- package/dist/fields/SearchMultiTagSelectField.js +14 -0
- package/dist/fields/StringField.d.ts +3 -3
- package/dist/fields/StringField.js +13 -51
- 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.d.ts +1 -1
- package/dist/formEditorSchemas.js +3 -3
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.js +2 -0
- package/dist/hooks/useExtractUiSchema.d.ts +8 -0
- package/dist/hooks/useExtractUiSchema.js +22 -0
- package/dist/hooks/useSetDefault.d.ts +2 -0
- package/dist/hooks/useSetDefault.js +16 -0
- package/dist/sampleData/completeSchema.d.ts +3 -0
- package/dist/{_sampleData.js → sampleData/completeSchema.js} +28 -97
- package/dist/sampleData/conditionsSchema.d.ts +3 -0
- package/dist/sampleData/conditionsSchema.js +80 -0
- package/dist/sampleData/generatedSchema.d.ts +2 -0
- package/dist/sampleData/generatedSchema.js +19 -0
- package/dist/sampleData/index.d.ts +5 -0
- package/dist/sampleData/index.js +5 -0
- package/dist/sampleData/requiredInputSchema.d.ts +3 -0
- package/dist/sampleData/requiredInputSchema.js +72 -0
- package/dist/sampleData/simpleData.d.ts +7 -0
- package/dist/sampleData/simpleData.js +16 -0
- package/dist/styledComponents.d.ts +193 -47
- package/dist/styledComponents.js +342 -138
- package/dist/templates/ArrayFieldTemplate.d.ts +3 -3
- package/dist/templates/ArrayFieldTemplate.js +11 -23
- package/dist/templates/FieldTemplate.d.ts +3 -3
- package/dist/templates/FieldTemplate.js +11 -23
- package/dist/templates/ObjectFieldTemplate.d.ts +3 -3
- package/dist/templates/ObjectFieldTemplate.js +13 -23
- package/dist/types.d.ts +34 -3
- package/dist/utils/__tests/getEnums.test.d.ts +1 -0
- package/dist/utils/__tests/getEnums.test.js +64 -0
- package/dist/utils/__tests/resolveSchema.test.d.ts +1 -0
- package/dist/utils/__tests/resolveSchema.test.js +106 -0
- package/dist/utils/deepEqual.d.ts +1 -0
- package/dist/utils/deepEqual.js +18 -0
- package/dist/utils/getEnums.d.ts +10 -0
- package/dist/utils/getEnums.js +30 -0
- package/dist/utils/getTitleAndDescription.d.ts +12 -0
- package/dist/utils/getTitleAndDescription.js +15 -0
- package/dist/utils/getTypes.d.ts +5 -0
- package/dist/utils/getTypes.js +53 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.js +14 -0
- package/dist/utils/mergeSchemas.d.ts +1 -0
- package/dist/utils/mergeSchemas.js +26 -0
- package/dist/utils/resolveSchema.d.ts +2 -0
- package/dist/utils/resolveSchema.js +68 -0
- package/package.json +32 -37
- package/dist/_sampleData.d.ts +0 -11
- package/dist/utils.d.ts +0 -25
- package/dist/utils.js +0 -125
package/README.md
CHANGED
|
@@ -340,6 +340,193 @@ 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
|
+
|
|
456
|
+
### Conditional fields
|
|
457
|
+
|
|
458
|
+
Conditional fields depending on a parent field input can be given with an `if-then-else` logic inside the schema making use of `allOf`. While `if`and `then` are required to make the condition work, `else` is optional.
|
|
459
|
+
|
|
460
|
+
```tsx
|
|
461
|
+
export const conditionsSchema = {
|
|
462
|
+
type: "object",
|
|
463
|
+
properties: {
|
|
464
|
+
animal: {
|
|
465
|
+
type: "string",
|
|
466
|
+
oneOf: [
|
|
467
|
+
{ const: "cat", title: "Cat" },
|
|
468
|
+
{ const: "fish", title: "Fish" },
|
|
469
|
+
{ const: "dog", title: "Dog" },
|
|
470
|
+
],
|
|
471
|
+
},
|
|
472
|
+
},
|
|
473
|
+
allOf: [
|
|
474
|
+
{
|
|
475
|
+
if: {
|
|
476
|
+
properties: {
|
|
477
|
+
animal: {
|
|
478
|
+
const: "cat",
|
|
479
|
+
},
|
|
480
|
+
},
|
|
481
|
+
},
|
|
482
|
+
then: {
|
|
483
|
+
properties: {
|
|
484
|
+
food: {
|
|
485
|
+
type: "string",
|
|
486
|
+
enum: ["meat", "grass", "fish"],
|
|
487
|
+
},
|
|
488
|
+
},
|
|
489
|
+
required: ["food"],
|
|
490
|
+
},
|
|
491
|
+
},
|
|
492
|
+
{
|
|
493
|
+
if: {
|
|
494
|
+
properties: {
|
|
495
|
+
animal: {
|
|
496
|
+
const: "fish",
|
|
497
|
+
},
|
|
498
|
+
},
|
|
499
|
+
},
|
|
500
|
+
then: {
|
|
501
|
+
properties: {
|
|
502
|
+
food: {
|
|
503
|
+
type: "string",
|
|
504
|
+
enum: ["insect", "worms"],
|
|
505
|
+
},
|
|
506
|
+
water: {
|
|
507
|
+
type: "string",
|
|
508
|
+
enum: ["lake", "sea"],
|
|
509
|
+
},
|
|
510
|
+
},
|
|
511
|
+
required: ["food", "water"],
|
|
512
|
+
},
|
|
513
|
+
else: {
|
|
514
|
+
properties: {
|
|
515
|
+
likesWalkiesWhere: {
|
|
516
|
+
type: "string",
|
|
517
|
+
enum: ["park", "forest", "garden"],
|
|
518
|
+
},
|
|
519
|
+
},
|
|
520
|
+
},
|
|
521
|
+
},
|
|
522
|
+
|
|
523
|
+
{
|
|
524
|
+
required: ["animal"],
|
|
525
|
+
},
|
|
526
|
+
],
|
|
527
|
+
};
|
|
528
|
+
```
|
|
529
|
+
|
|
343
530
|
## Props
|
|
344
531
|
|
|
345
532
|
`Form` component props:
|
package/dist/Form.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
+
import type { FormProps, FormRegistryContextValue } from "./types";
|
|
1
2
|
import React from "react";
|
|
2
|
-
import { FormProps, FormRegistryContextValue } from "./types";
|
|
3
3
|
export declare const FormRegistry: React.Context<FormRegistryContextValue>;
|
|
4
|
-
export declare
|
|
4
|
+
export declare const Form: <T>(props: FormProps<T>) => import("react/jsx-runtime").JSX.Element;
|
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,
|
|
@@ -25,7 +14,7 @@ export var FormRegistry = React.createContext({
|
|
|
25
14
|
useItemsAsAdditionalItems: false,
|
|
26
15
|
hideUnmarkedAdditionalProperties: false,
|
|
27
16
|
});
|
|
28
|
-
export
|
|
17
|
+
export const Form = (props) => {
|
|
29
18
|
warnFromUnsupportedKeys("Form", props, [
|
|
30
19
|
"schema",
|
|
31
20
|
"onSubmit",
|
|
@@ -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,
|
|
56
|
-
}
|
|
42
|
+
const { Form: FormEl, FormButton, FormButtonWrapper } = registry.components;
|
|
43
|
+
const SchemaField = registry.fields.SchemaField;
|
|
44
|
+
return (_jsx(FormRegistry.Provider, { value: registry, children: _jsxs(FormEl, { className: className, children: [_jsx(SchemaField, { name: "", schema: schema, uiSchema: uiSchema }), children ? (children) : (_jsx(FormButtonWrapper, { children: _jsx(FormButton, { type: "submit", disabled: isSubmitting, children: "Send" }) }))] }) }));
|
|
45
|
+
};
|
package/dist/Form.stories.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
import { ComponentStory, ComponentMeta } from "@storybook/react";
|
|
1
|
+
import type { StoryObj, Meta } from "@storybook/react";
|
|
3
2
|
import { Form } from "./";
|
|
4
|
-
declare const
|
|
5
|
-
export default
|
|
6
|
-
|
|
7
|
-
export declare const
|
|
8
|
-
export declare const
|
|
9
|
-
export declare const
|
|
10
|
-
export declare const
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
3
|
+
declare const meta: Meta<typeof Form>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof Form>;
|
|
6
|
+
export declare const Simple: Story;
|
|
7
|
+
export declare const WithUiSchema: Story;
|
|
8
|
+
export declare const CompleteSchema: Story;
|
|
9
|
+
export declare const StrictlyTyped: () => import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export declare const StylesCustomized: () => import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export declare const WithGeneratedSchema: Story;
|
|
12
|
+
export declare const WithRequiredInput: Story;
|
|
13
|
+
export declare const WithConditions: Story;
|
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,41 +7,25 @@ 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
|
|
26
|
-
var
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
}
|
|
10
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
11
|
+
var t = {};
|
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
15
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
16
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
17
|
+
t[p[i]] = s[p[i]];
|
|
18
|
+
}
|
|
19
|
+
return t;
|
|
51
20
|
};
|
|
52
21
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
53
22
|
import { action } from "@storybook/addon-actions";
|
|
54
23
|
import styled from "styled-components";
|
|
55
24
|
import { Formik, useFormikContext } from "formik";
|
|
56
|
-
import { InfoFieldButton } from "./styledComponents";
|
|
57
|
-
import { completeSchema, completeUiSchema, simpleSchema, simpleUiSchema, generatedSchema, requiredInputSchema, } from "./
|
|
25
|
+
import { InfoFieldButton, SearchableMultiTagSelectField, } from "./styledComponents";
|
|
26
|
+
import { completeSchema, completeUiSchema, simpleSchema, simpleUiSchema, generatedSchema, requiredInputSchema, requiredInputUiSchema, conditionsSchema, conditionsUiSchema, } from "./sampleData";
|
|
58
27
|
import { Form, styledComponents } from "./";
|
|
59
|
-
|
|
28
|
+
const meta = {
|
|
60
29
|
title: "Form",
|
|
61
30
|
component: Form,
|
|
62
31
|
// More on argTypes: https://storybook.js.org/docs/react/api/argtypes
|
|
@@ -64,60 +33,88 @@ export default {
|
|
|
64
33
|
schema: { control: { type: "object" } },
|
|
65
34
|
uiSchema: { control: { type: "object" } },
|
|
66
35
|
},
|
|
36
|
+
render: (_a) => {
|
|
37
|
+
var args = __rest(_a, []);
|
|
38
|
+
return (_jsx(Formik, { initialValues: {}, onSubmit: (values, formikHelpers) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
+
action("onSubmit(_, formHelper)")(formikHelpers);
|
|
40
|
+
action("onSubmit(values)")(values);
|
|
41
|
+
formikHelpers.setSubmitting(false);
|
|
42
|
+
}), children: _jsx(Form, Object.assign({}, args)) }));
|
|
43
|
+
},
|
|
67
44
|
};
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return [2 /*return*/];
|
|
74
|
-
});
|
|
75
|
-
}); } }, { children: _jsx(Form, __assign({}, args)) }))); };
|
|
76
|
-
export var Simple = Template.bind({});
|
|
77
|
-
Simple.args = {
|
|
78
|
-
schema: simpleSchema,
|
|
45
|
+
export default meta;
|
|
46
|
+
export const Simple = {
|
|
47
|
+
args: {
|
|
48
|
+
schema: simpleSchema,
|
|
49
|
+
},
|
|
79
50
|
};
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
51
|
+
const InfoFieldButtonNew = styled(InfoFieldButton) `
|
|
52
|
+
outline: 2px red solid;
|
|
53
|
+
margin: 0.5em;
|
|
54
|
+
${InfoFieldButton.styles.InfoFieldBoxInnerElementStyle} {
|
|
55
|
+
min-width: 200px;
|
|
56
|
+
background: orange;
|
|
57
|
+
color: blue;
|
|
58
|
+
}
|
|
59
|
+
${InfoFieldButton.styles.InfoFieldLabelStyle} {
|
|
60
|
+
color: green;
|
|
61
|
+
}
|
|
62
|
+
`;
|
|
63
|
+
export const WithUiSchema = {
|
|
64
|
+
args: {
|
|
65
|
+
schema: simpleSchema,
|
|
66
|
+
uiSchema: simpleUiSchema,
|
|
67
|
+
components: { InfoFieldButton: InfoFieldButtonNew },
|
|
68
|
+
},
|
|
86
69
|
};
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
70
|
+
// TODO: get customisable styling to work
|
|
71
|
+
const MyStyledSearchField = styled(SearchableMultiTagSelectField) `
|
|
72
|
+
${SearchableMultiTagSelectField.styles.MultiSelectInputStyle} {
|
|
73
|
+
height: 2.5em;
|
|
74
|
+
}
|
|
75
|
+
${SearchableMultiTagSelectField.styles.MultiSelectBadgeStyle} {
|
|
76
|
+
background: blue;
|
|
77
|
+
}
|
|
78
|
+
`;
|
|
79
|
+
export const CompleteSchema = {
|
|
80
|
+
args: {
|
|
81
|
+
schema: completeSchema,
|
|
82
|
+
uiSchema: completeUiSchema,
|
|
83
|
+
components: { SearchableMultiTagSelectField: MyStyledSearchField },
|
|
84
|
+
},
|
|
91
85
|
};
|
|
92
|
-
export
|
|
93
|
-
return (_jsx(Formik,
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return [2 /*return*/];
|
|
99
|
-
});
|
|
100
|
-
}); } }, { children: _jsx(Form, { schema: simpleSchema }) })));
|
|
86
|
+
export const StrictlyTyped = () => {
|
|
87
|
+
return (_jsx(Formik, { initialValues: { firstName: "", lastName: "" }, onSubmit: (values, formikHelpers) => __awaiter(void 0, void 0, void 0, function* () {
|
|
88
|
+
action("onSubmit(_, formHelper)")(formikHelpers);
|
|
89
|
+
action("onSubmit(values)")(values);
|
|
90
|
+
formikHelpers.setSubmitting(false);
|
|
91
|
+
}), children: _jsx(Form, { schema: simpleSchema }) }));
|
|
101
92
|
};
|
|
102
93
|
/*** CUSTOMIZATION ***/
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
94
|
+
const CustomizedForm = styled(Form) `
|
|
95
|
+
${styledComponents.FieldTitle} {
|
|
96
|
+
color: red;
|
|
97
|
+
}
|
|
98
|
+
`;
|
|
99
|
+
const CustomizedFieldWrapper = styled.div `
|
|
100
|
+
outline: 2px solid
|
|
101
|
+
${(props) => (props.title === "ABC" ? "blue" : "transparent")};
|
|
102
|
+
`;
|
|
103
|
+
const CustomizedErrorMessage = (props) => {
|
|
104
|
+
const { name } = props;
|
|
105
|
+
const { errors } = useFormikContext();
|
|
106
|
+
const error = errors[name];
|
|
109
107
|
return error ? _jsx("p", { children: error }) : _jsx("p", { children: "Hurray! No errors" });
|
|
110
108
|
};
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}); } }, { children: _jsx(CustomizedForm, { schema: simpleSchema, uiSchema: {
|
|
109
|
+
const CustomizedRequiredIndicator = styled(styledComponents.RequiredIndicator) `
|
|
110
|
+
color: aqua;
|
|
111
|
+
`;
|
|
112
|
+
export const StylesCustomized = () => {
|
|
113
|
+
return (_jsx(Formik, { initialValues: {}, onSubmit: (values, formikHelpers) => __awaiter(void 0, void 0, void 0, function* () {
|
|
114
|
+
action("onSubmit(_, formHelper)")(formikHelpers);
|
|
115
|
+
action("onSubmit(values)")(values);
|
|
116
|
+
formikHelpers.setSubmitting(false);
|
|
117
|
+
}), children: _jsx(CustomizedForm, { schema: simpleSchema, uiSchema: {
|
|
121
118
|
age: {
|
|
122
119
|
props: {
|
|
123
120
|
wrapper: {
|
|
@@ -136,17 +133,53 @@ export var StylesCustomized = function () {
|
|
|
136
133
|
FieldWrapper: CustomizedFieldWrapper,
|
|
137
134
|
ErrorMessage: CustomizedErrorMessage,
|
|
138
135
|
RequiredIndicator: CustomizedRequiredIndicator,
|
|
139
|
-
} }) }))
|
|
136
|
+
} }) }));
|
|
140
137
|
};
|
|
141
|
-
export
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
138
|
+
export const WithGeneratedSchema = {
|
|
139
|
+
args: {
|
|
140
|
+
schema: generatedSchema,
|
|
141
|
+
uiSchema: {},
|
|
142
|
+
useItemsAsAdditionalItems: true,
|
|
143
|
+
},
|
|
146
144
|
};
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
145
|
+
// Test to add style to RadioButtonField and ToggleSwitchField
|
|
146
|
+
// const MyRadioButtonField = styled(RadioButtonField)`
|
|
147
|
+
// border: 1px solid purple;
|
|
148
|
+
// ${RadioButtonField.styles.RadioButtonFieldElementStyle} {
|
|
149
|
+
// font-family: sans-serif;
|
|
150
|
+
// font-weight: bold;
|
|
151
|
+
// }
|
|
152
|
+
// ${RadioButtonField.styles.ButtonLabelTrueStyle} {
|
|
153
|
+
// color: green;
|
|
154
|
+
// }
|
|
155
|
+
// ${RadioButtonField.styles.ButtonLabelFalseStyle} {
|
|
156
|
+
// color: red;
|
|
157
|
+
// }
|
|
158
|
+
// `;
|
|
159
|
+
// const MyToggleSwitchField = styled(ToggleSwitchField)`
|
|
160
|
+
// margin-left: 0.5em;
|
|
161
|
+
// ${ToggleSwitchField.styles.ToggleStyle}:before {
|
|
162
|
+
// background: green;
|
|
163
|
+
// }
|
|
164
|
+
// ${ToggleSwitchField.styles.ToggleFieldInputStyle}:checked +${ToggleSwitchField
|
|
165
|
+
// .styles.ToggleStyle} {
|
|
166
|
+
// background: pink;
|
|
167
|
+
// }
|
|
168
|
+
// `;
|
|
169
|
+
export const WithRequiredInput = {
|
|
170
|
+
args: {
|
|
171
|
+
schema: requiredInputSchema,
|
|
172
|
+
uiSchema: requiredInputUiSchema,
|
|
173
|
+
// components: {
|
|
174
|
+
// RadioButtonField: MyRadioButtonField,
|
|
175
|
+
// ToggleSwitchField: MyToggleSwitchField,
|
|
176
|
+
// },
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
export const WithConditions = {
|
|
180
|
+
args: {
|
|
181
|
+
schema: conditionsSchema,
|
|
182
|
+
uiSchema: conditionsUiSchema,
|
|
183
|
+
hideUnmarkedAdditionalProperties: true,
|
|
184
|
+
},
|
|
151
185
|
};
|
|
152
|
-
var templateObject_1, templateObject_2, templateObject_3, templateObject_4;
|
package/dist/Form.test.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { render, screen } from "@testing-library/react";
|
|
3
3
|
import { Form } from "./Form";
|
|
4
|
-
import { simpleSchema } from "./
|
|
5
|
-
test("renders title",
|
|
4
|
+
import { simpleSchema } from "./sampleData";
|
|
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.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
1
|
+
import type { Schema, UiSchema } from "./types";
|
|
2
|
+
import React from "react";
|
|
3
3
|
export type FormEditorProps = {};
|
|
4
4
|
export type FormEditorValues = {
|
|
5
5
|
schema: Schema;
|
|
6
6
|
uiSchema: UiSchema;
|
|
7
7
|
};
|
|
8
|
-
export declare
|
|
8
|
+
export declare const FormEditor: React.FC<FormEditorProps>;
|