-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathMessage.vue
122 lines (107 loc) · 2.1 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<!-- eslint-disable vue/multi-word-component-names -->
<script setup lang="ts">
import { ref, watch } from "vue";
import { CompilerError } from "@vue/compiler-sfc";
const props = defineProps(["err", "warn"]);
const dismissed = ref(false);
watch(
() => [props.err, props.warn],
() => {
dismissed.value = false;
}
);
function formatMessage(err: string | Error): string {
if (typeof err === "string") {
return err;
} else {
let msg = err.message;
const loc = (err as CompilerError).loc;
if (loc && loc.start) {
msg = `(${loc.start.line}:${loc.start.column}) ` + msg;
}
return msg;
}
}
</script>
<template>
<Transition name="fade">
<div
v-if="!dismissed && (err || warn)"
class="msg"
:class="err ? 'err' : 'warn'"
>
<pre>{{ formatMessage(err || warn) }}</pre>
<button class="dismiss" @click="dismissed = true">✕</button>
</div>
</Transition>
</template>
<style scoped>
.msg {
position: absolute;
bottom: 0;
left: 8px;
right: 8px;
z-index: 10;
border: 2px solid transparent;
border-radius: 6px;
font-family: var(--font-code);
white-space: pre-wrap;
margin-bottom: 8px;
max-height: calc(100% - 300px);
min-height: 40px;
display: flex;
align-items: stretch;
}
pre {
margin: 0;
padding: 12px 20px;
overflow: auto;
}
.dismiss {
position: absolute;
top: 2px;
right: 2px;
width: 18px;
height: 18px;
line-height: 18px;
border-radius: 9px;
text-align: center;
display: block;
font-size: 9px;
padding: 0;
background-color: red;
color: #fff;
}
@media (max-width: 720px) {
.dismiss {
top: -9px;
right: -9px;
}
.msg {
bottom: 50px;
}
}
.msg.err {
color: red;
border-color: red;
background-color: #ffd7d7;
}
.msg.warn {
--color: rgb(105, 95, 27);
color: var(--color);
border-color: var(--color);
background-color: rgb(247, 240, 205);
}
.msg.warn .dismiss {
background-color: var(--color);
}
.fade-enter-active,
.fade-leave-active {
transition: all 0.15s ease-out;
}
.fade-enter-from,
.fade-leave-to {
opacity: 0;
transform: translate(0, 10px);
}
</style>