deepsite-companion / components /chat-bubble.js
raysite's picture
start
46a4236 verified
Raw History Blame Contribute Delete
1.22 kB
class ChatBubble extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: 'open' });
const type = this.getAttribute('type') || 'received';
const timestamp = new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
this.shadowRoot.innerHTML = `
<style>
.chat-bubble {
max-width: 80%;
padding: 0.75rem 1rem;
border-radius: 1rem;
margin-bottom: 0.5rem;
position: relative;
word-wrap: break-word;
}
.received {
background-color: #374151;
color: white;
align-self: flex-start;
border-bottom-left-radius: 0.25rem;
}
.sent {
background-color: #0ea5e9;
color: white;
align-self: flex-end;
border-bottom-right-radius: 0.25rem;
}
.timestamp {
font-size: 0.75rem;
color: #9ca3af;
margin-top: 0.25rem;
text-align: right;
}
</style>
<div class="chat-bubble ${type}">
<slot></slot>
<div class="timestamp">${timestamp}</div>
</div>
`;
}
}
customElements.define('chat-bubble', ChatBubble);