@opengov/form-renderer 0.0.31 → 0.0.32-beta.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.
@@ -0,0 +1,5 @@
1
+ export default function Field({ fieldId, manuallyDisabled, fullWidth, }: {
2
+ fieldId: string;
3
+ manuallyDisabled?: boolean;
4
+ fullWidth?: boolean;
5
+ }): import("react/jsx-runtime").JSX.Element | null | undefined;
@@ -0,0 +1,24 @@
1
+ import { default as React } from 'react';
2
+ import { UseFormProps } from 'react-hook-form';
3
+ import { LayoutState } from './context/LayoutContext';
4
+ import { Template, FieldRenders } from './types';
5
+ interface FormShellProps {
6
+ children: React.ReactNode;
7
+ onSubmit: (data: any) => void;
8
+ layout?: LayoutState;
9
+ template: Template;
10
+ renderFields?: FieldRenders;
11
+ formId?: string;
12
+ }
13
+ export declare function FormShell({ children, onSubmit, layout, template, renderFields, formId }: FormShellProps): import("react/jsx-runtime").JSX.Element;
14
+ interface FormProviderProps {
15
+ children: React.ReactNode;
16
+ onSubmit?: (data: any) => void;
17
+ layout?: LayoutState;
18
+ formOptions?: UseFormProps;
19
+ template: Template;
20
+ renderFields?: FieldRenders;
21
+ formId?: string;
22
+ }
23
+ declare function FormProvider({ children, onSubmit, layout, formOptions, template, renderFields, formId, }: FormProviderProps): import("react/jsx-runtime").JSX.Element;
24
+ export default FormProvider;
@@ -0,0 +1,18 @@
1
+ import { ReactNode } from 'react';
2
+ import { FieldRenders, Template } from '../types';
3
+ export interface FormRendererContextType {
4
+ template: Template;
5
+ renderFields?: FieldRenders;
6
+ }
7
+ interface FormRendererProviderProps {
8
+ children: ReactNode;
9
+ template: Template;
10
+ renderFields?: FieldRenders;
11
+ }
12
+ export declare const FormRendererProvider: React.FC<FormRendererProviderProps>;
13
+ export declare const useFormRenderer: () => FormRendererContextType;
14
+ export declare const useFormField: (fieldId: string) => {
15
+ template: import('react-hook-form').FieldValues;
16
+ render: ((field: import('react-hook-form').FieldValues, fullWidth?: boolean) => JSX.Element) | undefined;
17
+ };
18
+ export {};
@@ -1,5 +1,8 @@
1
+ import { SxProps, Theme } from '@mui/material';
1
2
  import { default as React, ReactNode } from 'react';
2
3
  export interface LayoutState {
4
+ form: SxProps<Theme>;
5
+ fields: SxProps<Theme>;
3
6
  }
4
7
  interface FormLayoutContextProps {
5
8
  layout: LayoutState;
@@ -0,0 +1,7 @@
1
+ import { FormRendererProps } from './types';
2
+ import { FieldValues } from 'react-hook-form';
3
+ export declare function Renderer({ fieldValues, formReadOnly }: {
4
+ fieldValues: FieldValues;
5
+ formReadOnly?: boolean;
6
+ }): import("react/jsx-runtime").JSX.Element;
7
+ export default function FormRenderer({ fieldValues, template, renderFields, onSubmit, layout, readonly, formId, formOptions, }: FormRendererProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,59 @@
1
+ import { FieldValues, UseFormProps } from 'react-hook-form';
2
+ import { LayoutState } from './context/LayoutContext';
3
+ export type ConditionTemplate = {
4
+ dependentEntityPrimaryKey: string;
5
+ dependentEntityType: string;
6
+ legacyId?: number;
7
+ logicTypeId: number;
8
+ comparate1?: string;
9
+ comparate2?: string;
10
+ };
11
+ export type SectionTemplate = FieldValues & {
12
+ type: 'singleEntry' | 'multiEntry';
13
+ id: string;
14
+ label: string;
15
+ helpText?: string;
16
+ internal: boolean;
17
+ required?: boolean;
18
+ sectionConditions: {
19
+ logicalOperator?: 'ALL' | 'ANY';
20
+ conditions?: ConditionTemplate[];
21
+ };
22
+ fields: string[];
23
+ };
24
+ export type FormTemplate = {
25
+ fields: Record<string, FieldValues>;
26
+ sections: SectionTemplate[];
27
+ };
28
+ export type Template = Omit<SectionTemplate, 'fields'> & {
29
+ fields: Record<string, FieldValues>;
30
+ };
31
+ export type FieldRenders = {
32
+ [key: string]: (field: FieldValues, fullWidth?: boolean) => JSX.Element;
33
+ };
34
+ export type FormRendererProps = {
35
+ fieldValues: FieldValues;
36
+ renderFields?: FieldRenders;
37
+ template: Template;
38
+ onSubmit?: (data: any) => void;
39
+ layout?: LayoutState;
40
+ readonly?: boolean;
41
+ formId?: string;
42
+ formOptions: {
43
+ defaultValues: FieldValues;
44
+ } & UseFormProps;
45
+ };
46
+ export declare enum LogicTypes {
47
+ EQUALS = 1,
48
+ BETWEEN = 2,
49
+ LESS_THAN = 3,
50
+ GREATER_THAN = 4,
51
+ LESS_THAN_OR_EQUAL = 5,
52
+ GREATER_THAN_OR_EQUAL = 6,
53
+ HAS_FLAGS = 7,
54
+ IS_RENEWAL = 8,
55
+ IS_NOT = 9,
56
+ TIME_AFTER_MORE_THAN = 10,
57
+ TIME_BEFORE_MORE_THAN = 11,
58
+ DATETIME_BETWEEN = 12
59
+ }
@@ -0,0 +1,3 @@
1
+ export default function BasicExample({ args }: {
2
+ args: any;
3
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1 @@
1
+ export default function CompoundExample(): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,5 @@
1
+ import { FieldValues } from 'react-hook-form';
2
+ export declare const customForm: FieldValues;
3
+ export default function BasicExample({ args }: {
4
+ args: any;
5
+ }): import("react/jsx-runtime").JSX.Element;
@@ -2,6 +2,6 @@ import { Meta, StoryObj } from '@storybook/react';
2
2
  declare const meta: Meta;
3
3
  export default meta;
4
4
  type Story = StoryObj<typeof meta>;
5
+ export declare const Basic: Story;
6
+ export declare const Custom: Story;
5
7
  export declare const Compound: Story;
6
- export declare const WithDefaultValues: Story;
7
- export declare const UsingReactHookForms: Story;
@@ -0,0 +1,2 @@
1
+ import { FieldValues } from 'react-hook-form';
2
+ export declare const basicForm: FieldValues;
@@ -0,0 +1,2 @@
1
+ import { Template } from '../renderer/types';
2
+ export declare const basicTemplate: Template;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengov/form-renderer",
3
- "version": "0.0.31",
3
+ "version": "0.0.32-beta.0",
4
4
  "description": "OpenGov Smart Forms form renderer",
5
5
  "type": "module",
6
6
  "files": [
@@ -26,7 +26,8 @@
26
26
  "@mdi/js": "^7.4.47",
27
27
  "@mdi/react": "^1.6.1",
28
28
  "@mui/icons-material": "^6.1.1",
29
- "date-fns": "^4.1.0"
29
+ "date-fns": "^4.1.0",
30
+ "sanitize-html": "^2.14.0"
30
31
  },
31
32
  "peerDependencies": {
32
33
  "@mui/material": ">= 5.0.0",
@@ -42,6 +43,7 @@
42
43
  "@mui/material": "^6.1.1",
43
44
  "@mui/x-date-pickers": "^7.22.0",
44
45
  "@opengov/capital-mui-theme": "^36.0.0-beta.9",
46
+ "@types/sanitize-html": "^2.13.0",
45
47
  "react": "^18.3.1",
46
48
  "react-dom": "^18.3.1",
47
49
  "react-hook-form": "^7.53.1"
@@ -1,19 +0,0 @@
1
- import { default as React } from 'react';
2
- import { LayoutState } from './LayoutContext';
3
- import { SxProps } from '@mui/material';
4
- interface FormShellProps {
5
- children: React.ReactNode;
6
- onSubmit: (data: any) => void;
7
- layout?: LayoutState;
8
- sx?: SxProps;
9
- }
10
- export declare function FormShell({ children, onSubmit, layout, sx }: FormShellProps): import("react/jsx-runtime").JSX.Element;
11
- interface FormProviderProps {
12
- children: React.ReactNode;
13
- onSubmit?: (data: any) => void;
14
- layout?: LayoutState;
15
- formOptions?: any;
16
- sx?: SxProps;
17
- }
18
- declare function FormProvider({ children, onSubmit, layout, formOptions, sx }: FormProviderProps): import("react/jsx-runtime").JSX.Element;
19
- export default FormProvider;
File without changes