import { ComponentType, ForwardedRef, forwardRef } from 'react'; import Form, { FormProps } from './components/Form'; import { FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils'; /** The properties for the `withTheme` function, essentially a subset of properties from the `FormProps` that can be * overridden while creating a theme */ export type ThemeProps = Pick< FormProps, 'fields' | 'templates' | 'widgets' | '_internalFormWrapper' >; /** A Higher-Order component that creates a wrapper around a `Form` with the overrides from the `WithThemeProps` */ export default function withTheme( themeProps: ThemeProps ): ComponentType> { return forwardRef( ({ fields, widgets, templates, ...directProps }: FormProps, ref: ForwardedRef>) => { fields = { ...themeProps?.fields, ...fields }; widgets = { ...themeProps?.widgets, ...widgets }; templates = { ...themeProps?.templates, ...templates, ButtonTemplates: { ...themeProps?.templates?.ButtonTemplates, ...templates?.ButtonTemplates, }, }; return ( {...themeProps} {...directProps} fields={fields} widgets={widgets} templates={templates} ref={ref} /> ); } ); }