Spaces:
Running

chattycodecanvas / index.html
LilChond's picture
can i talk to you before we start?
a7f5574 verified
Raw History Blame Contribute Delete
3.23 kB
<!-- Chat Initiation Button -->
<div id="chat-starter" class="fixed bottom-6 right-6 bg-blue-500 text-white p-4 rounded-full shadow-lg cursor-pointer hover:bg-blue-600 transition-all">
<i data-feather="message-circle"></i>
</div>
<!-- Chat Modal -->
<div id="chat-modal" class="hidden fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4 z-50">
<div class="bg-white rounded-lg shadow-xl w-full max-w-md max-h-[80vh] flex flex-col">
<div class="p-4 border-b flex justify-between items-center">
<h3 class="text-lg font-semibold">ChattyCodeCanvas Assistant</h3>
<button id="close-chat" class="text-gray-500 hover:text-gray-700">
<i data-feather="x"></i>
</button>
</div>
<div id="chat-messages" class="flex-1 p-4 overflow-y-auto">
<div class="text-center text-gray-500 py-4">How can I help you with your project today?</div>
</div>
<div class="p-4 border-t">
<div class="flex gap-2">
<input id="chat-input" type="text" placeholder="Type your message..." class="flex-1 border rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500">
<button id="send-chat" class="bg-blue-500 text-white px-4 py-2 rounded-lg hover:bg-blue-600 transition-all">
<i data-feather="send"></i>
</button>
</div>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
feather.replace();
const chatStarter = document.getElementById('chat-starter');
const chatModal = document.getElementById('chat-modal');
const closeChat = document.getElementById('close-chat');
const chatInput = document.getElementById('chat-input');
const sendChat = document.getElementById('send-chat');
const chatMessages = document.getElementById('chat-messages');
chatStarter.addEventListener('click', () => {
chatModal.classList.remove('hidden');
});
closeChat.addEventListener('click', () => {
chatModal.classList.add('hidden');
});
sendChat.addEventListener('click', sendMessage);
chatInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') sendMessage();
});
function sendMessage() {
const message = chatInput.value.trim();
if (message) {
addMessage(message, 'user');
chatInput.value = '';
// Here you would typically send to a backend or process
setTimeout(() => {
addMessage("I'm just a frontend demo! In a real app, this would connect to a backend.", 'bot');
}, 800);
}
}
function addMessage(text, sender) {
const messageDiv = document.createElement('div');
messageDiv.className = `mb-4 p-3 rounded-lg max-w-[80%] ${sender === 'user' ? 'bg-blue-100 ml-auto' : 'bg-gray-100'}`;
messageDiv.textContent = text;
chatMessages.appendChild(messageDiv);
chatMessages.scrollTop = chatMessages.scrollHeight;
}
});
</script>