@rjsf/fluentui-rc 5.14.1
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/LICENSE.md +201 -0
- package/README.md +127 -0
- package/dist/core.umd.js +940 -0
- package/dist/index.esm.js +1091 -0
- package/dist/index.esm.js.map +7 -0
- package/dist/index.js +1063 -0
- package/dist/index.js.map +7 -0
- package/lib/AddButton/AddButton.d.ts +3 -0
- package/lib/AddButton/AddButton.js +11 -0
- package/lib/AddButton/AddButton.js.map +1 -0
- package/lib/AddButton/index.d.ts +2 -0
- package/lib/AddButton/index.js +3 -0
- package/lib/AddButton/index.js.map +1 -0
- package/lib/ArrayFieldItemTemplate/ArrayFieldItemTemplate.d.ts +7 -0
- package/lib/ArrayFieldItemTemplate/ArrayFieldItemTemplate.js +12 -0
- package/lib/ArrayFieldItemTemplate/ArrayFieldItemTemplate.js.map +1 -0
- package/lib/ArrayFieldItemTemplate/index.d.ts +2 -0
- package/lib/ArrayFieldItemTemplate/index.js +3 -0
- package/lib/ArrayFieldItemTemplate/index.js.map +1 -0
- package/lib/ArrayFieldTemplate/ArrayFieldTemplate.d.ts +7 -0
- package/lib/ArrayFieldTemplate/ArrayFieldTemplate.js +28 -0
- package/lib/ArrayFieldTemplate/ArrayFieldTemplate.js.map +1 -0
- package/lib/ArrayFieldTemplate/index.d.ts +2 -0
- package/lib/ArrayFieldTemplate/index.js +3 -0
- package/lib/ArrayFieldTemplate/index.js.map +1 -0
- package/lib/BaseInputTemplate/BaseInputTemplate.d.ts +9 -0
- package/lib/BaseInputTemplate/BaseInputTemplate.js +38 -0
- package/lib/BaseInputTemplate/BaseInputTemplate.js.map +1 -0
- package/lib/BaseInputTemplate/index.d.ts +2 -0
- package/lib/BaseInputTemplate/index.js +3 -0
- package/lib/BaseInputTemplate/index.js.map +1 -0
- package/lib/CheckboxWidget/CheckboxWidget.d.ts +8 -0
- package/lib/CheckboxWidget/CheckboxWidget.js +23 -0
- package/lib/CheckboxWidget/CheckboxWidget.js.map +1 -0
- package/lib/CheckboxWidget/index.d.ts +2 -0
- package/lib/CheckboxWidget/index.js +3 -0
- package/lib/CheckboxWidget/index.js.map +1 -0
- package/lib/CheckboxesWidget/CheckboxesWidget.d.ts +8 -0
- package/lib/CheckboxesWidget/CheckboxesWidget.js +30 -0
- package/lib/CheckboxesWidget/CheckboxesWidget.js.map +1 -0
- package/lib/CheckboxesWidget/index.d.ts +2 -0
- package/lib/CheckboxesWidget/index.js +3 -0
- package/lib/CheckboxesWidget/index.js.map +1 -0
- package/lib/DescriptionField/DescriptionField.d.ts +7 -0
- package/lib/DescriptionField/DescriptionField.js +21 -0
- package/lib/DescriptionField/DescriptionField.js.map +1 -0
- package/lib/DescriptionField/index.d.ts +2 -0
- package/lib/DescriptionField/index.js +3 -0
- package/lib/DescriptionField/index.js.map +1 -0
- package/lib/ErrorList/ErrorList.d.ts +7 -0
- package/lib/ErrorList/ErrorList.js +26 -0
- package/lib/ErrorList/ErrorList.js.map +1 -0
- package/lib/ErrorList/index.d.ts +2 -0
- package/lib/ErrorList/index.js +3 -0
- package/lib/ErrorList/index.js.map +1 -0
- package/lib/FieldErrorTemplate/FieldErrorTemplate.d.ts +7 -0
- package/lib/FieldErrorTemplate/FieldErrorTemplate.js +28 -0
- package/lib/FieldErrorTemplate/FieldErrorTemplate.js.map +1 -0
- package/lib/FieldErrorTemplate/index.d.ts +2 -0
- package/lib/FieldErrorTemplate/index.js +3 -0
- package/lib/FieldErrorTemplate/index.js.map +1 -0
- package/lib/FieldHelpTemplate/FieldHelpTemplate.d.ts +7 -0
- package/lib/FieldHelpTemplate/FieldHelpTemplate.js +16 -0
- package/lib/FieldHelpTemplate/FieldHelpTemplate.js.map +1 -0
- package/lib/FieldHelpTemplate/index.d.ts +2 -0
- package/lib/FieldHelpTemplate/index.js +3 -0
- package/lib/FieldHelpTemplate/index.js.map +1 -0
- package/lib/FieldTemplate/FieldTemplate.d.ts +8 -0
- package/lib/FieldTemplate/FieldTemplate.js +18 -0
- package/lib/FieldTemplate/FieldTemplate.js.map +1 -0
- package/lib/FieldTemplate/index.d.ts +2 -0
- package/lib/FieldTemplate/index.js +3 -0
- package/lib/FieldTemplate/index.js.map +1 -0
- package/lib/FluentForm/FluentForm.d.ts +6 -0
- package/lib/FluentForm/FluentForm.js +7 -0
- package/lib/FluentForm/FluentForm.js.map +1 -0
- package/lib/FluentForm/index.d.ts +2 -0
- package/lib/FluentForm/index.js +3 -0
- package/lib/FluentForm/index.js.map +1 -0
- package/lib/FluentUIRCFrameProvider.d.ts +2 -0
- package/lib/FluentUIRCFrameProvider.js +12 -0
- package/lib/FluentUIRCFrameProvider.js.map +1 -0
- package/lib/IconButton/IconButton.d.ts +7 -0
- package/lib/IconButton/IconButton.js +26 -0
- package/lib/IconButton/IconButton.js.map +1 -0
- package/lib/IconButton/index.d.ts +2 -0
- package/lib/IconButton/index.js +3 -0
- package/lib/IconButton/index.js.map +1 -0
- package/lib/ObjectFieldTemplate/ObjectFieldTemplate.d.ts +9 -0
- package/lib/ObjectFieldTemplate/ObjectFieldTemplate.js +22 -0
- package/lib/ObjectFieldTemplate/ObjectFieldTemplate.js.map +1 -0
- package/lib/ObjectFieldTemplate/index.d.ts +2 -0
- package/lib/ObjectFieldTemplate/index.js +3 -0
- package/lib/ObjectFieldTemplate/index.js.map +1 -0
- package/lib/RadioWidget/RadioWidget.d.ts +8 -0
- package/lib/RadioWidget/RadioWidget.js +22 -0
- package/lib/RadioWidget/RadioWidget.js.map +1 -0
- package/lib/RadioWidget/index.d.ts +2 -0
- package/lib/RadioWidget/index.js +3 -0
- package/lib/RadioWidget/index.js.map +1 -0
- package/lib/RangeWidget/RangeWidget.d.ts +8 -0
- package/lib/RangeWidget/RangeWidget.js +20 -0
- package/lib/RangeWidget/RangeWidget.js.map +1 -0
- package/lib/RangeWidget/index.d.ts +2 -0
- package/lib/RangeWidget/index.js +3 -0
- package/lib/RangeWidget/index.js.map +1 -0
- package/lib/SelectWidget/SelectWidget.d.ts +9 -0
- package/lib/SelectWidget/SelectWidget.js +41 -0
- package/lib/SelectWidget/SelectWidget.js.map +1 -0
- package/lib/SelectWidget/index.d.ts +2 -0
- package/lib/SelectWidget/index.js +3 -0
- package/lib/SelectWidget/index.js.map +1 -0
- package/lib/SubmitButton/SubmitButton.d.ts +3 -0
- package/lib/SubmitButton/SubmitButton.js +17 -0
- package/lib/SubmitButton/SubmitButton.js.map +1 -0
- package/lib/SubmitButton/index.d.ts +2 -0
- package/lib/SubmitButton/index.js +3 -0
- package/lib/SubmitButton/index.js.map +1 -0
- package/lib/Templates/Templates.d.ts +4 -0
- package/lib/Templates/Templates.js +39 -0
- package/lib/Templates/Templates.js.map +1 -0
- package/lib/Templates/index.d.ts +2 -0
- package/lib/Templates/index.js +3 -0
- package/lib/Templates/index.js.map +1 -0
- package/lib/TextareaWidget/TextareaWidget.d.ts +7 -0
- package/lib/TextareaWidget/TextareaWidget.js +27 -0
- package/lib/TextareaWidget/TextareaWidget.js.map +1 -0
- package/lib/TextareaWidget/index.d.ts +2 -0
- package/lib/TextareaWidget/index.js +3 -0
- package/lib/TextareaWidget/index.js.map +1 -0
- package/lib/Theme/Theme.d.ts +5 -0
- package/lib/Theme/Theme.js +10 -0
- package/lib/Theme/Theme.js.map +1 -0
- package/lib/Theme/index.d.ts +2 -0
- package/lib/Theme/index.js +3 -0
- package/lib/Theme/index.js.map +1 -0
- package/lib/TitleField/TitleField.d.ts +7 -0
- package/lib/TitleField/TitleField.js +17 -0
- package/lib/TitleField/TitleField.js.map +1 -0
- package/lib/TitleField/index.d.ts +2 -0
- package/lib/TitleField/index.js +3 -0
- package/lib/TitleField/index.js.map +1 -0
- package/lib/Widgets/Widgets.d.ts +4 -0
- package/lib/Widgets/Widgets.js +18 -0
- package/lib/Widgets/Widgets.js.map +1 -0
- package/lib/Widgets/index.d.ts +2 -0
- package/lib/Widgets/index.js +3 -0
- package/lib/Widgets/index.js.map +1 -0
- package/lib/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.d.ts +8 -0
- package/lib/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.js +40 -0
- package/lib/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.js.map +1 -0
- package/lib/WrapIfAdditionalTemplate/index.d.ts +2 -0
- package/lib/WrapIfAdditionalTemplate/index.js +3 -0
- package/lib/WrapIfAdditionalTemplate/index.js.map +1 -0
- package/lib/index.d.ts +7 -0
- package/lib/index.js +8 -0
- package/lib/index.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/package.json +98 -0
- package/src/AddButton/AddButton.tsx +12 -0
- package/src/AddButton/index.ts +2 -0
- package/src/ArrayFieldItemTemplate/ArrayFieldItemTemplate.tsx +72 -0
- package/src/ArrayFieldItemTemplate/index.ts +2 -0
- package/src/ArrayFieldTemplate/ArrayFieldTemplate.tsx +87 -0
- package/src/ArrayFieldTemplate/index.ts +2 -0
- package/src/BaseInputTemplate/BaseInputTemplate.tsx +99 -0
- package/src/BaseInputTemplate/index.ts +2 -0
- package/src/CheckboxWidget/CheckboxWidget.tsx +81 -0
- package/src/CheckboxWidget/index.ts +2 -0
- package/src/CheckboxesWidget/CheckboxesWidget.tsx +91 -0
- package/src/CheckboxesWidget/index.ts +2 -0
- package/src/DescriptionField/DescriptionField.tsx +31 -0
- package/src/DescriptionField/index.ts +2 -0
- package/src/ErrorList/ErrorList.tsx +40 -0
- package/src/ErrorList/index.ts +2 -0
- package/src/FieldErrorTemplate/FieldErrorTemplate.tsx +44 -0
- package/src/FieldErrorTemplate/index.ts +2 -0
- package/src/FieldHelpTemplate/FieldHelpTemplate.tsx +19 -0
- package/src/FieldHelpTemplate/index.ts +2 -0
- package/src/FieldTemplate/FieldTemplate.tsx +80 -0
- package/src/FieldTemplate/index.ts +2 -0
- package/src/FluentForm/FluentForm.ts +15 -0
- package/src/FluentForm/index.ts +2 -0
- package/src/FluentUIRCFrameProvider.tsx +21 -0
- package/src/IconButton/IconButton.tsx +73 -0
- package/src/IconButton/index.ts +2 -0
- package/src/ObjectFieldTemplate/ObjectFieldTemplate.tsx +97 -0
- package/src/ObjectFieldTemplate/index.ts +2 -0
- package/src/RadioWidget/RadioWidget.tsx +77 -0
- package/src/RadioWidget/index.ts +2 -0
- package/src/RangeWidget/RangeWidget.tsx +49 -0
- package/src/RangeWidget/index.ts +2 -0
- package/src/SelectWidget/SelectWidget.tsx +98 -0
- package/src/SelectWidget/index.ts +2 -0
- package/src/SubmitButton/SubmitButton.tsx +27 -0
- package/src/SubmitButton/index.ts +2 -0
- package/src/Templates/Templates.ts +45 -0
- package/src/Templates/index.ts +2 -0
- package/src/TextareaWidget/TextareaWidget.tsx +81 -0
- package/src/TextareaWidget/index.ts +2 -0
- package/src/Theme/Theme.ts +18 -0
- package/src/Theme/index.ts +2 -0
- package/src/TitleField/TitleField.tsx +28 -0
- package/src/TitleField/index.ts +2 -0
- package/src/Widgets/Widgets.ts +24 -0
- package/src/Widgets/index.ts +2 -0
- package/src/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.tsx +100 -0
- package/src/WrapIfAdditionalTemplate/index.ts +2 -0
- package/src/index.ts +9 -0
- package/src/tsconfig.json +24 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { makeStyles, tokens } from '@fluentui/react-components';
|
|
2
|
+
import { errorId, FieldErrorProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
3
|
+
|
|
4
|
+
const useStyles = makeStyles({
|
|
5
|
+
list: { marginTop: 0, marginBottom: 0, paddingLeft: 0, listStyleType: 'none' },
|
|
6
|
+
listItem: {
|
|
7
|
+
paddingLeft: tokens.spacingHorizontalL,
|
|
8
|
+
paddingTop: tokens.spacingVerticalXS,
|
|
9
|
+
paddingBottom: tokens.spacingVerticalXS,
|
|
10
|
+
},
|
|
11
|
+
errorLabel: { color: tokens.colorPaletteRedForeground1 },
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
/** The `FieldErrorTemplate` component renders the errors local to the particular field
|
|
15
|
+
*
|
|
16
|
+
* @param props - The `FieldErrorProps` for the errors being rendered
|
|
17
|
+
*/
|
|
18
|
+
export default function FieldErrorTemplate<
|
|
19
|
+
T = any,
|
|
20
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
21
|
+
F extends FormContextType = any
|
|
22
|
+
>(props: FieldErrorProps<T, S, F>) {
|
|
23
|
+
const { errors = [], idSchema } = props;
|
|
24
|
+
const classes = useStyles();
|
|
25
|
+
|
|
26
|
+
if (errors.length === 0) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
const id = errorId<T>(idSchema);
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<ul className={classes.list}>
|
|
33
|
+
{errors.map((error, i: number) => {
|
|
34
|
+
return (
|
|
35
|
+
<li key={i} className={classes.listItem}>
|
|
36
|
+
<small className={classes.errorLabel} id={id}>
|
|
37
|
+
{error}
|
|
38
|
+
</small>
|
|
39
|
+
</li>
|
|
40
|
+
);
|
|
41
|
+
})}
|
|
42
|
+
</ul>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Caption1 } from '@fluentui/react-components';
|
|
2
|
+
import { helpId, FieldHelpProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
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 } = props;
|
|
14
|
+
if (!help) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
const id = helpId<T>(idSchema);
|
|
18
|
+
return <Caption1 id={id}>{help}</Caption1>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Field, Text } from '@fluentui/react-components';
|
|
2
|
+
import {
|
|
3
|
+
FieldTemplateProps,
|
|
4
|
+
FormContextType,
|
|
5
|
+
RJSFSchema,
|
|
6
|
+
StrictRJSFSchema,
|
|
7
|
+
getTemplate,
|
|
8
|
+
getUiOptions,
|
|
9
|
+
} from '@rjsf/utils';
|
|
10
|
+
|
|
11
|
+
/** The `FieldTemplate` component is the template used by `SchemaField` to render any field. It renders the field
|
|
12
|
+
* content, (label, description, children, errors and help) inside of a `WrapIfAdditional` component.
|
|
13
|
+
*
|
|
14
|
+
* @param props - The `FieldTemplateProps` for this component
|
|
15
|
+
*/
|
|
16
|
+
export default function FieldTemplate<
|
|
17
|
+
T = any,
|
|
18
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
19
|
+
F extends FormContextType = any
|
|
20
|
+
>(props: FieldTemplateProps<T, S, F>) {
|
|
21
|
+
const {
|
|
22
|
+
id,
|
|
23
|
+
children,
|
|
24
|
+
classNames,
|
|
25
|
+
style,
|
|
26
|
+
disabled,
|
|
27
|
+
displayLabel,
|
|
28
|
+
hidden,
|
|
29
|
+
label,
|
|
30
|
+
onDropPropertyClick,
|
|
31
|
+
onKeyChange,
|
|
32
|
+
readonly,
|
|
33
|
+
required,
|
|
34
|
+
rawErrors = [],
|
|
35
|
+
errors,
|
|
36
|
+
help,
|
|
37
|
+
description,
|
|
38
|
+
rawDescription,
|
|
39
|
+
schema,
|
|
40
|
+
uiSchema,
|
|
41
|
+
registry,
|
|
42
|
+
} = props;
|
|
43
|
+
const uiOptions = getUiOptions<T, S, F>(uiSchema);
|
|
44
|
+
const WrapIfAdditionalTemplate = getTemplate<'WrapIfAdditionalTemplate', T, S, F>(
|
|
45
|
+
'WrapIfAdditionalTemplate',
|
|
46
|
+
registry,
|
|
47
|
+
uiOptions
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
if (hidden) {
|
|
51
|
+
return <div style={{ display: 'none' }}>{children}</div>;
|
|
52
|
+
}
|
|
53
|
+
return (
|
|
54
|
+
<WrapIfAdditionalTemplate
|
|
55
|
+
classNames={classNames}
|
|
56
|
+
style={style}
|
|
57
|
+
disabled={disabled}
|
|
58
|
+
id={id}
|
|
59
|
+
label={label}
|
|
60
|
+
onDropPropertyClick={onDropPropertyClick}
|
|
61
|
+
onKeyChange={onKeyChange}
|
|
62
|
+
readonly={readonly}
|
|
63
|
+
required={required}
|
|
64
|
+
schema={schema}
|
|
65
|
+
uiSchema={uiSchema}
|
|
66
|
+
registry={registry}
|
|
67
|
+
>
|
|
68
|
+
<Field validationState={rawErrors.length ? 'error' : undefined} required={required}>
|
|
69
|
+
{children}
|
|
70
|
+
{displayLabel && rawDescription ? (
|
|
71
|
+
<Text as='p' block style={{ marginTop: 0, marginBottom: 0 }}>
|
|
72
|
+
{description}
|
|
73
|
+
</Text>
|
|
74
|
+
) : null}
|
|
75
|
+
{errors}
|
|
76
|
+
{help}
|
|
77
|
+
</Field>
|
|
78
|
+
</WrapIfAdditionalTemplate>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ComponentType } from 'react';
|
|
2
|
+
import { FormProps, withTheme } from '@rjsf/core';
|
|
3
|
+
|
|
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,21 @@
|
|
|
1
|
+
import { FluentProvider, RendererProvider, createDOMRenderer, teamsLightTheme } from '@fluentui/react-components';
|
|
2
|
+
import { ReactNode, useMemo } from 'react';
|
|
3
|
+
|
|
4
|
+
const FluentWrapper = (props: { children: ReactNode; targetDocument?: HTMLDocument }) => {
|
|
5
|
+
const { children, targetDocument } = props;
|
|
6
|
+
const renderer = useMemo(() => createDOMRenderer(targetDocument), [targetDocument]);
|
|
7
|
+
|
|
8
|
+
return (
|
|
9
|
+
<RendererProvider renderer={renderer} targetDocument={targetDocument}>
|
|
10
|
+
<FluentProvider targetDocument={targetDocument} theme={teamsLightTheme}>
|
|
11
|
+
{children}
|
|
12
|
+
</FluentProvider>
|
|
13
|
+
</RendererProvider>
|
|
14
|
+
);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const __createFluentUIRCFrameProvider =
|
|
18
|
+
(props: any) =>
|
|
19
|
+
({ document }: any) => {
|
|
20
|
+
return <FluentWrapper targetDocument={document}>{props.children}</FluentWrapper>;
|
|
21
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Button } from '@fluentui/react-components';
|
|
2
|
+
import { ArrowSortUpRegular, ArrowSortDownRegular, CopyRegular, SubtractRegular } from '@fluentui/react-icons';
|
|
3
|
+
import { FormContextType, IconButtonProps, RJSFSchema, StrictRJSFSchema, TranslatableString } from '@rjsf/utils';
|
|
4
|
+
|
|
5
|
+
export default function FluentIconButton<
|
|
6
|
+
T = any,
|
|
7
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
8
|
+
F extends FormContextType = any
|
|
9
|
+
>(props: IconButtonProps<T, S, F>) {
|
|
10
|
+
const { color, uiSchema, registry, ...otherProps } = props;
|
|
11
|
+
|
|
12
|
+
return <Button {...otherProps} color='secondary' />;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function CopyButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
16
|
+
props: IconButtonProps<T, S, F>
|
|
17
|
+
) {
|
|
18
|
+
const {
|
|
19
|
+
registry: { translateString },
|
|
20
|
+
} = props;
|
|
21
|
+
return (
|
|
22
|
+
<FluentIconButton<T, S, F>
|
|
23
|
+
title={translateString(TranslatableString.CopyButton)}
|
|
24
|
+
{...props}
|
|
25
|
+
icon={<CopyRegular />}
|
|
26
|
+
/>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function MoveDownButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
31
|
+
props: IconButtonProps<T, S, F>
|
|
32
|
+
) {
|
|
33
|
+
const {
|
|
34
|
+
registry: { translateString },
|
|
35
|
+
} = props;
|
|
36
|
+
return (
|
|
37
|
+
<FluentIconButton<T, S, F>
|
|
38
|
+
title={translateString(TranslatableString.MoveDownButton)}
|
|
39
|
+
{...props}
|
|
40
|
+
icon={<ArrowSortDownRegular />}
|
|
41
|
+
/>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function MoveUpButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
46
|
+
props: IconButtonProps<T, S, F>
|
|
47
|
+
) {
|
|
48
|
+
const {
|
|
49
|
+
registry: { translateString },
|
|
50
|
+
} = props;
|
|
51
|
+
return (
|
|
52
|
+
<FluentIconButton<T, S, F>
|
|
53
|
+
title={translateString(TranslatableString.MoveUpButton)}
|
|
54
|
+
{...props}
|
|
55
|
+
icon={<ArrowSortUpRegular />}
|
|
56
|
+
/>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function RemoveButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
61
|
+
props: IconButtonProps<T, S, F>
|
|
62
|
+
) {
|
|
63
|
+
const {
|
|
64
|
+
registry: { translateString },
|
|
65
|
+
} = props;
|
|
66
|
+
return (
|
|
67
|
+
<FluentIconButton<T, S, F>
|
|
68
|
+
title={translateString(TranslatableString.RemoveButton)}
|
|
69
|
+
{...props}
|
|
70
|
+
icon={<SubtractRegular />}
|
|
71
|
+
/>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Flex } from '@fluentui/react-migration-v0-v9';
|
|
2
|
+
import {
|
|
3
|
+
FormContextType,
|
|
4
|
+
ObjectFieldTemplateProps,
|
|
5
|
+
RJSFSchema,
|
|
6
|
+
StrictRJSFSchema,
|
|
7
|
+
canExpand,
|
|
8
|
+
descriptionId,
|
|
9
|
+
getTemplate,
|
|
10
|
+
getUiOptions,
|
|
11
|
+
titleId,
|
|
12
|
+
} from '@rjsf/utils';
|
|
13
|
+
|
|
14
|
+
/** The `ObjectFieldTemplate` is the template to use to render all the inner properties of an object along with the
|
|
15
|
+
* title and description if available. If the object is expandable, then an `AddButton` is also rendered after all
|
|
16
|
+
* the properties.
|
|
17
|
+
*
|
|
18
|
+
* @param props - The `ObjectFieldTemplateProps` for this component
|
|
19
|
+
*/
|
|
20
|
+
export default function ObjectFieldTemplate<
|
|
21
|
+
T = any,
|
|
22
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
23
|
+
F extends FormContextType = any
|
|
24
|
+
>(props: ObjectFieldTemplateProps<T, S, F>) {
|
|
25
|
+
const {
|
|
26
|
+
description,
|
|
27
|
+
title,
|
|
28
|
+
properties,
|
|
29
|
+
required,
|
|
30
|
+
disabled,
|
|
31
|
+
readonly,
|
|
32
|
+
uiSchema,
|
|
33
|
+
idSchema,
|
|
34
|
+
schema,
|
|
35
|
+
formData,
|
|
36
|
+
onAddClick,
|
|
37
|
+
registry,
|
|
38
|
+
} = props;
|
|
39
|
+
const uiOptions = getUiOptions<T, S, F>(uiSchema);
|
|
40
|
+
const TitleFieldTemplate = getTemplate<'TitleFieldTemplate', T, S, F>('TitleFieldTemplate', registry, uiOptions);
|
|
41
|
+
const DescriptionFieldTemplate = getTemplate<'DescriptionFieldTemplate', T, S, F>(
|
|
42
|
+
'DescriptionFieldTemplate',
|
|
43
|
+
registry,
|
|
44
|
+
uiOptions
|
|
45
|
+
);
|
|
46
|
+
// Button templates are not overridden in the uiSchema
|
|
47
|
+
const {
|
|
48
|
+
ButtonTemplates: { AddButton },
|
|
49
|
+
} = registry.templates;
|
|
50
|
+
return (
|
|
51
|
+
<>
|
|
52
|
+
{title && (
|
|
53
|
+
<TitleFieldTemplate
|
|
54
|
+
id={titleId<T>(idSchema)}
|
|
55
|
+
title={title}
|
|
56
|
+
required={required}
|
|
57
|
+
schema={schema}
|
|
58
|
+
uiSchema={uiSchema}
|
|
59
|
+
registry={registry}
|
|
60
|
+
/>
|
|
61
|
+
)}
|
|
62
|
+
{description && (
|
|
63
|
+
<DescriptionFieldTemplate
|
|
64
|
+
id={descriptionId<T>(idSchema)}
|
|
65
|
+
description={description}
|
|
66
|
+
schema={schema}
|
|
67
|
+
uiSchema={uiSchema}
|
|
68
|
+
registry={registry}
|
|
69
|
+
/>
|
|
70
|
+
)}
|
|
71
|
+
<Flex fill column gap='gap.medium'>
|
|
72
|
+
{properties.map((element, index) =>
|
|
73
|
+
// Remove the <Grid> if the inner element is hidden as the <Grid>
|
|
74
|
+
// itself would otherwise still take up space.
|
|
75
|
+
element.hidden ? (
|
|
76
|
+
element.content
|
|
77
|
+
) : (
|
|
78
|
+
<Flex column fill key={index} style={{ marginBottom: '10px' }}>
|
|
79
|
+
{element.content}
|
|
80
|
+
</Flex>
|
|
81
|
+
)
|
|
82
|
+
)}
|
|
83
|
+
{canExpand<T, S, F>(schema, uiSchema, formData) && (
|
|
84
|
+
<Flex hAlign='end'>
|
|
85
|
+
<AddButton
|
|
86
|
+
className='object-property-expand'
|
|
87
|
+
onClick={onAddClick(schema)}
|
|
88
|
+
disabled={disabled || readonly}
|
|
89
|
+
uiSchema={uiSchema}
|
|
90
|
+
registry={registry}
|
|
91
|
+
/>
|
|
92
|
+
</Flex>
|
|
93
|
+
)}
|
|
94
|
+
</Flex>
|
|
95
|
+
</>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { FocusEvent } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
ariaDescribedByIds,
|
|
4
|
+
enumOptionsIndexForValue,
|
|
5
|
+
enumOptionsValueForIndex,
|
|
6
|
+
labelValue,
|
|
7
|
+
optionId,
|
|
8
|
+
FormContextType,
|
|
9
|
+
RJSFSchema,
|
|
10
|
+
StrictRJSFSchema,
|
|
11
|
+
WidgetProps,
|
|
12
|
+
} from '@rjsf/utils';
|
|
13
|
+
import { Label, Radio, RadioGroup, RadioGroupOnChangeData } from '@fluentui/react-components';
|
|
14
|
+
|
|
15
|
+
/** The `RadioWidget` is a widget for rendering a radio group.
|
|
16
|
+
* It is typically used with a string property constrained with enum options.
|
|
17
|
+
*
|
|
18
|
+
* @param props - The `WidgetProps` for this component
|
|
19
|
+
*/
|
|
20
|
+
export default function RadioWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({
|
|
21
|
+
id,
|
|
22
|
+
options,
|
|
23
|
+
value,
|
|
24
|
+
required,
|
|
25
|
+
disabled,
|
|
26
|
+
readonly,
|
|
27
|
+
label,
|
|
28
|
+
hideLabel,
|
|
29
|
+
onChange,
|
|
30
|
+
onBlur,
|
|
31
|
+
onFocus,
|
|
32
|
+
}: WidgetProps<T, S, F>) {
|
|
33
|
+
const { enumOptions, enumDisabled, emptyValue } = options;
|
|
34
|
+
|
|
35
|
+
const _onChange = (_: any, data: RadioGroupOnChangeData) =>
|
|
36
|
+
onChange(enumOptionsValueForIndex<S>(data.value, enumOptions, emptyValue));
|
|
37
|
+
const _onBlur = ({ target: { value } }: FocusEvent<HTMLInputElement>) =>
|
|
38
|
+
onBlur(id, enumOptionsValueForIndex<S>(value, enumOptions, emptyValue));
|
|
39
|
+
const _onFocus = ({ target: { value } }: FocusEvent<HTMLInputElement>) =>
|
|
40
|
+
onFocus(id, enumOptionsValueForIndex<S>(value, enumOptions, emptyValue));
|
|
41
|
+
|
|
42
|
+
const selectedIndex = enumOptionsIndexForValue<S>(value, enumOptions) ?? undefined;
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<>
|
|
46
|
+
{labelValue(
|
|
47
|
+
<Label required={required} htmlFor={id}>
|
|
48
|
+
{label || undefined}
|
|
49
|
+
</Label>,
|
|
50
|
+
hideLabel
|
|
51
|
+
)}
|
|
52
|
+
<RadioGroup
|
|
53
|
+
id={id}
|
|
54
|
+
name={id}
|
|
55
|
+
value={selectedIndex as string | undefined}
|
|
56
|
+
onChange={_onChange}
|
|
57
|
+
onBlur={_onBlur}
|
|
58
|
+
onFocus={_onFocus}
|
|
59
|
+
aria-describedby={ariaDescribedByIds<T>(id)}
|
|
60
|
+
>
|
|
61
|
+
{Array.isArray(enumOptions) &&
|
|
62
|
+
enumOptions.map((option, index) => {
|
|
63
|
+
const itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1;
|
|
64
|
+
return (
|
|
65
|
+
<Radio
|
|
66
|
+
id={optionId(id, index)}
|
|
67
|
+
label={option.label}
|
|
68
|
+
value={String(index)}
|
|
69
|
+
key={index}
|
|
70
|
+
disabled={disabled || itemDisabled || readonly}
|
|
71
|
+
/>
|
|
72
|
+
);
|
|
73
|
+
})}
|
|
74
|
+
</RadioGroup>
|
|
75
|
+
</>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { FocusEvent } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
ariaDescribedByIds,
|
|
4
|
+
labelValue,
|
|
5
|
+
FormContextType,
|
|
6
|
+
RJSFSchema,
|
|
7
|
+
StrictRJSFSchema,
|
|
8
|
+
WidgetProps,
|
|
9
|
+
rangeSpec,
|
|
10
|
+
} from '@rjsf/utils';
|
|
11
|
+
import { Label, Slider, SliderOnChangeData } from '@fluentui/react-components';
|
|
12
|
+
|
|
13
|
+
/** The `RangeWidget` component uses the `BaseInputTemplate` changing the type to `range` and wrapping the result
|
|
14
|
+
* in a div, with the value along side it.
|
|
15
|
+
*
|
|
16
|
+
* @param props - The `WidgetProps` for this component
|
|
17
|
+
*/
|
|
18
|
+
export default function RangeWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
19
|
+
props: WidgetProps<T, S, F>
|
|
20
|
+
) {
|
|
21
|
+
const { value, readonly, disabled, onBlur, onFocus, options, schema, onChange, required, label, hideLabel, id } =
|
|
22
|
+
props;
|
|
23
|
+
const sliderProps = { value, label, id, name: id, ...rangeSpec<S>(schema) };
|
|
24
|
+
|
|
25
|
+
const _onChange = (_: any, data: SliderOnChangeData) => {
|
|
26
|
+
onChange(data.value ?? options.emptyValue);
|
|
27
|
+
};
|
|
28
|
+
const _onBlur = ({ target: { value } }: FocusEvent<HTMLInputElement>) => onBlur(id, value);
|
|
29
|
+
const _onFocus = ({ target: { value } }: FocusEvent<HTMLInputElement>) => onFocus(id, value);
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<>
|
|
33
|
+
{labelValue(
|
|
34
|
+
<Label required={required} htmlFor={id}>
|
|
35
|
+
{label || undefined}
|
|
36
|
+
</Label>,
|
|
37
|
+
hideLabel
|
|
38
|
+
)}
|
|
39
|
+
<Slider
|
|
40
|
+
disabled={disabled || readonly}
|
|
41
|
+
onChange={_onChange}
|
|
42
|
+
onBlur={_onBlur}
|
|
43
|
+
onFocus={_onFocus}
|
|
44
|
+
{...sliderProps}
|
|
45
|
+
aria-describedby={ariaDescribedByIds<T>(id)}
|
|
46
|
+
/>
|
|
47
|
+
</>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ariaDescribedByIds,
|
|
3
|
+
enumOptionsIndexForValue,
|
|
4
|
+
enumOptionsValueForIndex,
|
|
5
|
+
FormContextType,
|
|
6
|
+
labelValue,
|
|
7
|
+
RJSFSchema,
|
|
8
|
+
StrictRJSFSchema,
|
|
9
|
+
WidgetProps,
|
|
10
|
+
} from '@rjsf/utils';
|
|
11
|
+
import { Dropdown, Field, Option } from '@fluentui/react-components';
|
|
12
|
+
import { OptionOnSelectData } from '@fluentui/react-combobox';
|
|
13
|
+
|
|
14
|
+
function getValue(data: OptionOnSelectData, multiple: boolean) {
|
|
15
|
+
if (multiple) {
|
|
16
|
+
return data.selectedOptions;
|
|
17
|
+
}
|
|
18
|
+
return data.selectedOptions[0];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The `SelectWidget` is a widget for rendering dropdowns.
|
|
22
|
+
* It is typically used with string properties constrained with enum options.
|
|
23
|
+
*
|
|
24
|
+
* @param props - The `WidgetProps` for this component
|
|
25
|
+
*/
|
|
26
|
+
function SelectWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({
|
|
27
|
+
id,
|
|
28
|
+
options,
|
|
29
|
+
label,
|
|
30
|
+
hideLabel,
|
|
31
|
+
value,
|
|
32
|
+
required,
|
|
33
|
+
disabled,
|
|
34
|
+
readonly,
|
|
35
|
+
multiple = false,
|
|
36
|
+
autofocus = false,
|
|
37
|
+
rawErrors = [],
|
|
38
|
+
onChange,
|
|
39
|
+
onBlur,
|
|
40
|
+
onFocus,
|
|
41
|
+
}: WidgetProps<T, S, F>) {
|
|
42
|
+
const { enumOptions, enumDisabled, emptyValue: optEmptyVal } = options;
|
|
43
|
+
|
|
44
|
+
const selectedIndexes = enumOptionsIndexForValue<S>(value, enumOptions, multiple);
|
|
45
|
+
let selectedIndexesAsArray: string[] = [];
|
|
46
|
+
|
|
47
|
+
if (typeof selectedIndexes === 'string') {
|
|
48
|
+
selectedIndexesAsArray = [selectedIndexes];
|
|
49
|
+
} else if (Array.isArray(selectedIndexes)) {
|
|
50
|
+
selectedIndexesAsArray = selectedIndexes.map((index) => String(index));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const dropdownValue = selectedIndexesAsArray
|
|
54
|
+
.map((index) => (enumOptions ? enumOptions[Number(index)].label : undefined))
|
|
55
|
+
.join(', ');
|
|
56
|
+
|
|
57
|
+
const _onBlur = () => onBlur(id, selectedIndexes);
|
|
58
|
+
const _onFocus = () => onFocus(id, selectedIndexes);
|
|
59
|
+
const _onChange = (_: any, data: OptionOnSelectData) => {
|
|
60
|
+
const newValue = getValue(data, multiple);
|
|
61
|
+
return onChange(enumOptionsValueForIndex<S>(newValue, enumOptions, optEmptyVal));
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<Field
|
|
66
|
+
label={labelValue(label, hideLabel)}
|
|
67
|
+
validationState={rawErrors.length ? 'error' : undefined}
|
|
68
|
+
required={required}
|
|
69
|
+
>
|
|
70
|
+
<Dropdown
|
|
71
|
+
id={id}
|
|
72
|
+
name={id}
|
|
73
|
+
multiselect={multiple}
|
|
74
|
+
className='form-control'
|
|
75
|
+
value={dropdownValue}
|
|
76
|
+
disabled={disabled || readonly}
|
|
77
|
+
autoFocus={autofocus}
|
|
78
|
+
onBlur={_onBlur}
|
|
79
|
+
onFocus={_onFocus}
|
|
80
|
+
onOptionSelect={_onChange}
|
|
81
|
+
selectedOptions={selectedIndexesAsArray}
|
|
82
|
+
aria-describedby={ariaDescribedByIds<T>(id)}
|
|
83
|
+
>
|
|
84
|
+
{Array.isArray(enumOptions) &&
|
|
85
|
+
enumOptions.map(({ value, label }, i) => {
|
|
86
|
+
const disabled = enumDisabled && enumDisabled.indexOf(value) !== -1;
|
|
87
|
+
return (
|
|
88
|
+
<Option key={i} value={String(i)} disabled={disabled}>
|
|
89
|
+
{label}
|
|
90
|
+
</Option>
|
|
91
|
+
);
|
|
92
|
+
})}
|
|
93
|
+
</Dropdown>
|
|
94
|
+
</Field>
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export default SelectWidget;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { FormContextType, getSubmitButtonOptions, RJSFSchema, StrictRJSFSchema, SubmitButtonProps } from '@rjsf/utils';
|
|
2
|
+
import { Button, makeStyles, tokens } from '@fluentui/react-components';
|
|
3
|
+
|
|
4
|
+
const useStyles = makeStyles({
|
|
5
|
+
buttonRow: {
|
|
6
|
+
marginTop: tokens.spacingVerticalL,
|
|
7
|
+
},
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export default function SubmitButton<
|
|
11
|
+
T = any,
|
|
12
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
13
|
+
F extends FormContextType = any
|
|
14
|
+
>({ uiSchema }: SubmitButtonProps<T, S, F>) {
|
|
15
|
+
const classes = useStyles();
|
|
16
|
+
const { submitText, norender, props: submitButtonProps } = getSubmitButtonOptions(uiSchema);
|
|
17
|
+
if (norender) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
return (
|
|
21
|
+
<div className={classes.buttonRow}>
|
|
22
|
+
<Button appearance='primary' type='submit' {...submitButtonProps}>
|
|
23
|
+
{submitText}
|
|
24
|
+
</Button>
|
|
25
|
+
</div>
|
|
26
|
+
);
|
|
27
|
+
}
|