Material UI theme integration for react-jsonschema-form providing dual v4/v5 compatibility with Material Design components, widgets, fields, and themes for JSON schema-based forms.
npx @tessl/cli install tessl/npm-rjsf--material-ui@4.2.0@rjsf/material-ui provides comprehensive Material UI theme integration for react-jsonschema-form, offering both Material UI v4 and v5 compatibility through separate entry points. It includes custom fields, widgets, and themes that enable developers to create JSON schema-based forms with Material Design components and styling.
npm install @rjsf/material-uiThe package provides three entry points:
@rjsf/material-ui): Material UI v4 by default, exports all components@rjsf/material-ui/v4): Explicit Material UI v4 theme@rjsf/material-ui/v5): Material UI v5 themeimport Form from "@rjsf/material-ui";Material UI v4:
import Form from "@rjsf/material-ui/v4";
// or
import { withTheme } from "@rjsf/core";
import Theme from "@rjsf/material-ui/v4";
const Form = withTheme(Theme);Material UI v5:
import Form from "@rjsf/material-ui/v5";
// or
import { withTheme } from "@rjsf/core";
import Theme from "@rjsf/material-ui/v5";
const Form = withTheme(Theme);import {
Fields,
Widgets,
FieldTemplate,
ArrayFieldTemplate,
ObjectFieldTemplate,
Theme,
Theme4,
Theme5,
MuiForm,
MuiForm4,
MuiForm5,
MuiComponentContext
} from "@rjsf/material-ui";CommonJS:
const Form = require("@rjsf/material-ui").default;
// or
const { Fields, Widgets, Theme, Theme4, Theme5, MuiComponentContext } = require("@rjsf/material-ui");
// Version-specific
const Form4 = require("@rjsf/material-ui/v4").default;
const Form5 = require("@rjsf/material-ui/v5").default;import Form from "@rjsf/material-ui/v5";
const schema = {
type: "object",
properties: {
name: { type: "string", title: "Name" },
email: { type: "string", format: "email", title: "Email" },
age: { type: "integer", title: "Age", minimum: 18 }
},
required: ["name", "email"]
};
function MyForm() {
return (
<Form
schema={schema}
onSubmit={({formData}) => console.log("Submitted:", formData)}
/>
);
}import { withTheme } from "@rjsf/core";
import { Theme, Widgets } from "@rjsf/material-ui/v5";
// Customize the theme with additional widgets
const customTheme = {
...Theme,
widgets: {
...Theme.widgets,
CustomWidget: MyCustomWidget
}
};
const CustomForm = withTheme(customTheme);@rjsf/material-ui is built around several key components:
Pre-configured form components with Material UI themes and all necessary widgets and fields.
declare const MuiForm: React.ComponentType<FormProps<any>>;
declare const MuiForm4: React.ComponentType<FormProps<any>>;
declare const MuiForm5: React.ComponentType<FormProps<any>>;Complete set of form input widgets styled with Material UI components for different data types and input methods.
interface WidgetCollection {
CheckboxWidget: React.ComponentType<WidgetProps>;
CheckboxesWidget: React.ComponentType<WidgetProps>;
ColorWidget: React.ComponentType<WidgetProps>;
DateWidget: React.ComponentType<WidgetProps>;
DateTimeWidget: React.ComponentType<WidgetProps>;
EmailWidget: React.ComponentType<WidgetProps>;
PasswordWidget: React.ComponentType<WidgetProps>;
RadioWidget: React.ComponentType<WidgetProps>;
RangeWidget: React.ComponentType<WidgetProps>;
SelectWidget: React.ComponentType<WidgetProps>;
SubmitButton: React.ComponentType<WidgetProps>;
TextWidget: React.ComponentType<WidgetProps>;
TextareaWidget: React.ComponentType<WidgetProps>;
URLWidget: React.ComponentType<WidgetProps>;
UpDownWidget: React.ComponentType<WidgetProps>;
}Templates that control the layout and structure of form fields, providing consistent Material UI styling and behavior.
declare const FieldTemplate: React.ComponentType<FieldTemplateProps>;
declare const ArrayFieldTemplate: React.ComponentType<ArrayFieldTemplateProps>;
declare const ObjectFieldTemplate: React.ComponentType<ObjectFieldTemplateProps>;Custom field components for specific rendering needs like titles and descriptions.
interface FieldCollection {
DescriptionField: React.ComponentType<FieldProps>;
TitleField: React.ComponentType<FieldProps>;
}Theme objects that configure the complete form appearance and behavior for different Material UI versions.
interface ThemeProps {
_internalFormWrapper?: React.ComponentType<any>;
ArrayFieldTemplate?: React.ComponentType<ArrayFieldTemplateProps>;
FieldTemplate?: React.ComponentType<FieldTemplateProps>;
ObjectFieldTemplate?: React.ComponentType<ObjectFieldTemplateProps>;
fields?: { [key: string]: React.ComponentType<FieldProps> };
widgets?: { [key: string]: React.ComponentType<WidgetProps> };
ErrorList?: React.ComponentType<ErrorListProps>;
}
declare const Theme: ThemeProps;
declare const Theme4: ThemeProps;
declare const Theme5: ThemeProps;React Context system for providing Material UI components to form elements, enabling version compatibility.
declare const MuiComponentContext: React.Context<MaterialUIContextProps | Mui5ContextProps | null>;
function useMuiComponent(): MaterialUIContextProps | Mui5ContextProps;Material UI styled error list component for displaying form validation errors in a structured format.
declare const ErrorList: React.ComponentType<ErrorListProps>;
interface ErrorListProps {
errors: AjvError[];
errorSchema: ErrorSchema;
schema: JSONSchema7;
uiSchema: UiSchema;
formContext: any;
}// Re-exported from @rjsf/core
interface FormProps<T = any> {
schema: JSONSchema7;
formData?: T;
onSubmit?: (data: ISubmitEvent<T>) => void;
onChange?: (data: IChangeEvent<T>) => void;
onError?: (errors: AjvError[]) => void;
// ... additional FormProps from @rjsf/core
}
interface WidgetProps {
id: string;
value: any;
label?: string;
onChange: (value: any) => void;
onBlur?: (id: string, value: any) => void;
onFocus?: (id: string, value: any) => void;
options?: { [key: string]: any };
schema: JSONSchema7;
uiSchema?: UiSchema;
readonly?: boolean;
disabled?: boolean;
required?: boolean;
multiple?: boolean;
rawErrors?: string[];
// ... additional properties
}
interface FieldProps {
name: string;
title?: string;
description?: string;
properties?: { [key: string]: any };
schema: JSONSchema7;
uiSchema?: UiSchema;
formData?: any;
// ... additional properties
}interface MaterialUIContextProps {
Box: React.ComponentType<BoxProps>;
Button: React.ComponentType<ButtonProps>;
Checkbox: React.ComponentType<CheckboxProps>;
Divider: React.ComponentType<DividerProps>;
Grid: React.ComponentType<GridProps>;
FormControl: React.ComponentType<FormControlProps>;
FormControlLabel: React.ComponentType<FormControlLabelProps>;
FormGroup: React.ComponentType<FormGroupProps>;
FormHelperText: React.ComponentType<FormHelperTextProps>;
FormLabel: React.ComponentType<FormLabelProps>;
IconButton: React.ComponentType<IconButtonProps>;
Input: React.ComponentType<InputProps>;
InputLabel: React.ComponentType<InputLabelProps>;
List: React.ComponentType<ListProps>;
ListItem: React.ComponentType<ListItemProps>;
ListItemIcon: React.ComponentType<ListItemIconProps>;
ListItemText: React.ComponentType<ListItemTextProps>;
MenuItem: React.ComponentType<MenuItemProps>;
Paper: React.ComponentType<PaperProps>;
Radio: React.ComponentType<RadioProps>;
RadioGroup: React.ComponentType<RadioGroupProps>;
Slider: React.ComponentType<SliderProps>;
TextField: React.ComponentType<Omit<TextFieldProps, 'color' | 'variant'>>;
Typography: React.ComponentType<TypographyProps>;
AddIcon: React.ComponentType<SvgIconProps>;
ArrowDownwardIcon: React.ComponentType<SvgIconProps>;
ArrowUpwardIcon: React.ComponentType<SvgIconProps>;
ErrorIcon: React.ComponentType<SvgIconProps>;
RemoveIcon: React.ComponentType<SvgIconProps>;
}
interface Mui5ContextProps {
// Same interface as MaterialUIContextProps but for @mui/material v5
Box: React.ComponentType<BoxProps>;
Button: React.ComponentType<ButtonProps>;
// ... (same properties as MaterialUIContextProps)
Input: React.ComponentType<OutlinedInputProps>; // v5 uses OutlinedInputProps instead of InputProps
// ... rest of properties
}