-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Markdown in descriptions #4405
base: main
Are you sure you want to change the base?
Markdown in descriptions #4405
Changes from 6 commits
e195be6
bc3acf3
234a0f0
a7529dc
de02a01
f2f0616
b9bddd8
5c00058
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,9 @@ import { | |
RJSFSchema, | ||
StrictRJSFSchema, | ||
WidgetProps, | ||
getUiOptions, | ||
} from '@rjsf/utils'; | ||
import Markdown from 'markdown-to-jsx'; | ||
|
||
/** The `CheckBoxWidget` is a widget for rendering boolean properties. | ||
* It is typically used to represent a boolean. | ||
|
@@ -32,6 +34,9 @@ function CheckboxWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F exte | |
onChange, | ||
registry, | ||
}: WidgetProps<T, S, F>) { | ||
const { globalUiOptions } = registry; | ||
const uiOptions = getUiOptions<T, S, F>(uiSchema, globalUiOptions); | ||
|
||
const DescriptionFieldTemplate = getTemplate<'DescriptionFieldTemplate', T, S, F>( | ||
'DescriptionFieldTemplate', | ||
registry, | ||
|
@@ -58,12 +63,18 @@ function CheckboxWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F exte | |
); | ||
const description = options.description ?? schema.description; | ||
|
||
const richDescription = uiOptions.enableMarkdownInDescription ? ( | ||
<Markdown options={{ disableParsingRawHTML: true }}>{description || ''}</Markdown> | ||
) : ( | ||
description || '' | ||
); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dejanbelusic after looking around it turns out that every theme's export interface RichDescriptionProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> {
/** The description of the field being rendered */
description: ReactNode;
/** The uiSchema that was passed to field */
uiSchema?: UiSchema<T, S, F>;
/** The `registry` object */
registry: Registry<T, S, F>;
}
export default function RichDescription<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({ description, registry, uiSchema = {}}: RichDescriptionProps<T,S,F>) {
const { globalUiOptions } = registry;
const uiOptions = getUiOptions<T, S, F>(uiSchema, globalUiOptions);
if (uiOptions.enableMarkdownInDescription) {
return <Markdown options={{ disableParsingRawHTML: true }}>{description || ''}</Markdown>
}
return description;
} With all the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @heath-freenome, I see your point and I agree. I can create a new component When looking into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dejanbelusic I would leave the different implementations of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @heath-freenome, I commited the changes, please take a look if I understood you correctly. Also, was looking into updating the tests, but I'm getting some errors, can you give me some pointers on how to troubleshoot them? |
||
return ( | ||
<div className={`checkbox ${disabled || readonly ? 'disabled' : ''}`}> | ||
{!hideLabel && !!description && ( | ||
<DescriptionFieldTemplate | ||
id={descriptionId<T>(id)} | ||
description={description} | ||
description={richDescription} | ||
schema={schema} | ||
uiSchema={uiSchema} | ||
registry={registry} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The package change is so small as to not require mentioning. What does want to be mentioned is that it is a new feature so requires
5.25.0
AND you want to mention the changes in each package.