@rjsf/react-bootstrap 6.0.0-beta.20 → 6.0.0-beta.21

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.
Files changed (36) hide show
  1. package/dist/index.cjs +111 -43
  2. package/dist/index.cjs.map +4 -4
  3. package/dist/react-bootstrap.esm.js +107 -39
  4. package/dist/react-bootstrap.esm.js.map +4 -4
  5. package/dist/react-bootstrap.umd.js +70 -9
  6. package/lib/AddButton/AddButton.js +1 -1
  7. package/lib/AddButton/AddButton.js.map +1 -1
  8. package/lib/ArrayFieldTemplate/ArrayFieldTemplate.js +3 -3
  9. package/lib/ArrayFieldTemplate/ArrayFieldTemplate.js.map +1 -1
  10. package/lib/IconButton/IconButton.d.ts +6 -5
  11. package/lib/IconButton/IconButton.js +1 -1
  12. package/lib/IconButton/IconButton.js.map +1 -1
  13. package/lib/ObjectFieldTemplate/ObjectFieldTemplate.d.ts +1 -1
  14. package/lib/ObjectFieldTemplate/ObjectFieldTemplate.js +3 -2
  15. package/lib/ObjectFieldTemplate/ObjectFieldTemplate.js.map +1 -1
  16. package/lib/OptionalDataControlsTemplate/OptionalDataControlsTemplate.d.ts +10 -0
  17. package/lib/OptionalDataControlsTemplate/OptionalDataControlsTemplate.js +22 -0
  18. package/lib/OptionalDataControlsTemplate/OptionalDataControlsTemplate.js.map +1 -0
  19. package/lib/OptionalDataControlsTemplate/index.d.ts +2 -0
  20. package/lib/OptionalDataControlsTemplate/index.js +3 -0
  21. package/lib/OptionalDataControlsTemplate/index.js.map +1 -0
  22. package/lib/Templates/Templates.js +2 -0
  23. package/lib/Templates/Templates.js.map +1 -1
  24. package/lib/TitleField/TitleField.d.ts +1 -1
  25. package/lib/TitleField/TitleField.js +9 -2
  26. package/lib/TitleField/TitleField.js.map +1 -1
  27. package/lib/tsconfig.tsbuildinfo +1 -1
  28. package/package.json +7 -7
  29. package/src/AddButton/AddButton.tsx +1 -1
  30. package/src/ArrayFieldTemplate/ArrayFieldTemplate.tsx +20 -6
  31. package/src/IconButton/IconButton.tsx +12 -6
  32. package/src/ObjectFieldTemplate/ObjectFieldTemplate.tsx +4 -0
  33. package/src/OptionalDataControlsTemplate/OptionalDataControlsTemplate.tsx +47 -0
  34. package/src/OptionalDataControlsTemplate/index.ts +2 -0
  35. package/src/Templates/Templates.ts +2 -0
  36. package/src/TitleField/TitleField.tsx +19 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rjsf/react-bootstrap",
3
- "version": "6.0.0-beta.20",
3
+ "version": "6.0.0-beta.21",
4
4
  "main": "dist/index.js",
5
5
  "module": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -61,8 +61,8 @@
61
61
  ]
62
62
  },
63
63
  "peerDependencies": {
64
- "@rjsf/core": "^6.0.0-beta.20",
65
- "@rjsf/utils": "^6.0.0-beta.20",
64
+ "@rjsf/core": "^6.0.0-beta.21",
65
+ "@rjsf/utils": "^6.0.0-beta.21",
66
66
  "react": ">=18",
67
67
  "react-bootstrap": "^2.x"
68
68
  },
@@ -71,10 +71,10 @@
71
71
  "node": ">=20"
72
72
  },
73
73
  "devDependencies": {
74
- "@rjsf/core": "^6.0.0-beta.20",
75
- "@rjsf/snapshot-tests": "^6.0.0-beta.20",
76
- "@rjsf/utils": "^6.0.0-beta.20",
77
- "@rjsf/validator-ajv8": "^6.0.0-beta.20",
74
+ "@rjsf/core": "^6.0.0-beta.21",
75
+ "@rjsf/snapshot-tests": "^6.0.0-beta.21",
76
+ "@rjsf/utils": "^6.0.0-beta.21",
77
+ "@rjsf/validator-ajv8": "^6.0.0-beta.21",
78
78
  "eslint": "^8.57.1",
79
79
  "react-bootstrap": "^2.10.10"
80
80
  },
@@ -10,10 +10,10 @@ export default function AddButton<T = any, S extends StrictRJSFSchema = RJSFSche
10
10
  const { translateString } = registry;
11
11
  return (
12
12
  <Button
13
+ title={translateString(TranslatableString.AddItemButton)}
13
14
  {...props}
14
15
  style={{ width: '100%' }}
15
16
  className={`ml-1 ${props.className}`}
16
- title={translateString(TranslatableString.AddItemButton)}
17
17
  >
18
18
  <BsPlus />
19
19
  </Button>
@@ -17,8 +17,20 @@ export default function ArrayFieldTemplate<
17
17
  S extends StrictRJSFSchema = RJSFSchema,
18
18
  F extends FormContextType = any,
19
19
  >(props: ArrayFieldTemplateProps<T, S, F>) {
20
- const { canAdd, disabled, fieldPathId, uiSchema, items, onAddClick, readonly, registry, required, schema, title } =
21
- props;
20
+ const {
21
+ canAdd,
22
+ disabled,
23
+ fieldPathId,
24
+ uiSchema,
25
+ items,
26
+ optionalDataControl,
27
+ onAddClick,
28
+ readonly,
29
+ registry,
30
+ required,
31
+ schema,
32
+ title,
33
+ } = props;
22
34
  const uiOptions = getUiOptions<T, S, F>(uiSchema);
23
35
  const ArrayFieldDescriptionTemplate = getTemplate<'ArrayFieldDescriptionTemplate', T, S, F>(
24
36
  'ArrayFieldDescriptionTemplate',
@@ -35,6 +47,7 @@ export default function ArrayFieldTemplate<
35
47
  registry,
36
48
  uiOptions,
37
49
  );
50
+ const showOptionalDataControlInTitle = !readonly && !disabled;
38
51
  // Button templates are not overridden in the uiSchema
39
52
  const {
40
53
  ButtonTemplates: { AddButton },
@@ -50,6 +63,7 @@ export default function ArrayFieldTemplate<
50
63
  uiSchema={uiSchema}
51
64
  required={required}
52
65
  registry={registry}
66
+ optionalDataControl={showOptionalDataControlInTitle ? optionalDataControl : undefined}
53
67
  />
54
68
  <ArrayFieldDescriptionTemplate
55
69
  fieldPathId={fieldPathId}
@@ -59,10 +73,10 @@ export default function ArrayFieldTemplate<
59
73
  registry={registry}
60
74
  />
61
75
  <Container fluid key={`array-item-list-${fieldPathId.$id}`} className='p-0 m-0'>
62
- {items &&
63
- items.map(({ key, ...itemProps }: ArrayFieldItemTemplateType<T, S, F>) => (
64
- <ArrayFieldItemTemplate key={key} {...itemProps} />
65
- ))}
76
+ {!showOptionalDataControlInTitle ? optionalDataControl : undefined}
77
+ {items.map(({ key, ...itemProps }: ArrayFieldItemTemplateType<T, S, F>) => (
78
+ <ArrayFieldItemTemplate key={key} {...itemProps} />
79
+ ))}
66
80
  {canAdd && (
67
81
  <Container className=''>
68
82
  <Row className='mt-2'>
@@ -5,8 +5,14 @@ import { IoIosRemove } from '@react-icons/all-files/io/IoIosRemove';
5
5
  import { AiOutlineArrowUp } from '@react-icons/all-files/ai/AiOutlineArrowUp';
6
6
  import { AiOutlineArrowDown } from '@react-icons/all-files/ai/AiOutlineArrowDown';
7
7
 
8
+ export type BootstrapIconButtonProps<
9
+ T = any,
10
+ S extends StrictRJSFSchema = RJSFSchema,
11
+ F extends FormContextType = any,
12
+ > = IconButtonProps<T, S, F> & ButtonProps;
13
+
8
14
  export default function IconButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
9
- props: IconButtonProps<T, S, F> & ButtonProps,
15
+ props: BootstrapIconButtonProps<T, S, F>,
10
16
  ) {
11
17
  const { icon, iconType, className, uiSchema, registry, ...otherProps } = props;
12
18
  return (
@@ -17,7 +23,7 @@ export default function IconButton<T = any, S extends StrictRJSFSchema = RJSFSch
17
23
  }
18
24
 
19
25
  export function CopyButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
20
- props: IconButtonProps<T, S, F>,
26
+ props: BootstrapIconButtonProps<T, S, F>,
21
27
  ) {
22
28
  const {
23
29
  registry: { translateString },
@@ -26,7 +32,7 @@ export function CopyButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
26
32
  }
27
33
 
28
34
  export function MoveDownButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
29
- props: IconButtonProps<T, S, F>,
35
+ props: BootstrapIconButtonProps<T, S, F>,
30
36
  ) {
31
37
  const {
32
38
  registry: { translateString },
@@ -37,7 +43,7 @@ export function MoveDownButton<T = any, S extends StrictRJSFSchema = RJSFSchema,
37
43
  }
38
44
 
39
45
  export function MoveUpButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
40
- props: IconButtonProps<T, S, F>,
46
+ props: BootstrapIconButtonProps<T, S, F>,
41
47
  ) {
42
48
  const {
43
49
  registry: { translateString },
@@ -46,7 +52,7 @@ export function MoveUpButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F
46
52
  }
47
53
 
48
54
  export function RemoveButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
49
- props: IconButtonProps<T, S, F>,
55
+ props: BootstrapIconButtonProps<T, S, F>,
50
56
  ) {
51
57
  const {
52
58
  registry: { translateString },
@@ -54,8 +60,8 @@ export function RemoveButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F
54
60
  return (
55
61
  <IconButton
56
62
  title={translateString(TranslatableString.RemoveButton)}
57
- {...props}
58
63
  variant='danger'
64
+ {...props}
59
65
  icon={<IoIosRemove />}
60
66
  />
61
67
  );
@@ -28,6 +28,7 @@ export default function ObjectFieldTemplate<
28
28
  fieldPathId,
29
29
  schema,
30
30
  formData,
31
+ optionalDataControl,
31
32
  onAddClick,
32
33
  disabled,
33
34
  readonly,
@@ -40,6 +41,7 @@ export default function ObjectFieldTemplate<
40
41
  registry,
41
42
  uiOptions,
42
43
  );
44
+ const showOptionalDataControlInTitle = !readonly && !disabled;
43
45
  // Button templates are not overridden in the uiSchema
44
46
  const {
45
47
  ButtonTemplates: { AddButton },
@@ -54,6 +56,7 @@ export default function ObjectFieldTemplate<
54
56
  schema={schema}
55
57
  uiSchema={uiSchema}
56
58
  registry={registry}
59
+ optionalDataControl={showOptionalDataControlInTitle ? optionalDataControl : undefined}
57
60
  />
58
61
  )}
59
62
  {description && (
@@ -66,6 +69,7 @@ export default function ObjectFieldTemplate<
66
69
  />
67
70
  )}
68
71
  <Container fluid className='p-0'>
72
+ {!showOptionalDataControlInTitle ? optionalDataControl : undefined}
69
73
  {properties.map((element: any, index: number) => (
70
74
  <Row key={index} style={{ marginBottom: '10px' }} className={element.hidden ? 'd-none' : undefined}>
71
75
  <Col xs={12}> {element.content}</Col>
@@ -0,0 +1,47 @@
1
+ import { FormContextType, OptionalDataControlsTemplateProps, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
2
+ import { BsPlus } from '@react-icons/all-files/bs/BsPlus';
3
+
4
+ import IconButton, { RemoveButton } from '../IconButton';
5
+
6
+ /** The OptionalDataControlsTemplate renders one of three different states. If
7
+ * there is an `onAddClick()` function, it renders the "Add" button. If there is
8
+ * an `onRemoveClick()` function, it renders the "Remove" button. Otherwise it
9
+ * renders the "No data found" section. All of them use the `label` as either
10
+ * the `title` of buttons or simply outputting it.
11
+ *
12
+ * @param props - The `OptionalDataControlsTemplateProps` for the template
13
+ */
14
+ export default function OptionalDataControlsTemplate<
15
+ T = any,
16
+ S extends StrictRJSFSchema = RJSFSchema,
17
+ F extends FormContextType = any,
18
+ >(props: OptionalDataControlsTemplateProps<T, S, F>) {
19
+ const { id, registry, label, onAddClick, onRemoveClick } = props;
20
+ if (onAddClick) {
21
+ return (
22
+ <IconButton
23
+ id={id}
24
+ registry={registry}
25
+ className='rjsf-add-optional-data'
26
+ icon={<BsPlus />}
27
+ onClick={onAddClick}
28
+ title={label}
29
+ size='sm'
30
+ variant='secondary'
31
+ />
32
+ );
33
+ } else if (onRemoveClick) {
34
+ return (
35
+ <RemoveButton
36
+ id={id}
37
+ registry={registry}
38
+ className='rjsf-remove-optional-data'
39
+ onClick={onRemoveClick}
40
+ title={label}
41
+ size='sm'
42
+ variant='secondary'
43
+ />
44
+ );
45
+ }
46
+ return <em id={id}>{label}</em>;
47
+ }
@@ -0,0 +1,2 @@
1
+ export { default } from './OptionalDataControlsTemplate';
2
+ export * from './OptionalDataControlsTemplate';
@@ -11,6 +11,7 @@ import FieldTemplate from '../FieldTemplate';
11
11
  import GridTemplate from '../GridTemplate';
12
12
  import MultiSchemaFieldTemplate from '../MultiSchemaFieldTemplate';
13
13
  import ObjectFieldTemplate from '../ObjectFieldTemplate';
14
+ import OptionalDataControlsTemplate from '../OptionalDataControlsTemplate';
14
15
  import SubmitButton from '../SubmitButton';
15
16
  import TitleField from '../TitleField';
16
17
  import WrapIfAdditionalTemplate from '../WrapIfAdditionalTemplate';
@@ -41,6 +42,7 @@ export function generateTemplates<
41
42
  GridTemplate,
42
43
  MultiSchemaFieldTemplate,
43
44
  ObjectFieldTemplate,
45
+ OptionalDataControlsTemplate,
44
46
  TitleFieldTemplate: TitleField,
45
47
  WrapIfAdditionalTemplate,
46
48
  };
@@ -1,15 +1,32 @@
1
1
  import { FormContextType, getUiOptions, RJSFSchema, StrictRJSFSchema, TitleFieldProps } from '@rjsf/utils';
2
+ import Row from 'react-bootstrap/Row';
3
+ import Col from 'react-bootstrap/Col';
4
+ import Container from 'react-bootstrap/Container';
2
5
 
3
6
  export default function TitleField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({
4
7
  id,
5
8
  title,
6
9
  uiSchema,
10
+ optionalDataControl,
7
11
  }: TitleFieldProps<T, S, F>) {
8
12
  const uiOptions = getUiOptions<T, S, F>(uiSchema);
13
+ let heading = <h5>{uiOptions.title || title}</h5>;
14
+ if (optionalDataControl) {
15
+ heading = (
16
+ <Container fluid className='p-0'>
17
+ <Row>
18
+ <Col xs='11'>{heading}</Col>
19
+ <Col xs='1' style={{ marginLeft: '-5px' }}>
20
+ {optionalDataControl}
21
+ </Col>
22
+ </Row>
23
+ </Container>
24
+ );
25
+ }
9
26
  return (
10
27
  <div id={id} className='my-1'>
11
- <h5>{uiOptions.title || title}</h5>
12
- <hr className='border-0 bg-secondary' style={{ height: '1px' }} />
28
+ {heading}
29
+ <hr className='border-0 bg-secondary mt-0' style={{ height: '1px' }} />
13
30
  </div>
14
31
  );
15
32
  }