From 8e35b7ae741536162a4131d04da14f71c522c77d Mon Sep 17 00:00:00 2001 From: LuckyFBB <976060700@qq.com> Date: Mon, 31 Mar 2025 11:23:33 +0800 Subject: [PATCH] fix(drawer): update Drawer ts type --- src/drawer/index.tsx | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/drawer/index.tsx b/src/drawer/index.tsx index 9bd34832a..41b704c57 100644 --- a/src/drawer/index.tsx +++ b/src/drawer/index.tsx @@ -22,7 +22,7 @@ export enum DrawerType { Normal = 'normal', } -interface NormalDrawerProps extends Omit { +interface BaseDrawerProps extends Omit { size?: 'small' | 'default' | 'large'; loading?: boolean; bodyClassName?: string; @@ -33,35 +33,35 @@ interface NormalDrawerProps extends Omit { type?: DrawerType; } -interface TabsDrawerProps extends Omit { +export interface DrawerProps extends BaseDrawerProps { tabs?: T; defaultKey?: TabKey; activeKey?: TabKey; - children?: (key: TabKey) => React.ReactNode; + children?: React.ReactNode | ((key: TabKey) => React.ReactNode); onChange?: (key: TabKey) => void; } -function isFunction(props: DrawerProps): props is TabsDrawerProps { +function isFunction( + props: DrawerProps +): props is DrawerProps & { children: (key: string) => React.ReactNode } { return typeof props.children === 'function'; } -function isTabMode(props: DrawerProps): props is TabsDrawerProps { +function isTabMode(props: DrawerProps): props is DrawerProps { return 'tabs' in props; } -function isControlled(props: DrawerProps): props is TabsDrawerProps { +function isControlled(props: DrawerProps): props is DrawerProps { return 'activeKey' in props; } -export type DrawerProps = TabsDrawerProps | NormalDrawerProps; - -const getWidthFromSize = (size: NormalDrawerProps['size']) => { +const getWidthFromSize = (size: DrawerProps['size']) => { if (size === 'small') return 720; if (size === 'large') return 1256; return 1000; }; -const isValidBanner = (banner: NormalDrawerProps['banner']): banner is AlertProps['message'] => { +const isValidBanner = (banner: DrawerProps['banner']): banner is AlertProps['message'] => { if (typeof banner === 'object') return React.isValidElement(banner); return true; }; @@ -163,7 +163,9 @@ const Drawer = (props: DrawerProps) => { className={classNames(`${slidePrefixCls}-body`, bodyClassName)} style={bodyStyle} > - {isFunction(props) ? props.children?.(currentKey ?? '') : props.children} + {isFunction(props) + ? props.children?.(currentKey ?? '') + : (props.children as React.ReactNode)} {footer ? (
{footer}