@opengov/form-renderer 0.0.47 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +5 -4
- package/dist/lib.js +3666 -3671
- package/dist/lib.umd.cjs +46 -46
- package/dist/renderer/Field.d.ts +14 -3
- package/dist/renderer/Form.d.ts +19 -0
- package/dist/renderer/{FormProvider.d.ts → RendererProvider.d.ts} +4 -5
- package/dist/renderer/Section.d.ts +17 -0
- package/dist/renderer/context/FormRendererContext.d.ts +32 -18
- package/dist/renderer/context/LayoutContext.d.ts +3 -2
- package/dist/renderer/types.d.ts +5 -12
- package/dist/stories/Basic.d.ts +1 -3
- package/package.json +1 -1
- package/dist/renderer/index.d.ts +0 -11
package/dist/renderer/Field.d.ts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Field is a component that renders a field.
|
|
3
|
+
* It takes a fieldId and readonly.
|
|
4
|
+
* It uses the field template and the field type to render a field.
|
|
5
|
+
* The field is wrapped in a Box that can be styled by the layout object passed to the RendererProvider.
|
|
6
|
+
* @param id - The fieldId to render.
|
|
7
|
+
* @param name - The name of the field within the form.
|
|
8
|
+
* @param readonly - Whether the field is readonly.
|
|
9
|
+
* @returns A Field component.
|
|
10
|
+
*/
|
|
11
|
+
export default function Field({ id, name, readonly }: {
|
|
12
|
+
id: string;
|
|
13
|
+
name?: string;
|
|
3
14
|
readonly?: boolean;
|
|
4
|
-
}): import("react/jsx-runtime").JSX.Element
|
|
15
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { UseFormProps } from 'react-hook-form';
|
|
2
|
+
import { SubmitOptions } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Form is a component that renders a form.
|
|
5
|
+
* It takes children, formOptions, and submitOptions.
|
|
6
|
+
* It renders a FormProvider with the formOptions.
|
|
7
|
+
* It renders a form with the submitOptions.
|
|
8
|
+
* @param children - The children to render.
|
|
9
|
+
* @param formOptions - The form options to use.
|
|
10
|
+
* @param submitOptions - The submit options to use.
|
|
11
|
+
* @returns A Form component.
|
|
12
|
+
*/
|
|
13
|
+
export default function Form({ children, formOptions, submitOptions, }: {
|
|
14
|
+
children: React.ReactNode;
|
|
15
|
+
formOptions?: UseFormProps & {
|
|
16
|
+
defaultValues: Record<string, any>;
|
|
17
|
+
};
|
|
18
|
+
submitOptions?: SubmitOptions;
|
|
19
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
2
|
import { LayoutState } from './context/LayoutContext';
|
|
3
3
|
import { FormTemplate, FieldTypes } from '@opengov/form-utils';
|
|
4
|
-
interface
|
|
4
|
+
interface RendererProviderProps {
|
|
5
5
|
children: React.ReactNode;
|
|
6
|
-
layout?: LayoutState;
|
|
7
6
|
template: FormTemplate;
|
|
8
7
|
fieldTypes?: FieldTypes[];
|
|
9
|
-
|
|
8
|
+
layout?: LayoutState;
|
|
10
9
|
}
|
|
11
|
-
|
|
12
|
-
export
|
|
10
|
+
export default function RendererProvider({ children, template, fieldTypes, layout, }: RendererProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SectionTemplate } from '@opengov/form-utils';
|
|
2
|
+
/**
|
|
3
|
+
* Section is a component that renders a section.
|
|
4
|
+
* It takes a section template, a list of fields, and readonly.
|
|
5
|
+
* It renders a Box with the section layout.
|
|
6
|
+
* It maps every field to a Field component, passing the readonly prop.
|
|
7
|
+
* @param section - The section template to render.
|
|
8
|
+
* @param fields - The fields to render.
|
|
9
|
+
* @param readonly - Whether the section is readonly.
|
|
10
|
+
* @returns A Section component.
|
|
11
|
+
*/
|
|
12
|
+
export default function Section({ section, fields, fieldNames, readonly, }: {
|
|
13
|
+
section: SectionTemplate;
|
|
14
|
+
fields: string[];
|
|
15
|
+
fieldNames?: string[];
|
|
16
|
+
readonly?: boolean;
|
|
17
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -3,13 +3,11 @@ import { FormTemplate, FieldTypes } from '@opengov/form-utils';
|
|
|
3
3
|
export interface FormRendererContextType {
|
|
4
4
|
template: FormTemplate;
|
|
5
5
|
fieldTypes: FieldTypes[];
|
|
6
|
-
readonly?: boolean;
|
|
7
6
|
}
|
|
8
7
|
interface FormRendererProviderProps {
|
|
9
8
|
children: ReactNode;
|
|
10
9
|
template: FormTemplate;
|
|
11
10
|
fieldTypes: FieldTypes[];
|
|
12
|
-
readonly?: boolean;
|
|
13
11
|
}
|
|
14
12
|
export declare const FormRendererProvider: React.FC<FormRendererProviderProps>;
|
|
15
13
|
export declare const useFormRenderer: () => FormRendererContextType;
|
|
@@ -21,18 +19,22 @@ export declare const useFieldType: (type?: string) => {
|
|
|
21
19
|
groups: import('@opengov/form-utils').ConfigurationGroup<import('react-hook-form').FieldValues>[];
|
|
22
20
|
omitLabelConfiguration?: boolean;
|
|
23
21
|
fullWidth: boolean;
|
|
24
|
-
renderField: ((template: import('@opengov/form-utils').FieldTemplate, config: import('@opengov/form-utils').FieldConfiguration<import('react-hook-form').FieldValues>, { disabled, readonly }: {
|
|
22
|
+
renderField: ((template: import('@opengov/form-utils').FieldTemplate, config: import('@opengov/form-utils').FieldConfiguration<import('react-hook-form').FieldValues>, { disabled, readonly, name }: {
|
|
25
23
|
disabled?: boolean;
|
|
26
24
|
readonly?: boolean;
|
|
27
|
-
|
|
25
|
+
name?: string;
|
|
26
|
+
}) => JSX.Element) | ((template: import('@opengov/form-utils').FieldTemplate, config: import('@opengov/form-utils').TextConfiguration, { disabled, readonly, name }: {
|
|
28
27
|
disabled?: boolean;
|
|
29
28
|
readonly?: boolean;
|
|
30
|
-
|
|
29
|
+
name?: string;
|
|
30
|
+
}) => JSX.Element) | ((template: import('@opengov/form-utils').FieldTemplate, config: import('@opengov/form-utils').NumberConfiguration, { disabled, readonly, name }: {
|
|
31
31
|
disabled?: boolean;
|
|
32
32
|
readonly?: boolean;
|
|
33
|
-
|
|
33
|
+
name?: string;
|
|
34
|
+
}) => JSX.Element) | ((template: import('@opengov/form-utils').FieldTemplate, config: import('@opengov/form-utils').DateConfiguration, { disabled, readonly, name }: {
|
|
34
35
|
disabled?: boolean;
|
|
35
36
|
readonly?: boolean;
|
|
37
|
+
name?: string;
|
|
36
38
|
}) => JSX.Element);
|
|
37
39
|
} | {
|
|
38
40
|
type: string;
|
|
@@ -44,18 +46,22 @@ export declare const useFieldType: (type?: string) => {
|
|
|
44
46
|
fullWidth: boolean;
|
|
45
47
|
maxLength: number;
|
|
46
48
|
filter?: (value: string) => string;
|
|
47
|
-
renderField: ((template: import('@opengov/form-utils').FieldTemplate, config: import('@opengov/form-utils').FieldConfiguration<import('react-hook-form').FieldValues>, { disabled, readonly }: {
|
|
49
|
+
renderField: ((template: import('@opengov/form-utils').FieldTemplate, config: import('@opengov/form-utils').FieldConfiguration<import('react-hook-form').FieldValues>, { disabled, readonly, name }: {
|
|
48
50
|
disabled?: boolean;
|
|
49
51
|
readonly?: boolean;
|
|
50
|
-
|
|
52
|
+
name?: string;
|
|
53
|
+
}) => JSX.Element) | ((template: import('@opengov/form-utils').FieldTemplate, config: import('@opengov/form-utils').TextConfiguration, { disabled, readonly, name }: {
|
|
51
54
|
disabled?: boolean;
|
|
52
55
|
readonly?: boolean;
|
|
53
|
-
|
|
56
|
+
name?: string;
|
|
57
|
+
}) => JSX.Element) | ((template: import('@opengov/form-utils').FieldTemplate, config: import('@opengov/form-utils').NumberConfiguration, { disabled, readonly, name }: {
|
|
54
58
|
disabled?: boolean;
|
|
55
59
|
readonly?: boolean;
|
|
56
|
-
|
|
60
|
+
name?: string;
|
|
61
|
+
}) => JSX.Element) | ((template: import('@opengov/form-utils').FieldTemplate, config: import('@opengov/form-utils').DateConfiguration, { disabled, readonly, name }: {
|
|
57
62
|
disabled?: boolean;
|
|
58
63
|
readonly?: boolean;
|
|
64
|
+
name?: string;
|
|
59
65
|
}) => JSX.Element);
|
|
60
66
|
} | {
|
|
61
67
|
type: string;
|
|
@@ -66,18 +72,22 @@ export declare const useFieldType: (type?: string) => {
|
|
|
66
72
|
omitLabelConfiguration?: boolean;
|
|
67
73
|
fullWidth: boolean;
|
|
68
74
|
decimalPlaces: number;
|
|
69
|
-
renderField: ((template: import('@opengov/form-utils').FieldTemplate, config: import('@opengov/form-utils').FieldConfiguration<import('react-hook-form').FieldValues>, { disabled, readonly }: {
|
|
75
|
+
renderField: ((template: import('@opengov/form-utils').FieldTemplate, config: import('@opengov/form-utils').FieldConfiguration<import('react-hook-form').FieldValues>, { disabled, readonly, name }: {
|
|
70
76
|
disabled?: boolean;
|
|
71
77
|
readonly?: boolean;
|
|
72
|
-
|
|
78
|
+
name?: string;
|
|
79
|
+
}) => JSX.Element) | ((template: import('@opengov/form-utils').FieldTemplate, config: import('@opengov/form-utils').TextConfiguration, { disabled, readonly, name }: {
|
|
73
80
|
disabled?: boolean;
|
|
74
81
|
readonly?: boolean;
|
|
75
|
-
|
|
82
|
+
name?: string;
|
|
83
|
+
}) => JSX.Element) | ((template: import('@opengov/form-utils').FieldTemplate, config: import('@opengov/form-utils').NumberConfiguration, { disabled, readonly, name }: {
|
|
76
84
|
disabled?: boolean;
|
|
77
85
|
readonly?: boolean;
|
|
78
|
-
|
|
86
|
+
name?: string;
|
|
87
|
+
}) => JSX.Element) | ((template: import('@opengov/form-utils').FieldTemplate, config: import('@opengov/form-utils').DateConfiguration, { disabled, readonly, name }: {
|
|
79
88
|
disabled?: boolean;
|
|
80
89
|
readonly?: boolean;
|
|
90
|
+
name?: string;
|
|
81
91
|
}) => JSX.Element);
|
|
82
92
|
} | {
|
|
83
93
|
type: string;
|
|
@@ -88,18 +98,22 @@ export declare const useFieldType: (type?: string) => {
|
|
|
88
98
|
omitLabelConfiguration?: boolean;
|
|
89
99
|
fullWidth: boolean;
|
|
90
100
|
dateFormat: import('@opengov/form-utils').DateFormat;
|
|
91
|
-
renderField: ((template: import('@opengov/form-utils').FieldTemplate, config: import('@opengov/form-utils').FieldConfiguration<import('react-hook-form').FieldValues>, { disabled, readonly }: {
|
|
101
|
+
renderField: ((template: import('@opengov/form-utils').FieldTemplate, config: import('@opengov/form-utils').FieldConfiguration<import('react-hook-form').FieldValues>, { disabled, readonly, name }: {
|
|
92
102
|
disabled?: boolean;
|
|
93
103
|
readonly?: boolean;
|
|
94
|
-
|
|
104
|
+
name?: string;
|
|
105
|
+
}) => JSX.Element) | ((template: import('@opengov/form-utils').FieldTemplate, config: import('@opengov/form-utils').TextConfiguration, { disabled, readonly, name }: {
|
|
95
106
|
disabled?: boolean;
|
|
96
107
|
readonly?: boolean;
|
|
97
|
-
|
|
108
|
+
name?: string;
|
|
109
|
+
}) => JSX.Element) | ((template: import('@opengov/form-utils').FieldTemplate, config: import('@opengov/form-utils').NumberConfiguration, { disabled, readonly, name }: {
|
|
98
110
|
disabled?: boolean;
|
|
99
111
|
readonly?: boolean;
|
|
100
|
-
|
|
112
|
+
name?: string;
|
|
113
|
+
}) => JSX.Element) | ((template: import('@opengov/form-utils').FieldTemplate, config: import('@opengov/form-utils').DateConfiguration, { disabled, readonly, name }: {
|
|
101
114
|
disabled?: boolean;
|
|
102
115
|
readonly?: boolean;
|
|
116
|
+
name?: string;
|
|
103
117
|
}) => JSX.Element);
|
|
104
118
|
} | null;
|
|
105
119
|
export declare const useFieldTemplate: (fieldId: string) => import('@opengov/form-utils').FieldTemplate;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { SxProps, Theme } from '@mui/material';
|
|
2
|
+
import { FieldConfiguration, FieldTemplate, SectionTemplate } from '@opengov/form-utils';
|
|
2
3
|
import { default as React, ReactNode } from 'react';
|
|
3
4
|
export interface LayoutState {
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
section?: (template: SectionTemplate) => SxProps<Theme>;
|
|
6
|
+
field?: (template: FieldTemplate, config?: FieldConfiguration) => SxProps<Theme>;
|
|
6
7
|
}
|
|
7
8
|
interface FormLayoutContextProps {
|
|
8
9
|
layout: LayoutState;
|
package/dist/renderer/types.d.ts
CHANGED
|
@@ -2,11 +2,12 @@ import { UseFormProps } from 'react-hook-form';
|
|
|
2
2
|
import { LayoutState } from './context/LayoutContext';
|
|
3
3
|
import { FieldTypes, FormTemplate, DateFormat } from '@opengov/form-utils';
|
|
4
4
|
export type FormData = Record<string, any>;
|
|
5
|
-
export type
|
|
6
|
-
onSubmit
|
|
5
|
+
export type SubmitOptions = {
|
|
6
|
+
onSubmit?: (data: any) => void;
|
|
7
7
|
onReset?: () => void;
|
|
8
|
-
formId
|
|
8
|
+
formId?: string;
|
|
9
9
|
submitOnChange?: boolean;
|
|
10
|
+
registerForm?: (ref: HTMLFormElement | null) => void;
|
|
10
11
|
};
|
|
11
12
|
export type FormRendererProps = {
|
|
12
13
|
fieldTypes?: FieldTypes[];
|
|
@@ -16,15 +17,7 @@ export type FormRendererProps = {
|
|
|
16
17
|
formOptions?: UseFormProps & {
|
|
17
18
|
defaultValues: FormData;
|
|
18
19
|
};
|
|
19
|
-
|
|
20
|
+
submitOptions?: SubmitOptions;
|
|
20
21
|
decimalPlaces?: number;
|
|
21
22
|
dateFormat?: DateFormat;
|
|
22
23
|
};
|
|
23
|
-
export type RendererProps = {
|
|
24
|
-
fieldIds: string[];
|
|
25
|
-
formOptions?: UseFormProps & {
|
|
26
|
-
defaultValues: FormData;
|
|
27
|
-
};
|
|
28
|
-
submit?: SubmitProps;
|
|
29
|
-
readonly?: boolean;
|
|
30
|
-
};
|
package/dist/stories/Basic.d.ts
CHANGED
package/package.json
CHANGED
package/dist/renderer/index.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { FormRendererProps, RendererProps, SubmitProps } from './types';
|
|
2
|
-
import { UseFormProps } from 'react-hook-form';
|
|
3
|
-
export declare function FormShell({ children, formOptions, submit, }: {
|
|
4
|
-
children: React.ReactNode;
|
|
5
|
-
formOptions?: UseFormProps & {
|
|
6
|
-
defaultValues: Record<string, any>;
|
|
7
|
-
};
|
|
8
|
-
submit?: SubmitProps;
|
|
9
|
-
}): import("react/jsx-runtime").JSX.Element;
|
|
10
|
-
export declare function Renderer({ fieldIds, formOptions, submit, readonly }: RendererProps): import("react/jsx-runtime").JSX.Element;
|
|
11
|
-
export default function FormRenderer({ template, fieldTypes, layout, readonly, formOptions, submit, }: FormRendererProps): import("react/jsx-runtime").JSX.Element;
|