diff --git a/src/drawer/index.tsx b/src/drawer/index.tsx index 4d0e7ec91..b3876fc8b 100644 --- a/src/drawer/index.tsx +++ b/src/drawer/index.tsx @@ -5,6 +5,7 @@ import classNames from 'classnames'; import { omit } from 'lodash-es'; import RcDrawer, { DrawerProps as AntdDrawerProps } from 'rc-drawer'; +import { isAlertObjectProps } from '../utils'; import motionProps from './motion'; import './style.scss'; @@ -67,11 +68,6 @@ const getWidthFromSize = (size: DrawerProps['size']) => { return `${(DrawerSize.Default / 1440) * 100}%`; }; -const isValidBanner = (banner: DrawerProps['banner']): banner is AlertProps['message'] => { - if (typeof banner === 'object') return React.isValidElement(banner); - return true; -}; - const Drawer = (props: DrawerProps) => { const drawerPrefixCls = 'dtc-drawer'; @@ -148,9 +144,9 @@ const Drawer = (props: DrawerProps) => { )} {banner && ( )} {isTabMode(props) && ( diff --git a/src/modal/modal.tsx b/src/modal/modal.tsx index 4606632fd..86474130d 100644 --- a/src/modal/modal.tsx +++ b/src/modal/modal.tsx @@ -6,6 +6,7 @@ import { omit } from 'lodash-es'; import Float, { type IFloatProps } from '../float'; import useMergeOption, { type MergeOption } from '../useMergeOption'; +import { isAlertObjectProps } from '../utils'; import Handler from './handle'; import './index.scss'; @@ -29,11 +30,6 @@ const getWidthFromSize = (size: IModalProps['size']) => { return 520; }; -const isValidBanner = (banner: IModalProps['banner']): banner is AlertProps['message'] => { - if (typeof banner === 'object') return React.isValidElement(banner); - return true; -}; - export default function InternalModal({ bodyStyle, banner, @@ -137,9 +133,9 @@ export default function InternalModal({ {banner && ( )}
{children}
diff --git a/src/utils/index.ts b/src/utils/index.ts index aaec266c3..dbf743e26 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,5 +1,5 @@ import React from 'react'; -import { TooltipProps } from 'antd'; +import { AlertProps, TooltipProps } from 'antd'; export type LabelTooltipType = TooltipProps | TooltipProps['title']; @@ -11,3 +11,14 @@ export function toTooltipProps(tooltip: LabelTooltipType): TooltipProps | null { title: tooltip, }; } + +type BannerPropType = AlertProps['message'] | Omit; + +export function isAlertObjectProps(banner: BannerPropType): banner is Omit { + return ( + typeof banner === 'object' && + banner !== null && + !React.isValidElement(banner) && + 'message' in banner + ); +}