Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 5x 5x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 24x 24x 21x 21x 2x 21x 21x 1x 1x 1x 1x 22x 22x 22x 22x 22x 22x 22x 1x 1x 22x 22x 22x 22x 22x 22x 22x 1x 1x 22x 22x 22x 22x 22x 22x 22x 1x 1x 5x 5x 5x 5x 5x 5x 5x 1x 1x 22x 22x 22x 22x 22x 22x 22x 1x 1x 22x 22x 22x 22x 22x 22x 22x 1x 3x 3x 3x 3x 3x 1x 1x 1x | <template>
<Transition
enter-active-class="transition-all duration-300 ease-out"
enter-from-class="translate-x-full opacity-0"
enter-to-class="translate-x-0 opacity-100"
leave-active-class="transition-all duration-200 ease-in"
leave-from-class="translate-x-0 opacity-100"
leave-to-class="translate-x-full opacity-0"
>
<div
v-if="visible"
:class="[
'flex items-start gap-3 p-4 rounded-lg shadow-lg border',
'min-w-[320px] max-w-md',
variantClasses
]"
role="alert"
:aria-live="variant === 'error' ? 'assertive' : 'polite'"
>
<!-- Icon -->
<div class="flex-shrink-0 mt-0.5">
<svg
:class="['h-5 w-5', iconClasses]"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
:d="iconPath"
/>
</svg>
</div>
<!-- Content -->
<div class="flex-1 min-w-0">
<p :class="['text-sm font-medium', textClasses]">
{{ message }}
</p>
<button
v-if="actionLabel"
type="button"
:class="['text-sm font-medium underline mt-1', actionClasses]"
@click="handleAction"
>
{{ actionLabel }}
</button>
</div>
<!-- Dismiss Button -->
<button
type="button"
:class="['flex-shrink-0 rounded-md p-1 transition-colors', dismissClasses]"
:aria-label="$t('alerts.dismiss')"
@click="handleDismiss"
>
<svg
class="h-4 w-4"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M6 18L18 6M6 6l12 12"
/>
</svg>
</button>
</div>
</Transition>
</template>
<script setup lang="ts">
/**
* BaseToast
* @description Non-blocking toast notification component
* Appears briefly at the top-right corner with auto-dismiss
*/
interface Props {
/** Toast variant */
variant?: 'info' | 'success' | 'warning' | 'error'
/** Toast message */
message: string
/** Optional action button label */
actionLabel?: string
/** Auto-dismiss duration in ms (0 to disable) */
duration?: number
/** Control visibility externally */
modelValue?: boolean
}
const props = withDefaults(defineProps<Props>(), {
variant: 'info',
duration: 5000,
modelValue: true
})
const emit = defineEmits<{
'update:modelValue': [value: boolean]
dismiss: []
action: []
}>()
/**
* i18n
*/
const { t } = useI18n()
const visible = ref(props.modelValue)
let timeout: ReturnType<typeof setTimeout> | null = null
// Auto-dismiss
watch(() => props.modelValue, (newValue) => {
visible.value = newValue
if (newValue && props.duration > 0) {
if (timeout) clearTimeout(timeout)
timeout = setTimeout(() => {
handleDismiss()
}, props.duration)
}
}, { immediate: true })
// Cleanup on unmount
onUnmounted(() => {
if (timeout) clearTimeout(timeout)
})
const variantClasses = computed(() => {
const classes = {
info: 'bg-white border-info-300',
success: 'bg-white border-success-300',
warning: 'bg-white border-warning-300',
error: 'bg-white border-error-300',
}
return classes[props.variant]
})
const iconClasses = computed(() => {
const classes = {
info: 'text-info-600',
success: 'text-success-600',
warning: 'text-warning-600',
error: 'text-error-600',
}
return classes[props.variant]
})
const textClasses = computed(() => {
const classes = {
info: 'text-secondary-900',
success: 'text-secondary-900',
warning: 'text-secondary-900',
error: 'text-secondary-900',
}
return classes[props.variant]
})
const actionClasses = computed(() => {
const classes = {
info: 'text-info-700 hover:text-info-800',
success: 'text-success-700 hover:text-success-800',
warning: 'text-warning-700 hover:text-warning-800',
error: 'text-error-700 hover:text-error-800',
}
return classes[props.variant]
})
const dismissClasses = computed(() => {
const classes = {
info: 'text-info-600 hover:bg-info-50',
success: 'text-success-600 hover:bg-success-50',
warning: 'text-warning-600 hover:bg-warning-50',
error: 'text-error-600 hover:bg-error-50',
}
return classes[props.variant]
})
const iconPath = computed(() => {
const paths = {
info: 'M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z',
success: 'M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z',
warning: 'M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z',
error: 'M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z',
}
return paths[props.variant]
})
function handleDismiss() {
visible.value = false
emit('update:modelValue', false)
emit('dismiss')
}
function handleAction() {
emit('action')
}
</script>
|