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';
5
5
import { omit } from 'lodash-es' ;
6
6
import RcDrawer , { DrawerProps as AntdDrawerProps } from 'rc-drawer' ;
7
7
8
+ import { isAlertObjectProps } from '../utils' ;
8
9
import motionProps from './motion' ;
9
10
import './style.scss' ;
10
11
@@ -67,11 +68,6 @@ const getWidthFromSize = (size: DrawerProps['size']) => {
67
68
return `${ ( DrawerSize . Default / 1440 ) * 100 } %` ;
68
69
} ;
69
70
70
- const isValidBanner = ( banner : DrawerProps [ 'banner' ] ) : banner is AlertProps [ 'message' ] => {
71
- if ( typeof banner === 'object' ) return React . isValidElement ( banner ) ;
72
- return true ;
73
- } ;
74
-
75
71
const Drawer = < T extends readOnlyTab > ( props : DrawerProps < T > ) => {
76
72
const drawerPrefixCls = 'dtc-drawer' ;
77
73
@@ -148,9 +144,9 @@ const Drawer = <T extends readOnlyTab>(props: DrawerProps<T>) => {
148
144
) }
149
145
{ banner && (
150
146
< Alert
151
- message = { isValidBanner ( banner ) ? banner : ( banner as any ) . message }
147
+ message = { isAlertObjectProps ( banner ) ? banner . message : banner }
152
148
banner
153
- { ...( isValidBanner ( banner ) ? { } : omit ( banner , 'message' ) ) }
149
+ { ...( isAlertObjectProps ( banner ) ? omit ( banner , 'message' ) : { } ) }
154
150
/>
155
151
) }
156
152
{ isTabMode ( props ) && (
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import { omit } from 'lodash-es';
6
6
7
7
import Float , { type IFloatProps } from '../float' ;
8
8
import useMergeOption , { type MergeOption } from '../useMergeOption' ;
9
+ import { isAlertObjectProps } from '../utils' ;
9
10
import Handler from './handle' ;
10
11
import './index.scss' ;
11
12
@@ -29,11 +30,6 @@ const getWidthFromSize = (size: IModalProps['size']) => {
29
30
return 520 ;
30
31
} ;
31
32
32
- const isValidBanner = ( banner : IModalProps [ 'banner' ] ) : banner is AlertProps [ 'message' ] => {
33
- if ( typeof banner === 'object' ) return React . isValidElement ( banner ) ;
34
- return true ;
35
- } ;
36
-
37
33
export default function InternalModal ( {
38
34
bodyStyle,
39
35
banner,
@@ -137,9 +133,9 @@ export default function InternalModal({
137
133
{ banner && (
138
134
< Alert
139
135
className = "dtc-modal-alert"
140
- message = { isValidBanner ( banner ) ? banner : banner . message }
136
+ message = { isAlertObjectProps ( banner ) ? banner . message : banner }
141
137
banner
142
- { ...( isValidBanner ( banner ) ? { } : omit ( banner , 'message' ) ) }
138
+ { ...( isAlertObjectProps ( banner ) ? omit ( banner , 'message' ) : { } ) }
143
139
/>
144
140
) }
145
141
< section className = "dtc-modal-body" > { children } </ section >
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
- import { TooltipProps } from 'antd' ;
2
+ import { AlertProps , TooltipProps } from 'antd' ;
3
3
4
4
export type LabelTooltipType = TooltipProps | TooltipProps [ 'title' ] ;
5
5
@@ -11,3 +11,14 @@ export function toTooltipProps(tooltip: LabelTooltipType): TooltipProps | null {
11
11
title : tooltip ,
12
12
} ;
13
13
}
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 as any )
23
+ ) ;
24
+ }
You can’t perform that action at this time.
0 commit comments