|
| 1 | +<script setup lang="ts"> |
| 2 | + import { computed } from 'vue' |
| 3 | + import { useToastStore } from '@/stores/toast' |
| 4 | +
|
| 5 | + const toast = useToastStore() |
| 6 | +
|
| 7 | + const isVisible = computed(() => !!toast.message) |
| 8 | +
|
| 9 | + const accentColor = computed(() => { |
| 10 | + switch (toast.type) { |
| 11 | + case 'error': |
| 12 | + return 'var(--vscode-inputValidation-errorBorder, var(--vscode-editorError-foreground, #f14c4c))' |
| 13 | + case 'warning': |
| 14 | + return 'var(--vscode-inputValidation-warningBorder, var(--vscode-editorWarning-foreground, #cca700))' |
| 15 | + case 'info': |
| 16 | + default: |
| 17 | + return 'var(--vscode-inputValidation-infoBorder, var(--vscode-editorInfo-foreground, #3794ff))' |
| 18 | + } |
| 19 | + }) |
| 20 | +</script> |
| 21 | + |
| 22 | +<template> |
| 23 | + <transition name="toast-fade-slide"> |
| 24 | + <div |
| 25 | + v-if="isVisible" |
| 26 | + class="fixed z-[1000] right-4 bottom-4 max-w-md shadow-lg rounded border p-3 pr-8" |
| 27 | + :style="{ |
| 28 | + backgroundColor: 'var(--vscode-editorWidget-background, #1e1e1e)', |
| 29 | + color: 'var(--vscode-editor-foreground, #cccccc)', |
| 30 | + borderColor: 'var(--vscode-editorWidget-border, rgba(128,128,128,0.3))', |
| 31 | + boxShadow: '0 8px 24px rgba(0,0,0,0.24), 0 1px 2px rgba(0,0,0,0.4)', |
| 32 | + }" |
| 33 | + role="status" |
| 34 | + aria-live="polite" |
| 35 | + > |
| 36 | + <div class="flex items-start gap-2"> |
| 37 | + <span class="mt-[3px] inline-block w-1 h-5 rounded" :style="{ backgroundColor: accentColor }"></span> |
| 38 | + <div class="text-sm select-text whitespace-pre-line">{{ toast.message }}</div> |
| 39 | + </div> |
| 40 | + |
| 41 | + <button |
| 42 | + class="absolute top-2 right-2 w-6 h-6 flex items-center justify-center rounded hover:opacity-80" |
| 43 | + :style="{ |
| 44 | + color: 'var(--vscode-icon-foreground, var(--vscode-editor-foreground, #cccccc))', |
| 45 | + background: 'transparent', |
| 46 | + }" |
| 47 | + aria-label="Close notification" |
| 48 | + @click="toast.close()" |
| 49 | + > |
| 50 | + × |
| 51 | + </button> |
| 52 | + </div> |
| 53 | + </transition> |
| 54 | +</template> |
| 55 | + |
| 56 | +<style scoped> |
| 57 | + .toast-fade-slide-enter-active, |
| 58 | + .toast-fade-slide-leave-active { |
| 59 | + transition: all 150ms ease; |
| 60 | + } |
| 61 | + .toast-fade-slide-enter-from, |
| 62 | + .toast-fade-slide-leave-to { |
| 63 | + opacity: 0; |
| 64 | + transform: translateY(6px); |
| 65 | + } |
| 66 | +</style> |
0 commit comments