1
1
<template >
2
- <transition
3
- :name =" 0 ? null : 'fade'"
4
- :appear =" true"
5
- v-if =" !isClosed"
2
+ <div
3
+ :class =" toastClasses"
4
+ role =" alert"
5
+ aria-live =" assertive"
6
+ aria-atomic =" true"
7
+ :style =" computedStyles"
8
+ v-if =" isShowed"
6
9
>
7
- <div
8
- :class =" [toastClasses]"
9
- role =" alert"
10
- aria-live =" assertive"
11
- aria-atomic =" true"
12
- style =" z-index :1100 "
13
- :style =" computedStyles"
14
- >
15
- <div v-if =" !props.noHeader" class =" c-toast-header" >
10
+ <div v-if =" !props.noHeader" class =" c-toast-header" >
11
+ <slot name =" title" >
16
12
<strong class =" c-mr-auto" v-html =" props.titleHtml" ></strong >
17
- <CButtonClose
18
- v-if =" !props.noCloseButton"
19
- @click =" close()"
20
- class =" c-ml-2 c-mb-1"
21
- />
22
- </div >
23
- <slot :close =" close" >
24
- <div class =" c-toast-body" v-html =" props.bodyHtml" >
25
- </div >
26
13
</slot >
14
+ <CButtonClose
15
+ v-if =" !props.noCloseButton"
16
+ @click =" close()"
17
+ class =" c-ml-2 c-mb-1"
18
+ />
27
19
</div >
28
- </transition >
20
+ <slot >
21
+ <div class =" c-toast-body" v-html =" props.bodyHtml" ></div >
22
+ </slot >
23
+ </div >
29
24
</template >
30
25
31
26
<script >
32
27
import toastMixin from ' ./toastMixin'
33
28
import CButtonClose from ' ../Button/CButtonClose'
29
+ const props = Object .assign ({}, toastMixin .props , {
30
+ show: Boolean
31
+ })
34
32
35
33
export default {
36
34
name: ' CToast' ,
37
35
mixins: [ toastMixin ],
36
+ props,
38
37
components: {
39
38
CButtonClose
40
39
},
@@ -45,37 +44,52 @@ export default {
45
44
},
46
45
data () {
47
46
return {
48
- isClosed : false ,
47
+ isShowed : this . show ,
49
48
timeout: null
50
49
}
51
50
},
51
+ watch: {
52
+ show (val ) {
53
+ this .isShowed = val
54
+ }
55
+ },
52
56
mounted () {
53
57
if (this .props .autohide ) {
54
58
this .setAutohide ()
55
59
}
56
60
},
57
61
computed: {
58
62
toastClasses () {
59
- return [' c-toast' ,
63
+ return [
64
+ ' c-toast' ,
60
65
{
61
- ' c-show' : this .props . show ,
66
+ ' c-show' : this .isShowed ,
62
67
' c-full' : this .props .position .includes (' full' )
63
68
}
64
69
]
65
70
},
71
+ directlyDeclaredProps () {
72
+ return Object .keys (this .$options .propsData )
73
+ },
74
+ injectedProps () {
75
+ return this .toaster && this .toaster .props ? this .toaster .props : {}
76
+ },
66
77
props () {
67
- return Object .keys (toastMixin .props ).reduce ((props , key ) => {
68
- const propUndefined = ! Object .keys (this .$options .propsData ).includes (key)
69
- const propInheritedFromToaster = propUndefined && this .toaster .props [key]
70
- props[key] = propInheritedFromToaster ? this .toaster .props [key] : this [key]
71
- return props
78
+ return Object .keys (toastMixin .props ).reduce ((computedProps , key ) => {
79
+ const propIsDirectlyDeclared = this .directlyDeclaredProps .includes (key)
80
+ const parentPropExists = this .injectedProps [key] !== undefined
81
+ const propIsInherited = parentPropExists && ! propIsDirectlyDeclared
82
+ computedProps[key] = propIsInherited ? this .injectedProps [key] : this [key]
83
+ return computedProps
72
84
}, {})
73
85
}
74
86
},
75
87
methods: {
76
88
close () {
77
- this .isClosed = true
89
+ this .isShowed = false
90
+ this .$emit (' update:show' , false )
78
91
this .$el .removeEventListener (' mouseover' , this .onHover )
92
+ this .$el .removeEventListener (' mouseout' , this .onHoverOut )
79
93
},
80
94
onHover () {
81
95
this .$el .removeEventListener (' mouseover' , this .onHover )
@@ -100,12 +114,6 @@ export default {
100
114
.toast.full {
101
115
max-width : 100% ;
102
116
}
103
- .fade-enter , .fade-leave-to {
104
- opacity : 0 ;
105
- }
106
- .fade-enter-active , .fade-leave-active {
107
- transition : opacity .3s ;
108
- }
109
117
@import " ~@coreui/coreui/scss/partials/toasts.scss" ;
110
118
@import " ~@coreui/coreui/scss/utilities/_spacing.scss" ;
111
119
0 commit comments