@@ -4,12 +4,12 @@ import Icon from '../icon';
44import Loading from '../loading' ;
55
66const [ sfc , bem ] = use ( 'toast' ) ;
7- const STYLE = [ 'success' , 'fail' , 'loading' ] ;
87
98export default sfc ( {
109 mixins : [ PopupMixin ] ,
1110
1211 props : {
12+ icon : String ,
1313 className : null ,
1414 loadingType : String ,
1515 forbidClick : Boolean ,
@@ -62,6 +62,7 @@ export default sfc({
6262 }
6363 } ,
6464
65+ /* istanbul ignore next */
6566 onAfterEnter ( ) {
6667 this . $emit ( 'opened' ) ;
6768
@@ -72,31 +73,43 @@ export default sfc({
7273 } ,
7374
7475 render ( h ) {
75- const { type, message, loadingType } = this ;
76- const style = STYLE . indexOf ( type ) !== - 1 ? 'default' : type ;
77-
78- function Content ( ) {
79- switch ( style ) {
80- case 'text' :
81- return < div > { message } </ div > ;
82- case 'html' :
83- return < div domPropsInnerHTML = { message } /> ;
76+ const { type, icon, message, loadingType } = this ;
77+
78+ const hasIcon = icon || ( type === 'success' || type === 'fail' ) ;
79+
80+ function ToastIcon ( ) {
81+ if ( hasIcon ) {
82+ return < Icon class = { bem ( 'icon' ) } name = { icon || type } /> ;
83+ }
84+
85+ if ( type === 'loading' ) {
86+ return < Loading class = { bem ( 'loading' ) } color = "white" type = { loadingType } /> ;
87+ }
88+ }
89+
90+ function Message ( ) {
91+ if ( ! isDef ( message ) || message === '' ) {
92+ return ;
93+ }
94+
95+ if ( type === 'html' ) {
96+ return < div class = { bem ( 'text' ) } domPropsInnerHTML = { message } /> ;
8497 }
8598
86- return [
87- type === 'loading' ? (
88- < Loading color = "white" type = { loadingType } />
89- ) : (
90- < Icon class = { bem ( 'icon' ) } name = { type } />
91- ) ,
92- isDef ( message ) && < div class = { bem ( 'text' ) } > { message } </ div >
93- ] ;
99+ return < div class = { bem ( 'text' ) } > { message } </ div > ;
94100 }
95101
96102 return (
97103 < transition name = "van-fade" onAfterEnter = { this . onAfterEnter } >
98- < div vShow = { this . value } class = { [ bem ( [ style , this . position ] ) , this . className ] } >
99- { Content ( ) }
104+ < div
105+ vShow = { this . value }
106+ class = { [
107+ bem ( [ this . position , { text : ! hasIcon && type !== 'loading' } ] ) ,
108+ this . className
109+ ] }
110+ >
111+ { ToastIcon ( ) }
112+ { Message ( ) }
100113 </ div >
101114 </ transition >
102115 ) ;
0 commit comments