File tree Expand file tree Collapse file tree 3 files changed +18
-15
lines changed Expand file tree Collapse file tree 3 files changed +18
-15
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import classNames from 'classnames';
55import { omit } from 'lodash-es' ;
66import RcDrawer , { DrawerProps as AntdDrawerProps } from 'rc-drawer' ;
77
8+ import { isAlertObjectProps } from '../utils' ;
89import motionProps from './motion' ;
910import './style.scss' ;
1011
@@ -67,11 +68,6 @@ const getWidthFromSize = (size: DrawerProps['size']) => {
6768 return `${ ( DrawerSize . Default / 1440 ) * 100 } %` ;
6869} ;
6970
70- const isValidBanner = ( banner : DrawerProps [ 'banner' ] ) : banner is AlertProps [ 'message' ] => {
71- if ( typeof banner === 'object' ) return React . isValidElement ( banner ) ;
72- return true ;
73- } ;
74-
7571const Drawer = < T extends readOnlyTab > ( props : DrawerProps < T > ) => {
7672 const drawerPrefixCls = 'dtc-drawer' ;
7773
@@ -148,9 +144,9 @@ const Drawer = <T extends readOnlyTab>(props: DrawerProps<T>) => {
148144 ) }
149145 { banner && (
150146 < Alert
151- message = { isValidBanner ( banner ) ? banner : ( banner as any ) . message }
147+ message = { isAlertObjectProps ( banner ) ? banner . message : banner }
152148 banner
153- { ...( isValidBanner ( banner ) ? { } : omit ( banner , 'message' ) ) }
149+ { ...( isAlertObjectProps ( banner ) ? omit ( banner , 'message' ) : { } ) }
154150 />
155151 ) }
156152 { isTabMode ( props ) && (
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import { omit } from 'lodash-es';
66
77import Float , { type IFloatProps } from '../float' ;
88import useMergeOption , { type MergeOption } from '../useMergeOption' ;
9+ import { isAlertObjectProps } from '../utils' ;
910import Handler from './handle' ;
1011import './index.scss' ;
1112
@@ -29,11 +30,6 @@ const getWidthFromSize = (size: IModalProps['size']) => {
2930 return 520 ;
3031} ;
3132
32- const isValidBanner = ( banner : IModalProps [ 'banner' ] ) : banner is AlertProps [ 'message' ] => {
33- if ( typeof banner === 'object' ) return React . isValidElement ( banner ) ;
34- return true ;
35- } ;
36-
3733export default function InternalModal ( {
3834 bodyStyle,
3935 banner,
@@ -138,9 +134,9 @@ export default function InternalModal({
138134 { banner && (
139135 < Alert
140136 className = "dtc-modal-alert"
141- message = { isValidBanner ( banner ) ? banner : banner . message }
137+ message = { isAlertObjectProps ( banner ) ? banner . message : banner }
142138 banner
143- { ...( isValidBanner ( banner ) ? { } : omit ( banner , 'message' ) ) }
139+ { ...( isAlertObjectProps ( banner ) ? omit ( banner , 'message' ) : { } ) }
144140 />
145141 ) }
146142 < section className = "dtc-modal-body" > { children } </ section >
Original file line number Diff line number Diff line change 11import React from 'react' ;
2- import { TooltipProps } from 'antd' ;
2+ import { AlertProps , TooltipProps } from 'antd' ;
33
44export type LabelTooltipType = TooltipProps | TooltipProps [ 'title' ] ;
55
@@ -11,3 +11,14 @@ export function toTooltipProps(tooltip: LabelTooltipType): TooltipProps | null {
1111 title : tooltip ,
1212 } ;
1313}
14+
15+ type BannerPropType = AlertProps [ 'message' ] | Omit < AlertProps , 'banner' > ;
16+
17+ export function isAlertObjectProps ( banner : BannerPropType ) : banner is Omit < AlertProps , 'banner' > {
18+ return (
19+ typeof banner === 'object' &&
20+ banner !== null &&
21+ ! React . isValidElement ( banner ) &&
22+ 'message' in banner
23+ ) ;
24+ }
You can’t perform that action at this time.
0 commit comments