-
Notifications
You must be signed in to change notification settings - Fork 7
refactor: update component renders from antd #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,13 +1,14 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { createCache, extractStyle as extStyle, StyleProvider } from '@ant-design/cssinjs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { renderToString } from 'react-dom/server'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| createCache, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| extractStyle as extStyle, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| StyleProvider, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } from '@ant-design/cssinjs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import * as antd from 'antd'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import React from 'react'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { renderToString } from 'react-dom/server'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import type { CustomRender } from './interface'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const defaultBlackList: string[] = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'ConfigProvider', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'Grid', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const defaultBlackList: string[] = ['ConfigProvider', 'Grid']; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const ComponentCustomizeRender: Record< | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -19,6 +20,12 @@ const ComponentCustomizeRender: Record< | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </Affix> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| BackTop: () => <antd.FloatButton.BackTop />, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Cascader: (Cascader: typeof antd.Cascader) => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Cascader /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Cascader.Panel /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Dropdown: (Dropdown) => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Dropdown menu={{ items: [] }}> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -39,18 +46,32 @@ const ComponentCustomizeRender: Record< | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Badge.Ribbon /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Space: (Space: any) => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Space: (Space: typeof antd.Space) => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Space /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Space.Addon /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Space.Compact> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <antd.Button /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Space.Addon>1</Space.Addon> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </Space.Compact> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
48
to
56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Modal: (Modal: any) => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Input: (Input: typeof antd.Input) => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Input /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Input.Group> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Input /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Input /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </Input.Group> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Input.Search /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Input.TextArea /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Input.Password /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Input.OTP /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
57
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Modal: (Modal: typeof antd.Modal) => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Modal /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Modal._InternalPanelDoNotUseOrYouWillBeFired /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Modal._InternalPanelDoNotUseOrYouWillBeFired type="confirm" /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+70
to
76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -63,24 +84,12 @@ const ComponentCustomizeRender: Record< | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return <PurePanel />; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Layout: (Layout: typeof antd.Layout) => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Layout /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Layout.Sider /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Cascader: (Cascader: typeof antd.Cascader) => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Cascader options={[]} /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Cascader.Panel options={[]} /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Input: (Input: typeof antd.Input) => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Input /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Input.OTP /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Input.Search /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Input.TextArea /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Layout> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Layout.Header>Header</Layout.Header> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Layout.Sider>Sider</Layout.Sider> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Layout.Content>Content</Layout.Content> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Layout.Footer>Footer</Layout.Footer> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </Layout> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
85
to
+92
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For consistency with other component renderers, the
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -97,7 +106,9 @@ const defaultNode = ({ excludes = [], includes }: NodeProps) => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {components | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .filter( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (name) => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ![...defaultBlackList, ...excludes].includes(name) && (name[0] === name[0].toUpperCase() || ['notification', 'message'].includes(name)), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ![...defaultBlackList, ...excludes].includes(name) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (name[0] === name[0].toUpperCase() || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ['notification', 'message'].includes(name)), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .map((compName) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const Comp = antd[compName]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -114,13 +125,17 @@ const defaultNode = ({ excludes = [], includes }: NodeProps) => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| })} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export function extractStyle(arg?: CustomRender | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| customTheme?: CustomRender, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| excludes?: string[], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| includes?: string[], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }): string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export function extractStyle( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| arg?: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | CustomRender | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| customTheme?: CustomRender; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| excludes?: string[]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| includes?: string[]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ): string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const cache = createCache(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let customTheme: CustomRender | undefined; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -135,11 +150,13 @@ export function extractStyle(arg?: CustomRender | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const nodeProps: NodeProps = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| includes, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| excludes, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| renderToString( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <StyleProvider cache={cache}> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {customTheme ? customTheme(defaultNode(nodeProps)) : defaultNode(nodeProps)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {customTheme | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? customTheme(defaultNode(nodeProps)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| : defaultNode(nodeProps)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </StyleProvider>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency with other component renderers in this file, the
Cascaderrenderer should accept the component as a parameter instead of hardcodingantd.Cascader. ThedefaultNodefunction is designed to pass the component to this renderer. Additionally, theCascaderandCascader.Panelcomponents require anoptionsprop, which is missing and could cause runtime warnings or errors.