mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 02:59:58 +08:00
chore: type refactor (#46346)
* type: type refactor * chore: fix type WrapProps * chore: remove generic of Component --------- Co-authored-by: 张宁宁 <zhangnn1@yonghui.cn>
This commit is contained in:
parent
2eaa1f4e2e
commit
eaeb75eb44
@ -1,22 +1,15 @@
|
||||
import useMergedState from 'rc-util/lib/hooks/useMergedState';
|
||||
import * as React from 'react';
|
||||
import ConfigProvider, { ConfigContext } from '../config-provider';
|
||||
import useMergedState from 'rc-util/lib/hooks/useMergedState';
|
||||
|
||||
export function withPureRenderTheme(Component: any) {
|
||||
return function PureRenderThemeComponent(props: any) {
|
||||
return (
|
||||
<ConfigProvider
|
||||
theme={{
|
||||
token: {
|
||||
motion: false,
|
||||
zIndexPopupBase: 0,
|
||||
},
|
||||
}}
|
||||
>
|
||||
<Component {...props} />
|
||||
</ConfigProvider>
|
||||
);
|
||||
};
|
||||
import ConfigProvider, { ConfigContext } from '../config-provider';
|
||||
import type { AnyObject } from './type';
|
||||
|
||||
export function withPureRenderTheme<T extends AnyObject = AnyObject>(Component: React.FC) {
|
||||
return (props: T) => (
|
||||
<ConfigProvider theme={{ token: { motion: false, zIndexPopupBase: 0 } }}>
|
||||
<Component {...props} />
|
||||
</ConfigProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export interface BaseProps {
|
||||
@ -25,15 +18,15 @@ export interface BaseProps {
|
||||
}
|
||||
|
||||
/* istanbul ignore next */
|
||||
export default function genPurePanel<ComponentProps extends BaseProps>(
|
||||
const genPurePanel = <ComponentProps extends BaseProps = BaseProps>(
|
||||
Component: any,
|
||||
defaultPrefixCls?: string,
|
||||
getDropdownCls?: null | ((prefixCls: string) => string),
|
||||
postProps?: (props: ComponentProps) => ComponentProps,
|
||||
) {
|
||||
type WrapProps = Omit<ComponentProps, 'open' | 'visible'> & { open?: boolean };
|
||||
) => {
|
||||
type WrapProps = ComponentProps & AnyObject;
|
||||
|
||||
function PurePanel(props: WrapProps) {
|
||||
const PurePanel: React.FC<WrapProps> = (props) => {
|
||||
const { prefixCls: customizePrefixCls, style } = props;
|
||||
|
||||
const holderRef = React.useRef<HTMLDivElement>(null);
|
||||
@ -90,20 +83,19 @@ export default function genPurePanel<ComponentProps extends BaseProps>(
|
||||
if (postProps) {
|
||||
mergedProps = postProps(mergedProps as ComponentProps);
|
||||
}
|
||||
|
||||
const mergedStyle: React.CSSProperties = {
|
||||
paddingBottom: popupHeight,
|
||||
position: 'relative',
|
||||
minWidth: popupWidth,
|
||||
};
|
||||
return (
|
||||
<div
|
||||
ref={holderRef}
|
||||
style={{
|
||||
paddingBottom: popupHeight,
|
||||
position: 'relative',
|
||||
minWidth: popupWidth,
|
||||
}}
|
||||
>
|
||||
<div ref={holderRef} style={mergedStyle}>
|
||||
<Component {...mergedProps} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
return withPureRenderTheme(PurePanel);
|
||||
}
|
||||
};
|
||||
|
||||
export default genPurePanel;
|
||||
|
@ -1,7 +1,7 @@
|
||||
type RecordType = Record<string, any>;
|
||||
import type { AnyObject } from './type';
|
||||
|
||||
function extendsObject<T extends RecordType>(...list: T[]) {
|
||||
const result: RecordType = { ...list[0] };
|
||||
const extendsObject = <T extends AnyObject = AnyObject>(...list: T[]) => {
|
||||
const result: AnyObject = { ...list[0] };
|
||||
|
||||
for (let i = 1; i < list.length; i++) {
|
||||
const obj = list[i];
|
||||
@ -16,6 +16,6 @@ function extendsObject<T extends RecordType>(...list: T[]) {
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
export default extendsObject;
|
||||
|
@ -9,9 +9,5 @@ export const getRenderPropValue = (
|
||||
return null;
|
||||
}
|
||||
|
||||
if (typeof propValue === 'function') {
|
||||
return propValue();
|
||||
}
|
||||
|
||||
return propValue;
|
||||
return typeof propValue === 'function' ? propValue() : propValue;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user