Skip to content

Commit

Permalink
update: add DescriptionFieldTemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
k0stik committed Jul 29, 2024
1 parent aee5d2d commit 546aac9
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 0 deletions.
2 changes: 2 additions & 0 deletions dist/other/rjsf/RJSForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -13,6 +14,7 @@ export default function RJSForm({ widgets, templates, ...props }) {
ArrayFieldTemplate,
ArrayFieldItemTemplate,
TitleFieldTemplate,
DescriptionFieldTemplate,
...templates,
}, widgets: { SelectWidget, ...widgets } }));
}
7 changes: 7 additions & 0 deletions dist/other/rjsf/templates/DescriptionFieldTemplate.d.ts
Original file line number Diff line number Diff line change
@@ -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<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(props: DescriptionFieldProps<T, S, F>): React.JSX.Element | null;
14 changes: 14 additions & 0 deletions dist/other/rjsf/templates/DescriptionFieldTemplate.js
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 2 additions & 0 deletions src/other/rjsf/RJSForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -22,6 +23,7 @@ export default function RJSForm({ widgets, templates, ...props }: FormProps<any,
ArrayFieldTemplate,
ArrayFieldItemTemplate,
TitleFieldTemplate,
DescriptionFieldTemplate,
...templates,
}}
widgets={{ SelectWidget, ...widgets }}
Expand Down
25 changes: 25 additions & 0 deletions src/other/rjsf/templates/DescriptionFieldTemplate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import Typography from "@mui/material/Typography";
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<
T = any,
S extends StrictRJSFSchema = RJSFSchema,
F extends FormContextType = any,
>(props: DescriptionFieldProps<T, S, F>) {
const { id, description } = props;
if (description) {
return (
<Typography id={id} variant="subtitle2" style={{ marginTop: "5px" }}>
{description}
</Typography>
);
}

return null;
}

0 comments on commit 546aac9

Please sign in to comment.