From 546aac97cf086a2fb216ca609e78a6540bdba37f Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Mon, 29 Jul 2024 21:23:01 +0300 Subject: [PATCH] update: add DescriptionFieldTemplate --- dist/other/rjsf/RJSForm.js | 2 ++ .../templates/DescriptionFieldTemplate.d.ts | 7 ++++++ .../templates/DescriptionFieldTemplate.js | 14 +++++++++++ src/other/rjsf/RJSForm.tsx | 2 ++ .../templates/DescriptionFieldTemplate.tsx | 25 +++++++++++++++++++ 5 files changed, 50 insertions(+) create mode 100644 dist/other/rjsf/templates/DescriptionFieldTemplate.d.ts create mode 100644 dist/other/rjsf/templates/DescriptionFieldTemplate.js create mode 100644 src/other/rjsf/templates/DescriptionFieldTemplate.tsx diff --git a/dist/other/rjsf/RJSForm.js b/dist/other/rjsf/RJSForm.js index a7cb143..433f6d7 100644 --- a/dist/other/rjsf/RJSForm.js +++ b/dist/other/rjsf/RJSForm.js @@ -3,6 +3,7 @@ import React from "react"; import ArrayFieldItemTemplate from "./templates/ArrayFieldItemTemplate"; import ArrayFieldTemplate from "./templates/ArrayFieldTemplate"; import BaseInputTemplate from "./templates/BaseInputTemplate"; +import DescriptionFieldTemplate from "./templates/DescriptionFieldTemplate"; import ObjectFieldTemplate from "./templates/ObjectFieldTemplate"; import TitleFieldTemplate from "./templates/TitleFieldTemplate"; import SelectWidget from "./widgets/SelectWidget"; @@ -13,6 +14,7 @@ export default function RJSForm({ widgets, templates, ...props }) { ArrayFieldTemplate, ArrayFieldItemTemplate, TitleFieldTemplate, + DescriptionFieldTemplate, ...templates, }, widgets: { SelectWidget, ...widgets } })); } diff --git a/dist/other/rjsf/templates/DescriptionFieldTemplate.d.ts b/dist/other/rjsf/templates/DescriptionFieldTemplate.d.ts new file mode 100644 index 0000000..c3de649 --- /dev/null +++ b/dist/other/rjsf/templates/DescriptionFieldTemplate.d.ts @@ -0,0 +1,7 @@ +import { DescriptionFieldProps, FormContextType, RJSFSchema, StrictRJSFSchema } from "@rjsf/utils"; +import React from "react"; +/** The `DescriptionField` is the template to use to render the description of a field + * + * @param props - The `DescriptionFieldProps` for this component + */ +export default function DescriptionFieldTemplate(props: DescriptionFieldProps): React.JSX.Element | null; diff --git a/dist/other/rjsf/templates/DescriptionFieldTemplate.js b/dist/other/rjsf/templates/DescriptionFieldTemplate.js new file mode 100644 index 0000000..2ef85e8 --- /dev/null +++ b/dist/other/rjsf/templates/DescriptionFieldTemplate.js @@ -0,0 +1,14 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +import Typography from "@mui/material/Typography"; +import React from "react"; +/** The `DescriptionField` is the template to use to render the description of a field + * + * @param props - The `DescriptionFieldProps` for this component + */ +export default function DescriptionFieldTemplate(props) { + const { id, description } = props; + if (description) { + return (React.createElement(Typography, { id: id, variant: "subtitle2", style: { marginTop: "5px" } }, description)); + } + return null; +} diff --git a/src/other/rjsf/RJSForm.tsx b/src/other/rjsf/RJSForm.tsx index d1a8031..07e44e6 100644 --- a/src/other/rjsf/RJSForm.tsx +++ b/src/other/rjsf/RJSForm.tsx @@ -8,6 +8,7 @@ import React from "react"; import ArrayFieldItemTemplate from "./templates/ArrayFieldItemTemplate"; import ArrayFieldTemplate from "./templates/ArrayFieldTemplate"; import BaseInputTemplate from "./templates/BaseInputTemplate"; +import DescriptionFieldTemplate from "./templates/DescriptionFieldTemplate"; import ObjectFieldTemplate from "./templates/ObjectFieldTemplate"; import TitleFieldTemplate from "./templates/TitleFieldTemplate"; import SelectWidget from "./widgets/SelectWidget"; @@ -22,6 +23,7 @@ export default function RJSForm({ widgets, templates, ...props }: FormProps(props: DescriptionFieldProps) { + const { id, description } = props; + if (description) { + return ( + + {description} + + ); + } + + return null; +}