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 1
1
<template >
2
- <transition :name =" ! props.noFade ? 'fade' : null" appear >
2
+ <transition :name =" props.fade ? 'fade' : null" appear >
3
3
<div
4
4
v-show =" isShowed"
5
5
:class =" toastClasses"
8
8
aria-atomic =" true"
9
9
:style =" computedStyles"
10
10
>
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 >
14
14
</slot >
15
15
<CButtonClose
16
- v-if =" ! props.noCloseButton "
16
+ v-if =" props.closeButton "
17
17
@click =" close()"
18
18
class =" ml-2 mb-1"
19
19
/>
20
20
</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 >
24
25
</div >
25
26
</transition >
26
27
</template >
@@ -33,7 +34,9 @@ export default {
33
34
name: ' CToast' ,
34
35
mixins: [ toastMixin ],
35
36
props: {
36
- show: Boolean
37
+ show: Boolean ,
38
+ headerHtml: String ,
39
+ bodyHtml: String
37
40
},
38
41
components: {
39
42
CButtonClose
@@ -96,12 +99,16 @@ export default {
96
99
})
97
100
},
98
101
close (restoreOnHover = false ) {
102
+ if (this .isShowed === false ) {
103
+ return
104
+ }
105
+
99
106
this .isShowed = false
100
107
this .$emit (' update:show' , false )
101
108
this .$el .removeEventListener (' mouseout' , this .onHoverOut )
102
109
this .$el .removeEventListener (' mouseover' , this .onHover )
103
110
104
- if (! this .props .noFade ) {
111
+ if (this .props .fade ) {
105
112
this .setHiddingMode (restoreOnHover)
106
113
}
107
114
},
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ const ComponentName = 'CToast'
5
5
const wrapper = mount ( Component , {
6
6
propsData : {
7
7
show : true ,
8
- noFade : true ,
8
+ fade : false ,
9
9
position : 'static'
10
10
}
11
11
} )
@@ -14,10 +14,10 @@ const customWrapper = mount(Component, {
14
14
propsData : {
15
15
show : true ,
16
16
position : 'bottom-center' ,
17
- titleHtml : 'title' ,
17
+ headerHtml : 'title' ,
18
18
noHeader : false ,
19
19
autohide : 10 ,
20
- noCloseButton : false
20
+ closeButton : true
21
21
} ,
22
22
slots : {
23
23
default : 'CToast body'
@@ -31,7 +31,7 @@ describe(ComponentName, () => {
31
31
it ( 'renders correctly' , ( ) => {
32
32
expect ( wrapper . element ) . toMatchSnapshot ( )
33
33
} )
34
- it ( 'renders correctly' , ( ) => {
34
+ it ( 'renders correctly custom wrapper ' , ( ) => {
35
35
expect ( customWrapper . element ) . toMatchSnapshot ( )
36
36
} )
37
37
it ( 'closes by watcher correctly' , ( ) => {
Original file line number Diff line number Diff line change @@ -5,19 +5,22 @@ const ComponentName = 'CToaster'
5
5
6
6
const toast = {
7
7
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
+ )
9
13
}
10
14
}
11
15
12
16
const defaultWrapper = mount ( Component )
13
- const customWrapper2 = mount ( Component , {
17
+ const customWrapper = mount ( Component , {
14
18
propsData : {
15
19
position : 'top-left' ,
16
- titleHtml : 'title' ,
17
- noHeader : false ,
20
+ hasHeader : false ,
18
21
autohide : 3000 ,
19
- noCloseButton : false ,
20
- noFade : false
22
+ closeButton : false ,
23
+ fade : false
21
24
} ,
22
25
slots : {
23
26
default : toast
@@ -31,7 +34,7 @@ describe(ComponentName, () => {
31
34
it ( 'renders correctly' , ( ) => {
32
35
expect ( defaultWrapper . element ) . toMatchSnapshot ( )
33
36
} )
34
- it ( 'renders correctly' , ( ) => {
35
- expect ( customWrapper2 . element ) . toMatchSnapshot ( )
37
+ it ( 'renders correctly custom wrapper ' , ( ) => {
38
+ expect ( customWrapper . element ) . toMatchSnapshot ( )
36
39
} )
37
40
} )
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ exports[`CToast renders correctly 1`] = `
30
30
</div >
31
31
` ;
32
32
33
- exports [` CToast renders correctly 2 ` ] = `
33
+ exports [` CToast renders correctly custom wrapper 1 ` ] = `
34
34
<div
35
35
appear = " "
36
36
aria-atomic = " true"
@@ -45,9 +45,7 @@ exports[`CToast renders correctly 2`] = `
45
45
>
46
46
<strong
47
47
class = " mr-auto"
48
- >
49
- title
50
- </strong >
48
+ />
51
49
52
50
<button
53
51
aria-label = " Close"
@@ -57,6 +55,11 @@ exports[`CToast renders correctly 2`] = `
57
55
×
58
56
</button >
59
57
</div >
60
- CToast body
58
+
59
+ <div
60
+ class = " toast-body"
61
+ >
62
+ CToast body
63
+ </div >
61
64
</div >
62
65
` ;
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ exports[`CToaster renders correctly 1`] = `
7
7
/>
8
8
` ;
9
9
10
- exports [` CToaster renders correctly 2 ` ] = `
10
+ exports [` CToaster renders correctly custom wrapper 1 ` ] = `
11
11
<div
12
12
class = " toaster"
13
13
style = " z-index: 1100; min-width: 350px; position: fixed; top: 0px; left: 0px;"
@@ -17,27 +17,15 @@ exports[`CToaster renders correctly 2`] = `
17
17
aria-atomic = " true"
18
18
aria-live = " assertive"
19
19
class = " toast"
20
- name = " fade"
21
20
role = " alert"
22
21
>
22
+ <!---->
23
+
23
24
<div
24
- class = " toast-header "
25
+ class = " toast-body "
25
26
>
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
39
28
</div >
40
- toast body
41
29
</div >
42
30
</div >
43
31
` ;
Original file line number Diff line number Diff line change @@ -10,15 +10,22 @@ export default {
10
10
] . includes ( position )
11
11
}
12
12
} ,
13
- titleHtml : String ,
14
- bodyHtml : String ,
15
- noHeader : Boolean ,
13
+ hasHeader : {
14
+ type : Boolean ,
15
+ default : true
16
+ } ,
16
17
autohide : {
17
18
type : [ Number , Boolean ] ,
18
19
validator : val => typeof val === 'number' || val === false
19
20
} ,
20
- noCloseButton : Boolean ,
21
- noFade : Boolean
21
+ closeButton : {
22
+ type : Boolean ,
23
+ default : true
24
+ } ,
25
+ fade : {
26
+ type : Boolean ,
27
+ default : true
28
+ }
22
29
} ,
23
30
computed : {
24
31
computedStyles ( ) {
Original file line number Diff line number Diff line change @@ -583,16 +583,16 @@ export declare class CTab extends Vue {
583
583
584
584
declare class ToastProps extends Vue {
585
585
position : string
586
- titleHtml : string
587
- bodyHtml : string
588
- noHeader : boolean
586
+ hasHeader : boolean
589
587
autohide : number
590
- noCloseButton : boolean
591
- noFade : boolean
588
+ closeButton : boolean
589
+ fade : boolean
592
590
}
593
591
594
592
export declare class CToast extends ToastProps {
595
593
show : boolean
594
+ headerHtml : string
595
+ bodyHtml : string
596
596
}
597
597
598
598
export declare class CToaster extends ToastProps {
You can’t perform that action at this time.
0 commit comments