@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.
Files changed (88) hide show
  1. package/README.md +187 -0
  2. package/dist/Form.d.ts +2 -2
  3. package/dist/Form.js +15 -26
  4. package/dist/Form.stories.d.ts +12 -11
  5. package/dist/Form.stories.js +134 -101
  6. package/dist/Form.test.js +3 -3
  7. package/dist/FormEditor.d.ts +3 -3
  8. package/dist/FormEditor.js +14 -59
  9. package/dist/FormEditor.stories.d.ts +5 -4
  10. package/dist/FormEditor.stories.js +3 -16
  11. package/dist/fields/AnyField.d.ts +3 -3
  12. package/dist/fields/AnyField.js +12 -24
  13. package/dist/fields/ArrayField.d.ts +3 -3
  14. package/dist/fields/ArrayField.js +42 -64
  15. package/dist/fields/BooleanField.d.ts +3 -3
  16. package/dist/fields/BooleanField.js +7 -18
  17. package/dist/fields/DateField.d.ts +3 -3
  18. package/dist/fields/DateField.js +7 -18
  19. package/dist/fields/NullField.d.ts +3 -3
  20. package/dist/fields/NullField.js +5 -16
  21. package/dist/fields/NumberField.d.ts +3 -3
  22. package/dist/fields/NumberField.js +3 -14
  23. package/dist/fields/ObjectField.d.ts +3 -3
  24. package/dist/fields/ObjectField.js +43 -46
  25. package/dist/fields/RadioField.d.ts +3 -0
  26. package/dist/fields/RadioField.js +11 -0
  27. package/dist/fields/SchemaField.d.ts +3 -3
  28. package/dist/fields/SchemaField.js +13 -23
  29. package/dist/fields/SearchMultiTagSelectField.d.ts +3 -0
  30. package/dist/fields/SearchMultiTagSelectField.js +14 -0
  31. package/dist/fields/StringField.d.ts +3 -3
  32. package/dist/fields/StringField.js +13 -51
  33. package/dist/fields/ToggleField.d.ts +3 -0
  34. package/dist/fields/ToggleField.js +11 -0
  35. package/dist/fields/index.d.ts +3 -0
  36. package/dist/fields/index.js +3 -0
  37. package/dist/fields/types.js +1 -1
  38. package/dist/formEditorSchemas.d.ts +1 -1
  39. package/dist/formEditorSchemas.js +3 -3
  40. package/dist/hooks/index.d.ts +2 -0
  41. package/dist/hooks/index.js +2 -0
  42. package/dist/hooks/useExtractUiSchema.d.ts +8 -0
  43. package/dist/hooks/useExtractUiSchema.js +22 -0
  44. package/dist/hooks/useSetDefault.d.ts +2 -0
  45. package/dist/hooks/useSetDefault.js +16 -0
  46. package/dist/sampleData/completeSchema.d.ts +3 -0
  47. package/dist/{_sampleData.js → sampleData/completeSchema.js} +28 -97
  48. package/dist/sampleData/conditionsSchema.d.ts +3 -0
  49. package/dist/sampleData/conditionsSchema.js +80 -0
  50. package/dist/sampleData/generatedSchema.d.ts +2 -0
  51. package/dist/sampleData/generatedSchema.js +19 -0
  52. package/dist/sampleData/index.d.ts +5 -0
  53. package/dist/sampleData/index.js +5 -0
  54. package/dist/sampleData/requiredInputSchema.d.ts +3 -0
  55. package/dist/sampleData/requiredInputSchema.js +72 -0
  56. package/dist/sampleData/simpleData.d.ts +7 -0
  57. package/dist/sampleData/simpleData.js +16 -0
  58. package/dist/styledComponents.d.ts +193 -47
  59. package/dist/styledComponents.js +342 -138
  60. package/dist/templates/ArrayFieldTemplate.d.ts +3 -3
  61. package/dist/templates/ArrayFieldTemplate.js +11 -23
  62. package/dist/templates/FieldTemplate.d.ts +3 -3
  63. package/dist/templates/FieldTemplate.js +11 -23
  64. package/dist/templates/ObjectFieldTemplate.d.ts +3 -3
  65. package/dist/templates/ObjectFieldTemplate.js +13 -23
  66. package/dist/types.d.ts +34 -3
  67. package/dist/utils/__tests/getEnums.test.d.ts +1 -0
  68. package/dist/utils/__tests/getEnums.test.js +64 -0
  69. package/dist/utils/__tests/resolveSchema.test.d.ts +1 -0
  70. package/dist/utils/__tests/resolveSchema.test.js +106 -0
  71. package/dist/utils/deepEqual.d.ts +1 -0
  72. package/dist/utils/deepEqual.js +18 -0
  73. package/dist/utils/getEnums.d.ts +10 -0
  74. package/dist/utils/getEnums.js +30 -0
  75. package/dist/utils/getTitleAndDescription.d.ts +12 -0
  76. package/dist/utils/getTitleAndDescription.js +15 -0
  77. package/dist/utils/getTypes.d.ts +5 -0
  78. package/dist/utils/getTypes.js +53 -0
  79. package/dist/utils/index.d.ts +7 -0
  80. package/dist/utils/index.js +14 -0
  81. package/dist/utils/mergeSchemas.d.ts +1 -0
  82. package/dist/utils/mergeSchemas.js +26 -0
  83. package/dist/utils/resolveSchema.d.ts +2 -0
  84. package/dist/utils/resolveSchema.js +68 -0
  85. package/package.json +32 -37
  86. package/dist/_sampleData.d.ts +0 -11
  87. package/dist/utils.d.ts +0 -25
  88. 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 function Form<T>(props: FormProps<T>): JSX.Element;
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 var FormRegistry = React.createContext({
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 function Form(props) {
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
- 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" })) }))] })) })));
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
+ };
@@ -1,12 +1,13 @@
1
- /// <reference types="react" />
2
- import { ComponentStory, ComponentMeta } from "@storybook/react";
1
+ import type { StoryObj, Meta } from "@storybook/react";
3
2
  import { Form } from "./";
4
- declare const _default: ComponentMeta<typeof Form>;
5
- export default _default;
6
- export declare const Simple: ComponentStory<typeof Form>;
7
- export declare const WithUiSchema: ComponentStory<typeof Form>;
8
- export declare const CompleteSchema: ComponentStory<typeof Form>;
9
- export declare const StrictlyTyped: () => JSX.Element;
10
- export declare const StylesCustomized: () => JSX.Element;
11
- export declare const WithGeneratedSchema: ComponentStory<typeof Form>;
12
- export declare const WithRequiredInput: ComponentStory<typeof Form>;
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;
@@ -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 __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
- }
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 "./_sampleData";
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
- export default {
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
- 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({});
77
- Simple.args = {
78
- schema: simpleSchema,
45
+ export default meta;
46
+ export const Simple = {
47
+ args: {
48
+ schema: simpleSchema,
49
+ },
79
50
  };
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({});
82
- WithUiSchema.args = {
83
- schema: simpleSchema,
84
- uiSchema: simpleUiSchema,
85
- components: { InfoFieldButton: InfoFieldButtonNew },
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
- export var CompleteSchema = Template.bind({});
88
- CompleteSchema.args = {
89
- schema: completeSchema,
90
- uiSchema: completeUiSchema,
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 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 }) })));
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
- 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];
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
- 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: {
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 var WithGeneratedSchema = Template.bind({});
142
- WithGeneratedSchema.args = {
143
- schema: generatedSchema,
144
- uiSchema: {},
145
- useItemsAsAdditionalItems: true,
138
+ export const WithGeneratedSchema = {
139
+ args: {
140
+ schema: generatedSchema,
141
+ uiSchema: {},
142
+ useItemsAsAdditionalItems: true,
143
+ },
146
144
  };
147
- export var WithRequiredInput = Template.bind({});
148
- WithRequiredInput.args = {
149
- schema: requiredInputSchema,
150
- uiSchema: {},
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 "./_sampleData";
5
- test("renders title", function () {
4
+ import { simpleSchema } from "./sampleData";
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,8 +1,8 @@
1
- /// <reference types="react" />
2
- import { Schema, UiSchema } from "./types";
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 function FormEditor(props: FormEditorProps): JSX.Element;
8
+ export declare const FormEditor: React.FC<FormEditorProps>;