@tsed/react-formio 3.0.0-alpha.12 → 3.0.0-alpha.13

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 (131) hide show
  1. package/dist/all.d.ts +0 -0
  2. package/dist/all.js +38 -0
  3. package/dist/all.js.map +1 -0
  4. package/dist/chunks/_commonjsHelpers.js +30 -3
  5. package/dist/chunks/_commonjsHelpers.js.map +1 -1
  6. package/dist/chunks/index2.js +56953 -0
  7. package/dist/chunks/index2.js.map +1 -0
  8. package/dist/contexts/FormioContext.d.ts +20 -0
  9. package/dist/contexts/FormioContext.js +40 -0
  10. package/dist/contexts/FormioContext.js.map +1 -0
  11. package/dist/hooks/useFormioContext.d.ts +10 -0
  12. package/dist/hooks/useFormioContext.js +12 -0
  13. package/dist/hooks/useFormioContext.js.map +1 -0
  14. package/dist/hooks/useI18n.d.ts +4 -0
  15. package/dist/hooks/useI18n.js +9 -0
  16. package/dist/hooks/useI18n.js.map +1 -0
  17. package/dist/index.d.ts +1 -6
  18. package/dist/index.js +18 -13
  19. package/dist/index.js.map +1 -1
  20. package/dist/interfaces/ComponentType.d.ts +6 -2
  21. package/dist/interfaces/FormBuilderOptions.d.ts +7 -0
  22. package/dist/interfaces/FormBuilderOptions.js +2 -0
  23. package/dist/interfaces/FormBuilderOptions.js.map +1 -0
  24. package/dist/interfaces/FormOptions.d.ts +6 -13
  25. package/dist/interfaces/FormType.d.ts +4 -11
  26. package/dist/interfaces/SubmissionType.d.ts +5 -10
  27. package/dist/interfaces/index.d.ts +1 -0
  28. package/dist/molecules/forms/input-tags/components/ChoicesTags.d.ts +19 -19
  29. package/dist/molecules/forms/input-tags/components/ChoicesTags.js +16 -16
  30. package/dist/molecules/forms/input-tags/components/ChoicesTags.js.map +1 -1
  31. package/dist/molecules/forms/select/components/ChoicesSelect.js.map +1 -1
  32. package/dist/molecules/modal/Modal.js +6 -6
  33. package/dist/molecules/modal/Modal.js.map +1 -1
  34. package/dist/molecules/pagination/Pagination.d.ts +2 -1
  35. package/dist/molecules/pagination/Pagination.js +24 -24
  36. package/dist/molecules/pagination/Pagination.js.map +1 -1
  37. package/dist/molecules/table/Table.js +27 -27
  38. package/dist/molecules/table/Table.js.map +1 -1
  39. package/dist/molecules/table/hooks/useTable.d.ts +3 -3
  40. package/dist/molecules/table/hooks/useTable.js +13 -12
  41. package/dist/molecules/table/hooks/useTable.js.map +1 -1
  42. package/dist/molecules/table/utils/mapFormToColumns.js +22 -22
  43. package/dist/molecules/table/utils/mapFormToColumns.js.map +1 -1
  44. package/dist/molecules/tabs/TabsLegacy.d.ts +3 -2
  45. package/dist/molecules/tabs/TabsLegacy.js +30 -30
  46. package/dist/molecules/tabs/TabsLegacy.js.map +1 -1
  47. package/dist/organisms/form/access/FormAccess.schema.js +1 -0
  48. package/dist/organisms/form/access/FormAccess.schema.js.map +1 -1
  49. package/dist/organisms/form/actions/FormAction.js +14 -11
  50. package/dist/organisms/form/actions/FormAction.js.map +1 -1
  51. package/dist/organisms/form/builder/FormEdit.d.ts +4 -3
  52. package/dist/organisms/form/builder/FormEdit.js +36 -36
  53. package/dist/organisms/form/builder/FormEdit.js.map +1 -1
  54. package/dist/organisms/form/builder/FormEditCtas.d.ts +2 -2
  55. package/dist/organisms/form/builder/FormEditCtas.js +14 -13
  56. package/dist/organisms/form/builder/FormEditCtas.js.map +1 -1
  57. package/dist/organisms/form/builder/useFormBuilder.d.ts +4 -4
  58. package/dist/organisms/form/builder/useFormBuilder.js +12 -12
  59. package/dist/organisms/form/builder/useFormBuilder.js.map +1 -1
  60. package/dist/organisms/form/builder/useFormEdit.d.ts +1 -1
  61. package/dist/organisms/form/exports/FormExport.d.ts +3 -2
  62. package/dist/organisms/form/exports/FormExport.js +21 -20
  63. package/dist/organisms/form/exports/FormExport.js.map +1 -1
  64. package/dist/organisms/form/preview/FormPreview.d.ts +3 -3
  65. package/dist/organisms/form/preview/FormPreview.js +5 -4
  66. package/dist/organisms/form/preview/FormPreview.js.map +1 -1
  67. package/dist/organisms/form/settings/FormSettings.js +21 -21
  68. package/dist/organisms/form/settings/FormSettings.js.map +1 -1
  69. package/dist/organisms/form/useForm.d.ts +2 -1
  70. package/dist/organisms/form/useForm.js +2 -2
  71. package/dist/organisms/form/useForm.js.map +1 -1
  72. package/dist/organisms/table/actions/ActionsTable.d.ts +2 -1
  73. package/dist/organisms/table/actions/ActionsTable.js +10 -9
  74. package/dist/organisms/table/actions/ActionsTable.js.map +1 -1
  75. package/dist/organisms/table/forms/FormsTable.d.ts +1 -1
  76. package/dist/organisms/table/forms/FormsTable.js +9 -8
  77. package/dist/organisms/table/forms/FormsTable.js.map +1 -1
  78. package/dist/organisms/table/forms/components/FormsCell.js +10 -10
  79. package/dist/organisms/views/FormViews.d.ts +3 -3
  80. package/dist/organisms/views/FormViews.js +47 -46
  81. package/dist/organisms/views/FormViews.js.map +1 -1
  82. package/dist/utils/iconClass.js +4 -5
  83. package/dist/utils/iconClass.js.map +1 -1
  84. package/package.json +3 -3
  85. package/src/all.ts +34 -0
  86. package/src/contexts/FormioContext.tsx +96 -0
  87. package/src/hooks/useFormioContext.ts +13 -0
  88. package/src/hooks/useI18n.ts +9 -0
  89. package/src/index.ts +17 -13
  90. package/src/interfaces/ComponentType.ts +2 -2
  91. package/src/interfaces/FormBuilderOptions.ts +9 -0
  92. package/src/interfaces/FormOptions.ts +7 -13
  93. package/src/interfaces/FormType.ts +5 -11
  94. package/src/interfaces/SubmissionType.ts +9 -8
  95. package/src/interfaces/index.ts +1 -0
  96. package/src/molecules/forms/form-control/FormControl.spec.tsx +5 -2
  97. package/src/molecules/forms/input-tags/components/ChoicesTags.tsx +4 -4
  98. package/src/molecules/forms/select/components/ChoicesSelect.tsx +2 -2
  99. package/src/molecules/pagination/Pagination.tsx +10 -9
  100. package/src/molecules/table/Table.stories.tsx +6 -6
  101. package/src/molecules/table/Table.tsx +1 -1
  102. package/src/molecules/table/hooks/useTable.tsx +7 -6
  103. package/src/molecules/table/utils/mapFormToColumns.tsx +6 -5
  104. package/src/molecules/tabs/TabsLegacy.stories.tsx +1 -1
  105. package/src/molecules/tabs/TabsLegacy.tsx +5 -3
  106. package/src/organisms/form/Form.stories.tsx +4 -0
  107. package/src/organisms/form/access/FormAccess.schema.ts +1 -0
  108. package/src/organisms/form/access/FormAccess.stories.tsx +3 -1
  109. package/src/organisms/form/actions/FormAction.stories.tsx +5 -1
  110. package/src/organisms/form/actions/FormAction.tsx +2 -2
  111. package/src/organisms/form/builder/FormEdit.stories.tsx +10 -6
  112. package/src/organisms/form/builder/FormEdit.tsx +6 -6
  113. package/src/organisms/form/builder/FormEditCtas.tsx +10 -10
  114. package/src/organisms/form/builder/useFormBuilder.ts +7 -6
  115. package/src/organisms/form/exports/FormExport.stories.tsx +8 -11
  116. package/src/organisms/form/exports/FormExport.tsx +12 -9
  117. package/src/organisms/form/preview/FormPreview.stories.tsx +6 -9
  118. package/src/organisms/form/preview/FormPreview.tsx +7 -5
  119. package/src/organisms/form/settings/FormSettings.component.spec.tsx +3 -1
  120. package/src/organisms/form/settings/FormSettings.stories.tsx +1 -1
  121. package/src/organisms/form/settings/FormSettings.tsx +6 -6
  122. package/src/organisms/form/useForm.ts +2 -3
  123. package/src/organisms/table/actions/ActionsTable.tsx +7 -5
  124. package/src/organisms/table/forms/FormsTable.tsx +6 -5
  125. package/src/organisms/table/submissions/SubmissionsTable.stories.tsx +10 -13
  126. package/src/organisms/views/FormViews.stories.tsx +13 -16
  127. package/src/organisms/views/FormViews.tsx +18 -16
  128. package/src/utils/iconClass.ts +1 -3
  129. package/dist/typings.d.js +0 -2
  130. package/dist/typings.d.js.map +0 -1
  131. package/src/typings.d.ts +0 -3
@@ -1,14 +1,17 @@
1
1
  import { Icon } from "../../../atoms/icon/Icon.js";
2
+ import { useI18n } from "../../../hooks/useI18n.js";
3
+ import { FormOptions } from "../../../interfaces/FormOptions.js";
2
4
  import type { Card } from "../../../molecules/card/Card.js";
3
5
  import { getComponent } from "../../../registries/components.js";
4
6
 
5
7
  export interface FormExportProps {
6
- i18n?: (key: string) => string;
8
+ i18n?: FormOptions["i18n"];
7
9
  onClick?: (action: "export:form" | "export:submissions", format: "json" | "csv") => void;
8
10
  }
9
11
 
10
- export function FormExport({ i18n = (f: string) => f, onClick }: FormExportProps) {
12
+ export function FormExport({ onClick, ...props }: FormExportProps) {
11
13
  const FCard = getComponent<typeof Card>("Card");
14
+ const { t } = useI18n(props?.i18n);
12
15
 
13
16
  return (
14
17
  <div>
@@ -18,15 +21,15 @@ export function FormExport({ i18n = (f: string) => f, onClick }: FormExportProps
18
21
  label={
19
22
  (
20
23
  <span className={"flex items-center"}>
21
- <Icon name={"detail"} className={"mr-1 text-secondary"} /> {i18n(`Export schema`)}
24
+ <Icon name={"detail"} className={"mr-1 text-secondary"} /> {t(`Export schema`)}
22
25
  </span>
23
26
  ) as any
24
27
  }
25
28
  >
26
- <p className={"mb-5"}>{i18n("Export the formIO schema:")}</p>
29
+ <p className={"mb-5"}>{t("Export the formIO schema:")}</p>
27
30
  <div className={"flex items-center justify-center"}>
28
31
  <button className={"btn btn-primary"} onClick={() => onClick?.("export:form", "json")}>
29
- <Icon name={"code"} className={"mr-1"} /> {i18n(`Json`)}
32
+ <Icon name={"code"} className={"mr-1"} /> {t(`Json`)}
30
33
  </button>
31
34
  </div>
32
35
  </FCard>
@@ -36,18 +39,18 @@ export function FormExport({ i18n = (f: string) => f, onClick }: FormExportProps
36
39
  label={
37
40
  (
38
41
  <span className={"flex items-center"}>
39
- <Icon name={"data"} className={"mr-1 text-secondary"} /> {i18n(`Export submissions`)}
42
+ <Icon name={"data"} className={"mr-1 text-secondary"} /> {t(`Export submissions`)}
40
43
  </span>
41
44
  ) as any
42
45
  }
43
46
  >
44
- <p className={"mb-5"}>{i18n("Export all submission as JSON or CSV:")}</p>
47
+ <p className={"mb-5"}>{t("Export all submission as JSON or CSV:")}</p>
45
48
  <div className={"flex items-center justify-center"}>
46
49
  <button className={"btn btn-primary mr-4"} onClick={() => onClick?.("export:submissions", "json")}>
47
- <Icon name={"code"} className={"mr-1"} /> {i18n(`Json`)}
50
+ <Icon name={"code"} className={"mr-1"} /> {t(`Json`)}
48
51
  </button>
49
52
  <button className={"btn btn-primary"} onClick={() => onClick?.("export:submissions", "csv")}>
50
- <Icon name={"spreadsheet"} className={"mr-1"} /> {i18n(`Csv`)}
53
+ <Icon name={"spreadsheet"} className={"mr-1"} /> {t(`Csv`)}
51
54
  </button>
52
55
  </div>
53
56
  </FCard>
@@ -38,7 +38,7 @@ type Story = StoryObj<typeof FormPreview>;
38
38
  export const Usage: Story = {
39
39
  args: {
40
40
  form: formFirstname as any,
41
- i18n: (key: string) => key
41
+ i18n: {}
42
42
  }
43
43
  };
44
44
 
@@ -48,14 +48,11 @@ export const Usage: Story = {
48
48
  export const Translated: Story = {
49
49
  args: {
50
50
  form: formFirstname as any,
51
- i18n: (key: string) => {
52
- const translations: Record<string, string> = {
53
- "Form with First Name": "Formulaire avec prénom",
54
- "First name": "Prénom",
55
- "Last name": "Nom de famille",
56
- Submit: "Soumettre"
57
- };
58
- return translations[key] || key;
51
+ i18n: {
52
+ "Form with First Name": "Formulaire avec prénom",
53
+ "First name": "Prénom",
54
+ "Last name": "Nom de famille",
55
+ Submit: "Soumettre"
59
56
  }
60
57
  }
61
58
  };
@@ -1,20 +1,22 @@
1
- import type { FormType } from "../../../interfaces/index.js";
1
+ import { useI18n } from "../../../hooks/useI18n.js";
2
+ import type { FormOptions, FormType } from "../../../interfaces/index.js";
2
3
  import type { Card } from "../../../molecules/card/Card.js";
3
4
  import { getComponent } from "../../../registries/components.js";
4
5
  import { Form } from "../Form.js";
5
6
 
6
7
  export interface FormPreviewProps {
7
8
  form: FormType;
8
- i18n?: (key: string) => string;
9
+ i18n?: FormOptions["i18n"];
9
10
  }
10
11
 
11
- export function FormPreview({ form, i18n = (f) => f }: FormPreviewProps) {
12
+ export function FormPreview({ form, ...props }: FormPreviewProps) {
13
+ const { t } = useI18n(props?.i18n);
12
14
  const FCard = getComponent<typeof Card>("Card");
13
15
 
14
16
  return (
15
17
  <div className='p-10 bg-gray-500'>
16
- <FCard label={i18n(form.title || "")} className={"shadow"}>
17
- <Form form={form} options={{ i18n }} />
18
+ <FCard label={t(form.title || "")} className={"shadow"}>
19
+ <Form form={form} options={{ i18n: props.i18n }} />
18
20
  </FCard>
19
21
  </div>
20
22
  );
@@ -51,7 +51,9 @@ describe("FormSettings", () => {
51
51
  <FormSettings
52
52
  {...Sandbox.args}
53
53
  options={{
54
- i18n: (f: string) => f + " i18N"
54
+ i18n: {
55
+ "Save settings": "Save settings i18N"
56
+ }
55
57
  }}
56
58
  />
57
59
  );
@@ -56,6 +56,6 @@ Sandbox.args = {
56
56
  name: "textField",
57
57
  path: "textfield",
58
58
  machineName: "tcspjwhsevrzpcd:textField"
59
- },
59
+ } as any,
60
60
  options: { template: "tailwind", iconset: "bx" }
61
61
  };
@@ -2,6 +2,7 @@ import isEqual from "lodash/isEqual";
2
2
  import noop from "lodash/noop";
3
3
  import { useEffect, useState } from "react";
4
4
 
5
+ import { useI18n } from "../../../hooks/useI18n.js";
5
6
  import type { ChangedSubmission, FormOptions, FormType } from "../../../interfaces";
6
7
  import { Form } from "../../form/Form";
7
8
  import { getFormSettingsSchema } from "./FormSettings.schema";
@@ -13,7 +14,7 @@ export interface FormSettingsProps {
13
14
  options?: FormOptions;
14
15
  }
15
16
 
16
- function useFormSettings({ form: formDefinition, onSubmit = noop, options }: FormSettingsProps) {
17
+ function useFormSettings({ form: formDefinition, onSubmit = noop }: FormSettingsProps) {
17
18
  const form = getFormSettingsSchema();
18
19
  const [isValid, setIsValid] = useState(true);
19
20
  const [submission, setSubmission] = useState(() => formSettingsToSubmission(formDefinition));
@@ -33,7 +34,6 @@ function useFormSettings({ form: formDefinition, onSubmit = noop, options }: For
33
34
  }, [formDefinition?._id]);
34
35
 
35
36
  return {
36
- options,
37
37
  form,
38
38
  type: formDefinition.type,
39
39
  submission,
@@ -47,16 +47,16 @@ function useFormSettings({ form: formDefinition, onSubmit = noop, options }: For
47
47
  }
48
48
 
49
49
  export function FormSettings(props: FormSettingsProps) {
50
- const { form, submission, options = {}, onChange, onSubmit, isValid } = useFormSettings(props);
50
+ const { form, submission, onChange, onSubmit, isValid } = useFormSettings(props);
51
51
 
52
- const i18n = options.i18n || ((f: string) => f);
52
+ const { t } = useI18n(props?.options?.i18n);
53
53
 
54
54
  return (
55
55
  <div>
56
- <Form<FormSettingsType> form={form} submission={submission} onChange={onChange} options={options} />
56
+ <Form<FormSettingsType> form={form} submission={submission} onChange={onChange} options={props.options} />
57
57
 
58
58
  <button data-testid='submit' disabled={!isValid} className={"mt-5 btn btn-primary"} onClick={onSubmit} type={"submit"}>
59
- {i18n("Save settings")}
59
+ {t("Save settings")}
60
60
  </button>
61
61
  </div>
62
62
  );
@@ -1,5 +1,5 @@
1
+ import { Form } from "@formio/js";
1
2
  import { EventEmitter2 } from "eventemitter2";
2
- import { Form } from "formiojs";
3
3
  import { type MutableRefObject, useEffect, useRef, useState } from "react";
4
4
 
5
5
  import type { ChangedSubmission, ComponentType, FormOptions, FormType, JSON, SubmissionType } from "../../interfaces";
@@ -13,9 +13,8 @@ export interface UseFormProps<Data extends { [key: string]: JSON } = { [key: str
13
13
  url?: string;
14
14
  form?: FormType;
15
15
  submission?: SubmissionType<Data>;
16
- // TODO: once events is typed correctly in @formio/js options, we can remove this override
17
16
  options?: FormOptions;
18
- FormClass?: any;
17
+ FormClass?: typeof Form;
19
18
  onFormReady?: (instance: Webform) => void;
20
19
  onPrevPage?: (page: number, submission: SubmissionType<Data>) => void;
21
20
  onNextPage?: (page: number, submission: SubmissionType<Data>) => void;
@@ -3,7 +3,8 @@ import classnames from "classnames";
3
3
  import noop from "lodash/noop";
4
4
  import { useState } from "react";
5
5
 
6
- import { ActionType } from "../../../interfaces";
6
+ import { useI18n } from "../../../hooks/useI18n.js";
7
+ import { ActionType, type FormOptions } from "../../../interfaces";
7
8
  import { Select } from "../../../molecules/forms/select/Select";
8
9
  import { Table, type TableProps } from "../../../molecules/table/Table";
9
10
  import { iconClass } from "../../../utils/iconClass";
@@ -11,15 +12,16 @@ import { iconClass } from "../../../utils/iconClass";
11
12
  export type ActionsTableProps = Omit<TableProps<ActionType>, "columns"> & {
12
13
  onAddAction?: (actionName: string) => void;
13
14
  availableActions?: { label: string; value: string }[];
15
+ i18n?: FormOptions["i18n"];
14
16
  };
15
17
 
16
18
  export function ActionsTable({ availableActions = [], onAddAction = noop, ...props }: ActionsTableProps) {
17
- const { i18n = (f: string) => f } = props;
19
+ const { t } = useI18n(props.i18n);
18
20
  const [currentAction, setAction] = useState("");
19
21
 
20
22
  const columns: ColumnDef<ActionType>[] = [
21
23
  {
22
- header: i18n("Action"),
24
+ header: t("Action"),
23
25
  accessorKey: "title"
24
26
  }
25
27
  ];
@@ -31,7 +33,7 @@ export function ActionsTable({ availableActions = [], onAddAction = noop, ...pro
31
33
  data-testid={"action-table-select"}
32
34
  name={"actions"}
33
35
  value={currentAction}
34
- options={[{ label: i18n("Select an action"), value: "" }].concat(availableActions)}
36
+ options={[{ label: t("Select an action"), value: "" }].concat(availableActions)}
35
37
  onChange={(_, action) => setAction(action)}
36
38
  />
37
39
  <div className={"pl-3"}>
@@ -42,7 +44,7 @@ export function ActionsTable({ availableActions = [], onAddAction = noop, ...pro
42
44
  onClick={() => currentAction && onAddAction(currentAction)}
43
45
  type={"submit"}
44
46
  >
45
- <i className={classnames(iconClass(undefined, "plus"), "mr-1")} /> {i18n("Add action")}
47
+ <i className={classnames(iconClass(undefined, "plus"), "mr-1")} /> {t("Add action")}
46
48
  </button>
47
49
  </div>
48
50
  </div>
@@ -2,6 +2,7 @@ import "./components/FormsCell.js";
2
2
 
3
3
  import { ColumnDef } from "@tanstack/react-table";
4
4
 
5
+ import { useI18n } from "../../../hooks/useI18n.js";
5
6
  import type { FormType } from "../../../interfaces";
6
7
  import { Table, TableProps } from "../../../molecules/table/Table";
7
8
  import { getComponent } from "../../../registries/components.js";
@@ -11,15 +12,15 @@ export type FormsTableProps = Omit<TableProps<FormType>, "columns"> & {
11
12
  tags?: { label: string; value: string }[];
12
13
  };
13
14
 
14
- export function FormsTable({ ...props }: FormsTableProps) {
15
- const { i18n = (f: string) => f, tags } = props;
15
+ export function FormsTable({ tags, ...props }: FormsTableProps) {
16
+ const { t } = useI18n(props.i18n);
16
17
  const Cell = getComponent<typeof FormsCell>("FormsCell");
17
18
 
18
19
  const columns: ColumnDef<any>[] = [
19
20
  {
20
- header: i18n("Title"),
21
+ header: t("Title"),
21
22
  accessorKey: "title",
22
- cell: (context) => <Cell {...context} i18n={i18n} />,
23
+ cell: (context) => <Cell {...context} i18n={t} />,
23
24
  meta: {
24
25
  cellProps: {
25
26
  colSpan: 2
@@ -27,7 +28,7 @@ export function FormsTable({ ...props }: FormsTableProps) {
27
28
  }
28
29
  },
29
30
  {
30
- header: i18n("Tags"),
31
+ header: t("Tags"),
31
32
  accessorKey: "tags",
32
33
  meta: {
33
34
  cellProps: {
@@ -78,7 +78,7 @@ export default {
78
78
  },
79
79
  args: {
80
80
  form: FormSchema as any,
81
- data: formSubmissions,
81
+ data: formSubmissions as any[],
82
82
  operations: [
83
83
  {
84
84
  title: "Edit",
@@ -125,18 +125,15 @@ export const Empty: Story = {
125
125
  */
126
126
  export const Translated: Story = {
127
127
  args: {
128
- i18n: (key: string) => {
129
- const translations: Record<string, string> = {
130
- "Search...": "Rechercher...",
131
- "No results found": "Aucun résultat trouvé",
132
- "Loading...": "Chargement...",
133
- Page: "Page",
134
- of: "sur",
135
- rows: "lignes",
136
- Edit: "Éditer",
137
- Delete: "Supprimer"
138
- };
139
- return translations[key] || key;
128
+ i18n: {
129
+ "Search...": "Rechercher...",
130
+ "No results found": "Aucun résultat trouvé",
131
+ "Loading...": "Chargement...",
132
+ Page: "Page",
133
+ of: "sur",
134
+ rows: "lignes",
135
+ Edit: "Éditer",
136
+ Delete: "Supprimer"
140
137
  }
141
138
  }
142
139
  };
@@ -175,7 +175,7 @@ export const Usage: Story = {
175
175
  title: "Anonymous"
176
176
  }
177
177
  ],
178
- i18n: (key: string) => key,
178
+ i18n: {},
179
179
  onAction: () => console.log("Action triggered")
180
180
  }
181
181
  };
@@ -203,21 +203,18 @@ export const Translated: Story = {
203
203
  title: "Anonymous"
204
204
  }
205
205
  ],
206
- i18n: (key: string) => {
207
- const translations: Record<string, string> = {
208
- Edit: "Éditer",
209
- Data: "Données",
210
- Preview: "Aperçu",
211
- Actions: "Actions",
212
- Access: "Accès",
213
- Export: "Exporter",
214
- Settings: "Paramètres",
215
- "Form with First Name": "Formulaire avec prénom",
216
- "First name": "Prénom",
217
- "Last name": "Nom de famille",
218
- Submit: "Soumettre"
219
- };
220
- return translations[key] || key;
206
+ i18n: {
207
+ Edit: "Éditer",
208
+ Data: "Données",
209
+ Preview: "Aperçu",
210
+ Actions: "Actions",
211
+ Access: "Accès",
212
+ Export: "Exporter",
213
+ Settings: "Paramètres",
214
+ "Form with First Name": "Formulaire avec prénom",
215
+ "First name": "Prénom",
216
+ "Last name": "Nom de famille",
217
+ Submit: "Soumettre"
221
218
  },
222
219
  onAction: () => console.log("Action triggered")
223
220
  }
@@ -1,4 +1,5 @@
1
- import type { FormType, JSON, PermissionsResolver } from "../../interfaces/index.js";
1
+ import { useI18n } from "../../hooks/useI18n.js";
2
+ import type { FormOptions, FormType, JSON, PermissionsResolver } from "../../interfaces/index.js";
2
3
  import type { Tab as DefaultTab } from "../../molecules/tabs/Tab.js";
3
4
  import type { TabList as DefaultTabList } from "../../molecules/tabs/TabList.js";
4
5
  import type { TabPanel as DefaultTabPanel } from "../../molecules/tabs/TabPanel.js";
@@ -19,7 +20,7 @@ export type FormViewsProps<Data extends { [key: string]: JSON } = { [key: string
19
20
  availableActions: ActionsTableProps["availableActions"];
20
21
  actions: ActionsTableProps["data"];
21
22
  roles?: FormAccessProps["roles"];
22
- i18n?: (key: string) => string;
23
+ i18n?: FormOptions["i18n"];
23
24
  onAction: () => void;
24
25
  permissionsResolver?: PermissionsResolver<Data>;
25
26
  };
@@ -71,8 +72,9 @@ export function FormViews<Data extends { [key: string]: JSON } = { [key: string]
71
72
  actions,
72
73
  permissionsResolver,
73
74
  submissions,
74
- i18n = (f) => f
75
+ ...props
75
76
  }: FormViewsProps<Data>) {
77
+ const { t } = useI18n(props.i18n);
76
78
  const Tabs = getComponent<typeof DefaultTabs>("Tabs");
77
79
  const TabList = getComponent<typeof DefaultTabList>("TabList");
78
80
  const Tab = getComponent<typeof DefaultTab>("Tab");
@@ -85,42 +87,42 @@ export function FormViews<Data extends { [key: string]: JSON } = { [key: string]
85
87
  <Tabs>
86
88
  <TabList>
87
89
  <Tab value={0} icon='edit'>
88
- {i18n("Edit")}
90
+ {t("Edit")}
89
91
  </Tab>
90
92
  <Tab value={1} icon='data'>
91
- {i18n("Data")}
93
+ {t("Data")}
92
94
  </Tab>
93
95
  <Tab value={2} icon='test-tube'>
94
- {i18n("Preview")}
96
+ {t("Preview")}
95
97
  </Tab>
96
98
  <Tab value={3} icon='paper-plane'>
97
- {i18n("Actions")}
99
+ {t("Actions")}
98
100
  </Tab>
99
101
  <Tab value={4} icon='lock'>
100
- {i18n("Access")}
102
+ {t("Access")}
101
103
  </Tab>
102
104
  <Tab value={5} icon='download'>
103
- {i18n("Export")}
105
+ {t("Export")}
104
106
  </Tab>
105
107
  <Tab value={6} icon='cog'>
106
- {i18n("Settings")}
108
+ {t("Settings")}
107
109
  </Tab>
108
110
  </TabList>
109
111
  <TabsBody>
110
112
  <TabPanel value={0} className='p-3 border-l-1 border-b-1 border-r-1 border-gray-300'>
111
- <FormEdit form={form} options={{ i18n }} />
113
+ <FormEdit form={form} />
112
114
  </TabPanel>
113
115
  <TabPanel value={1}>
114
116
  <SubmissionsTable<Data>
115
117
  className={"border-top-0"}
116
118
  form={form as FormType}
117
119
  data={submissions}
118
- i18n={i18n}
120
+ i18n={props.i18n}
119
121
  operations={submissionsOperations}
120
122
  />
121
123
  </TabPanel>
122
124
  <TabPanel value={2}>
123
- <FormPreview form={form as FormType} i18n={i18n} />
125
+ <FormPreview form={form as FormType} i18n={props.i18n} />
124
126
  </TabPanel>
125
127
  <TabPanel value={3}>
126
128
  <ActionsTable
@@ -128,14 +130,14 @@ export function FormViews<Data extends { [key: string]: JSON } = { [key: string]
128
130
  availableActions={availableActions}
129
131
  data={actions}
130
132
  operations={actionsOperations as any}
131
- i18n={i18n}
133
+ i18n={props.i18n}
132
134
  />
133
135
  </TabPanel>
134
136
  <TabPanel value={4} className='pt-3'>
135
- <FormAccess form={form as FormType} roles={roles} options={{ i18n }} />
137
+ <FormAccess form={form as FormType} roles={roles} options={props} />
136
138
  </TabPanel>
137
139
  <TabPanel value={5} className='pt-3'>
138
- <FormExport i18n={i18n} />
140
+ <FormExport i18n={props.i18n} />
139
141
  </TabPanel>
140
142
  <TabPanel value={6} className='p-3 border-l-1 border-b-1 border-r-1 border-gray-300'>
141
143
  <FormSettings form={form as FormType} options={{}} />
@@ -1,6 +1,4 @@
1
- import * as formio from "formiojs";
2
-
3
- const { Templates } = formio;
1
+ import { Templates } from "@formio/js";
4
2
 
5
3
  export function iconClass(iconset: string | undefined, name: string, spinning?: boolean): string {
6
4
  return Templates.current.iconClass(iconset || Templates.current.defaultIconset, name, spinning);
package/dist/typings.d.js DELETED
@@ -1,2 +0,0 @@
1
-
2
- //# sourceMappingURL=typings.d.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"typings.d.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
package/src/typings.d.ts DELETED
@@ -1,3 +0,0 @@
1
- declare module "formiojs/*" {
2
- export = {} as any;
3
- }