summaryrefslogtreecommitdiff
path: root/packages/client/src/components/toast.vue
blob: c1143797167730e42b50a0d8ec6bd67d8bc317a1 (plain)
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
<template>
<div class="mk-toast">
	<transition :name="$store.state.animation ? 'toast' : ''" appear @after-leave="emit('closed')">
		<div v-if="showing" class="body _acrylic" :style="{ zIndex }">
			<div class="message">
				{{ message }}
			</div>
		</div>
	</transition>
</div>
</template>

<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import * as os from '@/os';

defineProps<{
	message: string;
}>();

const emit = defineEmits<{
	(e: 'closed'): void;
}>();

const showing = ref(true);
const zIndex = os.claimZIndex('high');

onMounted(() => {
	window.setTimeout(() => {
		showing.value = false;
	}, 4000);
});
</script>

<style lang="scss" scoped>
.toast-enter-active, .toast-leave-active {
	transition: opacity 0.3s, transform 0.3s !important;
}
.toast-enter-from, .toast-leave-to {
	opacity: 0;
	transform: translateY(-100%);
}

.mk-toast {
	> .body {
		position: fixed;
		left: 0;
		right: 0;
		top: 0;
		margin: 0 auto;
		margin-top: 16px;
		min-width: 300px;
		max-width: calc(100% - 32px);
		width: min-content;
		box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
		border-radius: 8px;
		overflow: clip;
		text-align: center;
		pointer-events: none;

		> .message {
			padding: 16px 24px;
		}
	}
}
</style>