forked from rjsf-team/react-jsonschema-form
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Add generic type support to the antd theme (rjsf-team#3338)
partially fix: rjsf-team#3072 by adding generic type support to the `antd` theme as follows: - In `@rjsf/antd` added generic type support as follows: - Updated all of the template and widget components to add the `T = any`, `S extends StrictRJSFSchema = RJSFSchema` and `F extends FormContextType = any` generics on the function definitions, types and utility function calls - Converted the three components that used the `withConfigConsumer()` HOC to instead use the `<ConfigConsumer>` component to generate the prefixCls - Added a `generateForm<T, S, F>()` function to main `index.ts`, exporting it and exporting the default `Form` as a call to `generateForm()` - Added a `generateTemplates<T, S, F>()` function to the `Templates.tsx`, exporting it and exporting the default `Templates` as a call to `generateTemplates()` - Added a `generateTheme<T, S, F>()` function to the main `index.ts`, exporting it and exporting the default `Theme` as a call to `generateTheme()` - Added a `generateWidgets<T, S, F>()` function to the `Widgets.tsx`, exporting it and exporting the default `Widgets` as a call to `generateWidgets()` - Updated the main `index.ts` for the theme to also export the `generateTemplates()` and `generateWidgets()` functions - Updated the `CHANGELOG.md` accordingly
- Loading branch information
1 parent
5a60e14
commit efa66fd
Showing
28 changed files
with
896 additions
and
618 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,33 @@ | ||
import { ComponentType } from "react"; | ||
import { FormContextType, RJSFSchema, StrictRJSFSchema } from "@rjsf/utils"; | ||
import { FormProps, ThemeProps, withTheme } from "@rjsf/core"; | ||
|
||
import Templates from "./templates"; | ||
import Widgets from "./widgets"; | ||
import Templates, { generateTemplates } from "./templates"; | ||
import Widgets, { generateWidgets } from "./widgets"; | ||
|
||
export { Templates, Widgets }; | ||
export function generateTheme< | ||
T = any, | ||
S extends StrictRJSFSchema = RJSFSchema, | ||
F extends FormContextType = any | ||
>(): ThemeProps<T, S, F> { | ||
return { | ||
templates: generateTemplates<T, S, F>(), | ||
widgets: generateWidgets<T, S, F>(), | ||
}; | ||
} | ||
|
||
export const Theme: ThemeProps = { | ||
templates: Templates, | ||
widgets: Widgets, | ||
}; | ||
const Theme = generateTheme(); | ||
|
||
export const Form: React.ComponentType<FormProps> = withTheme(Theme); | ||
export function generateForm< | ||
T = any, | ||
S extends StrictRJSFSchema = RJSFSchema, | ||
F extends FormContextType = any | ||
>(): ComponentType<FormProps<T, S, F>> { | ||
return withTheme<T, S, F>(generateTheme<T, S, F>()); | ||
} | ||
|
||
const Form = generateForm(); | ||
|
||
export { Form, Templates, Theme, Widgets, generateTemplates, generateWidgets }; | ||
|
||
export default Form; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.