-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathMessage.vue
78 lines (74 loc) · 1.53 KB
/
Message.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<template>
<Transition name="fade">
<div class="msg-wrapper" v-if="msg.showMsg" @click="msg.showMsg = false">
<div class="msg" :style="style">
{{ message }}
</div>
</div>
</Transition>
</template>
<script>
// referenced on
// https://github.com/vuejs/vue-next/blob/master/packages/sfc-playground/src/Message.vue
import { computed, toRefs, watch } from 'vue'
import { msg } from '../store.js'
export default {
props: {
message: {
type: String,
required: true
},
color: {
type: String,
required: true
}
},
setup(props) {
const { message, color } = toRefs(props)
const style = computed(() => {
return {
borderColor: color.value,
color: color.value,
background: color.value === 'blue' ? '#dbeafe' : '#fee2e2'
}
})
watch(
() => msg.showMsg,
() => {
if (msg.showMsg) {
setTimeout(() => (msg.showMsg = false), 5000)
}
}
)
return { message, color, style, msg }
}
}
</script>
<style scoped>
.msg-wrapper {
position: fixed;
--msg-offset: 1.5rem;
bottom: var(--msg-offset);
right: var(--msg-offset);
left: 0;
padding-left: var(--msg-offset);
width: inherit;
z-index: 10;
}
.msg {
border-radius: 8px;
border-width: 2px;
border-style: solid;
margin-right: var(--msg-offset);
padding: 1rem 2rem;
}
.fade-enter-active,
.fade-leave-active {
transition: all 0.25s ease-out;
}
.fade-enter-from,
.fade-leave-to {
opacity: 0;
transform: translate(0, 10px);
}
</style>