@nolwenture/formik-jsonschema-form 1.0.6 → 1.0.7
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/cjs/Form/Form.js +3 -1
- package/dist/cjs/Form/FormRegistry.js +1 -0
- package/dist/cjs/Form/components/FieldInfo.js +10 -3
- package/dist/cjs/FormView/FormView.js +3 -1
- package/dist/cjs/FormView/FormViewRegistry.js +2 -0
- package/dist/esm/Form/Form.js +3 -1
- package/dist/esm/Form/FormRegistry.js +1 -0
- package/dist/esm/Form/components/FieldInfo.js +11 -4
- package/dist/esm/FormView/FormView.js +3 -1
- package/dist/esm/FormView/FormViewRegistry.js +2 -0
- package/dist/types/Form/types/FormRegistryContext.d.ts +1 -0
- package/dist/types/FormView/types/FormViewRegistryContext.d.ts +2 -0
- package/dist/types/common/types/FieldInfo.d.ts +2 -1
- package/dist/types/common/types/Form.d.ts +2 -0
- package/dist/types/common/types/Schemas.d.ts +2 -1
- package/dist/types/utils/getTitleAndDescription.d.ts +1 -1
- package/package.json +1 -1
package/dist/cjs/Form/Form.js
CHANGED
|
@@ -9,7 +9,7 @@ const fields_1 = require("./fields");
|
|
|
9
9
|
const templates_1 = require("./templates");
|
|
10
10
|
const Form = (props) => {
|
|
11
11
|
const { isSubmitting } = (0, formik_1.useFormikContext)();
|
|
12
|
-
const { schema, uiSchema = {}, className, children, fields = {}, templates = {}, components = {}, formContext = {}, useItemsAsAdditionalItems = false, hideUnmarkedAdditionalProperties = false, hideSubmit = false, } = props;
|
|
12
|
+
const { schema, uiSchema = {}, className, children, fields = {}, templates = {}, components = {}, formContext = {}, formOptions = {}, formLocalization = {}, useItemsAsAdditionalItems = false, hideUnmarkedAdditionalProperties = false, hideSubmit = false, } = props;
|
|
13
13
|
const schemaDefinitions = schema.definitions;
|
|
14
14
|
const uiSchemaDefinitions = uiSchema?.definitions;
|
|
15
15
|
const registry = {
|
|
@@ -25,6 +25,8 @@ const Form = (props) => {
|
|
|
25
25
|
definitions: schemaDefinitions,
|
|
26
26
|
uiSchemaDefinitions,
|
|
27
27
|
formContext,
|
|
28
|
+
formOptions,
|
|
29
|
+
formLocalization,
|
|
28
30
|
useItemsAsAdditionalItems,
|
|
29
31
|
hideUnmarkedAdditionalProperties,
|
|
30
32
|
};
|
|
@@ -5,6 +5,7 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const styled_components_1 = require("styled-components");
|
|
7
7
|
const polished_1 = require("polished");
|
|
8
|
+
const FormRegistry_1 = require("../FormRegistry");
|
|
8
9
|
exports.FieldInfoBoxElement = styled_components_1.styled.div `
|
|
9
10
|
font-family: ${(props) => props.theme.typography.fontFamily.base};
|
|
10
11
|
font-size: ${(props) => props.theme.typography.size.small};
|
|
@@ -119,15 +120,21 @@ exports.InlineFieldInfoWrapper = styled_components_1.styled.div `
|
|
|
119
120
|
margin: ${(props) => `${props.theme.spacing.m} 0`};
|
|
120
121
|
width: 100%;
|
|
121
122
|
`;
|
|
122
|
-
const FieldInfo = ({ label, content, position, display
|
|
123
|
+
const FieldInfo = ({ label, content, position, display: displayProp, className, }) => {
|
|
124
|
+
const { formOptions } = (0, react_1.useContext)(FormRegistry_1.FormRegistry);
|
|
123
125
|
const [isInlineVisible, setIsInlineVisible] = (0, react_1.useState)(false);
|
|
126
|
+
const config = {
|
|
127
|
+
display: "tooltip",
|
|
128
|
+
...(formOptions?.components?.FieldInfo ?? {}),
|
|
129
|
+
...(displayProp && { display: displayProp }),
|
|
130
|
+
};
|
|
124
131
|
const handleToggle = (e) => {
|
|
125
132
|
e.preventDefault();
|
|
126
|
-
if (display === "inline") {
|
|
133
|
+
if (config.display === "inline") {
|
|
127
134
|
setIsInlineVisible((prev) => !prev);
|
|
128
135
|
}
|
|
129
136
|
};
|
|
130
|
-
if (display === "inline") {
|
|
137
|
+
if (config.display === "inline") {
|
|
131
138
|
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(exports.FieldInfoContainer, { href: "#", onClick: handleToggle, className: className, children: (0, jsx_runtime_1.jsx)(exports.FieldInfoLabel, { children: label ?? "i" }) }), isInlineVisible && ((0, jsx_runtime_1.jsx)(exports.InlineFieldInfoWrapper, { children: (0, jsx_runtime_1.jsx)(exports.InlineFieldInfoBoxInnerElement, { children: content }) }))] }));
|
|
132
139
|
}
|
|
133
140
|
else {
|
|
@@ -15,7 +15,7 @@ exports.FormWrapper = styled_components_1.default.div `
|
|
|
15
15
|
//padding: ${(props) => props.theme.spacing.xxxxxl};
|
|
16
16
|
`;
|
|
17
17
|
const FormView = (props) => {
|
|
18
|
-
const { schema, uiSchema = {}, className, fields = {}, templates = {}, components = {}, formContext = {}, useItemsAsAdditionalItems = false, hideUnmarkedAdditionalProperties = false, } = props;
|
|
18
|
+
const { schema, uiSchema = {}, className, fields = {}, templates = {}, components = {}, formContext = {}, formOptions = {}, formLocalization = {}, useItemsAsAdditionalItems = false, hideUnmarkedAdditionalProperties = false, } = props;
|
|
19
19
|
const schemaDefinitions = schema.definitions;
|
|
20
20
|
const uiSchemaDefinitions = uiSchema.definitions;
|
|
21
21
|
const registry = {
|
|
@@ -25,6 +25,8 @@ const FormView = (props) => {
|
|
|
25
25
|
definitions: schemaDefinitions,
|
|
26
26
|
uiSchemaDefinitions,
|
|
27
27
|
formContext,
|
|
28
|
+
formOptions,
|
|
29
|
+
formLocalization,
|
|
28
30
|
useItemsAsAdditionalItems,
|
|
29
31
|
hideUnmarkedAdditionalProperties,
|
|
30
32
|
};
|
package/dist/esm/Form/Form.js
CHANGED
|
@@ -6,7 +6,7 @@ import { fields as defaultFields } from "./fields";
|
|
|
6
6
|
import { templates as defaultTemplates } from "./templates";
|
|
7
7
|
export const Form = (props) => {
|
|
8
8
|
const { isSubmitting } = useFormikContext();
|
|
9
|
-
const { schema, uiSchema = {}, className, children, fields = {}, templates = {}, components = {}, formContext = {}, useItemsAsAdditionalItems = false, hideUnmarkedAdditionalProperties = false, hideSubmit = false, } = props;
|
|
9
|
+
const { schema, uiSchema = {}, className, children, fields = {}, templates = {}, components = {}, formContext = {}, formOptions = {}, formLocalization = {}, useItemsAsAdditionalItems = false, hideUnmarkedAdditionalProperties = false, hideSubmit = false, } = props;
|
|
10
10
|
const schemaDefinitions = schema.definitions;
|
|
11
11
|
const uiSchemaDefinitions = uiSchema?.definitions;
|
|
12
12
|
const registry = {
|
|
@@ -22,6 +22,8 @@ export const Form = (props) => {
|
|
|
22
22
|
definitions: schemaDefinitions,
|
|
23
23
|
uiSchemaDefinitions,
|
|
24
24
|
formContext,
|
|
25
|
+
formOptions,
|
|
26
|
+
formLocalization,
|
|
25
27
|
useItemsAsAdditionalItems,
|
|
26
28
|
hideUnmarkedAdditionalProperties,
|
|
27
29
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useState } from "react";
|
|
2
|
+
import { useContext, useState } from "react";
|
|
3
3
|
import { styled } from "styled-components";
|
|
4
4
|
import { readableColor } from "polished";
|
|
5
|
+
import { FormRegistry } from "../FormRegistry";
|
|
5
6
|
export const FieldInfoBoxElement = styled.div `
|
|
6
7
|
font-family: ${(props) => props.theme.typography.fontFamily.base};
|
|
7
8
|
font-size: ${(props) => props.theme.typography.size.small};
|
|
@@ -116,15 +117,21 @@ export const InlineFieldInfoWrapper = styled.div `
|
|
|
116
117
|
margin: ${(props) => `${props.theme.spacing.m} 0`};
|
|
117
118
|
width: 100%;
|
|
118
119
|
`;
|
|
119
|
-
export const FieldInfo = ({ label, content, position, display
|
|
120
|
+
export const FieldInfo = ({ label, content, position, display: displayProp, className, }) => {
|
|
121
|
+
const { formOptions } = useContext(FormRegistry);
|
|
120
122
|
const [isInlineVisible, setIsInlineVisible] = useState(false);
|
|
123
|
+
const config = {
|
|
124
|
+
display: "tooltip",
|
|
125
|
+
...(formOptions?.components?.FieldInfo ?? {}),
|
|
126
|
+
...(displayProp && { display: displayProp }),
|
|
127
|
+
};
|
|
121
128
|
const handleToggle = (e) => {
|
|
122
129
|
e.preventDefault();
|
|
123
|
-
if (display === "inline") {
|
|
130
|
+
if (config.display === "inline") {
|
|
124
131
|
setIsInlineVisible((prev) => !prev);
|
|
125
132
|
}
|
|
126
133
|
};
|
|
127
|
-
if (display === "inline") {
|
|
134
|
+
if (config.display === "inline") {
|
|
128
135
|
return (_jsxs(_Fragment, { children: [_jsx(FieldInfoContainer, { href: "#", onClick: handleToggle, className: className, children: _jsx(FieldInfoLabel, { children: label ?? "i" }) }), isInlineVisible && (_jsx(InlineFieldInfoWrapper, { children: _jsx(InlineFieldInfoBoxInnerElement, { children: content }) }))] }));
|
|
129
136
|
}
|
|
130
137
|
else {
|
|
@@ -9,7 +9,7 @@ export const FormWrapper = styled.div `
|
|
|
9
9
|
//padding: ${(props) => props.theme.spacing.xxxxxl};
|
|
10
10
|
`;
|
|
11
11
|
export const FormView = (props) => {
|
|
12
|
-
const { schema, uiSchema = {}, className, fields = {}, templates = {}, components = {}, formContext = {}, useItemsAsAdditionalItems = false, hideUnmarkedAdditionalProperties = false, } = props;
|
|
12
|
+
const { schema, uiSchema = {}, className, fields = {}, templates = {}, components = {}, formContext = {}, formOptions = {}, formLocalization = {}, useItemsAsAdditionalItems = false, hideUnmarkedAdditionalProperties = false, } = props;
|
|
13
13
|
const schemaDefinitions = schema.definitions;
|
|
14
14
|
const uiSchemaDefinitions = uiSchema.definitions;
|
|
15
15
|
const registry = {
|
|
@@ -19,6 +19,8 @@ export const FormView = (props) => {
|
|
|
19
19
|
definitions: schemaDefinitions,
|
|
20
20
|
uiSchemaDefinitions,
|
|
21
21
|
formContext,
|
|
22
|
+
formOptions,
|
|
23
|
+
formLocalization,
|
|
22
24
|
useItemsAsAdditionalItems,
|
|
23
25
|
hideUnmarkedAdditionalProperties,
|
|
24
26
|
};
|
|
@@ -16,6 +16,7 @@ export type FormRegistryContext = {
|
|
|
16
16
|
} | undefined;
|
|
17
17
|
formContext: Record<string, any>;
|
|
18
18
|
formLocalization?: Record<string, any>;
|
|
19
|
+
formOptions?: Record<string, any>;
|
|
19
20
|
useItemsAsAdditionalItems: boolean;
|
|
20
21
|
hideUnmarkedAdditionalProperties: boolean;
|
|
21
22
|
};
|
|
@@ -14,6 +14,8 @@ export type FormViewRegistryContext = {
|
|
|
14
14
|
[key: string]: UiSchema;
|
|
15
15
|
} | undefined;
|
|
16
16
|
formContext: Record<string, any>;
|
|
17
|
+
formLocalization?: Record<string, any>;
|
|
18
|
+
formOptions?: Record<string, any>;
|
|
17
19
|
useItemsAsAdditionalItems: boolean;
|
|
18
20
|
hideUnmarkedAdditionalProperties: boolean;
|
|
19
21
|
};
|
|
@@ -4,9 +4,10 @@ export interface FieldInfoBoxElementProps {
|
|
|
4
4
|
}
|
|
5
5
|
export type FieldInfoProps = {
|
|
6
6
|
label?: React.ReactNode;
|
|
7
|
-
content
|
|
7
|
+
content?: React.ReactNode;
|
|
8
8
|
position?: "top" | "right" | "bottom" | "left";
|
|
9
9
|
className?: string;
|
|
10
10
|
props?: any;
|
|
11
11
|
display?: "tooltip" | "inline";
|
|
12
|
+
formOptions?: Record<string, any>;
|
|
12
13
|
};
|
|
@@ -15,6 +15,8 @@ export type FormProps<T> = React.PropsWithChildren<{
|
|
|
15
15
|
uiSchema?: UiSchema | undefined;
|
|
16
16
|
/** Data that is passed down to all fields. Used for implementing context aware fields */
|
|
17
17
|
formContext?: Record<string, any>;
|
|
18
|
+
formOptions?: Record<string, any>;
|
|
19
|
+
formLocalization?: Record<string, any>;
|
|
18
20
|
/** Dictionary of registered fields */
|
|
19
21
|
fields?: Partial<FieldsType>;
|
|
20
22
|
templates?: Partial<TemplatesType>;
|
|
@@ -18,7 +18,8 @@ export type UiSchema = {
|
|
|
18
18
|
"ui:field"?: Field | string;
|
|
19
19
|
"ui:template"?: string;
|
|
20
20
|
"ui:options"?: {
|
|
21
|
-
|
|
21
|
+
info?: Partial<FieldInfoProps>;
|
|
22
|
+
[key: string]: any;
|
|
22
23
|
};
|
|
23
24
|
"ui:props"?: {
|
|
24
25
|
[key: string]: any;
|