@opengov/form-renderer 0.0.41-config-beta.2 → 0.0.41

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.
@@ -1,12 +1,13 @@
1
1
  import { default as React } from 'react';
2
2
  import { LayoutState } from './context/LayoutContext';
3
- import { FormTemplate, FieldTypes } from '@opengov/form-utils';
3
+ import { FormTemplate, FieldRenders, DateFormat } from './types';
4
4
  interface FormProviderProps {
5
5
  children: React.ReactNode;
6
6
  layout?: LayoutState;
7
7
  template: FormTemplate;
8
- fieldTypes?: FieldTypes[];
8
+ renderFields?: FieldRenders;
9
9
  readonly?: boolean;
10
+ dateFormat?: DateFormat;
10
11
  }
11
- declare function FormProvider({ children, layout, template, fieldTypes, readonly }: FormProviderProps): import("react/jsx-runtime").JSX.Element;
12
+ declare function FormProvider({ children, layout, template, renderFields, readonly, dateFormat, }: FormProviderProps): import("react/jsx-runtime").JSX.Element;
12
13
  export default FormProvider;
@@ -1,108 +1,24 @@
1
1
  import { ReactNode } from 'react';
2
- import { FormTemplate, FieldTypes } from '@opengov/form-utils';
2
+ import { FieldRenders, FormTemplate } from '../types';
3
3
  export interface FormRendererContextType {
4
4
  template: FormTemplate;
5
- fieldTypes: FieldTypes[];
5
+ renderFields?: FieldRenders;
6
+ dateFormat?: string;
6
7
  readonly?: boolean;
7
8
  }
8
9
  interface FormRendererProviderProps {
9
10
  children: ReactNode;
10
11
  template: FormTemplate;
11
- fieldTypes: FieldTypes[];
12
+ renderFields?: FieldRenders;
13
+ dateFormat?: string;
12
14
  readonly?: boolean;
13
15
  }
14
16
  export declare const FormRendererProvider: React.FC<FormRendererProviderProps>;
15
17
  export declare const useFormRenderer: () => FormRendererContextType;
16
- export declare const useFieldType: (type?: string) => {
17
- type: string;
18
- name: string;
19
- Icon?: React.ElementType;
20
- icon?: string;
21
- groups: import('@opengov/form-utils').ConfigurationGroup<import('react-hook-form').FieldValues>[];
22
- omitLabelConfiguration?: boolean;
23
- fullWidth: boolean;
24
- renderField: ((template: import('@opengov/form-utils').FieldTemplate, config: import('@opengov/form-utils').FieldConfiguration<import('react-hook-form').FieldValues>, { disabled, readonly }: {
25
- disabled?: boolean;
26
- readonly?: boolean;
27
- }) => JSX.Element) | ((template: import('@opengov/form-utils').FieldTemplate, config: import('@opengov/form-utils').TextConfiguration, { disabled, readonly }: {
28
- disabled?: boolean;
29
- readonly?: boolean;
30
- }) => JSX.Element) | ((template: import('@opengov/form-utils').FieldTemplate, config: import('@opengov/form-utils').NumberConfiguration, { disabled, readonly }: {
31
- disabled?: boolean;
32
- readonly?: boolean;
33
- }) => JSX.Element) | ((template: import('@opengov/form-utils').FieldTemplate, config: import('@opengov/form-utils').DateConfiguration, { disabled, readonly }: {
34
- disabled?: boolean;
35
- readonly?: boolean;
36
- }) => JSX.Element);
37
- } | {
38
- type: "TEXTINPUT";
39
- name: string;
40
- Icon?: React.ElementType;
41
- icon?: string;
42
- groups: import('@opengov/form-utils').ConfigurationGroup<import('react-hook-form').FieldValues>[];
43
- omitLabelConfiguration?: boolean;
44
- fullWidth: boolean;
45
- maxLength: number;
46
- renderField: ((template: import('@opengov/form-utils').FieldTemplate, config: import('@opengov/form-utils').FieldConfiguration<import('react-hook-form').FieldValues>, { disabled, readonly }: {
47
- disabled?: boolean;
48
- readonly?: boolean;
49
- }) => JSX.Element) | ((template: import('@opengov/form-utils').FieldTemplate, config: import('@opengov/form-utils').TextConfiguration, { disabled, readonly }: {
50
- disabled?: boolean;
51
- readonly?: boolean;
52
- }) => JSX.Element) | ((template: import('@opengov/form-utils').FieldTemplate, config: import('@opengov/form-utils').NumberConfiguration, { disabled, readonly }: {
53
- disabled?: boolean;
54
- readonly?: boolean;
55
- }) => JSX.Element) | ((template: import('@opengov/form-utils').FieldTemplate, config: import('@opengov/form-utils').DateConfiguration, { disabled, readonly }: {
56
- disabled?: boolean;
57
- readonly?: boolean;
58
- }) => JSX.Element);
59
- } | {
60
- type: "NUMBER";
61
- name: string;
62
- Icon?: React.ElementType;
63
- icon?: string;
64
- groups: import('@opengov/form-utils').ConfigurationGroup<import('react-hook-form').FieldValues>[];
65
- omitLabelConfiguration?: boolean;
66
- fullWidth: boolean;
67
- decimalPlaces: number;
68
- renderField: ((template: import('@opengov/form-utils').FieldTemplate, config: import('@opengov/form-utils').FieldConfiguration<import('react-hook-form').FieldValues>, { disabled, readonly }: {
69
- disabled?: boolean;
70
- readonly?: boolean;
71
- }) => JSX.Element) | ((template: import('@opengov/form-utils').FieldTemplate, config: import('@opengov/form-utils').TextConfiguration, { disabled, readonly }: {
72
- disabled?: boolean;
73
- readonly?: boolean;
74
- }) => JSX.Element) | ((template: import('@opengov/form-utils').FieldTemplate, config: import('@opengov/form-utils').NumberConfiguration, { disabled, readonly }: {
75
- disabled?: boolean;
76
- readonly?: boolean;
77
- }) => JSX.Element) | ((template: import('@opengov/form-utils').FieldTemplate, config: import('@opengov/form-utils').DateConfiguration, { disabled, readonly }: {
78
- disabled?: boolean;
79
- readonly?: boolean;
80
- }) => JSX.Element);
81
- } | {
82
- type: "DATE";
83
- name: string;
84
- Icon?: React.ElementType;
85
- icon?: string;
86
- groups: import('@opengov/form-utils').ConfigurationGroup<import('react-hook-form').FieldValues>[];
87
- omitLabelConfiguration?: boolean;
88
- fullWidth: boolean;
89
- dateFormat: import('@opengov/form-utils').DateFormat;
90
- renderField: ((template: import('@opengov/form-utils').FieldTemplate, config: import('@opengov/form-utils').FieldConfiguration<import('react-hook-form').FieldValues>, { disabled, readonly }: {
91
- disabled?: boolean;
92
- readonly?: boolean;
93
- }) => JSX.Element) | ((template: import('@opengov/form-utils').FieldTemplate, config: import('@opengov/form-utils').TextConfiguration, { disabled, readonly }: {
94
- disabled?: boolean;
95
- readonly?: boolean;
96
- }) => JSX.Element) | ((template: import('@opengov/form-utils').FieldTemplate, config: import('@opengov/form-utils').NumberConfiguration, { disabled, readonly }: {
97
- disabled?: boolean;
98
- readonly?: boolean;
99
- }) => JSX.Element) | ((template: import('@opengov/form-utils').FieldTemplate, config: import('@opengov/form-utils').DateConfiguration, { disabled, readonly }: {
100
- disabled?: boolean;
101
- readonly?: boolean;
102
- }) => JSX.Element);
103
- } | null;
104
- export declare const useFieldTemplate: (fieldId: string) => {
105
- template: import('@opengov/form-utils').FieldTemplate;
18
+ export declare const useFormField: (fieldId: string) => {
19
+ template: import('../types').FieldTemplate;
20
+ render: (field: import('../types').FieldTemplate) => JSX.Element;
21
+ renderReadOnly: ((field: import('../types').FieldTemplate) => JSX.Element) | undefined;
106
22
  formattedFormula: string;
107
23
  };
108
24
  export {};
@@ -8,4 +8,4 @@ export declare function FormShell({ children, formOptions, submit, }: {
8
8
  submit?: SubmitProps;
9
9
  }): import("react/jsx-runtime").JSX.Element;
10
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;
11
+ export default function FormRenderer({ template, renderFields, layout, readonly, formOptions, submit, dateFormat, }: FormRendererProps): import("react/jsx-runtime").JSX.Element;
@@ -1,6 +1,46 @@
1
- import { UseFormProps } from 'react-hook-form';
1
+ import { FieldValues, UseFormProps } from 'react-hook-form';
2
2
  import { LayoutState } from './context/LayoutContext';
3
- import { FieldTypes, FormTemplate, DateFormat } from '@opengov/form-utils';
3
+ export type SectionTemplate = FieldValues & {
4
+ type: 'singleEntry' | 'multiEntry';
5
+ id: string;
6
+ label: string;
7
+ helpText?: string;
8
+ internal: boolean;
9
+ required?: boolean;
10
+ fields: string[];
11
+ sectionConditions: {
12
+ logicalOperator?: 'ALL' | 'ANY';
13
+ conditions?: ConditionTemplate[];
14
+ };
15
+ };
16
+ export type FormTemplate = {
17
+ fields: Record<string, FieldTemplate>;
18
+ sections: SectionTemplate[];
19
+ };
20
+ export type FieldTemplate = FieldValues & {
21
+ id: string;
22
+ label: string;
23
+ helpText?: string;
24
+ internal?: boolean;
25
+ required?: boolean;
26
+ visibleId?: string;
27
+ fullWidth?: boolean;
28
+ readonly?: boolean;
29
+ };
30
+ export type ConditionTemplate = {
31
+ dependentEntityPrimaryKey: string;
32
+ dependentEntityType: string;
33
+ legacyId?: number;
34
+ logicTypeId: number;
35
+ comparate1?: string;
36
+ comparate2?: string;
37
+ };
38
+ export type FieldRenders = {
39
+ [key: string]: {
40
+ render: (field: FieldTemplate) => JSX.Element;
41
+ renderReadOnly?: (field: FieldTemplate) => JSX.Element;
42
+ };
43
+ };
4
44
  export type FormData = Record<string, any>;
5
45
  export type SubmitProps = {
6
46
  onSubmit: (data: any) => void;
@@ -9,7 +49,7 @@ export type SubmitProps = {
9
49
  submitOnChange?: boolean;
10
50
  };
11
51
  export type FormRendererProps = {
12
- fieldTypes?: FieldTypes[];
52
+ renderFields?: FieldRenders;
13
53
  template: FormTemplate;
14
54
  layout?: LayoutState;
15
55
  readonly?: boolean;
@@ -27,3 +67,44 @@ export type RendererProps = {
27
67
  submit?: SubmitProps;
28
68
  readonly?: boolean;
29
69
  };
70
+ export declare enum LogicTypes {
71
+ EQUALS = 1,
72
+ BETWEEN = 2,
73
+ LESS_THAN = 3,
74
+ GREATER_THAN = 4,
75
+ LESS_THAN_OR_EQUAL = 5,
76
+ GREATER_THAN_OR_EQUAL = 6,
77
+ HAS_FLAGS = 7,
78
+ IS_RENEWAL = 8,
79
+ IS_NOT = 9,
80
+ TIME_AFTER_MORE_THAN = 10,
81
+ TIME_BEFORE_MORE_THAN = 11,
82
+ DATETIME_BETWEEN = 12
83
+ }
84
+ export type DateFormat = 'yyyy-MM-dd' | 'MM/dd/yyyy' | 'dd/MM/yyyy' | 'yyyy/MM/dd' | 'dd MMM yyyy' | 'dd MMMM yyyy' | 'EEE, dd MMM yyyy' | 'EEEE, dd MMM yyyy';
85
+ export declare enum DateUnit {
86
+ DAY = "DAY",
87
+ WEEK = "WEEK",
88
+ MONTH = "MONTH",
89
+ YEAR = "YEAR"
90
+ }
91
+ export declare enum DayOfWeek {
92
+ SUNDAY = "SUNDAY",
93
+ MONDAY = "MONDAY",
94
+ TUESDAY = "TUESDAY",
95
+ WEDNESDAY = "WEDNESDAY",
96
+ THURSDAY = "THURSDAY",
97
+ FRIDAY = "FRIDAY",
98
+ SATURDAY = "SATURDAY"
99
+ }
100
+ export type DateConstraints = {
101
+ disableDaysOfWeek?: DayOfWeek[];
102
+ disablePastDates?: {
103
+ number: number;
104
+ unit: DateUnit;
105
+ };
106
+ disableFutureDates?: {
107
+ number: number;
108
+ unit: DateUnit;
109
+ };
110
+ };
@@ -1,2 +1,2 @@
1
- import { FormTemplate } from '@opengov/form-utils';
1
+ import { FormTemplate } from '../renderer/types';
2
2
  export declare const basicTemplate: FormTemplate;
@@ -1,2 +1,2 @@
1
- import { FormTemplate } from '@opengov/form-utils';
1
+ import { FormTemplate } from '../renderer/types';
2
2
  export declare const complexTemplate: FormTemplate;
@@ -1,4 +1,4 @@
1
- import { FieldTemplate } from '@opengov/form-utils';
1
+ import { FieldTemplate } from '../renderer/types';
2
2
  export default function TestWrapper({ children, fieldTemplate, defaultValues, }: {
3
3
  children: React.ReactNode;
4
4
  fieldTemplate: FieldTemplate;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengov/form-renderer",
3
- "version": "0.0.41-config-beta.2",
3
+ "version": "0.0.41",
4
4
  "description": "OpenGov Smart Forms form renderer",
5
5
  "type": "module",
6
6
  "files": [
@@ -26,7 +26,6 @@
26
26
  "@mdi/js": "^7.4.47",
27
27
  "@mdi/react": "^1.6.1",
28
28
  "@mui/icons-material": "^6.1.1",
29
- "@opengov/form-utils": "^0.0.1-beta.1",
30
29
  "date-fns": "^4.1.0",
31
30
  "sanitize-html": "^2.14.0"
32
31
  },
@@ -1,13 +0,0 @@
1
- import { GeneralInputProps } from '../types';
2
- import { FieldTemplate, FieldConfiguration } from '@opengov/form-utils';
3
- export declare function CalculatedNumberInput({ name, label, sx }: GeneralInputProps): import("react/jsx-runtime").JSX.Element;
4
- export declare function CalculationWithFormula({ template, readonly }: {
5
- template: FieldTemplate;
6
- readonly?: boolean;
7
- }): import("react/jsx-runtime").JSX.Element;
8
- export default function CalculatedNumber({ template, disabled, readonly, }: {
9
- template: FieldTemplate;
10
- config: FieldConfiguration;
11
- disabled?: boolean;
12
- readonly?: boolean;
13
- }): import("react/jsx-runtime").JSX.Element;
@@ -1,3 +0,0 @@
1
- import { TypeConfig } from '@opengov/form-utils';
2
- declare const calculatedNumberConfiguration: TypeConfig;
3
- export default calculatedNumberConfiguration;
@@ -1,3 +0,0 @@
1
- import { TypeConfig } from '@opengov/form-utils';
2
- declare const checkboxConfiguration: TypeConfig;
3
- export default checkboxConfiguration;
@@ -1,3 +0,0 @@
1
- import { TypeConfig, DateConfiguration } from '@opengov/form-utils';
2
- declare const dateConfiguration: TypeConfig<DateConfiguration>;
3
- export default dateConfiguration;
@@ -1,3 +0,0 @@
1
- import { TypeConfig } from '@opengov/form-utils';
2
- declare const dropdownConfiguration: TypeConfig;
3
- export default dropdownConfiguration;
@@ -1,3 +0,0 @@
1
- import { TypeConfig, NumberConfiguration } from '@opengov/form-utils';
2
- declare const numberConfiguration: TypeConfig<NumberConfiguration>;
3
- export default numberConfiguration;
@@ -1,5 +0,0 @@
1
- import { TextFieldProps } from '@mui/material';
2
- import { GeneralInputProps } from '../types';
3
- export default function NumberInput(props: Omit<GeneralInputProps & TextFieldProps, 'type'> & {
4
- readonly?: boolean;
5
- }): import("react/jsx-runtime").JSX.Element;
@@ -1,3 +0,0 @@
1
- import { TypeConfig, TextConfiguration } from '@opengov/form-utils';
2
- declare const textConfiguration: TypeConfig<TextConfiguration>;
3
- export default textConfiguration;
@@ -1,6 +0,0 @@
1
- import { TextFieldProps } from '@mui/material';
2
- import { GeneralInputProps } from '../types';
3
- declare function TextInput({ name, label, rules, sx, ...rest }: GeneralInputProps & TextFieldProps & {
4
- readonly?: boolean;
5
- }): import("react/jsx-runtime").JSX.Element;
6
- export default TextInput;