@tsed/react-formio 1.13.2 → 1.13.5

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 (135) hide show
  1. package/.eslintignore +13 -0
  2. package/.eslintrc.js +7 -0
  3. package/coverage.json +6 -0
  4. package/dist/components/form/form.stories.d.ts +25 -0
  5. package/dist/components/form/useForm.hook.d.ts +7 -3
  6. package/dist/components/form-control/formControl.component.d.ts +2 -2
  7. package/dist/components/form-control/formControl.component.spec.d.ts +1 -0
  8. package/dist/components/form-control/formControl.stories.d.ts +57 -0
  9. package/dist/components/index.d.ts +4 -2
  10. package/dist/components/table/components/defaultCellHeader.component.d.ts +1 -1
  11. package/dist/components/table/index.d.ts +1 -1
  12. package/dist/index.d.ts +3 -3
  13. package/dist/index.js +7929 -7904
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.modern.js +7366 -7339
  16. package/dist/index.modern.js.map +1 -1
  17. package/dist/stores/actions/index.d.ts +1 -1
  18. package/dist/stores/auth/index.d.ts +4 -4
  19. package/dist/stores/index.d.ts +2 -2
  20. package/jest.config.js +6 -1
  21. package/package.json +7 -4
  22. package/src/components/actions-table/actionsTable.component.spec.tsx +11 -11
  23. package/src/components/actions-table/actionsTable.component.tsx +8 -9
  24. package/src/components/actions-table/actionsTable.stories.tsx +1 -0
  25. package/src/components/alert/alert.component.spec.tsx +21 -19
  26. package/src/components/alert/alert.stories.tsx +1 -0
  27. package/src/components/card/card.component.spec.tsx +5 -4
  28. package/src/components/card/card.stories.tsx +1 -0
  29. package/src/components/form/form.component.spec.tsx +7 -6
  30. package/src/components/form/form.component.tsx +2 -1
  31. package/src/components/form/form.stories.tsx +118 -76
  32. package/src/components/form/useForm.hook.ts +47 -22
  33. package/src/components/form-access/formAccess.component.tsx +2 -1
  34. package/src/components/form-access/formAccess.schema.ts +1 -0
  35. package/src/components/form-access/formAccess.stories.tsx +1 -0
  36. package/src/components/form-access/formAccess.utils.ts +9 -8
  37. package/src/components/form-action/formAction.component.tsx +4 -3
  38. package/src/components/form-action/formAction.stories.tsx +225 -227
  39. package/src/components/form-builder/formBuilder.component.tsx +1 -0
  40. package/src/components/form-builder/formBuilder.stories.tsx +1 -0
  41. package/src/components/form-control/formControl.component.spec.tsx +76 -0
  42. package/src/components/form-control/formControl.component.tsx +15 -7
  43. package/src/components/form-control/formControl.stories.tsx +65 -0
  44. package/src/components/form-edit/formCtas.component.tsx +25 -26
  45. package/src/components/form-edit/formEdit.component.tsx +1 -0
  46. package/src/components/form-edit/formEdit.reducer.ts +1 -0
  47. package/src/components/form-edit/formEdit.stories.tsx +1 -0
  48. package/src/components/form-edit/formParameters.component.tsx +1 -0
  49. package/src/components/form-edit/useFormEdit.hook.ts +1 -0
  50. package/src/components/form-settings/formSettings.component.spec.tsx +7 -6
  51. package/src/components/form-settings/formSettings.component.tsx +12 -14
  52. package/src/components/form-settings/formSettings.stories.tsx +1 -0
  53. package/src/components/form-settings/formSettings.utils.ts +1 -0
  54. package/src/components/forms-table/components/formCell.component.tsx +1 -0
  55. package/src/components/forms-table/formsTable.component.tsx +23 -25
  56. package/src/components/forms-table/formsTable.stories.tsx +1 -0
  57. package/src/components/index.ts +4 -2
  58. package/src/components/input-tags/inputTags.component.tsx +5 -4
  59. package/src/components/input-tags/inputTags.stories.tsx +1 -0
  60. package/src/components/input-text/inputText.component.spec.tsx +12 -11
  61. package/src/components/input-text/inputText.component.tsx +1 -0
  62. package/src/components/input-text/inputText.stories.tsx +1 -0
  63. package/src/components/loader/loader.component.spec.tsx +6 -5
  64. package/src/components/loader/loader.component.tsx +1 -0
  65. package/src/components/loader/loader.stories.tsx +1 -0
  66. package/src/components/modal/modal.component.spec.tsx +36 -33
  67. package/src/components/modal/modal.component.tsx +1 -1
  68. package/src/components/modal/modal.stories.tsx +1 -0
  69. package/src/components/modal/removeModal.component.tsx +1 -0
  70. package/src/components/pagination/pagination.component.spec.tsx +24 -21
  71. package/src/components/pagination/pagination.component.tsx +1 -0
  72. package/src/components/pagination/pagination.stories.tsx +1 -0
  73. package/src/components/react-component/reactComponent.component.tsx +3 -2
  74. package/src/components/select/select.component.spec.tsx +17 -18
  75. package/src/components/select/select.component.tsx +1 -0
  76. package/src/components/select/select.stories.tsx +1 -0
  77. package/src/components/submissions-table/submissionsTable.component.tsx +6 -5
  78. package/src/components/submissions-table/submissionsTable.stories.tsx +1 -0
  79. package/src/components/table/components/defaultArrowSort.component.tsx +1 -0
  80. package/src/components/table/components/defaultCellHeader.component.tsx +1 -1
  81. package/src/components/table/components/defaultCellOperations.component.tsx +1 -0
  82. package/src/components/table/components/defaultOperationButton.component.tsx +1 -0
  83. package/src/components/table/filters/defaultColumnFilter.component.spec.tsx +5 -3
  84. package/src/components/table/filters/defaultColumnFilter.component.tsx +1 -0
  85. package/src/components/table/filters/selectColumnFilter.component.spec.tsx +9 -7
  86. package/src/components/table/filters/selectColumnFilter.component.tsx +1 -0
  87. package/src/components/table/index.ts +1 -1
  88. package/src/components/table/table.component.tsx +45 -58
  89. package/src/components/table/table.stories.tsx +2 -1
  90. package/src/components/table/utils/mapFormToColumns.tsx +2 -1
  91. package/src/components/table/utils/useOperations.hook.tsx +1 -0
  92. package/src/components/tabs/tabs.component.spec.tsx +6 -5
  93. package/src/components/tabs/tabs.component.stories.tsx +1 -0
  94. package/src/components/tabs/tabs.component.tsx +10 -4
  95. package/src/index.ts +3 -5
  96. package/src/interfaces/Operation.ts +1 -0
  97. package/src/stores/action/action.actions.spec.ts +1 -0
  98. package/src/stores/action/action.actions.ts +1 -0
  99. package/src/stores/action/action.reducers.ts +1 -1
  100. package/src/stores/action-info/action-info.actions.spec.ts +1 -0
  101. package/src/stores/action-info/action-info.actions.ts +2 -1
  102. package/src/stores/action-info/action-info.reducers.ts +2 -1
  103. package/src/stores/action-info/action-info.selectors.ts +2 -1
  104. package/src/stores/actions/actions.actions.spec.ts +1 -0
  105. package/src/stores/actions/actions.actions.ts +1 -0
  106. package/src/stores/actions/actions.reducers.ts +1 -0
  107. package/src/stores/actions/index.ts +1 -1
  108. package/src/stores/auth/auth.actions.ts +1 -0
  109. package/src/stores/auth/auth.reducers.ts +1 -0
  110. package/src/stores/auth/auth.selectors.ts +1 -0
  111. package/src/stores/auth/auth.utils.tsx +2 -1
  112. package/src/stores/auth/getAccess.action.spec.ts +1 -0
  113. package/src/stores/auth/getAccess.action.ts +1 -0
  114. package/src/stores/auth/getProjectAccess.action.ts +1 -0
  115. package/src/stores/auth/index.ts +4 -4
  116. package/src/stores/auth/initAuth.action.spec.ts +1 -0
  117. package/src/stores/auth/initAuth.action.ts +1 -0
  118. package/src/stores/auth/logout.action.spec.ts +2 -1
  119. package/src/stores/auth/logout.action.ts +1 -0
  120. package/src/stores/auth/setUser.action.spec.ts +1 -0
  121. package/src/stores/auth/setUser.action.ts +1 -0
  122. package/src/stores/form/form.actions.spec.ts +1 -0
  123. package/src/stores/form/form.actions.ts +1 -0
  124. package/src/stores/form/form.reducers.ts +1 -0
  125. package/src/stores/forms/forms.actions.spec.ts +1 -0
  126. package/src/stores/forms/forms.actions.ts +1 -0
  127. package/src/stores/forms/forms.reducers.ts +1 -0
  128. package/src/stores/index.ts +3 -2
  129. package/src/stores/root/root.selectors.ts +1 -1
  130. package/src/stores/submission/submission.actions.spec.ts +1 -0
  131. package/src/stores/submission/submission.actions.ts +1 -0
  132. package/src/stores/submission/submission.reducers.ts +1 -0
  133. package/src/stores/submissions/submissions.actions.spec.ts +1 -0
  134. package/src/stores/submissions/submissions.actions.ts +1 -0
  135. package/src/stores/submissions/submissions.reducers.ts +1 -0
@@ -1,4 +1,4 @@
1
- export * from "./actions.constant";
2
1
  export * from "./actions.actions";
2
+ export * from "./actions.constant";
3
3
  export * from "./actions.reducers";
4
4
  export * from "./actions.selectors";
@@ -1,10 +1,10 @@
1
- export * from "./auth.constant";
2
- export * from "./auth.utils";
3
1
  export * from "./auth.actions";
2
+ export * from "./auth.constant";
4
3
  export * from "./auth.reducers";
5
4
  export * from "./auth.selectors";
6
- export * from "./getProjectAccess.action";
5
+ export * from "./auth.utils";
7
6
  export * from "./getAccess.action";
7
+ export * from "./getProjectAccess.action";
8
+ export * from "./initAuth.action";
8
9
  export * from "./logout.action";
9
10
  export * from "./setUser.action";
10
- export * from "./initAuth.action";
@@ -1,10 +1,10 @@
1
- export * from "./auth";
2
1
  export * from "./action";
3
2
  export * from "./action-info";
4
3
  export * from "./actions";
4
+ export * from "./auth";
5
5
  export * from "./form";
6
6
  export * from "./forms";
7
+ export * from "./root";
7
8
  export * from "./submission";
8
9
  export * from "./submissions";
9
- export * from "./root";
10
10
  export declare const defaultFormioReducer: Record<string, import("@tsed/redux-utils").ReduceFunction<any, any>>;
package/jest.config.js CHANGED
@@ -1 +1,6 @@
1
- module.exports = require("@tsed/config/jest/jest.web.config.js");
1
+ module.exports = {
2
+ ...require("@tsed/config/jest/jest.web.config.js"),
3
+ coverageThreshold: {
4
+ global: require("./coverage.json")
5
+ }
6
+ };
package/package.json CHANGED
@@ -1,17 +1,20 @@
1
1
  {
2
2
  "name": "@tsed/react-formio",
3
- "version": "1.13.2",
3
+ "version": "1.13.5",
4
4
  "description": "Provide a react formio wrapper. Written in TypeScript.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.modern.js",
7
7
  "source": "src/index.ts",
8
8
  "scripts": {
9
+ "lint": "eslint \"**/*.{js,jsx,ts,tsx}\"",
10
+ "lint:fix": "yarn lint --fix",
9
11
  "test": "cross-env NODE_ENV=test jest --coverage",
12
+ "test:coverage:update": "write-coverage",
10
13
  "build": "microbundle --no-compress --format modern,cjs --jsx React.createElement",
11
14
  "watch": "microbundle watch --no-compress --format modern,cjs --jsx React.createElement"
12
15
  },
13
16
  "dependencies": {
14
- "@tsed/redux-utils": "1.13.2",
17
+ "@tsed/redux-utils": "1.13.5",
15
18
  "eventemitter2": "^6.4.3",
16
19
  "prop-types": "^15.7.2"
17
20
  },
@@ -26,8 +29,8 @@
26
29
  "tooltip.js": ">=1.3.3"
27
30
  },
28
31
  "devDependencies": {
29
- "@tsed/tailwind": "1.13.2",
30
- "@tsed/tailwind-formio": "1.13.2"
32
+ "@tsed/tailwind": "1.13.5",
33
+ "@tsed/tailwind-formio": "1.13.5"
31
34
  },
32
35
  "repository": "https://github.com/TypedProject/tsed-formio",
33
36
  "bugs": {
@@ -1,6 +1,6 @@
1
- import React from "react";
2
- import { fireEvent, render } from "@testing-library/react";
1
+ import { fireEvent, render, screen } from "@testing-library/react";
3
2
  import userEvent from "@testing-library/user-event";
3
+ import React from "react";
4
4
 
5
5
  import { Sandbox } from "./actionsTable.stories";
6
6
 
@@ -8,11 +8,11 @@ describe("ActionsTable", () => {
8
8
  it("should render the table actions", async () => {
9
9
  const onAddAction = jest.fn();
10
10
 
11
- const { getByRole, getAllByRole } = render(<Sandbox {...Sandbox.args} onAddAction={onAddAction} />);
11
+ render(<Sandbox {...Sandbox.args} onAddAction={onAddAction} />);
12
12
 
13
- const btn = getByRole("button", { name: /add action/i });
14
- const cells = getAllByRole("cell");
15
- const options = getAllByRole("option");
13
+ const btn = screen.getByRole("button", { name: /add action/i });
14
+ const cells = screen.getAllByRole("cell");
15
+ const options = screen.getAllByRole("option");
16
16
 
17
17
  expect(btn).toHaveProperty("disabled");
18
18
  expect(btn.innerHTML).toMatch("Add action");
@@ -25,9 +25,9 @@ describe("ActionsTable", () => {
25
25
  it("should not call addAction when the default item is selected", async () => {
26
26
  const onAddAction = jest.fn();
27
27
 
28
- const { getByRole } = render(<Sandbox {...Sandbox.args} onAddAction={onAddAction} />);
28
+ render(<Sandbox {...Sandbox.args} onAddAction={onAddAction} />);
29
29
 
30
- const btn = getByRole("button", { name: /add action/i });
30
+ const btn = screen.getByRole("button", { name: /add action/i });
31
31
 
32
32
  await fireEvent.click(btn);
33
33
  expect(onAddAction).not.toHaveBeenCalled();
@@ -35,10 +35,10 @@ describe("ActionsTable", () => {
35
35
  it("should call addAction with the selected action", async () => {
36
36
  const onAddAction = jest.fn();
37
37
 
38
- const { getByRole } = render(<Sandbox {...Sandbox.args} onAddAction={onAddAction} />);
38
+ render(<Sandbox {...Sandbox.args} onAddAction={onAddAction} />);
39
39
 
40
- const btn = getByRole("button", { name: /add action/i });
41
- const select = getByRole("combobox");
40
+ const btn = screen.getByRole("button", { name: /add action/i });
41
+ const select = screen.getByRole("combobox");
42
42
 
43
43
  await userEvent.selectOptions(select, String(Sandbox.args.availableActions[1].value));
44
44
 
@@ -1,6 +1,7 @@
1
1
  import classnames from "classnames";
2
2
  import noop from "lodash/noop";
3
3
  import React, { useState } from "react";
4
+
4
5
  import { ActionSchema } from "../../interfaces";
5
6
  import { iconClass } from "../../utils/iconClass";
6
7
  import { Select } from "../select/select.component";
@@ -21,15 +22,13 @@ export function ActionsTable({
21
22
  const { i18n = (f: string) => f } = props;
22
23
  const [currentAction, setAction] = useState("");
23
24
 
24
- const columns = React.useMemo(() => {
25
- return [
26
- {
27
- Header: i18n("Actions"),
28
- accessor: "title",
29
- id: "title"
30
- }
31
- ];
32
- }, []);
25
+ const columns = [
26
+ {
27
+ Header: i18n("Actions"),
28
+ accessor: "title",
29
+ id: "title"
30
+ }
31
+ ];
33
32
 
34
33
  return (
35
34
  <Table {...props} disableFilters={disableFilters} disablePagination={disablePagination} columns={columns}>
@@ -1,4 +1,5 @@
1
1
  import React from "react";
2
+
2
3
  import { ActionsTable } from "./actionsTable.component";
3
4
 
4
5
  export default {
@@ -1,5 +1,6 @@
1
+ import { render, screen } from "@testing-library/react";
1
2
  import React from "react";
2
- import { render } from "@testing-library/react";
3
+
3
4
  import { Sandbox } from "./alert.stories";
4
5
 
5
6
  describe("Alert component", () => {
@@ -11,9 +12,10 @@ describe("Alert component", () => {
11
12
 
12
13
  it("should display an error when the error is in string format", () => {
13
14
  const error = "error in string format";
14
- const { getByRole } = render(<Sandbox {...Sandbox.args} error={error} />);
15
15
 
16
- const alert = getByRole("alert") as HTMLDivElement;
16
+ render(<Sandbox {...Sandbox.args} error={error} />);
17
+
18
+ const alert = screen.getByRole("alert") as HTMLDivElement;
17
19
 
18
20
  expect(alert).toBeInTheDocument();
19
21
  expect(alert).toHaveClass("alert alert-danger");
@@ -23,13 +25,13 @@ describe("Alert component", () => {
23
25
  it("should display error(s) when the error is an array", () => {
24
26
  const arrayOfErrors = ["first error", "second error", "third error"];
25
27
  const joinedErrors = arrayOfErrors.map((error) => error).join("");
26
- const { getByRole, getByText } = render(<Sandbox {...Sandbox.args} error={arrayOfErrors} />);
28
+ render(<Sandbox {...Sandbox.args} error={arrayOfErrors} />);
27
29
 
28
- const alert = getByRole("alert") as HTMLDivElement;
30
+ const alert = screen.getByRole("alert") as HTMLDivElement;
29
31
 
30
32
  expect(alert).toBeInTheDocument();
31
33
  expect(alert).toHaveClass("alert alert-danger");
32
- expect(getByText(joinedErrors)).toBeInTheDocument();
34
+ expect(screen.getByText(joinedErrors)).toBeInTheDocument();
33
35
  });
34
36
 
35
37
  it("should display error's names paths and messages when the error is an object that has an 'errors' property that contains an array of error objects", () => {
@@ -40,9 +42,9 @@ describe("Alert component", () => {
40
42
  { name: "third error", path: "/path", message: "message" }
41
43
  ]
42
44
  };
43
- const { getByRole } = render(<Sandbox {...Sandbox.args} error={arrayOfErrors} />);
45
+ render(<Sandbox {...Sandbox.args} error={arrayOfErrors} />);
44
46
 
45
- const alert = getByRole("alert") as HTMLDivElement;
47
+ const alert = screen.getByRole("alert") as HTMLDivElement;
46
48
 
47
49
  expect(alert).toBeInTheDocument();
48
50
  expect(alert).toHaveClass("alert alert-danger");
@@ -51,33 +53,33 @@ describe("Alert component", () => {
51
53
 
52
54
  it("should display an error message when the error is a standard error", () => {
53
55
  const standardError = { message: "first error" };
54
- const { getByRole, getByText } = render(<Sandbox {...Sandbox.args} error={standardError} />);
56
+ render(<Sandbox {...Sandbox.args} error={standardError} />);
55
57
 
56
- const alert = getByRole("alert") as HTMLDivElement;
58
+ const alert = screen.getByRole("alert") as HTMLDivElement;
57
59
 
58
60
  expect(alert).toBeInTheDocument();
59
61
  expect(alert).toHaveClass("alert alert-danger");
60
- expect(getByText(standardError.message)).toBeInTheDocument();
62
+ expect(screen.getByText(standardError.message)).toBeInTheDocument();
61
63
  });
62
64
 
63
65
  it("should display error(s) message(s) when the error is a joi validation error", () => {
64
66
  const joiValidationError = { name: "ValidationError", details: [{ message: "message 1" }, { message: "message 2" }] };
65
- const { getByRole, getByText } = render(<Sandbox {...Sandbox.args} error={joiValidationError} />);
67
+ render(<Sandbox {...Sandbox.args} error={joiValidationError} />);
66
68
 
67
- const alert = getByRole("alert") as HTMLDivElement;
69
+ const alert = screen.getByRole("alert") as HTMLDivElement;
68
70
 
69
71
  expect(alert).toBeInTheDocument();
70
72
  expect(alert).toHaveClass("alert alert-danger");
71
- expect(getByText("message 1")).toBeInTheDocument();
72
- expect(getByText("message 2")).toBeInTheDocument();
73
+ expect(screen.getByText("message 1")).toBeInTheDocument();
74
+ expect(screen.getByText("message 2")).toBeInTheDocument();
73
75
  });
74
76
 
75
77
  it("should display a custom error message that asks to reload the form when a conflict error occurs in a form", () => {
76
78
  const error = { _id: "some id", display: "some value" };
77
79
  const messageReturned = "Another user has saved this form already. Please reload and re-apply your changes.";
78
- const { getByRole } = render(<Sandbox {...Sandbox.args} error={error} />);
80
+ render(<Sandbox {...Sandbox.args} error={error} />);
79
81
 
80
- const alert = getByRole("alert") as HTMLDivElement;
82
+ const alert = screen.getByRole("alert") as HTMLDivElement;
81
83
 
82
84
  expect(alert).toBeInTheDocument();
83
85
  expect(alert).toHaveClass("alert alert-danger");
@@ -86,9 +88,9 @@ describe("Alert component", () => {
86
88
 
87
89
  it("should display an error message by default when the error format does not match any of the conditions of the formatError() handler", () => {
88
90
  const messageError: string = "An error occurred. See console logs for details.";
89
- const { getByRole } = render(<Sandbox {...Sandbox.args} error={true} />);
91
+ render(<Sandbox {...Sandbox.args} error={true} />);
90
92
 
91
- const alert = getByRole("alert") as HTMLDivElement;
93
+ const alert = screen.getByRole("alert") as HTMLDivElement;
92
94
 
93
95
  expect(alert).toBeInTheDocument();
94
96
  expect(alert).toHaveClass("alert alert-danger");
@@ -1,4 +1,5 @@
1
1
  import React from "react";
2
+
2
3
  import { Alert } from "./alert.component";
3
4
 
4
5
  export default {
@@ -1,13 +1,14 @@
1
- import { render } from "@testing-library/react";
1
+ import { render, screen } from "@testing-library/react";
2
2
  import React from "react";
3
+
3
4
  import { Sandbox } from "./card.stories";
4
5
 
5
6
  describe("Card", () => {
6
7
  it("should render the card component", () => {
7
- const { getByRole } = render(<Sandbox {...Sandbox.args} />);
8
+ render(<Sandbox {...Sandbox.args} />);
8
9
 
9
- const title = getByRole("heading");
10
- const body = getByRole("article");
10
+ const title = screen.getByRole("heading");
11
+ const body = screen.getByRole("article");
11
12
 
12
13
  expect(title).toHaveTextContent("label");
13
14
  expect(body).toHaveTextContent("test");
@@ -1,4 +1,5 @@
1
1
  import React from "react";
2
+
2
3
  import { Card } from "./card.component";
3
4
 
4
5
  export default {
@@ -1,6 +1,7 @@
1
- import {render} from "@testing-library/react";
2
- import {screen} from "@testing-library/dom";
3
- import {Form} from "./form.component";
1
+ import { screen } from "@testing-library/react";
2
+ import { render } from "@testing-library/react";
3
+
4
+ import { Form } from "./form.component";
4
5
 
5
6
  async function createFixture(props: any = {}) {
6
7
  const onSubmit = jest.fn();
@@ -11,7 +12,7 @@ async function createFixture(props: any = {}) {
11
12
  components: [
12
13
  {
13
14
  label: "First name",
14
- "placeholder": "Fill first name",
15
+ placeholder: "Fill first name",
15
16
  widget: {
16
17
  type: "input"
17
18
  },
@@ -33,9 +34,9 @@ async function createFixture(props: any = {}) {
33
34
  ]
34
35
  };
35
36
 
36
- render(<Form {...props} form={form} onSubmit={onSubmit}/>);
37
+ render(<Form {...props} form={form} onSubmit={onSubmit} />);
37
38
 
38
- return {onSubmit};
39
+ return { onSubmit };
39
40
  }
40
41
 
41
42
  describe("Form", () => {
@@ -1,7 +1,8 @@
1
- import AllComponents from "formiojs/components";
2
1
  import { Components } from "formiojs";
2
+ import AllComponents from "formiojs/components";
3
3
  import PropTypes from "prop-types";
4
4
  import React from "react";
5
+
5
6
  import { useForm, UseFormHookProps } from "./useForm.hook";
6
7
 
7
8
  Components.setComponents(AllComponents);
@@ -1,7 +1,8 @@
1
- import React from "react";
2
- import {Form} from "./form.component";
1
+ import React, { useState } from "react";
2
+
3
+ import { Submission } from "../../interfaces";
3
4
  import form from "../__fixtures__/form.fixture.json";
4
- import {Submission} from "../../interfaces";
5
+ import { Form } from "./form.component";
5
6
 
6
7
  export default {
7
8
  title: "ReactFormio/Form",
@@ -12,44 +13,43 @@ export default {
12
13
  type: "object"
13
14
  }
14
15
  },
15
- onPrevPage: {action: "onPrevPage"},
16
- onNextPage: {action: "onNextPage"},
17
- onCancel: {action: "onCancel"},
18
- onChange: {action: "onChange"},
19
- onCustomEvent: {action: "onCustomEvent"},
20
- onComponentChange: {action: "onComponentChange"},
21
- onSubmit: {action: "onSubmit"},
22
- onAsyncSubmit: {action: "onAsyncSubmit"},
23
- onSubmitDone: {action: "onSubmitDone"},
24
- onFormLoad: {action: "onFormLoad"},
25
- onError: {action: "onError"},
26
- onRender: {action: "onRender"},
27
- onAttach: {action: "onAttach"},
28
- onBuild: {action: "onBuild"},
29
- onFocus: {action: "onFocus"},
30
- onBlur: {action: "onBlur"},
31
- onInitialized: {action: "onInitialized"},
32
- onFormReady: {action: "onFormReady"}
16
+ onPrevPage: { action: "onPrevPage" },
17
+ onNextPage: { action: "onNextPage" },
18
+ onCancel: { action: "onCancel" },
19
+ onChange: { action: "onChange" },
20
+ onCustomEvent: { action: "onCustomEvent" },
21
+ onComponentChange: { action: "onComponentChange" },
22
+ onSubmit: { action: "onSubmit" },
23
+ onAsyncSubmit: { action: "onAsyncSubmit" },
24
+ onSubmitDone: { action: "onSubmitDone" },
25
+ onFormLoad: { action: "onFormLoad" },
26
+ onError: { action: "onError" },
27
+ onRender: { action: "onRender" },
28
+ onAttach: { action: "onAttach" },
29
+ onBuild: { action: "onBuild" },
30
+ onFocus: { action: "onFocus" },
31
+ onBlur: { action: "onBlur" },
32
+ onInitialized: { action: "onInitialized" },
33
+ onFormReady: { action: "onFormReady" }
33
34
  }
34
35
  };
35
36
 
36
37
  function filter(args: any[]) {
37
- return args
38
- .map((item) => {
39
- if (item && (item._form)) {
40
- return "FormioInstance";
41
- }
38
+ return args.map((item) => {
39
+ if (item && item._form) {
40
+ return "FormioInstance";
41
+ }
42
42
 
43
- if (item && item.component) {
44
- return ["Component", item.component.type, item.component.key].filter(Boolean).join(":");
45
- }
43
+ if (item && item.component) {
44
+ return ["Component", item.component.type, item.component.key].filter(Boolean).join(":");
45
+ }
46
46
 
47
- if (item && item.changed) {
48
- return `${item.changed.component.key}(${item.changed.value})`;
49
- }
47
+ if (item && item.changed) {
48
+ return `${item.changed.component.key}(${item.changed.value})`;
49
+ }
50
50
 
51
- return item;
52
- });
51
+ return item;
52
+ });
53
53
  }
54
54
 
55
55
  function wrap(args: any) {
@@ -113,13 +113,7 @@ function wrap(args: any) {
113
113
  }
114
114
 
115
115
  export const Sandbox = (args: any) => {
116
- return (
117
- <Form
118
- {...wrap(args)}
119
- form={args.form}
120
- options={{template: "tailwind", iconset: "bx"}}
121
- />
122
- );
116
+ return <Form {...wrap(args)} form={args.form} options={{ template: "tailwind", iconset: "bx" }} />;
123
117
  };
124
118
 
125
119
  Sandbox.args = {
@@ -134,66 +128,57 @@ export const TriggerError = (args: any) => {
134
128
  }, 500);
135
129
  }).catch((error) => {
136
130
  error.errors = {
137
- "message": "My custom message about this field",
138
- "type": "custom",
139
- "path": ["firstName"],
140
- "level": "error"
131
+ message: "My custom message about this field",
132
+ type: "custom",
133
+ path: ["firstName"],
134
+ level: "error"
141
135
  };
142
136
  throw error;
143
137
  });
144
138
  };
145
139
 
146
- return (
147
- <Form<any>
148
- {...wrap(args)}
149
- form={args.form}
150
- onAsyncSubmit={onAsyncSubmit}
151
- />
152
- );
140
+ return <Form<any> {...wrap(args)} form={args.form} onAsyncSubmit={onAsyncSubmit} />;
153
141
  };
154
142
 
155
143
  TriggerError.args = {
156
144
  form: {
157
- "type": "form",
158
- "display": "form",
159
- "tags": [],
160
- "components": [
145
+ type: "form",
146
+ display: "form",
147
+ tags: [],
148
+ components: [
161
149
  {
162
- "label": "First name",
163
- "widget": {
164
- "type": "input"
150
+ label: "First name",
151
+ widget: {
152
+ type: "input"
165
153
  },
166
- "errorLabel": "",
167
- "key": "firstName",
168
- "inputType": "text",
169
- "type": "textfield",
170
- "id": "eqb1o4r",
171
- "defaultValue": ""
154
+ errorLabel: "",
155
+ key: "firstName",
156
+ inputType: "text",
157
+ type: "textfield",
158
+ id: "eqb1o4r",
159
+ defaultValue: ""
172
160
  },
173
161
  {
174
- "label": "Submit",
175
- "showValidations": false,
176
- "tableView": false,
177
- "key": "submit",
178
- "type": "button",
179
- "input": true
162
+ label: "Submit",
163
+ showValidations: false,
164
+ tableView: false,
165
+ key: "submit",
166
+ type: "button",
167
+ input: true
180
168
  }
181
169
  ]
182
170
  }
183
171
  };
184
172
 
185
-
186
173
  export const ReadOnly = (args: any) => {
187
174
  return (
188
175
  <Form
189
176
  {...wrap(args)}
190
- options={{template: "tailwind", iconset: "bx", readOnly: args.readOnly}}
177
+ options={{ template: "tailwind", iconset: "bx", readOnly: args.readOnly }}
191
178
  form={args.form}
192
179
  submission={{
193
180
  data: {
194
- editGrid: [
195
- {currency: "EUR"}
196
- ]
181
+ editGrid: [{ currency: "EUR" }]
197
182
  }
198
183
  }}
199
184
  />
@@ -204,3 +189,60 @@ ReadOnly.args = {
204
189
  readonly: true,
205
190
  form
206
191
  };
192
+
193
+ export const OnChange = (args: any) => {
194
+ const [data, setForm] = useState<any>(() => {});
195
+ const props = wrap(args);
196
+
197
+ return (
198
+ <Form
199
+ {...props}
200
+ options={{ template: "tailwind", iconset: "bx", readOnly: args.readOnly }}
201
+ form={args.form}
202
+ submission={{ data }}
203
+ onChange={(changedSubmission) => {
204
+ setForm(changedSubmission.data);
205
+ }}
206
+ />
207
+ );
208
+ };
209
+
210
+ OnChange.args = {
211
+ form: {
212
+ type: "form",
213
+ display: "form",
214
+ tags: [],
215
+ components: [
216
+ {
217
+ label: "First name",
218
+ widget: {
219
+ type: "input"
220
+ },
221
+ errorLabel: "",
222
+ key: "firstName",
223
+ inputType: "text",
224
+ type: "textfield",
225
+ id: "eqb1o4r",
226
+ defaultValue: "",
227
+ validate: {
228
+ required: true
229
+ }
230
+ },
231
+ {
232
+ label: "Last name",
233
+ widget: {
234
+ type: "input"
235
+ },
236
+ errorLabel: "",
237
+ key: "lastName",
238
+ inputType: "text",
239
+ type: "textfield",
240
+ id: "eqb1o4r",
241
+ defaultValue: "",
242
+ validate: {
243
+ required: true
244
+ }
245
+ }
246
+ ]
247
+ }
248
+ };