@@ -50,11 +50,47 @@ function Button(props: DButtonProps, ref: React.ForwardedRef<HTMLButtonElement>)
5050 const disabled = restProps . disabled || dLoading || gDisabled ;
5151
5252 const buttonIcon = ( loading : boolean , iconRef ?: React . RefObject < HTMLDivElement > , style ?: React . CSSProperties ) => (
53- < div ref = { iconRef } className = { `${ dPrefix } button__icon` } style = { style } >
53+ < div
54+ ref = { iconRef }
55+ className = { getClassName ( `${ dPrefix } button__icon` , {
56+ [ `${ dPrefix } button__icon--right` ] : dIconRight ,
57+ } ) }
58+ style = { style }
59+ >
5460 { loading ? < LoadingOutlined dSpin /> : dIcon }
5561 </ div >
5662 ) ;
5763
64+ const iconNode = checkNodeExist ( dIcon ) ? (
65+ buttonIcon ( dLoading )
66+ ) : (
67+ < DCollapseTransition
68+ dOriginalSize = { {
69+ width : '' ,
70+ } }
71+ dCollapsedStyle = { {
72+ width : 0 ,
73+ } }
74+ dIn = { dLoading }
75+ dDuring = { TTANSITION_DURING_SLOW }
76+ dHorizontal
77+ dStyles = { {
78+ entering : {
79+ transition : [ 'width' , 'padding' , 'margin' ] . map ( ( attr ) => `${ attr } ${ TTANSITION_DURING_SLOW } ms linear` ) . join ( ', ' ) ,
80+ } ,
81+ leaving : {
82+ transition : [ 'width' , 'padding' , 'margin' ] . map ( ( attr ) => `${ attr } ${ TTANSITION_DURING_SLOW } ms linear` ) . join ( ', ' ) ,
83+ } ,
84+ leaved : { display : 'none' } ,
85+ } }
86+ dDestroyWhenLeaved
87+ >
88+ { ( collapseRef , collapseStyle ) => buttonIcon ( true , collapseRef , collapseStyle ) }
89+ </ DCollapseTransition >
90+ ) ;
91+
92+ const contentNode = < div > { children } </ div > ;
93+
5894 return (
5995 < DBaseDesign
6096 dComposeDesign = { {
@@ -72,7 +108,6 @@ function Button(props: DButtonProps, ref: React.ForwardedRef<HTMLButtonElement>)
72108 [ `${ dPrefix } button--${ size } ` ] : size ,
73109 [ `${ dPrefix } button--block` ] : dBlock ,
74110 [ `${ dPrefix } button--icon` ] : ! children ,
75- [ `${ dPrefix } button--icon-right` ] : dIconRight ,
76111 'is-loading' : dLoading ,
77112 } ) }
78113 type = { restProps . type ?? 'button' }
@@ -85,34 +120,17 @@ function Button(props: DButtonProps, ref: React.ForwardedRef<HTMLButtonElement>)
85120 }
86121 } }
87122 >
88- { checkNodeExist ( dIcon ) ? (
89- buttonIcon ( dLoading )
123+ { dIconRight ? (
124+ < >
125+ { contentNode }
126+ { iconNode }
127+ </ >
90128 ) : (
91- < DCollapseTransition
92- dOriginalSize = { {
93- width : '' ,
94- } }
95- dCollapsedStyle = { {
96- width : 0 ,
97- } }
98- dIn = { dLoading }
99- dDuring = { TTANSITION_DURING_SLOW }
100- dHorizontal
101- dStyles = { {
102- entering : {
103- transition : [ 'width' , 'padding' , 'margin' ] . map ( ( attr ) => `${ attr } ${ TTANSITION_DURING_SLOW } ms linear` ) . join ( ', ' ) ,
104- } ,
105- leaving : {
106- transition : [ 'width' , 'padding' , 'margin' ] . map ( ( attr ) => `${ attr } ${ TTANSITION_DURING_SLOW } ms linear` ) . join ( ', ' ) ,
107- } ,
108- leaved : { display : 'none' } ,
109- } }
110- dDestroyWhenLeaved
111- >
112- { ( collapseRef , collapseStyle ) => buttonIcon ( true , collapseRef , collapseStyle ) }
113- </ DCollapseTransition >
129+ < >
130+ { iconNode }
131+ { contentNode }
132+ </ >
114133 ) }
115- < div > { children } </ div >
116134 { waveNode }
117135 </ button >
118136 )
0 commit comments