@rjsf/react-bootstrap 6.0.0-alpha.0

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 (206) hide show
  1. package/LICENSE.md +201 -0
  2. package/README.md +111 -0
  3. package/dist/index.js +940 -0
  4. package/dist/index.js.map +7 -0
  5. package/dist/react-bootstrap.esm.js +948 -0
  6. package/dist/react-bootstrap.esm.js.map +7 -0
  7. package/dist/react-bootstrap.umd.js +804 -0
  8. package/lib/AddButton/AddButton.d.ts +2 -0
  9. package/lib/AddButton/AddButton.js +9 -0
  10. package/lib/AddButton/AddButton.js.map +1 -0
  11. package/lib/AddButton/index.d.ts +2 -0
  12. package/lib/AddButton/index.js +3 -0
  13. package/lib/AddButton/index.js.map +1 -0
  14. package/lib/ArrayFieldItemTemplate/ArrayFieldItemTemplate.d.ts +2 -0
  15. package/lib/ArrayFieldItemTemplate/ArrayFieldItemTemplate.js +15 -0
  16. package/lib/ArrayFieldItemTemplate/ArrayFieldItemTemplate.js.map +1 -0
  17. package/lib/ArrayFieldItemTemplate/index.d.ts +2 -0
  18. package/lib/ArrayFieldItemTemplate/index.js +3 -0
  19. package/lib/ArrayFieldItemTemplate/index.js.map +1 -0
  20. package/lib/ArrayFieldTemplate/ArrayFieldTemplate.d.ts +2 -0
  21. package/lib/ArrayFieldTemplate/ArrayFieldTemplate.js +17 -0
  22. package/lib/ArrayFieldTemplate/ArrayFieldTemplate.js.map +1 -0
  23. package/lib/ArrayFieldTemplate/index.d.ts +2 -0
  24. package/lib/ArrayFieldTemplate/index.js +3 -0
  25. package/lib/ArrayFieldTemplate/index.js.map +1 -0
  26. package/lib/BaseInputTemplate/BaseInputTemplate.d.ts +2 -0
  27. package/lib/BaseInputTemplate/BaseInputTemplate.js +19 -0
  28. package/lib/BaseInputTemplate/BaseInputTemplate.js.map +1 -0
  29. package/lib/BaseInputTemplate/index.d.ts +2 -0
  30. package/lib/BaseInputTemplate/index.js +3 -0
  31. package/lib/BaseInputTemplate/index.js.map +1 -0
  32. package/lib/CheckboxWidget/CheckboxWidget.d.ts +2 -0
  33. package/lib/CheckboxWidget/CheckboxWidget.js +17 -0
  34. package/lib/CheckboxWidget/CheckboxWidget.js.map +1 -0
  35. package/lib/CheckboxWidget/index.d.ts +2 -0
  36. package/lib/CheckboxWidget/index.js +3 -0
  37. package/lib/CheckboxWidget/index.js.map +1 -0
  38. package/lib/CheckboxesWidget/CheckboxesWidget.d.ts +2 -0
  39. package/lib/CheckboxesWidget/CheckboxesWidget.js +24 -0
  40. package/lib/CheckboxesWidget/CheckboxesWidget.js.map +1 -0
  41. package/lib/CheckboxesWidget/index.d.ts +2 -0
  42. package/lib/CheckboxesWidget/index.js +3 -0
  43. package/lib/CheckboxesWidget/index.js.map +1 -0
  44. package/lib/DescriptionField/DescriptionField.d.ts +2 -0
  45. package/lib/DescriptionField/DescriptionField.js +8 -0
  46. package/lib/DescriptionField/DescriptionField.js.map +1 -0
  47. package/lib/DescriptionField/index.d.ts +2 -0
  48. package/lib/DescriptionField/index.js +3 -0
  49. package/lib/DescriptionField/index.js.map +1 -0
  50. package/lib/ErrorList/ErrorList.d.ts +2 -0
  51. package/lib/ErrorList/ErrorList.js +11 -0
  52. package/lib/ErrorList/ErrorList.js.map +1 -0
  53. package/lib/ErrorList/index.d.ts +2 -0
  54. package/lib/ErrorList/index.js +3 -0
  55. package/lib/ErrorList/index.js.map +1 -0
  56. package/lib/FieldErrorTemplate/FieldErrorTemplate.d.ts +6 -0
  57. package/lib/FieldErrorTemplate/FieldErrorTemplate.js +18 -0
  58. package/lib/FieldErrorTemplate/FieldErrorTemplate.js.map +1 -0
  59. package/lib/FieldErrorTemplate/index.d.ts +2 -0
  60. package/lib/FieldErrorTemplate/index.js +3 -0
  61. package/lib/FieldErrorTemplate/index.js.map +1 -0
  62. package/lib/FieldHelpTemplate/FieldHelpTemplate.d.ts +6 -0
  63. package/lib/FieldHelpTemplate/FieldHelpTemplate.js +16 -0
  64. package/lib/FieldHelpTemplate/FieldHelpTemplate.js.map +1 -0
  65. package/lib/FieldHelpTemplate/index.d.ts +2 -0
  66. package/lib/FieldHelpTemplate/index.js +3 -0
  67. package/lib/FieldHelpTemplate/index.js.map +1 -0
  68. package/lib/FieldTemplate/FieldTemplate.d.ts +2 -0
  69. package/lib/FieldTemplate/FieldTemplate.js +12 -0
  70. package/lib/FieldTemplate/FieldTemplate.js.map +1 -0
  71. package/lib/FieldTemplate/index.d.ts +2 -0
  72. package/lib/FieldTemplate/index.js +3 -0
  73. package/lib/FieldTemplate/index.js.map +1 -0
  74. package/lib/Form/Form.d.ts +6 -0
  75. package/lib/Form/Form.js +7 -0
  76. package/lib/Form/Form.js.map +1 -0
  77. package/lib/Form/index.d.ts +2 -0
  78. package/lib/Form/index.js +3 -0
  79. package/lib/Form/index.js.map +1 -0
  80. package/lib/IconButton/IconButton.d.ts +7 -0
  81. package/lib/IconButton/IconButton.js +28 -0
  82. package/lib/IconButton/IconButton.js.map +1 -0
  83. package/lib/IconButton/index.d.ts +2 -0
  84. package/lib/IconButton/index.js +3 -0
  85. package/lib/IconButton/index.js.map +1 -0
  86. package/lib/ObjectFieldTemplate/ObjectFieldTemplate.d.ts +2 -0
  87. package/lib/ObjectFieldTemplate/ObjectFieldTemplate.js +14 -0
  88. package/lib/ObjectFieldTemplate/ObjectFieldTemplate.js.map +1 -0
  89. package/lib/ObjectFieldTemplate/index.d.ts +2 -0
  90. package/lib/ObjectFieldTemplate/index.js +3 -0
  91. package/lib/ObjectFieldTemplate/index.js.map +1 -0
  92. package/lib/RadioWidget/RadioWidget.d.ts +2 -0
  93. package/lib/RadioWidget/RadioWidget.js +18 -0
  94. package/lib/RadioWidget/RadioWidget.js.map +1 -0
  95. package/lib/RadioWidget/index.d.ts +2 -0
  96. package/lib/RadioWidget/index.js +3 -0
  97. package/lib/RadioWidget/index.js.map +1 -0
  98. package/lib/RangeWidget/RangeWidget.d.ts +2 -0
  99. package/lib/RangeWidget/RangeWidget.js +21 -0
  100. package/lib/RangeWidget/RangeWidget.js.map +1 -0
  101. package/lib/RangeWidget/index.d.ts +2 -0
  102. package/lib/RangeWidget/index.js +3 -0
  103. package/lib/RangeWidget/index.js.map +1 -0
  104. package/lib/SelectWidget/SelectWidget.d.ts +2 -0
  105. package/lib/SelectWidget/SelectWidget.js +36 -0
  106. package/lib/SelectWidget/SelectWidget.js.map +1 -0
  107. package/lib/SelectWidget/index.d.ts +2 -0
  108. package/lib/SelectWidget/index.js +3 -0
  109. package/lib/SelectWidget/index.js.map +1 -0
  110. package/lib/SubmitButton/SubmitButton.d.ts +2 -0
  111. package/lib/SubmitButton/SubmitButton.js +11 -0
  112. package/lib/SubmitButton/SubmitButton.js.map +1 -0
  113. package/lib/SubmitButton/index.d.ts +2 -0
  114. package/lib/SubmitButton/index.js +3 -0
  115. package/lib/SubmitButton/index.js.map +1 -0
  116. package/lib/Templates/Templates.d.ts +4 -0
  117. package/lib/Templates/Templates.js +39 -0
  118. package/lib/Templates/Templates.js.map +1 -0
  119. package/lib/Templates/index.d.ts +2 -0
  120. package/lib/Templates/index.js +3 -0
  121. package/lib/Templates/index.js.map +1 -0
  122. package/lib/TextareaWidget/TextareaWidget.d.ts +6 -0
  123. package/lib/TextareaWidget/TextareaWidget.js +11 -0
  124. package/lib/TextareaWidget/TextareaWidget.js.map +1 -0
  125. package/lib/TextareaWidget/index.d.ts +2 -0
  126. package/lib/TextareaWidget/index.js +3 -0
  127. package/lib/TextareaWidget/index.js.map +1 -0
  128. package/lib/Theme/Theme.d.ts +5 -0
  129. package/lib/Theme/Theme.js +10 -0
  130. package/lib/Theme/Theme.js.map +1 -0
  131. package/lib/Theme/index.d.ts +2 -0
  132. package/lib/Theme/index.js +3 -0
  133. package/lib/Theme/index.js.map +1 -0
  134. package/lib/TitleField/TitleField.d.ts +2 -0
  135. package/lib/TitleField/TitleField.js +7 -0
  136. package/lib/TitleField/TitleField.js.map +1 -0
  137. package/lib/TitleField/index.d.ts +2 -0
  138. package/lib/TitleField/index.js +3 -0
  139. package/lib/TitleField/index.js.map +1 -0
  140. package/lib/Widgets/Widgets.d.ts +4 -0
  141. package/lib/Widgets/Widgets.js +18 -0
  142. package/lib/Widgets/Widgets.js.map +1 -0
  143. package/lib/Widgets/index.d.ts +2 -0
  144. package/lib/Widgets/index.js +3 -0
  145. package/lib/Widgets/index.js.map +1 -0
  146. package/lib/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.d.ts +2 -0
  147. package/lib/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.js +19 -0
  148. package/lib/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.js.map +1 -0
  149. package/lib/WrapIfAdditionalTemplate/index.d.ts +2 -0
  150. package/lib/WrapIfAdditionalTemplate/index.js +3 -0
  151. package/lib/WrapIfAdditionalTemplate/index.js.map +1 -0
  152. package/lib/index.d.ts +6 -0
  153. package/lib/index.js +7 -0
  154. package/lib/index.js.map +1 -0
  155. package/lib/tsconfig.tsbuildinfo +1 -0
  156. package/package.json +98 -0
  157. package/src/AddButton/AddButton.tsx +21 -0
  158. package/src/AddButton/index.ts +2 -0
  159. package/src/ArrayFieldItemTemplate/ArrayFieldItemTemplate.tsx +94 -0
  160. package/src/ArrayFieldItemTemplate/index.ts +2 -0
  161. package/src/ArrayFieldTemplate/ArrayFieldTemplate.tsx +86 -0
  162. package/src/ArrayFieldTemplate/index.ts +2 -0
  163. package/src/BaseInputTemplate/BaseInputTemplate.tsx +77 -0
  164. package/src/BaseInputTemplate/index.ts +2 -0
  165. package/src/CheckboxWidget/CheckboxWidget.tsx +80 -0
  166. package/src/CheckboxWidget/index.ts +2 -0
  167. package/src/CheckboxesWidget/CheckboxesWidget.tsx +68 -0
  168. package/src/CheckboxesWidget/index.ts +2 -0
  169. package/src/DescriptionField/DescriptionField.tsx +19 -0
  170. package/src/DescriptionField/index.ts +2 -0
  171. package/src/ErrorList/ErrorList.tsx +27 -0
  172. package/src/ErrorList/index.ts +2 -0
  173. package/src/FieldErrorTemplate/FieldErrorTemplate.tsx +30 -0
  174. package/src/FieldErrorTemplate/index.ts +2 -0
  175. package/src/FieldHelpTemplate/FieldHelpTemplate.tsx +23 -0
  176. package/src/FieldHelpTemplate/index.ts +2 -0
  177. package/src/FieldTemplate/FieldTemplate.tsx +77 -0
  178. package/src/FieldTemplate/index.ts +2 -0
  179. package/src/Form/Form.tsx +15 -0
  180. package/src/Form/index.ts +2 -0
  181. package/src/IconButton/IconButton.tsx +62 -0
  182. package/src/IconButton/index.ts +2 -0
  183. package/src/ObjectFieldTemplate/ObjectFieldTemplate.tsx +89 -0
  184. package/src/ObjectFieldTemplate/index.ts +2 -0
  185. package/src/RadioWidget/RadioWidget.tsx +65 -0
  186. package/src/RadioWidget/index.ts +2 -0
  187. package/src/RangeWidget/RangeWidget.tsx +31 -0
  188. package/src/RangeWidget/index.ts +2 -0
  189. package/src/SelectWidget/SelectWidget.tsx +91 -0
  190. package/src/SelectWidget/index.ts +2 -0
  191. package/src/SubmitButton/SubmitButton.tsx +18 -0
  192. package/src/SubmitButton/index.ts +2 -0
  193. package/src/Templates/Templates.ts +45 -0
  194. package/src/Templates/index.ts +2 -0
  195. package/src/TextareaWidget/TextareaWidget.tsx +56 -0
  196. package/src/TextareaWidget/index.ts +2 -0
  197. package/src/Theme/Theme.tsx +18 -0
  198. package/src/Theme/index.ts +2 -0
  199. package/src/TitleField/TitleField.tsx +15 -0
  200. package/src/TitleField/index.ts +2 -0
  201. package/src/Widgets/Widgets.ts +24 -0
  202. package/src/Widgets/index.ts +2 -0
  203. package/src/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.tsx +79 -0
  204. package/src/WrapIfAdditionalTemplate/index.ts +2 -0
  205. package/src/index.ts +8 -0
  206. package/src/tsconfig.json +23 -0
@@ -0,0 +1,80 @@
1
+ import { FocusEvent } from 'react';
2
+ import {
3
+ ariaDescribedByIds,
4
+ descriptionId,
5
+ getTemplate,
6
+ labelValue,
7
+ WidgetProps,
8
+ schemaRequiresTrueValue,
9
+ StrictRJSFSchema,
10
+ RJSFSchema,
11
+ FormContextType,
12
+ } from '@rjsf/utils';
13
+ import Form from 'react-bootstrap/Form';
14
+
15
+ export default function CheckboxWidget<
16
+ T = any,
17
+ S extends StrictRJSFSchema = RJSFSchema,
18
+ F extends FormContextType = any
19
+ >(props: WidgetProps<T, S, F>) {
20
+ const {
21
+ id,
22
+ value,
23
+ disabled,
24
+ readonly,
25
+ label,
26
+ hideLabel,
27
+ schema,
28
+ autofocus,
29
+ options,
30
+ onChange,
31
+ onBlur,
32
+ onFocus,
33
+ registry,
34
+ uiSchema,
35
+ } = props;
36
+ // Because an unchecked checkbox will cause html5 validation to fail, only add
37
+ // the "required" attribute if the field value must be "true", due to the
38
+ // "const" or "enum" keywords
39
+ const required = schemaRequiresTrueValue<S>(schema);
40
+ const DescriptionFieldTemplate = getTemplate<'DescriptionFieldTemplate', T, S, F>(
41
+ 'DescriptionFieldTemplate',
42
+ registry,
43
+ options
44
+ );
45
+
46
+ const _onChange = ({ target: { checked } }: FocusEvent<HTMLInputElement>) => onChange(checked);
47
+ const _onBlur = ({ target }: FocusEvent<HTMLInputElement>) => onBlur(id, target && target.checked);
48
+ const _onFocus = ({ target }: FocusEvent<HTMLInputElement>) => onFocus(id, target && target.checked);
49
+
50
+ const description = options.description || schema.description;
51
+ return (
52
+ <Form.Group
53
+ className={`checkbox ${disabled || readonly ? 'disabled' : ''}`}
54
+ aria-describedby={ariaDescribedByIds<T>(id)}
55
+ >
56
+ {!hideLabel && !!description && (
57
+ <DescriptionFieldTemplate
58
+ id={descriptionId<T>(id)}
59
+ description={description}
60
+ schema={schema}
61
+ uiSchema={uiSchema}
62
+ registry={registry}
63
+ />
64
+ )}
65
+ <Form.Check
66
+ id={id}
67
+ name={id}
68
+ label={labelValue(label, hideLabel || !label)}
69
+ checked={typeof value === 'undefined' ? false : value}
70
+ required={required}
71
+ disabled={disabled || readonly}
72
+ autoFocus={autofocus}
73
+ onChange={_onChange}
74
+ type='checkbox'
75
+ onBlur={_onBlur}
76
+ onFocus={_onFocus}
77
+ />
78
+ </Form.Group>
79
+ );
80
+ }
@@ -0,0 +1,2 @@
1
+ export { default } from './CheckboxWidget';
2
+ export * from './CheckboxWidget';
@@ -0,0 +1,68 @@
1
+ import { ChangeEvent, FocusEvent } from 'react';
2
+ import Form from 'react-bootstrap/Form';
3
+ import {
4
+ ariaDescribedByIds,
5
+ enumOptionsDeselectValue,
6
+ enumOptionsIsSelected,
7
+ enumOptionsSelectValue,
8
+ enumOptionsValueForIndex,
9
+ optionId,
10
+ FormContextType,
11
+ RJSFSchema,
12
+ StrictRJSFSchema,
13
+ WidgetProps,
14
+ } from '@rjsf/utils';
15
+
16
+ export default function CheckboxesWidget<
17
+ T = any,
18
+ S extends StrictRJSFSchema = RJSFSchema,
19
+ F extends FormContextType = any
20
+ >({ id, disabled, options, value, autofocus, readonly, required, onChange, onBlur, onFocus }: WidgetProps<T, S, F>) {
21
+ const { enumOptions, enumDisabled, inline, emptyValue } = options;
22
+ const checkboxesValues = Array.isArray(value) ? value : [value];
23
+
24
+ const _onChange =
25
+ (index: number) =>
26
+ ({ target: { checked } }: ChangeEvent<HTMLInputElement>) => {
27
+ if (checked) {
28
+ onChange(enumOptionsSelectValue<S>(index, checkboxesValues, enumOptions));
29
+ } else {
30
+ onChange(enumOptionsDeselectValue<S>(index, checkboxesValues, enumOptions));
31
+ }
32
+ };
33
+
34
+ const _onBlur = ({ target }: FocusEvent<HTMLInputElement>) =>
35
+ onBlur(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue));
36
+ const _onFocus = ({ target }: FocusEvent<HTMLInputElement>) =>
37
+ onFocus(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue));
38
+
39
+ return (
40
+ <Form.Group>
41
+ {Array.isArray(enumOptions) &&
42
+ enumOptions.map((option, index: number) => {
43
+ const checked = enumOptionsIsSelected<S>(option.value, checkboxesValues);
44
+ const itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1;
45
+
46
+ return (
47
+ <Form.Check
48
+ key={option.value}
49
+ inline={inline}
50
+ required={required}
51
+ checked={checked}
52
+ className='bg-transparent border-0'
53
+ type={'checkbox'}
54
+ id={optionId(id, index)}
55
+ name={id}
56
+ label={option.label}
57
+ autoFocus={autofocus && index === 0}
58
+ onChange={_onChange(index)}
59
+ onBlur={_onBlur}
60
+ onFocus={_onFocus}
61
+ disabled={disabled || itemDisabled || readonly}
62
+ aria-describedby={ariaDescribedByIds<T>(id)}
63
+ />
64
+ );
65
+ })}
66
+ </Form.Group>
67
+ );
68
+ }
@@ -0,0 +1,2 @@
1
+ export { default } from './CheckboxesWidget';
2
+ export * from './CheckboxesWidget';
@@ -0,0 +1,19 @@
1
+ import { DescriptionFieldProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
2
+
3
+ export default function DescriptionField<
4
+ T = any,
5
+ S extends StrictRJSFSchema = RJSFSchema,
6
+ 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
+ );
16
+ }
17
+
18
+ return null;
19
+ }
@@ -0,0 +1,2 @@
1
+ export { default } from './DescriptionField';
2
+ export * from './DescriptionField';
@@ -0,0 +1,27 @@
1
+ import Card from 'react-bootstrap/Card';
2
+ import ListGroup from 'react-bootstrap/ListGroup';
3
+
4
+ import { ErrorListProps, FormContextType, RJSFSchema, StrictRJSFSchema, TranslatableString } from '@rjsf/utils';
5
+
6
+ export default function ErrorList<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({
7
+ errors,
8
+ registry,
9
+ }: ErrorListProps<T, S, F>) {
10
+ const { translateString } = registry;
11
+ return (
12
+ <Card border='danger' className='mb-4'>
13
+ <Card.Header className='alert-danger'>{translateString(TranslatableString.ErrorsLabel)}</Card.Header>
14
+ <Card.Body className='p-0'>
15
+ <ListGroup>
16
+ {errors.map((error, i: number) => {
17
+ return (
18
+ <ListGroup.Item key={i} className='border-0'>
19
+ <span>{error.stack}</span>
20
+ </ListGroup.Item>
21
+ );
22
+ })}
23
+ </ListGroup>
24
+ </Card.Body>
25
+ </Card>
26
+ );
27
+ }
@@ -0,0 +1,2 @@
1
+ export { default } from './ErrorList';
2
+ export * from './ErrorList';
@@ -0,0 +1,30 @@
1
+ import { FieldErrorProps, FormContextType, RJSFSchema, StrictRJSFSchema, errorId } from '@rjsf/utils';
2
+ import ListGroup from 'react-bootstrap/ListGroup';
3
+
4
+ /** The `FieldErrorTemplate` component renders the errors local to the particular field
5
+ *
6
+ * @param props - The `FieldErrorProps` for the errors being rendered
7
+ */
8
+ export default function FieldErrorTemplate<
9
+ T = any,
10
+ S extends StrictRJSFSchema = RJSFSchema,
11
+ F extends FormContextType = any
12
+ >(props: FieldErrorProps<T, S, F>) {
13
+ const { errors = [], idSchema } = props;
14
+ if (errors.length === 0) {
15
+ return null;
16
+ }
17
+ const id = errorId<T>(idSchema);
18
+
19
+ return (
20
+ <ListGroup as='ul' id={id}>
21
+ {errors.map((error, i) => {
22
+ return (
23
+ <ListGroup.Item as='li' key={i} className='border-0 m-0 p-0'>
24
+ <small className='m-0 text-danger'>{error}</small>
25
+ </ListGroup.Item>
26
+ );
27
+ })}
28
+ </ListGroup>
29
+ );
30
+ }
@@ -0,0 +1,2 @@
1
+ export { default } from './FieldErrorTemplate';
2
+ export * from './FieldErrorTemplate';
@@ -0,0 +1,23 @@
1
+ import { FieldHelpProps, FormContextType, RJSFSchema, StrictRJSFSchema, helpId } from '@rjsf/utils';
2
+ import Form from 'react-bootstrap/Form';
3
+
4
+ /** The `FieldHelpTemplate` component renders any help desired for a field
5
+ *
6
+ * @param props - The `FieldHelpProps` to be rendered
7
+ */
8
+ export default function FieldHelpTemplate<
9
+ T = any,
10
+ S extends StrictRJSFSchema = RJSFSchema,
11
+ F extends FormContextType = any
12
+ >(props: FieldHelpProps<T, S, F>) {
13
+ const { idSchema, help, hasErrors } = props;
14
+ if (!help) {
15
+ return null;
16
+ }
17
+ const id = helpId<T>(idSchema);
18
+ return (
19
+ <Form.Text className={hasErrors ? 'text-danger' : 'text-muted'} id={id}>
20
+ {help}
21
+ </Form.Text>
22
+ );
23
+ }
@@ -0,0 +1,2 @@
1
+ export { default } from './FieldHelpTemplate';
2
+ export * from './FieldHelpTemplate';
@@ -0,0 +1,77 @@
1
+ import {
2
+ FieldTemplateProps,
3
+ FormContextType,
4
+ getTemplate,
5
+ getUiOptions,
6
+ RJSFSchema,
7
+ StrictRJSFSchema,
8
+ } from '@rjsf/utils';
9
+ import Form from 'react-bootstrap/Form';
10
+
11
+ export default function FieldTemplate<
12
+ T = any,
13
+ S extends StrictRJSFSchema = RJSFSchema,
14
+ F extends FormContextType = any
15
+ >({
16
+ id,
17
+ children,
18
+ displayLabel,
19
+ rawErrors = [],
20
+ errors,
21
+ help,
22
+ description,
23
+ rawDescription,
24
+ classNames,
25
+ style,
26
+ disabled,
27
+ label,
28
+ hidden,
29
+ onDropPropertyClick,
30
+ onKeyChange,
31
+ readonly,
32
+ required,
33
+ schema,
34
+ uiSchema,
35
+ registry,
36
+ }: FieldTemplateProps<T, S, F>) {
37
+ const uiOptions = getUiOptions(uiSchema);
38
+ const WrapIfAdditionalTemplate = getTemplate<'WrapIfAdditionalTemplate', T, S, F>(
39
+ 'WrapIfAdditionalTemplate',
40
+ registry,
41
+ uiOptions
42
+ );
43
+ if (hidden) {
44
+ return <div className='hidden'>{children}</div>;
45
+ }
46
+ return (
47
+ <WrapIfAdditionalTemplate
48
+ classNames={classNames}
49
+ style={style}
50
+ disabled={disabled}
51
+ id={id}
52
+ label={label}
53
+ onDropPropertyClick={onDropPropertyClick}
54
+ onKeyChange={onKeyChange}
55
+ readonly={readonly}
56
+ required={required}
57
+ schema={schema}
58
+ uiSchema={uiSchema}
59
+ registry={registry}
60
+ >
61
+ <Form.Group>
62
+ {displayLabel && (
63
+ <Form.Label htmlFor={id} className={rawErrors.length > 0 ? 'text-danger' : ''}>
64
+ {label}
65
+ {required ? '*' : null}
66
+ </Form.Label>
67
+ )}
68
+ {children}
69
+ {displayLabel && rawDescription && (
70
+ <Form.Text className={rawErrors.length > 0 ? 'text-danger' : 'text-muted'}>{description}</Form.Text>
71
+ )}
72
+ {errors}
73
+ {help}
74
+ </Form.Group>
75
+ </WrapIfAdditionalTemplate>
76
+ );
77
+ }
@@ -0,0 +1,2 @@
1
+ export { default } from './FieldTemplate';
2
+ export * from './FieldTemplate';
@@ -0,0 +1,15 @@
1
+ import { ComponentType } from 'react';
2
+
3
+ import { withTheme, FormProps } from '@rjsf/core';
4
+ import { generateTheme } from '../Theme';
5
+ import { FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
6
+
7
+ export function generateForm<
8
+ T = any,
9
+ S extends StrictRJSFSchema = RJSFSchema,
10
+ F extends FormContextType = any
11
+ >(): ComponentType<FormProps<T, S, F>> {
12
+ return withTheme<T, S, F>(generateTheme<T, S, F>());
13
+ }
14
+
15
+ export default generateForm();
@@ -0,0 +1,2 @@
1
+ export { default } from './Form';
2
+ export * from './Form';
@@ -0,0 +1,62 @@
1
+ import { FormContextType, IconButtonProps, RJSFSchema, StrictRJSFSchema, TranslatableString } from '@rjsf/utils';
2
+ import Button, { ButtonProps } from 'react-bootstrap/Button';
3
+ import { IoIosCopy } from '@react-icons/all-files/io/IoIosCopy';
4
+ import { IoIosRemove } from '@react-icons/all-files/io/IoIosRemove';
5
+ import { AiOutlineArrowUp } from '@react-icons/all-files/ai/AiOutlineArrowUp';
6
+ import { AiOutlineArrowDown } from '@react-icons/all-files/ai/AiOutlineArrowDown';
7
+
8
+ export default function IconButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
9
+ props: IconButtonProps<T, S, F> & ButtonProps
10
+ ) {
11
+ const { icon, iconType, className, uiSchema, registry, ...otherProps } = props;
12
+ return (
13
+ <Button {...otherProps} variant={props.variant || 'light'} size='sm'>
14
+ {icon}
15
+ </Button>
16
+ );
17
+ }
18
+
19
+ export function CopyButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
20
+ props: IconButtonProps<T, S, F>
21
+ ) {
22
+ const {
23
+ registry: { translateString },
24
+ } = props;
25
+ return <IconButton title={translateString(TranslatableString.CopyButton)} {...props} icon={<IoIosCopy />} />;
26
+ }
27
+
28
+ export function MoveDownButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
29
+ props: IconButtonProps<T, S, F>
30
+ ) {
31
+ const {
32
+ registry: { translateString },
33
+ } = props;
34
+ return (
35
+ <IconButton title={translateString(TranslatableString.MoveDownButton)} {...props} icon={<AiOutlineArrowDown />} />
36
+ );
37
+ }
38
+
39
+ export function MoveUpButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
40
+ props: IconButtonProps<T, S, F>
41
+ ) {
42
+ const {
43
+ registry: { translateString },
44
+ } = props;
45
+ return <IconButton title={translateString(TranslatableString.MoveUpButton)} {...props} icon={<AiOutlineArrowUp />} />;
46
+ }
47
+
48
+ export function RemoveButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
49
+ props: IconButtonProps<T, S, F>
50
+ ) {
51
+ const {
52
+ registry: { translateString },
53
+ } = props;
54
+ return (
55
+ <IconButton
56
+ title={translateString(TranslatableString.RemoveButton)}
57
+ {...props}
58
+ variant='danger'
59
+ icon={<IoIosRemove />}
60
+ />
61
+ );
62
+ }
@@ -0,0 +1,2 @@
1
+ export { default } from './IconButton';
2
+ export * from './IconButton';
@@ -0,0 +1,89 @@
1
+ import Row from 'react-bootstrap/Row';
2
+ import Col from 'react-bootstrap/Col';
3
+ import Container from 'react-bootstrap/Container';
4
+
5
+ import {
6
+ canExpand,
7
+ descriptionId,
8
+ FormContextType,
9
+ getTemplate,
10
+ getUiOptions,
11
+ ObjectFieldTemplateProps,
12
+ RJSFSchema,
13
+ StrictRJSFSchema,
14
+ titleId,
15
+ } from '@rjsf/utils';
16
+
17
+ export default function ObjectFieldTemplate<
18
+ T = any,
19
+ S extends StrictRJSFSchema = RJSFSchema,
20
+ F extends FormContextType = any
21
+ >({
22
+ description,
23
+ title,
24
+ properties,
25
+ required,
26
+ uiSchema,
27
+ idSchema,
28
+ schema,
29
+ formData,
30
+ onAddClick,
31
+ disabled,
32
+ readonly,
33
+ registry,
34
+ }: ObjectFieldTemplateProps<T, S, F>) {
35
+ const uiOptions = getUiOptions<T, S, F>(uiSchema);
36
+ const TitleFieldTemplate = getTemplate<'TitleFieldTemplate', T, S, F>('TitleFieldTemplate', registry, uiOptions);
37
+ const DescriptionFieldTemplate = getTemplate<'DescriptionFieldTemplate', T, S, F>(
38
+ 'DescriptionFieldTemplate',
39
+ registry,
40
+ uiOptions
41
+ );
42
+ // Button templates are not overridden in the uiSchema
43
+ const {
44
+ ButtonTemplates: { AddButton },
45
+ } = registry.templates;
46
+ return (
47
+ <>
48
+ {title && (
49
+ <TitleFieldTemplate
50
+ id={titleId<T>(idSchema)}
51
+ title={title}
52
+ required={required}
53
+ schema={schema}
54
+ uiSchema={uiSchema}
55
+ registry={registry}
56
+ />
57
+ )}
58
+ {description && (
59
+ <DescriptionFieldTemplate
60
+ id={descriptionId<T>(idSchema)}
61
+ description={description}
62
+ schema={schema}
63
+ uiSchema={uiSchema}
64
+ registry={registry}
65
+ />
66
+ )}
67
+ <Container fluid className='p-0'>
68
+ {properties.map((element: any, index: number) => (
69
+ <Row key={index} style={{ marginBottom: '10px' }} className={element.hidden ? 'd-none' : undefined}>
70
+ <Col xs={12}> {element.content}</Col>
71
+ </Row>
72
+ ))}
73
+ {canExpand(schema, uiSchema, formData) ? (
74
+ <Row>
75
+ <Col xs={{ offset: 9, span: 3 }} className='py-4'>
76
+ <AddButton
77
+ onClick={onAddClick(schema)}
78
+ disabled={disabled || readonly}
79
+ className='object-property-expand'
80
+ uiSchema={uiSchema}
81
+ registry={registry}
82
+ />
83
+ </Col>
84
+ </Row>
85
+ ) : null}
86
+ </Container>
87
+ </>
88
+ );
89
+ }
@@ -0,0 +1,2 @@
1
+ export { default } from './ObjectFieldTemplate';
2
+ export * from './ObjectFieldTemplate';
@@ -0,0 +1,65 @@
1
+ import { ChangeEvent, FocusEvent } from 'react';
2
+ import Form from 'react-bootstrap/Form';
3
+ import {
4
+ ariaDescribedByIds,
5
+ enumOptionsIsSelected,
6
+ enumOptionsValueForIndex,
7
+ optionId,
8
+ FormContextType,
9
+ RJSFSchema,
10
+ StrictRJSFSchema,
11
+ WidgetProps,
12
+ } from '@rjsf/utils';
13
+
14
+ export default function RadioWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({
15
+ id,
16
+ options,
17
+ value,
18
+ required,
19
+ disabled,
20
+ readonly,
21
+ onChange,
22
+ onBlur,
23
+ onFocus,
24
+ }: WidgetProps<T, S, F>) {
25
+ const { enumOptions, enumDisabled, emptyValue } = options;
26
+
27
+ const _onChange = ({ target: { value } }: ChangeEvent<HTMLInputElement>) =>
28
+ onChange(enumOptionsValueForIndex<S>(value, enumOptions, emptyValue));
29
+ const _onBlur = ({ target }: FocusEvent<HTMLInputElement>) =>
30
+ onBlur(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue));
31
+ const _onFocus = ({ target }: FocusEvent<HTMLInputElement>) =>
32
+ onFocus(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue));
33
+
34
+ const inline = Boolean(options && options.inline);
35
+
36
+ return (
37
+ <Form.Group className='mb-0'>
38
+ {Array.isArray(enumOptions) &&
39
+ enumOptions.map((option, index) => {
40
+ const itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1;
41
+ const checked = enumOptionsIsSelected<S>(option.value, value);
42
+
43
+ const radio = (
44
+ <Form.Check
45
+ inline={inline}
46
+ label={option.label}
47
+ id={optionId(id, index)}
48
+ key={index}
49
+ name={id}
50
+ type='radio'
51
+ disabled={disabled || itemDisabled || readonly}
52
+ checked={checked}
53
+ required={required}
54
+ value={String(index)}
55
+ onChange={_onChange}
56
+ onBlur={_onBlur}
57
+ onFocus={_onFocus}
58
+ aria-describedby={ariaDescribedByIds<T>(id)}
59
+ />
60
+ );
61
+ return radio;
62
+ })}
63
+ </Form.Group>
64
+ );
65
+ }
@@ -0,0 +1,2 @@
1
+ export { default } from './RadioWidget';
2
+ export * from './RadioWidget';
@@ -0,0 +1,31 @@
1
+ import { FormContextType, rangeSpec, RJSFSchema, StrictRJSFSchema, WidgetProps } from '@rjsf/utils';
2
+ import { ChangeEvent, FocusEvent } from 'react';
3
+ import FormRange from 'react-bootstrap/FormRange';
4
+
5
+ export default function RangeWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
6
+ props: WidgetProps<T, S, F>
7
+ ) {
8
+ const { id, value, disabled, onChange, onBlur, onFocus, schema } = props;
9
+
10
+ const _onChange = ({ target: { value } }: ChangeEvent<HTMLInputElement>) => onChange(value);
11
+ const _onBlur = ({ target: { value } }: FocusEvent<HTMLInputElement>) => onBlur(id, value);
12
+ const _onFocus = ({ target: { value } }: FocusEvent<HTMLInputElement>) => onFocus(id, value);
13
+
14
+ const rangeProps = {
15
+ value,
16
+ id,
17
+ name: id,
18
+ disabled,
19
+ onChange: _onChange,
20
+ onBlur: _onBlur,
21
+ onFocus: _onFocus,
22
+ ...rangeSpec<S>(schema),
23
+ };
24
+
25
+ return (
26
+ <>
27
+ <FormRange {...rangeProps} />
28
+ <span className='range-view'>{value}</span>
29
+ </>
30
+ );
31
+ }
@@ -0,0 +1,2 @@
1
+ export { default } from './RangeWidget';
2
+ export * from './RangeWidget';