11<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"
69 >
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" >
1612 <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 >
2613 </slot >
14+ <CButtonClose
15+ v-if =" !props.noCloseButton"
16+ @click =" close()"
17+ class =" c-ml-2 c-mb-1"
18+ />
2719 </div >
28- </transition >
20+ <slot >
21+ <div class =" c-toast-body" v-html =" props.bodyHtml" ></div >
22+ </slot >
23+ </div >
2924</template >
3025
3126<script >
3227import toastMixin from ' ./toastMixin'
3328import CButtonClose from ' ../Button/CButtonClose'
29+ const props = Object .assign ({}, toastMixin .props , {
30+ show: Boolean
31+ })
3432
3533export default {
3634 name: ' CToast' ,
3735 mixins: [ toastMixin ],
36+ props,
3837 components: {
3938 CButtonClose
4039 },
@@ -45,37 +44,52 @@ export default {
4544 },
4645 data () {
4746 return {
48- isClosed : false ,
47+ isShowed : this . show ,
4948 timeout: null
5049 }
5150 },
51+ watch: {
52+ show (val ) {
53+ this .isShowed = val
54+ }
55+ },
5256 mounted () {
5357 if (this .props .autohide ) {
5458 this .setAutohide ()
5559 }
5660 },
5761 computed: {
5862 toastClasses () {
59- return [' c-toast' ,
63+ return [
64+ ' c-toast' ,
6065 {
61- ' c-show' : this .props . show ,
66+ ' c-show' : this .isShowed ,
6267 ' c-full' : this .props .position .includes (' full' )
6368 }
6469 ]
6570 },
71+ directlyDeclaredProps () {
72+ return Object .keys (this .$options .propsData )
73+ },
74+ injectedProps () {
75+ return this .toaster && this .toaster .props ? this .toaster .props : {}
76+ },
6677 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
7284 }, {})
7385 }
7486 },
7587 methods: {
7688 close () {
77- this .isClosed = true
89+ this .isShowed = false
90+ this .$emit (' update:show' , false )
7891 this .$el .removeEventListener (' mouseover' , this .onHover )
92+ this .$el .removeEventListener (' mouseout' , this .onHoverOut )
7993 },
8094 onHover () {
8195 this .$el .removeEventListener (' mouseover' , this .onHover )
@@ -100,12 +114,6 @@ export default {
100114 .toast.full {
101115 max-width : 100% ;
102116 }
103- .fade-enter , .fade-leave-to {
104- opacity : 0 ;
105- }
106- .fade-enter-active , .fade-leave-active {
107- transition : opacity .3s ;
108- }
109117 @import " ~@coreui/coreui/scss/partials/toasts.scss" ;
110118 @import " ~@coreui/coreui/scss/utilities/_spacing.scss" ;
111119
0 commit comments