Skip to content

Commit 5c00058

Browse files
committed
Use the same 'RichDescription' component with all related fields and themes
1 parent b9bddd8 commit 5c00058

File tree

16 files changed

+102
-95
lines changed

16 files changed

+102
-95
lines changed
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DescriptionFieldProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
1+
import { DescriptionFieldProps, FormContextType, RichDescription, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
22

33
/** The `DescriptionField` is the template to use to render the description of a field
44
*
@@ -9,9 +9,13 @@ export default function DescriptionField<
99
S extends StrictRJSFSchema = RJSFSchema,
1010
F extends FormContextType = any
1111
>(props: DescriptionFieldProps<T, S, F>) {
12-
const { id, description } = props;
12+
const { id, description, registry, uiSchema } = props;
1313
if (!description) {
1414
return null;
1515
}
16-
return <span id={id}>{description}</span>;
16+
return (
17+
<span id={id}>
18+
<RichDescription description={description} registry={registry} uiSchema={uiSchema} />
19+
</span>
20+
);
1721
}
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import { DescriptionFieldProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
1+
import { DescriptionFieldProps, FormContextType, RichDescription, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
22

33
export default function DescriptionField<
44
T = any,
55
S extends StrictRJSFSchema = RJSFSchema,
66
F extends FormContextType = any
7-
>({ id, description }: DescriptionFieldProps<T, S, F>) {
8-
if (description) {
9-
return (
10-
<div>
11-
<div id={id} className='mb-3'>
12-
{description}
13-
</div>
14-
</div>
15-
);
7+
>({ id, description, registry, uiSchema }: DescriptionFieldProps<T, S, F>) {
8+
if (!description) {
9+
return null;
1610
}
1711

18-
return null;
12+
return (
13+
<div>
14+
<div id={id} className='mb-3'>
15+
<RichDescription description={description} registry={registry} uiSchema={uiSchema} />
16+
</div>
17+
</div>
18+
);
1919
}
Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
1-
import { DescriptionFieldProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
1+
import { DescriptionFieldProps, FormContextType, RichDescription, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
22
import { Text } from '@chakra-ui/react';
33

44
export default function DescriptionField<
55
T = any,
66
S extends StrictRJSFSchema = RJSFSchema,
77
F extends FormContextType = any
8-
>({ description, id }: DescriptionFieldProps<T, S, F>) {
8+
>({ id, description, registry, uiSchema }: DescriptionFieldProps<T, S, F>) {
99
if (!description) {
1010
return null;
1111
}
1212

13-
if (typeof description === 'string') {
14-
return (
15-
<Text as='sup' fontSize='md' id={id}>
16-
{description}
17-
</Text>
18-
);
19-
}
20-
21-
return <>{description}</>;
13+
return (
14+
<Text as='sup' fontSize='md' id={id}>
15+
<RichDescription description={description} registry={registry} uiSchema={uiSchema} />
16+
</Text>
17+
);
2218
}

packages/core/src/components/fields/ObjectField.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,6 @@ class ObjectField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
259259

260260
const templateTitle = uiOptions.title ?? schema.title ?? title ?? name;
261261
const description = uiOptions.description ?? schema.description;
262-
const richDescription = uiOptions.enableMarkdownInDescription ? (
263-
<Markdown options={{ disableParsingRawHTML: true }}>{description || ''}</Markdown>
264-
) : (
265-
description
266-
);
267262
let orderedProperties: string[];
268263
try {
269264
const properties = Object.keys(schemaProperties);
@@ -286,7 +281,7 @@ class ObjectField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
286281
const templateProps = {
287282
// getDisplayLabel() always returns false for object types, so just check the `uiOptions.label`
288283
title: uiOptions.label === false ? '' : templateTitle,
289-
description: uiOptions.label === false ? undefined : richDescription,
284+
description: uiOptions.label === false ? undefined : description,
290285
properties: orderedProperties.map((name) => {
291286
const addedByAdditionalProperties = has(schema, [PROPERTIES_KEY, name, ADDITIONAL_PROPERTY_FLAG]);
292287
const fieldUiSchema = addedByAdditionalProperties ? uiSchema.additionalProperties : uiSchema[name];

packages/core/src/components/fields/SchemaField.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import {
2222
} from '@rjsf/utils';
2323
import isObject from 'lodash/isObject';
2424
import omit from 'lodash/omit';
25-
import Markdown from 'markdown-to-jsx';
2625

2726
/** The map of component type to FieldName */
2827
const COMPONENT_TYPES: { [key: string]: string } = {
@@ -201,11 +200,6 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
201200

202201
const description = uiOptions.description || props.schema.description || schema.description || '';
203202

204-
const richDescription = uiOptions.enableMarkdownInDescription ? (
205-
<Markdown options={{ disableParsingRawHTML: true }}>{description}</Markdown>
206-
) : (
207-
description
208-
);
209203
const help = uiOptions.help;
210204
const hidden = uiOptions.widget === 'hidden';
211205

@@ -254,7 +248,7 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
254248
description: (
255249
<DescriptionFieldTemplate
256250
id={descriptionId<T>(id)}
257-
description={richDescription}
251+
description={description}
258252
schema={schema}
259253
uiSchema={uiSchema}
260254
registry={registry}
Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DescriptionFieldProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
1+
import { DescriptionFieldProps, FormContextType, RichDescription, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
22

33
/** The `DescriptionField` is the template to use to render the description of a field
44
*
@@ -9,21 +9,13 @@ export default function DescriptionField<
99
S extends StrictRJSFSchema = RJSFSchema,
1010
F extends FormContextType = any
1111
>(props: DescriptionFieldProps<T, S, F>) {
12-
const { id, description } = props;
12+
const { id, description, registry, uiSchema } = props;
1313
if (!description) {
1414
return null;
1515
}
16-
if (typeof description === 'string') {
17-
return (
18-
<p id={id} className='field-description'>
19-
{description}
20-
</p>
21-
);
22-
} else {
23-
return (
24-
<div id={id} className='field-description'>
25-
{description}
26-
</div>
27-
);
28-
}
16+
return (
17+
<div id={id} className='field-description'>
18+
<RichDescription description={description} registry={registry} uiSchema={uiSchema} />
19+
</div>
20+
);
2921
}

packages/core/src/components/widgets/CheckboxWidget.tsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ import {
99
RJSFSchema,
1010
StrictRJSFSchema,
1111
WidgetProps,
12-
getUiOptions,
1312
} from '@rjsf/utils';
14-
import Markdown from 'markdown-to-jsx';
1513

1614
/** The `CheckBoxWidget` is a widget for rendering boolean properties.
1715
* It is typically used to represent a boolean.
@@ -34,9 +32,6 @@ function CheckboxWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F exte
3432
onChange,
3533
registry,
3634
}: WidgetProps<T, S, F>) {
37-
const { globalUiOptions } = registry;
38-
const uiOptions = getUiOptions<T, S, F>(uiSchema, globalUiOptions);
39-
4035
const DescriptionFieldTemplate = getTemplate<'DescriptionFieldTemplate', T, S, F>(
4136
'DescriptionFieldTemplate',
4237
registry,
@@ -63,18 +58,12 @@ function CheckboxWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F exte
6358
);
6459
const description = options.description ?? schema.description;
6560

66-
const richDescription = uiOptions.enableMarkdownInDescription ? (
67-
<Markdown options={{ disableParsingRawHTML: true }}>{description || ''}</Markdown>
68-
) : (
69-
description || ''
70-
);
71-
7261
return (
7362
<div className={`checkbox ${disabled || readonly ? 'disabled' : ''}`}>
7463
{!hideLabel && !!description && (
7564
<DescriptionFieldTemplate
7665
id={descriptionId<T>(id)}
77-
description={richDescription}
66+
description={description}
7867
schema={schema}
7968
uiSchema={uiSchema}
8069
registry={registry}
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
import { DescriptionFieldProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
1+
import { DescriptionFieldProps, FormContextType, RichDescription, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
22
import { Text } from '@fluentui/react';
33

44
export default function DescriptionField<
55
T = any,
66
S extends StrictRJSFSchema = RJSFSchema,
77
F extends FormContextType = any
8-
>({ description, id }: DescriptionFieldProps<T, S, F>) {
9-
if (description) {
10-
return <Text id={id}>{description}</Text>;
8+
>({ id, description, registry, uiSchema }: DescriptionFieldProps<T, S, F>) {
9+
if (!description) {
10+
return null;
1111
}
1212

13-
return null;
13+
return (
14+
<Text id={id}>
15+
<RichDescription description={description} registry={registry} uiSchema={uiSchema} />
16+
</Text>
17+
);
1418
}

packages/fluentui-rc/src/DescriptionField/DescriptionField.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Text, makeStyles, tokens } from '@fluentui/react-components';
2-
import { DescriptionFieldProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
2+
import { DescriptionFieldProps, FormContextType, RichDescription, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
33

44
const useStyles = makeStyles({
55
label: {
@@ -17,15 +17,15 @@ export default function DescriptionField<
1717
S extends StrictRJSFSchema = RJSFSchema,
1818
F extends FormContextType = any
1919
>(props: DescriptionFieldProps<T, S, F>) {
20-
const { id, description } = props;
20+
const { id, description, registry, uiSchema } = props;
2121
const classes = useStyles();
22-
if (description) {
23-
return (
24-
<Text block id={id} className={classes.label}>
25-
{description}
26-
</Text>
27-
);
22+
if (!description) {
23+
return null;
2824
}
2925

30-
return null;
26+
return (
27+
<Text block id={id} className={classes.label}>
28+
<RichDescription description={description} registry={registry} uiSchema={uiSchema} />
29+
</Text>
30+
);
3131
}

packages/material-ui/src/DescriptionField/DescriptionField.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Typography from '@material-ui/core/Typography';
2-
import { DescriptionFieldProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
2+
import { DescriptionFieldProps, FormContextType, RichDescription, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
33

44
/** The `DescriptionField` is the template to use to render the description of a field
55
*
@@ -10,11 +10,11 @@ export default function DescriptionField<
1010
S extends StrictRJSFSchema = RJSFSchema,
1111
F extends FormContextType = any
1212
>(props: DescriptionFieldProps<T, S, F>) {
13-
const { id, description } = props;
13+
const { id, description, registry, uiSchema } = props;
1414
if (description) {
1515
return (
1616
<Typography id={id} variant='subtitle2' style={{ marginTop: '5px' }}>
17-
{description}
17+
<RichDescription description={description} registry={registry} uiSchema={uiSchema} />
1818
</Typography>
1919
);
2020
}

0 commit comments

Comments
 (0)