-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
114 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<script setup lang="ts"> | ||
import type { MessageOptions } from './useMessage' | ||
import Message from './index.vue' | ||
interface MessageItem extends MessageOptions { | ||
key: number | ||
} | ||
const messages = ref<MessageItem[]>([]) | ||
let keyCounter = 0 | ||
function addMessage(options: MessageOptions) { | ||
const key = keyCounter++ | ||
messages.value.push({ ...options, key }) | ||
setTimeout(() => { | ||
removeMessage(key) | ||
}, options.timeout || 3000) | ||
} | ||
function removeMessage(key: number) { | ||
messages.value = messages.value.filter(msg => msg.key !== key) | ||
} | ||
defineExpose({ | ||
addMessage, | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div class="fixed left-1/2 top-4 z-50 flex w-full -translate-x-1/2 flex-col gap-4"> | ||
<transition-group name="message_container"> | ||
<div | ||
v-for="msg in messages" | ||
:key="msg.key" | ||
class="flex w-full justify-center" | ||
> | ||
<Message v-bind="msg" /> | ||
</div> | ||
</transition-group> | ||
</div> | ||
</template> | ||
|
||
<style scoped> | ||
.message_container-move, | ||
.message_container-enter-active, | ||
.message_container-leave-active { | ||
transition: all 0.3s ease; | ||
} | ||
.message_container-enter-from, | ||
.message_container-leave-to { | ||
transform: translateY(calc(-100% - 1rem)); | ||
} | ||
.message_container-leave-active { | ||
position: absolute; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<script setup lang="ts"> | ||
defineProps<{ | ||
type: 'info' | 'success' | 'warning' | 'error' | ||
}>() | ||
</script> | ||
|
||
<template> | ||
<svg v-if="type === 'info'" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24"> | ||
<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"> | ||
<circle cx="12" cy="12" r="10" /><path d="M12 16v-4m0-4h.01" /> | ||
</g> | ||
</svg> | ||
<svg v-else-if="type === 'success'" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24"> | ||
<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 6L9 17l-5-5" /> | ||
</svg> | ||
<svg v-else-if="type === 'warning'" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24"> | ||
<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"> | ||
<circle cx="12" cy="12" r="10" /><path d="M12 8v4m0 4h.01" /> | ||
</g> | ||
</svg> | ||
<svg v-else xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24"> | ||
<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M18 6L6 18M6 6l12 12" /> | ||
</svg> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters