@rjsf/core 6.0.0-beta.1 → 6.0.0-beta.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rjsf/core",
3
- "version": "6.0.0-beta.1",
3
+ "version": "6.0.0-beta.3",
4
4
  "description": "A simple React component capable of building HTML forms out of a JSON schema.",
5
5
  "scripts": {
6
6
  "compileReplacer": "tsc -p tsconfig.replacer.json && move-file lodashReplacer.js lodashReplacer.cjs",
@@ -66,7 +66,7 @@
66
66
  "node": ">=20"
67
67
  },
68
68
  "peerDependencies": {
69
- "@rjsf/utils": "^6.x",
69
+ "@rjsf/utils": "6",
70
70
  "react": ">=18"
71
71
  },
72
72
  "dependencies": {
@@ -77,9 +77,9 @@
77
77
  "prop-types": "^15.8.1"
78
78
  },
79
79
  "devDependencies": {
80
- "@rjsf/snapshot-tests": "^6.0.0-beta.1",
81
- "@rjsf/utils": "^6.0.0-beta.1",
82
- "@rjsf/validator-ajv8": "^6.0.0-beta.1",
80
+ "@rjsf/snapshot-tests": "^6.0.0-beta.3",
81
+ "@rjsf/utils": "^6.0.0-beta.3",
82
+ "@rjsf/validator-ajv8": "^6.0.0-beta.3",
83
83
  "@testing-library/jest-dom": "^6.6.3",
84
84
  "@testing-library/react": "^16.2.0",
85
85
  "@testing-library/user-event": "^14.6.1",
@@ -0,0 +1,50 @@
1
+ import { ReactElement } from 'react';
2
+ import {
3
+ FormContextType,
4
+ Registry,
5
+ RJSFSchema,
6
+ StrictRJSFSchema,
7
+ UiSchema,
8
+ getTestIds,
9
+ getUiOptions,
10
+ } from '@rjsf/utils';
11
+ import Markdown from 'markdown-to-jsx';
12
+
13
+ const TEST_IDS = getTestIds();
14
+
15
+ export interface RichDescriptionProps<
16
+ T = any,
17
+ S extends StrictRJSFSchema = RJSFSchema,
18
+ F extends FormContextType = any,
19
+ > {
20
+ /** The description text for a field, potentially containing markdown */
21
+ description: string | ReactElement;
22
+ /** The uiSchema object for this base component */
23
+ uiSchema?: UiSchema<T, S, F>;
24
+ /** The `registry` object */
25
+ registry: Registry<T, S, F>;
26
+ }
27
+
28
+ /** Renders the given `description` in the props as
29
+ *
30
+ * @param props - The `RichDescriptionProps` for this component
31
+ */
32
+ export default function RichDescription<
33
+ T = any,
34
+ S extends StrictRJSFSchema = RJSFSchema,
35
+ F extends FormContextType = any,
36
+ >({ description, registry, uiSchema = {} }: RichDescriptionProps<T, S, F>) {
37
+ const { globalUiOptions } = registry;
38
+ const uiOptions = getUiOptions<T, S, F>(uiSchema, globalUiOptions);
39
+
40
+ if (uiOptions.enableMarkdownInDescription && typeof description === 'string') {
41
+ return (
42
+ <Markdown options={{ disableParsingRawHTML: true }} data-testid={TEST_IDS.markdown}>
43
+ {description}
44
+ </Markdown>
45
+ );
46
+ }
47
+ return description;
48
+ }
49
+
50
+ RichDescription.TEST_IDS = TEST_IDS;
@@ -22,7 +22,6 @@ import {
22
22
  } from '@rjsf/utils';
23
23
  import isObject from 'lodash/isObject';
24
24
  import omit from 'lodash/omit';
25
- import Markdown from 'markdown-to-jsx';
26
25
 
27
26
  /** The map of component type to FieldName */
28
27
  const COMPONENT_TYPES: { [key: string]: string } = {
@@ -200,12 +199,6 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
200
199
  }
201
200
 
202
201
  const description = uiOptions.description || props.schema.description || schema.description || '';
203
-
204
- const richDescription = uiOptions.enableMarkdownInDescription ? (
205
- <Markdown options={{ disableParsingRawHTML: true }}>{description}</Markdown>
206
- ) : (
207
- description
208
- );
209
202
  const help = uiOptions.help;
210
203
  const hidden = uiOptions.widget === 'hidden';
211
204
 
@@ -246,7 +239,7 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
246
239
  description: (
247
240
  <DescriptionFieldTemplate
248
241
  id={descriptionId<T>(id)}
249
- description={richDescription}
242
+ description={description}
250
243
  schema={schema}
251
244
  uiSchema={uiSchema}
252
245
  registry={registry}
@@ -1,5 +1,7 @@
1
1
  import { DescriptionFieldProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
2
2
 
3
+ import RichDescription from '../RichDescription';
4
+
3
5
  /** The `DescriptionField` is the template to use to render the description of a field
4
6
  *
5
7
  * @param props - The `DescriptionFieldProps` for this component
@@ -9,21 +11,13 @@ export default function DescriptionField<
9
11
  S extends StrictRJSFSchema = RJSFSchema,
10
12
  F extends FormContextType = any,
11
13
  >(props: DescriptionFieldProps<T, S, F>) {
12
- const { id, description } = props;
14
+ const { id, description, registry, uiSchema } = props;
13
15
  if (!description) {
14
16
  return null;
15
17
  }
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
- }
18
+ return (
19
+ <div id={id} className='field-description'>
20
+ <RichDescription description={description} registry={registry} uiSchema={uiSchema} />
21
+ </div>
22
+ );
29
23
  }
@@ -60,7 +60,7 @@ function CheckboxWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F exte
60
60
 
61
61
  return (
62
62
  <div className={`checkbox ${disabled || readonly ? 'disabled' : ''}`}>
63
- {!hideLabel && !!description && (
63
+ {!hideLabel && description && (
64
64
  <DescriptionFieldTemplate
65
65
  id={descriptionId<T>(id)}
66
66
  description={description}
package/src/index.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import Form, { FormProps, FormState, IChangeEvent } from './components/Form';
2
+ import RichDescription, { RichDescriptionProps } from './components/RichDescription';
2
3
  import withTheme, { ThemeProps } from './withTheme';
3
4
  import getDefaultRegistry from './getDefaultRegistry';
4
5
 
5
- export type { FormProps, FormState, IChangeEvent, ThemeProps };
6
+ export type { FormProps, FormState, IChangeEvent, ThemeProps, RichDescriptionProps };
6
7
 
7
- export { withTheme, getDefaultRegistry };
8
+ export { withTheme, getDefaultRegistry, RichDescription };
8
9
  export default Form;