suna/backend/agent/workspace/assets/toast.js

50 lines
1.5 KiB
JavaScript

// Toast notification system
function createToast() {
// Create toast container if it doesn't exist
let toastContainer = document.getElementById('toastContainer');
if (!toastContainer) {
toastContainer = document.createElement('div');
toastContainer.id = 'toastContainer';
toastContainer.style.position = 'fixed';
toastContainer.style.bottom = '30px';
toastContainer.style.left = '50%';
toastContainer.style.transform = 'translateX(-50%)';
toastContainer.style.zIndex = '1000';
document.body.appendChild(toastContainer);
}
return toastContainer;
}
// Show toast message
function showToast(message, duration = 3000) {
const toastContainer = createToast();
const toast = document.createElement('div');
toast.className = 'toast';
toast.textContent = message;
toast.style.backgroundColor = 'rgba(0, 0, 0, 0.8)';
toast.style.color = 'white';
toast.style.padding = '12px 20px';
toast.style.borderRadius = '20px';
toast.style.marginTop = '10px';
toast.style.opacity = '0';
toast.style.transition = 'opacity 0.3s';
toastContainer.appendChild(toast);
// Trigger animation
setTimeout(() => {
toast.style.opacity = '1';
}, 10);
// Remove toast after duration
setTimeout(() => {
toast.style.opacity = '0';
setTimeout(() => {
toastContainer.removeChild(toast);
}, 300);
}, duration);
}
// Export functions
window.showToast = showToast;