File tree Expand file tree Collapse file tree 7 files changed +62
-54
lines changed
Expand file tree Collapse file tree 7 files changed +62
-54
lines changed Original file line number Diff line number Diff line change 11<template >
2- <transition :name =" ! props.noFade ? 'fade' : null" appear >
2+ <transition :name =" props.fade ? 'fade' : null" appear >
33 <div
44 v-show =" isShowed"
55 :class =" toastClasses"
88 aria-atomic =" true"
99 :style =" computedStyles"
1010 >
11- <div v-if =" ! props.noHeader " class =" toast-header" >
12- <slot name =" title " :close = " close " >
13- <strong class =" mr-auto" v-html =" props.titleHtml " ></strong >
11+ <div v-if =" props.hasHeader " class =" toast-header" >
12+ <slot name =" header " >
13+ <strong class =" mr-auto" v-html =" props.headerHtml " ></strong >
1414 </slot >
1515 <CButtonClose
16- v-if =" ! props.noCloseButton "
16+ v-if =" props.closeButton "
1717 @click =" close()"
1818 class =" ml-2 mb-1"
1919 />
2020 </div >
21- <slot >
22- <div class =" toast-body" v-html =" props.bodyHtml" ></div >
23- </slot >
21+ <div v-if =" $slots.default" class =" toast-body" >
22+ <slot ></slot >
23+ </div >
24+ <div v-else class =" toast-body" v-html =" props.bodyHtml" ></div >
2425 </div >
2526 </transition >
2627</template >
@@ -33,7 +34,9 @@ export default {
3334 name: ' CToast' ,
3435 mixins: [ toastMixin ],
3536 props: {
36- show: Boolean
37+ show: Boolean ,
38+ headerHtml: String ,
39+ bodyHtml: String
3740 },
3841 components: {
3942 CButtonClose
@@ -96,12 +99,16 @@ export default {
9699 })
97100 },
98101 close (restoreOnHover = false ) {
102+ if (this .isShowed === false ) {
103+ return
104+ }
105+
99106 this .isShowed = false
100107 this .$emit (' update:show' , false )
101108 this .$el .removeEventListener (' mouseout' , this .onHoverOut )
102109 this .$el .removeEventListener (' mouseover' , this .onHover )
103110
104- if (! this .props .noFade ) {
111+ if (this .props .fade ) {
105112 this .setHiddingMode (restoreOnHover)
106113 }
107114 },
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ const ComponentName = 'CToast'
55const wrapper = mount ( Component , {
66 propsData : {
77 show : true ,
8- noFade : true ,
8+ fade : false ,
99 position : 'static'
1010 }
1111} )
@@ -14,10 +14,10 @@ const customWrapper = mount(Component, {
1414 propsData : {
1515 show : true ,
1616 position : 'bottom-center' ,
17- titleHtml : 'title' ,
17+ headerHtml : 'title' ,
1818 noHeader : false ,
1919 autohide : 10 ,
20- noCloseButton : false
20+ closeButton : true
2121 } ,
2222 slots : {
2323 default : 'CToast body'
@@ -31,7 +31,7 @@ describe(ComponentName, () => {
3131 it ( 'renders correctly' , ( ) => {
3232 expect ( wrapper . element ) . toMatchSnapshot ( )
3333 } )
34- it ( 'renders correctly' , ( ) => {
34+ it ( 'renders correctly custom wrapper ' , ( ) => {
3535 expect ( customWrapper . element ) . toMatchSnapshot ( )
3636 } )
3737 it ( 'closes by watcher correctly' , ( ) => {
Original file line number Diff line number Diff line change @@ -5,19 +5,22 @@ const ComponentName = 'CToaster'
55
66const toast = {
77 render ( h ) {
8- return h ( CToast , { props : { show : true } } , 'toast body' ) ;
8+ return h (
9+ CToast ,
10+ { props : { show : true , headerHtml : 'toast header' } } ,
11+ 'toast body'
12+ )
913 }
1014}
1115
1216const defaultWrapper = mount ( Component )
13- const customWrapper2 = mount ( Component , {
17+ const customWrapper = mount ( Component , {
1418 propsData : {
1519 position : 'top-left' ,
16- titleHtml : 'title' ,
17- noHeader : false ,
20+ hasHeader : false ,
1821 autohide : 3000 ,
19- noCloseButton : false ,
20- noFade : false
22+ closeButton : false ,
23+ fade : false
2124 } ,
2225 slots : {
2326 default : toast
@@ -31,7 +34,7 @@ describe(ComponentName, () => {
3134 it ( 'renders correctly' , ( ) => {
3235 expect ( defaultWrapper . element ) . toMatchSnapshot ( )
3336 } )
34- it ( 'renders correctly' , ( ) => {
35- expect ( customWrapper2 . element ) . toMatchSnapshot ( )
37+ it ( 'renders correctly custom wrapper ' , ( ) => {
38+ expect ( customWrapper . element ) . toMatchSnapshot ( )
3639 } )
3740} )
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ exports[`CToast renders correctly 1`] = `
3030</div >
3131` ;
3232
33- exports [` CToast renders correctly 2 ` ] = `
33+ exports [` CToast renders correctly custom wrapper 1 ` ] = `
3434<div
3535 appear = " "
3636 aria-atomic = " true"
@@ -45,9 +45,7 @@ exports[`CToast renders correctly 2`] = `
4545 >
4646 <strong
4747 class = " mr-auto"
48- >
49- title
50- </strong >
48+ />
5149
5250 <button
5351 aria-label = " Close"
@@ -57,6 +55,11 @@ exports[`CToast renders correctly 2`] = `
5755 ×
5856 </button >
5957 </div >
60- CToast body
58+
59+ <div
60+ class = " toast-body"
61+ >
62+ CToast body
63+ </div >
6164</div >
6265` ;
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ exports[`CToaster renders correctly 1`] = `
77/>
88` ;
99
10- exports [` CToaster renders correctly 2 ` ] = `
10+ exports [` CToaster renders correctly custom wrapper 1 ` ] = `
1111<div
1212 class = " toaster"
1313 style = " z-index: 1100; min-width: 350px; position: fixed; top: 0px; left: 0px;"
@@ -17,27 +17,15 @@ exports[`CToaster renders correctly 2`] = `
1717 aria-atomic = " true"
1818 aria-live = " assertive"
1919 class = " toast"
20- name = " fade"
2120 role = " alert"
2221 >
22+ <!---->
23+
2324 <div
24- class = " toast-header "
25+ class = " toast-body "
2526 >
26- <strong
27- class = " mr-auto"
28- >
29- title
30- </strong >
31-
32- <button
33- aria-label = " Close"
34- class = " ml-2 mb-1 close"
35- type = " button"
36- >
37- ×
38- </button >
27+ toast body
3928 </div >
40- toast body
4129 </div >
4230</div >
4331` ;
Original file line number Diff line number Diff line change @@ -10,15 +10,22 @@ export default {
1010 ] . includes ( position )
1111 }
1212 } ,
13- titleHtml : String ,
14- bodyHtml : String ,
15- noHeader : Boolean ,
13+ hasHeader : {
14+ type : Boolean ,
15+ default : true
16+ } ,
1617 autohide : {
1718 type : [ Number , Boolean ] ,
1819 validator : val => typeof val === 'number' || val === false
1920 } ,
20- noCloseButton : Boolean ,
21- noFade : Boolean
21+ closeButton : {
22+ type : Boolean ,
23+ default : true
24+ } ,
25+ fade : {
26+ type : Boolean ,
27+ default : true
28+ }
2229 } ,
2330 computed : {
2431 computedStyles ( ) {
Original file line number Diff line number Diff line change @@ -583,16 +583,16 @@ export declare class CTab extends Vue {
583583
584584declare class ToastProps extends Vue {
585585 position : string
586- titleHtml : string
587- bodyHtml : string
588- noHeader : boolean
586+ hasHeader : boolean
589587 autohide : number
590- noCloseButton : boolean
591- noFade : boolean
588+ closeButton : boolean
589+ fade : boolean
592590}
593591
594592export declare class CToast extends ToastProps {
595593 show : boolean
594+ headerHtml : string
595+ bodyHtml : string
596596}
597597
598598export declare class CToaster extends ToastProps {
You can’t perform that action at this time.
0 commit comments